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 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"
65 /* readline include files */
66 #include "readline/readline.h"
67 #include "readline/history.h"
69 /* readline defines this. */
72 #include "mi/mi-common.h"
74 /* Arguments to pass as context to some catch command handlers. */
75 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
76 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
78 /* Prototypes for local functions. */
80 static void enable_delete_command (char *, int);
82 static void enable_delete_breakpoint (struct breakpoint
*);
84 static void enable_once_command (char *, int);
86 static void enable_once_breakpoint (struct breakpoint
*);
88 static void disable_command (char *, int);
90 static void enable_command (char *, int);
92 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
94 static void ignore_command (char *, int);
96 static int breakpoint_re_set_one (void *);
98 static void clear_command (char *, int);
100 static void catch_command (char *, int);
102 static void watch_command (char *, int);
104 static int can_use_hardware_watchpoint (struct value
*);
106 static void break_command_1 (char *, int, int);
108 static void mention (struct breakpoint
*);
110 /* This function is used in gdbtk sources and thus can not be made static. */
111 struct breakpoint
*set_raw_breakpoint (struct gdbarch
*gdbarch
,
112 struct symtab_and_line
,
115 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
117 static CORE_ADDR
adjust_breakpoint_address (struct gdbarch
*gdbarch
,
121 static void describe_other_breakpoints (struct gdbarch
*,
122 struct program_space
*, CORE_ADDR
,
123 struct obj_section
*, int);
125 static int breakpoint_address_match (struct address_space
*aspace1
,
127 struct address_space
*aspace2
,
130 static int watchpoint_locations_match (struct bp_location
*loc1
,
131 struct bp_location
*loc2
);
133 static void breakpoints_info (char *, int);
135 static void breakpoint_1 (int, int);
137 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
139 static int breakpoint_cond_eval (void *);
141 static void cleanup_executing_breakpoints (void *);
143 static void commands_command (char *, int);
145 static void condition_command (char *, int);
147 static int get_number_trailer (char **, int);
149 void set_breakpoint_count (int);
158 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
159 static int remove_breakpoint_1 (struct bp_location
*, insertion_state_t
);
161 static enum print_stop_action
print_it_typical (bpstat
);
163 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
165 static int watchpoint_check (void *);
167 static void maintenance_info_breakpoints (char *, int);
169 static int hw_breakpoint_used_count (void);
171 static int hw_watchpoint_used_count (enum bptype
, int *);
173 static void hbreak_command (char *, int);
175 static void thbreak_command (char *, int);
177 static void watch_command_1 (char *, int, int);
179 static void rwatch_command (char *, int);
181 static void awatch_command (char *, int);
183 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
185 static void stop_command (char *arg
, int from_tty
);
187 static void stopin_command (char *arg
, int from_tty
);
189 static void stopat_command (char *arg
, int from_tty
);
191 static char *ep_parse_optional_if_clause (char **arg
);
193 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
194 char *arg
, int tempflag
, int from_tty
);
196 static void tcatch_command (char *arg
, int from_tty
);
198 static void ep_skip_leading_whitespace (char **s
);
200 static int single_step_breakpoint_inserted_here_p (struct address_space
*,
203 static void free_bp_location (struct bp_location
*loc
);
205 static struct bp_location
*allocate_bp_location (struct breakpoint
*bpt
);
207 static void update_global_location_list (int);
209 static void update_global_location_list_nothrow (int);
211 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
213 static int is_watchpoint (struct breakpoint
*bpt
);
215 static void insert_breakpoint_locations (void);
217 static int syscall_catchpoint_p (struct breakpoint
*b
);
219 static void tracepoints_info (char *, int);
221 static void delete_trace_command (char *, int);
223 static void enable_trace_command (char *, int);
225 static void disable_trace_command (char *, int);
227 static void trace_pass_command (char *, int);
229 static void skip_prologue_sal (struct symtab_and_line
*sal
);
232 /* Flag indicating that a command has proceeded the inferior past the
233 current breakpoint. */
235 static int breakpoint_proceeded
;
238 bpdisp_text (enum bpdisp disp
)
240 /* NOTE: the following values are a part of MI protocol and represent
241 values of 'disp' field returned when inferior stops at a breakpoint. */
242 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
243 return bpdisps
[(int) disp
];
246 /* Prototypes for exported functions. */
247 /* If FALSE, gdb will not use hardware support for watchpoints, even
248 if such is available. */
249 static int can_use_hw_watchpoints
;
252 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
253 struct cmd_list_element
*c
,
256 fprintf_filtered (file
, _("\
257 Debugger's willingness to use watchpoint hardware is %s.\n"),
261 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
262 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
263 for unrecognized breakpoint locations.
264 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
265 static enum auto_boolean pending_break_support
;
267 show_pending_break_support (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
,
271 fprintf_filtered (file
, _("\
272 Debugger's behavior regarding pending breakpoints is %s.\n"),
276 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
277 set with "break" but falling in read-only memory.
278 If 0, gdb will warn about such breakpoints, but won't automatically
279 use hardware breakpoints. */
280 static int automatic_hardware_breakpoints
;
282 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
283 struct cmd_list_element
*c
,
286 fprintf_filtered (file
, _("\
287 Automatic usage of hardware breakpoints is %s.\n"),
291 /* If on, gdb will keep breakpoints inserted even as inferior is
292 stopped, and immediately insert any new breakpoints. If off, gdb
293 will insert breakpoints into inferior only when resuming it, and
294 will remove breakpoints upon stop. If auto, GDB will behave as ON
295 if in non-stop mode, and as OFF if all-stop mode.*/
297 static const char always_inserted_auto
[] = "auto";
298 static const char always_inserted_on
[] = "on";
299 static const char always_inserted_off
[] = "off";
300 static const char *always_inserted_enums
[] = {
301 always_inserted_auto
,
306 static const char *always_inserted_mode
= always_inserted_auto
;
308 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
309 struct cmd_list_element
*c
, const char *value
)
311 if (always_inserted_mode
== always_inserted_auto
)
312 fprintf_filtered (file
, _("\
313 Always inserted breakpoint mode is %s (currently %s).\n"),
315 breakpoints_always_inserted_mode () ? "on" : "off");
317 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
321 breakpoints_always_inserted_mode (void)
323 return (always_inserted_mode
== always_inserted_on
324 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
327 void _initialize_breakpoint (void);
329 /* Are we executing breakpoint commands? */
330 static int executing_breakpoint_commands
;
332 /* Are overlay event breakpoints enabled? */
333 static int overlay_events_enabled
;
335 /* Walk the following statement or block through all breakpoints.
336 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
339 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
341 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
342 for (B = breakpoint_chain; \
343 B ? (TMP=B->next, 1): 0; \
346 /* Similar iterator for the low-level breakpoints. SAFE variant is not
347 provided so update_global_location_list must not be called while executing
348 the block of ALL_BP_LOCATIONS. */
350 #define ALL_BP_LOCATIONS(B,BP_TMP) \
351 for (BP_TMP = bp_location; \
352 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \
355 /* Iterator for tracepoints only. */
357 #define ALL_TRACEPOINTS(B) \
358 for (B = breakpoint_chain; B; B = B->next) \
359 if (tracepoint_type (B))
361 /* Chains of all breakpoints defined. */
363 struct breakpoint
*breakpoint_chain
;
365 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */
367 static struct bp_location
**bp_location
;
369 /* Number of elements of BP_LOCATION. */
371 static unsigned bp_location_count
;
373 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS
374 for the current elements of BP_LOCATION which get a valid result from
375 bp_location_has_shadow. You can use it for roughly limiting the subrange of
376 BP_LOCATION to scan for shadow bytes for an address you need to read. */
378 static CORE_ADDR bp_location_placed_address_before_address_max
;
380 /* Maximum offset plus alignment between
381 bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for
382 the current elements of BP_LOCATION which get a valid result from
383 bp_location_has_shadow. You can use it for roughly limiting the subrange of
384 BP_LOCATION to scan for shadow bytes for an address you need to read. */
386 static CORE_ADDR bp_location_shadow_len_after_address_max
;
388 /* The locations that no longer correspond to any breakpoint,
389 unlinked from bp_location array, but for which a hit
390 may still be reported by a target. */
391 VEC(bp_location_p
) *moribund_locations
= NULL
;
393 /* Number of last breakpoint made. */
395 int breakpoint_count
;
397 /* Number of last tracepoint made. */
399 int tracepoint_count
;
401 /* Return whether a breakpoint is an active enabled breakpoint. */
403 breakpoint_enabled (struct breakpoint
*b
)
405 return (b
->enable_state
== bp_enabled
);
408 /* Set breakpoint count to NUM. */
411 set_breakpoint_count (int num
)
413 breakpoint_count
= num
;
414 set_internalvar_integer (lookup_internalvar ("bpnum"), num
);
417 /* Used in run_command to zero the hit count when a new run starts. */
420 clear_breakpoint_hit_counts (void)
422 struct breakpoint
*b
;
428 /* Encapsulate tests for different types of tracepoints. */
431 tracepoint_type (const struct breakpoint
*b
)
433 return (b
->type
== bp_tracepoint
|| b
->type
== bp_fast_tracepoint
);
436 /* Allocate a new counted_command_line with reference count of 1.
437 The new structure owns COMMANDS. */
439 static struct counted_command_line
*
440 alloc_counted_command_line (struct command_line
*commands
)
442 struct counted_command_line
*result
443 = xmalloc (sizeof (struct counted_command_line
));
445 result
->commands
= commands
;
449 /* Increment reference count. This does nothing if CMD is NULL. */
452 incref_counted_command_line (struct counted_command_line
*cmd
)
458 /* Decrement reference count. If the reference count reaches 0,
459 destroy the counted_command_line. Sets *CMDP to NULL. This does
460 nothing if *CMDP is NULL. */
463 decref_counted_command_line (struct counted_command_line
**cmdp
)
467 if (--(*cmdp
)->refc
== 0)
469 free_command_lines (&(*cmdp
)->commands
);
476 /* A cleanup function that calls decref_counted_command_line. */
479 do_cleanup_counted_command_line (void *arg
)
481 decref_counted_command_line (arg
);
484 /* Create a cleanup that calls decref_counted_command_line on the
487 static struct cleanup
*
488 make_cleanup_decref_counted_command_line (struct counted_command_line
**cmdp
)
490 return make_cleanup (do_cleanup_counted_command_line
, cmdp
);
493 /* Default address, symtab and line to put a breakpoint at
494 for "break" command with no arg.
495 if default_breakpoint_valid is zero, the other three are
496 not valid, and "break" with no arg is an error.
498 This set by print_stack_frame, which calls set_default_breakpoint. */
500 int default_breakpoint_valid
;
501 CORE_ADDR default_breakpoint_address
;
502 struct symtab
*default_breakpoint_symtab
;
503 int default_breakpoint_line
;
504 struct program_space
*default_breakpoint_pspace
;
507 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
508 Advance *PP after the string and any trailing whitespace.
510 Currently the string can either be a number or "$" followed by the name
511 of a convenience variable. Making it an expression wouldn't work well
512 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
514 If the string is a NULL pointer, that denotes the last breakpoint.
516 TRAILER is a character which can be found after the number; most
517 commonly this is `-'. If you don't want a trailer, use \0. */
519 get_number_trailer (char **pp
, int trailer
)
521 int retval
= 0; /* default */
525 /* Empty line means refer to the last breakpoint. */
526 return breakpoint_count
;
529 /* Make a copy of the name, so we can null-terminate it
530 to pass to lookup_internalvar(). */
535 while (isalnum (*p
) || *p
== '_')
537 varname
= (char *) alloca (p
- start
+ 1);
538 strncpy (varname
, start
, p
- start
);
539 varname
[p
- start
] = '\0';
540 if (get_internalvar_integer (lookup_internalvar (varname
), &val
))
544 printf_filtered (_("Convenience variable must have integer value.\n"));
552 while (*p
>= '0' && *p
<= '9')
555 /* There is no number here. (e.g. "cond a == b"). */
557 /* Skip non-numeric token */
558 while (*p
&& !isspace((int) *p
))
560 /* Return zero, which caller must interpret as error. */
566 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
568 /* Trailing junk: return 0 and let caller print error msg. */
569 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
580 /* Like get_number_trailer, but don't allow a trailer. */
582 get_number (char **pp
)
584 return get_number_trailer (pp
, '\0');
587 /* Parse a number or a range.
588 * A number will be of the form handled by get_number.
589 * A range will be of the form <number1> - <number2>, and
590 * will represent all the integers between number1 and number2,
593 * While processing a range, this fuction is called iteratively;
594 * At each call it will return the next value in the range.
596 * At the beginning of parsing a range, the char pointer PP will
597 * be advanced past <number1> and left pointing at the '-' token.
598 * Subsequent calls will not advance the pointer until the range
599 * is completed. The call that completes the range will advance
600 * pointer PP past <number2>.
604 get_number_or_range (char **pp
)
606 static int last_retval
, end_value
;
607 static char *end_ptr
;
608 static int in_range
= 0;
612 /* Default case: pp is pointing either to a solo number,
613 or to the first number of a range. */
614 last_retval
= get_number_trailer (pp
, '-');
619 /* This is the start of a range (<number1> - <number2>).
620 Skip the '-', parse and remember the second number,
621 and also remember the end of the final token. */
625 while (isspace ((int) *end_ptr
))
626 end_ptr
++; /* skip white space */
627 end_value
= get_number (temp
);
628 if (end_value
< last_retval
)
630 error (_("inverted range"));
632 else if (end_value
== last_retval
)
634 /* degenerate range (number1 == number2). Advance the
635 token pointer so that the range will be treated as a
644 error (_("negative value"));
647 /* pp points to the '-' that betokens a range. All
648 number-parsing has already been done. Return the next
649 integer value (one greater than the saved previous value).
650 Do not advance the token pointer 'pp' until the end of range
653 if (++last_retval
== end_value
)
655 /* End of range reached; advance token pointer. */
663 /* Return the breakpoint with the specified number, or NULL
664 if the number does not refer to an existing breakpoint. */
667 get_breakpoint (int num
)
669 struct breakpoint
*b
;
672 if (b
->number
== num
)
679 /* condition N EXP -- set break condition of breakpoint N to EXP. */
682 condition_command (char *arg
, int from_tty
)
684 struct breakpoint
*b
;
689 error_no_arg (_("breakpoint number"));
692 bnum
= get_number (&p
);
694 error (_("Bad breakpoint argument: '%s'"), arg
);
697 if (b
->number
== bnum
)
699 struct bp_location
*loc
= b
->loc
;
700 for (; loc
; loc
= loc
->next
)
705 xfree (b
->cond_string
);
706 b
->cond_string
= NULL
;
713 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
718 /* I don't know if it matters whether this is the string the user
719 typed in or the decompiled expression. */
720 b
->cond_string
= xstrdup (arg
);
721 b
->condition_not_parsed
= 0;
723 if (is_watchpoint (b
))
725 innermost_block
= NULL
;
727 b
->cond_exp
= parse_exp_1 (&arg
, 0, 0);
729 error (_("Junk at end of expression"));
730 b
->cond_exp_valid_block
= innermost_block
;
734 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
738 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
740 error (_("Junk at end of expression"));
744 breakpoints_changed ();
745 observer_notify_breakpoint_modified (b
->number
);
749 error (_("No breakpoint number %d."), bnum
);
752 /* Check that COMMAND do not contain commands that are suitable
753 only for tracepoints and not suitable for ordinary breakpoints.
754 Throw if any such commands is found.
757 check_no_tracepoint_commands (struct command_line
*commands
)
759 struct command_line
*c
;
760 for (c
= commands
; c
; c
= c
->next
)
764 if (c
->control_type
== while_stepping_control
)
765 error (_("The 'while-stepping' command can only be used for tracepoints"));
767 for (i
= 0; i
< c
->body_count
; ++i
)
768 check_no_tracepoint_commands ((c
->body_list
)[i
]);
770 /* Not that command parsing removes leading whitespace and comment
771 lines and also empty lines. So, we only need to check for
773 if (strstr (c
->line
, "collect ") == c
->line
)
774 error (_("The 'collect' command can only be used for tracepoints"));
776 if (strstr (c
->line
, "teval ") == c
->line
)
777 error (_("The 'teval' command can only be used for tracepoints"));
782 breakpoint_is_tracepoint (const struct breakpoint
*b
)
787 case bp_fast_tracepoint
:
795 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint,
796 validate that only allowed commands are included.
800 breakpoint_set_commands (struct breakpoint
*b
, struct command_line
*commands
)
802 if (breakpoint_is_tracepoint (b
))
804 /* We need to verify that each top-level element of commands
805 is valid for tracepoints, that there's at most one while-stepping
806 element, and that while-stepping's body has valid tracing commands
807 excluding nested while-stepping. */
808 struct command_line
*c
;
809 struct command_line
*while_stepping
= 0;
810 for (c
= commands
; c
; c
= c
->next
)
813 if (c
->control_type
== while_stepping_control
)
815 if (b
->type
== bp_fast_tracepoint
)
816 error (_("The 'while-stepping' command cannot be used for fast tracepoint"));
819 error (_("The 'while-stepping' command can be used only once"));
826 struct command_line
*c2
;
828 gdb_assert (while_stepping
->body_count
== 1);
829 c2
= while_stepping
->body_list
[0];
830 for (; c2
; c2
= c2
->next
)
833 if (c2
->control_type
== while_stepping_control
)
834 error (_("The 'while-stepping' command cannot be nested"));
840 check_no_tracepoint_commands (commands
);
843 decref_counted_command_line (&b
->commands
);
844 b
->commands
= alloc_counted_command_line (commands
);
845 breakpoints_changed ();
846 observer_notify_breakpoint_modified (b
->number
);
849 void check_tracepoint_command (char *line
, void *closure
)
851 struct breakpoint
*b
= closure
;
852 validate_actionline (&line
, b
);
856 commands_command (char *arg
, int from_tty
)
858 struct breakpoint
*b
;
861 struct command_line
*l
;
864 bnum
= get_number (&p
);
867 error (_("Unexpected extra arguments following breakpoint number."));
870 if (b
->number
== bnum
)
872 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
874 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
876 if (breakpoint_is_tracepoint (b
))
877 l
= read_command_lines (tmpbuf
, from_tty
, 1,
878 check_tracepoint_command
, b
);
880 l
= read_command_lines (tmpbuf
, from_tty
, 1, 0, 0);
881 do_cleanups (cleanups
);
882 breakpoint_set_commands (b
, l
);
885 error (_("No breakpoint number %d."), bnum
);
888 /* Like commands_command, but instead of reading the commands from
889 input stream, takes them from an already parsed command structure.
891 This is used by cli-script.c to DTRT with breakpoint commands
892 that are part of if and while bodies. */
893 enum command_control_type
894 commands_from_control_command (char *arg
, struct command_line
*cmd
)
896 struct breakpoint
*b
;
900 /* An empty string for the breakpoint number means the last
901 breakpoint, but get_number expects a NULL pointer. */
906 bnum
= get_number (&p
);
909 error (_("Unexpected extra arguments following breakpoint number."));
912 if (b
->number
== bnum
)
914 decref_counted_command_line (&b
->commands
);
915 if (cmd
->body_count
!= 1)
916 error (_("Invalid \"commands\" block structure."));
917 /* We need to copy the commands because if/while will free the
918 list after it finishes execution. */
920 = alloc_counted_command_line (copy_command_lines (cmd
->body_list
[0]));
921 breakpoints_changed ();
922 observer_notify_breakpoint_modified (b
->number
);
923 return simple_control
;
925 error (_("No breakpoint number %d."), bnum
);
928 /* Return non-zero if BL->TARGET_INFO contains valid information. */
931 bp_location_has_shadow (struct bp_location
*bl
)
933 if (bl
->loc_type
!= bp_loc_software_breakpoint
)
937 if (bl
->target_info
.shadow_len
== 0)
938 /* bp isn't valid, or doesn't shadow memory. */
943 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
944 by replacing any memory breakpoints with their shadowed contents.
946 The range of shadowed area by each bp_location is:
947 b->address - bp_location_placed_address_before_address_max
948 up to b->address + bp_location_shadow_len_after_address_max
949 The range we were requested to resolve shadows for is:
950 memaddr ... memaddr + len
951 Thus the safe cutoff boundaries for performance optimization are
952 memaddr + len <= b->address - bp_location_placed_address_before_address_max
954 b->address + bp_location_shadow_len_after_address_max <= memaddr */
957 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
959 /* Left boundary, right boundary and median element of our binary search. */
960 unsigned bc_l
, bc_r
, bc
;
962 /* Find BC_L which is a leftmost element which may affect BUF content. It is
963 safe to report lower value but a failure to report higher one. */
966 bc_r
= bp_location_count
;
967 while (bc_l
+ 1 < bc_r
)
969 struct bp_location
*b
;
971 bc
= (bc_l
+ bc_r
) / 2;
974 /* Check first B->ADDRESS will not overflow due to the added constant.
975 Then advance the left boundary only if we are sure the BC element can
976 in no way affect the BUF content (MEMADDR to MEMADDR + LEN range).
978 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that
979 we cannot miss a breakpoint with its shadow range tail still reaching
982 if (b
->address
+ bp_location_shadow_len_after_address_max
>= b
->address
983 && b
->address
+ bp_location_shadow_len_after_address_max
<= memaddr
)
989 /* Now do full processing of the found relevant range of elements. */
991 for (bc
= bc_l
; bc
< bp_location_count
; bc
++)
993 struct bp_location
*b
= bp_location
[bc
];
994 CORE_ADDR bp_addr
= 0;
998 if (b
->owner
->type
== bp_none
)
999 warning (_("reading through apparently deleted breakpoint #%d?"),
1002 /* Performance optimization: any futher element can no longer affect BUF
1005 if (b
->address
>= bp_location_placed_address_before_address_max
1006 && memaddr
+ len
<= b
->address
1007 - bp_location_placed_address_before_address_max
)
1010 if (!bp_location_has_shadow (b
))
1012 if (!breakpoint_address_match (b
->target_info
.placed_address_space
, 0,
1013 current_program_space
->aspace
, 0))
1016 /* Addresses and length of the part of the breakpoint that
1018 bp_addr
= b
->target_info
.placed_address
;
1019 bp_size
= b
->target_info
.shadow_len
;
1021 if (bp_addr
+ bp_size
<= memaddr
)
1022 /* The breakpoint is entirely before the chunk of memory we
1026 if (bp_addr
>= memaddr
+ len
)
1027 /* The breakpoint is entirely after the chunk of memory we are
1031 /* Offset within shadow_contents. */
1032 if (bp_addr
< memaddr
)
1034 /* Only copy the second part of the breakpoint. */
1035 bp_size
-= memaddr
- bp_addr
;
1036 bptoffset
= memaddr
- bp_addr
;
1040 if (bp_addr
+ bp_size
> memaddr
+ len
)
1042 /* Only copy the first part of the breakpoint. */
1043 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
1046 memcpy (buf
+ bp_addr
- memaddr
,
1047 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
1052 /* A wrapper function for inserting catchpoints. */
1054 insert_catchpoint (struct ui_out
*uo
, void *args
)
1056 struct breakpoint
*b
= (struct breakpoint
*) args
;
1059 gdb_assert (b
->type
== bp_catchpoint
);
1060 gdb_assert (b
->ops
!= NULL
&& b
->ops
->insert
!= NULL
);
1065 /* Return true if BPT is of any hardware watchpoint kind. */
1068 is_hardware_watchpoint (struct breakpoint
*bpt
)
1070 return (bpt
->type
== bp_hardware_watchpoint
1071 || bpt
->type
== bp_read_watchpoint
1072 || bpt
->type
== bp_access_watchpoint
);
1075 /* Return true if BPT is of any watchpoint kind, hardware or
1079 is_watchpoint (struct breakpoint
*bpt
)
1081 return (is_hardware_watchpoint (bpt
)
1082 || bpt
->type
== bp_watchpoint
);
1085 /* Find the current value of a watchpoint on EXP. Return the value in
1086 *VALP and *RESULTP and the chain of intermediate and final values
1087 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
1090 If a memory error occurs while evaluating the expression, *RESULTP will
1091 be set to NULL. *RESULTP may be a lazy value, if the result could
1092 not be read from memory. It is used to determine whether a value
1093 is user-specified (we should watch the whole value) or intermediate
1094 (we should watch only the bit used to locate the final value).
1096 If the final value, or any intermediate value, could not be read
1097 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
1098 set to any referenced values. *VALP will never be a lazy value.
1099 This is the value which we store in struct breakpoint.
1101 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
1102 value chain. The caller must free the values individually. If
1103 VAL_CHAIN is NULL, all generated values will be left on the value
1107 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
1108 struct value
**resultp
, struct value
**val_chain
)
1110 struct value
*mark
, *new_mark
, *result
;
1111 volatile struct gdb_exception ex
;
1119 /* Evaluate the expression. */
1120 mark
= value_mark ();
1123 TRY_CATCH (ex
, RETURN_MASK_ALL
)
1125 result
= evaluate_expression (exp
);
1129 /* Ignore memory errors, we want watchpoints pointing at
1130 inaccessible memory to still be created; otherwise, throw the
1131 error to some higher catcher. */
1137 throw_exception (ex
);
1142 new_mark
= value_mark ();
1143 if (mark
== new_mark
)
1148 /* Make sure it's not lazy, so that after the target stops again we
1149 have a non-lazy previous value to compare with. */
1151 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
1156 /* Return the chain of intermediate values. We use this to
1157 decide which addresses to watch. */
1158 *val_chain
= new_mark
;
1159 value_release_to_mark (mark
);
1163 /* Assuming that B is a watchpoint: returns true if the current thread
1164 and its running state are safe to evaluate or update watchpoint B.
1165 Watchpoints on local expressions need to be evaluated in the
1166 context of the thread that was current when the watchpoint was
1167 created, and, that thread needs to be stopped to be able to select
1168 the correct frame context. Watchpoints on global expressions can
1169 be evaluated on any thread, and in any state. It is presently left
1170 to the target allowing memory accesses when threads are
1174 watchpoint_in_thread_scope (struct breakpoint
*b
)
1176 return (ptid_equal (b
->watchpoint_thread
, null_ptid
)
1177 || (ptid_equal (inferior_ptid
, b
->watchpoint_thread
)
1178 && !is_executing (inferior_ptid
)));
1181 /* Assuming that B is a watchpoint:
1182 - Reparse watchpoint expression, if REPARSE is non-zero
1183 - Evaluate expression and store the result in B->val
1184 - Evaluate the condition if there is one, and store the result
1186 - Update the list of values that must be watched in B->loc.
1188 If the watchpoint disposition is disp_del_at_next_stop, then do nothing.
1189 If this is local watchpoint that is out of scope, delete it.
1191 Even with `set breakpoint always-inserted on' the watchpoints are removed
1192 + inserted on each stop here. Normal breakpoints must never be removed
1193 because they might be missed by a running thread when debugging in non-stop
1194 mode. On the other hand, hardware watchpoints (is_hardware_watchpoint;
1195 processed here) are specific to each LWP since they are stored in each LWP's
1196 hardware debug registers. Therefore, such LWP must be stopped first in
1197 order to be able to modify its hardware watchpoints.
1199 Hardware watchpoints must be reset exactly once after being presented to the
1200 user. It cannot be done sooner, because it would reset the data used to
1201 present the watchpoint hit to the user. And it must not be done later
1202 because it could display the same single watchpoint hit during multiple GDB
1203 stops. Note that the latter is relevant only to the hardware watchpoint
1204 types bp_read_watchpoint and bp_access_watchpoint. False hit by
1205 bp_hardware_watchpoint is not user-visible - its hit is suppressed if the
1206 memory content has not changed.
1208 The following constraints influence the location where we can reset hardware
1211 * target_stopped_by_watchpoint and target_stopped_data_address are called
1212 several times when GDB stops.
1215 * Multiple hardware watchpoints can be hit at the same time, causing GDB to
1216 stop. GDB only presents one hardware watchpoint hit at a time as the
1217 reason for stopping, and all the other hits are presented later, one after
1218 the other, each time the user requests the execution to be resumed.
1219 Execution is not resumed for the threads still having pending hit event
1220 stored in LWP_INFO->STATUS. While the watchpoint is already removed from
1221 the inferior on the first stop the thread hit event is kept being reported
1222 from its cached value by linux_nat_stopped_data_address until the real
1223 thread resume happens after the watchpoint gets presented and thus its
1224 LWP_INFO->STATUS gets reset.
1226 Therefore the hardware watchpoint hit can get safely reset on the watchpoint
1227 removal from inferior. */
1230 update_watchpoint (struct breakpoint
*b
, int reparse
)
1232 int within_current_scope
;
1233 struct frame_id saved_frame_id
;
1234 struct bp_location
*loc
;
1238 /* If this is a local watchpoint, we only want to check if the
1239 watchpoint frame is in scope if the current thread is the thread
1240 that was used to create the watchpoint. */
1241 if (!watchpoint_in_thread_scope (b
))
1244 /* We don't free locations. They are stored in bp_location array and
1245 update_global_locations will eventually delete them and remove
1246 breakpoints if needed. */
1249 if (b
->disposition
== disp_del_at_next_stop
)
1254 /* Determine if the watchpoint is within scope. */
1255 if (b
->exp_valid_block
== NULL
)
1256 within_current_scope
= 1;
1259 struct frame_info
*fi
;
1261 /* Save the current frame's ID so we can restore it after
1262 evaluating the watchpoint expression on its own frame. */
1263 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
1264 took a frame parameter, so that we didn't have to change the
1267 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
1269 fi
= frame_find_by_id (b
->watchpoint_frame
);
1270 within_current_scope
= (fi
!= NULL
);
1271 if (within_current_scope
)
1275 if (within_current_scope
&& reparse
)
1284 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1285 /* If the meaning of expression itself changed, the old value is
1286 no longer relevant. We don't want to report a watchpoint hit
1287 to the user when the old value and the new value may actually
1288 be completely different objects. */
1289 value_free (b
->val
);
1293 /* Note that unlike with breakpoints, the watchpoint's condition
1294 expression is stored in the breakpoint object, not in the
1295 locations (re)created below. */
1296 if (b
->cond_string
!= NULL
)
1298 if (b
->cond_exp
!= NULL
)
1300 xfree (b
->cond_exp
);
1305 b
->cond_exp
= parse_exp_1 (&s
, b
->cond_exp_valid_block
, 0);
1309 /* If we failed to parse the expression, for example because
1310 it refers to a global variable in a not-yet-loaded shared library,
1311 don't try to insert watchpoint. We don't automatically delete
1312 such watchpoint, though, since failure to parse expression
1313 is different from out-of-scope watchpoint. */
1314 if ( !target_has_execution
)
1316 /* Without execution, memory can't change. No use to try and
1317 set watchpoint locations. The watchpoint will be reset when
1318 the target gains execution, through breakpoint_re_set. */
1320 else if (within_current_scope
&& b
->exp
)
1322 struct value
*val_chain
, *v
, *result
, *next
;
1323 struct program_space
*frame_pspace
;
1325 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
1327 /* Avoid setting b->val if it's already set. The meaning of
1328 b->val is 'the last value' user saw, and we should update
1329 it only if we reported that last value to user. As it
1330 happens, the code that reports it updates b->val directly. */
1337 /* Change the type of breakpoint between hardware assisted or an
1338 ordinary watchpoint depending on the hardware support and free
1339 hardware slots. REPARSE is set when the inferior is started. */
1340 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1343 int i
, mem_cnt
, other_type_used
;
1345 /* We need to determine how many resources are already used
1346 for all other hardware watchpoints to see if we still have
1347 enough resources to also fit this watchpoint in as well.
1348 To avoid the hw_watchpoint_used_count call below from counting
1349 this watchpoint, make sure that it is marked as a software
1351 b
->type
= bp_watchpoint
;
1352 i
= hw_watchpoint_used_count (bp_hardware_watchpoint
,
1354 mem_cnt
= can_use_hardware_watchpoint (val_chain
);
1357 b
->type
= bp_watchpoint
;
1360 int target_resources_ok
= target_can_use_hardware_watchpoint
1361 (bp_hardware_watchpoint
, i
+ mem_cnt
, other_type_used
);
1362 if (target_resources_ok
<= 0)
1363 b
->type
= bp_watchpoint
;
1365 b
->type
= bp_hardware_watchpoint
;
1369 frame_pspace
= get_frame_program_space (get_selected_frame (NULL
));
1371 /* Look at each value on the value chain. */
1372 for (v
= val_chain
; v
; v
= next
)
1374 /* If it's a memory location, and GDB actually needed
1375 its contents to evaluate the expression, then we
1376 must watch it. If the first value returned is
1377 still lazy, that means an error occurred reading it;
1378 watch it anyway in case it becomes readable. */
1379 if (VALUE_LVAL (v
) == lval_memory
1380 && (v
== val_chain
|| ! value_lazy (v
)))
1382 struct type
*vtype
= check_typedef (value_type (v
));
1384 /* We only watch structs and arrays if user asked
1385 for it explicitly, never if they just happen to
1386 appear in the middle of some value chain. */
1388 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1389 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1393 struct bp_location
*loc
, **tmp
;
1395 addr
= value_address (v
);
1396 len
= TYPE_LENGTH (value_type (v
));
1398 if (b
->type
== bp_read_watchpoint
)
1400 else if (b
->type
== bp_access_watchpoint
)
1403 loc
= allocate_bp_location (b
);
1404 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1407 loc
->gdbarch
= get_type_arch (value_type (v
));
1409 loc
->pspace
= frame_pspace
;
1410 loc
->address
= addr
;
1412 loc
->watchpoint_type
= type
;
1416 next
= value_next (v
);
1421 /* If a software watchpoint is not watching any memory, then the
1422 above left it without any location set up. But,
1423 bpstat_stop_status requires a location to be able to report
1424 stops, so make sure there's at least a dummy one. */
1425 if (b
->type
== bp_watchpoint
&& b
->loc
== NULL
)
1427 b
->loc
= allocate_bp_location (b
);
1428 b
->loc
->pspace
= frame_pspace
;
1429 b
->loc
->address
= -1;
1430 b
->loc
->length
= -1;
1431 b
->loc
->watchpoint_type
= -1;
1434 else if (!within_current_scope
)
1436 printf_filtered (_("\
1437 Watchpoint %d deleted because the program has left the block \n\
1438 in which its expression is valid.\n"),
1440 if (b
->related_breakpoint
)
1442 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1443 b
->related_breakpoint
->related_breakpoint
= NULL
;
1444 b
->related_breakpoint
= NULL
;
1446 b
->disposition
= disp_del_at_next_stop
;
1449 /* Restore the selected frame. */
1451 select_frame (frame_find_by_id (saved_frame_id
));
1455 /* Returns 1 iff breakpoint location should be
1456 inserted in the inferior. */
1458 should_be_inserted (struct bp_location
*bpt
)
1460 if (!breakpoint_enabled (bpt
->owner
))
1463 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1466 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1469 /* This is set for example, when we're attached to the parent of a
1470 vfork, and have detached from the child. The child is running
1471 free, and we expect it to do an exec or exit, at which point the
1472 OS makes the parent schedulable again (and the target reports
1473 that the vfork is done). Until the child is done with the shared
1474 memory region, do not insert breakpoints in the parent, otherwise
1475 the child could still trip on the parent's breakpoints. Since
1476 the parent is blocked anyway, it won't miss any breakpoint. */
1477 if (bpt
->pspace
->breakpoints_not_allowed
)
1480 /* Tracepoints are inserted by the target at a time of its choosing,
1482 if (tracepoint_type (bpt
->owner
))
1488 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1489 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1490 and HW_BREAKPOINT_ERROR are used to report problems.
1492 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1493 method for each breakpoint or catchpoint type. */
1495 insert_bp_location (struct bp_location
*bpt
,
1496 struct ui_file
*tmp_error_stream
,
1497 int *disabled_breaks
,
1498 int *hw_breakpoint_error
)
1502 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1505 /* Initialize the target-specific information. */
1506 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1507 bpt
->target_info
.placed_address
= bpt
->address
;
1508 bpt
->target_info
.placed_address_space
= bpt
->pspace
->aspace
;
1510 if (bpt
->loc_type
== bp_loc_software_breakpoint
1511 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1513 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1515 /* If the explicitly specified breakpoint type
1516 is not hardware breakpoint, check the memory map to see
1517 if the breakpoint address is in read only memory or not.
1518 Two important cases are:
1519 - location type is not hardware breakpoint, memory
1520 is readonly. We change the type of the location to
1521 hardware breakpoint.
1522 - location type is hardware breakpoint, memory is read-write.
1523 This means we've previously made the location hardware one, but
1524 then the memory map changed, so we undo.
1526 When breakpoints are removed, remove_breakpoints will
1527 use location types we've just set here, the only possible
1528 problem is that memory map has changed during running program,
1529 but it's not going to work anyway with current gdb. */
1530 struct mem_region
*mr
1531 = lookup_mem_region (bpt
->target_info
.placed_address
);
1535 if (automatic_hardware_breakpoints
)
1538 enum bp_loc_type new_type
;
1540 if (mr
->attrib
.mode
!= MEM_RW
)
1541 new_type
= bp_loc_hardware_breakpoint
;
1543 new_type
= bp_loc_software_breakpoint
;
1545 if (new_type
!= bpt
->loc_type
)
1547 static int said
= 0;
1548 bpt
->loc_type
= new_type
;
1551 fprintf_filtered (gdb_stdout
, _("\
1552 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1557 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1558 && mr
->attrib
.mode
!= MEM_RW
)
1559 warning (_("cannot set software breakpoint at readonly address %s"),
1560 paddress (bpt
->gdbarch
, bpt
->address
));
1564 /* First check to see if we have to handle an overlay. */
1565 if (overlay_debugging
== ovly_off
1566 || bpt
->section
== NULL
1567 || !(section_is_overlay (bpt
->section
)))
1569 /* No overlay handling: just set the breakpoint. */
1571 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1572 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1575 val
= target_insert_breakpoint (bpt
->gdbarch
,
1580 /* This breakpoint is in an overlay section.
1581 Shall we set a breakpoint at the LMA? */
1582 if (!overlay_events_enabled
)
1584 /* Yes -- overlay event support is not active,
1585 so we must try to set a breakpoint at the LMA.
1586 This will not work for a hardware breakpoint. */
1587 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1588 warning (_("hardware breakpoint %d not supported in overlay!"),
1589 bpt
->owner
->number
);
1592 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1594 /* Set a software (trap) breakpoint at the LMA. */
1595 bpt
->overlay_target_info
= bpt
->target_info
;
1596 bpt
->overlay_target_info
.placed_address
= addr
;
1597 val
= target_insert_breakpoint (bpt
->gdbarch
,
1598 &bpt
->overlay_target_info
);
1600 fprintf_unfiltered (tmp_error_stream
,
1601 "Overlay breakpoint %d failed: in ROM?\n",
1602 bpt
->owner
->number
);
1605 /* Shall we set a breakpoint at the VMA? */
1606 if (section_is_mapped (bpt
->section
))
1608 /* Yes. This overlay section is mapped into memory. */
1609 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1610 val
= target_insert_hw_breakpoint (bpt
->gdbarch
,
1613 val
= target_insert_breakpoint (bpt
->gdbarch
,
1618 /* No. This breakpoint will not be inserted.
1619 No error, but do not mark the bp as 'inserted'. */
1626 /* Can't set the breakpoint. */
1627 if (solib_name_from_address (bpt
->pspace
, bpt
->address
))
1629 /* See also: disable_breakpoints_in_shlibs. */
1631 bpt
->shlib_disabled
= 1;
1632 if (!*disabled_breaks
)
1634 fprintf_unfiltered (tmp_error_stream
,
1635 "Cannot insert breakpoint %d.\n",
1636 bpt
->owner
->number
);
1637 fprintf_unfiltered (tmp_error_stream
,
1638 "Temporarily disabling shared library breakpoints:\n");
1640 *disabled_breaks
= 1;
1641 fprintf_unfiltered (tmp_error_stream
,
1642 "breakpoint #%d\n", bpt
->owner
->number
);
1646 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1648 *hw_breakpoint_error
= 1;
1649 fprintf_unfiltered (tmp_error_stream
,
1650 "Cannot insert hardware breakpoint %d.\n",
1651 bpt
->owner
->number
);
1655 fprintf_unfiltered (tmp_error_stream
,
1656 "Cannot insert breakpoint %d.\n",
1657 bpt
->owner
->number
);
1658 fprintf_filtered (tmp_error_stream
,
1659 "Error accessing memory address ");
1660 fputs_filtered (paddress (bpt
->gdbarch
, bpt
->address
),
1662 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1663 safe_strerror (val
));
1674 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1675 /* NOTE drow/2003-09-08: This state only exists for removing
1676 watchpoints. It's not clear that it's necessary... */
1677 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1679 val
= target_insert_watchpoint (bpt
->address
,
1681 bpt
->watchpoint_type
);
1683 /* If trying to set a read-watchpoint, and it turns out it's not
1684 supported, try emulating one with an access watchpoint. */
1685 if (val
== 1 && bpt
->watchpoint_type
== hw_read
)
1687 struct bp_location
*loc
, **loc_temp
;
1689 /* But don't try to insert it, if there's already another
1690 hw_access location that would be considered a duplicate
1692 ALL_BP_LOCATIONS (loc
, loc_temp
)
1694 && loc
->watchpoint_type
== hw_access
1695 && watchpoint_locations_match (bpt
, loc
))
1699 bpt
->target_info
= loc
->target_info
;
1700 bpt
->watchpoint_type
= hw_access
;
1707 val
= target_insert_watchpoint (bpt
->address
,
1711 bpt
->watchpoint_type
= hw_access
;
1715 bpt
->inserted
= (val
== 0);
1718 else if (bpt
->owner
->type
== bp_catchpoint
)
1720 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1721 bpt
->owner
, RETURN_MASK_ERROR
);
1722 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1723 bpt
->owner
->number
);
1725 bpt
->owner
->enable_state
= bp_disabled
;
1729 /* We've already printed an error message if there was a problem
1730 inserting this catchpoint, and we've disabled the catchpoint,
1731 so just return success. */
1738 /* This function is called when program space PSPACE is about to be
1739 deleted. It takes care of updating breakpoints to not reference
1743 breakpoint_program_space_exit (struct program_space
*pspace
)
1745 struct breakpoint
*b
, *b_temp
;
1746 struct bp_location
*loc
, **loc_temp
;
1748 /* Remove any breakpoint that was set through this program space. */
1749 ALL_BREAKPOINTS_SAFE (b
, b_temp
)
1751 if (b
->pspace
== pspace
)
1752 delete_breakpoint (b
);
1755 /* Breakpoints set through other program spaces could have locations
1756 bound to PSPACE as well. Remove those. */
1757 ALL_BP_LOCATIONS (loc
, loc_temp
)
1759 struct bp_location
*tmp
;
1761 if (loc
->pspace
== pspace
)
1763 if (loc
->owner
->loc
== loc
)
1764 loc
->owner
->loc
= loc
->next
;
1766 for (tmp
= loc
->owner
->loc
; tmp
->next
!= NULL
; tmp
= tmp
->next
)
1767 if (tmp
->next
== loc
)
1769 tmp
->next
= loc
->next
;
1775 /* Now update the global location list to permanently delete the
1776 removed locations above. */
1777 update_global_location_list (0);
1780 /* Make sure all breakpoints are inserted in inferior.
1781 Throws exception on any error.
1782 A breakpoint that is already inserted won't be inserted
1783 again, so calling this function twice is safe. */
1785 insert_breakpoints (void)
1787 struct breakpoint
*bpt
;
1789 ALL_BREAKPOINTS (bpt
)
1790 if (is_hardware_watchpoint (bpt
))
1791 update_watchpoint (bpt
, 0 /* don't reparse. */);
1793 update_global_location_list (1);
1795 /* update_global_location_list does not insert breakpoints when
1796 always_inserted_mode is not enabled. Explicitly insert them
1798 if (!breakpoints_always_inserted_mode ())
1799 insert_breakpoint_locations ();
1802 /* insert_breakpoints is used when starting or continuing the program.
1803 remove_breakpoints is used when the program stops.
1804 Both return zero if successful,
1805 or an `errno' value if could not write the inferior. */
1808 insert_breakpoint_locations (void)
1810 struct breakpoint
*bpt
;
1811 struct bp_location
*b
, **bp_tmp
;
1814 int disabled_breaks
= 0;
1815 int hw_breakpoint_error
= 0;
1817 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1818 struct cleanup
*cleanups
= make_cleanup_ui_file_delete (tmp_error_stream
);
1820 /* Explicitly mark the warning -- this will only be printed if
1821 there was an error. */
1822 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1824 save_current_space_and_thread ();
1826 ALL_BP_LOCATIONS (b
, bp_tmp
)
1828 struct thread_info
*tp
;
1829 CORE_ADDR last_addr
;
1831 if (!should_be_inserted (b
) || b
->inserted
)
1834 /* There is no point inserting thread-specific breakpoints if the
1835 thread no longer exists. */
1836 if (b
->owner
->thread
!= -1
1837 && !valid_thread_id (b
->owner
->thread
))
1840 switch_to_program_space_and_thread (b
->pspace
);
1842 /* For targets that support global breakpoints, there's no need
1843 to select an inferior to insert breakpoint to. In fact, even
1844 if we aren't attached to any process yet, we should still
1845 insert breakpoints. */
1846 if (!gdbarch_has_global_breakpoints (target_gdbarch
)
1847 && ptid_equal (inferior_ptid
, null_ptid
))
1850 val
= insert_bp_location (b
, tmp_error_stream
,
1852 &hw_breakpoint_error
);
1857 /* If we failed to insert all locations of a watchpoint,
1858 remove them, as half-inserted watchpoint is of limited use. */
1859 ALL_BREAKPOINTS (bpt
)
1861 int some_failed
= 0;
1862 struct bp_location
*loc
;
1864 if (!is_hardware_watchpoint (bpt
))
1867 if (!breakpoint_enabled (bpt
))
1870 if (bpt
->disposition
== disp_del_at_next_stop
)
1873 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1874 if (!loc
->inserted
&& should_be_inserted (loc
))
1881 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1883 remove_breakpoint (loc
, mark_uninserted
);
1885 hw_breakpoint_error
= 1;
1886 fprintf_unfiltered (tmp_error_stream
,
1887 "Could not insert hardware watchpoint %d.\n",
1895 /* If a hardware breakpoint or watchpoint was inserted, add a
1896 message about possibly exhausted resources. */
1897 if (hw_breakpoint_error
)
1899 fprintf_unfiltered (tmp_error_stream
,
1900 "Could not insert hardware breakpoints:\n\
1901 You may have requested too many hardware breakpoints/watchpoints.\n");
1903 target_terminal_ours_for_output ();
1904 error_stream (tmp_error_stream
);
1907 do_cleanups (cleanups
);
1911 remove_breakpoints (void)
1913 struct bp_location
*b
, **bp_tmp
;
1916 ALL_BP_LOCATIONS (b
, bp_tmp
)
1919 val
|= remove_breakpoint (b
, mark_uninserted
);
1924 /* Remove breakpoints of process PID. */
1927 remove_breakpoints_pid (int pid
)
1929 struct bp_location
*b
, **b_tmp
;
1931 struct inferior
*inf
= find_inferior_pid (pid
);
1933 ALL_BP_LOCATIONS (b
, b_tmp
)
1935 if (b
->pspace
!= inf
->pspace
)
1940 val
= remove_breakpoint (b
, mark_uninserted
);
1949 remove_hw_watchpoints (void)
1951 struct bp_location
*b
, **bp_tmp
;
1954 ALL_BP_LOCATIONS (b
, bp_tmp
)
1956 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1957 val
|= remove_breakpoint (b
, mark_uninserted
);
1963 reattach_breakpoints (int pid
)
1965 struct cleanup
*old_chain
;
1966 struct bp_location
*b
, **bp_tmp
;
1968 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1969 int dummy1
= 0, dummy2
= 0;
1970 struct inferior
*inf
;
1971 struct thread_info
*tp
;
1973 tp
= any_live_thread_of_process (pid
);
1977 inf
= find_inferior_pid (pid
);
1978 old_chain
= save_inferior_ptid ();
1980 inferior_ptid
= tp
->ptid
;
1982 make_cleanup_ui_file_delete (tmp_error_stream
);
1984 ALL_BP_LOCATIONS (b
, bp_tmp
)
1986 if (b
->pspace
!= inf
->pspace
)
1992 val
= insert_bp_location (b
, tmp_error_stream
,
1996 do_cleanups (old_chain
);
2001 do_cleanups (old_chain
);
2005 static int internal_breakpoint_number
= -1;
2007 static struct breakpoint
*
2008 create_internal_breakpoint (struct gdbarch
*gdbarch
,
2009 CORE_ADDR address
, enum bptype type
)
2011 struct symtab_and_line sal
;
2012 struct breakpoint
*b
;
2014 init_sal (&sal
); /* initialize to zeroes */
2017 sal
.section
= find_pc_overlay (sal
.pc
);
2018 sal
.pspace
= current_program_space
;
2020 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
2021 b
->number
= internal_breakpoint_number
--;
2022 b
->disposition
= disp_donttouch
;
2028 create_overlay_event_breakpoint (char *func_name
)
2030 struct objfile
*objfile
;
2032 ALL_OBJFILES (objfile
)
2034 struct breakpoint
*b
;
2035 struct minimal_symbol
*m
;
2037 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2041 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2042 SYMBOL_VALUE_ADDRESS (m
),
2044 b
->addr_string
= xstrdup (func_name
);
2046 if (overlay_debugging
== ovly_auto
)
2048 b
->enable_state
= bp_enabled
;
2049 overlay_events_enabled
= 1;
2053 b
->enable_state
= bp_disabled
;
2054 overlay_events_enabled
= 0;
2057 update_global_location_list (1);
2061 create_longjmp_master_breakpoint (char *func_name
)
2063 struct program_space
*pspace
;
2064 struct objfile
*objfile
;
2065 struct cleanup
*old_chain
;
2067 old_chain
= save_current_program_space ();
2069 ALL_PSPACES (pspace
)
2070 ALL_OBJFILES (objfile
)
2072 struct breakpoint
*b
;
2073 struct minimal_symbol
*m
;
2075 if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile
)))
2078 set_current_program_space (pspace
);
2080 m
= lookup_minimal_symbol_text (func_name
, objfile
);
2084 b
= create_internal_breakpoint (get_objfile_arch (objfile
),
2085 SYMBOL_VALUE_ADDRESS (m
),
2087 b
->addr_string
= xstrdup (func_name
);
2088 b
->enable_state
= bp_disabled
;
2090 update_global_location_list (1);
2092 do_cleanups (old_chain
);
2096 update_breakpoints_after_exec (void)
2098 struct breakpoint
*b
;
2099 struct breakpoint
*temp
;
2100 struct bp_location
*bploc
, **bplocp_tmp
;
2102 /* We're about to delete breakpoints from GDB's lists. If the
2103 INSERTED flag is true, GDB will try to lift the breakpoints by
2104 writing the breakpoints' "shadow contents" back into memory. The
2105 "shadow contents" are NOT valid after an exec, so GDB should not
2106 do that. Instead, the target is responsible from marking
2107 breakpoints out as soon as it detects an exec. We don't do that
2108 here instead, because there may be other attempts to delete
2109 breakpoints after detecting an exec and before reaching here. */
2110 ALL_BP_LOCATIONS (bploc
, bplocp_tmp
)
2111 if (bploc
->pspace
== current_program_space
)
2112 gdb_assert (!bploc
->inserted
);
2114 ALL_BREAKPOINTS_SAFE (b
, temp
)
2116 if (b
->pspace
!= current_program_space
)
2119 /* Solib breakpoints must be explicitly reset after an exec(). */
2120 if (b
->type
== bp_shlib_event
)
2122 delete_breakpoint (b
);
2126 /* JIT breakpoints must be explicitly reset after an exec(). */
2127 if (b
->type
== bp_jit_event
)
2129 delete_breakpoint (b
);
2133 /* Thread event breakpoints must be set anew after an exec(),
2134 as must overlay event and longjmp master breakpoints. */
2135 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
2136 || b
->type
== bp_longjmp_master
)
2138 delete_breakpoint (b
);
2142 /* Step-resume breakpoints are meaningless after an exec(). */
2143 if (b
->type
== bp_step_resume
)
2145 delete_breakpoint (b
);
2149 /* Longjmp and longjmp-resume breakpoints are also meaningless
2151 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
2153 delete_breakpoint (b
);
2157 if (b
->type
== bp_catchpoint
)
2159 /* For now, none of the bp_catchpoint breakpoints need to
2160 do anything at this point. In the future, if some of
2161 the catchpoints need to something, we will need to add
2162 a new method, and call this method from here. */
2166 /* bp_finish is a special case. The only way we ought to be able
2167 to see one of these when an exec() has happened, is if the user
2168 caught a vfork, and then said "finish". Ordinarily a finish just
2169 carries them to the call-site of the current callee, by setting
2170 a temporary bp there and resuming. But in this case, the finish
2171 will carry them entirely through the vfork & exec.
2173 We don't want to allow a bp_finish to remain inserted now. But
2174 we can't safely delete it, 'cause finish_command has a handle to
2175 the bp on a bpstat, and will later want to delete it. There's a
2176 chance (and I've seen it happen) that if we delete the bp_finish
2177 here, that its storage will get reused by the time finish_command
2178 gets 'round to deleting the "use to be a bp_finish" breakpoint.
2179 We really must allow finish_command to delete a bp_finish.
2181 In the absense of a general solution for the "how do we know
2182 it's safe to delete something others may have handles to?"
2183 problem, what we'll do here is just uninsert the bp_finish, and
2184 let finish_command delete it.
2186 (We know the bp_finish is "doomed" in the sense that it's
2187 momentary, and will be deleted as soon as finish_command sees
2188 the inferior stopped. So it doesn't matter that the bp's
2189 address is probably bogus in the new a.out, unlike e.g., the
2190 solib breakpoints.) */
2192 if (b
->type
== bp_finish
)
2197 /* Without a symbolic address, we have little hope of the
2198 pre-exec() address meaning the same thing in the post-exec()
2200 if (b
->addr_string
== NULL
)
2202 delete_breakpoint (b
);
2206 /* FIXME what about longjmp breakpoints? Re-create them here? */
2207 create_overlay_event_breakpoint ("_ovly_debug_event");
2208 create_longjmp_master_breakpoint ("longjmp");
2209 create_longjmp_master_breakpoint ("_longjmp");
2210 create_longjmp_master_breakpoint ("siglongjmp");
2211 create_longjmp_master_breakpoint ("_siglongjmp");
2215 detach_breakpoints (int pid
)
2217 struct bp_location
*b
, **bp_tmp
;
2219 struct cleanup
*old_chain
= save_inferior_ptid ();
2220 struct inferior
*inf
= current_inferior ();
2222 if (pid
== PIDGET (inferior_ptid
))
2223 error (_("Cannot detach breakpoints of inferior_ptid"));
2225 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */
2226 inferior_ptid
= pid_to_ptid (pid
);
2227 ALL_BP_LOCATIONS (b
, bp_tmp
)
2229 if (b
->pspace
!= inf
->pspace
)
2233 val
|= remove_breakpoint_1 (b
, mark_inserted
);
2235 do_cleanups (old_chain
);
2239 /* Remove the breakpoint location B from the current address space.
2240 Note that this is used to detach breakpoints from a child fork.
2241 When we get here, the child isn't in the inferior list, and neither
2242 do we have objects to represent its address space --- we should
2243 *not* look at b->pspace->aspace here. */
2246 remove_breakpoint_1 (struct bp_location
*b
, insertion_state_t is
)
2249 struct cleanup
*old_chain
;
2251 if (b
->owner
->enable_state
== bp_permanent
)
2252 /* Permanent breakpoints cannot be inserted or removed. */
2255 /* The type of none suggests that owner is actually deleted.
2256 This should not ever happen. */
2257 gdb_assert (b
->owner
->type
!= bp_none
);
2259 if (b
->loc_type
== bp_loc_software_breakpoint
2260 || b
->loc_type
== bp_loc_hardware_breakpoint
)
2262 /* "Normal" instruction breakpoint: either the standard
2263 trap-instruction bp (bp_breakpoint), or a
2264 bp_hardware_breakpoint. */
2266 /* First check to see if we have to handle an overlay. */
2267 if (overlay_debugging
== ovly_off
2268 || b
->section
== NULL
2269 || !(section_is_overlay (b
->section
)))
2271 /* No overlay handling: just remove the breakpoint. */
2273 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2274 val
= target_remove_hw_breakpoint (b
->gdbarch
, &b
->target_info
);
2276 val
= target_remove_breakpoint (b
->gdbarch
, &b
->target_info
);
2280 /* This breakpoint is in an overlay section.
2281 Did we set a breakpoint at the LMA? */
2282 if (!overlay_events_enabled
)
2284 /* Yes -- overlay event support is not active, so we
2285 should have set a breakpoint at the LMA. Remove it.
2287 /* Ignore any failures: if the LMA is in ROM, we will
2288 have already warned when we failed to insert it. */
2289 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2290 target_remove_hw_breakpoint (b
->gdbarch
,
2291 &b
->overlay_target_info
);
2293 target_remove_breakpoint (b
->gdbarch
,
2294 &b
->overlay_target_info
);
2296 /* Did we set a breakpoint at the VMA?
2297 If so, we will have marked the breakpoint 'inserted'. */
2300 /* Yes -- remove it. Previously we did not bother to
2301 remove the breakpoint if the section had been
2302 unmapped, but let's not rely on that being safe. We
2303 don't know what the overlay manager might do. */
2304 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
2305 val
= target_remove_hw_breakpoint (b
->gdbarch
,
2308 /* However, we should remove *software* breakpoints only
2309 if the section is still mapped, or else we overwrite
2310 wrong code with the saved shadow contents. */
2311 else if (section_is_mapped (b
->section
))
2312 val
= target_remove_breakpoint (b
->gdbarch
,
2319 /* No -- not inserted, so no need to remove. No error. */
2324 /* In some cases, we might not be able to remove a breakpoint
2325 in a shared library that has already been removed, but we
2326 have not yet processed the shlib unload event. */
2327 if (val
&& solib_name_from_address (b
->pspace
, b
->address
))
2332 b
->inserted
= (is
== mark_inserted
);
2334 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
2339 b
->inserted
= (is
== mark_inserted
);
2340 val
= target_remove_watchpoint (b
->address
, b
->length
,
2341 b
->watchpoint_type
);
2343 /* Failure to remove any of the hardware watchpoints comes here. */
2344 if ((is
== mark_uninserted
) && (b
->inserted
))
2345 warning (_("Could not remove hardware watchpoint %d."),
2348 else if (b
->owner
->type
== bp_catchpoint
2349 && breakpoint_enabled (b
->owner
)
2352 gdb_assert (b
->owner
->ops
!= NULL
&& b
->owner
->ops
->remove
!= NULL
);
2354 val
= b
->owner
->ops
->remove (b
->owner
);
2357 b
->inserted
= (is
== mark_inserted
);
2364 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
2367 struct cleanup
*old_chain
;
2369 if (b
->owner
->enable_state
== bp_permanent
)
2370 /* Permanent breakpoints cannot be inserted or removed. */
2373 /* The type of none suggests that owner is actually deleted.
2374 This should not ever happen. */
2375 gdb_assert (b
->owner
->type
!= bp_none
);
2377 old_chain
= save_current_space_and_thread ();
2379 switch_to_program_space_and_thread (b
->pspace
);
2381 ret
= remove_breakpoint_1 (b
, is
);
2383 do_cleanups (old_chain
);
2387 /* Clear the "inserted" flag in all breakpoints. */
2390 mark_breakpoints_out (void)
2392 struct bp_location
*bpt
, **bptp_tmp
;
2394 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2395 if (bpt
->pspace
== current_program_space
)
2399 /* Clear the "inserted" flag in all breakpoints and delete any
2400 breakpoints which should go away between runs of the program.
2402 Plus other such housekeeping that has to be done for breakpoints
2405 Note: this function gets called at the end of a run (by
2406 generic_mourn_inferior) and when a run begins (by
2407 init_wait_for_inferior). */
2412 breakpoint_init_inferior (enum inf_context context
)
2414 struct breakpoint
*b
, *temp
;
2415 struct bp_location
*bpt
, **bptp_tmp
;
2417 struct program_space
*pspace
= current_program_space
;
2419 /* If breakpoint locations are shared across processes, then there's
2421 if (gdbarch_has_global_breakpoints (target_gdbarch
))
2424 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2426 if (bpt
->pspace
== pspace
2427 && bpt
->owner
->enable_state
!= bp_permanent
)
2431 ALL_BREAKPOINTS_SAFE (b
, temp
)
2433 if (b
->loc
&& b
->loc
->pspace
!= pspace
)
2440 /* If the call dummy breakpoint is at the entry point it will
2441 cause problems when the inferior is rerun, so we better get
2444 case bp_watchpoint_scope
:
2446 /* Also get rid of scope breakpoints. */
2448 case bp_shlib_event
:
2450 /* Also remove solib event breakpoints. Their addresses may
2451 have changed since the last time we ran the program.
2452 Actually we may now be debugging against different target;
2453 and so the solib backend that installed this breakpoint may
2454 not be used in by the target. E.g.,
2456 (gdb) file prog-linux
2457 (gdb) run # native linux target
2460 (gdb) file prog-win.exe
2461 (gdb) tar rem :9999 # remote Windows gdbserver.
2464 delete_breakpoint (b
);
2468 case bp_hardware_watchpoint
:
2469 case bp_read_watchpoint
:
2470 case bp_access_watchpoint
:
2472 /* Likewise for watchpoints on local expressions. */
2473 if (b
->exp_valid_block
!= NULL
)
2474 delete_breakpoint (b
);
2475 else if (context
== inf_starting
)
2477 /* Reset val field to force reread of starting value
2478 in insert_breakpoints. */
2480 value_free (b
->val
);
2490 /* Get rid of the moribund locations. */
2491 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, bpt
); ++ix
)
2492 free_bp_location (bpt
);
2493 VEC_free (bp_location_p
, moribund_locations
);
2496 /* These functions concern about actual breakpoints inserted in the
2497 target --- to e.g. check if we need to do decr_pc adjustment or if
2498 we need to hop over the bkpt --- so we check for address space
2499 match, not program space. */
2501 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
2502 exists at PC. It returns ordinary_breakpoint_here if it's an
2503 ordinary breakpoint, or permanent_breakpoint_here if it's a
2504 permanent breakpoint.
2505 - When continuing from a location with an ordinary breakpoint, we
2506 actually single step once before calling insert_breakpoints.
2507 - When continuing from a localion with a permanent breakpoint, we
2508 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
2509 the target, to advance the PC past the breakpoint. */
2511 enum breakpoint_here
2512 breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2514 struct bp_location
*bpt
, **bptp_tmp
;
2515 int any_breakpoint_here
= 0;
2517 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2519 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2520 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2523 if ((breakpoint_enabled (bpt
->owner
)
2524 || bpt
->owner
->enable_state
== bp_permanent
)
2525 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2528 if (overlay_debugging
2529 && section_is_overlay (bpt
->section
)
2530 && !section_is_mapped (bpt
->section
))
2531 continue; /* unmapped overlay -- can't be a match */
2532 else if (bpt
->owner
->enable_state
== bp_permanent
)
2533 return permanent_breakpoint_here
;
2535 any_breakpoint_here
= 1;
2539 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
2542 /* Return true if there's a moribund breakpoint at PC. */
2545 moribund_breakpoint_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2547 struct bp_location
*loc
;
2550 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
2551 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
2558 /* Returns non-zero if there's a breakpoint inserted at PC, which is
2559 inserted using regular breakpoint_chain / bp_location array mechanism.
2560 This does not check for single-step breakpoints, which are
2561 inserted and removed using direct target manipulation. */
2564 regular_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2566 struct bp_location
*bpt
, **bptp_tmp
;
2568 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2570 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2571 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2575 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2578 if (overlay_debugging
2579 && section_is_overlay (bpt
->section
)
2580 && !section_is_mapped (bpt
->section
))
2581 continue; /* unmapped overlay -- can't be a match */
2589 /* Returns non-zero iff there's either regular breakpoint
2590 or a single step breakpoint inserted at PC. */
2593 breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2595 if (regular_breakpoint_inserted_here_p (aspace
, pc
))
2598 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2604 /* This function returns non-zero iff there is a software breakpoint
2608 software_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
2610 struct bp_location
*bpt
, **bptp_tmp
;
2611 int any_breakpoint_here
= 0;
2613 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2615 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
2619 && breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2622 if (overlay_debugging
2623 && section_is_overlay (bpt
->section
)
2624 && !section_is_mapped (bpt
->section
))
2625 continue; /* unmapped overlay -- can't be a match */
2631 /* Also check for software single-step breakpoints. */
2632 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
2639 hardware_watchpoint_inserted_in_range (struct address_space
*aspace
,
2640 CORE_ADDR addr
, ULONGEST len
)
2642 struct breakpoint
*bpt
;
2644 ALL_BREAKPOINTS (bpt
)
2646 struct bp_location
*loc
;
2648 if (bpt
->type
!= bp_hardware_watchpoint
2649 && bpt
->type
!= bp_access_watchpoint
)
2652 if (!breakpoint_enabled (bpt
))
2655 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
2656 if (loc
->pspace
->aspace
== aspace
&& loc
->inserted
)
2660 /* Check for intersection. */
2661 l
= max (loc
->address
, addr
);
2662 h
= min (loc
->address
+ loc
->length
, addr
+ len
);
2670 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
2671 PC is valid for process/thread PTID. */
2674 breakpoint_thread_match (struct address_space
*aspace
, CORE_ADDR pc
,
2677 struct bp_location
*bpt
, **bptp_tmp
;
2678 /* The thread and task IDs associated to PTID, computed lazily. */
2682 ALL_BP_LOCATIONS (bpt
, bptp_tmp
)
2684 if (bpt
->loc_type
!= bp_loc_software_breakpoint
2685 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
2688 if (!breakpoint_enabled (bpt
->owner
)
2689 && bpt
->owner
->enable_state
!= bp_permanent
)
2692 if (!breakpoint_address_match (bpt
->pspace
->aspace
, bpt
->address
,
2696 if (bpt
->owner
->thread
!= -1)
2698 /* This is a thread-specific breakpoint. Check that ptid
2699 matches that thread. If thread hasn't been computed yet,
2700 it is now time to do so. */
2702 thread
= pid_to_thread_id (ptid
);
2703 if (bpt
->owner
->thread
!= thread
)
2707 if (bpt
->owner
->task
!= 0)
2709 /* This is a task-specific breakpoint. Check that ptid
2710 matches that task. If task hasn't been computed yet,
2711 it is now time to do so. */
2713 task
= ada_get_task_number (ptid
);
2714 if (bpt
->owner
->task
!= task
)
2718 if (overlay_debugging
2719 && section_is_overlay (bpt
->section
)
2720 && !section_is_mapped (bpt
->section
))
2721 continue; /* unmapped overlay -- can't be a match */
2730 /* bpstat stuff. External routines' interfaces are documented
2734 ep_is_catchpoint (struct breakpoint
*ep
)
2736 return (ep
->type
== bp_catchpoint
);
2740 bpstat_free (bpstat bs
)
2742 if (bs
->old_val
!= NULL
)
2743 value_free (bs
->old_val
);
2744 decref_counted_command_line (&bs
->commands
);
2748 /* Clear a bpstat so that it says we are not at any breakpoint.
2749 Also free any storage that is part of a bpstat. */
2752 bpstat_clear (bpstat
*bsp
)
2769 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
2770 is part of the bpstat is copied as well. */
2773 bpstat_copy (bpstat bs
)
2777 bpstat retval
= NULL
;
2782 for (; bs
!= NULL
; bs
= bs
->next
)
2784 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2785 memcpy (tmp
, bs
, sizeof (*tmp
));
2786 incref_counted_command_line (tmp
->commands
);
2787 if (bs
->old_val
!= NULL
)
2789 tmp
->old_val
= value_copy (bs
->old_val
);
2790 release_value (tmp
->old_val
);
2794 /* This is the first thing in the chain. */
2804 /* Find the bpstat associated with this breakpoint */
2807 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2812 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2814 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2820 /* Find a step_resume breakpoint associated with this bpstat.
2821 (If there are multiple step_resume bp's on the list, this function
2822 will arbitrarily pick one.)
2824 It is an error to use this function if BPSTAT doesn't contain a
2825 step_resume breakpoint.
2827 See wait_for_inferior's use of this function. */
2829 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2833 gdb_assert (bsp
!= NULL
);
2835 current_thread
= pid_to_thread_id (inferior_ptid
);
2837 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2839 if ((bsp
->breakpoint_at
!= NULL
)
2840 && (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
)
2841 && (bsp
->breakpoint_at
->owner
->thread
== current_thread
2842 || bsp
->breakpoint_at
->owner
->thread
== -1))
2843 return bsp
->breakpoint_at
->owner
;
2846 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2850 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2851 at. *BSP upon return is a bpstat which points to the remaining
2852 breakpoints stopped at (but which is not guaranteed to be good for
2853 anything but further calls to bpstat_num).
2854 Return 0 if passed a bpstat which does not indicate any breakpoints.
2855 Return -1 if stopped at a breakpoint that has been deleted since
2857 Return 1 otherwise. */
2860 bpstat_num (bpstat
*bsp
, int *num
)
2862 struct breakpoint
*b
;
2865 return 0; /* No more breakpoint values */
2867 /* We assume we'll never have several bpstats that
2868 correspond to a single breakpoint -- otherwise,
2869 this function might return the same number more
2870 than once and this will look ugly. */
2871 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2872 *bsp
= (*bsp
)->next
;
2874 return -1; /* breakpoint that's been deleted since */
2876 *num
= b
->number
; /* We have its number */
2880 /* Modify BS so that the actions will not be performed. */
2883 bpstat_clear_actions (bpstat bs
)
2885 for (; bs
!= NULL
; bs
= bs
->next
)
2887 decref_counted_command_line (&bs
->commands
);
2888 if (bs
->old_val
!= NULL
)
2890 value_free (bs
->old_val
);
2896 /* Called when a command is about to proceed the inferior. */
2899 breakpoint_about_to_proceed (void)
2901 if (!ptid_equal (inferior_ptid
, null_ptid
))
2903 struct thread_info
*tp
= inferior_thread ();
2905 /* Allow inferior function calls in breakpoint commands to not
2906 interrupt the command list. When the call finishes
2907 successfully, the inferior will be standing at the same
2908 breakpoint as if nothing happened. */
2913 breakpoint_proceeded
= 1;
2916 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2918 cleanup_executing_breakpoints (void *ignore
)
2920 executing_breakpoint_commands
= 0;
2923 /* Execute all the commands associated with all the breakpoints at this
2924 location. Any of these commands could cause the process to proceed
2925 beyond this point, etc. We look out for such changes by checking
2926 the global "breakpoint_proceeded" after each command.
2928 Returns true if a breakpoint command resumed the inferior. In that
2929 case, it is the caller's responsibility to recall it again with the
2930 bpstat of the current thread. */
2933 bpstat_do_actions_1 (bpstat
*bsp
)
2936 struct cleanup
*old_chain
;
2939 /* Avoid endless recursion if a `source' command is contained
2941 if (executing_breakpoint_commands
)
2944 executing_breakpoint_commands
= 1;
2945 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2947 /* This pointer will iterate over the list of bpstat's. */
2950 breakpoint_proceeded
= 0;
2951 for (; bs
!= NULL
; bs
= bs
->next
)
2953 struct counted_command_line
*ccmd
;
2954 struct command_line
*cmd
;
2955 struct cleanup
*this_cmd_tree_chain
;
2957 /* Take ownership of the BSP's command tree, if it has one.
2959 The command tree could legitimately contain commands like
2960 'step' and 'next', which call clear_proceed_status, which
2961 frees stop_bpstat's command tree. To make sure this doesn't
2962 free the tree we're executing out from under us, we need to
2963 take ownership of the tree ourselves. Since a given bpstat's
2964 commands are only executed once, we don't need to copy it; we
2965 can clear the pointer in the bpstat, and make sure we free
2966 the tree when we're done. */
2967 ccmd
= bs
->commands
;
2968 bs
->commands
= NULL
;
2970 = make_cleanup_decref_counted_command_line (&ccmd
);
2971 cmd
= bs
->commands_left
;
2972 bs
->commands_left
= NULL
;
2976 execute_control_command (cmd
);
2978 if (breakpoint_proceeded
)
2984 /* We can free this command tree now. */
2985 do_cleanups (this_cmd_tree_chain
);
2987 if (breakpoint_proceeded
)
2989 if (target_can_async_p ())
2990 /* If we are in async mode, then the target might be still
2991 running, not stopped at any breakpoint, so nothing for
2992 us to do here -- just return to the event loop. */
2995 /* In sync mode, when execute_control_command returns
2996 we're already standing on the next breakpoint.
2997 Breakpoint commands for that stop were not run, since
2998 execute_command does not run breakpoint commands --
2999 only command_line_handler does, but that one is not
3000 involved in execution of breakpoint commands. So, we
3001 can now execute breakpoint commands. It should be
3002 noted that making execute_command do bpstat actions is
3003 not an option -- in this case we'll have recursive
3004 invocation of bpstat for each breakpoint with a
3005 command, and can easily blow up GDB stack. Instead, we
3006 return true, which will trigger the caller to recall us
3007 with the new stop_bpstat. */
3012 do_cleanups (old_chain
);
3017 bpstat_do_actions (void)
3019 /* Do any commands attached to breakpoint we are stopped at. */
3020 while (!ptid_equal (inferior_ptid
, null_ptid
)
3021 && target_has_execution
3022 && !is_exited (inferior_ptid
)
3023 && !is_executing (inferior_ptid
))
3024 /* Since in sync mode, bpstat_do_actions may resume the inferior,
3025 and only return when it is stopped at the next breakpoint, we
3026 keep doing breakpoint actions until it returns false to
3027 indicate the inferior was not resumed. */
3028 if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat
))
3032 /* Print out the (old or new) value associated with a watchpoint. */
3035 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
3038 fprintf_unfiltered (stream
, _("<unreadable>"));
3041 struct value_print_options opts
;
3042 get_user_print_options (&opts
);
3043 value_print (val
, stream
, &opts
);
3047 /* This is the normal print function for a bpstat. In the future,
3048 much of this logic could (should?) be moved to bpstat_stop_status,
3049 by having it set different print_it values.
3051 Current scheme: When we stop, bpstat_print() is called. It loops
3052 through the bpstat list of things causing this stop, calling the
3053 print_bp_stop_message function on each one. The behavior of the
3054 print_bp_stop_message function depends on the print_it field of
3055 bpstat. If such field so indicates, call this function here.
3057 Return values from this routine (ultimately used by bpstat_print()
3058 and normal_stop() to decide what to do):
3059 PRINT_NOTHING: Means we already printed all we needed to print,
3060 don't print anything else.
3061 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
3062 that something to be followed by a location.
3063 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
3064 that something to be followed by a location.
3065 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
3068 static enum print_stop_action
3069 print_it_typical (bpstat bs
)
3071 struct cleanup
*old_chain
;
3072 struct breakpoint
*b
;
3073 const struct bp_location
*bl
;
3074 struct ui_stream
*stb
;
3076 enum print_stop_action result
;
3078 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
3079 which has since been deleted. */
3080 if (bs
->breakpoint_at
== NULL
)
3081 return PRINT_UNKNOWN
;
3082 bl
= bs
->breakpoint_at
;
3085 stb
= ui_out_stream_new (uiout
);
3086 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3091 case bp_hardware_breakpoint
:
3092 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
3093 if (bl
->address
!= bl
->requested_address
)
3094 breakpoint_adjustment_warning (bl
->requested_address
,
3097 annotate_breakpoint (b
->number
);
3099 ui_out_text (uiout
, "\nTemporary breakpoint ");
3101 ui_out_text (uiout
, "\nBreakpoint ");
3102 if (ui_out_is_mi_like_p (uiout
))
3104 ui_out_field_string (uiout
, "reason",
3105 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
3106 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3108 ui_out_field_int (uiout
, "bkptno", b
->number
);
3109 ui_out_text (uiout
, ", ");
3110 result
= PRINT_SRC_AND_LOC
;
3113 case bp_shlib_event
:
3114 /* Did we stop because the user set the stop_on_solib_events
3115 variable? (If so, we report this as a generic, "Stopped due
3116 to shlib event" message.) */
3117 printf_filtered (_("Stopped due to shared library event\n"));
3118 result
= PRINT_NOTHING
;
3121 case bp_thread_event
:
3122 /* Not sure how we will get here.
3123 GDB should not stop for these breakpoints. */
3124 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
3125 result
= PRINT_NOTHING
;
3128 case bp_overlay_event
:
3129 /* By analogy with the thread event, GDB should not stop for these. */
3130 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
3131 result
= PRINT_NOTHING
;
3134 case bp_longjmp_master
:
3135 /* These should never be enabled. */
3136 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n"));
3137 result
= PRINT_NOTHING
;
3141 case bp_hardware_watchpoint
:
3142 annotate_watchpoint (b
->number
);
3143 if (ui_out_is_mi_like_p (uiout
))
3146 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
3148 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3149 ui_out_text (uiout
, "\nOld value = ");
3150 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3151 ui_out_field_stream (uiout
, "old", stb
);
3152 ui_out_text (uiout
, "\nNew value = ");
3153 watchpoint_value_print (b
->val
, stb
->stream
);
3154 ui_out_field_stream (uiout
, "new", stb
);
3155 ui_out_text (uiout
, "\n");
3156 /* More than one watchpoint may have been triggered. */
3157 result
= PRINT_UNKNOWN
;
3160 case bp_read_watchpoint
:
3161 if (ui_out_is_mi_like_p (uiout
))
3164 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
3166 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3167 ui_out_text (uiout
, "\nValue = ");
3168 watchpoint_value_print (b
->val
, stb
->stream
);
3169 ui_out_field_stream (uiout
, "value", stb
);
3170 ui_out_text (uiout
, "\n");
3171 result
= PRINT_UNKNOWN
;
3174 case bp_access_watchpoint
:
3175 if (bs
->old_val
!= NULL
)
3177 annotate_watchpoint (b
->number
);
3178 if (ui_out_is_mi_like_p (uiout
))
3181 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3183 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3184 ui_out_text (uiout
, "\nOld value = ");
3185 watchpoint_value_print (bs
->old_val
, stb
->stream
);
3186 ui_out_field_stream (uiout
, "old", stb
);
3187 ui_out_text (uiout
, "\nNew value = ");
3192 if (ui_out_is_mi_like_p (uiout
))
3195 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
3196 make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
3197 ui_out_text (uiout
, "\nValue = ");
3199 watchpoint_value_print (b
->val
, stb
->stream
);
3200 ui_out_field_stream (uiout
, "new", stb
);
3201 ui_out_text (uiout
, "\n");
3202 result
= PRINT_UNKNOWN
;
3205 /* Fall through, we don't deal with these types of breakpoints
3209 if (ui_out_is_mi_like_p (uiout
))
3212 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
3213 result
= PRINT_UNKNOWN
;
3217 if (ui_out_is_mi_like_p (uiout
))
3220 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
3221 result
= PRINT_UNKNOWN
;
3226 case bp_longjmp_resume
:
3227 case bp_step_resume
:
3228 case bp_watchpoint_scope
:
3231 case bp_fast_tracepoint
:
3234 result
= PRINT_UNKNOWN
;
3238 do_cleanups (old_chain
);
3242 /* Generic routine for printing messages indicating why we
3243 stopped. The behavior of this function depends on the value
3244 'print_it' in the bpstat structure. Under some circumstances we
3245 may decide not to print anything here and delegate the task to
3248 static enum print_stop_action
3249 print_bp_stop_message (bpstat bs
)
3251 switch (bs
->print_it
)
3254 /* Nothing should be printed for this bpstat entry. */
3255 return PRINT_UNKNOWN
;
3259 /* We still want to print the frame, but we already printed the
3260 relevant messages. */
3261 return PRINT_SRC_AND_LOC
;
3264 case print_it_normal
:
3266 const struct bp_location
*bl
= bs
->breakpoint_at
;
3267 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
3269 /* Normal case. Call the breakpoint's print_it method, or
3270 print_it_typical. */
3271 /* FIXME: how breakpoint can ever be NULL here? */
3272 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
3273 return b
->ops
->print_it (b
);
3275 return print_it_typical (bs
);
3280 internal_error (__FILE__
, __LINE__
,
3281 _("print_bp_stop_message: unrecognized enum value"));
3286 /* Print a message indicating what happened. This is called from
3287 normal_stop(). The input to this routine is the head of the bpstat
3288 list - a list of the eventpoints that caused this stop. This
3289 routine calls the generic print routine for printing a message
3290 about reasons for stopping. This will print (for example) the
3291 "Breakpoint n," part of the output. The return value of this
3294 PRINT_UNKNOWN: Means we printed nothing
3295 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
3296 code to print the location. An example is
3297 "Breakpoint 1, " which should be followed by
3299 PRINT_SRC_ONLY: Means we printed something, but there is no need
3300 to also print the location part of the message.
3301 An example is the catch/throw messages, which
3302 don't require a location appended to the end.
3303 PRINT_NOTHING: We have done some printing and we don't need any
3304 further info to be printed.*/
3306 enum print_stop_action
3307 bpstat_print (bpstat bs
)
3311 /* Maybe another breakpoint in the chain caused us to stop.
3312 (Currently all watchpoints go on the bpstat whether hit or not.
3313 That probably could (should) be changed, provided care is taken
3314 with respect to bpstat_explains_signal). */
3315 for (; bs
; bs
= bs
->next
)
3317 val
= print_bp_stop_message (bs
);
3318 if (val
== PRINT_SRC_ONLY
3319 || val
== PRINT_SRC_AND_LOC
3320 || val
== PRINT_NOTHING
)
3324 /* We reached the end of the chain, or we got a null BS to start
3325 with and nothing was printed. */
3326 return PRINT_UNKNOWN
;
3329 /* Evaluate the expression EXP and return 1 if value is zero.
3330 This is used inside a catch_errors to evaluate the breakpoint condition.
3331 The argument is a "struct expression *" that has been cast to char * to
3332 make it pass through catch_errors. */
3335 breakpoint_cond_eval (void *exp
)
3337 struct value
*mark
= value_mark ();
3338 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
3339 value_free_to_mark (mark
);
3343 /* Allocate a new bpstat and chain it to the current one. */
3346 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
3350 bs
= (bpstat
) xmalloc (sizeof (*bs
));
3352 bs
->breakpoint_at
= bl
;
3353 /* If the condition is false, etc., don't do the commands. */
3354 bs
->commands
= NULL
;
3355 bs
->commands_left
= NULL
;
3357 bs
->print_it
= print_it_normal
;
3361 /* The target has stopped with waitstatus WS. Check if any hardware
3362 watchpoints have triggered, according to the target. */
3365 watchpoints_triggered (struct target_waitstatus
*ws
)
3367 int stopped_by_watchpoint
= target_stopped_by_watchpoint ();
3369 struct breakpoint
*b
;
3371 if (!stopped_by_watchpoint
)
3373 /* We were not stopped by a watchpoint. Mark all watchpoints
3374 as not triggered. */
3376 if (b
->type
== bp_hardware_watchpoint
3377 || b
->type
== bp_read_watchpoint
3378 || b
->type
== bp_access_watchpoint
)
3379 b
->watchpoint_triggered
= watch_triggered_no
;
3384 if (!target_stopped_data_address (¤t_target
, &addr
))
3386 /* We were stopped by a watchpoint, but we don't know where.
3387 Mark all watchpoints as unknown. */
3389 if (b
->type
== bp_hardware_watchpoint
3390 || b
->type
== bp_read_watchpoint
3391 || b
->type
== bp_access_watchpoint
)
3392 b
->watchpoint_triggered
= watch_triggered_unknown
;
3394 return stopped_by_watchpoint
;
3397 /* The target could report the data address. Mark watchpoints
3398 affected by this data address as triggered, and all others as not
3402 if (b
->type
== bp_hardware_watchpoint
3403 || b
->type
== bp_read_watchpoint
3404 || b
->type
== bp_access_watchpoint
)
3406 struct bp_location
*loc
;
3409 b
->watchpoint_triggered
= watch_triggered_no
;
3410 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3411 /* Exact match not required. Within range is
3413 if (target_watchpoint_addr_within_range (¤t_target
,
3417 b
->watchpoint_triggered
= watch_triggered_yes
;
3425 /* Possible return values for watchpoint_check (this can't be an enum
3426 because of check_errors). */
3427 /* The watchpoint has been deleted. */
3428 #define WP_DELETED 1
3429 /* The value has changed. */
3430 #define WP_VALUE_CHANGED 2
3431 /* The value has not changed. */
3432 #define WP_VALUE_NOT_CHANGED 3
3433 /* Ignore this watchpoint, no matter if the value changed or not. */
3436 #define BP_TEMPFLAG 1
3437 #define BP_HARDWAREFLAG 2
3439 /* Evaluate watchpoint condition expression and check if its value changed.
3441 P should be a pointer to struct bpstat, but is defined as a void *
3442 in order for this function to be usable with catch_errors. */
3445 watchpoint_check (void *p
)
3447 bpstat bs
= (bpstat
) p
;
3448 struct breakpoint
*b
;
3449 struct frame_info
*fr
;
3450 int within_current_scope
;
3452 b
= bs
->breakpoint_at
->owner
;
3454 /* If this is a local watchpoint, we only want to check if the
3455 watchpoint frame is in scope if the current thread is the thread
3456 that was used to create the watchpoint. */
3457 if (!watchpoint_in_thread_scope (b
))
3460 if (b
->exp_valid_block
== NULL
)
3461 within_current_scope
= 1;
3464 struct frame_info
*frame
= get_current_frame ();
3465 struct gdbarch
*frame_arch
= get_frame_arch (frame
);
3466 CORE_ADDR frame_pc
= get_frame_pc (frame
);
3468 /* in_function_epilogue_p() returns a non-zero value if we're still
3469 in the function but the stack frame has already been invalidated.
3470 Since we can't rely on the values of local variables after the
3471 stack has been destroyed, we are treating the watchpoint in that
3472 state as `not changed' without further checking. Don't mark
3473 watchpoints as changed if the current frame is in an epilogue -
3474 even if they are in some other frame, our view of the stack
3475 is likely to be wrong and frame_find_by_id could error out. */
3476 if (gdbarch_in_function_epilogue_p (frame_arch
, frame_pc
))
3479 fr
= frame_find_by_id (b
->watchpoint_frame
);
3480 within_current_scope
= (fr
!= NULL
);
3482 /* If we've gotten confused in the unwinder, we might have
3483 returned a frame that can't describe this variable. */
3484 if (within_current_scope
)
3486 struct symbol
*function
;
3488 function
= get_frame_function (fr
);
3489 if (function
== NULL
3490 || !contained_in (b
->exp_valid_block
,
3491 SYMBOL_BLOCK_VALUE (function
)))
3492 within_current_scope
= 0;
3495 if (within_current_scope
)
3496 /* If we end up stopping, the current frame will get selected
3497 in normal_stop. So this call to select_frame won't affect
3502 if (within_current_scope
)
3504 /* We use value_{,free_to_}mark because it could be a
3505 *long* time before we return to the command level and
3506 call free_all_values. We can't call free_all_values because
3507 we might be in the middle of evaluating a function call. */
3509 struct value
*mark
= value_mark ();
3510 struct value
*new_val
;
3512 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
3514 /* We use value_equal_contents instead of value_equal because the latter
3515 coerces an array to a pointer, thus comparing just the address of the
3516 array instead of its contents. This is not what we want. */
3517 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
3518 || (b
->val
!= NULL
&& !value_equal_contents (b
->val
, new_val
)))
3520 if (new_val
!= NULL
)
3522 release_value (new_val
);
3523 value_free_to_mark (mark
);
3525 bs
->old_val
= b
->val
;
3528 return WP_VALUE_CHANGED
;
3532 /* Nothing changed. */
3533 value_free_to_mark (mark
);
3534 return WP_VALUE_NOT_CHANGED
;
3539 /* This seems like the only logical thing to do because
3540 if we temporarily ignored the watchpoint, then when
3541 we reenter the block in which it is valid it contains
3542 garbage (in the case of a function, it may have two
3543 garbage values, one before and one after the prologue).
3544 So we can't even detect the first assignment to it and
3545 watch after that (since the garbage may or may not equal
3546 the first value assigned). */
3547 /* We print all the stop information in print_it_typical(), but
3548 in this case, by the time we call print_it_typical() this bp
3549 will be deleted already. So we have no choice but print the
3550 information here. */
3551 if (ui_out_is_mi_like_p (uiout
))
3553 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
3554 ui_out_text (uiout
, "\nWatchpoint ");
3555 ui_out_field_int (uiout
, "wpnum", b
->number
);
3556 ui_out_text (uiout
, " deleted because the program has left the block in\n\
3557 which its expression is valid.\n");
3559 if (b
->related_breakpoint
)
3561 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3562 b
->related_breakpoint
->related_breakpoint
= NULL
;
3563 b
->related_breakpoint
= NULL
;
3565 b
->disposition
= disp_del_at_next_stop
;
3571 /* Return true if it looks like target has stopped due to hitting
3572 breakpoint location BL. This function does not check if we
3573 should stop, only if BL explains the stop. */
3575 bpstat_check_location (const struct bp_location
*bl
,
3576 struct address_space
*aspace
, CORE_ADDR bp_addr
)
3578 struct breakpoint
*b
= bl
->owner
;
3580 /* By definition, the inferior does not report stops at
3582 if (tracepoint_type (b
))
3585 if (b
->type
!= bp_watchpoint
3586 && b
->type
!= bp_hardware_watchpoint
3587 && b
->type
!= bp_read_watchpoint
3588 && b
->type
!= bp_access_watchpoint
3589 && b
->type
!= bp_hardware_breakpoint
3590 && b
->type
!= bp_catchpoint
) /* a non-watchpoint bp */
3592 if (!breakpoint_address_match (bl
->pspace
->aspace
, bl
->address
,
3595 if (overlay_debugging
/* unmapped overlay section */
3596 && section_is_overlay (bl
->section
)
3597 && !section_is_mapped (bl
->section
))
3601 /* Continuable hardware watchpoints are treated as non-existent if the
3602 reason we stopped wasn't a hardware watchpoint (we didn't stop on
3603 some data address). Otherwise gdb won't stop on a break instruction
3604 in the code (not from a breakpoint) when a hardware watchpoint has
3605 been defined. Also skip watchpoints which we know did not trigger
3606 (did not match the data address). */
3608 if ((b
->type
== bp_hardware_watchpoint
3609 || b
->type
== bp_read_watchpoint
3610 || b
->type
== bp_access_watchpoint
)
3611 && b
->watchpoint_triggered
== watch_triggered_no
)
3614 if (b
->type
== bp_hardware_breakpoint
)
3616 if (bl
->address
!= bp_addr
)
3618 if (overlay_debugging
/* unmapped overlay section */
3619 && section_is_overlay (bl
->section
)
3620 && !section_is_mapped (bl
->section
))
3624 if (b
->type
== bp_catchpoint
)
3626 gdb_assert (b
->ops
!= NULL
&& b
->ops
->breakpoint_hit
!= NULL
);
3627 if (!b
->ops
->breakpoint_hit (b
))
3634 /* If BS refers to a watchpoint, determine if the watched values
3635 has actually changed, and we should stop. If not, set BS->stop
3638 bpstat_check_watchpoint (bpstat bs
)
3640 const struct bp_location
*bl
= bs
->breakpoint_at
;
3641 struct breakpoint
*b
= bl
->owner
;
3643 if (b
->type
== bp_watchpoint
3644 || b
->type
== bp_read_watchpoint
3645 || b
->type
== bp_access_watchpoint
3646 || b
->type
== bp_hardware_watchpoint
)
3650 int must_check_value
= 0;
3652 if (b
->type
== bp_watchpoint
)
3653 /* For a software watchpoint, we must always check the
3655 must_check_value
= 1;
3656 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
3657 /* We have a hardware watchpoint (read, write, or access)
3658 and the target earlier reported an address watched by
3660 must_check_value
= 1;
3661 else if (b
->watchpoint_triggered
== watch_triggered_unknown
3662 && b
->type
== bp_hardware_watchpoint
)
3663 /* We were stopped by a hardware watchpoint, but the target could
3664 not report the data address. We must check the watchpoint's
3665 value. Access and read watchpoints are out of luck; without
3666 a data address, we can't figure it out. */
3667 must_check_value
= 1;
3669 if (must_check_value
)
3671 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
3673 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
3674 int e
= catch_errors (watchpoint_check
, bs
, message
,
3676 do_cleanups (cleanups
);
3680 /* We've already printed what needs to be printed. */
3681 bs
->print_it
= print_it_done
;
3685 bs
->print_it
= print_it_noop
;
3688 case WP_VALUE_CHANGED
:
3689 if (b
->type
== bp_read_watchpoint
)
3691 /* There are two cases to consider here:
3693 1. we're watching the triggered memory for reads.
3694 In that case, trust the target, and always report
3695 the watchpoint hit to the user. Even though
3696 reads don't cause value changes, the value may
3697 have changed since the last time it was read, and
3698 since we're not trapping writes, we will not see
3699 those, and as such we should ignore our notion of
3702 2. we're watching the triggered memory for both
3703 reads and writes. There are two ways this may
3706 2.1. this is a target that can't break on data
3707 reads only, but can break on accesses (reads or
3708 writes), such as e.g., x86. We detect this case
3709 at the time we try to insert read watchpoints.
3711 2.2. otherwise, the target supports read
3712 watchpoints, but, the user set an access or write
3713 watchpoint watching the same memory as this read
3716 If we're watching memory writes as well as reads,
3717 ignore watchpoint hits when we find that the
3718 value hasn't changed, as reads don't cause
3719 changes. This still gives false positives when
3720 the program writes the same value to memory as
3721 what there was already in memory (we will confuse
3722 it for a read), but it's much better than
3725 int other_write_watchpoint
= 0;
3727 if (bl
->watchpoint_type
== hw_read
)
3729 struct breakpoint
*other_b
;
3731 ALL_BREAKPOINTS (other_b
)
3732 if ((other_b
->type
== bp_hardware_watchpoint
3733 || other_b
->type
== bp_access_watchpoint
)
3734 && (other_b
->watchpoint_triggered
3735 == watch_triggered_yes
))
3737 other_write_watchpoint
= 1;
3742 if (other_write_watchpoint
3743 || bl
->watchpoint_type
== hw_access
)
3745 /* We're watching the same memory for writes,
3746 and the value changed since the last time we
3747 updated it, so this trap must be for a write.
3749 bs
->print_it
= print_it_noop
;
3754 case WP_VALUE_NOT_CHANGED
:
3755 if (b
->type
== bp_hardware_watchpoint
3756 || b
->type
== bp_watchpoint
)
3758 /* Don't stop: write watchpoints shouldn't fire if
3759 the value hasn't changed. */
3760 bs
->print_it
= print_it_noop
;
3768 /* Error from catch_errors. */
3769 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
3770 if (b
->related_breakpoint
)
3771 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
3772 b
->disposition
= disp_del_at_next_stop
;
3773 /* We've already printed what needs to be printed. */
3774 bs
->print_it
= print_it_done
;
3778 else /* must_check_value == 0 */
3780 /* This is a case where some watchpoint(s) triggered, but
3781 not at the address of this watchpoint, or else no
3782 watchpoint triggered after all. So don't print
3783 anything for this watchpoint. */
3784 bs
->print_it
= print_it_noop
;
3791 /* Check conditions (condition proper, frame, thread and ignore count)
3792 of breakpoint referred to by BS. If we should not stop for this
3793 breakpoint, set BS->stop to 0. */
3795 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
3797 int thread_id
= pid_to_thread_id (ptid
);
3798 const struct bp_location
*bl
= bs
->breakpoint_at
;
3799 struct breakpoint
*b
= bl
->owner
;
3801 if (frame_id_p (b
->frame_id
)
3802 && !frame_id_eq (b
->frame_id
, get_stack_frame_id (get_current_frame ())))
3806 int value_is_zero
= 0;
3807 struct expression
*cond
;
3809 /* If this is a scope breakpoint, mark the associated
3810 watchpoint as triggered so that we will handle the
3811 out-of-scope event. We'll get to the watchpoint next
3813 if (b
->type
== bp_watchpoint_scope
)
3814 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
3816 if (is_watchpoint (b
))
3821 if (cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
3823 int within_current_scope
= 1;
3825 /* We use value_mark and value_free_to_mark because it could
3826 be a long time before we return to the command level and
3827 call free_all_values. We can't call free_all_values
3828 because we might be in the middle of evaluating a
3830 struct value
*mark
= value_mark ();
3832 /* Need to select the frame, with all that implies so that
3833 the conditions will have the right context. Because we
3834 use the frame, we will not see an inlined function's
3835 variables when we arrive at a breakpoint at the start
3836 of the inlined function; the current frame will be the
3838 if (!is_watchpoint (b
) || b
->cond_exp_valid_block
== NULL
)
3839 select_frame (get_current_frame ());
3842 struct frame_info
*frame
;
3844 /* For local watchpoint expressions, which particular
3845 instance of a local is being watched matters, so we
3846 keep track of the frame to evaluate the expression
3847 in. To evaluate the condition however, it doesn't
3848 really matter which instantiation of the function
3849 where the condition makes sense triggers the
3850 watchpoint. This allows an expression like "watch
3851 global if q > 10" set in `func', catch writes to
3852 global on all threads that call `func', or catch
3853 writes on all recursive calls of `func' by a single
3854 thread. We simply always evaluate the condition in
3855 the innermost frame that's executing where it makes
3856 sense to evaluate the condition. It seems
3858 frame
= block_innermost_frame (b
->cond_exp_valid_block
);
3860 select_frame (frame
);
3862 within_current_scope
= 0;
3864 if (within_current_scope
)
3866 = catch_errors (breakpoint_cond_eval
, cond
,
3867 "Error in testing breakpoint condition:\n",
3871 warning (_("Watchpoint condition cannot be tested "
3872 "in the current scope"));
3873 /* If we failed to set the right context for this
3874 watchpoint, unconditionally report it. */
3877 /* FIXME-someday, should give breakpoint # */
3878 value_free_to_mark (mark
);
3881 if (cond
&& value_is_zero
)
3885 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
3889 else if (b
->ignore_count
> 0)
3892 annotate_ignore_count_change ();
3894 /* Increase the hit count even though we don't
3902 /* Get a bpstat associated with having just stopped at address
3903 BP_ADDR in thread PTID.
3905 Determine whether we stopped at a breakpoint, etc, or whether we
3906 don't understand this stop. Result is a chain of bpstat's such that:
3908 if we don't understand the stop, the result is a null pointer.
3910 if we understand why we stopped, the result is not null.
3912 Each element of the chain refers to a particular breakpoint or
3913 watchpoint at which we have stopped. (We may have stopped for
3914 several reasons concurrently.)
3916 Each element of the chain has valid next, breakpoint_at,
3917 commands, FIXME??? fields. */
3920 bpstat_stop_status (struct address_space
*aspace
,
3921 CORE_ADDR bp_addr
, ptid_t ptid
)
3923 struct breakpoint
*b
= NULL
;
3924 struct bp_location
*bl
, **blp_tmp
;
3925 struct bp_location
*loc
;
3926 /* Root of the chain of bpstat's */
3927 struct bpstats root_bs
[1];
3928 /* Pointer to the last thing in the chain currently. */
3929 bpstat bs
= root_bs
;
3931 int need_remove_insert
;
3933 /* ALL_BP_LOCATIONS iteration would break across
3934 update_global_location_list possibly executed by
3935 bpstat_check_breakpoint_conditions's inferior call. */
3939 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3942 for (bl
= b
->loc
; bl
!= NULL
; bl
= bl
->next
)
3944 /* For hardware watchpoints, we look only at the first location.
3945 The watchpoint_check function will work on entire expression,
3946 not the individual locations. For read watchopints, the
3947 watchpoints_triggered function have checked all locations
3949 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3952 if (bl
->shlib_disabled
)
3955 if (!bpstat_check_location (bl
, aspace
, bp_addr
))
3958 /* Come here if it's a watchpoint, or if the break address matches */
3960 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3962 /* Assume we stop. Should we find watchpoint that is not actually
3963 triggered, or if condition of breakpoint is false, we'll reset
3968 bpstat_check_watchpoint (bs
);
3972 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
3973 || b
->type
== bp_longjmp_master
)
3974 /* We do not stop for these. */
3977 bpstat_check_breakpoint_conditions (bs
, ptid
);
3983 /* We will stop here */
3984 if (b
->disposition
== disp_disable
)
3986 if (b
->enable_state
!= bp_permanent
)
3987 b
->enable_state
= bp_disabled
;
3988 update_global_location_list (0);
3992 bs
->commands
= b
->commands
;
3993 incref_counted_command_line (bs
->commands
);
3994 bs
->commands_left
= bs
->commands
? bs
->commands
->commands
: NULL
;
3995 if (bs
->commands_left
3996 && (strcmp ("silent", bs
->commands_left
->line
) == 0
3999 bs
->commands_left
->line
) == 0)))
4001 bs
->commands_left
= bs
->commands_left
->next
;
4006 /* Print nothing for this entry if we dont stop or dont print. */
4007 if (bs
->stop
== 0 || bs
->print
== 0)
4008 bs
->print_it
= print_it_noop
;
4012 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
4014 if (breakpoint_address_match (loc
->pspace
->aspace
, loc
->address
,
4017 bs
= bpstat_alloc (loc
, bs
);
4018 /* For hits of moribund locations, we should just proceed. */
4021 bs
->print_it
= print_it_noop
;
4025 bs
->next
= NULL
; /* Terminate the chain */
4027 /* If we aren't stopping, the value of some hardware watchpoint may
4028 not have changed, but the intermediate memory locations we are
4029 watching may have. Don't bother if we're stopping; this will get
4031 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4035 need_remove_insert
= 0;
4037 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
4039 && bs
->breakpoint_at
->owner
4040 && is_hardware_watchpoint (bs
->breakpoint_at
->owner
))
4042 update_watchpoint (bs
->breakpoint_at
->owner
, 0 /* don't reparse. */);
4043 /* Updating watchpoints invalidates bs->breakpoint_at.
4044 Prevent further code from trying to use it. */
4045 bs
->breakpoint_at
= NULL
;
4046 need_remove_insert
= 1;
4049 if (need_remove_insert
)
4050 update_global_location_list (1);
4052 return root_bs
->next
;
4055 /* Tell what to do about this bpstat. */
4057 bpstat_what (bpstat bs
)
4059 /* Classify each bpstat as one of the following. */
4062 /* This bpstat element has no effect on the main_action. */
4065 /* There was a watchpoint, stop but don't print. */
4068 /* There was a watchpoint, stop and print. */
4071 /* There was a breakpoint but we're not stopping. */
4074 /* There was a breakpoint, stop but don't print. */
4077 /* There was a breakpoint, stop and print. */
4080 /* We hit the longjmp breakpoint. */
4083 /* We hit the longjmp_resume breakpoint. */
4086 /* We hit the step_resume breakpoint. */
4089 /* We hit the shared library event breakpoint. */
4092 /* We hit the jit event breakpoint. */
4095 /* This is just used to count how many enums there are. */
4099 /* Here is the table which drives this routine. So that we can
4100 format it pretty, we define some abbreviations for the
4101 enum bpstat_what codes. */
4102 #define kc BPSTAT_WHAT_KEEP_CHECKING
4103 #define ss BPSTAT_WHAT_STOP_SILENT
4104 #define sn BPSTAT_WHAT_STOP_NOISY
4105 #define sgl BPSTAT_WHAT_SINGLE
4106 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
4107 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
4108 #define sr BPSTAT_WHAT_STEP_RESUME
4109 #define shl BPSTAT_WHAT_CHECK_SHLIBS
4110 #define jit BPSTAT_WHAT_CHECK_JIT
4112 /* "Can't happen." Might want to print an error message.
4113 abort() is not out of the question, but chances are GDB is just
4114 a bit confused, not unusable. */
4115 #define err BPSTAT_WHAT_STOP_NOISY
4117 /* Given an old action and a class, come up with a new action. */
4118 /* One interesting property of this table is that wp_silent is the same
4119 as bp_silent and wp_noisy is the same as bp_noisy. That is because
4120 after stopping, the check for whether to step over a breakpoint
4121 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
4122 reference to how we stopped. We retain separate wp_silent and
4123 bp_silent codes in case we want to change that someday.
4125 Another possibly interesting property of this table is that
4126 there's a partial ordering, priority-like, of the actions. Once
4127 you've decided that some action is appropriate, you'll never go
4128 back and decide something of a lower priority is better. The
4131 kc < jit clr sgl shl slr sn sr ss
4132 sgl < jit shl slr sn sr ss
4133 slr < jit err shl sn sr ss
4134 clr < jit err shl sn sr ss
4141 What I think this means is that we don't need a damned table
4142 here. If you just put the rows and columns in the right order,
4143 it'd look awfully regular. We could simply walk the bpstat list
4144 and choose the highest priority action we find, with a little
4145 logic to handle the 'err' cases. */
4147 /* step_resume entries: a step resume breakpoint overrides another
4148 breakpoint of signal handling (see comment in wait_for_inferior
4149 at where we set the step_resume breakpoint). */
4151 static const enum bpstat_what_main_action
4152 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
4155 /* kc ss sn sgl slr clr sr shl jit */
4156 /* no_effect */ {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, jit
},
4157 /* wp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4158 /* wp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4159 /* bp_nostop */ {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, jit
},
4160 /* bp_silent */ {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, jit
},
4161 /* bp_noisy */ {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, jit
},
4162 /* long_jump */ {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, jit
},
4163 /* long_resume */ {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, jit
},
4164 /* step_resume */ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
4165 /* shlib */ {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shl
},
4166 /* jit_event */ {jit
, jit
, jit
, jit
, jit
, jit
, sr
, jit
, jit
}
4180 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
4181 struct bpstat_what retval
;
4183 retval
.call_dummy
= 0;
4184 for (; bs
!= NULL
; bs
= bs
->next
)
4186 enum class bs_class
= no_effect
;
4187 if (bs
->breakpoint_at
== NULL
)
4188 /* I suspect this can happen if it was a momentary breakpoint
4189 which has since been deleted. */
4191 if (bs
->breakpoint_at
->owner
== NULL
)
4192 bs_class
= bp_nostop
;
4194 switch (bs
->breakpoint_at
->owner
->type
)
4200 case bp_hardware_breakpoint
:
4206 bs_class
= bp_noisy
;
4208 bs_class
= bp_silent
;
4211 bs_class
= bp_nostop
;
4214 case bp_hardware_watchpoint
:
4215 case bp_read_watchpoint
:
4216 case bp_access_watchpoint
:
4220 bs_class
= wp_noisy
;
4222 bs_class
= wp_silent
;
4225 /* There was a watchpoint, but we're not stopping.
4226 This requires no further action. */
4227 bs_class
= no_effect
;
4230 bs_class
= long_jump
;
4232 case bp_longjmp_resume
:
4233 bs_class
= long_resume
;
4235 case bp_step_resume
:
4238 bs_class
= step_resume
;
4241 /* It is for the wrong frame. */
4242 bs_class
= bp_nostop
;
4244 case bp_watchpoint_scope
:
4245 bs_class
= bp_nostop
;
4247 case bp_shlib_event
:
4248 bs_class
= shlib_event
;
4251 bs_class
= jit_event
;
4253 case bp_thread_event
:
4254 case bp_overlay_event
:
4255 case bp_longjmp_master
:
4256 bs_class
= bp_nostop
;
4262 bs_class
= bp_noisy
;
4264 bs_class
= bp_silent
;
4267 /* There was a catchpoint, but we're not stopping.
4268 This requires no further action. */
4269 bs_class
= no_effect
;
4272 /* Make sure the action is stop (silent or noisy),
4273 so infrun.c pops the dummy frame. */
4274 bs_class
= bp_silent
;
4275 retval
.call_dummy
= 1;
4278 case bp_fast_tracepoint
:
4279 /* Tracepoint hits should not be reported back to GDB, and
4280 if one got through somehow, it should have been filtered
4282 internal_error (__FILE__
, __LINE__
,
4283 _("bpstat_what: tracepoint encountered"));
4286 current_action
= table
[(int) bs_class
][(int) current_action
];
4288 retval
.main_action
= current_action
;
4292 /* Nonzero if we should step constantly (e.g. watchpoints on machines
4293 without hardware support). This isn't related to a specific bpstat,
4294 just to things like whether watchpoints are set. */
4297 bpstat_should_step (void)
4299 struct breakpoint
*b
;
4301 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
&& b
->loc
!= NULL
)
4307 bpstat_causes_stop (bpstat bs
)
4309 for (; bs
!= NULL
; bs
= bs
->next
)
4318 /* Print the LOC location out of the list of B->LOC locations. */
4320 static void print_breakpoint_location (struct breakpoint
*b
,
4321 struct bp_location
*loc
,
4323 struct ui_stream
*stb
)
4325 struct cleanup
*old_chain
= save_current_program_space ();
4327 if (loc
!= NULL
&& loc
->shlib_disabled
)
4331 set_current_program_space (loc
->pspace
);
4333 if (b
->source_file
&& loc
)
4336 = find_pc_sect_function (loc
->address
, loc
->section
);
4339 ui_out_text (uiout
, "in ");
4340 ui_out_field_string (uiout
, "func",
4341 SYMBOL_PRINT_NAME (sym
));
4342 ui_out_wrap_hint (uiout
, wrap_indent
);
4343 ui_out_text (uiout
, " at ");
4345 ui_out_field_string (uiout
, "file", b
->source_file
);
4346 ui_out_text (uiout
, ":");
4348 if (ui_out_is_mi_like_p (uiout
))
4350 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
4351 char *fullname
= symtab_to_fullname (sal
.symtab
);
4354 ui_out_field_string (uiout
, "fullname", fullname
);
4357 ui_out_field_int (uiout
, "line", b
->line_number
);
4361 print_address_symbolic (loc
->gdbarch
, loc
->address
, stb
->stream
,
4363 ui_out_field_stream (uiout
, "at", stb
);
4366 ui_out_field_string (uiout
, "pending", b
->addr_string
);
4368 do_cleanups (old_chain
);
4371 /* Print B to gdb_stdout. */
4373 print_one_breakpoint_location (struct breakpoint
*b
,
4374 struct bp_location
*loc
,
4376 struct bp_location
**last_loc
,
4377 int print_address_bits
,
4380 struct command_line
*l
;
4382 struct ep_type_description
4387 static struct ep_type_description bptypes
[] =
4389 {bp_none
, "?deleted?"},
4390 {bp_breakpoint
, "breakpoint"},
4391 {bp_hardware_breakpoint
, "hw breakpoint"},
4392 {bp_until
, "until"},
4393 {bp_finish
, "finish"},
4394 {bp_watchpoint
, "watchpoint"},
4395 {bp_hardware_watchpoint
, "hw watchpoint"},
4396 {bp_read_watchpoint
, "read watchpoint"},
4397 {bp_access_watchpoint
, "acc watchpoint"},
4398 {bp_longjmp
, "longjmp"},
4399 {bp_longjmp_resume
, "longjmp resume"},
4400 {bp_step_resume
, "step resume"},
4401 {bp_watchpoint_scope
, "watchpoint scope"},
4402 {bp_call_dummy
, "call dummy"},
4403 {bp_shlib_event
, "shlib events"},
4404 {bp_thread_event
, "thread events"},
4405 {bp_overlay_event
, "overlay events"},
4406 {bp_longjmp_master
, "longjmp master"},
4407 {bp_catchpoint
, "catchpoint"},
4408 {bp_tracepoint
, "tracepoint"},
4409 {bp_fast_tracepoint
, "fast tracepoint"},
4410 {bp_jit_event
, "jit events"},
4413 static char bpenables
[] = "nynny";
4414 char wrap_indent
[80];
4415 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4416 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4417 struct cleanup
*bkpt_chain
;
4419 int header_of_multiple
= 0;
4420 int part_of_multiple
= (loc
!= NULL
);
4421 struct value_print_options opts
;
4423 get_user_print_options (&opts
);
4425 gdb_assert (!loc
|| loc_number
!= 0);
4426 /* See comment in print_one_breakpoint concerning
4427 treatment of breakpoints with single disabled
4431 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
4432 header_of_multiple
= 1;
4437 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
4441 if (part_of_multiple
)
4444 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
4445 ui_out_field_string (uiout
, "number", formatted
);
4450 ui_out_field_int (uiout
, "number", b
->number
);
4455 if (part_of_multiple
)
4456 ui_out_field_skip (uiout
, "type");
4459 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
4460 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
4461 internal_error (__FILE__
, __LINE__
,
4462 _("bptypes table does not describe type #%d."),
4464 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
4469 if (part_of_multiple
)
4470 ui_out_field_skip (uiout
, "disp");
4472 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
4477 if (part_of_multiple
)
4478 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
4480 ui_out_field_fmt (uiout
, "enabled", "%c",
4481 bpenables
[(int) b
->enable_state
]);
4482 ui_out_spaces (uiout
, 2);
4486 strcpy (wrap_indent
, " ");
4487 if (opts
.addressprint
)
4489 if (print_address_bits
<= 32)
4490 strcat (wrap_indent
, " ");
4492 strcat (wrap_indent
, " ");
4495 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
4497 /* Although the print_one can possibly print
4498 all locations, calling it here is not likely
4499 to get any nice result. So, make sure there's
4500 just one location. */
4501 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
4502 b
->ops
->print_one (b
, last_loc
);
4508 internal_error (__FILE__
, __LINE__
,
4509 _("print_one_breakpoint: bp_none encountered\n"));
4513 case bp_hardware_watchpoint
:
4514 case bp_read_watchpoint
:
4515 case bp_access_watchpoint
:
4516 /* Field 4, the address, is omitted (which makes the columns
4517 not line up too nicely with the headers, but the effect
4518 is relatively readable). */
4519 if (opts
.addressprint
)
4520 ui_out_field_skip (uiout
, "addr");
4522 ui_out_field_string (uiout
, "what", b
->exp_string
);
4526 case bp_hardware_breakpoint
:
4530 case bp_longjmp_resume
:
4531 case bp_step_resume
:
4532 case bp_watchpoint_scope
:
4534 case bp_shlib_event
:
4535 case bp_thread_event
:
4536 case bp_overlay_event
:
4537 case bp_longjmp_master
:
4539 case bp_fast_tracepoint
:
4541 if (opts
.addressprint
)
4544 if (header_of_multiple
)
4545 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
4546 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
4547 ui_out_field_string (uiout
, "addr", "<PENDING>");
4549 ui_out_field_core_addr (uiout
, "addr",
4550 loc
->gdbarch
, loc
->address
);
4553 if (!header_of_multiple
)
4554 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
4561 /* For backward compatibility, don't display inferiors unless there
4564 && !header_of_multiple
4566 || (!gdbarch_has_global_breakpoints (target_gdbarch
)
4567 && (number_of_program_spaces () > 1
4568 || number_of_inferiors () > 1)
4569 && loc
->owner
->type
!= bp_catchpoint
)))
4571 struct inferior
*inf
;
4574 for (inf
= inferior_list
; inf
!= NULL
; inf
= inf
->next
)
4576 if (inf
->pspace
== loc
->pspace
)
4581 ui_out_text (uiout
, " inf ");
4584 ui_out_text (uiout
, ", ");
4585 ui_out_text (uiout
, plongest (inf
->num
));
4590 if (!part_of_multiple
)
4592 if (b
->thread
!= -1)
4594 /* FIXME: This seems to be redundant and lost here; see the
4595 "stop only in" line a little further down. */
4596 ui_out_text (uiout
, " thread ");
4597 ui_out_field_int (uiout
, "thread", b
->thread
);
4599 else if (b
->task
!= 0)
4601 ui_out_text (uiout
, " task ");
4602 ui_out_field_int (uiout
, "task", b
->task
);
4606 ui_out_text (uiout
, "\n");
4608 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
4611 ui_out_text (uiout
, "\tstop only in stack frame at ");
4612 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
4614 ui_out_field_core_addr (uiout
, "frame",
4615 b
->gdbarch
, b
->frame_id
.stack_addr
);
4616 ui_out_text (uiout
, "\n");
4619 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
4621 /* We do not print the condition for Ada exception catchpoints
4622 because the condition is an internal implementation detail
4623 that we do not want to expose to the user. */
4625 if (tracepoint_type (b
))
4626 ui_out_text (uiout
, "\ttrace only if ");
4628 ui_out_text (uiout
, "\tstop only if ");
4629 ui_out_field_string (uiout
, "cond", b
->cond_string
);
4630 ui_out_text (uiout
, "\n");
4633 if (!part_of_multiple
&& b
->thread
!= -1)
4635 /* FIXME should make an annotation for this */
4636 ui_out_text (uiout
, "\tstop only in thread ");
4637 ui_out_field_int (uiout
, "thread", b
->thread
);
4638 ui_out_text (uiout
, "\n");
4641 if (!part_of_multiple
&& b
->hit_count
)
4643 /* FIXME should make an annotation for this */
4644 if (ep_is_catchpoint (b
))
4645 ui_out_text (uiout
, "\tcatchpoint");
4647 ui_out_text (uiout
, "\tbreakpoint");
4648 ui_out_text (uiout
, " already hit ");
4649 ui_out_field_int (uiout
, "times", b
->hit_count
);
4650 if (b
->hit_count
== 1)
4651 ui_out_text (uiout
, " time\n");
4653 ui_out_text (uiout
, " times\n");
4656 /* Output the count also if it is zero, but only if this is
4657 mi. FIXME: Should have a better test for this. */
4658 if (ui_out_is_mi_like_p (uiout
))
4659 if (!part_of_multiple
&& b
->hit_count
== 0)
4660 ui_out_field_int (uiout
, "times", b
->hit_count
);
4662 if (!part_of_multiple
&& b
->ignore_count
)
4665 ui_out_text (uiout
, "\tignore next ");
4666 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
4667 ui_out_text (uiout
, " hits\n");
4670 l
= b
->commands
? b
->commands
->commands
: NULL
;
4671 if (!part_of_multiple
&& l
)
4673 struct cleanup
*script_chain
;
4676 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
4677 print_command_lines (uiout
, l
, 4);
4678 do_cleanups (script_chain
);
4681 if (!part_of_multiple
&& b
->pass_count
)
4683 annotate_field (10);
4684 ui_out_text (uiout
, "\tpass count ");
4685 ui_out_field_int (uiout
, "pass", b
->pass_count
);
4686 ui_out_text (uiout
, " \n");
4689 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
4692 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
4693 else if (b
->exp_string
)
4694 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
4697 do_cleanups (bkpt_chain
);
4698 do_cleanups (old_chain
);
4702 print_one_breakpoint (struct breakpoint
*b
,
4703 struct bp_location
**last_loc
, int print_address_bits
,
4706 print_one_breakpoint_location (b
, NULL
, 0, last_loc
,
4707 print_address_bits
, allflag
);
4709 /* If this breakpoint has custom print function,
4710 it's already printed. Otherwise, print individual
4711 locations, if any. */
4712 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
4714 /* If breakpoint has a single location that is
4715 disabled, we print it as if it had
4716 several locations, since otherwise it's hard to
4717 represent "breakpoint enabled, location disabled"
4719 Note that while hardware watchpoints have
4720 several locations internally, that's no a property
4723 && !is_hardware_watchpoint (b
)
4724 && (b
->loc
->next
|| !b
->loc
->enabled
)
4725 && !ui_out_is_mi_like_p (uiout
))
4727 struct bp_location
*loc
;
4729 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
4730 print_one_breakpoint_location (b
, loc
, n
, last_loc
,
4731 print_address_bits
, allflag
);
4737 breakpoint_address_bits (struct breakpoint
*b
)
4739 int print_address_bits
= 0;
4740 struct bp_location
*loc
;
4742 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
4746 /* Software watchpoints that aren't watching memory don't have
4747 an address to print. */
4748 if (b
->type
== bp_watchpoint
&& loc
->watchpoint_type
== -1)
4751 addr_bit
= gdbarch_addr_bit (loc
->gdbarch
);
4752 if (addr_bit
> print_address_bits
)
4753 print_address_bits
= addr_bit
;
4756 return print_address_bits
;
4759 struct captured_breakpoint_query_args
4765 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
4767 struct captured_breakpoint_query_args
*args
= data
;
4768 struct breakpoint
*b
;
4769 struct bp_location
*dummy_loc
= NULL
;
4772 if (args
->bnum
== b
->number
)
4774 int print_address_bits
= breakpoint_address_bits (b
);
4775 print_one_breakpoint (b
, &dummy_loc
, print_address_bits
, 0);
4783 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
4785 struct captured_breakpoint_query_args args
;
4787 /* For the moment we don't trust print_one_breakpoint() to not throw
4789 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
4790 error_message
, RETURN_MASK_ALL
) < 0)
4796 /* Return non-zero if B is user settable (breakpoints, watchpoints,
4797 catchpoints, et.al.). */
4800 user_settable_breakpoint (const struct breakpoint
*b
)
4802 return (b
->type
== bp_breakpoint
4803 || b
->type
== bp_catchpoint
4804 || b
->type
== bp_hardware_breakpoint
4805 || tracepoint_type (b
)
4806 || b
->type
== bp_watchpoint
4807 || b
->type
== bp_read_watchpoint
4808 || b
->type
== bp_access_watchpoint
4809 || b
->type
== bp_hardware_watchpoint
);
4812 /* Print information on user settable breakpoint (watchpoint, etc)
4813 number BNUM. If BNUM is -1 print all user settable breakpoints.
4814 If ALLFLAG is non-zero, include non- user settable breakpoints. */
4817 breakpoint_1 (int bnum
, int allflag
)
4819 struct breakpoint
*b
;
4820 struct bp_location
*last_loc
= NULL
;
4821 int nr_printable_breakpoints
;
4822 struct cleanup
*bkpttbl_chain
;
4823 struct value_print_options opts
;
4824 int print_address_bits
= 0;
4826 get_user_print_options (&opts
);
4828 /* Compute the number of rows in the table, as well as the
4829 size required for address fields. */
4830 nr_printable_breakpoints
= 0;
4833 || bnum
== b
->number
)
4835 if (allflag
|| user_settable_breakpoint (b
))
4837 int addr_bit
= breakpoint_address_bits (b
);
4838 if (addr_bit
> print_address_bits
)
4839 print_address_bits
= addr_bit
;
4841 nr_printable_breakpoints
++;
4845 if (opts
.addressprint
)
4847 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
4851 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
4854 if (nr_printable_breakpoints
> 0)
4855 annotate_breakpoints_headers ();
4856 if (nr_printable_breakpoints
> 0)
4858 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
4859 if (nr_printable_breakpoints
> 0)
4861 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
4862 if (nr_printable_breakpoints
> 0)
4864 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
4865 if (nr_printable_breakpoints
> 0)
4867 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
4868 if (opts
.addressprint
)
4870 if (nr_printable_breakpoints
> 0)
4872 if (print_address_bits
<= 32)
4873 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
4875 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
4877 if (nr_printable_breakpoints
> 0)
4879 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
4880 ui_out_table_body (uiout
);
4881 if (nr_printable_breakpoints
> 0)
4882 annotate_breakpoints_table ();
4888 || bnum
== b
->number
)
4890 /* We only print out user settable breakpoints unless the
4892 if (allflag
|| user_settable_breakpoint (b
))
4893 print_one_breakpoint (b
, &last_loc
, print_address_bits
, allflag
);
4897 do_cleanups (bkpttbl_chain
);
4899 if (nr_printable_breakpoints
== 0)
4902 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4904 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4909 if (last_loc
&& !server_command
)
4910 set_next_address (last_loc
->gdbarch
, last_loc
->address
);
4913 /* FIXME? Should this be moved up so that it is only called when
4914 there have been breakpoints? */
4915 annotate_breakpoints_table_end ();
4919 breakpoints_info (char *bnum_exp
, int from_tty
)
4924 bnum
= parse_and_eval_long (bnum_exp
);
4926 breakpoint_1 (bnum
, 0);
4930 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4935 bnum
= parse_and_eval_long (bnum_exp
);
4937 breakpoint_1 (bnum
, 1);
4941 breakpoint_has_pc (struct breakpoint
*b
,
4942 struct program_space
*pspace
,
4943 CORE_ADDR pc
, struct obj_section
*section
)
4945 struct bp_location
*bl
= b
->loc
;
4946 for (; bl
; bl
= bl
->next
)
4948 if (bl
->pspace
== pspace
4949 && bl
->address
== pc
4950 && (!overlay_debugging
|| bl
->section
== section
))
4956 /* Print a message describing any breakpoints set at PC. This
4957 concerns with logical breakpoints, so we match program spaces, not
4961 describe_other_breakpoints (struct gdbarch
*gdbarch
,
4962 struct program_space
*pspace
, CORE_ADDR pc
,
4963 struct obj_section
*section
, int thread
)
4966 struct breakpoint
*b
;
4969 others
+= breakpoint_has_pc (b
, pspace
, pc
, section
);
4973 printf_filtered (_("Note: breakpoint "));
4974 else /* if (others == ???) */
4975 printf_filtered (_("Note: breakpoints "));
4977 if (breakpoint_has_pc (b
, pspace
, pc
, section
))
4980 printf_filtered ("%d", b
->number
);
4981 if (b
->thread
== -1 && thread
!= -1)
4982 printf_filtered (" (all threads)");
4983 else if (b
->thread
!= -1)
4984 printf_filtered (" (thread %d)", b
->thread
);
4985 printf_filtered ("%s%s ",
4986 ((b
->enable_state
== bp_disabled
4987 || b
->enable_state
== bp_call_disabled
4988 || b
->enable_state
== bp_startup_disabled
)
4990 : b
->enable_state
== bp_permanent
4994 : ((others
== 1) ? " and" : ""));
4996 printf_filtered (_("also set at pc "));
4997 fputs_filtered (paddress (gdbarch
, pc
), gdb_stdout
);
4998 printf_filtered (".\n");
5002 /* Set the default place to put a breakpoint
5003 for the `break' command with no arguments. */
5006 set_default_breakpoint (int valid
, struct program_space
*pspace
,
5007 CORE_ADDR addr
, struct symtab
*symtab
,
5010 default_breakpoint_valid
= valid
;
5011 default_breakpoint_pspace
= pspace
;
5012 default_breakpoint_address
= addr
;
5013 default_breakpoint_symtab
= symtab
;
5014 default_breakpoint_line
= line
;
5017 /* Return true iff it is meaningful to use the address member of
5018 BPT. For some breakpoint types, the address member is irrelevant
5019 and it makes no sense to attempt to compare it to other addresses
5020 (or use it for any other purpose either).
5022 More specifically, each of the following breakpoint types will always
5023 have a zero valued address and we don't want to mark breakpoints of any of
5024 these types to be a duplicate of an actual breakpoint at address zero:
5032 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
5034 enum bptype type
= bpt
->type
;
5036 return (type
!= bp_watchpoint
&& type
!= bp_catchpoint
);
5039 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns
5040 true if LOC1 and LOC2 represent the same watchpoint location. */
5043 watchpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5045 /* Note that this checks the owner's type, not the location's. In
5046 case the target does not support read watchpoints, but does
5047 support access watchpoints, we'll have bp_read_watchpoint
5048 watchpoints with hw_access locations. Those should be considered
5049 duplicates of hw_read locations. The hw_read locations will
5050 become hw_access locations later. */
5051 return (loc1
->owner
->type
== loc2
->owner
->type
5052 && loc1
->pspace
->aspace
== loc2
->pspace
->aspace
5053 && loc1
->address
== loc2
->address
5054 && loc1
->length
== loc2
->length
);
5057 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the
5058 same breakpoint location. In most targets, this can only be true
5059 if ASPACE1 matches ASPACE2. On targets that have global
5060 breakpoints, the address space doesn't really matter. */
5063 breakpoint_address_match (struct address_space
*aspace1
, CORE_ADDR addr1
,
5064 struct address_space
*aspace2
, CORE_ADDR addr2
)
5066 return ((gdbarch_has_global_breakpoints (target_gdbarch
)
5067 || aspace1
== aspace2
)
5071 /* Assuming LOC1 and LOC2's types' have meaningful target addresses
5072 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2
5073 represent the same location. */
5076 breakpoint_locations_match (struct bp_location
*loc1
, struct bp_location
*loc2
)
5078 int hw_point1
= is_hardware_watchpoint (loc1
->owner
);
5079 int hw_point2
= is_hardware_watchpoint (loc2
->owner
);
5081 if (hw_point1
!= hw_point2
)
5084 return watchpoint_locations_match (loc1
, loc2
);
5086 return breakpoint_address_match (loc1
->pspace
->aspace
, loc1
->address
,
5087 loc2
->pspace
->aspace
, loc2
->address
);
5091 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
5092 int bnum
, int have_bnum
)
5097 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
5098 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
5100 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
5101 bnum
, astr1
, astr2
);
5103 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
5106 /* Adjust a breakpoint's address to account for architectural constraints
5107 on breakpoint placement. Return the adjusted address. Note: Very
5108 few targets require this kind of adjustment. For most targets,
5109 this function is simply the identity function. */
5112 adjust_breakpoint_address (struct gdbarch
*gdbarch
,
5113 CORE_ADDR bpaddr
, enum bptype bptype
)
5115 if (!gdbarch_adjust_breakpoint_address_p (gdbarch
))
5117 /* Very few targets need any kind of breakpoint adjustment. */
5120 else if (bptype
== bp_watchpoint
5121 || bptype
== bp_hardware_watchpoint
5122 || bptype
== bp_read_watchpoint
5123 || bptype
== bp_access_watchpoint
5124 || bptype
== bp_catchpoint
)
5126 /* Watchpoints and the various bp_catch_* eventpoints should not
5127 have their addresses modified. */
5132 CORE_ADDR adjusted_bpaddr
;
5134 /* Some targets have architectural constraints on the placement
5135 of breakpoint instructions. Obtain the adjusted address. */
5136 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (gdbarch
, bpaddr
);
5138 /* An adjusted breakpoint address can significantly alter
5139 a user's expectations. Print a warning if an adjustment
5141 if (adjusted_bpaddr
!= bpaddr
)
5142 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
5144 return adjusted_bpaddr
;
5148 /* Allocate a struct bp_location. */
5150 static struct bp_location
*
5151 allocate_bp_location (struct breakpoint
*bpt
)
5153 struct bp_location
*loc
, *loc_p
;
5155 loc
= xmalloc (sizeof (struct bp_location
));
5156 memset (loc
, 0, sizeof (*loc
));
5160 loc
->shlib_disabled
= 0;
5169 case bp_longjmp_resume
:
5170 case bp_step_resume
:
5171 case bp_watchpoint_scope
:
5173 case bp_shlib_event
:
5174 case bp_thread_event
:
5175 case bp_overlay_event
:
5177 case bp_longjmp_master
:
5178 loc
->loc_type
= bp_loc_software_breakpoint
;
5180 case bp_hardware_breakpoint
:
5181 loc
->loc_type
= bp_loc_hardware_breakpoint
;
5183 case bp_hardware_watchpoint
:
5184 case bp_read_watchpoint
:
5185 case bp_access_watchpoint
:
5186 loc
->loc_type
= bp_loc_hardware_watchpoint
;
5191 case bp_fast_tracepoint
:
5192 loc
->loc_type
= bp_loc_other
;
5195 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
5201 static void free_bp_location (struct bp_location
*loc
)
5206 if (loc
->function_name
)
5207 xfree (loc
->function_name
);
5212 /* Helper to set_raw_breakpoint below. Creates a breakpoint
5213 that has type BPTYPE and has no locations as yet. */
5214 /* This function is used in gdbtk sources and thus can not be made static. */
5216 static struct breakpoint
*
5217 set_raw_breakpoint_without_location (struct gdbarch
*gdbarch
,
5220 struct breakpoint
*b
, *b1
;
5222 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
5223 memset (b
, 0, sizeof (*b
));
5226 b
->gdbarch
= gdbarch
;
5227 b
->language
= current_language
->la_language
;
5228 b
->input_radix
= input_radix
;
5230 b
->enable_state
= bp_enabled
;
5233 b
->ignore_count
= 0;
5235 b
->frame_id
= null_frame_id
;
5236 b
->forked_inferior_pid
= null_ptid
;
5237 b
->exec_pathname
= NULL
;
5238 b
->syscalls_to_be_caught
= NULL
;
5240 b
->condition_not_parsed
= 0;
5242 /* Add this breakpoint to the end of the chain
5243 so that a list of breakpoints will come out in order
5244 of increasing numbers. */
5246 b1
= breakpoint_chain
;
5248 breakpoint_chain
= b
;
5258 /* Initialize loc->function_name. */
5260 set_breakpoint_location_function (struct bp_location
*loc
)
5262 if (loc
->owner
->type
== bp_breakpoint
5263 || loc
->owner
->type
== bp_hardware_breakpoint
5264 || tracepoint_type (loc
->owner
))
5266 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
5268 if (loc
->function_name
)
5269 loc
->function_name
= xstrdup (loc
->function_name
);
5273 /* Attempt to determine architecture of location identified by SAL. */
5274 static struct gdbarch
*
5275 get_sal_arch (struct symtab_and_line sal
)
5278 return get_objfile_arch (sal
.section
->objfile
);
5280 return get_objfile_arch (sal
.symtab
->objfile
);
5285 /* set_raw_breakpoint is a low level routine for allocating and
5286 partially initializing a breakpoint of type BPTYPE. The newly
5287 created breakpoint's address, section, source file name, and line
5288 number are provided by SAL. The newly created and partially
5289 initialized breakpoint is added to the breakpoint chain and
5290 is also returned as the value of this function.
5292 It is expected that the caller will complete the initialization of
5293 the newly created breakpoint struct as well as output any status
5294 information regarding the creation of a new breakpoint. In
5295 particular, set_raw_breakpoint does NOT set the breakpoint
5296 number! Care should be taken to not allow an error to occur
5297 prior to completing the initialization of the breakpoint. If this
5298 should happen, a bogus breakpoint will be left on the chain. */
5301 set_raw_breakpoint (struct gdbarch
*gdbarch
,
5302 struct symtab_and_line sal
, enum bptype bptype
)
5304 struct breakpoint
*b
= set_raw_breakpoint_without_location (gdbarch
, bptype
);
5305 CORE_ADDR adjusted_address
;
5306 struct gdbarch
*loc_gdbarch
;
5308 loc_gdbarch
= get_sal_arch (sal
);
5310 loc_gdbarch
= b
->gdbarch
;
5312 if (bptype
!= bp_catchpoint
)
5313 gdb_assert (sal
.pspace
!= NULL
);
5315 /* Adjust the breakpoint's address prior to allocating a location.
5316 Once we call allocate_bp_location(), that mostly uninitialized
5317 location will be placed on the location chain. Adjustment of the
5318 breakpoint may cause target_read_memory() to be called and we do
5319 not want its scan of the location chain to find a breakpoint and
5320 location that's only been partially initialized. */
5321 adjusted_address
= adjust_breakpoint_address (loc_gdbarch
, sal
.pc
, b
->type
);
5323 b
->loc
= allocate_bp_location (b
);
5324 b
->loc
->gdbarch
= loc_gdbarch
;
5325 b
->loc
->requested_address
= sal
.pc
;
5326 b
->loc
->address
= adjusted_address
;
5327 b
->loc
->pspace
= sal
.pspace
;
5329 /* Store the program space that was used to set the breakpoint, for
5330 breakpoint resetting. */
5331 b
->pspace
= sal
.pspace
;
5333 if (sal
.symtab
== NULL
)
5334 b
->source_file
= NULL
;
5336 b
->source_file
= xstrdup (sal
.symtab
->filename
);
5337 b
->loc
->section
= sal
.section
;
5338 b
->line_number
= sal
.line
;
5340 set_breakpoint_location_function (b
->loc
);
5342 breakpoints_changed ();
5348 /* Note that the breakpoint object B describes a permanent breakpoint
5349 instruction, hard-wired into the inferior's code. */
5351 make_breakpoint_permanent (struct breakpoint
*b
)
5353 struct bp_location
*bl
;
5354 b
->enable_state
= bp_permanent
;
5356 /* By definition, permanent breakpoints are already present in the code.
5357 Mark all locations as inserted. For now, make_breakpoint_permanent
5358 is called in just one place, so it's hard to say if it's reasonable
5359 to have permanent breakpoint with multiple locations or not,
5360 but it's easy to implmement. */
5361 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
5365 /* Call this routine when stepping and nexting to enable a breakpoint
5366 if we do a longjmp() in THREAD. When we hit that breakpoint, call
5367 set_longjmp_resume_breakpoint() to figure out where we are going. */
5370 set_longjmp_breakpoint (int thread
)
5372 struct breakpoint
*b
, *temp
;
5374 /* To avoid having to rescan all objfile symbols at every step,
5375 we maintain a list of continually-inserted but always disabled
5376 longjmp "master" breakpoints. Here, we simply create momentary
5377 clones of those and enable them for the requested thread. */
5378 ALL_BREAKPOINTS_SAFE (b
, temp
)
5379 if (b
->pspace
== current_program_space
5380 && b
->type
== bp_longjmp_master
)
5382 struct breakpoint
*clone
= clone_momentary_breakpoint (b
);
5383 clone
->type
= bp_longjmp
;
5384 clone
->thread
= thread
;
5388 /* Delete all longjmp breakpoints from THREAD. */
5390 delete_longjmp_breakpoint (int thread
)
5392 struct breakpoint
*b
, *temp
;
5394 ALL_BREAKPOINTS_SAFE (b
, temp
)
5395 if (b
->type
== bp_longjmp
)
5397 if (b
->thread
== thread
)
5398 delete_breakpoint (b
);
5403 enable_overlay_breakpoints (void)
5405 struct breakpoint
*b
;
5408 if (b
->type
== bp_overlay_event
)
5410 b
->enable_state
= bp_enabled
;
5411 update_global_location_list (1);
5412 overlay_events_enabled
= 1;
5417 disable_overlay_breakpoints (void)
5419 struct breakpoint
*b
;
5422 if (b
->type
== bp_overlay_event
)
5424 b
->enable_state
= bp_disabled
;
5425 update_global_location_list (0);
5426 overlay_events_enabled
= 0;
5431 create_thread_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5433 struct breakpoint
*b
;
5435 b
= create_internal_breakpoint (gdbarch
, address
, bp_thread_event
);
5437 b
->enable_state
= bp_enabled
;
5438 /* addr_string has to be used or breakpoint_re_set will delete me. */
5440 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
5442 update_global_location_list_nothrow (1);
5448 remove_thread_event_breakpoints (void)
5450 struct breakpoint
*b
, *temp
;
5452 ALL_BREAKPOINTS_SAFE (b
, temp
)
5453 if (b
->type
== bp_thread_event
5454 && b
->loc
->pspace
== current_program_space
)
5455 delete_breakpoint (b
);
5458 struct captured_parse_breakpoint_args
5461 struct symtabs_and_lines
*sals_p
;
5462 char ***addr_string_p
;
5466 struct lang_and_radix
5472 /* Create a breakpoint for JIT code registration and unregistration. */
5475 create_jit_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5477 struct breakpoint
*b
;
5479 b
= create_internal_breakpoint (gdbarch
, address
, bp_jit_event
);
5480 update_global_location_list_nothrow (1);
5485 remove_solib_event_breakpoints (void)
5487 struct breakpoint
*b
, *temp
;
5489 ALL_BREAKPOINTS_SAFE (b
, temp
)
5490 if (b
->type
== bp_shlib_event
5491 && b
->loc
->pspace
== current_program_space
)
5492 delete_breakpoint (b
);
5496 create_solib_event_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR address
)
5498 struct breakpoint
*b
;
5500 b
= create_internal_breakpoint (gdbarch
, address
, bp_shlib_event
);
5501 update_global_location_list_nothrow (1);
5505 /* Disable any breakpoints that are on code in shared libraries. Only
5506 apply to enabled breakpoints, disabled ones can just stay disabled. */
5509 disable_breakpoints_in_shlibs (void)
5511 struct bp_location
*loc
, **locp_tmp
;
5513 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5515 struct breakpoint
*b
= loc
->owner
;
5516 /* We apply the check to all breakpoints, including disabled
5517 for those with loc->duplicate set. This is so that when breakpoint
5518 becomes enabled, or the duplicate is removed, gdb will try to insert
5519 all breakpoints. If we don't set shlib_disabled here, we'll try
5520 to insert those breakpoints and fail. */
5521 if (((b
->type
== bp_breakpoint
)
5522 || (b
->type
== bp_jit_event
)
5523 || (b
->type
== bp_hardware_breakpoint
)
5524 || (tracepoint_type (b
)))
5525 && loc
->pspace
== current_program_space
5526 && !loc
->shlib_disabled
5528 && PC_SOLIB (loc
->address
)
5530 && solib_name_from_address (loc
->pspace
, loc
->address
)
5534 loc
->shlib_disabled
= 1;
5539 /* Disable any breakpoints that are in in an unloaded shared library. Only
5540 apply to enabled breakpoints, disabled ones can just stay disabled. */
5543 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
5545 struct bp_location
*loc
, **locp_tmp
;
5546 int disabled_shlib_breaks
= 0;
5548 /* SunOS a.out shared libraries are always mapped, so do not
5549 disable breakpoints; they will only be reported as unloaded
5550 through clear_solib when GDB discards its shared library
5551 list. See clear_solib for more information. */
5552 if (exec_bfd
!= NULL
5553 && bfd_get_flavour (exec_bfd
) == bfd_target_aout_flavour
)
5556 ALL_BP_LOCATIONS (loc
, locp_tmp
)
5558 struct breakpoint
*b
= loc
->owner
;
5559 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
5560 || loc
->loc_type
== bp_loc_software_breakpoint
)
5561 && solib
->pspace
== loc
->pspace
5562 && !loc
->shlib_disabled
5563 && (b
->type
== bp_breakpoint
5564 || b
->type
== bp_jit_event
5565 || b
->type
== bp_hardware_breakpoint
)
5566 && solib_contains_address_p (solib
, loc
->address
))
5568 loc
->shlib_disabled
= 1;
5569 /* At this point, we cannot rely on remove_breakpoint
5570 succeeding so we must mark the breakpoint as not inserted
5571 to prevent future errors occurring in remove_breakpoints. */
5573 if (!disabled_shlib_breaks
)
5575 target_terminal_ours_for_output ();
5576 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
5579 disabled_shlib_breaks
= 1;
5584 /* FORK & VFORK catchpoints. */
5586 /* Implement the "insert" breakpoint_ops method for fork catchpoints. */
5589 insert_catch_fork (struct breakpoint
*b
)
5591 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
5594 /* Implement the "remove" breakpoint_ops method for fork catchpoints. */
5597 remove_catch_fork (struct breakpoint
*b
)
5599 return target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
5602 /* Implement the "breakpoint_hit" breakpoint_ops method for fork
5606 breakpoint_hit_catch_fork (struct breakpoint
*b
)
5608 return inferior_has_forked (inferior_ptid
, &b
->forked_inferior_pid
);
5611 /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */
5613 static enum print_stop_action
5614 print_it_catch_fork (struct breakpoint
*b
)
5616 annotate_catchpoint (b
->number
);
5617 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
5618 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5619 return PRINT_SRC_AND_LOC
;
5622 /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */
5625 print_one_catch_fork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5627 struct value_print_options opts
;
5629 get_user_print_options (&opts
);
5631 /* Field 4, the address, is omitted (which makes the columns
5632 not line up too nicely with the headers, but the effect
5633 is relatively readable). */
5634 if (opts
.addressprint
)
5635 ui_out_field_skip (uiout
, "addr");
5637 ui_out_text (uiout
, "fork");
5638 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5640 ui_out_text (uiout
, ", process ");
5641 ui_out_field_int (uiout
, "what",
5642 ptid_get_pid (b
->forked_inferior_pid
));
5643 ui_out_spaces (uiout
, 1);
5647 /* Implement the "print_mention" breakpoint_ops method for fork
5651 print_mention_catch_fork (struct breakpoint
*b
)
5653 printf_filtered (_("Catchpoint %d (fork)"), b
->number
);
5656 /* The breakpoint_ops structure to be used in fork catchpoints. */
5658 static struct breakpoint_ops catch_fork_breakpoint_ops
=
5662 breakpoint_hit_catch_fork
,
5663 print_it_catch_fork
,
5664 print_one_catch_fork
,
5665 print_mention_catch_fork
5668 /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */
5671 insert_catch_vfork (struct breakpoint
*b
)
5673 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
5676 /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */
5679 remove_catch_vfork (struct breakpoint
*b
)
5681 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
5684 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork
5688 breakpoint_hit_catch_vfork (struct breakpoint
*b
)
5690 return inferior_has_vforked (inferior_ptid
, &b
->forked_inferior_pid
);
5693 /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */
5695 static enum print_stop_action
5696 print_it_catch_vfork (struct breakpoint
*b
)
5698 annotate_catchpoint (b
->number
);
5699 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
5700 b
->number
, ptid_get_pid (b
->forked_inferior_pid
));
5701 return PRINT_SRC_AND_LOC
;
5704 /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */
5707 print_one_catch_vfork (struct breakpoint
*b
, struct bp_location
**last_loc
)
5709 struct value_print_options opts
;
5711 get_user_print_options (&opts
);
5712 /* Field 4, the address, is omitted (which makes the columns
5713 not line up too nicely with the headers, but the effect
5714 is relatively readable). */
5715 if (opts
.addressprint
)
5716 ui_out_field_skip (uiout
, "addr");
5718 ui_out_text (uiout
, "vfork");
5719 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
5721 ui_out_text (uiout
, ", process ");
5722 ui_out_field_int (uiout
, "what",
5723 ptid_get_pid (b
->forked_inferior_pid
));
5724 ui_out_spaces (uiout
, 1);
5728 /* Implement the "print_mention" breakpoint_ops method for vfork
5732 print_mention_catch_vfork (struct breakpoint
*b
)
5734 printf_filtered (_("Catchpoint %d (vfork)"), b
->number
);
5737 /* The breakpoint_ops structure to be used in vfork catchpoints. */
5739 static struct breakpoint_ops catch_vfork_breakpoint_ops
=
5743 breakpoint_hit_catch_vfork
,
5744 print_it_catch_vfork
,
5745 print_one_catch_vfork
,
5746 print_mention_catch_vfork
5749 /* Implement the "insert" breakpoint_ops method for syscall
5753 insert_catch_syscall (struct breakpoint
*b
)
5755 struct inferior
*inf
= current_inferior ();
5757 ++inf
->total_syscalls_count
;
5758 if (!b
->syscalls_to_be_caught
)
5759 ++inf
->any_syscall_count
;
5764 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5768 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5770 int old_size
= VEC_length (int, inf
->syscalls_counts
);
5771 uintptr_t vec_addr_offset
= old_size
* ((uintptr_t) sizeof (int));
5773 VEC_safe_grow (int, inf
->syscalls_counts
, iter
+ 1);
5774 vec_addr
= (uintptr_t) VEC_address (int, inf
->syscalls_counts
) +
5776 memset ((void *) vec_addr
, 0,
5777 (iter
+ 1 - old_size
) * sizeof (int));
5779 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5780 VEC_replace (int, inf
->syscalls_counts
, iter
, ++elem
);
5784 target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5785 inf
->total_syscalls_count
!= 0,
5786 inf
->any_syscall_count
,
5787 VEC_length (int, inf
->syscalls_counts
),
5788 VEC_address (int, inf
->syscalls_counts
));
5791 /* Implement the "remove" breakpoint_ops method for syscall
5795 remove_catch_syscall (struct breakpoint
*b
)
5797 struct inferior
*inf
= current_inferior ();
5799 --inf
->total_syscalls_count
;
5800 if (!b
->syscalls_to_be_caught
)
5801 --inf
->any_syscall_count
;
5806 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5810 if (iter
>= VEC_length (int, inf
->syscalls_counts
))
5811 /* Shouldn't happen. */
5813 elem
= VEC_index (int, inf
->syscalls_counts
, iter
);
5814 VEC_replace (int, inf
->syscalls_counts
, iter
, --elem
);
5818 return target_set_syscall_catchpoint (PIDGET (inferior_ptid
),
5819 inf
->total_syscalls_count
!= 0,
5820 inf
->any_syscall_count
,
5821 VEC_length (int, inf
->syscalls_counts
),
5822 VEC_address (int, inf
->syscalls_counts
));
5825 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
5829 breakpoint_hit_catch_syscall (struct breakpoint
*b
)
5831 /* We must check if we are catching specific syscalls in this breakpoint.
5832 If we are, then we must guarantee that the called syscall is the same
5833 syscall we are catching. */
5834 int syscall_number
= 0;
5836 if (!inferior_has_called_syscall (inferior_ptid
, &syscall_number
))
5839 /* Now, checking if the syscall is the same. */
5840 if (b
->syscalls_to_be_caught
)
5844 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5846 if (syscall_number
== iter
)
5856 /* Implement the "print_it" breakpoint_ops method for syscall
5859 static enum print_stop_action
5860 print_it_catch_syscall (struct breakpoint
*b
)
5862 /* These are needed because we want to know in which state a
5863 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
5864 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we
5865 must print "called syscall" or "returned from syscall". */
5867 struct target_waitstatus last
;
5869 struct cleanup
*old_chain
;
5872 get_last_target_status (&ptid
, &last
);
5874 get_syscall_by_number (last
.value
.syscall_number
, &s
);
5876 annotate_catchpoint (b
->number
);
5879 syscall_id
= xstrprintf ("%d", last
.value
.syscall_number
);
5881 syscall_id
= xstrprintf ("'%s'", s
.name
);
5883 old_chain
= make_cleanup (xfree
, syscall_id
);
5885 if (last
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
)
5886 printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
5887 b
->number
, syscall_id
);
5888 else if (last
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
5889 printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
5890 b
->number
, syscall_id
);
5892 do_cleanups (old_chain
);
5894 return PRINT_SRC_AND_LOC
;
5897 /* Implement the "print_one" breakpoint_ops method for syscall
5901 print_one_catch_syscall (struct breakpoint
*b
,
5902 struct bp_location
**last_loc
)
5904 struct value_print_options opts
;
5906 get_user_print_options (&opts
);
5907 /* Field 4, the address, is omitted (which makes the columns
5908 not line up too nicely with the headers, but the effect
5909 is relatively readable). */
5910 if (opts
.addressprint
)
5911 ui_out_field_skip (uiout
, "addr");
5914 if (b
->syscalls_to_be_caught
5915 && VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5916 ui_out_text (uiout
, "syscalls \"");
5918 ui_out_text (uiout
, "syscall \"");
5920 if (b
->syscalls_to_be_caught
)
5923 char *text
= xstrprintf ("%s", "");
5925 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5930 get_syscall_by_number (iter
, &s
);
5933 text
= xstrprintf ("%s%s, ", text
, s
.name
);
5935 text
= xstrprintf ("%s%d, ", text
, iter
);
5937 /* We have to xfree the last 'text' (now stored at 'x')
5938 because xstrprintf dinamically allocates new space for it
5942 /* Remove the last comma. */
5943 text
[strlen (text
) - 2] = '\0';
5944 ui_out_field_string (uiout
, "what", text
);
5947 ui_out_field_string (uiout
, "what", "<any syscall>");
5948 ui_out_text (uiout
, "\" ");
5951 /* Implement the "print_mention" breakpoint_ops method for syscall
5955 print_mention_catch_syscall (struct breakpoint
*b
)
5957 if (b
->syscalls_to_be_caught
)
5961 if (VEC_length (int, b
->syscalls_to_be_caught
) > 1)
5962 printf_filtered (_("Catchpoint %d (syscalls"), b
->number
);
5964 printf_filtered (_("Catchpoint %d (syscall"), b
->number
);
5967 VEC_iterate (int, b
->syscalls_to_be_caught
, i
, iter
);
5971 get_syscall_by_number (iter
, &s
);
5974 printf_filtered (" '%s' [%d]", s
.name
, s
.number
);
5976 printf_filtered (" %d", s
.number
);
5978 printf_filtered (")");
5981 printf_filtered (_("Catchpoint %d (any syscall)"),
5985 /* The breakpoint_ops structure to be used in syscall catchpoints. */
5987 static struct breakpoint_ops catch_syscall_breakpoint_ops
=
5989 insert_catch_syscall
,
5990 remove_catch_syscall
,
5991 breakpoint_hit_catch_syscall
,
5992 print_it_catch_syscall
,
5993 print_one_catch_syscall
,
5994 print_mention_catch_syscall
5997 /* Returns non-zero if 'b' is a syscall catchpoint. */
6000 syscall_catchpoint_p (struct breakpoint
*b
)
6002 return (b
->ops
== &catch_syscall_breakpoint_ops
);
6005 /* Create a new breakpoint of the bp_catchpoint kind and return it,
6006 but does NOT mention it nor update the global location list.
6007 This is useful if you need to fill more fields in the
6008 struct breakpoint before calling mention.
6010 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6011 If COND_STRING is not NULL, then store it in the breakpoint.
6012 OPS, if not NULL, is the breakpoint_ops structure associated
6013 to the catchpoint. */
6015 static struct breakpoint
*
6016 create_catchpoint_without_mention (struct gdbarch
*gdbarch
, int tempflag
,
6018 struct breakpoint_ops
*ops
)
6020 struct symtab_and_line sal
;
6021 struct breakpoint
*b
;
6024 sal
.pspace
= current_program_space
;
6026 b
= set_raw_breakpoint (gdbarch
, sal
, bp_catchpoint
);
6027 set_breakpoint_count (breakpoint_count
+ 1);
6028 b
->number
= breakpoint_count
;
6030 b
->cond_string
= (cond_string
== NULL
) ? NULL
: xstrdup (cond_string
);
6032 b
->addr_string
= NULL
;
6033 b
->enable_state
= bp_enabled
;
6034 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6040 /* Create a new breakpoint of the bp_catchpoint kind and return it.
6042 If TEMPFLAG is non-zero, then make the breakpoint temporary.
6043 If COND_STRING is not NULL, then store it in the breakpoint.
6044 OPS, if not NULL, is the breakpoint_ops structure associated
6045 to the catchpoint. */
6047 static struct breakpoint
*
6048 create_catchpoint (struct gdbarch
*gdbarch
, int tempflag
,
6049 char *cond_string
, struct breakpoint_ops
*ops
)
6051 struct breakpoint
*b
=
6052 create_catchpoint_without_mention (gdbarch
, tempflag
, cond_string
, ops
);
6055 update_global_location_list (1);
6061 create_fork_vfork_event_catchpoint (struct gdbarch
*gdbarch
,
6062 int tempflag
, char *cond_string
,
6063 struct breakpoint_ops
*ops
)
6065 struct breakpoint
*b
6066 = create_catchpoint (gdbarch
, tempflag
, cond_string
, ops
);
6068 /* FIXME: We should put this information in a breakpoint private data
6070 b
->forked_inferior_pid
= null_ptid
;
6073 /* Exec catchpoints. */
6076 insert_catch_exec (struct breakpoint
*b
)
6078 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
6082 remove_catch_exec (struct breakpoint
*b
)
6084 return target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
6088 breakpoint_hit_catch_exec (struct breakpoint
*b
)
6090 return inferior_has_execd (inferior_ptid
, &b
->exec_pathname
);
6093 static enum print_stop_action
6094 print_it_catch_exec (struct breakpoint
*b
)
6096 annotate_catchpoint (b
->number
);
6097 printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b
->number
,
6099 return PRINT_SRC_AND_LOC
;
6103 print_one_catch_exec (struct breakpoint
*b
, struct bp_location
**last_loc
)
6105 struct value_print_options opts
;
6107 get_user_print_options (&opts
);
6109 /* Field 4, the address, is omitted (which makes the columns
6110 not line up too nicely with the headers, but the effect
6111 is relatively readable). */
6112 if (opts
.addressprint
)
6113 ui_out_field_skip (uiout
, "addr");
6115 ui_out_text (uiout
, "exec");
6116 if (b
->exec_pathname
!= NULL
)
6118 ui_out_text (uiout
, ", program \"");
6119 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
6120 ui_out_text (uiout
, "\" ");
6125 print_mention_catch_exec (struct breakpoint
*b
)
6127 printf_filtered (_("Catchpoint %d (exec)"), b
->number
);
6130 static struct breakpoint_ops catch_exec_breakpoint_ops
=
6134 breakpoint_hit_catch_exec
,
6135 print_it_catch_exec
,
6136 print_one_catch_exec
,
6137 print_mention_catch_exec
6141 create_syscall_event_catchpoint (int tempflag
, VEC(int) *filter
,
6142 struct breakpoint_ops
*ops
)
6144 struct gdbarch
*gdbarch
= get_current_arch ();
6145 struct breakpoint
*b
=
6146 create_catchpoint_without_mention (gdbarch
, tempflag
, NULL
, ops
);
6148 b
->syscalls_to_be_caught
= filter
;
6150 /* Now, we have to mention the breakpoint and update the global
6153 update_global_location_list (1);
6157 hw_breakpoint_used_count (void)
6159 struct breakpoint
*b
;
6164 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
6172 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
6174 struct breakpoint
*b
;
6177 *other_type_used
= 0;
6180 if (breakpoint_enabled (b
))
6182 if (b
->type
== type
)
6184 else if ((b
->type
== bp_hardware_watchpoint
6185 || b
->type
== bp_read_watchpoint
6186 || b
->type
== bp_access_watchpoint
))
6187 *other_type_used
= 1;
6194 disable_watchpoints_before_interactive_call_start (void)
6196 struct breakpoint
*b
;
6200 if (((b
->type
== bp_watchpoint
)
6201 || (b
->type
== bp_hardware_watchpoint
)
6202 || (b
->type
== bp_read_watchpoint
)
6203 || (b
->type
== bp_access_watchpoint
))
6204 && breakpoint_enabled (b
))
6206 b
->enable_state
= bp_call_disabled
;
6207 update_global_location_list (0);
6213 enable_watchpoints_after_interactive_call_stop (void)
6215 struct breakpoint
*b
;
6219 if (((b
->type
== bp_watchpoint
)
6220 || (b
->type
== bp_hardware_watchpoint
)
6221 || (b
->type
== bp_read_watchpoint
)
6222 || (b
->type
== bp_access_watchpoint
))
6223 && (b
->enable_state
== bp_call_disabled
))
6225 b
->enable_state
= bp_enabled
;
6226 update_global_location_list (1);
6232 disable_breakpoints_before_startup (void)
6234 struct breakpoint
*b
;
6239 if (b
->pspace
!= current_program_space
)
6242 if ((b
->type
== bp_breakpoint
6243 || b
->type
== bp_hardware_breakpoint
)
6244 && breakpoint_enabled (b
))
6246 b
->enable_state
= bp_startup_disabled
;
6252 update_global_location_list (0);
6254 current_program_space
->executing_startup
= 1;
6258 enable_breakpoints_after_startup (void)
6260 struct breakpoint
*b
;
6263 current_program_space
->executing_startup
= 0;
6267 if (b
->pspace
!= current_program_space
)
6270 if ((b
->type
== bp_breakpoint
6271 || b
->type
== bp_hardware_breakpoint
)
6272 && b
->enable_state
== bp_startup_disabled
)
6274 b
->enable_state
= bp_enabled
;
6280 breakpoint_re_set ();
6284 /* Set a breakpoint that will evaporate an end of command
6285 at address specified by SAL.
6286 Restrict it to frame FRAME if FRAME is nonzero. */
6289 set_momentary_breakpoint (struct gdbarch
*gdbarch
, struct symtab_and_line sal
,
6290 struct frame_id frame_id
, enum bptype type
)
6292 struct breakpoint
*b
;
6294 /* If FRAME_ID is valid, it should be a real frame, not an inlined
6296 gdb_assert (!frame_id_inlined_p (frame_id
));
6298 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6299 b
->enable_state
= bp_enabled
;
6300 b
->disposition
= disp_donttouch
;
6301 b
->frame_id
= frame_id
;
6303 /* If we're debugging a multi-threaded program, then we
6304 want momentary breakpoints to be active in only a
6305 single thread of control. */
6306 if (in_thread_list (inferior_ptid
))
6307 b
->thread
= pid_to_thread_id (inferior_ptid
);
6309 update_global_location_list_nothrow (1);
6314 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if
6318 clone_momentary_breakpoint (struct breakpoint
*orig
)
6320 struct breakpoint
*copy
;
6322 /* If there's nothing to clone, then return nothing. */
6326 copy
= set_raw_breakpoint_without_location (orig
->gdbarch
, orig
->type
);
6327 copy
->loc
= allocate_bp_location (copy
);
6328 set_breakpoint_location_function (copy
->loc
);
6330 copy
->loc
->gdbarch
= orig
->loc
->gdbarch
;
6331 copy
->loc
->requested_address
= orig
->loc
->requested_address
;
6332 copy
->loc
->address
= orig
->loc
->address
;
6333 copy
->loc
->section
= orig
->loc
->section
;
6334 copy
->loc
->pspace
= orig
->loc
->pspace
;
6336 if (orig
->source_file
== NULL
)
6337 copy
->source_file
= NULL
;
6339 copy
->source_file
= xstrdup (orig
->source_file
);
6341 copy
->line_number
= orig
->line_number
;
6342 copy
->frame_id
= orig
->frame_id
;
6343 copy
->thread
= orig
->thread
;
6344 copy
->pspace
= orig
->pspace
;
6346 copy
->enable_state
= bp_enabled
;
6347 copy
->disposition
= disp_donttouch
;
6348 copy
->number
= internal_breakpoint_number
--;
6350 update_global_location_list_nothrow (0);
6355 set_momentary_breakpoint_at_pc (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
6358 struct symtab_and_line sal
;
6360 sal
= find_pc_line (pc
, 0);
6362 sal
.section
= find_pc_overlay (pc
);
6363 sal
.explicit_pc
= 1;
6365 return set_momentary_breakpoint (gdbarch
, sal
, null_frame_id
, type
);
6369 /* Tell the user we have just set a breakpoint B. */
6372 mention (struct breakpoint
*b
)
6375 struct cleanup
*ui_out_chain
;
6376 struct value_print_options opts
;
6378 get_user_print_options (&opts
);
6380 /* FIXME: This is misplaced; mention() is called by things (like
6381 hitting a watchpoint) other than breakpoint creation. It should
6382 be possible to clean this up and at the same time replace the
6383 random calls to breakpoint_changed with this hook. */
6384 observer_notify_breakpoint_created (b
->number
);
6386 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
6387 b
->ops
->print_mention (b
);
6392 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
6395 ui_out_text (uiout
, "Watchpoint ");
6396 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6397 ui_out_field_int (uiout
, "number", b
->number
);
6398 ui_out_text (uiout
, ": ");
6399 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6400 do_cleanups (ui_out_chain
);
6402 case bp_hardware_watchpoint
:
6403 ui_out_text (uiout
, "Hardware watchpoint ");
6404 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
6405 ui_out_field_int (uiout
, "number", b
->number
);
6406 ui_out_text (uiout
, ": ");
6407 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6408 do_cleanups (ui_out_chain
);
6410 case bp_read_watchpoint
:
6411 ui_out_text (uiout
, "Hardware read watchpoint ");
6412 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
6413 ui_out_field_int (uiout
, "number", b
->number
);
6414 ui_out_text (uiout
, ": ");
6415 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6416 do_cleanups (ui_out_chain
);
6418 case bp_access_watchpoint
:
6419 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
6420 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
6421 ui_out_field_int (uiout
, "number", b
->number
);
6422 ui_out_text (uiout
, ": ");
6423 ui_out_field_string (uiout
, "exp", b
->exp_string
);
6424 do_cleanups (ui_out_chain
);
6427 if (ui_out_is_mi_like_p (uiout
))
6432 if (b
->disposition
== disp_del
)
6433 printf_filtered (_("Temporary breakpoint"));
6435 printf_filtered (_("Breakpoint"));
6436 printf_filtered (_(" %d"), b
->number
);
6439 case bp_hardware_breakpoint
:
6440 if (ui_out_is_mi_like_p (uiout
))
6445 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
6449 if (ui_out_is_mi_like_p (uiout
))
6454 printf_filtered (_("Tracepoint"));
6455 printf_filtered (_(" %d"), b
->number
);
6458 case bp_fast_tracepoint
:
6459 if (ui_out_is_mi_like_p (uiout
))
6464 printf_filtered (_("Fast tracepoint"));
6465 printf_filtered (_(" %d"), b
->number
);
6472 case bp_longjmp_resume
:
6473 case bp_step_resume
:
6475 case bp_watchpoint_scope
:
6476 case bp_shlib_event
:
6477 case bp_thread_event
:
6478 case bp_overlay_event
:
6480 case bp_longjmp_master
:
6486 /* i18n: cagney/2005-02-11: Below needs to be merged into a
6490 printf_filtered (_(" (%s) pending."), b
->addr_string
);
6494 if (opts
.addressprint
|| b
->source_file
== NULL
)
6496 printf_filtered (" at ");
6497 fputs_filtered (paddress (b
->loc
->gdbarch
, b
->loc
->address
),
6501 printf_filtered (": file %s, line %d.",
6502 b
->source_file
, b
->line_number
);
6506 struct bp_location
*loc
= b
->loc
;
6508 for (; loc
; loc
= loc
->next
)
6510 printf_filtered (" (%d locations)", n
);
6515 if (ui_out_is_mi_like_p (uiout
))
6517 printf_filtered ("\n");
6521 static struct bp_location
*
6522 add_location_to_breakpoint (struct breakpoint
*b
,
6523 const struct symtab_and_line
*sal
)
6525 struct bp_location
*loc
, **tmp
;
6527 loc
= allocate_bp_location (b
);
6528 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
6531 loc
->gdbarch
= get_sal_arch (*sal
);
6533 loc
->gdbarch
= b
->gdbarch
;
6534 loc
->requested_address
= sal
->pc
;
6535 loc
->address
= adjust_breakpoint_address (loc
->gdbarch
,
6536 loc
->requested_address
, b
->type
);
6537 loc
->pspace
= sal
->pspace
;
6538 gdb_assert (loc
->pspace
!= NULL
);
6539 loc
->section
= sal
->section
;
6541 set_breakpoint_location_function (loc
);
6546 /* Return 1 if LOC is pointing to a permanent breakpoint,
6547 return 0 otherwise. */
6550 bp_loc_is_permanent (struct bp_location
*loc
)
6554 const gdb_byte
*brk
;
6555 gdb_byte
*target_mem
;
6556 struct cleanup
*cleanup
;
6559 gdb_assert (loc
!= NULL
);
6561 addr
= loc
->address
;
6562 brk
= gdbarch_breakpoint_from_pc (loc
->gdbarch
, &addr
, &len
);
6564 /* Software breakpoints unsupported? */
6568 target_mem
= alloca (len
);
6570 /* Enable the automatic memory restoration from breakpoints while
6571 we read the memory. Otherwise we could say about our temporary
6572 breakpoints they are permanent. */
6573 cleanup
= save_current_space_and_thread ();
6575 switch_to_program_space_and_thread (loc
->pspace
);
6576 make_show_memory_breakpoints_cleanup (0);
6578 if (target_read_memory (loc
->address
, target_mem
, len
) == 0
6579 && memcmp (target_mem
, brk
, len
) == 0)
6582 do_cleanups (cleanup
);
6589 /* Create a breakpoint with SAL as location. Use ADDR_STRING
6590 as textual description of the location, and COND_STRING
6591 as condition expression. */
6594 create_breakpoint_sal (struct gdbarch
*gdbarch
,
6595 struct symtabs_and_lines sals
, char *addr_string
,
6597 enum bptype type
, enum bpdisp disposition
,
6598 int thread
, int task
, int ignore_count
,
6599 struct breakpoint_ops
*ops
, int from_tty
, int enabled
)
6601 struct breakpoint
*b
= NULL
;
6604 if (type
== bp_hardware_breakpoint
)
6606 int i
= hw_breakpoint_used_count ();
6607 int target_resources_ok
=
6608 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
6610 if (target_resources_ok
== 0)
6611 error (_("No hardware breakpoint support in the target."));
6612 else if (target_resources_ok
< 0)
6613 error (_("Hardware breakpoints used exceeds limit."));
6616 gdb_assert (sals
.nelts
> 0);
6618 for (i
= 0; i
< sals
.nelts
; ++i
)
6620 struct symtab_and_line sal
= sals
.sals
[i
];
6621 struct bp_location
*loc
;
6625 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
6627 loc_gdbarch
= gdbarch
;
6629 describe_other_breakpoints (loc_gdbarch
,
6630 sal
.pspace
, sal
.pc
, sal
.section
, thread
);
6635 b
= set_raw_breakpoint (gdbarch
, sal
, type
);
6636 set_breakpoint_count (breakpoint_count
+ 1);
6637 b
->number
= breakpoint_count
;
6641 b
->cond_string
= cond_string
;
6642 b
->ignore_count
= ignore_count
;
6643 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
6644 b
->disposition
= disposition
;
6646 b
->pspace
= sals
.sals
[0].pspace
;
6648 if (enabled
&& b
->pspace
->executing_startup
6649 && (b
->type
== bp_breakpoint
6650 || b
->type
== bp_hardware_breakpoint
))
6651 b
->enable_state
= bp_startup_disabled
;
6657 loc
= add_location_to_breakpoint (b
, &sal
);
6660 if (bp_loc_is_permanent (loc
))
6661 make_breakpoint_permanent (b
);
6665 char *arg
= b
->cond_string
;
6666 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
6668 error (_("Garbage %s follows condition"), arg
);
6673 b
->addr_string
= addr_string
;
6675 /* addr_string has to be used or breakpoint_re_set will delete
6678 = xstrprintf ("*%s", paddress (b
->loc
->gdbarch
, b
->loc
->address
));
6684 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
6685 elements to fill the void space. */
6687 remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
6689 int i
= index_to_remove
+1;
6690 int last_index
= sal
->nelts
-1;
6692 for (;i
<= last_index
; ++i
)
6693 sal
->sals
[i
-1] = sal
->sals
[i
];
6698 /* If appropriate, obtains all sals that correspond to the same file
6699 and line as SAL, in all program spaces. Users debugging with IDEs,
6700 will want to set a breakpoint at foo.c:line, and not really care
6701 about program spaces. This is done only if SAL does not have
6702 explicit PC and has line and file information. If we got just a
6703 single expanded sal, return the original.
6705 Otherwise, if SAL.explicit_line is not set, filter out all sals for
6706 which the name of enclosing function is different from SAL. This
6707 makes sure that if we have breakpoint originally set in template
6708 instantiation, say foo<int>(), we won't expand SAL to locations at
6709 the same line in all existing instantiations of 'foo'. */
6711 static struct symtabs_and_lines
6712 expand_line_sal_maybe (struct symtab_and_line sal
)
6714 struct symtabs_and_lines expanded
;
6715 CORE_ADDR original_pc
= sal
.pc
;
6716 char *original_function
= NULL
;
6719 struct cleanup
*old_chain
;
6721 /* If we have explicit pc, don't expand.
6722 If we have no line number, we can't expand. */
6723 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
6726 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6727 expanded
.sals
[0] = sal
;
6733 old_chain
= save_current_space_and_thread ();
6735 switch_to_program_space_and_thread (sal
.pspace
);
6737 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
6739 /* Note that expand_line_sal visits *all* program spaces. */
6740 expanded
= expand_line_sal (sal
);
6742 if (expanded
.nelts
== 1)
6744 /* We had one sal, we got one sal. Return that sal, adjusting it
6745 past the function prologue if necessary. */
6746 xfree (expanded
.sals
);
6748 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6749 sal
.pc
= original_pc
;
6750 expanded
.sals
[0] = sal
;
6751 skip_prologue_sal (&expanded
.sals
[0]);
6752 do_cleanups (old_chain
);
6756 if (!sal
.explicit_line
)
6758 CORE_ADDR func_addr
, func_end
;
6759 for (i
= 0; i
< expanded
.nelts
; ++i
)
6761 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
6762 char *this_function
;
6764 /* We need to switch threads as well since we're about to
6766 switch_to_program_space_and_thread (expanded
.sals
[i
].pspace
);
6768 if (find_pc_partial_function (pc
, &this_function
,
6769 &func_addr
, &func_end
))
6772 && strcmp (this_function
, original_function
) != 0)
6774 remove_sal (&expanded
, i
);
6777 else if (func_addr
== pc
)
6779 /* We're at beginning of a function, and should
6781 struct symbol
*sym
= find_pc_function (pc
);
6783 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
6786 /* Since find_pc_partial_function returned true,
6787 we should really always find the section here. */
6788 struct obj_section
*section
= find_pc_section (pc
);
6791 struct gdbarch
*gdbarch
6792 = get_objfile_arch (section
->objfile
);
6794 = gdbarch_skip_prologue (gdbarch
, pc
);
6803 for (i
= 0; i
< expanded
.nelts
; ++i
)
6805 /* If this SAL corresponds to a breakpoint inserted using a
6806 line number, then skip the function prologue if necessary. */
6807 skip_prologue_sal (&expanded
.sals
[i
]);
6811 do_cleanups (old_chain
);
6813 if (expanded
.nelts
<= 1)
6815 /* This is un ugly workaround. If we get zero
6816 expanded sals then something is really wrong.
6817 Fix that by returnign the original sal. */
6818 xfree (expanded
.sals
);
6820 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
6821 sal
.pc
= original_pc
;
6822 expanded
.sals
[0] = sal
;
6829 for (i
= 0; i
< expanded
.nelts
; ++i
)
6830 if (expanded
.sals
[i
].pc
== original_pc
)
6841 /* Add SALS.nelts breakpoints to the breakpoint table. For each
6842 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
6843 value. COND_STRING, if not NULL, specified the condition to be
6844 used for all breakpoints. Essentially the only case where
6845 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
6846 function. In that case, it's still not possible to specify
6847 separate conditions for different overloaded functions, so
6848 we take just a single condition string.
6850 NOTE: If the function succeeds, the caller is expected to cleanup
6851 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
6852 array contents). If the function fails (error() is called), the
6853 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
6854 COND and SALS arrays and each of those arrays contents. */
6857 create_breakpoints_sal (struct gdbarch
*gdbarch
,
6858 struct symtabs_and_lines sals
, char **addr_string
,
6860 enum bptype type
, enum bpdisp disposition
,
6861 int thread
, int task
, int ignore_count
,
6862 struct breakpoint_ops
*ops
, int from_tty
,
6866 for (i
= 0; i
< sals
.nelts
; ++i
)
6868 struct symtabs_and_lines expanded
=
6869 expand_line_sal_maybe (sals
.sals
[i
]);
6871 create_breakpoint_sal (gdbarch
, expanded
, addr_string
[i
],
6872 cond_string
, type
, disposition
,
6873 thread
, task
, ignore_count
, ops
, from_tty
, enabled
);
6877 /* Parse ARG which is assumed to be a SAL specification possibly
6878 followed by conditionals. On return, SALS contains an array of SAL
6879 addresses found. ADDR_STRING contains a vector of (canonical)
6880 address strings. ARG points to the end of the SAL. */
6883 parse_breakpoint_sals (char **address
,
6884 struct symtabs_and_lines
*sals
,
6885 char ***addr_string
,
6888 char *addr_start
= *address
;
6889 *addr_string
= NULL
;
6890 /* If no arg given, or if first arg is 'if ', use the default
6892 if ((*address
) == NULL
6893 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
6895 if (default_breakpoint_valid
)
6897 struct symtab_and_line sal
;
6898 init_sal (&sal
); /* initialize to zeroes */
6899 sals
->sals
= (struct symtab_and_line
*)
6900 xmalloc (sizeof (struct symtab_and_line
));
6901 sal
.pc
= default_breakpoint_address
;
6902 sal
.line
= default_breakpoint_line
;
6903 sal
.symtab
= default_breakpoint_symtab
;
6904 sal
.pspace
= default_breakpoint_pspace
;
6905 sal
.section
= find_pc_overlay (sal
.pc
);
6907 /* "break" without arguments is equivalent to "break *PC" where PC is
6908 the default_breakpoint_address. So make sure to set
6909 sal.explicit_pc to prevent GDB from trying to expand the list of
6910 sals to include all other instances with the same symtab and line.
6912 sal
.explicit_pc
= 1;
6914 sals
->sals
[0] = sal
;
6918 error (_("No default breakpoint address now."));
6922 /* Force almost all breakpoints to be in terms of the
6923 current_source_symtab (which is decode_line_1's default). This
6924 should produce the results we want almost all of the time while
6925 leaving default_breakpoint_* alone.
6926 ObjC: However, don't match an Objective-C method name which
6927 may have a '+' or '-' succeeded by a '[' */
6929 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
6931 if (default_breakpoint_valid
6933 || ((strchr ("+-", (*address
)[0]) != NULL
)
6934 && ((*address
)[1] != '['))))
6935 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
6936 default_breakpoint_line
, addr_string
,
6939 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
6940 addr_string
, not_found_ptr
);
6942 /* For any SAL that didn't have a canonical string, fill one in. */
6943 if (sals
->nelts
> 0 && *addr_string
== NULL
)
6944 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
6945 if (addr_start
!= (*address
))
6948 for (i
= 0; i
< sals
->nelts
; i
++)
6950 /* Add the string if not present. */
6951 if ((*addr_string
)[i
] == NULL
)
6952 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
6958 /* Convert each SAL into a real PC. Verify that the PC can be
6959 inserted as a breakpoint. If it can't throw an error. */
6962 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
6966 for (i
= 0; i
< sals
->nelts
; i
++)
6967 resolve_sal_pc (&sals
->sals
[i
]);
6970 /* Fast tracepoints may have restrictions on valid locations. For
6971 instance, a fast tracepoint using a jump instead of a trap will
6972 likely have to overwrite more bytes than a trap would, and so can
6973 only be placed where the instruction is longer than the jump, or a
6974 multi-instruction sequence does not have a jump into the middle of
6978 check_fast_tracepoint_sals (struct gdbarch
*gdbarch
,
6979 struct symtabs_and_lines
*sals
)
6982 struct symtab_and_line
*sal
;
6984 struct cleanup
*old_chain
;
6986 for (i
= 0; i
< sals
->nelts
; i
++)
6988 sal
= &sals
->sals
[i
];
6990 rslt
= gdbarch_fast_tracepoint_valid_at (gdbarch
, sal
->pc
,
6992 old_chain
= make_cleanup (xfree
, msg
);
6995 error (_("May not have a fast tracepoint at 0x%s%s"),
6996 paddress (gdbarch
, sal
->pc
), (msg
? msg
: ""));
6998 do_cleanups (old_chain
);
7003 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
7005 struct captured_parse_breakpoint_args
*args
= data
;
7007 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
7008 args
->not_found_ptr
);
7011 /* Given TOK, a string specification of condition and thread, as
7012 accepted by the 'break' command, extract the condition
7013 string and thread number and set *COND_STRING and *THREAD.
7014 PC identifies the context at which the condition should be parsed.
7015 If no condition is found, *COND_STRING is set to NULL.
7016 If no thread is found, *THREAD is set to -1. */
7018 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
7019 char **cond_string
, int *thread
, int *task
)
7021 *cond_string
= NULL
;
7027 char *cond_start
= NULL
;
7028 char *cond_end
= NULL
;
7029 while (*tok
== ' ' || *tok
== '\t')
7034 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7037 toklen
= end_tok
- tok
;
7039 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7041 struct expression
*expr
;
7043 tok
= cond_start
= end_tok
+ 1;
7044 expr
= parse_exp_1 (&tok
, block_for_pc (pc
), 0);
7047 *cond_string
= savestring (cond_start
,
7048 cond_end
- cond_start
);
7050 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7056 *thread
= strtol (tok
, &tok
, 0);
7058 error (_("Junk after thread keyword."));
7059 if (!valid_thread_id (*thread
))
7060 error (_("Unknown thread %d."), *thread
);
7062 else if (toklen
>= 1 && strncmp (tok
, "task", toklen
) == 0)
7068 *task
= strtol (tok
, &tok
, 0);
7070 error (_("Junk after task keyword."));
7071 if (!valid_task_id (*task
))
7072 error (_("Unknown task %d."), *task
);
7075 error (_("Junk at end of arguments."));
7079 /* Set a breakpoint. This function is shared between CLI and MI
7080 functions for setting a breakpoint. This function has two major
7081 modes of operations, selected by the PARSE_CONDITION_AND_THREAD
7082 parameter. If non-zero, the function will parse arg, extracting
7083 breakpoint location, address and thread. Otherwise, ARG is just the
7084 location of breakpoint, with condition and thread specified by the
7085 COND_STRING and THREAD parameters. Returns true if any breakpoint
7086 was created; false otherwise. */
7089 create_breakpoint (struct gdbarch
*gdbarch
,
7090 char *arg
, char *cond_string
, int thread
,
7091 int parse_condition_and_thread
,
7092 int tempflag
, int hardwareflag
, int traceflag
,
7094 enum auto_boolean pending_break_support
,
7095 struct breakpoint_ops
*ops
,
7099 struct gdb_exception e
;
7100 struct symtabs_and_lines sals
;
7101 struct symtab_and_line pending_sal
;
7104 char *addr_start
= arg
;
7106 struct cleanup
*old_chain
;
7107 struct cleanup
*bkpt_chain
= NULL
;
7108 struct captured_parse_breakpoint_args parse_args
;
7112 enum bptype type_wanted
;
7119 parse_args
.arg_p
= &arg
;
7120 parse_args
.sals_p
= &sals
;
7121 parse_args
.addr_string_p
= &addr_string
;
7122 parse_args
.not_found_ptr
= ¬_found
;
7124 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
7125 &parse_args
, RETURN_MASK_ALL
);
7127 /* If caller is interested in rc value from parse, set value. */
7131 throw_exception (e
);
7135 case NOT_FOUND_ERROR
:
7137 /* If pending breakpoint support is turned off, throw
7140 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
7141 throw_exception (e
);
7143 exception_print (gdb_stderr
, e
);
7145 /* If pending breakpoint support is auto query and the user
7146 selects no, then simply return the error code. */
7147 if (pending_break_support
== AUTO_BOOLEAN_AUTO
7148 && !nquery ("Make breakpoint pending on future shared library load? "))
7151 /* At this point, either the user was queried about setting
7152 a pending breakpoint and selected yes, or pending
7153 breakpoint behavior is on and thus a pending breakpoint
7154 is defaulted on behalf of the user. */
7155 copy_arg
= xstrdup (addr_start
);
7156 addr_string
= ©_arg
;
7158 sals
.sals
= &pending_sal
;
7163 throw_exception (e
);
7170 /* Create a chain of things that always need to be cleaned up. */
7171 old_chain
= make_cleanup (null_cleanup
, 0);
7175 /* Make sure that all storage allocated to SALS gets freed. */
7176 make_cleanup (xfree
, sals
.sals
);
7178 /* Cleanup the addr_string array but not its contents. */
7179 make_cleanup (xfree
, addr_string
);
7182 /* ----------------------------- SNIP -----------------------------
7183 Anything added to the cleanup chain beyond this point is assumed
7184 to be part of a breakpoint. If the breakpoint create succeeds
7185 then the memory is not reclaimed. */
7186 bkpt_chain
= make_cleanup (null_cleanup
, 0);
7188 /* Mark the contents of the addr_string for cleanup. These go on
7189 the bkpt_chain and only occur if the breakpoint create fails. */
7190 for (i
= 0; i
< sals
.nelts
; i
++)
7192 if (addr_string
[i
] != NULL
)
7193 make_cleanup (xfree
, addr_string
[i
]);
7196 /* Resolve all line numbers to PC's and verify that the addresses
7197 are ok for the target. */
7199 breakpoint_sals_to_pc (&sals
, addr_start
);
7201 type_wanted
= (traceflag
7202 ? (hardwareflag
? bp_fast_tracepoint
: bp_tracepoint
)
7203 : (hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
));
7205 /* Fast tracepoints may have additional restrictions on location. */
7206 if (type_wanted
== bp_fast_tracepoint
)
7207 check_fast_tracepoint_sals (gdbarch
, &sals
);
7209 /* Verify that condition can be parsed, before setting any
7210 breakpoints. Allocate a separate condition expression for each
7214 if (parse_condition_and_thread
)
7216 /* Here we only parse 'arg' to separate condition
7217 from thread number, so parsing in context of first
7218 sal is OK. When setting the breakpoint we'll
7219 re-parse it in context of each sal. */
7222 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
,
7225 make_cleanup (xfree
, cond_string
);
7229 /* Create a private copy of condition string. */
7232 cond_string
= xstrdup (cond_string
);
7233 make_cleanup (xfree
, cond_string
);
7236 create_breakpoints_sal (gdbarch
, sals
, addr_string
, cond_string
,
7237 type_wanted
, tempflag
? disp_del
: disp_donttouch
,
7238 thread
, task
, ignore_count
, ops
, from_tty
,
7243 struct symtab_and_line sal
= {0};
7244 struct breakpoint
*b
;
7246 make_cleanup (xfree
, copy_arg
);
7248 b
= set_raw_breakpoint_without_location (gdbarch
, type_wanted
);
7249 set_breakpoint_count (breakpoint_count
+ 1);
7250 b
->number
= breakpoint_count
;
7252 b
->addr_string
= addr_string
[0];
7253 b
->cond_string
= NULL
;
7254 b
->ignore_count
= ignore_count
;
7255 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
7256 b
->condition_not_parsed
= 1;
7258 b
->enable_state
= enabled
? bp_enabled
: bp_disabled
;
7259 b
->pspace
= current_program_space
;
7261 if (enabled
&& b
->pspace
->executing_startup
7262 && (b
->type
== bp_breakpoint
7263 || b
->type
== bp_hardware_breakpoint
))
7264 b
->enable_state
= bp_startup_disabled
;
7270 warning (_("Multiple breakpoints were set.\n"
7271 "Use the \"delete\" command to delete unwanted breakpoints."));
7272 /* That's it. Discard the cleanups for data inserted into the
7274 discard_cleanups (bkpt_chain
);
7275 /* But cleanup everything else. */
7276 do_cleanups (old_chain
);
7278 /* error call may happen here - have BKPT_CHAIN already discarded. */
7279 update_global_location_list (1);
7284 /* Set a breakpoint.
7285 ARG is a string describing breakpoint address,
7286 condition, and thread.
7287 FLAG specifies if a breakpoint is hardware on,
7288 and if breakpoint is temporary, using BP_HARDWARE_FLAG
7292 break_command_1 (char *arg
, int flag
, int from_tty
)
7294 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
7295 int tempflag
= flag
& BP_TEMPFLAG
;
7297 create_breakpoint (get_current_arch (),
7299 NULL
, 0, 1 /* parse arg */,
7300 tempflag
, hardwareflag
, 0 /* traceflag */,
7301 0 /* Ignore count */,
7302 pending_break_support
,
7303 NULL
/* breakpoint_ops */,
7310 /* Adjust SAL to the first instruction past the function prologue.
7311 The end of the prologue is determined using the line table from
7312 the debugging information. explicit_pc and explicit_line are
7315 If SAL is already past the prologue, then do nothing. */
7318 skip_prologue_sal (struct symtab_and_line
*sal
)
7321 struct symtab_and_line start_sal
;
7322 struct cleanup
*old_chain
;
7324 old_chain
= save_current_space_and_thread ();
7326 sym
= find_pc_function (sal
->pc
);
7329 start_sal
= find_function_start_sal (sym
, 1);
7330 if (sal
->pc
< start_sal
.pc
)
7332 start_sal
.explicit_line
= sal
->explicit_line
;
7333 start_sal
.explicit_pc
= sal
->explicit_pc
;
7338 do_cleanups (old_chain
);
7341 /* Helper function for break_command_1 and disassemble_command. */
7344 resolve_sal_pc (struct symtab_and_line
*sal
)
7348 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
7350 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
7351 error (_("No line %d in file \"%s\"."),
7352 sal
->line
, sal
->symtab
->filename
);
7355 /* If this SAL corresponds to a breakpoint inserted using
7356 a line number, then skip the function prologue if necessary. */
7357 if (sal
->explicit_line
)
7359 /* Preserve the original line number. */
7360 int saved_line
= sal
->line
;
7361 skip_prologue_sal (sal
);
7362 sal
->line
= saved_line
;
7366 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
7368 struct blockvector
*bv
;
7372 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
7375 sym
= block_linkage_function (b
);
7378 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
7379 sal
->section
= SYMBOL_OBJ_SECTION (sym
);
7383 /* It really is worthwhile to have the section, so we'll just
7384 have to look harder. This case can be executed if we have
7385 line numbers but no functions (as can happen in assembly
7388 struct minimal_symbol
*msym
;
7389 struct cleanup
*old_chain
= save_current_space_and_thread ();
7391 switch_to_program_space_and_thread (sal
->pspace
);
7393 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
7395 sal
->section
= SYMBOL_OBJ_SECTION (msym
);
7397 do_cleanups (old_chain
);
7404 break_command (char *arg
, int from_tty
)
7406 break_command_1 (arg
, 0, from_tty
);
7410 tbreak_command (char *arg
, int from_tty
)
7412 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
7416 hbreak_command (char *arg
, int from_tty
)
7418 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
7422 thbreak_command (char *arg
, int from_tty
)
7424 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
7428 stop_command (char *arg
, int from_tty
)
7430 printf_filtered (_("Specify the type of breakpoint to set.\n\
7431 Usage: stop in <function | address>\n\
7432 stop at <line>\n"));
7436 stopin_command (char *arg
, int from_tty
)
7440 if (arg
== (char *) NULL
)
7442 else if (*arg
!= '*')
7447 /* look for a ':'. If this is a line number specification, then
7448 say it is bad, otherwise, it should be an address or
7449 function/method name */
7450 while (*argptr
&& !hasColon
)
7452 hasColon
= (*argptr
== ':');
7457 badInput
= (*argptr
!= ':'); /* Not a class::method */
7459 badInput
= isdigit (*arg
); /* a simple line number */
7463 printf_filtered (_("Usage: stop in <function | address>\n"));
7465 break_command_1 (arg
, 0, from_tty
);
7469 stopat_command (char *arg
, int from_tty
)
7473 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
7480 /* look for a ':'. If there is a '::' then get out, otherwise
7481 it is probably a line number. */
7482 while (*argptr
&& !hasColon
)
7484 hasColon
= (*argptr
== ':');
7489 badInput
= (*argptr
== ':'); /* we have class::method */
7491 badInput
= !isdigit (*arg
); /* not a line number */
7495 printf_filtered (_("Usage: stop at <line>\n"));
7497 break_command_1 (arg
, 0, from_tty
);
7500 /* accessflag: hw_write: watch write,
7501 hw_read: watch read,
7502 hw_access: watch access (read or write) */
7504 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
7506 struct gdbarch
*gdbarch
= get_current_arch ();
7507 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
7508 struct expression
*exp
;
7509 struct block
*exp_valid_block
= NULL
, *cond_exp_valid_block
= NULL
;
7510 struct value
*val
, *mark
;
7511 struct frame_info
*frame
;
7512 char *exp_start
= NULL
;
7513 char *exp_end
= NULL
;
7514 char *tok
, *id_tok_start
, *end_tok
;
7516 char *cond_start
= NULL
;
7517 char *cond_end
= NULL
;
7518 int i
, other_type_used
, target_resources_ok
= 0;
7519 enum bptype bp_type
;
7523 /* Make sure that we actually have parameters to parse. */
7524 if (arg
!= NULL
&& arg
[0] != '\0')
7526 toklen
= strlen (arg
); /* Size of argument list. */
7528 /* Points tok to the end of the argument list. */
7529 tok
= arg
+ toklen
- 1;
7531 /* Go backwards in the parameters list. Skip the last parameter.
7532 If we're expecting a 'thread <thread_num>' parameter, this should
7533 be the thread identifier. */
7534 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7536 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7539 /* Points end_tok to the beginning of the last token. */
7540 id_tok_start
= tok
+ 1;
7542 /* Go backwards in the parameters list. Skip one more parameter.
7543 If we're expecting a 'thread <thread_num>' parameter, we should
7544 reach a "thread" token. */
7545 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
7550 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
7553 /* Move the pointer forward to skip the whitespace and
7554 calculate the length of the token. */
7556 toklen
= end_tok
- tok
;
7558 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
7560 /* At this point we've found a "thread" token, which means
7561 the user is trying to set a watchpoint that triggers
7562 only in a specific thread. */
7565 /* Extract the thread ID from the next token. */
7566 thread
= strtol (id_tok_start
, &endp
, 0);
7568 /* Check if the user provided a valid numeric value for the
7570 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
7571 error (_("Invalid thread ID specification %s."), id_tok_start
);
7573 /* Check if the thread actually exists. */
7574 if (!valid_thread_id (thread
))
7575 error (_("Unknown thread %d."), thread
);
7577 /* Truncate the string and get rid of the thread <thread_num>
7578 parameter before the parameter list is parsed by the
7579 evaluate_expression() function. */
7584 /* Parse the rest of the arguments. */
7585 innermost_block
= NULL
;
7587 exp
= parse_exp_1 (&arg
, 0, 0);
7589 /* Remove trailing whitespace from the expression before saving it.
7590 This makes the eventual display of the expression string a bit
7592 while (exp_end
> exp_start
&& (exp_end
[-1] == ' ' || exp_end
[-1] == '\t'))
7595 exp_valid_block
= innermost_block
;
7596 mark
= value_mark ();
7597 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
7599 release_value (val
);
7602 while (*tok
== ' ' || *tok
== '\t')
7606 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
7609 toklen
= end_tok
- tok
;
7610 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
7612 struct expression
*cond
;
7614 innermost_block
= NULL
;
7615 tok
= cond_start
= end_tok
+ 1;
7616 cond
= parse_exp_1 (&tok
, 0, 0);
7618 /* The watchpoint expression may not be local, but the condition
7619 may still be. E.g.: `watch global if local > 0'. */
7620 cond_exp_valid_block
= innermost_block
;
7626 error (_("Junk at end of command."));
7628 if (accessflag
== hw_read
)
7629 bp_type
= bp_read_watchpoint
;
7630 else if (accessflag
== hw_access
)
7631 bp_type
= bp_access_watchpoint
;
7633 bp_type
= bp_hardware_watchpoint
;
7635 mem_cnt
= can_use_hardware_watchpoint (val
);
7636 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
7637 error (_("Expression cannot be implemented with read/access watchpoint."));
7640 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
7641 target_resources_ok
=
7642 target_can_use_hardware_watchpoint (bp_type
, i
+ mem_cnt
,
7644 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
7645 error (_("Target does not support this type of hardware watchpoint."));
7647 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
7648 error (_("Target can only support one kind of HW watchpoint at a time."));
7651 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
7652 watchpoint could not be set. */
7653 if (!mem_cnt
|| target_resources_ok
<= 0)
7654 bp_type
= bp_watchpoint
;
7656 frame
= block_innermost_frame (exp_valid_block
);
7658 /* If the expression is "local", then set up a "watchpoint scope"
7659 breakpoint at the point where we've left the scope of the watchpoint
7660 expression. Create the scope breakpoint before the watchpoint, so
7661 that we will encounter it first in bpstat_stop_status. */
7662 if (exp_valid_block
&& frame
)
7664 if (frame_id_p (frame_unwind_caller_id (frame
)))
7667 = create_internal_breakpoint (frame_unwind_caller_arch (frame
),
7668 frame_unwind_caller_pc (frame
),
7669 bp_watchpoint_scope
);
7671 scope_breakpoint
->enable_state
= bp_enabled
;
7673 /* Automatically delete the breakpoint when it hits. */
7674 scope_breakpoint
->disposition
= disp_del
;
7676 /* Only break in the proper frame (help with recursion). */
7677 scope_breakpoint
->frame_id
= frame_unwind_caller_id (frame
);
7679 /* Set the address at which we will stop. */
7680 scope_breakpoint
->loc
->gdbarch
7681 = frame_unwind_caller_arch (frame
);
7682 scope_breakpoint
->loc
->requested_address
7683 = frame_unwind_caller_pc (frame
);
7684 scope_breakpoint
->loc
->address
7685 = adjust_breakpoint_address (scope_breakpoint
->loc
->gdbarch
,
7686 scope_breakpoint
->loc
->requested_address
,
7687 scope_breakpoint
->type
);
7691 /* Now set up the breakpoint. */
7692 b
= set_raw_breakpoint_without_location (NULL
, bp_type
);
7693 set_breakpoint_count (breakpoint_count
+ 1);
7694 b
->number
= breakpoint_count
;
7696 b
->disposition
= disp_donttouch
;
7698 b
->exp_valid_block
= exp_valid_block
;
7699 b
->cond_exp_valid_block
= cond_exp_valid_block
;
7700 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
7704 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
7710 b
->watchpoint_frame
= get_frame_id (frame
);
7711 b
->watchpoint_thread
= inferior_ptid
;
7715 b
->watchpoint_frame
= null_frame_id
;
7716 b
->watchpoint_thread
= null_ptid
;
7719 if (scope_breakpoint
!= NULL
)
7721 /* The scope breakpoint is related to the watchpoint. We will
7722 need to act on them together. */
7723 b
->related_breakpoint
= scope_breakpoint
;
7724 scope_breakpoint
->related_breakpoint
= b
;
7727 value_free_to_mark (mark
);
7729 /* Finally update the new watchpoint. This creates the locations
7730 that should be inserted. */
7731 update_watchpoint (b
, 1);
7734 update_global_location_list (1);
7737 /* Return count of locations need to be watched and can be handled
7738 in hardware. If the watchpoint can not be handled
7739 in hardware return zero. */
7742 can_use_hardware_watchpoint (struct value
*v
)
7744 int found_memory_cnt
= 0;
7745 struct value
*head
= v
;
7747 /* Did the user specifically forbid us to use hardware watchpoints? */
7748 if (!can_use_hw_watchpoints
)
7751 /* Make sure that the value of the expression depends only upon
7752 memory contents, and values computed from them within GDB. If we
7753 find any register references or function calls, we can't use a
7754 hardware watchpoint.
7756 The idea here is that evaluating an expression generates a series
7757 of values, one holding the value of every subexpression. (The
7758 expression a*b+c has five subexpressions: a, b, a*b, c, and
7759 a*b+c.) GDB's values hold almost enough information to establish
7760 the criteria given above --- they identify memory lvalues,
7761 register lvalues, computed values, etcetera. So we can evaluate
7762 the expression, and then scan the chain of values that leaves
7763 behind to decide whether we can detect any possible change to the
7764 expression's final value using only hardware watchpoints.
7766 However, I don't think that the values returned by inferior
7767 function calls are special in any way. So this function may not
7768 notice that an expression involving an inferior function call
7769 can't be watched with hardware watchpoints. FIXME. */
7770 for (; v
; v
= value_next (v
))
7772 if (VALUE_LVAL (v
) == lval_memory
)
7775 /* A lazy memory lvalue is one that GDB never needed to fetch;
7776 we either just used its address (e.g., `a' in `a.b') or
7777 we never needed it at all (e.g., `a' in `a,b'). */
7781 /* Ahh, memory we actually used! Check if we can cover
7782 it with hardware watchpoints. */
7783 struct type
*vtype
= check_typedef (value_type (v
));
7785 /* We only watch structs and arrays if user asked for it
7786 explicitly, never if they just happen to appear in a
7787 middle of some value chain. */
7789 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
7790 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
7792 CORE_ADDR vaddr
= value_address (v
);
7793 int len
= TYPE_LENGTH (value_type (v
));
7795 if (!target_region_ok_for_hw_watchpoint (vaddr
, len
))
7802 else if (VALUE_LVAL (v
) != not_lval
7803 && deprecated_value_modifiable (v
) == 0)
7804 return 0; /* ??? What does this represent? */
7805 else if (VALUE_LVAL (v
) == lval_register
)
7806 return 0; /* cannot watch a register with a HW watchpoint */
7809 /* The expression itself looks suitable for using a hardware
7810 watchpoint, but give the target machine a chance to reject it. */
7811 return found_memory_cnt
;
7815 watch_command_wrapper (char *arg
, int from_tty
)
7817 watch_command (arg
, from_tty
);
7821 watch_command (char *arg
, int from_tty
)
7823 watch_command_1 (arg
, hw_write
, from_tty
);
7827 rwatch_command_wrapper (char *arg
, int from_tty
)
7829 rwatch_command (arg
, from_tty
);
7833 rwatch_command (char *arg
, int from_tty
)
7835 watch_command_1 (arg
, hw_read
, from_tty
);
7839 awatch_command_wrapper (char *arg
, int from_tty
)
7841 awatch_command (arg
, from_tty
);
7845 awatch_command (char *arg
, int from_tty
)
7847 watch_command_1 (arg
, hw_access
, from_tty
);
7851 /* Helper routines for the until_command routine in infcmd.c. Here
7852 because it uses the mechanisms of breakpoints. */
7854 struct until_break_command_continuation_args
7856 struct breakpoint
*breakpoint
;
7857 struct breakpoint
*breakpoint2
;
7860 /* This function is called by fetch_inferior_event via the
7861 cmd_continuation pointer, to complete the until command. It takes
7862 care of cleaning up the temporary breakpoints set up by the until
7865 until_break_command_continuation (void *arg
)
7867 struct until_break_command_continuation_args
*a
= arg
;
7869 delete_breakpoint (a
->breakpoint
);
7871 delete_breakpoint (a
->breakpoint2
);
7875 until_break_command (char *arg
, int from_tty
, int anywhere
)
7877 struct symtabs_and_lines sals
;
7878 struct symtab_and_line sal
;
7879 struct frame_info
*frame
= get_selected_frame (NULL
);
7880 struct breakpoint
*breakpoint
;
7881 struct breakpoint
*breakpoint2
= NULL
;
7882 struct cleanup
*old_chain
;
7884 clear_proceed_status ();
7886 /* Set a breakpoint where the user wants it and at return from
7889 if (default_breakpoint_valid
)
7890 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
7891 default_breakpoint_line
, (char ***) NULL
, NULL
);
7893 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
7894 0, (char ***) NULL
, NULL
);
7896 if (sals
.nelts
!= 1)
7897 error (_("Couldn't get information on specified line."));
7900 xfree (sals
.sals
); /* malloc'd, so freed */
7903 error (_("Junk at end of arguments."));
7905 resolve_sal_pc (&sal
);
7908 /* If the user told us to continue until a specified location,
7909 we don't specify a frame at which we need to stop. */
7910 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7911 null_frame_id
, bp_until
);
7913 /* Otherwise, specify the selected frame, because we want to stop only
7914 at the very same frame. */
7915 breakpoint
= set_momentary_breakpoint (get_frame_arch (frame
), sal
,
7916 get_stack_frame_id (frame
),
7919 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
7921 /* Keep within the current frame, or in frames called by the current
7924 if (frame_id_p (frame_unwind_caller_id (frame
)))
7926 sal
= find_pc_line (frame_unwind_caller_pc (frame
), 0);
7927 sal
.pc
= frame_unwind_caller_pc (frame
);
7928 breakpoint2
= set_momentary_breakpoint (frame_unwind_caller_arch (frame
),
7930 frame_unwind_caller_id (frame
),
7932 make_cleanup_delete_breakpoint (breakpoint2
);
7935 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
7937 /* If we are running asynchronously, and proceed call above has actually
7938 managed to start the target, arrange for breakpoints to be
7939 deleted when the target stops. Otherwise, we're already stopped and
7940 delete breakpoints via cleanup chain. */
7942 if (target_can_async_p () && is_running (inferior_ptid
))
7944 struct until_break_command_continuation_args
*args
;
7945 args
= xmalloc (sizeof (*args
));
7947 args
->breakpoint
= breakpoint
;
7948 args
->breakpoint2
= breakpoint2
;
7950 discard_cleanups (old_chain
);
7951 add_continuation (inferior_thread (),
7952 until_break_command_continuation
, args
,
7956 do_cleanups (old_chain
);
7960 ep_skip_leading_whitespace (char **s
)
7962 if ((s
== NULL
) || (*s
== NULL
))
7964 while (isspace (**s
))
7968 /* This function attempts to parse an optional "if <cond>" clause
7969 from the arg string. If one is not found, it returns NULL.
7971 Else, it returns a pointer to the condition string. (It does not
7972 attempt to evaluate the string against a particular block.) And,
7973 it updates arg to point to the first character following the parsed
7974 if clause in the arg string. */
7977 ep_parse_optional_if_clause (char **arg
)
7981 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
7984 /* Skip the "if" keyword. */
7987 /* Skip any extra leading whitespace, and record the start of the
7988 condition string. */
7989 ep_skip_leading_whitespace (arg
);
7992 /* Assume that the condition occupies the remainder of the arg string. */
7993 (*arg
) += strlen (cond_string
);
7998 /* Commands to deal with catching events, such as signals, exceptions,
7999 process start/exit, etc. */
8003 catch_fork_temporary
, catch_vfork_temporary
,
8004 catch_fork_permanent
, catch_vfork_permanent
8009 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8011 struct gdbarch
*gdbarch
= get_current_arch ();
8012 char *cond_string
= NULL
;
8013 catch_fork_kind fork_kind
;
8016 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
8017 tempflag
= (fork_kind
== catch_fork_temporary
8018 || fork_kind
== catch_vfork_temporary
);
8022 ep_skip_leading_whitespace (&arg
);
8024 /* The allowed syntax is:
8026 catch [v]fork if <cond>
8028 First, check if there's an if clause. */
8029 cond_string
= ep_parse_optional_if_clause (&arg
);
8031 if ((*arg
!= '\0') && !isspace (*arg
))
8032 error (_("Junk at end of arguments."));
8034 /* If this target supports it, create a fork or vfork catchpoint
8035 and enable reporting of such events. */
8038 case catch_fork_temporary
:
8039 case catch_fork_permanent
:
8040 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8041 &catch_fork_breakpoint_ops
);
8043 case catch_vfork_temporary
:
8044 case catch_vfork_permanent
:
8045 create_fork_vfork_event_catchpoint (gdbarch
, tempflag
, cond_string
,
8046 &catch_vfork_breakpoint_ops
);
8049 error (_("unsupported or unknown fork kind; cannot catch it"));
8055 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8057 struct gdbarch
*gdbarch
= get_current_arch ();
8059 char *cond_string
= NULL
;
8061 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8065 ep_skip_leading_whitespace (&arg
);
8067 /* The allowed syntax is:
8069 catch exec if <cond>
8071 First, check if there's an if clause. */
8072 cond_string
= ep_parse_optional_if_clause (&arg
);
8074 if ((*arg
!= '\0') && !isspace (*arg
))
8075 error (_("Junk at end of arguments."));
8077 /* If this target supports it, create an exec catchpoint
8078 and enable reporting of such events. */
8079 create_catchpoint (gdbarch
, tempflag
, cond_string
,
8080 &catch_exec_breakpoint_ops
);
8083 static enum print_stop_action
8084 print_exception_catchpoint (struct breakpoint
*b
)
8086 int bp_temp
, bp_throw
;
8088 annotate_catchpoint (b
->number
);
8090 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8091 if (b
->loc
->address
!= b
->loc
->requested_address
)
8092 breakpoint_adjustment_warning (b
->loc
->requested_address
,
8095 bp_temp
= b
->disposition
== disp_del
;
8097 bp_temp
? "Temporary catchpoint "
8099 if (!ui_out_is_mi_like_p (uiout
))
8100 ui_out_field_int (uiout
, "bkptno", b
->number
);
8102 bp_throw
? " (exception thrown), "
8103 : " (exception caught), ");
8104 if (ui_out_is_mi_like_p (uiout
))
8106 ui_out_field_string (uiout
, "reason",
8107 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
8108 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
8109 ui_out_field_int (uiout
, "bkptno", b
->number
);
8111 return PRINT_SRC_AND_LOC
;
8115 print_one_exception_catchpoint (struct breakpoint
*b
, struct bp_location
**last_loc
)
8117 struct value_print_options opts
;
8118 get_user_print_options (&opts
);
8119 if (opts
.addressprint
)
8122 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
8123 ui_out_field_string (uiout
, "addr", "<PENDING>");
8125 ui_out_field_core_addr (uiout
, "addr",
8126 b
->loc
->gdbarch
, b
->loc
->address
);
8131 if (strstr (b
->addr_string
, "throw") != NULL
)
8132 ui_out_field_string (uiout
, "what", "exception throw");
8134 ui_out_field_string (uiout
, "what", "exception catch");
8138 print_mention_exception_catchpoint (struct breakpoint
*b
)
8143 bp_temp
= b
->disposition
== disp_del
;
8144 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
8145 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
8146 : _("Catchpoint "));
8147 ui_out_field_int (uiout
, "bkptno", b
->number
);
8148 ui_out_text (uiout
, bp_throw
? _(" (throw)")
8152 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
8155 NULL
, /* breakpoint_hit */
8156 print_exception_catchpoint
,
8157 print_one_exception_catchpoint
,
8158 print_mention_exception_catchpoint
8162 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
8163 enum exception_event_kind ex_event
, int from_tty
)
8165 char *trigger_func_name
;
8167 if (ex_event
== EX_EVENT_CATCH
)
8168 trigger_func_name
= "__cxa_begin_catch";
8170 trigger_func_name
= "__cxa_throw";
8172 create_breakpoint (get_current_arch (),
8173 trigger_func_name
, cond_string
, -1,
8174 0 /* condition and thread are valid. */,
8177 AUTO_BOOLEAN_TRUE
/* pending */,
8178 &gnu_v3_exception_catchpoint_ops
, from_tty
,
8184 /* Deal with "catch catch" and "catch throw" commands */
8187 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
8188 int tempflag
, int from_tty
)
8190 char *cond_string
= NULL
;
8191 struct symtab_and_line
*sal
= NULL
;
8195 ep_skip_leading_whitespace (&arg
);
8197 cond_string
= ep_parse_optional_if_clause (&arg
);
8199 if ((*arg
!= '\0') && !isspace (*arg
))
8200 error (_("Junk at end of arguments."));
8202 if (ex_event
!= EX_EVENT_THROW
8203 && ex_event
!= EX_EVENT_CATCH
)
8204 error (_("Unsupported or unknown exception event; cannot catch it"));
8206 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
8209 warning (_("Unsupported with this platform/compiler combination."));
8212 /* Implementation of "catch catch" command. */
8215 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8217 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8218 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
8221 /* Implementation of "catch throw" command. */
8224 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8226 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8227 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
8230 /* Create a breakpoint struct for Ada exception catchpoints. */
8233 create_ada_exception_breakpoint (struct gdbarch
*gdbarch
,
8234 struct symtab_and_line sal
,
8238 struct expression
*cond
,
8239 struct breakpoint_ops
*ops
,
8243 struct breakpoint
*b
;
8247 struct gdbarch
*loc_gdbarch
= get_sal_arch (sal
);
8249 loc_gdbarch
= gdbarch
;
8251 describe_other_breakpoints (loc_gdbarch
,
8252 sal
.pspace
, sal
.pc
, sal
.section
, -1);
8253 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
8254 version for exception catchpoints, because two catchpoints
8255 used for different exception names will use the same address.
8256 In this case, a "breakpoint ... also set at..." warning is
8257 unproductive. Besides. the warning phrasing is also a bit
8258 inapropriate, we should use the word catchpoint, and tell
8259 the user what type of catchpoint it is. The above is good
8260 enough for now, though. */
8263 b
= set_raw_breakpoint (gdbarch
, sal
, bp_breakpoint
);
8264 set_breakpoint_count (breakpoint_count
+ 1);
8266 b
->enable_state
= bp_enabled
;
8267 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
8268 b
->number
= breakpoint_count
;
8269 b
->ignore_count
= 0;
8270 b
->loc
->cond
= cond
;
8271 b
->addr_string
= addr_string
;
8272 b
->language
= language_ada
;
8273 b
->cond_string
= cond_string
;
8274 b
->exp_string
= exp_string
;
8279 update_global_location_list (1);
8282 /* Implement the "catch exception" command. */
8285 catch_ada_exception_command (char *arg
, int from_tty
,
8286 struct cmd_list_element
*command
)
8288 struct gdbarch
*gdbarch
= get_current_arch ();
8290 struct symtab_and_line sal
;
8292 char *addr_string
= NULL
;
8293 char *exp_string
= NULL
;
8294 char *cond_string
= NULL
;
8295 struct expression
*cond
= NULL
;
8296 struct breakpoint_ops
*ops
= NULL
;
8298 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8302 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
8303 &cond_string
, &cond
, &ops
);
8304 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, exp_string
,
8305 cond_string
, cond
, ops
, tempflag
,
8309 /* Cleanup function for a syscall filter list. */
8311 clean_up_filters (void *arg
)
8313 VEC(int) *iter
= *(VEC(int) **) arg
;
8314 VEC_free (int, iter
);
8317 /* Splits the argument using space as delimiter. Returns an xmalloc'd
8318 filter list, or NULL if no filtering is required. */
8320 catch_syscall_split_args (char *arg
)
8322 VEC(int) *result
= NULL
;
8323 struct cleanup
*cleanup
= make_cleanup (clean_up_filters
, &result
);
8325 while (*arg
!= '\0')
8327 int i
, syscall_number
;
8332 /* Skip whitespace. */
8333 while (isspace (*arg
))
8336 for (i
= 0; i
< 127 && arg
[i
] && !isspace (arg
[i
]); ++i
)
8337 cur_name
[i
] = arg
[i
];
8341 /* Check if the user provided a syscall name or a number. */
8342 syscall_number
= (int) strtol (cur_name
, &endptr
, 0);
8343 if (*endptr
== '\0')
8344 get_syscall_by_number (syscall_number
, &s
);
8347 /* We have a name. Let's check if it's valid and convert it
8349 get_syscall_by_name (cur_name
, &s
);
8351 if (s
.number
== UNKNOWN_SYSCALL
)
8352 /* Here we have to issue an error instead of a warning, because
8353 GDB cannot do anything useful if there's no syscall number to
8355 error (_("Unknown syscall name '%s'."), cur_name
);
8358 /* Ok, it's valid. */
8359 VEC_safe_push (int, result
, s
.number
);
8362 discard_cleanups (cleanup
);
8366 /* Implement the "catch syscall" command. */
8369 catch_syscall_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8374 struct gdbarch
*gdbarch
= get_current_arch ();
8376 /* Checking if the feature if supported. */
8377 if (gdbarch_get_syscall_number_p (gdbarch
) == 0)
8378 error (_("The feature 'catch syscall' is not supported on \
8379 this architeture yet."));
8381 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8383 ep_skip_leading_whitespace (&arg
);
8385 /* We need to do this first "dummy" translation in order
8386 to get the syscall XML file loaded or, most important,
8387 to display a warning to the user if there's no XML file
8388 for his/her architecture. */
8389 get_syscall_by_number (0, &s
);
8391 /* The allowed syntax is:
8393 catch syscall <name | number> [<name | number> ... <name | number>]
8395 Let's check if there's a syscall name. */
8398 filter
= catch_syscall_split_args (arg
);
8402 create_syscall_event_catchpoint (tempflag
, filter
,
8403 &catch_syscall_breakpoint_ops
);
8406 /* Implement the "catch assert" command. */
8409 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
8411 struct gdbarch
*gdbarch
= get_current_arch ();
8413 struct symtab_and_line sal
;
8414 char *addr_string
= NULL
;
8415 struct breakpoint_ops
*ops
= NULL
;
8417 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
8421 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
8422 create_ada_exception_breakpoint (gdbarch
, sal
, addr_string
, NULL
, NULL
, NULL
,
8423 ops
, tempflag
, from_tty
);
8427 catch_command (char *arg
, int from_tty
)
8429 error (_("Catch requires an event name."));
8434 tcatch_command (char *arg
, int from_tty
)
8436 error (_("Catch requires an event name."));
8439 /* Delete breakpoints by address or line. */
8442 clear_command (char *arg
, int from_tty
)
8444 struct breakpoint
*b
;
8445 VEC(breakpoint_p
) *found
= 0;
8448 struct symtabs_and_lines sals
;
8449 struct symtab_and_line sal
;
8454 sals
= decode_line_spec (arg
, 1);
8459 sals
.sals
= (struct symtab_and_line
*)
8460 xmalloc (sizeof (struct symtab_and_line
));
8461 make_cleanup (xfree
, sals
.sals
);
8462 init_sal (&sal
); /* initialize to zeroes */
8463 sal
.line
= default_breakpoint_line
;
8464 sal
.symtab
= default_breakpoint_symtab
;
8465 sal
.pc
= default_breakpoint_address
;
8466 sal
.pspace
= default_breakpoint_pspace
;
8467 if (sal
.symtab
== 0)
8468 error (_("No source file specified."));
8476 /* We don't call resolve_sal_pc here. That's not
8477 as bad as it seems, because all existing breakpoints
8478 typically have both file/line and pc set. So, if
8479 clear is given file/line, we can match this to existing
8480 breakpoint without obtaining pc at all.
8482 We only support clearing given the address explicitly
8483 present in breakpoint table. Say, we've set breakpoint
8484 at file:line. There were several PC values for that file:line,
8485 due to optimization, all in one block.
8486 We've picked one PC value. If "clear" is issued with another
8487 PC corresponding to the same file:line, the breakpoint won't
8488 be cleared. We probably can still clear the breakpoint, but
8489 since the other PC value is never presented to user, user
8490 can only find it by guessing, and it does not seem important
8493 /* For each line spec given, delete bps which correspond
8494 to it. Do it in two passes, solely to preserve the current
8495 behavior that from_tty is forced true if we delete more than
8499 for (i
= 0; i
< sals
.nelts
; i
++)
8501 /* If exact pc given, clear bpts at that pc.
8502 If line given (pc == 0), clear all bpts on specified line.
8503 If defaulting, clear all bpts on default line
8506 defaulting sal.pc != 0 tests to do
8511 1 0 <can't happen> */
8515 /* Find all matching breakpoints and add them to
8520 /* Are we going to delete b? */
8521 if (b
->type
!= bp_none
8522 && b
->type
!= bp_watchpoint
8523 && b
->type
!= bp_hardware_watchpoint
8524 && b
->type
!= bp_read_watchpoint
8525 && b
->type
!= bp_access_watchpoint
)
8527 struct bp_location
*loc
= b
->loc
;
8528 for (; loc
; loc
= loc
->next
)
8530 int pc_match
= sal
.pc
8531 && (loc
->pspace
== sal
.pspace
)
8532 && (loc
->address
== sal
.pc
)
8533 && (!section_is_overlay (loc
->section
)
8534 || loc
->section
== sal
.section
);
8535 int line_match
= ((default_match
|| (0 == sal
.pc
))
8536 && b
->source_file
!= NULL
8537 && sal
.symtab
!= NULL
8538 && sal
.pspace
== loc
->pspace
8539 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
8540 && b
->line_number
== sal
.line
);
8541 if (pc_match
|| line_match
)
8550 VEC_safe_push(breakpoint_p
, found
, b
);
8553 /* Now go thru the 'found' chain and delete them. */
8554 if (VEC_empty(breakpoint_p
, found
))
8557 error (_("No breakpoint at %s."), arg
);
8559 error (_("No breakpoint at this line."));
8562 if (VEC_length(breakpoint_p
, found
) > 1)
8563 from_tty
= 1; /* Always report if deleted more than one */
8566 if (VEC_length(breakpoint_p
, found
) == 1)
8567 printf_unfiltered (_("Deleted breakpoint "));
8569 printf_unfiltered (_("Deleted breakpoints "));
8571 breakpoints_changed ();
8573 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
8576 printf_unfiltered ("%d ", b
->number
);
8577 delete_breakpoint (b
);
8580 putchar_unfiltered ('\n');
8583 /* Delete breakpoint in BS if they are `delete' breakpoints and
8584 all breakpoints that are marked for deletion, whether hit or not.
8585 This is called after any breakpoint is hit, or after errors. */
8588 breakpoint_auto_delete (bpstat bs
)
8590 struct breakpoint
*b
, *temp
;
8592 for (; bs
; bs
= bs
->next
)
8593 if (bs
->breakpoint_at
8594 && bs
->breakpoint_at
->owner
8595 && bs
->breakpoint_at
->owner
->disposition
== disp_del
8597 delete_breakpoint (bs
->breakpoint_at
->owner
);
8599 ALL_BREAKPOINTS_SAFE (b
, temp
)
8601 if (b
->disposition
== disp_del_at_next_stop
)
8602 delete_breakpoint (b
);
8606 /* A comparison function for bp_location AP and BP being interfaced to qsort.
8607 Sort elements primarily by their ADDRESS (no matter what does
8608 breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering
8609 first bp_permanent OWNERed elements and terciarily just ensuring the array
8610 is sorted stable way despite qsort being an instable algorithm. */
8613 bp_location_compare (const void *ap
, const void *bp
)
8615 struct bp_location
*a
= *(void **) ap
;
8616 struct bp_location
*b
= *(void **) bp
;
8617 int a_perm
= a
->owner
->enable_state
== bp_permanent
;
8618 int b_perm
= b
->owner
->enable_state
== bp_permanent
;
8620 if (a
->address
!= b
->address
)
8621 return (a
->address
> b
->address
) - (a
->address
< b
->address
);
8623 /* Sort permanent breakpoints first. */
8624 if (a_perm
!= b_perm
)
8625 return (a_perm
< b_perm
) - (a_perm
> b_perm
);
8627 /* Make the user-visible order stable across GDB runs. Locations of the same
8628 breakpoint can be sorted in arbitrary order. */
8630 if (a
->owner
->number
!= b
->owner
->number
)
8631 return (a
->owner
->number
> b
->owner
->number
)
8632 - (a
->owner
->number
< b
->owner
->number
);
8634 return (a
> b
) - (a
< b
);
8637 /* Set bp_location_placed_address_before_address_max and
8638 bp_location_shadow_len_after_address_max according to the current content of
8639 the bp_location array. */
8642 bp_location_target_extensions_update (void)
8644 struct bp_location
*bl
, **blp_tmp
;
8646 bp_location_placed_address_before_address_max
= 0;
8647 bp_location_shadow_len_after_address_max
= 0;
8649 ALL_BP_LOCATIONS (bl
, blp_tmp
)
8651 CORE_ADDR start
, end
, addr
;
8653 if (!bp_location_has_shadow (bl
))
8656 start
= bl
->target_info
.placed_address
;
8657 end
= start
+ bl
->target_info
.shadow_len
;
8659 gdb_assert (bl
->address
>= start
);
8660 addr
= bl
->address
- start
;
8661 if (addr
> bp_location_placed_address_before_address_max
)
8662 bp_location_placed_address_before_address_max
= addr
;
8664 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */
8666 gdb_assert (bl
->address
< end
);
8667 addr
= end
- bl
->address
;
8668 if (addr
> bp_location_shadow_len_after_address_max
)
8669 bp_location_shadow_len_after_address_max
= addr
;
8673 /* If SHOULD_INSERT is false, do not insert any breakpoint locations
8674 into the inferior, only remove already-inserted locations that no
8675 longer should be inserted. Functions that delete a breakpoint or
8676 breakpoints should pass false, so that deleting a breakpoint
8677 doesn't have the side effect of inserting the locations of other
8678 breakpoints that are marked not-inserted, but should_be_inserted
8679 returns true on them.
8681 This behaviour is useful is situations close to tear-down -- e.g.,
8682 after an exec, while the target still has execution, but breakpoint
8683 shadows of the previous executable image should *NOT* be restored
8684 to the new image; or before detaching, where the target still has
8685 execution and wants to delete breakpoints from GDB's lists, and all
8686 breakpoints had already been removed from the inferior. */
8689 update_global_location_list (int should_insert
)
8691 struct breakpoint
*b
;
8692 struct bp_location
**locp
, *loc
;
8693 struct cleanup
*cleanups
;
8695 /* Used in the duplicates detection below. When iterating over all
8696 bp_locations, points to the first bp_location of a given address.
8697 Breakpoints and watchpoints of different types are never
8698 duplicates of each other. Keep one pointer for each type of
8699 breakpoint/watchpoint, so we only need to loop over all locations
8701 struct bp_location
*bp_loc_first
; /* breakpoint */
8702 struct bp_location
*wp_loc_first
; /* hardware watchpoint */
8703 struct bp_location
*awp_loc_first
; /* access watchpoint */
8704 struct bp_location
*rwp_loc_first
; /* read watchpoint */
8706 /* Saved former bp_location array which we compare against the newly built
8707 bp_location from the current state of ALL_BREAKPOINTS. */
8708 struct bp_location
**old_location
, **old_locp
;
8709 unsigned old_location_count
;
8711 old_location
= bp_location
;
8712 old_location_count
= bp_location_count
;
8714 bp_location_count
= 0;
8715 cleanups
= make_cleanup (xfree
, old_location
);
8718 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8719 bp_location_count
++;
8721 bp_location
= xmalloc (sizeof (*bp_location
) * bp_location_count
);
8724 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
8726 qsort (bp_location
, bp_location_count
, sizeof (*bp_location
),
8727 bp_location_compare
);
8729 bp_location_target_extensions_update ();
8731 /* Identify bp_location instances that are no longer present in the new
8732 list, and therefore should be freed. Note that it's not necessary that
8733 those locations should be removed from inferior -- if there's another
8734 location at the same address (previously marked as duplicate),
8735 we don't need to remove/insert the location.
8737 LOCP is kept in sync with OLD_LOCP, each pointing to the current and
8738 former bp_location array state respectively. */
8741 for (old_locp
= old_location
; old_locp
< old_location
+ old_location_count
;
8744 struct bp_location
*old_loc
= *old_locp
;
8745 struct bp_location
**loc2p
;
8747 /* Tells if 'old_loc' is found amoung the new locations. If not, we
8749 int found_object
= 0;
8750 /* Tells if the location should remain inserted in the target. */
8751 int keep_in_target
= 0;
8754 /* Skip LOCP entries which will definitely never be needed. Stop either
8755 at or being the one matching OLD_LOC. */
8756 while (locp
< bp_location
+ bp_location_count
8757 && (*locp
)->address
< old_loc
->address
)
8761 (loc2p
< bp_location
+ bp_location_count
8762 && (*loc2p
)->address
== old_loc
->address
);
8765 if (*loc2p
== old_loc
)
8772 /* If this location is no longer present, and inserted, look if there's
8773 maybe a new location at the same address. If so, mark that one
8774 inserted, and don't remove this one. This is needed so that we
8775 don't have a time window where a breakpoint at certain location is not
8778 if (old_loc
->inserted
)
8780 /* If the location is inserted now, we might have to remove it. */
8782 if (found_object
&& should_be_inserted (old_loc
))
8784 /* The location is still present in the location list, and still
8785 should be inserted. Don't do anything. */
8790 /* The location is either no longer present, or got disabled.
8791 See if there's another location at the same address, in which
8792 case we don't need to remove this one from the target. */
8794 if (breakpoint_address_is_meaningful (old_loc
->owner
))
8797 (loc2p
< bp_location
+ bp_location_count
8798 && (*loc2p
)->address
== old_loc
->address
);
8801 struct bp_location
*loc2
= *loc2p
;
8803 if (breakpoint_locations_match (loc2
, old_loc
))
8805 /* For the sake of should_be_inserted.
8806 Duplicates check below will fix up this later. */
8807 loc2
->duplicate
= 0;
8809 /* Read watchpoint locations are switched to
8810 access watchpoints, if the former are not
8811 supported, but the latter are. */
8812 if (is_hardware_watchpoint (old_loc
->owner
))
8814 gdb_assert (is_hardware_watchpoint (loc2
->owner
));
8815 loc2
->watchpoint_type
= old_loc
->watchpoint_type
;
8818 if (loc2
!= old_loc
&& should_be_inserted (loc2
))
8821 loc2
->target_info
= old_loc
->target_info
;
8830 if (!keep_in_target
)
8832 if (remove_breakpoint (old_loc
, mark_uninserted
))
8834 /* This is just about all we can do. We could keep this
8835 location on the global list, and try to remove it next
8836 time, but there's no particular reason why we will
8839 Note that at this point, old_loc->owner is still valid,
8840 as delete_breakpoint frees the breakpoint only
8841 after calling us. */
8842 printf_filtered (_("warning: Error removing breakpoint %d\n"),
8843 old_loc
->owner
->number
);
8851 if (removed
&& non_stop
8852 && breakpoint_address_is_meaningful (old_loc
->owner
)
8853 && !is_hardware_watchpoint (old_loc
->owner
))
8855 /* This location was removed from the target. In
8856 non-stop mode, a race condition is possible where
8857 we've removed a breakpoint, but stop events for that
8858 breakpoint are already queued and will arrive later.
8859 We apply an heuristic to be able to distinguish such
8860 SIGTRAPs from other random SIGTRAPs: we keep this
8861 breakpoint location for a bit, and will retire it
8862 after we see some number of events. The theory here
8863 is that reporting of events should, "on the average",
8864 be fair, so after a while we'll see events from all
8865 threads that have anything of interest, and no longer
8866 need to keep this breakpoint location around. We
8867 don't hold locations forever so to reduce chances of
8868 mistaking a non-breakpoint SIGTRAP for a breakpoint
8871 The heuristic failing can be disastrous on
8872 decr_pc_after_break targets.
8874 On decr_pc_after_break targets, like e.g., x86-linux,
8875 if we fail to recognize a late breakpoint SIGTRAP,
8876 because events_till_retirement has reached 0 too
8877 soon, we'll fail to do the PC adjustment, and report
8878 a random SIGTRAP to the user. When the user resumes
8879 the inferior, it will most likely immediately crash
8880 with SIGILL/SIGBUS/SEGSEGV, or worse, get silently
8881 corrupted, because of being resumed e.g., in the
8882 middle of a multi-byte instruction, or skipped a
8883 one-byte instruction. This was actually seen happen
8884 on native x86-linux, and should be less rare on
8885 targets that do not support new thread events, like
8886 remote, due to the heuristic depending on
8889 Mistaking a random SIGTRAP for a breakpoint trap
8890 causes similar symptoms (PC adjustment applied when
8891 it shouldn't), but then again, playing with SIGTRAPs
8892 behind the debugger's back is asking for trouble.
8894 Since hardware watchpoint traps are always
8895 distinguishable from other traps, so we don't need to
8896 apply keep hardware watchpoint moribund locations
8897 around. We simply always ignore hardware watchpoint
8898 traps we can no longer explain. */
8900 old_loc
->events_till_retirement
= 3 * (thread_count () + 1);
8901 old_loc
->owner
= NULL
;
8903 VEC_safe_push (bp_location_p
, moribund_locations
, old_loc
);
8906 free_bp_location (old_loc
);
8910 /* Rescan breakpoints at the same address and section, marking the
8911 first one as "first" and any others as "duplicates". This is so
8912 that the bpt instruction is only inserted once. If we have a
8913 permanent breakpoint at the same place as BPT, make that one the
8914 official one, and the rest as duplicates. Permanent breakpoints
8915 are sorted first for the same address.
8917 Do the same for hardware watchpoints, but also considering the
8918 watchpoint's type (regular/access/read) and length. */
8920 bp_loc_first
= NULL
;
8921 wp_loc_first
= NULL
;
8922 awp_loc_first
= NULL
;
8923 rwp_loc_first
= NULL
;
8924 ALL_BP_LOCATIONS (loc
, locp
)
8926 struct breakpoint
*b
= loc
->owner
;
8927 struct bp_location
**loc_first_p
;
8929 if (b
->enable_state
== bp_disabled
8930 || b
->enable_state
== bp_call_disabled
8931 || b
->enable_state
== bp_startup_disabled
8933 || loc
->shlib_disabled
8934 || !breakpoint_address_is_meaningful (b
)
8935 || tracepoint_type (b
))
8938 /* Permanent breakpoint should always be inserted. */
8939 if (b
->enable_state
== bp_permanent
&& ! loc
->inserted
)
8940 internal_error (__FILE__
, __LINE__
,
8941 _("allegedly permanent breakpoint is not "
8942 "actually inserted"));
8944 if (b
->type
== bp_hardware_watchpoint
)
8945 loc_first_p
= &wp_loc_first
;
8946 else if (b
->type
== bp_read_watchpoint
)
8947 loc_first_p
= &rwp_loc_first
;
8948 else if (b
->type
== bp_access_watchpoint
)
8949 loc_first_p
= &awp_loc_first
;
8951 loc_first_p
= &bp_loc_first
;
8953 if (*loc_first_p
== NULL
8954 || (overlay_debugging
&& loc
->section
!= (*loc_first_p
)->section
)
8955 || !breakpoint_locations_match (loc
, *loc_first_p
))
8964 if ((*loc_first_p
)->owner
->enable_state
== bp_permanent
&& loc
->inserted
8965 && b
->enable_state
!= bp_permanent
)
8966 internal_error (__FILE__
, __LINE__
,
8967 _("another breakpoint was inserted on top of "
8968 "a permanent breakpoint"));
8971 if (breakpoints_always_inserted_mode () && should_insert
8972 && (have_live_inferiors ()
8973 || (gdbarch_has_global_breakpoints (target_gdbarch
))))
8974 insert_breakpoint_locations ();
8976 do_cleanups (cleanups
);
8980 breakpoint_retire_moribund (void)
8982 struct bp_location
*loc
;
8985 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
8986 if (--(loc
->events_till_retirement
) == 0)
8988 free_bp_location (loc
);
8989 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
8995 update_global_location_list_nothrow (int inserting
)
8997 struct gdb_exception e
;
8998 TRY_CATCH (e
, RETURN_MASK_ERROR
)
8999 update_global_location_list (inserting
);
9002 /* Clear BPT from a BPS. */
9004 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
9007 for (bs
= bps
; bs
; bs
= bs
->next
)
9008 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
9010 bs
->breakpoint_at
= NULL
;
9012 /* bs->commands will be freed later. */
9016 /* Callback for iterate_over_threads. */
9018 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
9020 struct breakpoint
*bpt
= data
;
9021 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
9025 /* Delete a breakpoint and clean up all traces of it in the data
9029 delete_breakpoint (struct breakpoint
*bpt
)
9031 struct breakpoint
*b
;
9032 struct bp_location
*loc
, *next
;
9034 gdb_assert (bpt
!= NULL
);
9036 /* Has this bp already been deleted? This can happen because multiple
9037 lists can hold pointers to bp's. bpstat lists are especial culprits.
9039 One example of this happening is a watchpoint's scope bp. When the
9040 scope bp triggers, we notice that the watchpoint is out of scope, and
9041 delete it. We also delete its scope bp. But the scope bp is marked
9042 "auto-deleting", and is already on a bpstat. That bpstat is then
9043 checked for auto-deleting bp's, which are deleted.
9045 A real solution to this problem might involve reference counts in bp's,
9046 and/or giving them pointers back to their referencing bpstat's, and
9047 teaching delete_breakpoint to only free a bp's storage when no more
9048 references were extent. A cheaper bandaid was chosen. */
9049 if (bpt
->type
== bp_none
)
9052 /* At least avoid this stale reference until the reference counting of
9053 breakpoints gets resolved. */
9054 if (bpt
->related_breakpoint
!= NULL
)
9056 gdb_assert (bpt
->related_breakpoint
->related_breakpoint
== bpt
);
9057 bpt
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
9058 bpt
->related_breakpoint
->related_breakpoint
= NULL
;
9059 bpt
->related_breakpoint
= NULL
;
9062 observer_notify_breakpoint_deleted (bpt
->number
);
9064 if (breakpoint_chain
== bpt
)
9065 breakpoint_chain
= bpt
->next
;
9070 b
->next
= bpt
->next
;
9074 decref_counted_command_line (&bpt
->commands
);
9075 xfree (bpt
->cond_string
);
9076 xfree (bpt
->cond_exp
);
9077 xfree (bpt
->addr_string
);
9079 xfree (bpt
->exp_string
);
9080 value_free (bpt
->val
);
9081 xfree (bpt
->source_file
);
9082 xfree (bpt
->exec_pathname
);
9083 clean_up_filters (&bpt
->syscalls_to_be_caught
);
9085 /* Be sure no bpstat's are pointing at it after it's been freed. */
9086 /* FIXME, how can we find all bpstat's?
9087 We just check stop_bpstat for now. Note that we cannot just
9088 remove bpstats pointing at bpt from the stop_bpstat list
9089 entirely, as breakpoint commands are associated with the bpstat;
9090 if we remove it here, then the later call to
9091 bpstat_do_actions (&stop_bpstat);
9092 in event-top.c won't do anything, and temporary breakpoints
9093 with commands won't work. */
9095 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
9097 /* Now that breakpoint is removed from breakpoint
9098 list, update the global location list. This
9099 will remove locations that used to belong to
9100 this breakpoint. Do this before freeing
9101 the breakpoint itself, since remove_breakpoint
9102 looks at location's owner. It might be better
9103 design to have location completely self-contained,
9104 but it's not the case now. */
9105 update_global_location_list (0);
9108 /* On the chance that someone will soon try again to delete this same
9109 bp, we mark it as deleted before freeing its storage. */
9110 bpt
->type
= bp_none
;
9116 do_delete_breakpoint_cleanup (void *b
)
9118 delete_breakpoint (b
);
9122 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
9124 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
9128 delete_command (char *arg
, int from_tty
)
9130 struct breakpoint
*b
, *temp
;
9136 int breaks_to_delete
= 0;
9138 /* Delete all breakpoints if no argument.
9139 Do not delete internal or call-dummy breakpoints, these
9140 have to be deleted with an explicit breakpoint number argument. */
9143 if (b
->type
!= bp_call_dummy
9144 && b
->type
!= bp_shlib_event
9145 && b
->type
!= bp_jit_event
9146 && b
->type
!= bp_thread_event
9147 && b
->type
!= bp_overlay_event
9148 && b
->type
!= bp_longjmp_master
9151 breaks_to_delete
= 1;
9156 /* Ask user only if there are some breakpoints to delete. */
9158 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
9160 ALL_BREAKPOINTS_SAFE (b
, temp
)
9162 if (b
->type
!= bp_call_dummy
9163 && b
->type
!= bp_shlib_event
9164 && b
->type
!= bp_thread_event
9165 && b
->type
!= bp_jit_event
9166 && b
->type
!= bp_overlay_event
9167 && b
->type
!= bp_longjmp_master
9169 delete_breakpoint (b
);
9174 map_breakpoint_numbers (arg
, delete_breakpoint
);
9178 all_locations_are_pending (struct bp_location
*loc
)
9180 for (; loc
; loc
= loc
->next
)
9181 if (!loc
->shlib_disabled
)
9186 /* Subroutine of update_breakpoint_locations to simplify it.
9187 Return non-zero if multiple fns in list LOC have the same name.
9188 Null names are ignored. */
9191 ambiguous_names_p (struct bp_location
*loc
)
9193 struct bp_location
*l
;
9194 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
9195 (int (*) (const void *, const void *)) streq
,
9196 NULL
, xcalloc
, xfree
);
9198 for (l
= loc
; l
!= NULL
; l
= l
->next
)
9201 const char *name
= l
->function_name
;
9203 /* Allow for some names to be NULL, ignore them. */
9207 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
9209 /* NOTE: We can assume slot != NULL here because xcalloc never returns
9224 update_breakpoint_locations (struct breakpoint
*b
,
9225 struct symtabs_and_lines sals
)
9229 struct bp_location
*existing_locations
= b
->loc
;
9231 /* If there's no new locations, and all existing locations
9232 are pending, don't do anything. This optimizes
9233 the common case where all locations are in the same
9234 shared library, that was unloaded. We'd like to
9235 retain the location, so that when the library
9236 is loaded again, we don't loose the enabled/disabled
9237 status of the individual locations. */
9238 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
9243 for (i
= 0; i
< sals
.nelts
; ++i
)
9245 struct bp_location
*new_loc
=
9246 add_location_to_breakpoint (b
, &(sals
.sals
[i
]));
9248 /* Reparse conditions, they might contain references to the
9250 if (b
->cond_string
!= NULL
)
9252 struct gdb_exception e
;
9255 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9257 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
9262 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
9263 b
->number
, e
.message
);
9264 new_loc
->enabled
= 0;
9268 if (b
->source_file
!= NULL
)
9269 xfree (b
->source_file
);
9270 if (sals
.sals
[i
].symtab
== NULL
)
9271 b
->source_file
= NULL
;
9273 b
->source_file
= xstrdup (sals
.sals
[i
].symtab
->filename
);
9275 if (b
->line_number
== 0)
9276 b
->line_number
= sals
.sals
[i
].line
;
9279 /* Update locations of permanent breakpoints. */
9280 if (b
->enable_state
== bp_permanent
)
9281 make_breakpoint_permanent (b
);
9283 /* If possible, carry over 'disable' status from existing breakpoints. */
9285 struct bp_location
*e
= existing_locations
;
9286 /* If there are multiple breakpoints with the same function name,
9287 e.g. for inline functions, comparing function names won't work.
9288 Instead compare pc addresses; this is just a heuristic as things
9289 may have moved, but in practice it gives the correct answer
9290 often enough until a better solution is found. */
9291 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
9293 for (; e
; e
= e
->next
)
9295 if (!e
->enabled
&& e
->function_name
)
9297 struct bp_location
*l
= b
->loc
;
9298 if (have_ambiguous_names
)
9300 for (; l
; l
= l
->next
)
9301 if (breakpoint_address_match (e
->pspace
->aspace
, e
->address
,
9302 l
->pspace
->aspace
, l
->address
))
9310 for (; l
; l
= l
->next
)
9311 if (l
->function_name
9312 && strcmp (e
->function_name
, l
->function_name
) == 0)
9322 update_global_location_list (1);
9326 /* Reset a breakpoint given it's struct breakpoint * BINT.
9327 The value we return ends up being the return value from catch_errors.
9328 Unused in this case. */
9331 breakpoint_re_set_one (void *bint
)
9333 /* get past catch_errs */
9334 struct breakpoint
*b
= (struct breakpoint
*) bint
;
9338 int *not_found_ptr
= ¬_found
;
9339 struct symtabs_and_lines sals
= {0};
9340 struct symtabs_and_lines expanded
= {0};
9342 enum enable_state save_enable
;
9343 struct gdb_exception e
;
9344 struct cleanup
*cleanups
= make_cleanup (null_cleanup
, NULL
);
9349 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
9353 case bp_hardware_breakpoint
:
9355 case bp_fast_tracepoint
:
9356 /* Do not attempt to re-set breakpoints disabled during startup. */
9357 if (b
->enable_state
== bp_startup_disabled
)
9360 if (b
->addr_string
== NULL
)
9362 /* Anything without a string can't be re-set. */
9363 delete_breakpoint (b
);
9367 set_language (b
->language
);
9368 input_radix
= b
->input_radix
;
9371 save_current_space_and_thread ();
9372 switch_to_program_space_and_thread (b
->pspace
);
9374 TRY_CATCH (e
, RETURN_MASK_ERROR
)
9376 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
9381 int not_found_and_ok
= 0;
9382 /* For pending breakpoints, it's expected that parsing
9383 will fail until the right shared library is loaded.
9384 User has already told to create pending breakpoints and
9385 don't need extra messages. If breakpoint is in bp_shlib_disabled
9386 state, then user already saw the message about that breakpoint
9387 being disabled, and don't want to see more errors. */
9389 && (b
->condition_not_parsed
9390 || (b
->loc
&& b
->loc
->shlib_disabled
)
9391 || b
->enable_state
== bp_disabled
))
9392 not_found_and_ok
= 1;
9394 if (!not_found_and_ok
)
9396 /* We surely don't want to warn about the same breakpoint
9397 10 times. One solution, implemented here, is disable
9398 the breakpoint on error. Another solution would be to
9399 have separate 'warning emitted' flag. Since this
9400 happens only when a binary has changed, I don't know
9401 which approach is better. */
9402 b
->enable_state
= bp_disabled
;
9403 throw_exception (e
);
9409 gdb_assert (sals
.nelts
== 1);
9411 resolve_sal_pc (&sals
.sals
[0]);
9412 if (b
->condition_not_parsed
&& s
&& s
[0])
9414 char *cond_string
= 0;
9418 find_condition_and_thread (s
, sals
.sals
[0].pc
,
9419 &cond_string
, &thread
, &task
);
9421 b
->cond_string
= cond_string
;
9424 b
->condition_not_parsed
= 0;
9427 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
9430 make_cleanup (xfree
, sals
.sals
);
9431 update_breakpoint_locations (b
, expanded
);
9435 case bp_hardware_watchpoint
:
9436 case bp_read_watchpoint
:
9437 case bp_access_watchpoint
:
9438 /* Watchpoint can be either on expression using entirely global variables,
9439 or it can be on local variables.
9441 Watchpoints of the first kind are never auto-deleted, and even persist
9442 across program restarts. Since they can use variables from shared
9443 libraries, we need to reparse expression as libraries are loaded
9446 Watchpoints on local variables can also change meaning as result
9447 of solib event. For example, if a watchpoint uses both a local and
9448 a global variables in expression, it's a local watchpoint, but
9449 unloading of a shared library will make the expression invalid.
9450 This is not a very common use case, but we still re-evaluate
9451 expression, to avoid surprises to the user.
9453 Note that for local watchpoints, we re-evaluate it only if
9454 watchpoints frame id is still valid. If it's not, it means
9455 the watchpoint is out of scope and will be deleted soon. In fact,
9456 I'm not sure we'll ever be called in this case.
9458 If a local watchpoint's frame id is still valid, then
9459 b->exp_valid_block is likewise valid, and we can safely use it.
9461 Don't do anything about disabled watchpoints, since they will
9462 be reevaluated again when enabled. */
9463 update_watchpoint (b
, 1 /* reparse */);
9465 /* We needn't really do anything to reset these, since the mask
9466 that requests them is unaffected by e.g., new libraries being
9472 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
9474 /* Delete overlay event and longjmp master breakpoints; they will be
9475 reset later by breakpoint_re_set. */
9476 case bp_overlay_event
:
9477 case bp_longjmp_master
:
9478 delete_breakpoint (b
);
9481 /* This breakpoint is special, it's set up when the inferior
9482 starts and we really don't want to touch it. */
9483 case bp_shlib_event
:
9485 /* Like bp_shlib_event, this breakpoint type is special.
9486 Once it is set up, we do not want to touch it. */
9487 case bp_thread_event
:
9489 /* Keep temporary breakpoints, which can be encountered when we step
9490 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
9491 Otherwise these should have been blown away via the cleanup chain
9492 or by breakpoint_init_inferior when we rerun the executable. */
9495 case bp_watchpoint_scope
:
9497 case bp_step_resume
:
9499 case bp_longjmp_resume
:
9504 do_cleanups (cleanups
);
9508 /* Re-set all breakpoints after symbols have been re-loaded. */
9510 breakpoint_re_set (void)
9512 struct breakpoint
*b
, *temp
;
9513 enum language save_language
;
9514 int save_input_radix
;
9515 struct cleanup
*old_chain
;
9517 save_language
= current_language
->la_language
;
9518 save_input_radix
= input_radix
;
9519 old_chain
= save_current_program_space ();
9521 ALL_BREAKPOINTS_SAFE (b
, temp
)
9523 /* Format possible error msg */
9524 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
9526 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
9527 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
9528 do_cleanups (cleanups
);
9530 set_language (save_language
);
9531 input_radix
= save_input_radix
;
9533 jit_breakpoint_re_set ();
9535 do_cleanups (old_chain
);
9537 create_overlay_event_breakpoint ("_ovly_debug_event");
9538 create_longjmp_master_breakpoint ("longjmp");
9539 create_longjmp_master_breakpoint ("_longjmp");
9540 create_longjmp_master_breakpoint ("siglongjmp");
9541 create_longjmp_master_breakpoint ("_siglongjmp");
9544 /* Reset the thread number of this breakpoint:
9546 - If the breakpoint is for all threads, leave it as-is.
9547 - Else, reset it to the current thread for inferior_ptid. */
9549 breakpoint_re_set_thread (struct breakpoint
*b
)
9551 if (b
->thread
!= -1)
9553 if (in_thread_list (inferior_ptid
))
9554 b
->thread
= pid_to_thread_id (inferior_ptid
);
9556 /* We're being called after following a fork. The new fork is
9557 selected as current, and unless this was a vfork will have a
9558 different program space from the original thread. Reset that
9560 b
->loc
->pspace
= current_program_space
;
9564 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9565 If from_tty is nonzero, it prints a message to that effect,
9566 which ends with a period (no newline). */
9569 set_ignore_count (int bptnum
, int count
, int from_tty
)
9571 struct breakpoint
*b
;
9577 if (b
->number
== bptnum
)
9579 b
->ignore_count
= count
;
9583 printf_filtered (_("Will stop next time breakpoint %d is reached."),
9585 else if (count
== 1)
9586 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
9589 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
9592 breakpoints_changed ();
9593 observer_notify_breakpoint_modified (b
->number
);
9597 error (_("No breakpoint number %d."), bptnum
);
9601 make_breakpoint_silent (struct breakpoint
*b
)
9603 /* Silence the breakpoint. */
9607 /* Command to set ignore-count of breakpoint N to COUNT. */
9610 ignore_command (char *args
, int from_tty
)
9616 error_no_arg (_("a breakpoint number"));
9618 num
= get_number (&p
);
9620 error (_("bad breakpoint number: '%s'"), args
);
9622 error (_("Second argument (specified ignore-count) is missing."));
9624 set_ignore_count (num
,
9625 longest_to_int (value_as_long (parse_and_eval (p
))),
9628 printf_filtered ("\n");
9631 /* Call FUNCTION on each of the breakpoints
9632 whose numbers are given in ARGS. */
9635 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
9640 struct breakpoint
*b
, *tmp
;
9644 error_no_arg (_("one or more breakpoint numbers"));
9651 num
= get_number_or_range (&p1
);
9654 warning (_("bad breakpoint number at or near '%s'"), p
);
9658 ALL_BREAKPOINTS_SAFE (b
, tmp
)
9659 if (b
->number
== num
)
9661 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
9664 if (related_breakpoint
)
9665 function (related_breakpoint
);
9669 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
9675 static struct bp_location
*
9676 find_location_by_number (char *number
)
9678 char *dot
= strchr (number
, '.');
9682 struct breakpoint
*b
;
9683 struct bp_location
*loc
;
9688 bp_num
= get_number_or_range (&p1
);
9690 error (_("Bad breakpoint number '%s'"), number
);
9693 if (b
->number
== bp_num
)
9698 if (!b
|| b
->number
!= bp_num
)
9699 error (_("Bad breakpoint number '%s'"), number
);
9702 loc_num
= get_number_or_range (&p1
);
9704 error (_("Bad breakpoint location number '%s'"), number
);
9708 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
9711 error (_("Bad breakpoint location number '%s'"), dot
+1);
9717 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
9718 If from_tty is nonzero, it prints a message to that effect,
9719 which ends with a period (no newline). */
9722 disable_breakpoint (struct breakpoint
*bpt
)
9724 /* Never disable a watchpoint scope breakpoint; we want to
9725 hit them when we leave scope so we can delete both the
9726 watchpoint and its scope breakpoint at that time. */
9727 if (bpt
->type
== bp_watchpoint_scope
)
9730 /* You can't disable permanent breakpoints. */
9731 if (bpt
->enable_state
== bp_permanent
)
9734 bpt
->enable_state
= bp_disabled
;
9736 update_global_location_list (0);
9738 observer_notify_breakpoint_modified (bpt
->number
);
9742 disable_command (char *args
, int from_tty
)
9744 struct breakpoint
*bpt
;
9746 ALL_BREAKPOINTS (bpt
)
9750 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
9755 case bp_fast_tracepoint
:
9757 case bp_hardware_breakpoint
:
9759 case bp_hardware_watchpoint
:
9760 case bp_read_watchpoint
:
9761 case bp_access_watchpoint
:
9762 disable_breakpoint (bpt
);
9766 else if (strchr (args
, '.'))
9768 struct bp_location
*loc
= find_location_by_number (args
);
9771 update_global_location_list (0);
9774 map_breakpoint_numbers (args
, disable_breakpoint
);
9778 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
9780 int target_resources_ok
, other_type_used
;
9783 if (bpt
->type
== bp_hardware_breakpoint
)
9786 i
= hw_breakpoint_used_count ();
9787 target_resources_ok
=
9788 target_can_use_hardware_watchpoint (bp_hardware_breakpoint
,
9790 if (target_resources_ok
== 0)
9791 error (_("No hardware breakpoint support in the target."));
9792 else if (target_resources_ok
< 0)
9793 error (_("Hardware breakpoints used exceeds limit."));
9796 if (bpt
->type
== bp_watchpoint
9797 || bpt
->type
== bp_hardware_watchpoint
9798 || bpt
->type
== bp_read_watchpoint
9799 || bpt
->type
== bp_access_watchpoint
)
9801 struct gdb_exception e
;
9803 TRY_CATCH (e
, RETURN_MASK_ALL
)
9805 update_watchpoint (bpt
, 1 /* reparse */);
9809 exception_fprintf (gdb_stderr
, e
, _("Cannot enable watchpoint %d: "),
9815 if (bpt
->enable_state
!= bp_permanent
)
9816 bpt
->enable_state
= bp_enabled
;
9817 bpt
->disposition
= disposition
;
9818 update_global_location_list (1);
9819 breakpoints_changed ();
9821 observer_notify_breakpoint_modified (bpt
->number
);
9826 enable_breakpoint (struct breakpoint
*bpt
)
9828 do_enable_breakpoint (bpt
, bpt
->disposition
);
9831 /* The enable command enables the specified breakpoints (or all defined
9832 breakpoints) so they once again become (or continue to be) effective
9833 in stopping the inferior. */
9836 enable_command (char *args
, int from_tty
)
9838 struct breakpoint
*bpt
;
9840 ALL_BREAKPOINTS (bpt
)
9844 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
9849 case bp_fast_tracepoint
:
9851 case bp_hardware_breakpoint
:
9853 case bp_hardware_watchpoint
:
9854 case bp_read_watchpoint
:
9855 case bp_access_watchpoint
:
9856 enable_breakpoint (bpt
);
9860 else if (strchr (args
, '.'))
9862 struct bp_location
*loc
= find_location_by_number (args
);
9865 update_global_location_list (1);
9868 map_breakpoint_numbers (args
, enable_breakpoint
);
9872 enable_once_breakpoint (struct breakpoint
*bpt
)
9874 do_enable_breakpoint (bpt
, disp_disable
);
9878 enable_once_command (char *args
, int from_tty
)
9880 map_breakpoint_numbers (args
, enable_once_breakpoint
);
9884 enable_delete_breakpoint (struct breakpoint
*bpt
)
9886 do_enable_breakpoint (bpt
, disp_del
);
9890 enable_delete_command (char *args
, int from_tty
)
9892 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
9896 set_breakpoint_cmd (char *args
, int from_tty
)
9901 show_breakpoint_cmd (char *args
, int from_tty
)
9905 /* Invalidate last known value of any hardware watchpoint if
9906 the memory which that value represents has been written to by
9910 invalidate_bp_value_on_memory_change (CORE_ADDR addr
, int len
,
9911 const bfd_byte
*data
)
9913 struct breakpoint
*bp
;
9915 ALL_BREAKPOINTS (bp
)
9916 if (bp
->enable_state
== bp_enabled
9917 && bp
->type
== bp_hardware_watchpoint
9918 && bp
->val_valid
&& bp
->val
)
9920 struct bp_location
*loc
;
9922 for (loc
= bp
->loc
; loc
!= NULL
; loc
= loc
->next
)
9923 if (loc
->loc_type
== bp_loc_hardware_watchpoint
9924 && loc
->address
+ loc
->length
> addr
9925 && addr
+ len
> loc
->address
)
9927 value_free (bp
->val
);
9934 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
9936 struct symtabs_and_lines
9937 decode_line_spec_1 (char *string
, int funfirstline
)
9939 struct symtabs_and_lines sals
;
9941 error (_("Empty line specification."));
9942 if (default_breakpoint_valid
)
9943 sals
= decode_line_1 (&string
, funfirstline
,
9944 default_breakpoint_symtab
,
9945 default_breakpoint_line
,
9946 (char ***) NULL
, NULL
);
9948 sals
= decode_line_1 (&string
, funfirstline
,
9949 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
9951 error (_("Junk at end of line specification: %s"), string
);
9955 /* Create and insert a raw software breakpoint at PC. Return an
9956 identifier, which should be used to remove the breakpoint later.
9957 In general, places which call this should be using something on the
9958 breakpoint chain instead; this function should be eliminated
9962 deprecated_insert_raw_breakpoint (struct gdbarch
*gdbarch
,
9963 struct address_space
*aspace
, CORE_ADDR pc
)
9965 struct bp_target_info
*bp_tgt
;
9967 bp_tgt
= XZALLOC (struct bp_target_info
);
9969 bp_tgt
->placed_address_space
= aspace
;
9970 bp_tgt
->placed_address
= pc
;
9972 if (target_insert_breakpoint (gdbarch
, bp_tgt
) != 0)
9974 /* Could not insert the breakpoint. */
9982 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
9985 deprecated_remove_raw_breakpoint (struct gdbarch
*gdbarch
, void *bp
)
9987 struct bp_target_info
*bp_tgt
= bp
;
9990 ret
= target_remove_breakpoint (gdbarch
, bp_tgt
);
9996 /* One (or perhaps two) breakpoints used for software single stepping. */
9998 static void *single_step_breakpoints
[2];
9999 static struct gdbarch
*single_step_gdbarch
[2];
10001 /* Create and insert a breakpoint for software single step. */
10004 insert_single_step_breakpoint (struct gdbarch
*gdbarch
,
10005 struct address_space
*aspace
, CORE_ADDR next_pc
)
10009 if (single_step_breakpoints
[0] == NULL
)
10011 bpt_p
= &single_step_breakpoints
[0];
10012 single_step_gdbarch
[0] = gdbarch
;
10016 gdb_assert (single_step_breakpoints
[1] == NULL
);
10017 bpt_p
= &single_step_breakpoints
[1];
10018 single_step_gdbarch
[1] = gdbarch
;
10021 /* NOTE drow/2006-04-11: A future improvement to this function would be
10022 to only create the breakpoints once, and actually put them on the
10023 breakpoint chain. That would let us use set_raw_breakpoint. We could
10024 adjust the addresses each time they were needed. Doing this requires
10025 corresponding changes elsewhere where single step breakpoints are
10026 handled, however. So, for now, we use this. */
10028 *bpt_p
= deprecated_insert_raw_breakpoint (gdbarch
, aspace
, next_pc
);
10029 if (*bpt_p
== NULL
)
10030 error (_("Could not insert single-step breakpoint at %s"),
10031 paddress (gdbarch
, next_pc
));
10034 /* Remove and delete any breakpoints used for software single step. */
10037 remove_single_step_breakpoints (void)
10039 gdb_assert (single_step_breakpoints
[0] != NULL
);
10041 /* See insert_single_step_breakpoint for more about this deprecated
10043 deprecated_remove_raw_breakpoint (single_step_gdbarch
[0],
10044 single_step_breakpoints
[0]);
10045 single_step_gdbarch
[0] = NULL
;
10046 single_step_breakpoints
[0] = NULL
;
10048 if (single_step_breakpoints
[1] != NULL
)
10050 deprecated_remove_raw_breakpoint (single_step_gdbarch
[1],
10051 single_step_breakpoints
[1]);
10052 single_step_gdbarch
[1] = NULL
;
10053 single_step_breakpoints
[1] = NULL
;
10057 /* Check whether a software single-step breakpoint is inserted at PC. */
10060 single_step_breakpoint_inserted_here_p (struct address_space
*aspace
, CORE_ADDR pc
)
10064 for (i
= 0; i
< 2; i
++)
10066 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
10068 && breakpoint_address_match (bp_tgt
->placed_address_space
,
10069 bp_tgt
->placed_address
,
10077 /* Returns 0 if 'bp' is NOT a syscall catchpoint,
10078 non-zero otherwise. */
10080 is_syscall_catchpoint_enabled (struct breakpoint
*bp
)
10082 if (syscall_catchpoint_p (bp
)
10083 && bp
->enable_state
!= bp_disabled
10084 && bp
->enable_state
!= bp_call_disabled
)
10091 catch_syscall_enabled (void)
10093 struct inferior
*inf
= current_inferior ();
10095 return inf
->total_syscalls_count
!= 0;
10099 catching_syscall_number (int syscall_number
)
10101 struct breakpoint
*bp
;
10103 ALL_BREAKPOINTS (bp
)
10104 if (is_syscall_catchpoint_enabled (bp
))
10106 if (bp
->syscalls_to_be_caught
)
10110 VEC_iterate (int, bp
->syscalls_to_be_caught
, i
, iter
);
10112 if (syscall_number
== iter
)
10122 /* Complete syscall names. Used by "catch syscall". */
10124 catch_syscall_completer (struct cmd_list_element
*cmd
,
10125 char *text
, char *word
)
10127 const char **list
= get_syscall_names ();
10128 return (list
== NULL
) ? NULL
: complete_on_enum (list
, text
, word
);
10131 /* Tracepoint-specific operations. */
10133 /* Set tracepoint count to NUM. */
10135 set_tracepoint_count (int num
)
10137 tracepoint_count
= num
;
10138 set_internalvar_integer (lookup_internalvar ("tpnum"), num
);
10142 trace_command (char *arg
, int from_tty
)
10144 if (create_breakpoint (get_current_arch (),
10146 NULL
, 0, 1 /* parse arg */,
10147 0 /* tempflag */, 0 /* hardwareflag */,
10149 0 /* Ignore count */,
10150 pending_break_support
,
10154 set_tracepoint_count (breakpoint_count
);
10158 ftrace_command (char *arg
, int from_tty
)
10160 if (create_breakpoint (get_current_arch (),
10162 NULL
, 0, 1 /* parse arg */,
10163 0 /* tempflag */, 1 /* hardwareflag */,
10165 0 /* Ignore count */,
10166 pending_break_support
,
10170 set_tracepoint_count (breakpoint_count
);
10173 /* Given information about a tracepoint as recorded on a target (which
10174 can be either a live system or a trace file), attempt to create an
10175 equivalent GDB tracepoint. This is not a reliable process, since
10176 the target does not necessarily have all the information used when
10177 the tracepoint was originally defined. */
10179 struct breakpoint
*
10180 create_tracepoint_from_upload (struct uploaded_tp
*utp
)
10183 struct breakpoint
*tp
;
10185 /* In the absence of a source location, fall back to raw address. */
10186 sprintf (buf
, "*%s", paddress (get_current_arch(), utp
->addr
));
10188 if (!create_breakpoint (get_current_arch (),
10190 NULL
, 0, 1 /* parse arg */,
10192 (utp
->type
== bp_fast_tracepoint
) /* hardwareflag */,
10194 0 /* Ignore count */,
10195 pending_break_support
,
10198 utp
->enabled
/* enabled */))
10201 set_tracepoint_count (breakpoint_count
);
10203 tp
= get_tracepoint (tracepoint_count
);
10204 gdb_assert (tp
!= NULL
);
10208 sprintf (buf
, "%d %d", utp
->pass
, tp
->number
);
10210 trace_pass_command (buf
, 0);
10215 printf_filtered ("Want to restore a condition\n");
10218 if (utp
->numactions
> 0)
10220 printf_filtered ("Want to restore action list\n");
10223 if (utp
->num_step_actions
> 0)
10225 printf_filtered ("Want to restore action list\n");
10231 /* Print information on tracepoint number TPNUM_EXP, or all if
10235 tracepoints_info (char *tpnum_exp
, int from_tty
)
10237 struct breakpoint
*b
;
10238 int tps_to_list
= 0;
10240 /* In the no-arguments case, say "No tracepoints" if none found. */
10241 if (tpnum_exp
== 0)
10243 ALL_TRACEPOINTS (b
)
10245 if (b
->number
>= 0)
10253 ui_out_message (uiout
, 0, "No tracepoints.\n");
10258 /* Otherwise be the same as "info break". */
10259 breakpoints_info (tpnum_exp
, from_tty
);
10262 /* The 'enable trace' command enables tracepoints.
10263 Not supported by all targets. */
10265 enable_trace_command (char *args
, int from_tty
)
10267 enable_command (args
, from_tty
);
10270 /* The 'disable trace' command disables tracepoints.
10271 Not supported by all targets. */
10273 disable_trace_command (char *args
, int from_tty
)
10275 disable_command (args
, from_tty
);
10278 /* Remove a tracepoint (or all if no argument) */
10280 delete_trace_command (char *arg
, int from_tty
)
10282 struct breakpoint
*b
, *temp
;
10288 int breaks_to_delete
= 0;
10290 /* Delete all breakpoints if no argument.
10291 Do not delete internal or call-dummy breakpoints, these
10292 have to be deleted with an explicit breakpoint number argument. */
10293 ALL_TRACEPOINTS (b
)
10295 if (b
->number
>= 0)
10297 breaks_to_delete
= 1;
10302 /* Ask user only if there are some breakpoints to delete. */
10304 || (breaks_to_delete
&& query (_("Delete all tracepoints? "))))
10306 ALL_BREAKPOINTS_SAFE (b
, temp
)
10308 if (tracepoint_type (b
)
10310 delete_breakpoint (b
);
10315 map_breakpoint_numbers (arg
, delete_breakpoint
);
10318 /* Set passcount for tracepoint.
10320 First command argument is passcount, second is tracepoint number.
10321 If tracepoint number omitted, apply to most recently defined.
10322 Also accepts special argument "all". */
10325 trace_pass_command (char *args
, int from_tty
)
10327 struct breakpoint
*t1
= (struct breakpoint
*) -1, *t2
;
10328 unsigned int count
;
10331 if (args
== 0 || *args
== 0)
10332 error (_("passcount command requires an argument (count + optional TP num)"));
10334 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
10336 while (*args
&& isspace ((int) *args
))
10339 if (*args
&& strncasecmp (args
, "all", 3) == 0)
10341 args
+= 3; /* Skip special argument "all". */
10344 error (_("Junk at end of arguments."));
10347 t1
= get_tracepoint_by_number (&args
, 1, 1);
10353 ALL_TRACEPOINTS (t2
)
10354 if (t1
== (struct breakpoint
*) -1 || t1
== t2
)
10356 t2
->pass_count
= count
;
10357 observer_notify_tracepoint_modified (t2
->number
);
10359 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"),
10360 t2
->number
, count
);
10362 if (! all
&& *args
)
10363 t1
= get_tracepoint_by_number (&args
, 1, 0);
10369 struct breakpoint
*
10370 get_tracepoint (int num
)
10372 struct breakpoint
*t
;
10374 ALL_TRACEPOINTS (t
)
10375 if (t
->number
== num
)
10381 /* Find the tracepoint with the given target-side number (which may be
10382 different from the tracepoint number after disconnecting and
10385 struct breakpoint
*
10386 get_tracepoint_by_number_on_target (int num
)
10388 struct breakpoint
*t
;
10390 ALL_TRACEPOINTS (t
)
10391 if (t
->number_on_target
== num
)
10397 /* Utility: parse a tracepoint number and look it up in the list.
10398 If MULTI_P is true, there might be a range of tracepoints in ARG.
10399 if OPTIONAL_P is true, then if the argument is missing, the most
10400 recent tracepoint (tracepoint_count) is returned. */
10401 struct breakpoint
*
10402 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
10404 extern int tracepoint_count
;
10405 struct breakpoint
*t
;
10407 char *instring
= arg
== NULL
? NULL
: *arg
;
10409 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
10412 tpnum
= tracepoint_count
;
10414 error_no_arg (_("tracepoint number"));
10417 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
10421 if (instring
&& *instring
)
10422 printf_filtered (_("bad tracepoint number at or near '%s'\n"),
10425 printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n"));
10429 ALL_TRACEPOINTS (t
)
10430 if (t
->number
== tpnum
)
10435 /* FIXME: if we are in the middle of a range we don't want to give
10436 a message. The current interface to get_number_or_range doesn't
10437 allow us to discover this. */
10438 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
10442 /* save-tracepoints command */
10444 tracepoint_save_command (char *args
, int from_tty
)
10446 struct breakpoint
*tp
;
10448 struct command_line
*line
;
10451 struct cleanup
*cleanup
;
10452 struct ui_file
*fp
;
10454 if (args
== 0 || *args
== 0)
10455 error (_("Argument required (file name in which to save tracepoints)"));
10457 /* See if we have anything to save. */
10458 ALL_TRACEPOINTS (tp
)
10465 warning (_("save-tracepoints: no tracepoints to save."));
10469 pathname
= tilde_expand (args
);
10470 cleanup
= make_cleanup (xfree
, pathname
);
10471 fp
= gdb_fopen (pathname
, "w");
10473 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
10474 args
, safe_strerror (errno
));
10475 make_cleanup_ui_file_delete (fp
);
10477 ALL_TRACEPOINTS (tp
)
10479 if (tp
->addr_string
)
10480 fprintf_unfiltered (fp
, "trace %s\n", tp
->addr_string
);
10483 sprintf_vma (tmp
, tp
->loc
->address
);
10484 fprintf_unfiltered (fp
, "trace *0x%s\n", tmp
);
10487 if (tp
->pass_count
)
10488 fprintf_unfiltered (fp
, " passcount %d\n", tp
->pass_count
);
10492 volatile struct gdb_exception ex
;
10494 fprintf_unfiltered (fp
, " actions\n");
10496 ui_out_redirect (uiout
, fp
);
10497 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
10499 print_command_lines (uiout
, tp
->commands
->commands
, 2);
10501 ui_out_redirect (uiout
, NULL
);
10504 throw_exception (ex
);
10506 fprintf_unfiltered (fp
, " end\n");
10509 do_cleanups (cleanup
);
10511 printf_filtered (_("Tracepoints saved to file '%s'.\n"), args
);
10515 /* Create a vector of all tracepoints. */
10517 VEC(breakpoint_p
) *
10520 VEC(breakpoint_p
) *tp_vec
= 0;
10521 struct breakpoint
*tp
;
10523 ALL_TRACEPOINTS (tp
)
10525 VEC_safe_push (breakpoint_p
, tp_vec
, tp
);
10532 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
10533 It is defined as a macro to prevent duplication.
10534 COMMAND should be a string constant containing the name of the command. */
10535 #define BREAK_ARGS_HELP(command) \
10536 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
10537 LOCATION may be a line number, function name, or \"*\" and an address.\n\
10538 If a line number is specified, break at start of code for that line.\n\
10539 If a function is specified, break at start of code for that function.\n\
10540 If an address is specified, break at that exact address.\n\
10541 With no LOCATION, uses current execution address of selected stack frame.\n\
10542 This is useful for breaking on return to a stack frame.\n\
10544 THREADNUM is the number from \"info threads\".\n\
10545 CONDITION is a boolean expression.\n\
10547 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
10549 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
10551 /* List of subcommands for "catch". */
10552 static struct cmd_list_element
*catch_cmdlist
;
10554 /* List of subcommands for "tcatch". */
10555 static struct cmd_list_element
*tcatch_cmdlist
;
10557 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
10558 lists, and pass some additional user data to the command function. */
10560 add_catch_command (char *name
, char *docstring
,
10561 void (*sfunc
) (char *args
, int from_tty
,
10562 struct cmd_list_element
*command
),
10563 char **(*completer
) (struct cmd_list_element
*cmd
,
10564 char *text
, char *word
),
10565 void *user_data_catch
,
10566 void *user_data_tcatch
)
10568 struct cmd_list_element
*command
;
10570 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10572 set_cmd_sfunc (command
, sfunc
);
10573 set_cmd_context (command
, user_data_catch
);
10574 set_cmd_completer (command
, completer
);
10576 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
10578 set_cmd_sfunc (command
, sfunc
);
10579 set_cmd_context (command
, user_data_tcatch
);
10580 set_cmd_completer (command
, completer
);
10584 clear_syscall_counts (struct inferior
*inf
)
10586 inf
->total_syscalls_count
= 0;
10587 inf
->any_syscall_count
= 0;
10588 VEC_free (int, inf
->syscalls_counts
);
10592 _initialize_breakpoint (void)
10594 static struct cmd_list_element
*breakpoint_set_cmdlist
;
10595 static struct cmd_list_element
*breakpoint_show_cmdlist
;
10596 struct cmd_list_element
*c
;
10598 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
10599 observer_attach_inferior_exit (clear_syscall_counts
);
10600 observer_attach_memory_changed (invalidate_bp_value_on_memory_change
);
10602 breakpoint_chain
= 0;
10603 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
10604 before a breakpoint is set. */
10605 breakpoint_count
= 0;
10607 tracepoint_count
= 0;
10609 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
10610 Set ignore-count of breakpoint number N to COUNT.\n\
10611 Usage is `ignore N COUNT'."));
10613 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
10615 add_com ("commands", class_breakpoint
, commands_command
, _("\
10616 Set commands to be executed when a breakpoint is hit.\n\
10617 Give breakpoint number as argument after \"commands\".\n\
10618 With no argument, the targeted breakpoint is the last one set.\n\
10619 The commands themselves follow starting on the next line.\n\
10620 Type a line containing \"end\" to indicate the end of them.\n\
10621 Give \"silent\" as the first line to make the breakpoint silent;\n\
10622 then no output is printed when it is hit, except what the commands print."));
10624 add_com ("condition", class_breakpoint
, condition_command
, _("\
10625 Specify breakpoint number N to break only if COND is true.\n\
10626 Usage is `condition N COND', where N is an integer and COND is an\n\
10627 expression to be evaluated whenever breakpoint N is reached."));
10629 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
10630 Set a temporary breakpoint.\n\
10631 Like \"break\" except the breakpoint is only temporary,\n\
10632 so it will be deleted when hit. Equivalent to \"break\" followed\n\
10633 by using \"enable delete\" on the breakpoint number.\n\
10635 BREAK_ARGS_HELP ("tbreak")));
10636 set_cmd_completer (c
, location_completer
);
10638 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
10639 Set a hardware assisted breakpoint.\n\
10640 Like \"break\" except the breakpoint requires hardware support,\n\
10641 some target hardware may not have this support.\n\
10643 BREAK_ARGS_HELP ("hbreak")));
10644 set_cmd_completer (c
, location_completer
);
10646 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
10647 Set a temporary hardware assisted breakpoint.\n\
10648 Like \"hbreak\" except the breakpoint is only temporary,\n\
10649 so it will be deleted when hit.\n\
10651 BREAK_ARGS_HELP ("thbreak")));
10652 set_cmd_completer (c
, location_completer
);
10654 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
10655 Enable some breakpoints.\n\
10656 Give breakpoint numbers (separated by spaces) as arguments.\n\
10657 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10658 This is used to cancel the effect of the \"disable\" command.\n\
10659 With a subcommand you can enable temporarily."),
10660 &enablelist
, "enable ", 1, &cmdlist
);
10662 add_com ("ab", class_breakpoint
, enable_command
, _("\
10663 Enable some breakpoints.\n\
10664 Give breakpoint numbers (separated by spaces) as arguments.\n\
10665 With no subcommand, breakpoints are enabled until you command otherwise.\n\
10666 This is used to cancel the effect of the \"disable\" command.\n\
10667 With a subcommand you can enable temporarily."));
10669 add_com_alias ("en", "enable", class_breakpoint
, 1);
10671 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
10672 Enable some breakpoints.\n\
10673 Give breakpoint numbers (separated by spaces) as arguments.\n\
10674 This is used to cancel the effect of the \"disable\" command.\n\
10675 May be abbreviated to simply \"enable\".\n"),
10676 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
10678 add_cmd ("once", no_class
, enable_once_command
, _("\
10679 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10680 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10683 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10684 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10685 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10688 add_cmd ("delete", no_class
, enable_delete_command
, _("\
10689 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
10690 If a breakpoint is hit while enabled in this fashion, it is deleted."),
10693 add_cmd ("once", no_class
, enable_once_command
, _("\
10694 Enable breakpoints for one hit. Give breakpoint numbers.\n\
10695 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
10698 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
10699 Disable some breakpoints.\n\
10700 Arguments are breakpoint numbers with spaces in between.\n\
10701 To disable all breakpoints, give no argument.\n\
10702 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
10703 &disablelist
, "disable ", 1, &cmdlist
);
10704 add_com_alias ("dis", "disable", class_breakpoint
, 1);
10705 add_com_alias ("disa", "disable", class_breakpoint
, 1);
10707 add_com ("sb", class_breakpoint
, disable_command
, _("\
10708 Disable some breakpoints.\n\
10709 Arguments are breakpoint numbers with spaces in between.\n\
10710 To disable all breakpoints, give no argument.\n\
10711 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
10713 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
10714 Disable some breakpoints.\n\
10715 Arguments are breakpoint numbers with spaces in between.\n\
10716 To disable all breakpoints, give no argument.\n\
10717 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
10718 This command may be abbreviated \"disable\"."),
10721 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
10722 Delete some breakpoints or auto-display expressions.\n\
10723 Arguments are breakpoint numbers with spaces in between.\n\
10724 To delete all breakpoints, give no argument.\n\
10726 Also a prefix command for deletion of other GDB objects.\n\
10727 The \"unset\" command is also an alias for \"delete\"."),
10728 &deletelist
, "delete ", 1, &cmdlist
);
10729 add_com_alias ("d", "delete", class_breakpoint
, 1);
10730 add_com_alias ("del", "delete", class_breakpoint
, 1);
10732 add_com ("db", class_breakpoint
, delete_command
, _("\
10733 Delete some breakpoints.\n\
10734 Arguments are breakpoint numbers with spaces in between.\n\
10735 To delete all breakpoints, give no argument.\n"));
10737 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
10738 Delete some breakpoints or auto-display expressions.\n\
10739 Arguments are breakpoint numbers with spaces in between.\n\
10740 To delete all breakpoints, give no argument.\n\
10741 This command may be abbreviated \"delete\"."),
10744 add_com ("clear", class_breakpoint
, clear_command
, _("\
10745 Clear breakpoint at specified line or function.\n\
10746 Argument may be line number, function name, or \"*\" and an address.\n\
10747 If line number is specified, all breakpoints in that line are cleared.\n\
10748 If function is specified, breakpoints at beginning of function are cleared.\n\
10749 If an address is specified, breakpoints at that address are cleared.\n\
10751 With no argument, clears all breakpoints in the line that the selected frame\n\
10752 is executing in.\n\
10754 See also the \"delete\" command which clears breakpoints by number."));
10756 c
= add_com ("break", class_breakpoint
, break_command
, _("\
10757 Set breakpoint at specified line or function.\n"
10758 BREAK_ARGS_HELP ("break")));
10759 set_cmd_completer (c
, location_completer
);
10761 add_com_alias ("b", "break", class_run
, 1);
10762 add_com_alias ("br", "break", class_run
, 1);
10763 add_com_alias ("bre", "break", class_run
, 1);
10764 add_com_alias ("brea", "break", class_run
, 1);
10767 add_com_alias ("ba", "break", class_breakpoint
, 1);
10771 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
10772 Break in function/address or break at a line in the current file."),
10773 &stoplist
, "stop ", 1, &cmdlist
);
10774 add_cmd ("in", class_breakpoint
, stopin_command
,
10775 _("Break in function or address."), &stoplist
);
10776 add_cmd ("at", class_breakpoint
, stopat_command
,
10777 _("Break at a line in the current file."), &stoplist
);
10778 add_com ("status", class_info
, breakpoints_info
, _("\
10779 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10780 The \"Type\" column indicates one of:\n\
10781 \tbreakpoint - normal breakpoint\n\
10782 \twatchpoint - watchpoint\n\
10783 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10784 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10785 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10786 address and file/line number respectively.\n\
10788 Convenience variable \"$_\" and default examine address for \"x\"\n\
10789 are set to the address of the last breakpoint listed unless the command\n\
10790 is prefixed with \"server \".\n\n\
10791 Convenience variable \"$bpnum\" contains the number of the last\n\
10792 breakpoint set."));
10795 add_info ("breakpoints", breakpoints_info
, _("\
10796 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10797 The \"Type\" column indicates one of:\n\
10798 \tbreakpoint - normal breakpoint\n\
10799 \twatchpoint - watchpoint\n\
10800 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10801 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10802 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10803 address and file/line number respectively.\n\
10805 Convenience variable \"$_\" and default examine address for \"x\"\n\
10806 are set to the address of the last breakpoint listed unless the command\n\
10807 is prefixed with \"server \".\n\n\
10808 Convenience variable \"$bpnum\" contains the number of the last\n\
10809 breakpoint set."));
10811 add_info_alias ("b", "breakpoints", 1);
10814 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
10815 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
10816 The \"Type\" column indicates one of:\n\
10817 \tbreakpoint - normal breakpoint\n\
10818 \twatchpoint - watchpoint\n\
10819 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10820 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10821 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10822 address and file/line number respectively.\n\
10824 Convenience variable \"$_\" and default examine address for \"x\"\n\
10825 are set to the address of the last breakpoint listed unless the command\n\
10826 is prefixed with \"server \".\n\n\
10827 Convenience variable \"$bpnum\" contains the number of the last\n\
10828 breakpoint set."));
10830 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
10831 Status of all breakpoints, or breakpoint number NUMBER.\n\
10832 The \"Type\" column indicates one of:\n\
10833 \tbreakpoint - normal breakpoint\n\
10834 \twatchpoint - watchpoint\n\
10835 \tlongjmp - internal breakpoint used to step through longjmp()\n\
10836 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
10837 \tuntil - internal breakpoint used by the \"until\" command\n\
10838 \tfinish - internal breakpoint used by the \"finish\" command\n\
10839 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
10840 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
10841 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
10842 address and file/line number respectively.\n\
10844 Convenience variable \"$_\" and default examine address for \"x\"\n\
10845 are set to the address of the last breakpoint listed unless the command\n\
10846 is prefixed with \"server \".\n\n\
10847 Convenience variable \"$bpnum\" contains the number of the last\n\
10849 &maintenanceinfolist
);
10851 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
10852 Set catchpoints to catch events."),
10853 &catch_cmdlist
, "catch ",
10854 0/*allow-unknown*/, &cmdlist
);
10856 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
10857 Set temporary catchpoints to catch events."),
10858 &tcatch_cmdlist
, "tcatch ",
10859 0/*allow-unknown*/, &cmdlist
);
10861 /* Add catch and tcatch sub-commands. */
10862 add_catch_command ("catch", _("\
10863 Catch an exception, when caught.\n\
10864 With an argument, catch only exceptions with the given name."),
10865 catch_catch_command
,
10869 add_catch_command ("throw", _("\
10870 Catch an exception, when thrown.\n\
10871 With an argument, catch only exceptions with the given name."),
10872 catch_throw_command
,
10876 add_catch_command ("fork", _("Catch calls to fork."),
10877 catch_fork_command_1
,
10879 (void *) (uintptr_t) catch_fork_permanent
,
10880 (void *) (uintptr_t) catch_fork_temporary
);
10881 add_catch_command ("vfork", _("Catch calls to vfork."),
10882 catch_fork_command_1
,
10884 (void *) (uintptr_t) catch_vfork_permanent
,
10885 (void *) (uintptr_t) catch_vfork_temporary
);
10886 add_catch_command ("exec", _("Catch calls to exec."),
10887 catch_exec_command_1
,
10891 add_catch_command ("syscall", _("\
10892 Catch system calls by their names and/or numbers.\n\
10893 Arguments say which system calls to catch. If no arguments\n\
10894 are given, every system call will be caught.\n\
10895 Arguments, if given, should be one or more system call names\n\
10896 (if your system supports that), or system call numbers."),
10897 catch_syscall_command_1
,
10898 catch_syscall_completer
,
10901 add_catch_command ("exception", _("\
10902 Catch Ada exceptions, when raised.\n\
10903 With an argument, catch only exceptions with the given name."),
10904 catch_ada_exception_command
,
10908 add_catch_command ("assert", _("\
10909 Catch failed Ada assertions, when raised.\n\
10910 With an argument, catch only exceptions with the given name."),
10911 catch_assert_command
,
10916 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
10917 Set a watchpoint for an expression.\n\
10918 A watchpoint stops execution of your program whenever the value of\n\
10919 an expression changes."));
10920 set_cmd_completer (c
, expression_completer
);
10922 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
10923 Set a read watchpoint for an expression.\n\
10924 A watchpoint stops execution of your program whenever the value of\n\
10925 an expression is read."));
10926 set_cmd_completer (c
, expression_completer
);
10928 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
10929 Set a watchpoint for an expression.\n\
10930 A watchpoint stops execution of your program whenever the value of\n\
10931 an expression is either read or written."));
10932 set_cmd_completer (c
, expression_completer
);
10934 add_info ("watchpoints", breakpoints_info
,
10935 _("Synonym for ``info breakpoints''."));
10938 /* XXX: cagney/2005-02-23: This should be a boolean, and should
10939 respond to changes - contrary to the description. */
10940 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
10941 &can_use_hw_watchpoints
, _("\
10942 Set debugger's willingness to use watchpoint hardware."), _("\
10943 Show debugger's willingness to use watchpoint hardware."), _("\
10944 If zero, gdb will not use hardware for new watchpoints, even if\n\
10945 such is available. (However, any hardware watchpoints that were\n\
10946 created before setting this to nonzero, will continue to use watchpoint\n\
10949 show_can_use_hw_watchpoints
,
10950 &setlist
, &showlist
);
10952 can_use_hw_watchpoints
= 1;
10954 /* Tracepoint manipulation commands. */
10956 c
= add_com ("trace", class_breakpoint
, trace_command
, _("\
10957 Set a tracepoint at specified line or function.\n\
10959 BREAK_ARGS_HELP ("trace") "\n\
10960 Do \"help tracepoints\" for info on other tracepoint commands."));
10961 set_cmd_completer (c
, location_completer
);
10963 add_com_alias ("tp", "trace", class_alias
, 0);
10964 add_com_alias ("tr", "trace", class_alias
, 1);
10965 add_com_alias ("tra", "trace", class_alias
, 1);
10966 add_com_alias ("trac", "trace", class_alias
, 1);
10968 c
= add_com ("ftrace", class_breakpoint
, ftrace_command
, _("\
10969 Set a fast tracepoint at specified line or function.\n\
10971 BREAK_ARGS_HELP ("ftrace") "\n\
10972 Do \"help tracepoints\" for info on other tracepoint commands."));
10973 set_cmd_completer (c
, location_completer
);
10975 add_info ("tracepoints", tracepoints_info
, _("\
10976 Status of tracepoints, or tracepoint number NUMBER.\n\
10977 Convenience variable \"$tpnum\" contains the number of the\n\
10978 last tracepoint set."));
10980 add_info_alias ("tp", "tracepoints", 1);
10982 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
10983 Delete specified tracepoints.\n\
10984 Arguments are tracepoint numbers, separated by spaces.\n\
10985 No argument means delete all tracepoints."),
10988 c
= add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
10989 Disable specified tracepoints.\n\
10990 Arguments are tracepoint numbers, separated by spaces.\n\
10991 No argument means disable all tracepoints."),
10993 deprecate_cmd (c
, "disable");
10995 c
= add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
10996 Enable specified tracepoints.\n\
10997 Arguments are tracepoint numbers, separated by spaces.\n\
10998 No argument means enable all tracepoints."),
11000 deprecate_cmd (c
, "enable");
11002 add_com ("passcount", class_trace
, trace_pass_command
, _("\
11003 Set the passcount for a tracepoint.\n\
11004 The trace will end when the tracepoint has been passed 'count' times.\n\
11005 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
11006 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
11008 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
11009 Save current tracepoint definitions as a script.\n\
11010 Use the 'source' command in another debug session to restore them."));
11011 set_cmd_completer (c
, filename_completer
);
11013 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
11014 Breakpoint specific settings\n\
11015 Configure various breakpoint-specific variables such as\n\
11016 pending breakpoint behavior"),
11017 &breakpoint_set_cmdlist
, "set breakpoint ",
11018 0/*allow-unknown*/, &setlist
);
11019 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
11020 Breakpoint specific settings\n\
11021 Configure various breakpoint-specific variables such as\n\
11022 pending breakpoint behavior"),
11023 &breakpoint_show_cmdlist
, "show breakpoint ",
11024 0/*allow-unknown*/, &showlist
);
11026 add_setshow_auto_boolean_cmd ("pending", no_class
,
11027 &pending_break_support
, _("\
11028 Set debugger's behavior regarding pending breakpoints."), _("\
11029 Show debugger's behavior regarding pending breakpoints."), _("\
11030 If on, an unrecognized breakpoint location will cause gdb to create a\n\
11031 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
11032 an error. If auto, an unrecognized breakpoint location results in a\n\
11033 user-query to see if a pending breakpoint should be created."),
11035 show_pending_break_support
,
11036 &breakpoint_set_cmdlist
,
11037 &breakpoint_show_cmdlist
);
11039 pending_break_support
= AUTO_BOOLEAN_AUTO
;
11041 add_setshow_boolean_cmd ("auto-hw", no_class
,
11042 &automatic_hardware_breakpoints
, _("\
11043 Set automatic usage of hardware breakpoints."), _("\
11044 Show automatic usage of hardware breakpoints."), _("\
11045 If set, the debugger will automatically use hardware breakpoints for\n\
11046 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
11047 a warning will be emitted for such breakpoints."),
11049 show_automatic_hardware_breakpoints
,
11050 &breakpoint_set_cmdlist
,
11051 &breakpoint_show_cmdlist
);
11053 add_setshow_enum_cmd ("always-inserted", class_support
,
11054 always_inserted_enums
, &always_inserted_mode
, _("\
11055 Set mode for inserting breakpoints."), _("\
11056 Show mode for inserting breakpoints."), _("\
11057 When this mode is off, breakpoints are inserted in inferior when it is\n\
11058 resumed, and removed when execution stops. When this mode is on,\n\
11059 breakpoints are inserted immediately and removed only when the user\n\
11060 deletes the breakpoint. When this mode is auto (which is the default),\n\
11061 the behaviour depends on the non-stop setting (see help set non-stop).\n\
11062 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
11063 behaves as if always-inserted mode is on; if gdb is controlling the\n\
11064 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
11066 &show_always_inserted_mode
,
11067 &breakpoint_set_cmdlist
,
11068 &breakpoint_show_cmdlist
);
11070 automatic_hardware_breakpoints
= 1;
11072 observer_attach_about_to_proceed (breakpoint_about_to_proceed
);