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 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/>. */
27 #include "breakpoint.h"
29 #include "expression.h"
35 #include "gdbthread.h"
38 #include "gdb_string.h"
45 #include "completer.h"
48 #include "cli/cli-script.h"
49 #include "gdb_assert.h"
54 #include "exceptions.h"
60 #include "mi/mi-common.h"
62 /* Arguments to pass as context to some catch command handlers. */
63 #define CATCH_PERMANENT ((void *) (uintptr_t) 0)
64 #define CATCH_TEMPORARY ((void *) (uintptr_t) 1)
66 /* Prototypes for local functions. */
68 static void enable_delete_command (char *, int);
70 static void enable_delete_breakpoint (struct breakpoint
*);
72 static void enable_once_command (char *, int);
74 static void enable_once_breakpoint (struct breakpoint
*);
76 static void disable_command (char *, int);
78 static void enable_command (char *, int);
80 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
82 static void ignore_command (char *, int);
84 static int breakpoint_re_set_one (void *);
86 static void clear_command (char *, int);
88 static void catch_command (char *, int);
90 static void watch_command (char *, int);
92 static int can_use_hardware_watchpoint (struct value
*);
94 static void break_command_1 (char *, int, int);
96 static void mention (struct breakpoint
*);
98 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
100 static void check_duplicates (struct breakpoint
*);
102 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
104 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
107 static void describe_other_breakpoints (CORE_ADDR
, asection
*, int);
109 static void breakpoints_info (char *, int);
111 static void breakpoint_1 (int, int);
113 static bpstat
bpstat_alloc (const struct bp_location
*, bpstat
);
115 static int breakpoint_cond_eval (void *);
117 static void cleanup_executing_breakpoints (void *);
119 static void commands_command (char *, int);
121 static void condition_command (char *, int);
123 static int get_number_trailer (char **, int);
125 void set_breakpoint_count (int);
134 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
136 static enum print_stop_action
print_it_typical (bpstat
);
138 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
140 static int watchpoint_check (void *);
142 static void maintenance_info_breakpoints (char *, int);
144 static void create_overlay_event_breakpoint (char *);
146 static int hw_breakpoint_used_count (void);
148 static int hw_watchpoint_used_count (enum bptype
, int *);
150 static void hbreak_command (char *, int);
152 static void thbreak_command (char *, int);
154 static void watch_command_1 (char *, int, int);
156 static void rwatch_command (char *, int);
158 static void awatch_command (char *, int);
160 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
162 static void create_fork_vfork_event_catchpoint (int tempflag
,
164 enum bptype bp_kind
);
166 static void stop_command (char *arg
, int from_tty
);
168 static void stopin_command (char *arg
, int from_tty
);
170 static void stopat_command (char *arg
, int from_tty
);
172 static char *ep_parse_optional_if_clause (char **arg
);
174 static char *ep_parse_optional_filename (char **arg
);
176 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
177 char *arg
, int tempflag
, int from_tty
);
179 static void tcatch_command (char *arg
, int from_tty
);
181 static void ep_skip_leading_whitespace (char **s
);
183 static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc
);
185 static void free_bp_location (struct bp_location
*loc
);
187 static struct bp_location
*
188 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
);
190 static void update_global_location_list (int);
192 static void update_global_location_list_nothrow (int);
194 static int is_hardware_watchpoint (struct breakpoint
*bpt
);
196 static void insert_breakpoint_locations (void);
199 bpdisp_text (enum bpdisp disp
)
201 /* NOTE: the following values are a part of MI protocol and represent
202 values of 'disp' field returned when inferior stops at a breakpoint. */
203 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
204 return bpdisps
[(int) disp
];
207 /* Prototypes for exported functions. */
208 /* If FALSE, gdb will not use hardware support for watchpoints, even
209 if such is available. */
210 static int can_use_hw_watchpoints
;
213 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
214 struct cmd_list_element
*c
,
217 fprintf_filtered (file
, _("\
218 Debugger's willingness to use watchpoint hardware is %s.\n"),
222 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
223 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
224 for unrecognized breakpoint locations.
225 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
226 static enum auto_boolean pending_break_support
;
228 show_pending_break_support (struct ui_file
*file
, int from_tty
,
229 struct cmd_list_element
*c
,
232 fprintf_filtered (file
, _("\
233 Debugger's behavior regarding pending breakpoints is %s.\n"),
237 /* If 1, gdb will automatically use hardware breakpoints for breakpoints
238 set with "break" but falling in read-only memory.
239 If 0, gdb will warn about such breakpoints, but won't automatically
240 use hardware breakpoints. */
241 static int automatic_hardware_breakpoints
;
243 show_automatic_hardware_breakpoints (struct ui_file
*file
, int from_tty
,
244 struct cmd_list_element
*c
,
247 fprintf_filtered (file
, _("\
248 Automatic usage of hardware breakpoints is %s.\n"),
252 /* If on, gdb will keep breakpoints inserted even as inferior is
253 stopped, and immediately insert any new breakpoints. If off, gdb
254 will insert breakpoints into inferior only when resuming it, and
255 will remove breakpoints upon stop. If auto, GDB will behave as ON
256 if in non-stop mode, and as OFF if all-stop mode.*/
258 static const char always_inserted_auto
[] = "auto";
259 static const char always_inserted_on
[] = "on";
260 static const char always_inserted_off
[] = "off";
261 static const char *always_inserted_enums
[] = {
262 always_inserted_auto
,
267 static const char *always_inserted_mode
= always_inserted_auto
;
269 show_always_inserted_mode (struct ui_file
*file
, int from_tty
,
270 struct cmd_list_element
*c
, const char *value
)
272 if (always_inserted_mode
== always_inserted_auto
)
273 fprintf_filtered (file
, _("\
274 Always inserted breakpoint mode is %s (currently %s).\n"),
276 breakpoints_always_inserted_mode () ? "on" : "off");
278 fprintf_filtered (file
, _("Always inserted breakpoint mode is %s.\n"), value
);
282 breakpoints_always_inserted_mode (void)
284 return (always_inserted_mode
== always_inserted_on
285 || (always_inserted_mode
== always_inserted_auto
&& non_stop
));
288 void _initialize_breakpoint (void);
290 extern int addressprint
; /* Print machine addresses? */
292 /* Are we executing breakpoint commands? */
293 static int executing_breakpoint_commands
;
295 /* Are overlay event breakpoints enabled? */
296 static int overlay_events_enabled
;
298 /* Walk the following statement or block through all breakpoints.
299 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
302 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
304 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
305 for (B = breakpoint_chain; \
306 B ? (TMP=B->next, 1): 0; \
309 /* Similar iterators for the low-level breakpoints. */
311 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next)
313 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
314 for (B = bp_location_chain; \
315 B ? (TMP=B->global_next, 1): 0; \
318 /* True if breakpoint hit counts should be displayed in breakpoint info. */
320 int show_breakpoint_hit_counts
= 1;
322 /* Chains of all breakpoints defined. */
324 struct breakpoint
*breakpoint_chain
;
326 struct bp_location
*bp_location_chain
;
328 /* The locations that no longer correspond to any breakpoint,
329 unlinked from bp_location_chain, but for which a hit
330 may still be reported by a target. */
331 VEC(bp_location_p
) *moribund_locations
= NULL
;
333 /* Number of last breakpoint made. */
335 int breakpoint_count
;
337 /* This function returns a pointer to the string representation of the
338 pathname of the dynamically-linked library that has just been
341 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
342 or undefined results are guaranteed.
344 This string's contents are only valid immediately after the
345 inferior has stopped in the dynamic linker hook, and becomes
346 invalid as soon as the inferior is continued. Clients should make
347 a copy of this string if they wish to continue the inferior and
348 then access the string. */
350 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
351 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
354 /* This function returns a pointer to the string representation of the
355 pathname of the dynamically-linked library that has just been
358 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
359 TRUE, or undefined results are guaranteed.
361 This string's contents are only valid immediately after the
362 inferior has stopped in the dynamic linker hook, and becomes
363 invalid as soon as the inferior is continued. Clients should make
364 a copy of this string if they wish to continue the inferior and
365 then access the string. */
367 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
368 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
371 /* This function is called by the "catch load" command. It allows the
372 debugger to be notified by the dynamic linker when a specified
373 library file (or any library file, if filename is NULL) is loaded. */
375 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
376 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
377 error (_("catch of library loads not yet implemented on this platform"))
380 /* This function is called by the "catch unload" command. It allows
381 the debugger to be notified by the dynamic linker when a specified
382 library file (or any library file, if filename is NULL) is
385 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
386 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
387 error (_("catch of library unloads not yet implemented on this platform"))
390 /* Return whether a breakpoint is an active enabled breakpoint. */
392 breakpoint_enabled (struct breakpoint
*b
)
394 return (b
->enable_state
== bp_enabled
);
397 /* Set breakpoint count to NUM. */
400 set_breakpoint_count (int num
)
402 breakpoint_count
= num
;
403 set_internalvar (lookup_internalvar ("bpnum"),
404 value_from_longest (builtin_type_int
, (LONGEST
) num
));
407 /* Used in run_command to zero the hit count when a new run starts. */
410 clear_breakpoint_hit_counts (void)
412 struct breakpoint
*b
;
418 /* Default address, symtab and line to put a breakpoint at
419 for "break" command with no arg.
420 if default_breakpoint_valid is zero, the other three are
421 not valid, and "break" with no arg is an error.
423 This set by print_stack_frame, which calls set_default_breakpoint. */
425 int default_breakpoint_valid
;
426 CORE_ADDR default_breakpoint_address
;
427 struct symtab
*default_breakpoint_symtab
;
428 int default_breakpoint_line
;
430 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
431 Advance *PP after the string and any trailing whitespace.
433 Currently the string can either be a number or "$" followed by the name
434 of a convenience variable. Making it an expression wouldn't work well
435 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
437 If the string is a NULL pointer, that denotes the last breakpoint.
439 TRAILER is a character which can be found after the number; most
440 commonly this is `-'. If you don't want a trailer, use \0. */
442 get_number_trailer (char **pp
, int trailer
)
444 int retval
= 0; /* default */
448 /* Empty line means refer to the last breakpoint. */
449 return breakpoint_count
;
452 /* Make a copy of the name, so we can null-terminate it
453 to pass to lookup_internalvar(). */
458 while (isalnum (*p
) || *p
== '_')
460 varname
= (char *) alloca (p
- start
+ 1);
461 strncpy (varname
, start
, p
- start
);
462 varname
[p
- start
] = '\0';
463 val
= value_of_internalvar (lookup_internalvar (varname
));
464 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
465 retval
= (int) value_as_long (val
);
468 printf_filtered (_("Convenience variable must have integer value.\n"));
476 while (*p
>= '0' && *p
<= '9')
479 /* There is no number here. (e.g. "cond a == b"). */
481 /* Skip non-numeric token */
482 while (*p
&& !isspace((int) *p
))
484 /* Return zero, which caller must interpret as error. */
490 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
492 /* Trailing junk: return 0 and let caller print error msg. */
493 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
504 /* Like get_number_trailer, but don't allow a trailer. */
506 get_number (char **pp
)
508 return get_number_trailer (pp
, '\0');
511 /* Parse a number or a range.
512 * A number will be of the form handled by get_number.
513 * A range will be of the form <number1> - <number2>, and
514 * will represent all the integers between number1 and number2,
517 * While processing a range, this fuction is called iteratively;
518 * At each call it will return the next value in the range.
520 * At the beginning of parsing a range, the char pointer PP will
521 * be advanced past <number1> and left pointing at the '-' token.
522 * Subsequent calls will not advance the pointer until the range
523 * is completed. The call that completes the range will advance
524 * pointer PP past <number2>.
528 get_number_or_range (char **pp
)
530 static int last_retval
, end_value
;
531 static char *end_ptr
;
532 static int in_range
= 0;
536 /* Default case: pp is pointing either to a solo number,
537 or to the first number of a range. */
538 last_retval
= get_number_trailer (pp
, '-');
543 /* This is the start of a range (<number1> - <number2>).
544 Skip the '-', parse and remember the second number,
545 and also remember the end of the final token. */
549 while (isspace ((int) *end_ptr
))
550 end_ptr
++; /* skip white space */
551 end_value
= get_number (temp
);
552 if (end_value
< last_retval
)
554 error (_("inverted range"));
556 else if (end_value
== last_retval
)
558 /* degenerate range (number1 == number2). Advance the
559 token pointer so that the range will be treated as a
568 error (_("negative value"));
571 /* pp points to the '-' that betokens a range. All
572 number-parsing has already been done. Return the next
573 integer value (one greater than the saved previous value).
574 Do not advance the token pointer 'pp' until the end of range
577 if (++last_retval
== end_value
)
579 /* End of range reached; advance token pointer. */
589 /* condition N EXP -- set break condition of breakpoint N to EXP. */
592 condition_command (char *arg
, int from_tty
)
594 struct breakpoint
*b
;
599 error_no_arg (_("breakpoint number"));
602 bnum
= get_number (&p
);
604 error (_("Bad breakpoint argument: '%s'"), arg
);
607 if (b
->number
== bnum
)
609 struct bp_location
*loc
= b
->loc
;
610 for (; loc
; loc
= loc
->next
)
618 if (b
->cond_string
!= NULL
)
619 xfree (b
->cond_string
);
623 b
->cond_string
= NULL
;
625 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
630 /* I don't know if it matters whether this is the string the user
631 typed in or the decompiled expression. */
632 b
->cond_string
= savestring (arg
, strlen (arg
));
633 b
->condition_not_parsed
= 0;
634 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
638 parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
640 error (_("Junk at end of expression"));
643 breakpoints_changed ();
644 observer_notify_breakpoint_modified (b
->number
);
648 error (_("No breakpoint number %d."), bnum
);
652 commands_command (char *arg
, int from_tty
)
654 struct breakpoint
*b
;
657 struct command_line
*l
;
659 /* If we allowed this, we would have problems with when to
660 free the storage, if we change the commands currently
663 if (executing_breakpoint_commands
)
664 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
667 bnum
= get_number (&p
);
670 error (_("Unexpected extra arguments following breakpoint number."));
673 if (b
->number
== bnum
)
675 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
677 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
678 l
= read_command_lines (tmpbuf
, from_tty
, 1);
679 do_cleanups (cleanups
);
680 free_command_lines (&b
->commands
);
682 breakpoints_changed ();
683 observer_notify_breakpoint_modified (b
->number
);
686 error (_("No breakpoint number %d."), bnum
);
689 /* Like commands_command, but instead of reading the commands from
690 input stream, takes them from an already parsed command structure.
692 This is used by cli-script.c to DTRT with breakpoint commands
693 that are part of if and while bodies. */
694 enum command_control_type
695 commands_from_control_command (char *arg
, struct command_line
*cmd
)
697 struct breakpoint
*b
;
701 /* If we allowed this, we would have problems with when to
702 free the storage, if we change the commands currently
705 if (executing_breakpoint_commands
)
706 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
708 /* An empty string for the breakpoint number means the last
709 breakpoint, but get_number expects a NULL pointer. */
714 bnum
= get_number (&p
);
717 error (_("Unexpected extra arguments following breakpoint number."));
720 if (b
->number
== bnum
)
722 free_command_lines (&b
->commands
);
723 if (cmd
->body_count
!= 1)
724 error (_("Invalid \"commands\" block structure."));
725 /* We need to copy the commands because if/while will free the
726 list after it finishes execution. */
727 b
->commands
= copy_command_lines (cmd
->body_list
[0]);
728 breakpoints_changed ();
729 observer_notify_breakpoint_modified (b
->number
);
730 return simple_control
;
732 error (_("No breakpoint number %d."), bnum
);
735 /* Update BUF, which is LEN bytes read from the target address MEMADDR,
736 by replacing any memory breakpoints with their shadowed contents. */
739 breakpoint_restore_shadows (gdb_byte
*buf
, ULONGEST memaddr
, LONGEST len
)
741 struct bp_location
*b
;
742 CORE_ADDR bp_addr
= 0;
748 if (b
->owner
->type
== bp_none
)
749 warning (_("reading through apparently deleted breakpoint #%d?"),
752 if (b
->loc_type
!= bp_loc_software_breakpoint
)
756 /* Addresses and length of the part of the breakpoint that
758 bp_addr
= b
->target_info
.placed_address
;
759 bp_size
= b
->target_info
.shadow_len
;
761 /* bp isn't valid, or doesn't shadow memory. */
764 if (bp_addr
+ bp_size
<= memaddr
)
765 /* The breakpoint is entirely before the chunk of memory we
769 if (bp_addr
>= memaddr
+ len
)
770 /* The breakpoint is entirely after the chunk of memory we are
774 /* Offset within shadow_contents. */
775 if (bp_addr
< memaddr
)
777 /* Only copy the second part of the breakpoint. */
778 bp_size
-= memaddr
- bp_addr
;
779 bptoffset
= memaddr
- bp_addr
;
783 if (bp_addr
+ bp_size
> memaddr
+ len
)
785 /* Only copy the first part of the breakpoint. */
786 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
789 memcpy (buf
+ bp_addr
- memaddr
,
790 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
795 /* A wrapper function for inserting catchpoints. */
797 insert_catchpoint (struct ui_out
*uo
, void *args
)
799 struct breakpoint
*b
= (struct breakpoint
*) args
;
805 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
808 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
811 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
814 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
820 is_hardware_watchpoint (struct breakpoint
*bpt
)
822 return (bpt
->type
== bp_hardware_watchpoint
823 || bpt
->type
== bp_read_watchpoint
824 || bpt
->type
== bp_access_watchpoint
);
827 /* Find the current value of a watchpoint on EXP. Return the value in
828 *VALP and *RESULTP and the chain of intermediate and final values
829 in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
832 If an error occurs while evaluating the expression, *RESULTP will
833 be set to NULL. *RESULTP may be a lazy value, if the result could
834 not be read from memory. It is used to determine whether a value
835 is user-specified (we should watch the whole value) or intermediate
836 (we should watch only the bit used to locate the final value).
838 If the final value, or any intermediate value, could not be read
839 from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
840 set to any referenced values. *VALP will never be a lazy value.
841 This is the value which we store in struct breakpoint.
843 If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
844 value chain. The caller must free the values individually. If
845 VAL_CHAIN is NULL, all generated values will be left on the value
849 fetch_watchpoint_value (struct expression
*exp
, struct value
**valp
,
850 struct value
**resultp
, struct value
**val_chain
)
852 struct value
*mark
, *new_mark
, *result
;
860 /* Evaluate the expression. */
861 mark
= value_mark ();
863 gdb_evaluate_expression (exp
, &result
);
864 new_mark
= value_mark ();
865 if (mark
== new_mark
)
870 /* Make sure it's not lazy, so that after the target stops again we
871 have a non-lazy previous value to compare with. */
873 && (!value_lazy (result
) || gdb_value_fetch_lazy (result
)))
878 /* Return the chain of intermediate values. We use this to
879 decide which addresses to watch. */
880 *val_chain
= new_mark
;
881 value_release_to_mark (mark
);
885 /* Assuming that B is a hardware watchpoint:
886 - Reparse watchpoint expression, is REPARSE is non-zero
887 - Evaluate expression and store the result in B->val
888 - Update the list of values that must be watched in B->loc.
890 If the watchpoint is disabled, do nothing. If this is
891 local watchpoint that is out of scope, delete it. */
893 update_watchpoint (struct breakpoint
*b
, int reparse
)
895 int within_current_scope
;
896 struct frame_id saved_frame_id
;
897 struct bp_location
*loc
;
900 /* We don't free locations. They are stored in
901 bp_location_chain and update_global_locations will
902 eventually delete them and remove breakpoints if
906 if (b
->disposition
== disp_del_at_next_stop
)
909 /* Save the current frame's ID so we can restore it after
910 evaluating the watchpoint expression on its own frame. */
911 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
912 took a frame parameter, so that we didn't have to change the
914 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
916 /* Determine if the watchpoint is within scope. */
917 if (b
->exp_valid_block
== NULL
)
918 within_current_scope
= 1;
921 struct frame_info
*fi
;
922 fi
= frame_find_by_id (b
->watchpoint_frame
);
923 within_current_scope
= (fi
!= NULL
);
924 if (within_current_scope
)
928 if (within_current_scope
&& reparse
)
937 b
->exp
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
938 /* If the meaning of expression itself changed, the old value is
939 no longer relevant. We don't want to report a watchpoint hit
940 to the user when the old value and the new value may actually
941 be completely different objects. */
947 /* If we failed to parse the expression, for example because
948 it refers to a global variable in a not-yet-loaded shared library,
949 don't try to insert watchpoint. We don't automatically delete
950 such watchpoint, though, since failure to parse expression
951 is different from out-of-scope watchpoint. */
952 if (within_current_scope
&& b
->exp
)
954 struct value
*val_chain
, *v
, *result
, *next
;
956 fetch_watchpoint_value (b
->exp
, &v
, &result
, &val_chain
);
958 /* Avoid setting b->val if it's already set. The meaning of
959 b->val is 'the last value' user saw, and we should update
960 it only if we reported that last value to user. As it
961 happens, the code that reports it updates b->val directly. */
968 /* Look at each value on the value chain. */
969 for (v
= val_chain
; v
; v
= next
)
971 /* If it's a memory location, and GDB actually needed
972 its contents to evaluate the expression, then we
973 must watch it. If the first value returned is
974 still lazy, that means an error occurred reading it;
975 watch it anyway in case it becomes readable. */
976 if (VALUE_LVAL (v
) == lval_memory
977 && (v
== val_chain
|| ! value_lazy (v
)))
979 struct type
*vtype
= check_typedef (value_type (v
));
981 /* We only watch structs and arrays if user asked
982 for it explicitly, never if they just happen to
983 appear in the middle of some value chain. */
985 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
986 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
990 struct bp_location
*loc
, **tmp
;
992 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
993 len
= TYPE_LENGTH (value_type (v
));
995 if (b
->type
== bp_read_watchpoint
)
997 else if (b
->type
== bp_access_watchpoint
)
1000 loc
= allocate_bp_location (b
, bp_hardware_watchpoint
);
1001 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
1004 loc
->address
= addr
;
1006 loc
->watchpoint_type
= type
;
1010 next
= value_next (v
);
1015 /* We just regenerated the list of breakpoint locations.
1016 The new location does not have its condition field set to anything
1017 and therefore, we must always reparse the cond_string, independently
1018 of the value of the reparse flag. */
1019 if (b
->cond_string
!= NULL
)
1021 char *s
= b
->cond_string
;
1022 b
->loc
->cond
= parse_exp_1 (&s
, b
->exp_valid_block
, 0);
1025 else if (!within_current_scope
)
1027 printf_filtered (_("\
1028 Hardware watchpoint %d deleted because the program has left the block \n\
1029 in which its expression is valid.\n"),
1031 if (b
->related_breakpoint
)
1032 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1033 b
->disposition
= disp_del_at_next_stop
;
1036 /* Restore the selected frame. */
1037 select_frame (frame_find_by_id (saved_frame_id
));
1041 /* Returns 1 iff breakpoint location should be
1042 inserted in the inferior. */
1044 should_be_inserted (struct bp_location
*bpt
)
1046 if (!breakpoint_enabled (bpt
->owner
))
1049 if (bpt
->owner
->disposition
== disp_del_at_next_stop
)
1052 if (!bpt
->enabled
|| bpt
->shlib_disabled
|| bpt
->duplicate
)
1058 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
1059 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
1060 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
1062 NOTE drow/2003-09-09: This routine could be broken down to an object-style
1063 method for each breakpoint or catchpoint type. */
1065 insert_bp_location (struct bp_location
*bpt
,
1066 struct ui_file
*tmp_error_stream
,
1067 int *disabled_breaks
, int *process_warning
,
1068 int *hw_breakpoint_error
)
1072 if (!should_be_inserted (bpt
) || bpt
->inserted
)
1075 /* Initialize the target-specific information. */
1076 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
1077 bpt
->target_info
.placed_address
= bpt
->address
;
1079 if (bpt
->loc_type
== bp_loc_software_breakpoint
1080 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1082 if (bpt
->owner
->type
!= bp_hardware_breakpoint
)
1084 /* If the explicitly specified breakpoint type
1085 is not hardware breakpoint, check the memory map to see
1086 if the breakpoint address is in read only memory or not.
1087 Two important cases are:
1088 - location type is not hardware breakpoint, memory
1089 is readonly. We change the type of the location to
1090 hardware breakpoint.
1091 - location type is hardware breakpoint, memory is read-write.
1092 This means we've previously made the location hardware one, but
1093 then the memory map changed, so we undo.
1095 When breakpoints are removed, remove_breakpoints will
1096 use location types we've just set here, the only possible
1097 problem is that memory map has changed during running program,
1098 but it's not going to work anyway with current gdb. */
1099 struct mem_region
*mr
1100 = lookup_mem_region (bpt
->target_info
.placed_address
);
1104 if (automatic_hardware_breakpoints
)
1107 enum bp_loc_type new_type
;
1109 if (mr
->attrib
.mode
!= MEM_RW
)
1110 new_type
= bp_loc_hardware_breakpoint
;
1112 new_type
= bp_loc_software_breakpoint
;
1114 if (new_type
!= bpt
->loc_type
)
1116 static int said
= 0;
1117 bpt
->loc_type
= new_type
;
1120 fprintf_filtered (gdb_stdout
, _("\
1121 Note: automatically using hardware breakpoints for read-only addresses.\n"));
1126 else if (bpt
->loc_type
== bp_loc_software_breakpoint
1127 && mr
->attrib
.mode
!= MEM_RW
)
1128 warning (_("cannot set software breakpoint at readonly address %s"),
1129 paddr (bpt
->address
));
1133 /* First check to see if we have to handle an overlay. */
1134 if (overlay_debugging
== ovly_off
1135 || bpt
->section
== NULL
1136 || !(section_is_overlay (bpt
->section
)))
1138 /* No overlay handling: just set the breakpoint. */
1140 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1141 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1143 val
= target_insert_breakpoint (&bpt
->target_info
);
1147 /* This breakpoint is in an overlay section.
1148 Shall we set a breakpoint at the LMA? */
1149 if (!overlay_events_enabled
)
1151 /* Yes -- overlay event support is not active,
1152 so we must try to set a breakpoint at the LMA.
1153 This will not work for a hardware breakpoint. */
1154 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1155 warning (_("hardware breakpoint %d not supported in overlay!"),
1156 bpt
->owner
->number
);
1159 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
1161 /* Set a software (trap) breakpoint at the LMA. */
1162 bpt
->overlay_target_info
= bpt
->target_info
;
1163 bpt
->overlay_target_info
.placed_address
= addr
;
1164 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
1166 fprintf_unfiltered (tmp_error_stream
,
1167 "Overlay breakpoint %d failed: in ROM?",
1168 bpt
->owner
->number
);
1171 /* Shall we set a breakpoint at the VMA? */
1172 if (section_is_mapped (bpt
->section
))
1174 /* Yes. This overlay section is mapped into memory. */
1175 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1176 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
1178 val
= target_insert_breakpoint (&bpt
->target_info
);
1182 /* No. This breakpoint will not be inserted.
1183 No error, but do not mark the bp as 'inserted'. */
1190 /* Can't set the breakpoint. */
1191 if (solib_address (bpt
->address
))
1193 /* See also: disable_breakpoints_in_shlibs. */
1195 bpt
->shlib_disabled
= 1;
1196 if (!*disabled_breaks
)
1198 fprintf_unfiltered (tmp_error_stream
,
1199 "Cannot insert breakpoint %d.\n",
1200 bpt
->owner
->number
);
1201 fprintf_unfiltered (tmp_error_stream
,
1202 "Temporarily disabling shared library breakpoints:\n");
1204 *disabled_breaks
= 1;
1205 fprintf_unfiltered (tmp_error_stream
,
1206 "breakpoint #%d\n", bpt
->owner
->number
);
1210 #ifdef ONE_PROCESS_WRITETEXT
1211 *process_warning
= 1;
1213 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
1215 *hw_breakpoint_error
= 1;
1216 fprintf_unfiltered (tmp_error_stream
,
1217 "Cannot insert hardware breakpoint %d.\n",
1218 bpt
->owner
->number
);
1222 fprintf_unfiltered (tmp_error_stream
,
1223 "Cannot insert breakpoint %d.\n",
1224 bpt
->owner
->number
);
1225 fprintf_filtered (tmp_error_stream
,
1226 "Error accessing memory address ");
1227 fputs_filtered (paddress (bpt
->address
), tmp_error_stream
);
1228 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1229 safe_strerror (val
));
1240 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
1241 /* NOTE drow/2003-09-08: This state only exists for removing
1242 watchpoints. It's not clear that it's necessary... */
1243 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
1245 val
= target_insert_watchpoint (bpt
->address
,
1247 bpt
->watchpoint_type
);
1248 bpt
->inserted
= (val
!= -1);
1251 else if (bpt
->owner
->type
== bp_catch_fork
1252 || bpt
->owner
->type
== bp_catch_vfork
1253 || bpt
->owner
->type
== bp_catch_exec
)
1255 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1256 bpt
->owner
, RETURN_MASK_ERROR
);
1257 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1258 bpt
->owner
->number
);
1260 bpt
->owner
->enable_state
= bp_disabled
;
1264 /* We've already printed an error message if there was a problem
1265 inserting this catchpoint, and we've disabled the catchpoint,
1266 so just return success. */
1273 /* Make sure all breakpoints are inserted in inferior.
1274 Throws exception on any error.
1275 A breakpoint that is already inserted won't be inserted
1276 again, so calling this function twice is safe. */
1278 insert_breakpoints (void)
1280 struct breakpoint
*bpt
;
1282 ALL_BREAKPOINTS (bpt
)
1283 if (is_hardware_watchpoint (bpt
))
1284 update_watchpoint (bpt
, 0 /* don't reparse. */);
1286 update_global_location_list (1);
1288 if (!always_inserted_mode
&& target_has_execution
)
1289 /* update_global_location_list does not insert breakpoints
1290 when always_inserted_mode is not enabled. Explicitly
1292 insert_breakpoint_locations ();
1295 /* insert_breakpoints is used when starting or continuing the program.
1296 remove_breakpoints is used when the program stops.
1297 Both return zero if successful,
1298 or an `errno' value if could not write the inferior. */
1301 insert_breakpoint_locations (void)
1303 struct breakpoint
*bpt
;
1304 struct bp_location
*b
, *temp
;
1307 int disabled_breaks
= 0;
1308 int hw_breakpoint_error
= 0;
1309 int process_warning
= 0;
1311 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1312 make_cleanup_ui_file_delete (tmp_error_stream
);
1314 /* Explicitly mark the warning -- this will only be printed if
1315 there was an error. */
1316 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1318 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1320 if (!should_be_inserted (b
) || b
->inserted
)
1323 /* There is no point inserting thread-specific breakpoints if the
1324 thread no longer exists. */
1325 if (b
->owner
->thread
!= -1
1326 && !valid_thread_id (b
->owner
->thread
))
1329 val
= insert_bp_location (b
, tmp_error_stream
,
1330 &disabled_breaks
, &process_warning
,
1331 &hw_breakpoint_error
);
1336 /* If we failed to insert all locations of a watchpoint,
1337 remove them, as half-inserted watchpoint is of limited use. */
1338 ALL_BREAKPOINTS (bpt
)
1340 int some_failed
= 0;
1341 struct bp_location
*loc
;
1343 if (!is_hardware_watchpoint (bpt
))
1346 if (!breakpoint_enabled (bpt
))
1349 if (bpt
->disposition
== disp_del_at_next_stop
)
1352 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1360 for (loc
= bpt
->loc
; loc
; loc
= loc
->next
)
1362 remove_breakpoint (loc
, mark_uninserted
);
1364 hw_breakpoint_error
= 1;
1365 fprintf_unfiltered (tmp_error_stream
,
1366 "Could not insert hardware watchpoint %d.\n",
1374 /* If a hardware breakpoint or watchpoint was inserted, add a
1375 message about possibly exhausted resources. */
1376 if (hw_breakpoint_error
)
1378 fprintf_unfiltered (tmp_error_stream
,
1379 "Could not insert hardware breakpoints:\n\
1380 You may have requested too many hardware breakpoints/watchpoints.\n");
1382 #ifdef ONE_PROCESS_WRITETEXT
1383 if (process_warning
)
1384 fprintf_unfiltered (tmp_error_stream
,
1385 "The same program may be running in another process.");
1387 target_terminal_ours_for_output ();
1388 error_stream (tmp_error_stream
);
1393 remove_breakpoints (void)
1395 struct bp_location
*b
;
1398 ALL_BP_LOCATIONS (b
)
1402 val
= remove_breakpoint (b
, mark_uninserted
);
1411 remove_hw_watchpoints (void)
1413 struct bp_location
*b
;
1416 ALL_BP_LOCATIONS (b
)
1418 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1420 val
= remove_breakpoint (b
, mark_uninserted
);
1429 reattach_breakpoints (int pid
)
1431 struct bp_location
*b
;
1433 struct cleanup
*old_chain
= save_inferior_ptid ();
1434 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1435 int dummy1
= 0, dummy2
= 0, dummy3
= 0;
1437 make_cleanup_ui_file_delete (tmp_error_stream
);
1439 inferior_ptid
= pid_to_ptid (pid
);
1440 ALL_BP_LOCATIONS (b
)
1445 val
= insert_bp_location (b
, tmp_error_stream
,
1446 &dummy1
, &dummy2
, &dummy3
);
1449 do_cleanups (old_chain
);
1454 do_cleanups (old_chain
);
1459 update_breakpoints_after_exec (void)
1461 struct breakpoint
*b
;
1462 struct breakpoint
*temp
;
1463 struct bp_location
*bploc
;
1465 /* We're about to delete breakpoints from GDB's lists. If the
1466 INSERTED flag is true, GDB will try to lift the breakpoints by
1467 writing the breakpoints' "shadow contents" back into memory. The
1468 "shadow contents" are NOT valid after an exec, so GDB should not
1469 do that. Instead, the target is responsible from marking
1470 breakpoints out as soon as it detects an exec. We don't do that
1471 here instead, because there may be other attempts to delete
1472 breakpoints after detecting an exec and before reaching here. */
1473 ALL_BP_LOCATIONS (bploc
)
1474 gdb_assert (!bploc
->inserted
);
1476 ALL_BREAKPOINTS_SAFE (b
, temp
)
1478 /* Solib breakpoints must be explicitly reset after an exec(). */
1479 if (b
->type
== bp_shlib_event
)
1481 delete_breakpoint (b
);
1485 /* Thread event breakpoints must be set anew after an exec(),
1486 as must overlay event breakpoints. */
1487 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1489 delete_breakpoint (b
);
1493 /* Step-resume breakpoints are meaningless after an exec(). */
1494 if (b
->type
== bp_step_resume
)
1496 delete_breakpoint (b
);
1500 /* Longjmp and longjmp-resume breakpoints are also meaningless
1502 if (b
->type
== bp_longjmp
|| b
->type
== bp_longjmp_resume
)
1504 delete_breakpoint (b
);
1508 /* Don't delete an exec catchpoint, because else the inferior
1509 won't stop when it ought!
1511 Similarly, we probably ought to keep vfork catchpoints, 'cause
1512 on this target, we may not be able to stop when the vfork is
1513 seen, but only when the subsequent exec is seen. (And because
1514 deleting fork catchpoints here but not vfork catchpoints will
1515 seem mysterious to users, keep those too.) */
1516 if ((b
->type
== bp_catch_exec
) ||
1517 (b
->type
== bp_catch_vfork
) ||
1518 (b
->type
== bp_catch_fork
))
1523 /* bp_finish is a special case. The only way we ought to be able
1524 to see one of these when an exec() has happened, is if the user
1525 caught a vfork, and then said "finish". Ordinarily a finish just
1526 carries them to the call-site of the current callee, by setting
1527 a temporary bp there and resuming. But in this case, the finish
1528 will carry them entirely through the vfork & exec.
1530 We don't want to allow a bp_finish to remain inserted now. But
1531 we can't safely delete it, 'cause finish_command has a handle to
1532 the bp on a bpstat, and will later want to delete it. There's a
1533 chance (and I've seen it happen) that if we delete the bp_finish
1534 here, that its storage will get reused by the time finish_command
1535 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1536 We really must allow finish_command to delete a bp_finish.
1538 In the absense of a general solution for the "how do we know
1539 it's safe to delete something others may have handles to?"
1540 problem, what we'll do here is just uninsert the bp_finish, and
1541 let finish_command delete it.
1543 (We know the bp_finish is "doomed" in the sense that it's
1544 momentary, and will be deleted as soon as finish_command sees
1545 the inferior stopped. So it doesn't matter that the bp's
1546 address is probably bogus in the new a.out, unlike e.g., the
1547 solib breakpoints.) */
1549 if (b
->type
== bp_finish
)
1554 /* Without a symbolic address, we have little hope of the
1555 pre-exec() address meaning the same thing in the post-exec()
1557 if (b
->addr_string
== NULL
)
1559 delete_breakpoint (b
);
1563 /* FIXME what about longjmp breakpoints? Re-create them here? */
1564 create_overlay_event_breakpoint ("_ovly_debug_event");
1568 detach_breakpoints (int pid
)
1570 struct bp_location
*b
;
1572 struct cleanup
*old_chain
= save_inferior_ptid ();
1574 if (pid
== PIDGET (inferior_ptid
))
1575 error (_("Cannot detach breakpoints of inferior_ptid"));
1577 /* Set inferior_ptid; remove_breakpoint uses this global. */
1578 inferior_ptid
= pid_to_ptid (pid
);
1579 ALL_BP_LOCATIONS (b
)
1583 val
= remove_breakpoint (b
, mark_inserted
);
1586 do_cleanups (old_chain
);
1591 do_cleanups (old_chain
);
1596 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1600 if (b
->owner
->enable_state
== bp_permanent
)
1601 /* Permanent breakpoints cannot be inserted or removed. */
1604 /* The type of none suggests that owner is actually deleted.
1605 This should not ever happen. */
1606 gdb_assert (b
->owner
->type
!= bp_none
);
1608 if (b
->loc_type
== bp_loc_software_breakpoint
1609 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1611 /* "Normal" instruction breakpoint: either the standard
1612 trap-instruction bp (bp_breakpoint), or a
1613 bp_hardware_breakpoint. */
1615 /* First check to see if we have to handle an overlay. */
1616 if (overlay_debugging
== ovly_off
1617 || b
->section
== NULL
1618 || !(section_is_overlay (b
->section
)))
1620 /* No overlay handling: just remove the breakpoint. */
1622 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1623 val
= target_remove_hw_breakpoint (&b
->target_info
);
1625 val
= target_remove_breakpoint (&b
->target_info
);
1629 /* This breakpoint is in an overlay section.
1630 Did we set a breakpoint at the LMA? */
1631 if (!overlay_events_enabled
)
1633 /* Yes -- overlay event support is not active, so we
1634 should have set a breakpoint at the LMA. Remove it.
1636 /* Ignore any failures: if the LMA is in ROM, we will
1637 have already warned when we failed to insert it. */
1638 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1639 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1641 target_remove_breakpoint (&b
->overlay_target_info
);
1643 /* Did we set a breakpoint at the VMA?
1644 If so, we will have marked the breakpoint 'inserted'. */
1647 /* Yes -- remove it. Previously we did not bother to
1648 remove the breakpoint if the section had been
1649 unmapped, but let's not rely on that being safe. We
1650 don't know what the overlay manager might do. */
1651 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1652 val
= target_remove_hw_breakpoint (&b
->target_info
);
1654 /* However, we should remove *software* breakpoints only
1655 if the section is still mapped, or else we overwrite
1656 wrong code with the saved shadow contents. */
1657 else if (section_is_mapped (b
->section
))
1658 val
= target_remove_breakpoint (&b
->target_info
);
1664 /* No -- not inserted, so no need to remove. No error. */
1670 b
->inserted
= (is
== mark_inserted
);
1672 else if (b
->loc_type
== bp_loc_hardware_watchpoint
)
1677 b
->inserted
= (is
== mark_inserted
);
1678 val
= target_remove_watchpoint (b
->address
, b
->length
,
1679 b
->watchpoint_type
);
1681 /* Failure to remove any of the hardware watchpoints comes here. */
1682 if ((is
== mark_uninserted
) && (b
->inserted
))
1683 warning (_("Could not remove hardware watchpoint %d."),
1686 else if ((b
->owner
->type
== bp_catch_fork
||
1687 b
->owner
->type
== bp_catch_vfork
||
1688 b
->owner
->type
== bp_catch_exec
)
1689 && breakpoint_enabled (b
->owner
)
1693 switch (b
->owner
->type
)
1696 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1698 case bp_catch_vfork
:
1699 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1702 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1705 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1710 b
->inserted
= (is
== mark_inserted
);
1716 /* Clear the "inserted" flag in all breakpoints. */
1719 mark_breakpoints_out (void)
1721 struct bp_location
*bpt
;
1723 ALL_BP_LOCATIONS (bpt
)
1727 /* Clear the "inserted" flag in all breakpoints and delete any
1728 breakpoints which should go away between runs of the program.
1730 Plus other such housekeeping that has to be done for breakpoints
1733 Note: this function gets called at the end of a run (by
1734 generic_mourn_inferior) and when a run begins (by
1735 init_wait_for_inferior). */
1740 breakpoint_init_inferior (enum inf_context context
)
1742 struct breakpoint
*b
, *temp
;
1743 struct bp_location
*bpt
;
1745 ALL_BP_LOCATIONS (bpt
)
1748 ALL_BREAKPOINTS_SAFE (b
, temp
)
1753 case bp_watchpoint_scope
:
1755 /* If the call dummy breakpoint is at the entry point it will
1756 cause problems when the inferior is rerun, so we better
1759 Also get rid of scope breakpoints. */
1760 delete_breakpoint (b
);
1764 case bp_hardware_watchpoint
:
1765 case bp_read_watchpoint
:
1766 case bp_access_watchpoint
:
1768 /* Likewise for watchpoints on local expressions. */
1769 if (b
->exp_valid_block
!= NULL
)
1770 delete_breakpoint (b
);
1771 else if (context
== inf_starting
)
1773 /* Reset val field to force reread of starting value
1774 in insert_breakpoints. */
1776 value_free (b
->val
);
1787 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1788 exists at PC. It returns ordinary_breakpoint_here if it's an
1789 ordinary breakpoint, or permanent_breakpoint_here if it's a
1790 permanent breakpoint.
1791 - When continuing from a location with an ordinary breakpoint, we
1792 actually single step once before calling insert_breakpoints.
1793 - When continuing from a localion with a permanent breakpoint, we
1794 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1795 the target, to advance the PC past the breakpoint. */
1797 enum breakpoint_here
1798 breakpoint_here_p (CORE_ADDR pc
)
1800 const struct bp_location
*bpt
;
1801 int any_breakpoint_here
= 0;
1803 ALL_BP_LOCATIONS (bpt
)
1805 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1806 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1809 if ((breakpoint_enabled (bpt
->owner
)
1810 || bpt
->owner
->enable_state
== bp_permanent
)
1811 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1813 if (overlay_debugging
1814 && section_is_overlay (bpt
->section
)
1815 && !section_is_mapped (bpt
->section
))
1816 continue; /* unmapped overlay -- can't be a match */
1817 else if (bpt
->owner
->enable_state
== bp_permanent
)
1818 return permanent_breakpoint_here
;
1820 any_breakpoint_here
= 1;
1824 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1828 /* Returns non-zero if there's a breakpoint inserted at PC, which is
1829 inserted using regular breakpoint_chain/bp_location_chain mechanism.
1830 This does not check for single-step breakpoints, which are
1831 inserted and removed using direct target manipulation. */
1834 regular_breakpoint_inserted_here_p (CORE_ADDR pc
)
1836 const struct bp_location
*bpt
;
1838 ALL_BP_LOCATIONS (bpt
)
1840 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1841 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1845 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1847 if (overlay_debugging
1848 && section_is_overlay (bpt
->section
)
1849 && !section_is_mapped (bpt
->section
))
1850 continue; /* unmapped overlay -- can't be a match */
1858 /* Returns non-zero iff there's either regular breakpoint
1859 or a single step breakpoint inserted at PC. */
1862 breakpoint_inserted_here_p (CORE_ADDR pc
)
1864 if (regular_breakpoint_inserted_here_p (pc
))
1867 if (single_step_breakpoint_inserted_here_p (pc
))
1873 /* This function returns non-zero iff there is a software breakpoint
1877 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1879 const struct bp_location
*bpt
;
1880 int any_breakpoint_here
= 0;
1882 ALL_BP_LOCATIONS (bpt
)
1884 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1888 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1890 if (overlay_debugging
1891 && section_is_overlay (bpt
->section
)
1892 && !section_is_mapped (bpt
->section
))
1893 continue; /* unmapped overlay -- can't be a match */
1899 /* Also check for software single-step breakpoints. */
1900 if (single_step_breakpoint_inserted_here_p (pc
))
1906 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1907 PC is valid for process/thread PTID. */
1910 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1912 const struct bp_location
*bpt
;
1915 thread
= pid_to_thread_id (ptid
);
1917 ALL_BP_LOCATIONS (bpt
)
1919 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1920 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1923 if ((breakpoint_enabled (bpt
->owner
)
1924 || bpt
->owner
->enable_state
== bp_permanent
)
1925 && bpt
->address
== pc
1926 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1928 if (overlay_debugging
1929 && section_is_overlay (bpt
->section
)
1930 && !section_is_mapped (bpt
->section
))
1931 continue; /* unmapped overlay -- can't be a match */
1941 /* bpstat stuff. External routines' interfaces are documented
1945 ep_is_catchpoint (struct breakpoint
*ep
)
1948 (ep
->type
== bp_catch_load
)
1949 || (ep
->type
== bp_catch_unload
)
1950 || (ep
->type
== bp_catch_fork
)
1951 || (ep
->type
== bp_catch_vfork
)
1952 || (ep
->type
== bp_catch_exec
);
1954 /* ??rehrauer: Add more kinds here, as are implemented... */
1958 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1961 (ep
->type
== bp_catch_load
)
1962 || (ep
->type
== bp_catch_unload
);
1966 bpstat_free (bpstat bs
)
1968 if (bs
->old_val
!= NULL
)
1969 value_free (bs
->old_val
);
1970 free_command_lines (&bs
->commands
);
1974 /* Clear a bpstat so that it says we are not at any breakpoint.
1975 Also free any storage that is part of a bpstat. */
1978 bpstat_clear (bpstat
*bsp
)
1995 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1996 is part of the bpstat is copied as well. */
1999 bpstat_copy (bpstat bs
)
2003 bpstat retval
= NULL
;
2008 for (; bs
!= NULL
; bs
= bs
->next
)
2010 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
2011 memcpy (tmp
, bs
, sizeof (*tmp
));
2012 if (bs
->commands
!= NULL
)
2013 tmp
->commands
= copy_command_lines (bs
->commands
);
2014 if (bs
->old_val
!= NULL
)
2016 tmp
->old_val
= value_copy (bs
->old_val
);
2017 release_value (tmp
->old_val
);
2021 /* This is the first thing in the chain. */
2031 /* Find the bpstat associated with this breakpoint */
2034 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
2039 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2041 if (bsp
->breakpoint_at
&& bsp
->breakpoint_at
->owner
== breakpoint
)
2047 /* Find a step_resume breakpoint associated with this bpstat.
2048 (If there are multiple step_resume bp's on the list, this function
2049 will arbitrarily pick one.)
2051 It is an error to use this function if BPSTAT doesn't contain a
2052 step_resume breakpoint.
2054 See wait_for_inferior's use of this function. */
2056 bpstat_find_step_resume_breakpoint (bpstat bsp
)
2060 gdb_assert (bsp
!= NULL
);
2062 current_thread
= pid_to_thread_id (inferior_ptid
);
2064 for (; bsp
!= NULL
; bsp
= bsp
->next
)
2066 if ((bsp
->breakpoint_at
!= NULL
) &&
2067 (bsp
->breakpoint_at
->owner
->type
== bp_step_resume
) &&
2068 (bsp
->breakpoint_at
->owner
->thread
== current_thread
||
2069 bsp
->breakpoint_at
->owner
->thread
== -1))
2070 return bsp
->breakpoint_at
->owner
;
2073 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
2077 /* Put in *NUM the breakpoint number of the first breakpoint we are stopped
2078 at. *BSP upon return is a bpstat which points to the remaining
2079 breakpoints stopped at (but which is not guaranteed to be good for
2080 anything but further calls to bpstat_num).
2081 Return 0 if passed a bpstat which does not indicate any breakpoints.
2082 Return -1 if stopped at a breakpoint that has been deleted since
2084 Return 1 otherwise. */
2087 bpstat_num (bpstat
*bsp
, int *num
)
2089 struct breakpoint
*b
;
2092 return 0; /* No more breakpoint values */
2094 /* We assume we'll never have several bpstats that
2095 correspond to a single breakpoint -- otherwise,
2096 this function might return the same number more
2097 than once and this will look ugly. */
2098 b
= (*bsp
)->breakpoint_at
? (*bsp
)->breakpoint_at
->owner
: NULL
;
2099 *bsp
= (*bsp
)->next
;
2101 return -1; /* breakpoint that's been deleted since */
2103 *num
= b
->number
; /* We have its number */
2107 /* Modify BS so that the actions will not be performed. */
2110 bpstat_clear_actions (bpstat bs
)
2112 for (; bs
!= NULL
; bs
= bs
->next
)
2114 free_command_lines (&bs
->commands
);
2115 if (bs
->old_val
!= NULL
)
2117 value_free (bs
->old_val
);
2123 /* Stub for cleaning up our state if we error-out of a breakpoint command */
2125 cleanup_executing_breakpoints (void *ignore
)
2127 executing_breakpoint_commands
= 0;
2130 /* Execute all the commands associated with all the breakpoints at this
2131 location. Any of these commands could cause the process to proceed
2132 beyond this point, etc. We look out for such changes by checking
2133 the global "breakpoint_proceeded" after each command. */
2136 bpstat_do_actions (bpstat
*bsp
)
2139 struct cleanup
*old_chain
;
2141 /* Avoid endless recursion if a `source' command is contained
2143 if (executing_breakpoint_commands
)
2146 executing_breakpoint_commands
= 1;
2147 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2150 /* Note that (as of this writing), our callers all appear to
2151 be passing us the address of global stop_bpstat. And, if
2152 our calls to execute_control_command cause the inferior to
2153 proceed, that global (and hence, *bsp) will change.
2155 We must be careful to not touch *bsp unless the inferior
2156 has not proceeded. */
2158 /* This pointer will iterate over the list of bpstat's. */
2161 breakpoint_proceeded
= 0;
2162 for (; bs
!= NULL
; bs
= bs
->next
)
2164 struct command_line
*cmd
;
2165 struct cleanup
*this_cmd_tree_chain
;
2167 /* Take ownership of the BSP's command tree, if it has one.
2169 The command tree could legitimately contain commands like
2170 'step' and 'next', which call clear_proceed_status, which
2171 frees stop_bpstat's command tree. To make sure this doesn't
2172 free the tree we're executing out from under us, we need to
2173 take ownership of the tree ourselves. Since a given bpstat's
2174 commands are only executed once, we don't need to copy it; we
2175 can clear the pointer in the bpstat, and make sure we free
2176 the tree when we're done. */
2179 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2183 execute_control_command (cmd
);
2185 if (breakpoint_proceeded
)
2191 /* We can free this command tree now. */
2192 do_cleanups (this_cmd_tree_chain
);
2194 if (breakpoint_proceeded
)
2196 if (target_can_async_p ())
2197 /* If we are in async mode, then the target might
2198 be still running, not stopped at any breakpoint,
2199 so nothing for us to do here -- just return to
2203 /* In sync mode, when execute_control_command returns
2204 we're already standing on the next breakpoint.
2205 Breakpoint commands for that stop were not run,
2206 since execute_command does not run breakpoint
2207 commands -- only command_line_handler does, but
2208 that one is not involved in execution of breakpoint
2209 commands. So, we can now execute breakpoint commands.
2210 There's an implicit assumption that we're called with
2211 stop_bpstat, so our parameter is the new bpstat to
2213 It should be noted that making execute_command do
2214 bpstat actions is not an option -- in this case we'll
2215 have recursive invocation of bpstat for each breakpoint
2216 with a command, and can easily blow up GDB stack. */
2220 do_cleanups (old_chain
);
2223 /* Print out the (old or new) value associated with a watchpoint. */
2226 watchpoint_value_print (struct value
*val
, struct ui_file
*stream
)
2229 fprintf_unfiltered (stream
, _("<unreadable>"));
2231 value_print (val
, stream
, 0, Val_pretty_default
);
2234 /* This is the normal print function for a bpstat. In the future,
2235 much of this logic could (should?) be moved to bpstat_stop_status,
2236 by having it set different print_it values.
2238 Current scheme: When we stop, bpstat_print() is called. It loops
2239 through the bpstat list of things causing this stop, calling the
2240 print_bp_stop_message function on each one. The behavior of the
2241 print_bp_stop_message function depends on the print_it field of
2242 bpstat. If such field so indicates, call this function here.
2244 Return values from this routine (ultimately used by bpstat_print()
2245 and normal_stop() to decide what to do):
2246 PRINT_NOTHING: Means we already printed all we needed to print,
2247 don't print anything else.
2248 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2249 that something to be followed by a location.
2250 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2251 that something to be followed by a location.
2252 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2255 static enum print_stop_action
2256 print_it_typical (bpstat bs
)
2258 struct cleanup
*old_chain
, *ui_out_chain
;
2259 struct breakpoint
*b
;
2260 const struct bp_location
*bl
;
2261 struct ui_stream
*stb
;
2263 stb
= ui_out_stream_new (uiout
);
2264 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2265 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2266 which has since been deleted. */
2267 if (bs
->breakpoint_at
== NULL
)
2268 return PRINT_UNKNOWN
;
2269 bl
= bs
->breakpoint_at
;
2275 case bp_hardware_breakpoint
:
2276 bp_temp
= bs
->breakpoint_at
->owner
->disposition
== disp_del
;
2277 if (bl
->address
!= bl
->requested_address
)
2278 breakpoint_adjustment_warning (bl
->requested_address
,
2281 annotate_breakpoint (b
->number
);
2283 ui_out_text (uiout
, "\nTemporary breakpoint ");
2285 ui_out_text (uiout
, "\nBreakpoint ");
2286 if (ui_out_is_mi_like_p (uiout
))
2288 ui_out_field_string (uiout
, "reason",
2289 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2290 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
2292 ui_out_field_int (uiout
, "bkptno", b
->number
);
2293 ui_out_text (uiout
, ", ");
2294 return PRINT_SRC_AND_LOC
;
2297 case bp_shlib_event
:
2298 /* Did we stop because the user set the stop_on_solib_events
2299 variable? (If so, we report this as a generic, "Stopped due
2300 to shlib event" message.) */
2301 printf_filtered (_("Stopped due to shared library event\n"));
2302 return PRINT_NOTHING
;
2305 case bp_thread_event
:
2306 /* Not sure how we will get here.
2307 GDB should not stop for these breakpoints. */
2308 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2309 return PRINT_NOTHING
;
2312 case bp_overlay_event
:
2313 /* By analogy with the thread event, GDB should not stop for these. */
2314 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2315 return PRINT_NOTHING
;
2319 annotate_catchpoint (b
->number
);
2320 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2322 b
->triggered_dll_pathname
);
2323 return PRINT_SRC_AND_LOC
;
2326 case bp_catch_unload
:
2327 annotate_catchpoint (b
->number
);
2328 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2330 b
->triggered_dll_pathname
);
2331 return PRINT_SRC_AND_LOC
;
2335 annotate_catchpoint (b
->number
);
2336 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2338 ptid_get_pid (b
->forked_inferior_pid
));
2339 return PRINT_SRC_AND_LOC
;
2342 case bp_catch_vfork
:
2343 annotate_catchpoint (b
->number
);
2344 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2346 ptid_get_pid (b
->forked_inferior_pid
));
2347 return PRINT_SRC_AND_LOC
;
2351 annotate_catchpoint (b
->number
);
2352 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2355 return PRINT_SRC_AND_LOC
;
2359 case bp_hardware_watchpoint
:
2360 annotate_watchpoint (b
->number
);
2361 if (ui_out_is_mi_like_p (uiout
))
2364 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2366 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2367 ui_out_text (uiout
, "\nOld value = ");
2368 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2369 ui_out_field_stream (uiout
, "old", stb
);
2370 ui_out_text (uiout
, "\nNew value = ");
2371 watchpoint_value_print (b
->val
, stb
->stream
);
2372 ui_out_field_stream (uiout
, "new", stb
);
2373 do_cleanups (ui_out_chain
);
2374 ui_out_text (uiout
, "\n");
2375 /* More than one watchpoint may have been triggered. */
2376 return PRINT_UNKNOWN
;
2379 case bp_read_watchpoint
:
2380 if (ui_out_is_mi_like_p (uiout
))
2383 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2385 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2386 ui_out_text (uiout
, "\nValue = ");
2387 watchpoint_value_print (b
->val
, stb
->stream
);
2388 ui_out_field_stream (uiout
, "value", stb
);
2389 do_cleanups (ui_out_chain
);
2390 ui_out_text (uiout
, "\n");
2391 return PRINT_UNKNOWN
;
2394 case bp_access_watchpoint
:
2395 if (bs
->old_val
!= NULL
)
2397 annotate_watchpoint (b
->number
);
2398 if (ui_out_is_mi_like_p (uiout
))
2401 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2403 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2404 ui_out_text (uiout
, "\nOld value = ");
2405 watchpoint_value_print (bs
->old_val
, stb
->stream
);
2406 ui_out_field_stream (uiout
, "old", stb
);
2407 ui_out_text (uiout
, "\nNew value = ");
2412 if (ui_out_is_mi_like_p (uiout
))
2415 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2416 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2417 ui_out_text (uiout
, "\nValue = ");
2419 watchpoint_value_print (b
->val
, stb
->stream
);
2420 ui_out_field_stream (uiout
, "new", stb
);
2421 do_cleanups (ui_out_chain
);
2422 ui_out_text (uiout
, "\n");
2423 return PRINT_UNKNOWN
;
2426 /* Fall through, we don't deal with these types of breakpoints
2430 if (ui_out_is_mi_like_p (uiout
))
2433 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2434 return PRINT_UNKNOWN
;
2438 if (ui_out_is_mi_like_p (uiout
))
2441 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2442 return PRINT_UNKNOWN
;
2447 case bp_longjmp_resume
:
2448 case bp_step_resume
:
2449 case bp_watchpoint_scope
:
2452 return PRINT_UNKNOWN
;
2456 /* Generic routine for printing messages indicating why we
2457 stopped. The behavior of this function depends on the value
2458 'print_it' in the bpstat structure. Under some circumstances we
2459 may decide not to print anything here and delegate the task to
2462 static enum print_stop_action
2463 print_bp_stop_message (bpstat bs
)
2465 switch (bs
->print_it
)
2468 /* Nothing should be printed for this bpstat entry. */
2469 return PRINT_UNKNOWN
;
2473 /* We still want to print the frame, but we already printed the
2474 relevant messages. */
2475 return PRINT_SRC_AND_LOC
;
2478 case print_it_normal
:
2480 const struct bp_location
*bl
= bs
->breakpoint_at
;
2481 struct breakpoint
*b
= bl
? bl
->owner
: NULL
;
2483 /* Normal case. Call the breakpoint's print_it method, or
2484 print_it_typical. */
2485 /* FIXME: how breakpoint can ever be NULL here? */
2486 if (b
!= NULL
&& b
->ops
!= NULL
&& b
->ops
->print_it
!= NULL
)
2487 return b
->ops
->print_it (b
);
2489 return print_it_typical (bs
);
2494 internal_error (__FILE__
, __LINE__
,
2495 _("print_bp_stop_message: unrecognized enum value"));
2500 /* Print a message indicating what happened. This is called from
2501 normal_stop(). The input to this routine is the head of the bpstat
2502 list - a list of the eventpoints that caused this stop. This
2503 routine calls the generic print routine for printing a message
2504 about reasons for stopping. This will print (for example) the
2505 "Breakpoint n," part of the output. The return value of this
2508 PRINT_UNKNOWN: Means we printed nothing
2509 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2510 code to print the location. An example is
2511 "Breakpoint 1, " which should be followed by
2513 PRINT_SRC_ONLY: Means we printed something, but there is no need
2514 to also print the location part of the message.
2515 An example is the catch/throw messages, which
2516 don't require a location appended to the end.
2517 PRINT_NOTHING: We have done some printing and we don't need any
2518 further info to be printed.*/
2520 enum print_stop_action
2521 bpstat_print (bpstat bs
)
2525 /* Maybe another breakpoint in the chain caused us to stop.
2526 (Currently all watchpoints go on the bpstat whether hit or not.
2527 That probably could (should) be changed, provided care is taken
2528 with respect to bpstat_explains_signal). */
2529 for (; bs
; bs
= bs
->next
)
2531 val
= print_bp_stop_message (bs
);
2532 if (val
== PRINT_SRC_ONLY
2533 || val
== PRINT_SRC_AND_LOC
2534 || val
== PRINT_NOTHING
)
2538 /* We reached the end of the chain, or we got a null BS to start
2539 with and nothing was printed. */
2540 return PRINT_UNKNOWN
;
2543 /* Evaluate the expression EXP and return 1 if value is zero.
2544 This is used inside a catch_errors to evaluate the breakpoint condition.
2545 The argument is a "struct expression *" that has been cast to char * to
2546 make it pass through catch_errors. */
2549 breakpoint_cond_eval (void *exp
)
2551 struct value
*mark
= value_mark ();
2552 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2553 value_free_to_mark (mark
);
2557 /* Allocate a new bpstat and chain it to the current one. */
2560 bpstat_alloc (const struct bp_location
*bl
, bpstat cbs
/* Current "bs" value */ )
2564 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2566 bs
->breakpoint_at
= bl
;
2567 /* If the condition is false, etc., don't do the commands. */
2568 bs
->commands
= NULL
;
2570 bs
->print_it
= print_it_normal
;
2574 /* The target has stopped with waitstatus WS. Check if any hardware
2575 watchpoints have triggered, according to the target. */
2578 watchpoints_triggered (struct target_waitstatus
*ws
)
2580 int stopped_by_watchpoint
= STOPPED_BY_WATCHPOINT (*ws
);
2582 struct breakpoint
*b
;
2584 if (!stopped_by_watchpoint
)
2586 /* We were not stopped by a watchpoint. Mark all watchpoints
2587 as not triggered. */
2589 if (b
->type
== bp_hardware_watchpoint
2590 || b
->type
== bp_read_watchpoint
2591 || b
->type
== bp_access_watchpoint
)
2592 b
->watchpoint_triggered
= watch_triggered_no
;
2597 if (!target_stopped_data_address (¤t_target
, &addr
))
2599 /* We were stopped by a watchpoint, but we don't know where.
2600 Mark all watchpoints as unknown. */
2602 if (b
->type
== bp_hardware_watchpoint
2603 || b
->type
== bp_read_watchpoint
2604 || b
->type
== bp_access_watchpoint
)
2605 b
->watchpoint_triggered
= watch_triggered_unknown
;
2607 return stopped_by_watchpoint
;
2610 /* The target could report the data address. Mark watchpoints
2611 affected by this data address as triggered, and all others as not
2615 if (b
->type
== bp_hardware_watchpoint
2616 || b
->type
== bp_read_watchpoint
2617 || b
->type
== bp_access_watchpoint
)
2619 struct bp_location
*loc
;
2622 b
->watchpoint_triggered
= watch_triggered_no
;
2623 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
2624 /* Exact match not required. Within range is
2626 if (target_watchpoint_addr_within_range (¤t_target
,
2630 b
->watchpoint_triggered
= watch_triggered_yes
;
2638 /* Possible return values for watchpoint_check (this can't be an enum
2639 because of check_errors). */
2640 /* The watchpoint has been deleted. */
2641 #define WP_DELETED 1
2642 /* The value has changed. */
2643 #define WP_VALUE_CHANGED 2
2644 /* The value has not changed. */
2645 #define WP_VALUE_NOT_CHANGED 3
2647 #define BP_TEMPFLAG 1
2648 #define BP_HARDWAREFLAG 2
2650 /* Check watchpoint condition. */
2653 watchpoint_check (void *p
)
2655 bpstat bs
= (bpstat
) p
;
2656 struct breakpoint
*b
;
2657 struct frame_info
*fr
;
2658 int within_current_scope
;
2660 b
= bs
->breakpoint_at
->owner
;
2662 if (b
->exp_valid_block
== NULL
)
2663 within_current_scope
= 1;
2666 /* There is no current frame at this moment. If we're going to have
2667 any chance of handling watchpoints on local variables, we'll need
2668 the frame chain (so we can determine if we're in scope). */
2669 reinit_frame_cache ();
2670 fr
= frame_find_by_id (b
->watchpoint_frame
);
2671 within_current_scope
= (fr
!= NULL
);
2673 /* If we've gotten confused in the unwinder, we might have
2674 returned a frame that can't describe this variable. */
2675 if (within_current_scope
2676 && (block_linkage_function (b
->exp_valid_block
)
2677 != get_frame_function (fr
)))
2678 within_current_scope
= 0;
2680 /* in_function_epilogue_p() returns a non-zero value if we're still
2681 in the function but the stack frame has already been invalidated.
2682 Since we can't rely on the values of local variables after the
2683 stack has been destroyed, we are treating the watchpoint in that
2684 state as `not changed' without further checking.
2686 vinschen/2003-09-04: The former implementation left out the case
2687 that the watchpoint frame couldn't be found by frame_find_by_id()
2688 because the current PC is currently in an epilogue. Calling
2689 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2690 if ((!within_current_scope
|| fr
== get_current_frame ())
2691 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2692 return WP_VALUE_NOT_CHANGED
;
2693 if (fr
&& within_current_scope
)
2694 /* If we end up stopping, the current frame will get selected
2695 in normal_stop. So this call to select_frame won't affect
2700 if (within_current_scope
)
2702 /* We use value_{,free_to_}mark because it could be a
2703 *long* time before we return to the command level and
2704 call free_all_values. We can't call free_all_values because
2705 we might be in the middle of evaluating a function call. */
2707 struct value
*mark
= value_mark ();
2708 struct value
*new_val
;
2710 fetch_watchpoint_value (b
->exp
, &new_val
, NULL
, NULL
);
2711 if ((b
->val
!= NULL
) != (new_val
!= NULL
)
2712 || (b
->val
!= NULL
&& !value_equal (b
->val
, new_val
)))
2714 if (new_val
!= NULL
)
2716 release_value (new_val
);
2717 value_free_to_mark (mark
);
2719 bs
->old_val
= b
->val
;
2722 /* We will stop here */
2723 return WP_VALUE_CHANGED
;
2727 /* Nothing changed, don't do anything. */
2728 value_free_to_mark (mark
);
2729 /* We won't stop here */
2730 return WP_VALUE_NOT_CHANGED
;
2735 /* This seems like the only logical thing to do because
2736 if we temporarily ignored the watchpoint, then when
2737 we reenter the block in which it is valid it contains
2738 garbage (in the case of a function, it may have two
2739 garbage values, one before and one after the prologue).
2740 So we can't even detect the first assignment to it and
2741 watch after that (since the garbage may or may not equal
2742 the first value assigned). */
2743 /* We print all the stop information in print_it_typical(), but
2744 in this case, by the time we call print_it_typical() this bp
2745 will be deleted already. So we have no choice but print the
2746 information here. */
2747 if (ui_out_is_mi_like_p (uiout
))
2749 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2750 ui_out_text (uiout
, "\nWatchpoint ");
2751 ui_out_field_int (uiout
, "wpnum", b
->number
);
2752 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2753 which its expression is valid.\n");
2755 if (b
->related_breakpoint
)
2756 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2757 b
->disposition
= disp_del_at_next_stop
;
2763 /* Return true if it looks like target has stopped due to hitting
2764 breakpoint location BL. This function does not check if we
2765 should stop, only if BL explains the stop. */
2767 bpstat_check_location (const struct bp_location
*bl
, CORE_ADDR bp_addr
)
2769 struct breakpoint
*b
= bl
->owner
;
2771 if (b
->type
!= bp_watchpoint
2772 && b
->type
!= bp_hardware_watchpoint
2773 && b
->type
!= bp_read_watchpoint
2774 && b
->type
!= bp_access_watchpoint
2775 && b
->type
!= bp_hardware_breakpoint
2776 && b
->type
!= bp_catch_fork
2777 && b
->type
!= bp_catch_vfork
2778 && b
->type
!= bp_catch_exec
) /* a non-watchpoint bp */
2780 if (bl
->address
!= bp_addr
) /* address doesn't match */
2782 if (overlay_debugging
/* unmapped overlay section */
2783 && section_is_overlay (bl
->section
)
2784 && !section_is_mapped (bl
->section
))
2788 /* Continuable hardware watchpoints are treated as non-existent if the
2789 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2790 some data address). Otherwise gdb won't stop on a break instruction
2791 in the code (not from a breakpoint) when a hardware watchpoint has
2792 been defined. Also skip watchpoints which we know did not trigger
2793 (did not match the data address). */
2795 if ((b
->type
== bp_hardware_watchpoint
2796 || b
->type
== bp_read_watchpoint
2797 || b
->type
== bp_access_watchpoint
)
2798 && b
->watchpoint_triggered
== watch_triggered_no
)
2801 if (b
->type
== bp_hardware_breakpoint
)
2803 if (bl
->address
!= bp_addr
)
2805 if (overlay_debugging
/* unmapped overlay section */
2806 && section_is_overlay (bl
->section
)
2807 && !section_is_mapped (bl
->section
))
2811 /* Is this a catchpoint of a load or unload? If so, did we
2812 get a load or unload of the specified library? If not,
2814 if ((b
->type
== bp_catch_load
)
2815 #if defined(SOLIB_HAVE_LOAD_EVENT)
2816 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2817 || ((b
->dll_pathname
!= NULL
)
2818 && (strcmp (b
->dll_pathname
,
2819 SOLIB_LOADED_LIBRARY_PATHNAME (
2820 PIDGET (inferior_ptid
)))
2826 if ((b
->type
== bp_catch_unload
)
2827 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2828 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2829 || ((b
->dll_pathname
!= NULL
)
2830 && (strcmp (b
->dll_pathname
,
2831 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2832 PIDGET (inferior_ptid
)))
2838 if ((b
->type
== bp_catch_fork
)
2839 && !inferior_has_forked (inferior_ptid
,
2840 &b
->forked_inferior_pid
))
2843 if ((b
->type
== bp_catch_vfork
)
2844 && !inferior_has_vforked (inferior_ptid
,
2845 &b
->forked_inferior_pid
))
2848 if ((b
->type
== bp_catch_exec
)
2849 && !inferior_has_execd (inferior_ptid
, &b
->exec_pathname
))
2855 /* If BS refers to a watchpoint, determine if the watched values
2856 has actually changed, and we should stop. If not, set BS->stop
2859 bpstat_check_watchpoint (bpstat bs
)
2861 const struct bp_location
*bl
= bs
->breakpoint_at
;
2862 struct breakpoint
*b
= bl
->owner
;
2864 if (b
->type
== bp_watchpoint
2865 || b
->type
== bp_read_watchpoint
2866 || b
->type
== bp_access_watchpoint
2867 || b
->type
== bp_hardware_watchpoint
)
2871 int must_check_value
= 0;
2873 if (b
->type
== bp_watchpoint
)
2874 /* For a software watchpoint, we must always check the
2876 must_check_value
= 1;
2877 else if (b
->watchpoint_triggered
== watch_triggered_yes
)
2878 /* We have a hardware watchpoint (read, write, or access)
2879 and the target earlier reported an address watched by
2881 must_check_value
= 1;
2882 else if (b
->watchpoint_triggered
== watch_triggered_unknown
2883 && b
->type
== bp_hardware_watchpoint
)
2884 /* We were stopped by a hardware watchpoint, but the target could
2885 not report the data address. We must check the watchpoint's
2886 value. Access and read watchpoints are out of luck; without
2887 a data address, we can't figure it out. */
2888 must_check_value
= 1;
2890 if (must_check_value
)
2892 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2894 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2895 int e
= catch_errors (watchpoint_check
, bs
, message
,
2897 do_cleanups (cleanups
);
2901 /* We've already printed what needs to be printed. */
2902 bs
->print_it
= print_it_done
;
2905 case WP_VALUE_CHANGED
:
2906 if (b
->type
== bp_read_watchpoint
)
2908 /* Don't stop: read watchpoints shouldn't fire if
2909 the value has changed. This is for targets
2910 which cannot set read-only watchpoints. */
2911 bs
->print_it
= print_it_noop
;
2915 case WP_VALUE_NOT_CHANGED
:
2916 if (b
->type
== bp_hardware_watchpoint
2917 || b
->type
== bp_watchpoint
)
2919 /* Don't stop: write watchpoints shouldn't fire if
2920 the value hasn't changed. */
2921 bs
->print_it
= print_it_noop
;
2929 /* Error from catch_errors. */
2930 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2931 if (b
->related_breakpoint
)
2932 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2933 b
->disposition
= disp_del_at_next_stop
;
2934 /* We've already printed what needs to be printed. */
2935 bs
->print_it
= print_it_done
;
2939 else /* must_check_value == 0 */
2941 /* This is a case where some watchpoint(s) triggered, but
2942 not at the address of this watchpoint, or else no
2943 watchpoint triggered after all. So don't print
2944 anything for this watchpoint. */
2945 bs
->print_it
= print_it_noop
;
2952 /* Check conditions (condition proper, frame, thread and ignore count)
2953 of breakpoint referred to by BS. If we should not stop for this
2954 breakpoint, set BS->stop to 0. */
2956 bpstat_check_breakpoint_conditions (bpstat bs
, ptid_t ptid
)
2958 int thread_id
= pid_to_thread_id (ptid
);
2959 const struct bp_location
*bl
= bs
->breakpoint_at
;
2960 struct breakpoint
*b
= bl
->owner
;
2962 if (frame_id_p (b
->frame_id
)
2963 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2967 int value_is_zero
= 0;
2969 /* If this is a scope breakpoint, mark the associated
2970 watchpoint as triggered so that we will handle the
2971 out-of-scope event. We'll get to the watchpoint next
2973 if (b
->type
== bp_watchpoint_scope
)
2974 b
->related_breakpoint
->watchpoint_triggered
= watch_triggered_yes
;
2976 if (bl
->cond
&& bl
->owner
->disposition
!= disp_del_at_next_stop
)
2978 /* Need to select the frame, with all that implies
2979 so that the conditions will have the right context. */
2980 select_frame (get_current_frame ());
2982 = catch_errors (breakpoint_cond_eval
, (bl
->cond
),
2983 "Error in testing breakpoint condition:\n",
2985 /* FIXME-someday, should give breakpoint # */
2988 if (bl
->cond
&& value_is_zero
)
2992 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2996 else if (b
->ignore_count
> 0)
2999 annotate_ignore_count_change ();
3001 /* Increase the hit count even though we don't
3009 /* Get a bpstat associated with having just stopped at address
3010 BP_ADDR in thread PTID.
3012 Determine whether we stopped at a breakpoint, etc, or whether we
3013 don't understand this stop. Result is a chain of bpstat's such that:
3015 if we don't understand the stop, the result is a null pointer.
3017 if we understand why we stopped, the result is not null.
3019 Each element of the chain refers to a particular breakpoint or
3020 watchpoint at which we have stopped. (We may have stopped for
3021 several reasons concurrently.)
3023 Each element of the chain has valid next, breakpoint_at,
3024 commands, FIXME??? fields. */
3027 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
)
3029 struct breakpoint
*b
= NULL
;
3030 const struct bp_location
*bl
;
3031 struct bp_location
*loc
;
3032 /* Root of the chain of bpstat's */
3033 struct bpstats root_bs
[1];
3034 /* Pointer to the last thing in the chain currently. */
3035 bpstat bs
= root_bs
;
3038 ALL_BP_LOCATIONS (bl
)
3042 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
3045 /* For hardware watchpoints, we look only at the first location.
3046 The watchpoint_check function will work on entire expression,
3047 not the individual locations. For read watchopints, the
3048 watchpoints_triggered function have checked all locations
3051 if (b
->type
== bp_hardware_watchpoint
&& bl
!= b
->loc
)
3054 if (!bpstat_check_location (bl
, bp_addr
))
3057 /* Come here if it's a watchpoint, or if the break address matches */
3059 bs
= bpstat_alloc (bl
, bs
); /* Alloc a bpstat to explain stop */
3061 /* Assume we stop. Should we find watchpoint that is not actually
3062 triggered, or if condition of breakpoint is false, we'll reset
3067 bpstat_check_watchpoint (bs
);
3071 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
3072 /* We do not stop for these. */
3075 bpstat_check_breakpoint_conditions (bs
, ptid
);
3081 /* We will stop here */
3082 if (b
->disposition
== disp_disable
)
3084 b
->enable_state
= bp_disabled
;
3085 update_global_location_list (0);
3089 bs
->commands
= b
->commands
;
3091 (strcmp ("silent", bs
->commands
->line
) == 0
3092 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
3094 bs
->commands
= bs
->commands
->next
;
3097 bs
->commands
= copy_command_lines (bs
->commands
);
3100 /* Print nothing for this entry if we dont stop or if we dont print. */
3101 if (bs
->stop
== 0 || bs
->print
== 0)
3102 bs
->print_it
= print_it_noop
;
3105 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
3107 if (loc
->address
== bp_addr
)
3109 bs
= bpstat_alloc (loc
, bs
);
3110 /* For hits of moribund locations, we should just proceed. */
3113 bs
->print_it
= print_it_noop
;
3117 bs
->next
= NULL
; /* Terminate the chain */
3118 bs
= root_bs
->next
; /* Re-grab the head of the chain */
3120 /* If we aren't stopping, the value of some hardware watchpoint may
3121 not have changed, but the intermediate memory locations we are
3122 watching may have. Don't bother if we're stopping; this will get
3124 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3129 for (bs
= root_bs
->next
; bs
!= NULL
; bs
= bs
->next
)
3131 && bs
->breakpoint_at
->owner
3132 && (bs
->breakpoint_at
->owner
->type
== bp_hardware_watchpoint
3133 || bs
->breakpoint_at
->owner
->type
== bp_read_watchpoint
3134 || bs
->breakpoint_at
->owner
->type
== bp_access_watchpoint
))
3136 /* remove/insert can invalidate bs->breakpoint_at, if this
3137 location is no longer used by the watchpoint. Prevent
3138 further code from trying to use it. */
3139 bs
->breakpoint_at
= NULL
;
3140 remove_breakpoints ();
3141 insert_breakpoints ();
3145 return root_bs
->next
;
3148 /* Tell what to do about this bpstat. */
3150 bpstat_what (bpstat bs
)
3152 /* Classify each bpstat as one of the following. */
3155 /* This bpstat element has no effect on the main_action. */
3158 /* There was a watchpoint, stop but don't print. */
3161 /* There was a watchpoint, stop and print. */
3164 /* There was a breakpoint but we're not stopping. */
3167 /* There was a breakpoint, stop but don't print. */
3170 /* There was a breakpoint, stop and print. */
3173 /* We hit the longjmp breakpoint. */
3176 /* We hit the longjmp_resume breakpoint. */
3179 /* We hit the step_resume breakpoint. */
3182 /* We hit the shared library event breakpoint. */
3185 /* We caught a shared library event. */
3188 /* This is just used to count how many enums there are. */
3192 /* Here is the table which drives this routine. So that we can
3193 format it pretty, we define some abbreviations for the
3194 enum bpstat_what codes. */
3195 #define kc BPSTAT_WHAT_KEEP_CHECKING
3196 #define ss BPSTAT_WHAT_STOP_SILENT
3197 #define sn BPSTAT_WHAT_STOP_NOISY
3198 #define sgl BPSTAT_WHAT_SINGLE
3199 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
3200 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
3201 #define sr BPSTAT_WHAT_STEP_RESUME
3202 #define shl BPSTAT_WHAT_CHECK_SHLIBS
3203 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
3205 /* "Can't happen." Might want to print an error message.
3206 abort() is not out of the question, but chances are GDB is just
3207 a bit confused, not unusable. */
3208 #define err BPSTAT_WHAT_STOP_NOISY
3210 /* Given an old action and a class, come up with a new action. */
3211 /* One interesting property of this table is that wp_silent is the same
3212 as bp_silent and wp_noisy is the same as bp_noisy. That is because
3213 after stopping, the check for whether to step over a breakpoint
3214 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
3215 reference to how we stopped. We retain separate wp_silent and
3216 bp_silent codes in case we want to change that someday.
3218 Another possibly interesting property of this table is that
3219 there's a partial ordering, priority-like, of the actions. Once
3220 you've decided that some action is appropriate, you'll never go
3221 back and decide something of a lower priority is better. The
3224 kc < clr sgl shl shlr slr sn sr ss
3225 sgl < shl shlr slr sn sr ss
3226 slr < err shl shlr sn sr ss
3227 clr < err shl shlr sn sr ss
3234 What I think this means is that we don't need a damned table
3235 here. If you just put the rows and columns in the right order,
3236 it'd look awfully regular. We could simply walk the bpstat list
3237 and choose the highest priority action we find, with a little
3238 logic to handle the 'err' cases. */
3240 /* step_resume entries: a step resume breakpoint overrides another
3241 breakpoint of signal handling (see comment in wait_for_inferior
3242 at where we set the step_resume breakpoint). */
3244 static const enum bpstat_what_main_action
3245 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3248 /* kc ss sn sgl slr clr sr shl shlr
3251 {kc
, ss
, sn
, sgl
, slr
, clr
, sr
, shl
, shlr
},
3253 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3255 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3257 {sgl
, ss
, sn
, sgl
, slr
, slr
, sr
, shl
, shlr
},
3259 {ss
, ss
, sn
, ss
, ss
, ss
, sr
, shl
, shlr
},
3261 {sn
, sn
, sn
, sn
, sn
, sn
, sr
, shl
, shlr
},
3263 {slr
, ss
, sn
, slr
, slr
, err
, sr
, shl
, shlr
},
3265 {clr
, ss
, sn
, err
, err
, err
, sr
, shl
, shlr
},
3267 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
},
3269 {shl
, shl
, shl
, shl
, shl
, shl
, sr
, shl
, shlr
},
3271 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, sr
, shlr
, shlr
}
3285 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3286 struct bpstat_what retval
;
3288 retval
.call_dummy
= 0;
3289 for (; bs
!= NULL
; bs
= bs
->next
)
3291 enum class bs_class
= no_effect
;
3292 if (bs
->breakpoint_at
== NULL
)
3293 /* I suspect this can happen if it was a momentary breakpoint
3294 which has since been deleted. */
3296 if (bs
->breakpoint_at
->owner
== NULL
)
3297 bs_class
= bp_nostop
;
3299 switch (bs
->breakpoint_at
->owner
->type
)
3305 case bp_hardware_breakpoint
:
3311 bs_class
= bp_noisy
;
3313 bs_class
= bp_silent
;
3316 bs_class
= bp_nostop
;
3319 case bp_hardware_watchpoint
:
3320 case bp_read_watchpoint
:
3321 case bp_access_watchpoint
:
3325 bs_class
= wp_noisy
;
3327 bs_class
= wp_silent
;
3330 /* There was a watchpoint, but we're not stopping.
3331 This requires no further action. */
3332 bs_class
= no_effect
;
3335 bs_class
= long_jump
;
3337 case bp_longjmp_resume
:
3338 bs_class
= long_resume
;
3340 case bp_step_resume
:
3343 bs_class
= step_resume
;
3346 /* It is for the wrong frame. */
3347 bs_class
= bp_nostop
;
3349 case bp_watchpoint_scope
:
3350 bs_class
= bp_nostop
;
3352 case bp_shlib_event
:
3353 bs_class
= shlib_event
;
3355 case bp_thread_event
:
3356 case bp_overlay_event
:
3357 bs_class
= bp_nostop
;
3360 case bp_catch_unload
:
3361 /* Only if this catchpoint triggered should we cause the
3362 step-out-of-dld behaviour. Otherwise, we ignore this
3365 bs_class
= catch_shlib_event
;
3367 bs_class
= no_effect
;
3370 case bp_catch_vfork
:
3375 bs_class
= bp_noisy
;
3377 bs_class
= bp_silent
;
3380 /* There was a catchpoint, but we're not stopping.
3381 This requires no further action. */
3382 bs_class
= no_effect
;
3385 /* Make sure the action is stop (silent or noisy),
3386 so infrun.c pops the dummy frame. */
3387 bs_class
= bp_silent
;
3388 retval
.call_dummy
= 1;
3391 current_action
= table
[(int) bs_class
][(int) current_action
];
3393 retval
.main_action
= current_action
;
3397 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3398 without hardware support). This isn't related to a specific bpstat,
3399 just to things like whether watchpoints are set. */
3402 bpstat_should_step (void)
3404 struct breakpoint
*b
;
3406 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3413 /* Given a bpstat that records zero or more triggered eventpoints, this
3414 function returns another bpstat which contains only the catchpoints
3415 on that first list, if any. */
3417 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3419 struct bpstats root_bs
[1];
3420 bpstat bs
= root_bs
;
3421 struct breakpoint
*ep
;
3424 bpstat_clear (cp_list
);
3425 root_bs
->next
= NULL
;
3427 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3429 /* Is this eventpoint a catchpoint? If not, ignore it. */
3430 ep
= ep_list
->breakpoint_at
->owner
;
3433 if ((ep
->type
!= bp_catch_load
) &&
3434 (ep
->type
!= bp_catch_unload
))
3435 /* pai: (temp) ADD fork/vfork here!! */
3438 /* Yes; add it to the list. */
3439 bs
= bpstat_alloc (ep_list
->breakpoint_at
, bs
);
3444 #if defined(SOLIB_ADD)
3445 /* Also, for each triggered catchpoint, tag it with the name of
3446 the library that caused this trigger. (We copy the name now,
3447 because it's only guaranteed to be available NOW, when the
3448 catchpoint triggers. Clients who may wish to know the name
3449 later must get it from the catchpoint itself.) */
3450 if (ep
->triggered_dll_pathname
!= NULL
)
3451 xfree (ep
->triggered_dll_pathname
);
3452 if (ep
->type
== bp_catch_load
)
3453 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3454 PIDGET (inferior_ptid
));
3456 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3457 PIDGET (inferior_ptid
));
3459 dll_pathname
= NULL
;
3463 ep
->triggered_dll_pathname
= (char *)
3464 xmalloc (strlen (dll_pathname
) + 1);
3465 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3468 ep
->triggered_dll_pathname
= NULL
;
3474 static void print_breakpoint_location (struct breakpoint
*b
,
3475 struct bp_location
*loc
,
3477 struct ui_stream
*stb
)
3482 = find_pc_sect_function (loc
->address
, loc
->section
);
3485 ui_out_text (uiout
, "in ");
3486 ui_out_field_string (uiout
, "func",
3487 SYMBOL_PRINT_NAME (sym
));
3488 ui_out_wrap_hint (uiout
, wrap_indent
);
3489 ui_out_text (uiout
, " at ");
3491 ui_out_field_string (uiout
, "file", b
->source_file
);
3492 ui_out_text (uiout
, ":");
3494 if (ui_out_is_mi_like_p (uiout
))
3496 struct symtab_and_line sal
= find_pc_line (loc
->address
, 0);
3497 char *fullname
= symtab_to_fullname (sal
.symtab
);
3500 ui_out_field_string (uiout
, "fullname", fullname
);
3503 ui_out_field_int (uiout
, "line", b
->line_number
);
3507 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3511 print_address_symbolic (loc
->address
, stb
->stream
, demangle
, "");
3512 ui_out_field_stream (uiout
, "at", stb
);
3516 /* Print B to gdb_stdout. */
3518 print_one_breakpoint_location (struct breakpoint
*b
,
3519 struct bp_location
*loc
,
3521 CORE_ADDR
*last_addr
)
3523 struct command_line
*l
;
3525 struct ep_type_description
3530 static struct ep_type_description bptypes
[] =
3532 {bp_none
, "?deleted?"},
3533 {bp_breakpoint
, "breakpoint"},
3534 {bp_hardware_breakpoint
, "hw breakpoint"},
3535 {bp_until
, "until"},
3536 {bp_finish
, "finish"},
3537 {bp_watchpoint
, "watchpoint"},
3538 {bp_hardware_watchpoint
, "hw watchpoint"},
3539 {bp_read_watchpoint
, "read watchpoint"},
3540 {bp_access_watchpoint
, "acc watchpoint"},
3541 {bp_longjmp
, "longjmp"},
3542 {bp_longjmp_resume
, "longjmp resume"},
3543 {bp_step_resume
, "step resume"},
3544 {bp_watchpoint_scope
, "watchpoint scope"},
3545 {bp_call_dummy
, "call dummy"},
3546 {bp_shlib_event
, "shlib events"},
3547 {bp_thread_event
, "thread events"},
3548 {bp_overlay_event
, "overlay events"},
3549 {bp_catch_load
, "catch load"},
3550 {bp_catch_unload
, "catch unload"},
3551 {bp_catch_fork
, "catch fork"},
3552 {bp_catch_vfork
, "catch vfork"},
3553 {bp_catch_exec
, "catch exec"}
3556 static char bpenables
[] = "nynny";
3557 char wrap_indent
[80];
3558 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3559 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3560 struct cleanup
*bkpt_chain
;
3562 int header_of_multiple
= 0;
3563 int part_of_multiple
= (loc
!= NULL
);
3565 gdb_assert (!loc
|| loc_number
!= 0);
3566 /* See comment in print_one_breakpoint concerning
3567 treatment of breakpoints with single disabled
3571 && (b
->loc
->next
!= NULL
|| !b
->loc
->enabled
)))
3572 header_of_multiple
= 1;
3577 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3581 if (part_of_multiple
)
3584 formatted
= xstrprintf ("%d.%d", b
->number
, loc_number
);
3585 ui_out_field_string (uiout
, "number", formatted
);
3590 ui_out_field_int (uiout
, "number", b
->number
);
3595 if (part_of_multiple
)
3596 ui_out_field_skip (uiout
, "type");
3599 if (((int) b
->type
>= (sizeof (bptypes
) / sizeof (bptypes
[0])))
3600 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3601 internal_error (__FILE__
, __LINE__
,
3602 _("bptypes table does not describe type #%d."),
3604 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3609 if (part_of_multiple
)
3610 ui_out_field_skip (uiout
, "disp");
3612 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
3617 if (part_of_multiple
)
3618 ui_out_field_string (uiout
, "enabled", loc
->enabled
? "y" : "n");
3620 ui_out_field_fmt (uiout
, "enabled", "%c",
3621 bpenables
[(int) b
->enable_state
]);
3622 ui_out_spaces (uiout
, 2);
3626 strcpy (wrap_indent
, " ");
3629 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3630 strcat (wrap_indent
, " ");
3632 strcat (wrap_indent
, " ");
3635 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3637 /* Although the print_one can possibly print
3638 all locations, calling it here is not likely
3639 to get any nice result. So, make sure there's
3640 just one location. */
3641 gdb_assert (b
->loc
== NULL
|| b
->loc
->next
== NULL
);
3642 b
->ops
->print_one (b
, last_addr
);
3648 internal_error (__FILE__
, __LINE__
,
3649 _("print_one_breakpoint: bp_none encountered\n"));
3653 case bp_hardware_watchpoint
:
3654 case bp_read_watchpoint
:
3655 case bp_access_watchpoint
:
3656 /* Field 4, the address, is omitted (which makes the columns
3657 not line up too nicely with the headers, but the effect
3658 is relatively readable). */
3660 ui_out_field_skip (uiout
, "addr");
3662 print_expression (b
->exp
, stb
->stream
);
3663 ui_out_field_stream (uiout
, "what", stb
);
3667 case bp_catch_unload
:
3668 /* Field 4, the address, is omitted (which makes the columns
3669 not line up too nicely with the headers, but the effect
3670 is relatively readable). */
3672 ui_out_field_skip (uiout
, "addr");
3674 if (b
->dll_pathname
== NULL
)
3676 ui_out_field_string (uiout
, "what", "<any library>");
3677 ui_out_spaces (uiout
, 1);
3681 ui_out_text (uiout
, "library \"");
3682 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3683 ui_out_text (uiout
, "\" ");
3688 case bp_catch_vfork
:
3689 /* Field 4, the address, is omitted (which makes the columns
3690 not line up too nicely with the headers, but the effect
3691 is relatively readable). */
3693 ui_out_field_skip (uiout
, "addr");
3695 if (!ptid_equal (b
->forked_inferior_pid
, null_ptid
))
3697 ui_out_text (uiout
, "process ");
3698 ui_out_field_int (uiout
, "what",
3699 ptid_get_pid (b
->forked_inferior_pid
));
3700 ui_out_spaces (uiout
, 1);
3705 /* Field 4, the address, is omitted (which makes the columns
3706 not line up too nicely with the headers, but the effect
3707 is relatively readable). */
3709 ui_out_field_skip (uiout
, "addr");
3711 if (b
->exec_pathname
!= NULL
)
3713 ui_out_text (uiout
, "program \"");
3714 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3715 ui_out_text (uiout
, "\" ");
3720 case bp_hardware_breakpoint
:
3724 case bp_longjmp_resume
:
3725 case bp_step_resume
:
3726 case bp_watchpoint_scope
:
3728 case bp_shlib_event
:
3729 case bp_thread_event
:
3730 case bp_overlay_event
:
3734 if (header_of_multiple
)
3735 ui_out_field_string (uiout
, "addr", "<MULTIPLE>");
3736 else if (b
->loc
== NULL
|| loc
->shlib_disabled
)
3737 ui_out_field_string (uiout
, "addr", "<PENDING>");
3739 ui_out_field_core_addr (uiout
, "addr", loc
->address
);
3742 if (!header_of_multiple
)
3743 print_breakpoint_location (b
, loc
, wrap_indent
, stb
);
3745 *last_addr
= b
->loc
->address
;
3749 if (!part_of_multiple
&& b
->thread
!= -1)
3751 /* FIXME: This seems to be redundant and lost here; see the
3752 "stop only in" line a little further down. */
3753 ui_out_text (uiout
, " thread ");
3754 ui_out_field_int (uiout
, "thread", b
->thread
);
3757 ui_out_text (uiout
, "\n");
3759 if (part_of_multiple
&& frame_id_p (b
->frame_id
))
3762 ui_out_text (uiout
, "\tstop only in stack frame at ");
3763 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3765 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3766 ui_out_text (uiout
, "\n");
3769 if (!part_of_multiple
&& b
->cond_string
&& !ada_exception_catchpoint_p (b
))
3771 /* We do not print the condition for Ada exception catchpoints
3772 because the condition is an internal implementation detail
3773 that we do not want to expose to the user. */
3775 ui_out_text (uiout
, "\tstop only if ");
3776 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3777 ui_out_text (uiout
, "\n");
3780 if (!part_of_multiple
&& b
->thread
!= -1)
3782 /* FIXME should make an annotation for this */
3783 ui_out_text (uiout
, "\tstop only in thread ");
3784 ui_out_field_int (uiout
, "thread", b
->thread
);
3785 ui_out_text (uiout
, "\n");
3788 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
)
3790 /* FIXME should make an annotation for this */
3791 if (ep_is_catchpoint (b
))
3792 ui_out_text (uiout
, "\tcatchpoint");
3794 ui_out_text (uiout
, "\tbreakpoint");
3795 ui_out_text (uiout
, " already hit ");
3796 ui_out_field_int (uiout
, "times", b
->hit_count
);
3797 if (b
->hit_count
== 1)
3798 ui_out_text (uiout
, " time\n");
3800 ui_out_text (uiout
, " times\n");
3803 /* Output the count also if it is zero, but only if this is
3804 mi. FIXME: Should have a better test for this. */
3805 if (ui_out_is_mi_like_p (uiout
))
3806 if (!part_of_multiple
&& show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3807 ui_out_field_int (uiout
, "times", b
->hit_count
);
3809 if (!part_of_multiple
&& b
->ignore_count
)
3812 ui_out_text (uiout
, "\tignore next ");
3813 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3814 ui_out_text (uiout
, " hits\n");
3817 if (!part_of_multiple
&& (l
= b
->commands
))
3819 struct cleanup
*script_chain
;
3822 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3823 print_command_lines (uiout
, l
, 4);
3824 do_cleanups (script_chain
);
3827 if (ui_out_is_mi_like_p (uiout
) && !part_of_multiple
)
3830 ui_out_field_string (uiout
, "original-location", b
->addr_string
);
3831 else if (b
->exp_string
)
3832 ui_out_field_string (uiout
, "original-location", b
->exp_string
);
3835 do_cleanups (bkpt_chain
);
3836 do_cleanups (old_chain
);
3840 print_one_breakpoint (struct breakpoint
*b
,
3841 CORE_ADDR
*last_addr
)
3843 print_one_breakpoint_location (b
, NULL
, 0, last_addr
);
3845 /* If this breakpoint has custom print function,
3846 it's already printed. Otherwise, print individual
3847 locations, if any. */
3848 if (b
->ops
== NULL
|| b
->ops
->print_one
== NULL
)
3850 /* If breakpoint has a single location that is
3851 disabled, we print it as if it had
3852 several locations, since otherwise it's hard to
3853 represent "breakpoint enabled, location disabled"
3855 Note that while hardware watchpoints have
3856 several locations internally, that's no a property
3859 && !is_hardware_watchpoint (b
)
3860 && (b
->loc
->next
|| !b
->loc
->enabled
)
3861 && !ui_out_is_mi_like_p (uiout
))
3863 struct bp_location
*loc
;
3865 for (loc
= b
->loc
; loc
; loc
= loc
->next
, ++n
)
3866 print_one_breakpoint_location (b
, loc
, n
, last_addr
);
3872 struct captured_breakpoint_query_args
3878 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3880 struct captured_breakpoint_query_args
*args
= data
;
3881 struct breakpoint
*b
;
3882 CORE_ADDR dummy_addr
= 0;
3885 if (args
->bnum
== b
->number
)
3887 print_one_breakpoint (b
, &dummy_addr
);
3895 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3897 struct captured_breakpoint_query_args args
;
3899 /* For the moment we don't trust print_one_breakpoint() to not throw
3901 if (catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3902 error_message
, RETURN_MASK_ALL
) < 0)
3908 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3909 catchpoints, et.al.). */
3912 user_settable_breakpoint (const struct breakpoint
*b
)
3914 return (b
->type
== bp_breakpoint
3915 || b
->type
== bp_catch_load
3916 || b
->type
== bp_catch_unload
3917 || b
->type
== bp_catch_fork
3918 || b
->type
== bp_catch_vfork
3919 || b
->type
== bp_catch_exec
3920 || b
->type
== bp_hardware_breakpoint
3921 || b
->type
== bp_watchpoint
3922 || b
->type
== bp_read_watchpoint
3923 || b
->type
== bp_access_watchpoint
3924 || b
->type
== bp_hardware_watchpoint
);
3927 /* Print information on user settable breakpoint (watchpoint, etc)
3928 number BNUM. If BNUM is -1 print all user settable breakpoints.
3929 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3932 breakpoint_1 (int bnum
, int allflag
)
3934 struct breakpoint
*b
;
3935 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3936 int nr_printable_breakpoints
;
3937 struct cleanup
*bkpttbl_chain
;
3939 /* Compute the number of rows in the table. */
3940 nr_printable_breakpoints
= 0;
3943 || bnum
== b
->number
)
3945 if (allflag
|| user_settable_breakpoint (b
))
3946 nr_printable_breakpoints
++;
3951 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3955 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3958 if (nr_printable_breakpoints
> 0)
3959 annotate_breakpoints_headers ();
3960 if (nr_printable_breakpoints
> 0)
3962 ui_out_table_header (uiout
, 7, ui_left
, "number", "Num"); /* 1 */
3963 if (nr_printable_breakpoints
> 0)
3965 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3966 if (nr_printable_breakpoints
> 0)
3968 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3969 if (nr_printable_breakpoints
> 0)
3971 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3974 if (nr_printable_breakpoints
> 0)
3976 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3977 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3979 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3981 if (nr_printable_breakpoints
> 0)
3983 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3984 ui_out_table_body (uiout
);
3985 if (nr_printable_breakpoints
> 0)
3986 annotate_breakpoints_table ();
3990 || bnum
== b
->number
)
3992 /* We only print out user settable breakpoints unless the
3994 if (allflag
|| user_settable_breakpoint (b
))
3995 print_one_breakpoint (b
, &last_addr
);
3998 do_cleanups (bkpttbl_chain
);
4000 if (nr_printable_breakpoints
== 0)
4003 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
4005 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
4010 /* Compare against (CORE_ADDR)-1 in case some compiler decides
4011 that a comparison of an unsigned with -1 is always false. */
4012 if (last_addr
!= (CORE_ADDR
) -1 && !server_command
)
4013 set_next_address (last_addr
);
4016 /* FIXME? Should this be moved up so that it is only called when
4017 there have been breakpoints? */
4018 annotate_breakpoints_table_end ();
4022 breakpoints_info (char *bnum_exp
, int from_tty
)
4027 bnum
= parse_and_eval_long (bnum_exp
);
4029 breakpoint_1 (bnum
, 0);
4033 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
4038 bnum
= parse_and_eval_long (bnum_exp
);
4040 breakpoint_1 (bnum
, 1);
4044 breakpoint_has_pc (struct breakpoint
*b
, CORE_ADDR pc
, asection
*section
)
4046 struct bp_location
*bl
= b
->loc
;
4047 for (; bl
; bl
= bl
->next
)
4049 if (bl
->address
== pc
4050 && (!overlay_debugging
|| bl
->section
== section
))
4056 /* Print a message describing any breakpoints set at PC. */
4059 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
, int thread
)
4062 struct breakpoint
*b
;
4065 others
+= breakpoint_has_pc (b
, pc
, section
);
4069 printf_filtered (_("Note: breakpoint "));
4070 else /* if (others == ???) */
4071 printf_filtered (_("Note: breakpoints "));
4073 if (breakpoint_has_pc (b
, pc
, section
))
4076 printf_filtered ("%d", b
->number
);
4077 if (b
->thread
== -1 && thread
!= -1)
4078 printf_filtered (" (all threads)");
4079 else if (b
->thread
!= -1)
4080 printf_filtered (" (thread %d)", b
->thread
);
4081 printf_filtered ("%s%s ",
4082 ((b
->enable_state
== bp_disabled
||
4083 b
->enable_state
== bp_call_disabled
)
4085 : b
->enable_state
== bp_permanent
4089 : ((others
== 1) ? " and" : ""));
4091 printf_filtered (_("also set at pc "));
4092 fputs_filtered (paddress (pc
), gdb_stdout
);
4093 printf_filtered (".\n");
4097 /* Set the default place to put a breakpoint
4098 for the `break' command with no arguments. */
4101 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
4104 default_breakpoint_valid
= valid
;
4105 default_breakpoint_address
= addr
;
4106 default_breakpoint_symtab
= symtab
;
4107 default_breakpoint_line
= line
;
4110 /* Return true iff it is meaningful to use the address member of
4111 BPT. For some breakpoint types, the address member is irrelevant
4112 and it makes no sense to attempt to compare it to other addresses
4113 (or use it for any other purpose either).
4115 More specifically, each of the following breakpoint types will always
4116 have a zero valued address and we don't want check_duplicates() to mark
4117 breakpoints of any of these types to be a duplicate of an actual
4118 breakpoint at address zero:
4121 bp_hardware_watchpoint
4123 bp_access_watchpoint
4129 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
4131 enum bptype type
= bpt
->type
;
4133 return (type
!= bp_watchpoint
4134 && type
!= bp_hardware_watchpoint
4135 && type
!= bp_read_watchpoint
4136 && type
!= bp_access_watchpoint
4137 && type
!= bp_catch_exec
4138 && type
!= bp_catch_fork
4139 && type
!= bp_catch_vfork
);
4142 /* Rescan breakpoints at the same address and section as BPT,
4143 marking the first one as "first" and any others as "duplicates".
4144 This is so that the bpt instruction is only inserted once.
4145 If we have a permanent breakpoint at the same place as BPT, make
4146 that one the official one, and the rest as duplicates. */
4149 check_duplicates_for (CORE_ADDR address
, asection
*section
)
4151 struct bp_location
*b
;
4153 struct bp_location
*perm_bp
= 0;
4155 ALL_BP_LOCATIONS (b
)
4156 if (b
->owner
->enable_state
!= bp_disabled
4157 && b
->owner
->enable_state
!= bp_call_disabled
4159 && !b
->shlib_disabled
4160 && b
->address
== address
/* address / overlay match */
4161 && (!overlay_debugging
|| b
->section
== section
)
4162 && breakpoint_address_is_meaningful (b
->owner
))
4164 /* Have we found a permanent breakpoint? */
4165 if (b
->owner
->enable_state
== bp_permanent
)
4172 b
->duplicate
= count
> 1;
4175 /* If we found a permanent breakpoint at this address, go over the
4176 list again and declare all the other breakpoints there to be the
4180 perm_bp
->duplicate
= 0;
4182 /* Permanent breakpoint should always be inserted. */
4183 if (! perm_bp
->inserted
)
4184 internal_error (__FILE__
, __LINE__
,
4185 _("allegedly permanent breakpoint is not "
4186 "actually inserted"));
4188 ALL_BP_LOCATIONS (b
)
4191 if (b
->owner
->enable_state
!= bp_disabled
4192 && b
->owner
->enable_state
!= bp_call_disabled
4193 && b
->enabled
&& !b
->shlib_disabled
4194 && b
->address
== address
/* address / overlay match */
4195 && (!overlay_debugging
|| b
->section
== section
)
4196 && breakpoint_address_is_meaningful (b
->owner
))
4199 internal_error (__FILE__
, __LINE__
,
4200 _("another breakpoint was inserted on top of "
4201 "a permanent breakpoint"));
4210 check_duplicates (struct breakpoint
*bpt
)
4212 struct bp_location
*bl
= bpt
->loc
;
4214 if (! breakpoint_address_is_meaningful (bpt
))
4217 for (; bl
; bl
= bl
->next
)
4218 check_duplicates_for (bl
->address
, bl
->section
);
4222 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
4223 int bnum
, int have_bnum
)
4228 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
4229 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
4231 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
4232 bnum
, astr1
, astr2
);
4234 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
4237 /* Adjust a breakpoint's address to account for architectural constraints
4238 on breakpoint placement. Return the adjusted address. Note: Very
4239 few targets require this kind of adjustment. For most targets,
4240 this function is simply the identity function. */
4243 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
4245 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
4247 /* Very few targets need any kind of breakpoint adjustment. */
4250 else if (bptype
== bp_watchpoint
4251 || bptype
== bp_hardware_watchpoint
4252 || bptype
== bp_read_watchpoint
4253 || bptype
== bp_access_watchpoint
4254 || bptype
== bp_catch_fork
4255 || bptype
== bp_catch_vfork
4256 || bptype
== bp_catch_exec
)
4258 /* Watchpoints and the various bp_catch_* eventpoints should not
4259 have their addresses modified. */
4264 CORE_ADDR adjusted_bpaddr
;
4266 /* Some targets have architectural constraints on the placement
4267 of breakpoint instructions. Obtain the adjusted address. */
4268 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
4271 /* An adjusted breakpoint address can significantly alter
4272 a user's expectations. Print a warning if an adjustment
4274 if (adjusted_bpaddr
!= bpaddr
)
4275 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
4277 return adjusted_bpaddr
;
4281 /* Allocate a struct bp_location. */
4283 static struct bp_location
*
4284 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4286 struct bp_location
*loc
, *loc_p
;
4288 loc
= xmalloc (sizeof (struct bp_location
));
4289 memset (loc
, 0, sizeof (*loc
));
4293 loc
->shlib_disabled
= 0;
4302 case bp_longjmp_resume
:
4303 case bp_step_resume
:
4304 case bp_watchpoint_scope
:
4306 case bp_shlib_event
:
4307 case bp_thread_event
:
4308 case bp_overlay_event
:
4310 case bp_catch_unload
:
4311 loc
->loc_type
= bp_loc_software_breakpoint
;
4313 case bp_hardware_breakpoint
:
4314 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4316 case bp_hardware_watchpoint
:
4317 case bp_read_watchpoint
:
4318 case bp_access_watchpoint
:
4319 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4323 case bp_catch_vfork
:
4325 loc
->loc_type
= bp_loc_other
;
4328 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4334 static void free_bp_location (struct bp_location
*loc
)
4339 if (loc
->function_name
)
4340 xfree (loc
->function_name
);
4345 /* Helper to set_raw_breakpoint below. Creates a breakpoint
4346 that has type BPTYPE and has no locations as yet. */
4348 static struct breakpoint
*
4349 set_raw_breakpoint_without_location (enum bptype bptype
)
4351 struct breakpoint
*b
, *b1
;
4353 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4354 memset (b
, 0, sizeof (*b
));
4357 b
->language
= current_language
->la_language
;
4358 b
->input_radix
= input_radix
;
4360 b
->enable_state
= bp_enabled
;
4363 b
->ignore_count
= 0;
4365 b
->frame_id
= null_frame_id
;
4366 b
->dll_pathname
= NULL
;
4367 b
->triggered_dll_pathname
= NULL
;
4368 b
->forked_inferior_pid
= null_ptid
;
4369 b
->exec_pathname
= NULL
;
4371 b
->condition_not_parsed
= 0;
4373 /* Add this breakpoint to the end of the chain
4374 so that a list of breakpoints will come out in order
4375 of increasing numbers. */
4377 b1
= breakpoint_chain
;
4379 breakpoint_chain
= b
;
4389 /* Initialize loc->function_name. */
4391 set_breakpoint_location_function (struct bp_location
*loc
)
4393 if (loc
->owner
->type
== bp_breakpoint
4394 || loc
->owner
->type
== bp_hardware_breakpoint
)
4396 find_pc_partial_function (loc
->address
, &(loc
->function_name
),
4398 if (loc
->function_name
)
4399 loc
->function_name
= xstrdup (loc
->function_name
);
4403 /* set_raw_breakpoint is a low level routine for allocating and
4404 partially initializing a breakpoint of type BPTYPE. The newly
4405 created breakpoint's address, section, source file name, and line
4406 number are provided by SAL. The newly created and partially
4407 initialized breakpoint is added to the breakpoint chain and
4408 is also returned as the value of this function.
4410 It is expected that the caller will complete the initialization of
4411 the newly created breakpoint struct as well as output any status
4412 information regarding the creation of a new breakpoint. In
4413 particular, set_raw_breakpoint does NOT set the breakpoint
4414 number! Care should be taken to not allow an error to occur
4415 prior to completing the initialization of the breakpoint. If this
4416 should happen, a bogus breakpoint will be left on the chain. */
4419 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4421 struct breakpoint
*b
= set_raw_breakpoint_without_location (bptype
);
4422 CORE_ADDR adjusted_address
;
4424 /* Adjust the breakpoint's address prior to allocating a location.
4425 Once we call allocate_bp_location(), that mostly uninitialized
4426 location will be placed on the location chain. Adjustment of the
4427 breakpoint may cause target_read_memory() to be called and we do
4428 not want its scan of the location chain to find a breakpoint and
4429 location that's only been partially initialized. */
4430 adjusted_address
= adjust_breakpoint_address (sal
.pc
, bptype
);
4432 b
->loc
= allocate_bp_location (b
, bptype
);
4433 b
->loc
->requested_address
= sal
.pc
;
4434 b
->loc
->address
= adjusted_address
;
4436 if (sal
.symtab
== NULL
)
4437 b
->source_file
= NULL
;
4439 b
->source_file
= savestring (sal
.symtab
->filename
,
4440 strlen (sal
.symtab
->filename
));
4441 b
->loc
->section
= sal
.section
;
4442 b
->line_number
= sal
.line
;
4444 set_breakpoint_location_function (b
->loc
);
4446 breakpoints_changed ();
4452 /* Note that the breakpoint object B describes a permanent breakpoint
4453 instruction, hard-wired into the inferior's code. */
4455 make_breakpoint_permanent (struct breakpoint
*b
)
4457 struct bp_location
*bl
;
4458 b
->enable_state
= bp_permanent
;
4460 /* By definition, permanent breakpoints are already present in the code.
4461 Mark all locations as inserted. For now, make_breakpoint_permanent
4462 is called in just one place, so it's hard to say if it's reasonable
4463 to have permanent breakpoint with multiple locations or not,
4464 but it's easy to implmement. */
4465 for (bl
= b
->loc
; bl
; bl
= bl
->next
)
4469 static struct breakpoint
*
4470 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4472 static int internal_breakpoint_number
= -1;
4473 struct symtab_and_line sal
;
4474 struct breakpoint
*b
;
4476 init_sal (&sal
); /* initialize to zeroes */
4479 sal
.section
= find_pc_overlay (sal
.pc
);
4481 b
= set_raw_breakpoint (sal
, type
);
4482 b
->number
= internal_breakpoint_number
--;
4483 b
->disposition
= disp_donttouch
;
4490 create_longjmp_breakpoint (char *func_name
)
4492 struct minimal_symbol
*m
;
4494 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4496 set_momentary_breakpoint_at_pc (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4497 update_global_location_list (1);
4500 /* Call this routine when stepping and nexting to enable a breakpoint
4501 if we do a longjmp(). When we hit that breakpoint, call
4502 set_longjmp_resume_breakpoint() to figure out where we are going. */
4505 set_longjmp_breakpoint (void)
4507 if (gdbarch_get_longjmp_target_p (current_gdbarch
))
4509 create_longjmp_breakpoint ("longjmp");
4510 create_longjmp_breakpoint ("_longjmp");
4511 create_longjmp_breakpoint ("siglongjmp");
4512 create_longjmp_breakpoint ("_siglongjmp");
4516 /* Delete all longjmp breakpoints from THREAD. */
4518 delete_longjmp_breakpoint (int thread
)
4520 struct breakpoint
*b
, *temp
;
4522 ALL_BREAKPOINTS_SAFE (b
, temp
)
4523 if (b
->type
== bp_longjmp
)
4525 if (b
->thread
== thread
)
4526 delete_breakpoint (b
);
4531 create_overlay_event_breakpoint (char *func_name
)
4533 struct breakpoint
*b
;
4534 struct minimal_symbol
*m
;
4536 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4539 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4541 b
->addr_string
= xstrdup (func_name
);
4543 if (overlay_debugging
== ovly_auto
)
4545 b
->enable_state
= bp_enabled
;
4546 overlay_events_enabled
= 1;
4550 b
->enable_state
= bp_disabled
;
4551 overlay_events_enabled
= 0;
4553 update_global_location_list (1);
4557 enable_overlay_breakpoints (void)
4559 struct breakpoint
*b
;
4562 if (b
->type
== bp_overlay_event
)
4564 b
->enable_state
= bp_enabled
;
4565 update_global_location_list (1);
4566 overlay_events_enabled
= 1;
4571 disable_overlay_breakpoints (void)
4573 struct breakpoint
*b
;
4576 if (b
->type
== bp_overlay_event
)
4578 b
->enable_state
= bp_disabled
;
4579 update_global_location_list (0);
4580 overlay_events_enabled
= 0;
4585 create_thread_event_breakpoint (CORE_ADDR address
)
4587 struct breakpoint
*b
;
4589 b
= create_internal_breakpoint (address
, bp_thread_event
);
4591 b
->enable_state
= bp_enabled
;
4592 /* addr_string has to be used or breakpoint_re_set will delete me. */
4593 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4595 update_global_location_list_nothrow (1);
4601 remove_thread_event_breakpoints (void)
4603 struct breakpoint
*b
, *temp
;
4605 ALL_BREAKPOINTS_SAFE (b
, temp
)
4606 if (b
->type
== bp_thread_event
)
4607 delete_breakpoint (b
);
4610 struct captured_parse_breakpoint_args
4613 struct symtabs_and_lines
*sals_p
;
4614 char ***addr_string_p
;
4618 struct lang_and_radix
4626 remove_solib_event_breakpoints (void)
4628 struct breakpoint
*b
, *temp
;
4630 ALL_BREAKPOINTS_SAFE (b
, temp
)
4631 if (b
->type
== bp_shlib_event
)
4632 delete_breakpoint (b
);
4636 create_solib_event_breakpoint (CORE_ADDR address
)
4638 struct breakpoint
*b
;
4640 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4641 update_global_location_list_nothrow (1);
4645 /* Disable any breakpoints that are on code in shared libraries. Only
4646 apply to enabled breakpoints, disabled ones can just stay disabled. */
4649 disable_breakpoints_in_shlibs (void)
4651 struct bp_location
*loc
;
4652 int disabled_shlib_breaks
= 0;
4654 ALL_BP_LOCATIONS (loc
)
4656 struct breakpoint
*b
= loc
->owner
;
4657 /* We apply the check to all breakpoints, including disabled
4658 for those with loc->duplicate set. This is so that when breakpoint
4659 becomes enabled, or the duplicate is removed, gdb will try to insert
4660 all breakpoints. If we don't set shlib_disabled here, we'll try
4661 to insert those breakpoints and fail. */
4662 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4663 && !loc
->shlib_disabled
4665 && PC_SOLIB (loc
->address
)
4667 && solib_address (loc
->address
)
4671 loc
->shlib_disabled
= 1;
4676 /* Disable any breakpoints that are in in an unloaded shared library. Only
4677 apply to enabled breakpoints, disabled ones can just stay disabled. */
4680 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4682 struct bp_location
*loc
;
4683 int disabled_shlib_breaks
= 0;
4685 ALL_BP_LOCATIONS (loc
)
4687 struct breakpoint
*b
= loc
->owner
;
4688 if ((loc
->loc_type
== bp_loc_hardware_breakpoint
4689 || loc
->loc_type
== bp_loc_software_breakpoint
)
4690 && !loc
->shlib_disabled
)
4693 char *so_name
= PC_SOLIB (loc
->address
);
4695 char *so_name
= solib_address (loc
->address
);
4697 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4699 loc
->shlib_disabled
= 1;
4700 /* At this point, we cannot rely on remove_breakpoint
4701 succeeding so we must mark the breakpoint as not inserted
4702 to prevent future errors occurring in remove_breakpoints. */
4704 if (!disabled_shlib_breaks
)
4706 target_terminal_ours_for_output ();
4707 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4710 disabled_shlib_breaks
= 1;
4717 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4718 enum bptype bp_kind
)
4720 struct symtab_and_line sal
;
4721 struct breakpoint
*b
;
4722 int thread
= -1; /* All threads. */
4729 b
= set_raw_breakpoint (sal
, bp_kind
);
4730 set_breakpoint_count (breakpoint_count
+ 1);
4731 b
->number
= breakpoint_count
;
4732 b
->cond_string
= (cond_string
== NULL
) ?
4733 NULL
: savestring (cond_string
, strlen (cond_string
));
4735 b
->addr_string
= NULL
;
4736 b
->enable_state
= bp_enabled
;
4737 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4738 b
->forked_inferior_pid
= null_ptid
;
4739 update_global_location_list (1);
4746 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4748 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4752 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4754 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4758 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4760 struct symtab_and_line sal
;
4761 struct breakpoint
*b
;
4762 int thread
= -1; /* All threads. */
4769 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4770 set_breakpoint_count (breakpoint_count
+ 1);
4771 b
->number
= breakpoint_count
;
4772 b
->cond_string
= (cond_string
== NULL
) ?
4773 NULL
: savestring (cond_string
, strlen (cond_string
));
4775 b
->addr_string
= NULL
;
4776 b
->enable_state
= bp_enabled
;
4777 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4778 update_global_location_list (1);
4784 hw_breakpoint_used_count (void)
4786 struct breakpoint
*b
;
4791 if (b
->type
== bp_hardware_breakpoint
&& breakpoint_enabled (b
))
4799 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4801 struct breakpoint
*b
;
4804 *other_type_used
= 0;
4807 if (breakpoint_enabled (b
))
4809 if (b
->type
== type
)
4811 else if ((b
->type
== bp_hardware_watchpoint
||
4812 b
->type
== bp_read_watchpoint
||
4813 b
->type
== bp_access_watchpoint
))
4814 *other_type_used
= 1;
4821 disable_watchpoints_before_interactive_call_start (void)
4823 struct breakpoint
*b
;
4827 if (((b
->type
== bp_watchpoint
)
4828 || (b
->type
== bp_hardware_watchpoint
)
4829 || (b
->type
== bp_read_watchpoint
)
4830 || (b
->type
== bp_access_watchpoint
))
4831 && breakpoint_enabled (b
))
4833 b
->enable_state
= bp_call_disabled
;
4834 update_global_location_list (0);
4840 enable_watchpoints_after_interactive_call_stop (void)
4842 struct breakpoint
*b
;
4846 if (((b
->type
== bp_watchpoint
)
4847 || (b
->type
== bp_hardware_watchpoint
)
4848 || (b
->type
== bp_read_watchpoint
)
4849 || (b
->type
== bp_access_watchpoint
))
4850 && (b
->enable_state
== bp_call_disabled
))
4852 b
->enable_state
= bp_enabled
;
4853 update_global_location_list (1);
4859 /* Set a breakpoint that will evaporate an end of command
4860 at address specified by SAL.
4861 Restrict it to frame FRAME if FRAME is nonzero. */
4864 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4867 struct breakpoint
*b
;
4868 b
= set_raw_breakpoint (sal
, type
);
4869 b
->enable_state
= bp_enabled
;
4870 b
->disposition
= disp_donttouch
;
4871 b
->frame_id
= frame_id
;
4873 /* If we're debugging a multi-threaded program, then we
4874 want momentary breakpoints to be active in only a
4875 single thread of control. */
4876 if (in_thread_list (inferior_ptid
))
4877 b
->thread
= pid_to_thread_id (inferior_ptid
);
4879 update_global_location_list_nothrow (1);
4885 set_momentary_breakpoint_at_pc (CORE_ADDR pc
, enum bptype type
)
4887 struct symtab_and_line sal
;
4889 sal
= find_pc_line (pc
, 0);
4891 sal
.section
= find_pc_overlay (pc
);
4892 sal
.explicit_pc
= 1;
4894 return set_momentary_breakpoint (sal
, null_frame_id
, type
);
4898 /* Tell the user we have just set a breakpoint B. */
4901 mention (struct breakpoint
*b
)
4904 struct cleanup
*old_chain
, *ui_out_chain
;
4905 struct ui_stream
*stb
;
4907 stb
= ui_out_stream_new (uiout
);
4908 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4910 /* FIXME: This is misplaced; mention() is called by things (like
4911 hitting a watchpoint) other than breakpoint creation. It should
4912 be possible to clean this up and at the same time replace the
4913 random calls to breakpoint_changed with this hook. */
4914 observer_notify_breakpoint_created (b
->number
);
4916 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4917 b
->ops
->print_mention (b
);
4922 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4925 ui_out_text (uiout
, "Watchpoint ");
4926 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4927 ui_out_field_int (uiout
, "number", b
->number
);
4928 ui_out_text (uiout
, ": ");
4929 print_expression (b
->exp
, stb
->stream
);
4930 ui_out_field_stream (uiout
, "exp", stb
);
4931 do_cleanups (ui_out_chain
);
4933 case bp_hardware_watchpoint
:
4934 ui_out_text (uiout
, "Hardware watchpoint ");
4935 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4936 ui_out_field_int (uiout
, "number", b
->number
);
4937 ui_out_text (uiout
, ": ");
4938 print_expression (b
->exp
, stb
->stream
);
4939 ui_out_field_stream (uiout
, "exp", stb
);
4940 do_cleanups (ui_out_chain
);
4942 case bp_read_watchpoint
:
4943 ui_out_text (uiout
, "Hardware read watchpoint ");
4944 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4945 ui_out_field_int (uiout
, "number", b
->number
);
4946 ui_out_text (uiout
, ": ");
4947 print_expression (b
->exp
, stb
->stream
);
4948 ui_out_field_stream (uiout
, "exp", stb
);
4949 do_cleanups (ui_out_chain
);
4951 case bp_access_watchpoint
:
4952 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4953 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4954 ui_out_field_int (uiout
, "number", b
->number
);
4955 ui_out_text (uiout
, ": ");
4956 print_expression (b
->exp
, stb
->stream
);
4957 ui_out_field_stream (uiout
, "exp", stb
);
4958 do_cleanups (ui_out_chain
);
4961 if (ui_out_is_mi_like_p (uiout
))
4966 if (b
->disposition
== disp_del
)
4967 printf_filtered (_("Temporary breakpoint"));
4969 printf_filtered (_("Breakpoint"));
4970 printf_filtered (_(" %d"), b
->number
);
4973 case bp_hardware_breakpoint
:
4974 if (ui_out_is_mi_like_p (uiout
))
4979 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4983 case bp_catch_unload
:
4984 printf_filtered (_("Catchpoint %d (%s %s)"),
4986 (b
->type
== bp_catch_load
) ? "load" : "unload",
4987 (b
->dll_pathname
!= NULL
) ?
4988 b
->dll_pathname
: "<any library>");
4991 case bp_catch_vfork
:
4992 printf_filtered (_("Catchpoint %d (%s)"),
4994 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4997 printf_filtered (_("Catchpoint %d (exec)"),
5004 case bp_longjmp_resume
:
5005 case bp_step_resume
:
5007 case bp_watchpoint_scope
:
5008 case bp_shlib_event
:
5009 case bp_thread_event
:
5010 case bp_overlay_event
:
5016 /* i18n: cagney/2005-02-11: Below needs to be merged into a
5020 printf_filtered (_(" (%s) pending."), b
->addr_string
);
5024 if (addressprint
|| b
->source_file
== NULL
)
5026 printf_filtered (" at ");
5027 fputs_filtered (paddress (b
->loc
->address
), gdb_stdout
);
5030 printf_filtered (": file %s, line %d.",
5031 b
->source_file
, b
->line_number
);
5035 struct bp_location
*loc
= b
->loc
;
5037 for (; loc
; loc
= loc
->next
)
5039 printf_filtered (" (%d locations)", n
);
5044 do_cleanups (old_chain
);
5045 if (ui_out_is_mi_like_p (uiout
))
5047 printf_filtered ("\n");
5051 static struct bp_location
*
5052 add_location_to_breakpoint (struct breakpoint
*b
, enum bptype bptype
,
5053 const struct symtab_and_line
*sal
)
5055 struct bp_location
*loc
, **tmp
;
5057 loc
= allocate_bp_location (b
, bptype
);
5058 for (tmp
= &(b
->loc
); *tmp
!= NULL
; tmp
= &((*tmp
)->next
))
5061 loc
->requested_address
= sal
->pc
;
5062 loc
->address
= adjust_breakpoint_address (loc
->requested_address
,
5064 loc
->section
= sal
->section
;
5066 set_breakpoint_location_function (loc
);
5070 /* Create a breakpoint with SAL as location. Use ADDR_STRING
5071 as textual description of the location, and COND_STRING
5072 as condition expression. */
5075 create_breakpoint (struct symtabs_and_lines sals
, char *addr_string
,
5077 enum bptype type
, enum bpdisp disposition
,
5078 int thread
, int ignore_count
,
5079 struct breakpoint_ops
*ops
, int from_tty
)
5081 struct breakpoint
*b
= NULL
;
5084 if (type
== bp_hardware_breakpoint
)
5086 int i
= hw_breakpoint_used_count ();
5087 int target_resources_ok
=
5088 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
5090 if (target_resources_ok
== 0)
5091 error (_("No hardware breakpoint support in the target."));
5092 else if (target_resources_ok
< 0)
5093 error (_("Hardware breakpoints used exceeds limit."));
5096 for (i
= 0; i
< sals
.nelts
; ++i
)
5098 struct symtab_and_line sal
= sals
.sals
[i
];
5099 struct bp_location
*loc
;
5102 describe_other_breakpoints (sal
.pc
, sal
.section
, thread
);
5106 b
= set_raw_breakpoint (sal
, type
);
5107 set_breakpoint_count (breakpoint_count
+ 1);
5108 b
->number
= breakpoint_count
;
5111 b
->cond_string
= cond_string
;
5112 b
->ignore_count
= ignore_count
;
5113 b
->enable_state
= bp_enabled
;
5114 b
->disposition
= disposition
;
5120 loc
= add_location_to_breakpoint (b
, type
, &sal
);
5125 char *arg
= b
->cond_string
;
5126 loc
->cond
= parse_exp_1 (&arg
, block_for_pc (loc
->address
), 0);
5128 error (_("Garbage %s follows condition"), arg
);
5133 b
->addr_string
= addr_string
;
5135 /* addr_string has to be used or breakpoint_re_set will delete
5137 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
5143 /* Remove element at INDEX_TO_REMOVE from SAL, shifting other
5144 elements to fill the void space. */
5145 static void remove_sal (struct symtabs_and_lines
*sal
, int index_to_remove
)
5147 int i
= index_to_remove
+1;
5148 int last_index
= sal
->nelts
-1;
5150 for (;i
<= last_index
; ++i
)
5151 sal
->sals
[i
-1] = sal
->sals
[i
];
5156 /* If appropriate, obtains all sals that correspond
5157 to the same file and line as SAL. This is done
5158 only if SAL does not have explicit PC and has
5159 line and file information. If we got just a single
5160 expanded sal, return the original.
5162 Otherwise, if SAL.explicit_line is not set, filter out
5163 all sals for which the name of enclosing function
5164 is different from SAL. This makes sure that if we have
5165 breakpoint originally set in template instantiation, say
5166 foo<int>(), we won't expand SAL to locations at the same
5167 line in all existing instantiations of 'foo'.
5170 struct symtabs_and_lines
5171 expand_line_sal_maybe (struct symtab_and_line sal
)
5173 struct symtabs_and_lines expanded
;
5174 CORE_ADDR original_pc
= sal
.pc
;
5175 char *original_function
= NULL
;
5179 /* If we have explicit pc, don't expand.
5180 If we have no line number, we can't expand. */
5181 if (sal
.explicit_pc
|| sal
.line
== 0 || sal
.symtab
== NULL
)
5184 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5185 expanded
.sals
[0] = sal
;
5190 find_pc_partial_function (original_pc
, &original_function
, NULL
, NULL
);
5192 expanded
= expand_line_sal (sal
);
5193 if (expanded
.nelts
== 1)
5195 /* We had one sal, we got one sal. Without futher
5196 processing, just return the original sal. */
5197 xfree (expanded
.sals
);
5199 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5200 sal
.pc
= original_pc
;
5201 expanded
.sals
[0] = sal
;
5205 if (!sal
.explicit_line
)
5207 CORE_ADDR func_addr
, func_end
;
5208 for (i
= 0; i
< expanded
.nelts
; ++i
)
5210 CORE_ADDR pc
= expanded
.sals
[i
].pc
;
5211 char *this_function
;
5212 if (find_pc_partial_function (pc
, &this_function
,
5213 &func_addr
, &func_end
))
5215 if (this_function
&&
5216 strcmp (this_function
, original_function
) != 0)
5218 remove_sal (&expanded
, i
);
5221 else if (func_addr
== pc
)
5223 /* We're at beginning of a function, and should
5225 struct symbol
*sym
= find_pc_function (pc
);
5227 expanded
.sals
[i
] = find_function_start_sal (sym
, 1);
5230 = gdbarch_skip_prologue (current_gdbarch
, pc
);
5237 if (expanded
.nelts
<= 1)
5239 /* This is un ugly workaround. If we get zero
5240 expanded sals then something is really wrong.
5241 Fix that by returnign the original sal. */
5242 xfree (expanded
.sals
);
5244 expanded
.sals
= xmalloc (sizeof (struct symtab_and_line
));
5245 sal
.pc
= original_pc
;
5246 expanded
.sals
[0] = sal
;
5253 for (i
= 0; i
< expanded
.nelts
; ++i
)
5254 if (expanded
.sals
[i
].pc
== original_pc
)
5265 /* Add SALS.nelts breakpoints to the breakpoint table. For each
5266 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i]
5267 value. COND_STRING, if not NULL, specified the condition to be
5268 used for all breakpoints. Essentially the only case where
5269 SALS.nelts is not 1 is when we set a breakpoint on an overloaded
5270 function. In that case, it's still not possible to specify
5271 separate conditions for different overloaded functions, so
5272 we take just a single condition string.
5274 NOTE: If the function succeeds, the caller is expected to cleanup
5275 the arrays ADDR_STRING, COND_STRING, and SALS (but not the
5276 array contents). If the function fails (error() is called), the
5277 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
5278 COND and SALS arrays and each of those arrays contents. */
5281 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
5283 enum bptype type
, enum bpdisp disposition
,
5284 int thread
, int ignore_count
,
5285 struct breakpoint_ops
*ops
, int from_tty
)
5288 for (i
= 0; i
< sals
.nelts
; ++i
)
5290 struct symtabs_and_lines expanded
=
5291 expand_line_sal_maybe (sals
.sals
[i
]);
5293 create_breakpoint (expanded
, addr_string
[i
],
5294 cond_string
, type
, disposition
,
5295 thread
, ignore_count
, ops
, from_tty
);
5298 update_global_location_list (1);
5301 /* Parse ARG which is assumed to be a SAL specification possibly
5302 followed by conditionals. On return, SALS contains an array of SAL
5303 addresses found. ADDR_STRING contains a vector of (canonical)
5304 address strings. ARG points to the end of the SAL. */
5307 parse_breakpoint_sals (char **address
,
5308 struct symtabs_and_lines
*sals
,
5309 char ***addr_string
,
5312 char *addr_start
= *address
;
5313 *addr_string
= NULL
;
5314 /* If no arg given, or if first arg is 'if ', use the default
5316 if ((*address
) == NULL
5317 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5319 if (default_breakpoint_valid
)
5321 struct symtab_and_line sal
;
5322 init_sal (&sal
); /* initialize to zeroes */
5323 sals
->sals
= (struct symtab_and_line
*)
5324 xmalloc (sizeof (struct symtab_and_line
));
5325 sal
.pc
= default_breakpoint_address
;
5326 sal
.line
= default_breakpoint_line
;
5327 sal
.symtab
= default_breakpoint_symtab
;
5328 sal
.section
= find_pc_overlay (sal
.pc
);
5329 sals
->sals
[0] = sal
;
5333 error (_("No default breakpoint address now."));
5337 /* Force almost all breakpoints to be in terms of the
5338 current_source_symtab (which is decode_line_1's default). This
5339 should produce the results we want almost all of the time while
5340 leaving default_breakpoint_* alone.
5341 ObjC: However, don't match an Objective-C method name which
5342 may have a '+' or '-' succeeded by a '[' */
5344 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5346 if (default_breakpoint_valid
5348 || ((strchr ("+-", (*address
)[0]) != NULL
)
5349 && ((*address
)[1] != '['))))
5350 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5351 default_breakpoint_line
, addr_string
,
5354 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5355 addr_string
, not_found_ptr
);
5357 /* For any SAL that didn't have a canonical string, fill one in. */
5358 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5359 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5360 if (addr_start
!= (*address
))
5363 for (i
= 0; i
< sals
->nelts
; i
++)
5365 /* Add the string if not present. */
5366 if ((*addr_string
)[i
] == NULL
)
5367 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5373 /* Convert each SAL into a real PC. Verify that the PC can be
5374 inserted as a breakpoint. If it can't throw an error. */
5377 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5381 for (i
= 0; i
< sals
->nelts
; i
++)
5382 resolve_sal_pc (&sals
->sals
[i
]);
5386 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5388 struct captured_parse_breakpoint_args
*args
= data
;
5390 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5391 args
->not_found_ptr
);
5394 /* Given TOK, a string specification of condition and thread, as
5395 accepted by the 'break' command, extract the condition
5396 string and thread number and set *COND_STRING and *THREAD.
5397 PC identifies the context at which the condition should be parsed.
5398 If no condition is found, *COND_STRING is set to NULL.
5399 If no thread is found, *THREAD is set to -1. */
5401 find_condition_and_thread (char *tok
, CORE_ADDR pc
,
5402 char **cond_string
, int *thread
)
5404 *cond_string
= NULL
;
5410 char *cond_start
= NULL
;
5411 char *cond_end
= NULL
;
5412 while (*tok
== ' ' || *tok
== '\t')
5417 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5420 toklen
= end_tok
- tok
;
5422 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5424 tok
= cond_start
= end_tok
+ 1;
5425 parse_exp_1 (&tok
, block_for_pc (pc
), 0);
5427 *cond_string
= savestring (cond_start
,
5428 cond_end
- cond_start
);
5430 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5436 *thread
= strtol (tok
, &tok
, 0);
5438 error (_("Junk after thread keyword."));
5439 if (!valid_thread_id (*thread
))
5440 error (_("Unknown thread %d."), *thread
);
5443 error (_("Junk at end of arguments."));
5447 /* Set a breakpoint. This function is shared between
5448 CLI and MI functions for setting a breakpoint.
5449 This function has two major modes of operations,
5450 selected by the PARSE_CONDITION_AND_THREAD parameter.
5451 If non-zero, the function will parse arg, extracting
5452 breakpoint location, address and thread. Otherwise,
5453 ARG is just the location of breakpoint, with condition
5454 and thread specified by the COND_STRING and THREAD
5458 break_command_really (char *arg
, char *cond_string
, int thread
,
5459 int parse_condition_and_thread
,
5460 int tempflag
, int hardwareflag
,
5462 enum auto_boolean pending_break_support
,
5463 struct breakpoint_ops
*ops
,
5466 struct gdb_exception e
;
5467 struct symtabs_and_lines sals
;
5468 struct symtab_and_line pending_sal
;
5471 char *addr_start
= arg
;
5473 struct cleanup
*old_chain
;
5474 struct cleanup
*breakpoint_chain
= NULL
;
5475 struct captured_parse_breakpoint_args parse_args
;
5484 parse_args
.arg_p
= &arg
;
5485 parse_args
.sals_p
= &sals
;
5486 parse_args
.addr_string_p
= &addr_string
;
5487 parse_args
.not_found_ptr
= ¬_found
;
5489 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5490 &parse_args
, RETURN_MASK_ALL
);
5492 /* If caller is interested in rc value from parse, set value. */
5496 throw_exception (e
);
5500 case NOT_FOUND_ERROR
:
5502 /* If pending breakpoint support is turned off, throw
5505 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5506 throw_exception (e
);
5508 exception_print (gdb_stderr
, e
);
5510 /* If pending breakpoint support is auto query and the user
5511 selects no, then simply return the error code. */
5512 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5513 !nquery ("Make breakpoint pending on future shared library load? "))
5516 /* At this point, either the user was queried about setting
5517 a pending breakpoint and selected yes, or pending
5518 breakpoint behavior is on and thus a pending breakpoint
5519 is defaulted on behalf of the user. */
5520 copy_arg
= xstrdup (addr_start
);
5521 addr_string
= ©_arg
;
5523 sals
.sals
= &pending_sal
;
5528 throw_exception (e
);
5535 /* Create a chain of things that always need to be cleaned up. */
5536 old_chain
= make_cleanup (null_cleanup
, 0);
5540 /* Make sure that all storage allocated to SALS gets freed. */
5541 make_cleanup (xfree
, sals
.sals
);
5543 /* Cleanup the addr_string array but not its contents. */
5544 make_cleanup (xfree
, addr_string
);
5547 /* ----------------------------- SNIP -----------------------------
5548 Anything added to the cleanup chain beyond this point is assumed
5549 to be part of a breakpoint. If the breakpoint create succeeds
5550 then the memory is not reclaimed. */
5551 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5553 /* Mark the contents of the addr_string for cleanup. These go on
5554 the breakpoint_chain and only occure if the breakpoint create
5556 for (i
= 0; i
< sals
.nelts
; i
++)
5558 if (addr_string
[i
] != NULL
)
5559 make_cleanup (xfree
, addr_string
[i
]);
5562 /* Resolve all line numbers to PC's and verify that the addresses
5563 are ok for the target. */
5565 breakpoint_sals_to_pc (&sals
, addr_start
);
5567 /* Verify that condition can be parsed, before setting any
5568 breakpoints. Allocate a separate condition expression for each
5572 if (parse_condition_and_thread
)
5574 /* Here we only parse 'arg' to separate condition
5575 from thread number, so parsing in context of first
5576 sal is OK. When setting the breakpoint we'll
5577 re-parse it in context of each sal. */
5580 find_condition_and_thread (arg
, sals
.sals
[0].pc
, &cond_string
, &thread
);
5582 make_cleanup (xfree
, cond_string
);
5586 /* Create a private copy of condition string. */
5589 cond_string
= xstrdup (cond_string
);
5590 make_cleanup (xfree
, cond_string
);
5593 create_breakpoints (sals
, addr_string
, cond_string
,
5594 hardwareflag
? bp_hardware_breakpoint
5596 tempflag
? disp_del
: disp_donttouch
,
5597 thread
, ignore_count
, ops
, from_tty
);
5601 struct symtab_and_line sal
= {0};
5602 struct breakpoint
*b
;
5604 make_cleanup (xfree
, copy_arg
);
5606 b
= set_raw_breakpoint_without_location (hardwareflag
5607 ? bp_hardware_breakpoint
5609 set_breakpoint_count (breakpoint_count
+ 1);
5610 b
->number
= breakpoint_count
;
5612 b
->addr_string
= addr_string
[0];
5613 b
->cond_string
= NULL
;
5614 b
->ignore_count
= ignore_count
;
5615 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5616 b
->condition_not_parsed
= 1;
5619 update_global_location_list (1);
5624 warning (_("Multiple breakpoints were set.\n"
5625 "Use the \"delete\" command to delete unwanted breakpoints."));
5626 /* That's it. Discard the cleanups for data inserted into the
5628 discard_cleanups (breakpoint_chain
);
5629 /* But cleanup everything else. */
5630 do_cleanups (old_chain
);
5633 /* Set a breakpoint.
5634 ARG is a string describing breakpoint address,
5635 condition, and thread.
5636 FLAG specifies if a breakpoint is hardware on,
5637 and if breakpoint is temporary, using BP_HARDWARE_FLAG
5641 break_command_1 (char *arg
, int flag
, int from_tty
)
5643 int hardwareflag
= flag
& BP_HARDWAREFLAG
;
5644 int tempflag
= flag
& BP_TEMPFLAG
;
5646 break_command_really (arg
,
5647 NULL
, 0, 1 /* parse arg */,
5648 tempflag
, hardwareflag
,
5649 0 /* Ignore count */,
5650 pending_break_support
,
5651 NULL
/* breakpoint_ops */,
5657 set_breakpoint (char *address
, char *condition
,
5658 int hardwareflag
, int tempflag
,
5659 int thread
, int ignore_count
,
5662 break_command_really (address
, condition
, thread
,
5663 0 /* condition and thread are valid. */,
5664 tempflag
, hardwareflag
,
5667 ? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
5671 /* Adjust SAL to the first instruction past the function prologue.
5672 The end of the prologue is determined using the line table from
5673 the debugging information.
5675 If SAL is already past the prologue, then do nothing. */
5678 skip_prologue_sal (struct symtab_and_line
*sal
)
5680 struct symbol
*sym
= find_pc_function (sal
->pc
);
5681 struct symtab_and_line start_sal
;
5686 start_sal
= find_function_start_sal (sym
, 1);
5687 if (sal
->pc
< start_sal
.pc
)
5691 /* Helper function for break_command_1 and disassemble_command. */
5694 resolve_sal_pc (struct symtab_and_line
*sal
)
5698 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5700 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5701 error (_("No line %d in file \"%s\"."),
5702 sal
->line
, sal
->symtab
->filename
);
5705 /* If this SAL corresponds to a breakpoint inserted using
5706 a line number, then skip the function prologue if necessary. */
5707 if (sal
->explicit_line
)
5708 skip_prologue_sal (sal
);
5711 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5713 struct blockvector
*bv
;
5717 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &b
, sal
->symtab
);
5720 sym
= block_linkage_function (b
);
5723 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5724 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5728 /* It really is worthwhile to have the section, so we'll just
5729 have to look harder. This case can be executed if we have
5730 line numbers but no functions (as can happen in assembly
5733 struct minimal_symbol
*msym
;
5735 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5737 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5744 break_command (char *arg
, int from_tty
)
5746 break_command_1 (arg
, 0, from_tty
);
5750 tbreak_command (char *arg
, int from_tty
)
5752 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5756 hbreak_command (char *arg
, int from_tty
)
5758 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5762 thbreak_command (char *arg
, int from_tty
)
5764 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5768 stop_command (char *arg
, int from_tty
)
5770 printf_filtered (_("Specify the type of breakpoint to set.\n\
5771 Usage: stop in <function | address>\n\
5772 stop at <line>\n"));
5776 stopin_command (char *arg
, int from_tty
)
5780 if (arg
== (char *) NULL
)
5782 else if (*arg
!= '*')
5787 /* look for a ':'. If this is a line number specification, then
5788 say it is bad, otherwise, it should be an address or
5789 function/method name */
5790 while (*argptr
&& !hasColon
)
5792 hasColon
= (*argptr
== ':');
5797 badInput
= (*argptr
!= ':'); /* Not a class::method */
5799 badInput
= isdigit (*arg
); /* a simple line number */
5803 printf_filtered (_("Usage: stop in <function | address>\n"));
5805 break_command_1 (arg
, 0, from_tty
);
5809 stopat_command (char *arg
, int from_tty
)
5813 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5820 /* look for a ':'. If there is a '::' then get out, otherwise
5821 it is probably a line number. */
5822 while (*argptr
&& !hasColon
)
5824 hasColon
= (*argptr
== ':');
5829 badInput
= (*argptr
== ':'); /* we have class::method */
5831 badInput
= !isdigit (*arg
); /* not a line number */
5835 printf_filtered (_("Usage: stop at <line>\n"));
5837 break_command_1 (arg
, 0, from_tty
);
5840 /* accessflag: hw_write: watch write,
5841 hw_read: watch read,
5842 hw_access: watch access (read or write) */
5844 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5846 struct breakpoint
*b
, *scope_breakpoint
= NULL
;
5847 struct symtab_and_line sal
;
5848 struct expression
*exp
;
5849 struct block
*exp_valid_block
;
5850 struct value
*val
, *mark
;
5851 struct frame_info
*frame
;
5852 struct frame_info
*prev_frame
= NULL
;
5853 char *exp_start
= NULL
;
5854 char *exp_end
= NULL
;
5855 char *tok
, *id_tok_start
, *end_tok
;
5857 char *cond_start
= NULL
;
5858 char *cond_end
= NULL
;
5859 struct expression
*cond
= NULL
;
5860 int i
, other_type_used
, target_resources_ok
= 0;
5861 enum bptype bp_type
;
5865 init_sal (&sal
); /* initialize to zeroes */
5867 /* Make sure that we actually have parameters to parse. */
5868 if (arg
!= NULL
&& arg
[0] != '\0')
5870 toklen
= strlen (arg
); /* Size of argument list. */
5872 /* Points tok to the end of the argument list. */
5873 tok
= arg
+ toklen
- 1;
5875 /* Go backwards in the parameters list. Skip the last parameter.
5876 If we're expecting a 'thread <thread_num>' parameter, this should
5877 be the thread identifier. */
5878 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5880 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5883 /* Points end_tok to the beginning of the last token. */
5884 id_tok_start
= tok
+ 1;
5886 /* Go backwards in the parameters list. Skip one more parameter.
5887 If we're expecting a 'thread <thread_num>' parameter, we should
5888 reach a "thread" token. */
5889 while (tok
> arg
&& (*tok
== ' ' || *tok
== '\t'))
5894 while (tok
> arg
&& (*tok
!= ' ' && *tok
!= '\t'))
5897 /* Move the pointer forward to skip the whitespace and
5898 calculate the length of the token. */
5900 toklen
= end_tok
- tok
;
5902 if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5904 /* At this point we've found a "thread" token, which means
5905 the user is trying to set a watchpoint that triggers
5906 only in a specific thread. */
5909 /* Extract the thread ID from the next token. */
5910 thread
= strtol (id_tok_start
, &endp
, 0);
5912 /* Check if the user provided a valid numeric value for the
5914 if (*endp
!= ' ' && *endp
!= '\t' && *endp
!= '\0')
5915 error (_("Invalid thread ID specification %s."), id_tok_start
);
5917 /* Check if the thread actually exists. */
5918 if (!valid_thread_id (thread
))
5919 error (_("Unknown thread %d."), thread
);
5921 /* Truncate the string and get rid of the thread <thread_num>
5922 parameter before the parameter list is parsed by the
5923 evaluate_expression() function. */
5928 /* Parse the rest of the arguments. */
5929 innermost_block
= NULL
;
5931 exp
= parse_exp_1 (&arg
, 0, 0);
5933 exp_valid_block
= innermost_block
;
5934 mark
= value_mark ();
5935 fetch_watchpoint_value (exp
, &val
, NULL
, NULL
);
5937 release_value (val
);
5940 while (*tok
== ' ' || *tok
== '\t')
5944 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5947 toklen
= end_tok
- tok
;
5948 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5950 tok
= cond_start
= end_tok
+ 1;
5951 cond
= parse_exp_1 (&tok
, 0, 0);
5955 error (_("Junk at end of command."));
5957 if (accessflag
== hw_read
)
5958 bp_type
= bp_read_watchpoint
;
5959 else if (accessflag
== hw_access
)
5960 bp_type
= bp_access_watchpoint
;
5962 bp_type
= bp_hardware_watchpoint
;
5964 mem_cnt
= can_use_hardware_watchpoint (val
);
5965 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5966 error (_("Expression cannot be implemented with read/access watchpoint."));
5969 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5970 target_resources_ok
=
5971 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5973 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5974 error (_("Target does not support this type of hardware watchpoint."));
5976 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5977 error (_("Target can only support one kind of HW watchpoint at a time."));
5980 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5981 watchpoint could not be set. */
5982 if (!mem_cnt
|| target_resources_ok
<= 0)
5983 bp_type
= bp_watchpoint
;
5985 frame
= block_innermost_frame (exp_valid_block
);
5987 prev_frame
= get_prev_frame (frame
);
5991 /* If the expression is "local", then set up a "watchpoint scope"
5992 breakpoint at the point where we've left the scope of the watchpoint
5993 expression. Create the scope breakpoint before the watchpoint, so
5994 that we will encounter it first in bpstat_stop_status. */
5995 if (innermost_block
&& prev_frame
)
5997 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5998 bp_watchpoint_scope
);
6000 scope_breakpoint
->enable_state
= bp_enabled
;
6002 /* Automatically delete the breakpoint when it hits. */
6003 scope_breakpoint
->disposition
= disp_del
;
6005 /* Only break in the proper frame (help with recursion). */
6006 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
6008 /* Set the address at which we will stop. */
6009 scope_breakpoint
->loc
->requested_address
6010 = get_frame_pc (prev_frame
);
6011 scope_breakpoint
->loc
->address
6012 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
6013 scope_breakpoint
->type
);
6016 /* Now set up the breakpoint. */
6017 b
= set_raw_breakpoint (sal
, bp_type
);
6018 set_breakpoint_count (breakpoint_count
+ 1);
6019 b
->number
= breakpoint_count
;
6021 b
->disposition
= disp_donttouch
;
6023 b
->exp_valid_block
= exp_valid_block
;
6024 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
6027 b
->loc
->cond
= cond
;
6029 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
6034 b
->watchpoint_frame
= get_frame_id (frame
);
6036 b
->watchpoint_frame
= null_frame_id
;
6038 if (scope_breakpoint
!= NULL
)
6040 /* The scope breakpoint is related to the watchpoint. We will
6041 need to act on them together. */
6042 b
->related_breakpoint
= scope_breakpoint
;
6043 scope_breakpoint
->related_breakpoint
= b
;
6046 value_free_to_mark (mark
);
6048 update_global_location_list (1);
6051 /* Return count of locations need to be watched and can be handled
6052 in hardware. If the watchpoint can not be handled
6053 in hardware return zero. */
6056 can_use_hardware_watchpoint (struct value
*v
)
6058 int found_memory_cnt
= 0;
6059 struct value
*head
= v
;
6061 /* Did the user specifically forbid us to use hardware watchpoints? */
6062 if (!can_use_hw_watchpoints
)
6065 /* Make sure that the value of the expression depends only upon
6066 memory contents, and values computed from them within GDB. If we
6067 find any register references or function calls, we can't use a
6068 hardware watchpoint.
6070 The idea here is that evaluating an expression generates a series
6071 of values, one holding the value of every subexpression. (The
6072 expression a*b+c has five subexpressions: a, b, a*b, c, and
6073 a*b+c.) GDB's values hold almost enough information to establish
6074 the criteria given above --- they identify memory lvalues,
6075 register lvalues, computed values, etcetera. So we can evaluate
6076 the expression, and then scan the chain of values that leaves
6077 behind to decide whether we can detect any possible change to the
6078 expression's final value using only hardware watchpoints.
6080 However, I don't think that the values returned by inferior
6081 function calls are special in any way. So this function may not
6082 notice that an expression involving an inferior function call
6083 can't be watched with hardware watchpoints. FIXME. */
6084 for (; v
; v
= value_next (v
))
6086 if (VALUE_LVAL (v
) == lval_memory
)
6089 /* A lazy memory lvalue is one that GDB never needed to fetch;
6090 we either just used its address (e.g., `a' in `a.b') or
6091 we never needed it at all (e.g., `a' in `a,b'). */
6095 /* Ahh, memory we actually used! Check if we can cover
6096 it with hardware watchpoints. */
6097 struct type
*vtype
= check_typedef (value_type (v
));
6099 /* We only watch structs and arrays if user asked for it
6100 explicitly, never if they just happen to appear in a
6101 middle of some value chain. */
6103 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
6104 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
6106 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
6107 int len
= TYPE_LENGTH (value_type (v
));
6109 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
6116 else if (VALUE_LVAL (v
) != not_lval
6117 && deprecated_value_modifiable (v
) == 0)
6118 return 0; /* ??? What does this represent? */
6119 else if (VALUE_LVAL (v
) == lval_register
)
6120 return 0; /* cannot watch a register with a HW watchpoint */
6123 /* The expression itself looks suitable for using a hardware
6124 watchpoint, but give the target machine a chance to reject it. */
6125 return found_memory_cnt
;
6129 watch_command_wrapper (char *arg
, int from_tty
)
6131 watch_command (arg
, from_tty
);
6135 watch_command (char *arg
, int from_tty
)
6137 watch_command_1 (arg
, hw_write
, from_tty
);
6141 rwatch_command_wrapper (char *arg
, int from_tty
)
6143 rwatch_command (arg
, from_tty
);
6147 rwatch_command (char *arg
, int from_tty
)
6149 watch_command_1 (arg
, hw_read
, from_tty
);
6153 awatch_command_wrapper (char *arg
, int from_tty
)
6155 awatch_command (arg
, from_tty
);
6159 awatch_command (char *arg
, int from_tty
)
6161 watch_command_1 (arg
, hw_access
, from_tty
);
6165 /* Helper routines for the until_command routine in infcmd.c. Here
6166 because it uses the mechanisms of breakpoints. */
6168 struct until_break_command_continuation_args
6170 struct breakpoint
*breakpoint
;
6171 struct breakpoint
*breakpoint2
;
6174 /* This function is called by fetch_inferior_event via the
6175 cmd_continuation pointer, to complete the until command. It takes
6176 care of cleaning up the temporary breakpoints set up by the until
6179 until_break_command_continuation (void *arg
)
6181 struct until_break_command_continuation_args
*a
= arg
;
6183 delete_breakpoint (a
->breakpoint
);
6185 delete_breakpoint (a
->breakpoint2
);
6189 until_break_command (char *arg
, int from_tty
, int anywhere
)
6191 struct symtabs_and_lines sals
;
6192 struct symtab_and_line sal
;
6193 struct frame_info
*frame
= get_selected_frame (NULL
);
6194 struct frame_info
*prev_frame
= get_prev_frame (frame
);
6195 struct breakpoint
*breakpoint
;
6196 struct breakpoint
*breakpoint2
= NULL
;
6197 struct cleanup
*old_chain
;
6199 clear_proceed_status ();
6201 /* Set a breakpoint where the user wants it and at return from
6204 if (default_breakpoint_valid
)
6205 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
6206 default_breakpoint_line
, (char ***) NULL
, NULL
);
6208 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
6209 0, (char ***) NULL
, NULL
);
6211 if (sals
.nelts
!= 1)
6212 error (_("Couldn't get information on specified line."));
6215 xfree (sals
.sals
); /* malloc'd, so freed */
6218 error (_("Junk at end of arguments."));
6220 resolve_sal_pc (&sal
);
6223 /* If the user told us to continue until a specified location,
6224 we don't specify a frame at which we need to stop. */
6225 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
6227 /* Otherwise, specify the current frame, because we want to stop only
6228 at the very same frame. */
6229 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (frame
),
6232 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
6234 /* Keep within the current frame, or in frames called by the current
6238 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6239 sal
.pc
= get_frame_pc (prev_frame
);
6240 breakpoint2
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6242 make_cleanup_delete_breakpoint (breakpoint2
);
6245 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6247 /* If we are running asynchronously, and proceed call above has actually
6248 managed to start the target, arrange for breakpoints to be
6249 deleted when the target stops. Otherwise, we're already stopped and
6250 delete breakpoints via cleanup chain. */
6252 if (target_can_async_p () && is_running (inferior_ptid
))
6254 struct until_break_command_continuation_args
*args
;
6255 args
= xmalloc (sizeof (*args
));
6257 args
->breakpoint
= breakpoint
;
6258 args
->breakpoint2
= breakpoint2
;
6260 discard_cleanups (old_chain
);
6261 add_continuation (until_break_command_continuation
, args
,
6265 do_cleanups (old_chain
);
6269 ep_skip_leading_whitespace (char **s
)
6271 if ((s
== NULL
) || (*s
== NULL
))
6273 while (isspace (**s
))
6277 /* This function attempts to parse an optional "if <cond>" clause
6278 from the arg string. If one is not found, it returns NULL.
6280 Else, it returns a pointer to the condition string. (It does not
6281 attempt to evaluate the string against a particular block.) And,
6282 it updates arg to point to the first character following the parsed
6283 if clause in the arg string. */
6286 ep_parse_optional_if_clause (char **arg
)
6290 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6293 /* Skip the "if" keyword. */
6296 /* Skip any extra leading whitespace, and record the start of the
6297 condition string. */
6298 ep_skip_leading_whitespace (arg
);
6301 /* Assume that the condition occupies the remainder of the arg string. */
6302 (*arg
) += strlen (cond_string
);
6307 /* This function attempts to parse an optional filename from the arg
6308 string. If one is not found, it returns NULL.
6310 Else, it returns a pointer to the parsed filename. (This function
6311 makes no attempt to verify that a file of that name exists, or is
6312 accessible.) And, it updates arg to point to the first character
6313 following the parsed filename in the arg string.
6315 Note that clients needing to preserve the returned filename for
6316 future access should copy it to their own buffers. */
6318 ep_parse_optional_filename (char **arg
)
6320 static char filename
[1024];
6325 if ((*arg_p
== '\0') || isspace (*arg_p
))
6343 /* Commands to deal with catching events, such as signals, exceptions,
6344 process start/exit, etc. */
6348 catch_fork_temporary
, catch_vfork_temporary
,
6349 catch_fork_permanent
, catch_vfork_permanent
6354 catch_fork_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6356 char *cond_string
= NULL
;
6357 catch_fork_kind fork_kind
;
6360 fork_kind
= (catch_fork_kind
) (uintptr_t) get_cmd_context (command
);
6361 tempflag
= (fork_kind
== catch_fork_temporary
6362 || fork_kind
== catch_vfork_temporary
);
6366 ep_skip_leading_whitespace (&arg
);
6368 /* The allowed syntax is:
6370 catch [v]fork if <cond>
6372 First, check if there's an if clause. */
6373 cond_string
= ep_parse_optional_if_clause (&arg
);
6375 if ((*arg
!= '\0') && !isspace (*arg
))
6376 error (_("Junk at end of arguments."));
6378 /* If this target supports it, create a fork or vfork catchpoint
6379 and enable reporting of such events. */
6382 case catch_fork_temporary
:
6383 case catch_fork_permanent
:
6384 create_fork_event_catchpoint (tempflag
, cond_string
);
6386 case catch_vfork_temporary
:
6387 case catch_vfork_permanent
:
6388 create_vfork_event_catchpoint (tempflag
, cond_string
);
6391 error (_("unsupported or unknown fork kind; cannot catch it"));
6397 catch_exec_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6400 char *cond_string
= NULL
;
6402 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6406 ep_skip_leading_whitespace (&arg
);
6408 /* The allowed syntax is:
6410 catch exec if <cond>
6412 First, check if there's an if clause. */
6413 cond_string
= ep_parse_optional_if_clause (&arg
);
6415 if ((*arg
!= '\0') && !isspace (*arg
))
6416 error (_("Junk at end of arguments."));
6418 /* If this target supports it, create an exec catchpoint
6419 and enable reporting of such events. */
6420 create_exec_event_catchpoint (tempflag
, cond_string
);
6424 catch_load_command_1 (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6427 char *dll_pathname
= NULL
;
6428 char *cond_string
= NULL
;
6430 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6434 ep_skip_leading_whitespace (&arg
);
6436 /* The allowed syntax is:
6438 catch load if <cond>
6439 catch load <filename>
6440 catch load <filename> if <cond>
6442 The user is not allowed to specify the <filename> after an
6445 We'll ignore the pathological case of a file named "if".
6447 First, check if there's an if clause. If so, then there
6448 cannot be a filename. */
6449 cond_string
= ep_parse_optional_if_clause (&arg
);
6451 /* If there was an if clause, then there cannot be a filename.
6452 Else, there might be a filename and an if clause. */
6453 if (cond_string
== NULL
)
6455 dll_pathname
= ep_parse_optional_filename (&arg
);
6456 ep_skip_leading_whitespace (&arg
);
6457 cond_string
= ep_parse_optional_if_clause (&arg
);
6460 if ((*arg
!= '\0') && !isspace (*arg
))
6461 error (_("Junk at end of arguments."));
6463 /* Create a load breakpoint that only triggers when a load of
6464 the specified dll (or any dll, if no pathname was specified)
6466 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6467 dll_pathname
, cond_string
);
6471 catch_unload_command_1 (char *arg
, int from_tty
,
6472 struct cmd_list_element
*command
)
6475 char *dll_pathname
= NULL
;
6476 char *cond_string
= NULL
;
6478 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6482 ep_skip_leading_whitespace (&arg
);
6484 /* The allowed syntax is:
6486 catch unload if <cond>
6487 catch unload <filename>
6488 catch unload <filename> if <cond>
6490 The user is not allowed to specify the <filename> after an
6493 We'll ignore the pathological case of a file named "if".
6495 First, check if there's an if clause. If so, then there
6496 cannot be a filename. */
6497 cond_string
= ep_parse_optional_if_clause (&arg
);
6499 /* If there was an if clause, then there cannot be a filename.
6500 Else, there might be a filename and an if clause. */
6501 if (cond_string
== NULL
)
6503 dll_pathname
= ep_parse_optional_filename (&arg
);
6504 ep_skip_leading_whitespace (&arg
);
6505 cond_string
= ep_parse_optional_if_clause (&arg
);
6508 if ((*arg
!= '\0') && !isspace (*arg
))
6509 error (_("Junk at end of arguments."));
6511 /* Create an unload breakpoint that only triggers when an unload of
6512 the specified dll (or any dll, if no pathname was specified)
6514 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6515 dll_pathname
, cond_string
);
6518 static enum print_stop_action
6519 print_exception_catchpoint (struct breakpoint
*b
)
6521 int bp_temp
, bp_throw
;
6523 annotate_catchpoint (b
->number
);
6525 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6526 if (b
->loc
->address
!= b
->loc
->requested_address
)
6527 breakpoint_adjustment_warning (b
->loc
->requested_address
,
6530 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6532 bp_temp
? "Temporary catchpoint "
6534 if (!ui_out_is_mi_like_p (uiout
))
6535 ui_out_field_int (uiout
, "bkptno", b
->number
);
6537 bp_throw
? " (exception thrown), "
6538 : " (exception caught), ");
6539 if (ui_out_is_mi_like_p (uiout
))
6541 ui_out_field_string (uiout
, "reason",
6542 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
6543 ui_out_field_string (uiout
, "disp", bpdisp_text (b
->disposition
));
6544 ui_out_field_int (uiout
, "bkptno", b
->number
);
6546 return PRINT_SRC_AND_LOC
;
6550 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6555 if (b
->loc
== NULL
|| b
->loc
->shlib_disabled
)
6556 ui_out_field_string (uiout
, "addr", "<PENDING>");
6558 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6562 *last_addr
= b
->loc
->address
;
6563 if (strstr (b
->addr_string
, "throw") != NULL
)
6564 ui_out_field_string (uiout
, "what", "exception throw");
6566 ui_out_field_string (uiout
, "what", "exception catch");
6570 print_mention_exception_catchpoint (struct breakpoint
*b
)
6575 bp_temp
= b
->loc
->owner
->disposition
== disp_del
;
6576 bp_throw
= strstr (b
->addr_string
, "throw") != NULL
;
6577 ui_out_text (uiout
, bp_temp
? _("Temporary catchpoint ")
6578 : _("Catchpoint "));
6579 ui_out_field_int (uiout
, "bkptno", b
->number
);
6580 ui_out_text (uiout
, bp_throw
? _(" (throw)")
6584 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6585 print_exception_catchpoint
,
6586 print_one_exception_catchpoint
,
6587 print_mention_exception_catchpoint
6591 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6592 enum exception_event_kind ex_event
, int from_tty
)
6594 char *trigger_func_name
;
6596 if (ex_event
== EX_EVENT_CATCH
)
6597 trigger_func_name
= "__cxa_begin_catch";
6599 trigger_func_name
= "__cxa_throw";
6601 break_command_really (trigger_func_name
, cond_string
, -1,
6602 0 /* condition and thread are valid. */,
6605 AUTO_BOOLEAN_TRUE
/* pending */,
6606 &gnu_v3_exception_catchpoint_ops
, from_tty
);
6611 /* Deal with "catch catch" and "catch throw" commands */
6614 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6615 int tempflag
, int from_tty
)
6617 char *cond_string
= NULL
;
6618 struct symtab_and_line
*sal
= NULL
;
6622 ep_skip_leading_whitespace (&arg
);
6624 cond_string
= ep_parse_optional_if_clause (&arg
);
6626 if ((*arg
!= '\0') && !isspace (*arg
))
6627 error (_("Junk at end of arguments."));
6629 if ((ex_event
!= EX_EVENT_THROW
) &&
6630 (ex_event
!= EX_EVENT_CATCH
))
6631 error (_("Unsupported or unknown exception event; cannot catch it"));
6633 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6636 warning (_("Unsupported with this platform/compiler combination."));
6639 /* Implementation of "catch catch" command. */
6642 catch_catch_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6644 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6645 catch_exception_command_1 (EX_EVENT_CATCH
, arg
, tempflag
, from_tty
);
6648 /* Implementation of "catch throw" command. */
6651 catch_throw_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6653 int tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6654 catch_exception_command_1 (EX_EVENT_THROW
, arg
, tempflag
, from_tty
);
6657 /* Create a breakpoint struct for Ada exception catchpoints. */
6660 create_ada_exception_breakpoint (struct symtab_and_line sal
,
6664 struct expression
*cond
,
6665 struct breakpoint_ops
*ops
,
6669 struct breakpoint
*b
;
6673 describe_other_breakpoints (sal
.pc
, sal
.section
, -1);
6674 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
6675 version for exception catchpoints, because two catchpoints
6676 used for different exception names will use the same address.
6677 In this case, a "breakpoint ... also set at..." warning is
6678 unproductive. Besides. the warning phrasing is also a bit
6679 inapropriate, we should use the word catchpoint, and tell
6680 the user what type of catchpoint it is. The above is good
6681 enough for now, though. */
6684 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6685 set_breakpoint_count (breakpoint_count
+ 1);
6687 b
->enable_state
= bp_enabled
;
6688 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6689 b
->number
= breakpoint_count
;
6690 b
->ignore_count
= 0;
6691 b
->loc
->cond
= cond
;
6692 b
->addr_string
= addr_string
;
6693 b
->language
= language_ada
;
6694 b
->cond_string
= cond_string
;
6695 b
->exp_string
= exp_string
;
6700 update_global_location_list (1);
6703 /* Implement the "catch exception" command. */
6706 catch_ada_exception_command (char *arg
, int from_tty
,
6707 struct cmd_list_element
*command
)
6710 struct symtab_and_line sal
;
6712 char *addr_string
= NULL
;
6713 char *exp_string
= NULL
;
6714 char *cond_string
= NULL
;
6715 struct expression
*cond
= NULL
;
6716 struct breakpoint_ops
*ops
= NULL
;
6718 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6722 sal
= ada_decode_exception_location (arg
, &addr_string
, &exp_string
,
6723 &cond_string
, &cond
, &ops
);
6724 create_ada_exception_breakpoint (sal
, addr_string
, exp_string
,
6725 cond_string
, cond
, ops
, tempflag
,
6729 /* Implement the "catch assert" command. */
6732 catch_assert_command (char *arg
, int from_tty
, struct cmd_list_element
*command
)
6735 struct symtab_and_line sal
;
6736 char *addr_string
= NULL
;
6737 struct breakpoint_ops
*ops
= NULL
;
6739 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
6743 sal
= ada_decode_assert_location (arg
, &addr_string
, &ops
);
6744 create_ada_exception_breakpoint (sal
, addr_string
, NULL
, NULL
, NULL
, ops
,
6745 tempflag
, from_tty
);
6749 catch_command (char *arg
, int from_tty
)
6751 error (_("Catch requires an event name."));
6756 tcatch_command (char *arg
, int from_tty
)
6758 error (_("Catch requires an event name."));
6761 /* Delete breakpoints by address or line. */
6764 clear_command (char *arg
, int from_tty
)
6766 struct breakpoint
*b
;
6767 VEC(breakpoint_p
) *found
= 0;
6770 struct symtabs_and_lines sals
;
6771 struct symtab_and_line sal
;
6776 sals
= decode_line_spec (arg
, 1);
6781 sals
.sals
= (struct symtab_and_line
*)
6782 xmalloc (sizeof (struct symtab_and_line
));
6783 make_cleanup (xfree
, sals
.sals
);
6784 init_sal (&sal
); /* initialize to zeroes */
6785 sal
.line
= default_breakpoint_line
;
6786 sal
.symtab
= default_breakpoint_symtab
;
6787 sal
.pc
= default_breakpoint_address
;
6788 if (sal
.symtab
== 0)
6789 error (_("No source file specified."));
6797 /* We don't call resolve_sal_pc here. That's not
6798 as bad as it seems, because all existing breakpoints
6799 typically have both file/line and pc set. So, if
6800 clear is given file/line, we can match this to existing
6801 breakpoint without obtaining pc at all.
6803 We only support clearing given the address explicitly
6804 present in breakpoint table. Say, we've set breakpoint
6805 at file:line. There were several PC values for that file:line,
6806 due to optimization, all in one block.
6807 We've picked one PC value. If "clear" is issued with another
6808 PC corresponding to the same file:line, the breakpoint won't
6809 be cleared. We probably can still clear the breakpoint, but
6810 since the other PC value is never presented to user, user
6811 can only find it by guessing, and it does not seem important
6814 /* For each line spec given, delete bps which correspond
6815 to it. Do it in two passes, solely to preserve the current
6816 behavior that from_tty is forced true if we delete more than
6820 for (i
= 0; i
< sals
.nelts
; i
++)
6822 /* If exact pc given, clear bpts at that pc.
6823 If line given (pc == 0), clear all bpts on specified line.
6824 If defaulting, clear all bpts on default line
6827 defaulting sal.pc != 0 tests to do
6832 1 0 <can't happen> */
6836 /* Find all matching breakpoints and add them to
6841 /* Are we going to delete b? */
6842 if (b
->type
!= bp_none
6843 && b
->type
!= bp_watchpoint
6844 && b
->type
!= bp_hardware_watchpoint
6845 && b
->type
!= bp_read_watchpoint
6846 && b
->type
!= bp_access_watchpoint
)
6848 struct bp_location
*loc
= b
->loc
;
6849 for (; loc
; loc
= loc
->next
)
6851 int pc_match
= sal
.pc
6852 && (loc
->address
== sal
.pc
)
6853 && (!section_is_overlay (loc
->section
)
6854 || loc
->section
== sal
.section
);
6855 int line_match
= ((default_match
|| (0 == sal
.pc
))
6856 && b
->source_file
!= NULL
6857 && sal
.symtab
!= NULL
6858 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6859 && b
->line_number
== sal
.line
);
6860 if (pc_match
|| line_match
)
6869 VEC_safe_push(breakpoint_p
, found
, b
);
6872 /* Now go thru the 'found' chain and delete them. */
6873 if (VEC_empty(breakpoint_p
, found
))
6876 error (_("No breakpoint at %s."), arg
);
6878 error (_("No breakpoint at this line."));
6881 if (VEC_length(breakpoint_p
, found
) > 1)
6882 from_tty
= 1; /* Always report if deleted more than one */
6885 if (VEC_length(breakpoint_p
, found
) == 1)
6886 printf_unfiltered (_("Deleted breakpoint "));
6888 printf_unfiltered (_("Deleted breakpoints "));
6890 breakpoints_changed ();
6892 for (ix
= 0; VEC_iterate(breakpoint_p
, found
, ix
, b
); ix
++)
6895 printf_unfiltered ("%d ", b
->number
);
6896 delete_breakpoint (b
);
6899 putchar_unfiltered ('\n');
6902 /* Delete breakpoint in BS if they are `delete' breakpoints and
6903 all breakpoints that are marked for deletion, whether hit or not.
6904 This is called after any breakpoint is hit, or after errors. */
6907 breakpoint_auto_delete (bpstat bs
)
6909 struct breakpoint
*b
, *temp
;
6911 for (; bs
; bs
= bs
->next
)
6912 if (bs
->breakpoint_at
6913 && bs
->breakpoint_at
->owner
6914 && bs
->breakpoint_at
->owner
->disposition
== disp_del
6916 delete_breakpoint (bs
->breakpoint_at
->owner
);
6918 ALL_BREAKPOINTS_SAFE (b
, temp
)
6920 if (b
->disposition
== disp_del_at_next_stop
)
6921 delete_breakpoint (b
);
6925 /* If SHOULD_INSERT is true, do not insert any breakpoint locations
6926 into the inferior, only remove already-inserted locations that no
6927 longer should be inserted. Functions that delete a breakpoint or
6928 breakpoints should pass false, so that deleting a breakpoint
6929 doesn't have the side effect of inserting the locations of other
6930 breakpoints that are marked not-inserted, but should_be_inserted
6931 returns true on them.
6933 This behaviour is useful is situations close to tear-down -- e.g.,
6934 after an exec, while the target still has execution, but breakpoint
6935 shadows of the previous executable image should *NOT* be restored
6936 to the new image; or before detaching, where the target still has
6937 execution and wants to delete breakpoints from GDB's lists, and all
6938 breakpoints had already been removed from the inferior. */
6941 update_global_location_list (int should_insert
)
6943 struct breakpoint
*b
;
6944 struct bp_location
**next
= &bp_location_chain
;
6945 struct bp_location
*loc
;
6946 struct bp_location
*loc2
;
6947 struct gdb_exception e
;
6948 VEC(bp_location_p
) *old_locations
= NULL
;
6952 /* Store old locations for future reference. */
6953 for (loc
= bp_location_chain
; loc
; loc
= loc
->global_next
)
6954 VEC_safe_push (bp_location_p
, old_locations
, loc
);
6956 bp_location_chain
= NULL
;
6959 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
6962 next
= &(loc
->global_next
);
6967 /* Identify bp_location instances that are no longer present in the new
6968 list, and therefore should be freed. Note that it's not necessary that
6969 those locations should be removed from inferior -- if there's another
6970 location at the same address (previously marked as duplicate),
6971 we don't need to remove/insert the location. */
6972 for (ix
= 0; VEC_iterate(bp_location_p
, old_locations
, ix
, loc
); ++ix
)
6974 /* Tells if 'loc' is found amoung the new locations. If not, we
6976 int found_object
= 0;
6977 /* Tells if the location should remain inserted in the target. */
6978 int keep_in_target
= 0;
6980 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
6987 /* If this location is no longer present, and inserted, look if there's
6988 maybe a new location at the same address. If so, mark that one
6989 inserted, and don't remove this one. This is needed so that we
6990 don't have a time window where a breakpoint at certain location is not
6995 /* If the location is inserted now, we might have to remove it. */
6997 if (found_object
&& should_be_inserted (loc
))
6999 /* The location is still present in the location list, and still
7000 should be inserted. Don't do anything. */
7005 /* The location is either no longer present, or got disabled.
7006 See if there's another location at the same address, in which
7007 case we don't need to remove this one from the target. */
7008 if (breakpoint_address_is_meaningful (loc
->owner
))
7009 for (loc2
= bp_location_chain
; loc2
; loc2
= loc2
->global_next
)
7011 /* For the sake of should_insert_location. The
7012 call to check_duplicates will fix up this later. */
7013 loc2
->duplicate
= 0;
7014 if (should_be_inserted (loc2
)
7015 && loc2
!= loc
&& loc2
->address
== loc
->address
)
7018 loc2
->target_info
= loc
->target_info
;
7025 if (!keep_in_target
)
7027 if (remove_breakpoint (loc
, mark_uninserted
))
7029 /* This is just about all we can do. We could keep this
7030 location on the global list, and try to remove it next
7031 time, but there's no particular reason why we will
7034 Note that at this point, loc->owner is still valid,
7035 as delete_breakpoint frees the breakpoint only
7036 after calling us. */
7037 printf_filtered (_("warning: Error removing breakpoint %d\n"),
7038 loc
->owner
->number
);
7048 /* This location was removed from the targets. In non-stop mode,
7049 a race condition is possible where we've removed a breakpoint,
7050 but stop events for that breakpoint are already queued and will
7051 arrive later. To suppress spurious SIGTRAPs reported to user,
7052 we keep this breakpoint location for a bit, and will retire it
7053 after we see 3 * thread_count events.
7054 The theory here is that reporting of events should,
7055 "on the average", be fair, so after that many event we'll see
7056 events from all threads that have anything of interest, and no
7057 longer need to keep this breakpoint. This is just a
7058 heuristic, but if it's wrong, we'll report unexpected SIGTRAP,
7059 which is usability issue, but not a correctness problem. */
7060 loc
->events_till_retirement
= 3 * (thread_count () + 1);
7064 free_bp_location (loc
);
7070 check_duplicates (b
);
7073 if (always_inserted_mode
&& should_insert
&& target_has_execution
)
7074 insert_breakpoint_locations ();
7078 breakpoint_retire_moribund (void)
7080 struct bp_location
*loc
;
7083 for (ix
= 0; VEC_iterate (bp_location_p
, moribund_locations
, ix
, loc
); ++ix
)
7084 if (--(loc
->events_till_retirement
) == 0)
7086 free_bp_location (loc
);
7087 VEC_unordered_remove (bp_location_p
, moribund_locations
, ix
);
7093 update_global_location_list_nothrow (int inserting
)
7095 struct gdb_exception e
;
7096 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7097 update_global_location_list (inserting
);
7100 /* Clear BPT from a BPS. */
7102 bpstat_remove_breakpoint (bpstat bps
, struct breakpoint
*bpt
)
7105 for (bs
= bps
; bs
; bs
= bs
->next
)
7106 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->owner
== bpt
)
7108 bs
->breakpoint_at
= NULL
;
7110 /* bs->commands will be freed later. */
7114 /* Callback for iterate_over_threads. */
7116 bpstat_remove_breakpoint_callback (struct thread_info
*th
, void *data
)
7118 struct breakpoint
*bpt
= data
;
7119 bpstat_remove_breakpoint (th
->stop_bpstat
, bpt
);
7123 /* Delete a breakpoint and clean up all traces of it in the data
7127 delete_breakpoint (struct breakpoint
*bpt
)
7129 struct breakpoint
*b
;
7130 struct bp_location
*loc
, *next
;
7132 gdb_assert (bpt
!= NULL
);
7134 /* Has this bp already been deleted? This can happen because multiple
7135 lists can hold pointers to bp's. bpstat lists are especial culprits.
7137 One example of this happening is a watchpoint's scope bp. When the
7138 scope bp triggers, we notice that the watchpoint is out of scope, and
7139 delete it. We also delete its scope bp. But the scope bp is marked
7140 "auto-deleting", and is already on a bpstat. That bpstat is then
7141 checked for auto-deleting bp's, which are deleted.
7143 A real solution to this problem might involve reference counts in bp's,
7144 and/or giving them pointers back to their referencing bpstat's, and
7145 teaching delete_breakpoint to only free a bp's storage when no more
7146 references were extent. A cheaper bandaid was chosen. */
7147 if (bpt
->type
== bp_none
)
7150 observer_notify_breakpoint_deleted (bpt
->number
);
7152 if (breakpoint_chain
== bpt
)
7153 breakpoint_chain
= bpt
->next
;
7158 b
->next
= bpt
->next
;
7162 free_command_lines (&bpt
->commands
);
7163 if (bpt
->cond_string
!= NULL
)
7164 xfree (bpt
->cond_string
);
7165 if (bpt
->addr_string
!= NULL
)
7166 xfree (bpt
->addr_string
);
7167 if (bpt
->exp
!= NULL
)
7169 if (bpt
->exp_string
!= NULL
)
7170 xfree (bpt
->exp_string
);
7171 if (bpt
->val
!= NULL
)
7172 value_free (bpt
->val
);
7173 if (bpt
->source_file
!= NULL
)
7174 xfree (bpt
->source_file
);
7175 if (bpt
->dll_pathname
!= NULL
)
7176 xfree (bpt
->dll_pathname
);
7177 if (bpt
->triggered_dll_pathname
!= NULL
)
7178 xfree (bpt
->triggered_dll_pathname
);
7179 if (bpt
->exec_pathname
!= NULL
)
7180 xfree (bpt
->exec_pathname
);
7182 /* Be sure no bpstat's are pointing at it after it's been freed. */
7183 /* FIXME, how can we find all bpstat's?
7184 We just check stop_bpstat for now. Note that we cannot just
7185 remove bpstats pointing at bpt from the stop_bpstat list
7186 entirely, as breakpoint commands are associated with the bpstat;
7187 if we remove it here, then the later call to
7188 bpstat_do_actions (&stop_bpstat);
7189 in event-top.c won't do anything, and temporary breakpoints
7190 with commands won't work. */
7192 /* Clear the current context. */
7193 bpstat_remove_breakpoint (stop_bpstat
, bpt
);
7194 /* And from all threads. */
7195 iterate_over_threads (bpstat_remove_breakpoint_callback
, bpt
);
7197 /* Now that breakpoint is removed from breakpoint
7198 list, update the global location list. This
7199 will remove locations that used to belong to
7200 this breakpoint. Do this before freeing
7201 the breakpoint itself, since remove_breakpoint
7202 looks at location's owner. It might be better
7203 design to have location completely self-contained,
7204 but it's not the case now. */
7205 update_global_location_list (0);
7208 /* On the chance that someone will soon try again to delete this same
7209 bp, we mark it as deleted before freeing its storage. */
7210 bpt
->type
= bp_none
;
7216 do_delete_breakpoint_cleanup (void *b
)
7218 delete_breakpoint (b
);
7222 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
7224 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
7228 delete_command (char *arg
, int from_tty
)
7230 struct breakpoint
*b
, *temp
;
7236 int breaks_to_delete
= 0;
7238 /* Delete all breakpoints if no argument.
7239 Do not delete internal or call-dummy breakpoints, these
7240 have to be deleted with an explicit breakpoint number argument. */
7243 if (b
->type
!= bp_call_dummy
&&
7244 b
->type
!= bp_shlib_event
&&
7245 b
->type
!= bp_thread_event
&&
7246 b
->type
!= bp_overlay_event
&&
7249 breaks_to_delete
= 1;
7254 /* Ask user only if there are some breakpoints to delete. */
7256 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
7258 ALL_BREAKPOINTS_SAFE (b
, temp
)
7260 if (b
->type
!= bp_call_dummy
&&
7261 b
->type
!= bp_shlib_event
&&
7262 b
->type
!= bp_thread_event
&&
7263 b
->type
!= bp_overlay_event
&&
7265 delete_breakpoint (b
);
7270 map_breakpoint_numbers (arg
, delete_breakpoint
);
7274 all_locations_are_pending (struct bp_location
*loc
)
7276 for (; loc
; loc
= loc
->next
)
7277 if (!loc
->shlib_disabled
)
7282 /* Subroutine of update_breakpoint_locations to simplify it.
7283 Return non-zero if multiple fns in list LOC have the same name.
7284 Null names are ignored. */
7287 ambiguous_names_p (struct bp_location
*loc
)
7289 struct bp_location
*l
;
7290 htab_t htab
= htab_create_alloc (13, htab_hash_string
,
7291 (int (*) (const void *, const void *)) streq
,
7292 NULL
, xcalloc
, xfree
);
7294 for (l
= loc
; l
!= NULL
; l
= l
->next
)
7297 const char *name
= l
->function_name
;
7299 /* Allow for some names to be NULL, ignore them. */
7303 slot
= (const char **) htab_find_slot (htab
, (const void *) name
,
7305 /* NOTE: We can assume slot != NULL here because xcalloc never returns
7320 update_breakpoint_locations (struct breakpoint
*b
,
7321 struct symtabs_and_lines sals
)
7325 struct bp_location
*existing_locations
= b
->loc
;
7327 /* If there's no new locations, and all existing locations
7328 are pending, don't do anything. This optimizes
7329 the common case where all locations are in the same
7330 shared library, that was unloaded. We'd like to
7331 retain the location, so that when the library
7332 is loaded again, we don't loose the enabled/disabled
7333 status of the individual locations. */
7334 if (all_locations_are_pending (existing_locations
) && sals
.nelts
== 0)
7339 for (i
= 0; i
< sals
.nelts
; ++i
)
7341 struct bp_location
*new_loc
=
7342 add_location_to_breakpoint (b
, b
->type
, &(sals
.sals
[i
]));
7344 /* Reparse conditions, they might contain references to the
7346 if (b
->cond_string
!= NULL
)
7348 struct gdb_exception e
;
7351 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7353 new_loc
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
),
7358 warning (_("failed to reevaluate condition for breakpoint %d: %s"),
7359 b
->number
, e
.message
);
7360 new_loc
->enabled
= 0;
7364 if (b
->source_file
!= NULL
)
7365 xfree (b
->source_file
);
7366 if (sals
.sals
[i
].symtab
== NULL
)
7367 b
->source_file
= NULL
;
7370 savestring (sals
.sals
[i
].symtab
->filename
,
7371 strlen (sals
.sals
[i
].symtab
->filename
));
7373 if (b
->line_number
== 0)
7374 b
->line_number
= sals
.sals
[i
].line
;
7377 /* If possible, carry over 'disable' status from existing breakpoints. */
7379 struct bp_location
*e
= existing_locations
;
7380 /* If there are multiple breakpoints with the same function name,
7381 e.g. for inline functions, comparing function names won't work.
7382 Instead compare pc addresses; this is just a heuristic as things
7383 may have moved, but in practice it gives the correct answer
7384 often enough until a better solution is found. */
7385 int have_ambiguous_names
= ambiguous_names_p (b
->loc
);
7387 for (; e
; e
= e
->next
)
7389 if (!e
->enabled
&& e
->function_name
)
7391 struct bp_location
*l
= b
->loc
;
7392 if (have_ambiguous_names
)
7394 for (; l
; l
= l
->next
)
7395 if (e
->address
== l
->address
)
7403 for (; l
; l
= l
->next
)
7404 if (l
->function_name
7405 && strcmp (e
->function_name
, l
->function_name
) == 0)
7415 update_global_location_list (1);
7419 /* Reset a breakpoint given it's struct breakpoint * BINT.
7420 The value we return ends up being the return value from catch_errors.
7421 Unused in this case. */
7424 breakpoint_re_set_one (void *bint
)
7426 /* get past catch_errs */
7427 struct breakpoint
*b
= (struct breakpoint
*) bint
;
7431 int *not_found_ptr
= ¬_found
;
7432 struct symtabs_and_lines sals
= {};
7433 struct symtabs_and_lines expanded
;
7435 enum enable_state save_enable
;
7436 struct gdb_exception e
;
7442 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7446 case bp_hardware_breakpoint
:
7448 case bp_catch_unload
:
7449 if (b
->addr_string
== NULL
)
7451 /* Anything without a string can't be re-set. */
7452 delete_breakpoint (b
);
7456 set_language (b
->language
);
7457 input_radix
= b
->input_radix
;
7459 TRY_CATCH (e
, RETURN_MASK_ERROR
)
7461 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7466 int not_found_and_ok
= 0;
7467 /* For pending breakpoints, it's expected that parsing
7468 will fail until the right shared library is loaded.
7469 User has already told to create pending breakpoints and
7470 don't need extra messages. If breakpoint is in bp_shlib_disabled
7471 state, then user already saw the message about that breakpoint
7472 being disabled, and don't want to see more errors. */
7474 && (b
->condition_not_parsed
7475 || (b
->loc
&& b
->loc
->shlib_disabled
)
7476 || b
->enable_state
== bp_disabled
))
7477 not_found_and_ok
= 1;
7479 if (!not_found_and_ok
)
7481 /* We surely don't want to warn about the same breakpoint
7482 10 times. One solution, implemented here, is disable
7483 the breakpoint on error. Another solution would be to
7484 have separate 'warning emitted' flag. Since this
7485 happens only when a binary has changed, I don't know
7486 which approach is better. */
7487 b
->enable_state
= bp_disabled
;
7488 throw_exception (e
);
7495 gdb_assert (sals
.nelts
== 1);
7496 resolve_sal_pc (&sals
.sals
[0]);
7497 if (b
->condition_not_parsed
&& s
&& s
[0])
7499 char *cond_string
= 0;
7501 find_condition_and_thread (s
, sals
.sals
[0].pc
,
7502 &cond_string
, &thread
);
7504 b
->cond_string
= cond_string
;
7506 b
->condition_not_parsed
= 0;
7508 expanded
= expand_line_sal_maybe (sals
.sals
[0]);
7509 update_breakpoint_locations (b
, expanded
);
7515 case bp_hardware_watchpoint
:
7516 case bp_read_watchpoint
:
7517 case bp_access_watchpoint
:
7518 /* Watchpoint can be either on expression using entirely global variables,
7519 or it can be on local variables.
7521 Watchpoints of the first kind are never auto-deleted, and even persist
7522 across program restarts. Since they can use variables from shared
7523 libraries, we need to reparse expression as libraries are loaded
7526 Watchpoints on local variables can also change meaning as result
7527 of solib event. For example, if a watchpoint uses both a local and
7528 a global variables in expression, it's a local watchpoint, but
7529 unloading of a shared library will make the expression invalid.
7530 This is not a very common use case, but we still re-evaluate
7531 expression, to avoid surprises to the user.
7533 Note that for local watchpoints, we re-evaluate it only if
7534 watchpoints frame id is still valid. If it's not, it means
7535 the watchpoint is out of scope and will be deleted soon. In fact,
7536 I'm not sure we'll ever be called in this case.
7538 If a local watchpoint's frame id is still valid, then
7539 b->exp_valid_block is likewise valid, and we can safely use it.
7541 Don't do anything about disabled watchpoints, since they will
7542 be reevaluated again when enabled. */
7543 update_watchpoint (b
, 1 /* reparse */);
7545 /* We needn't really do anything to reset these, since the mask
7546 that requests them is unaffected by e.g., new libraries being
7549 case bp_catch_vfork
:
7554 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7556 /* Delete overlay event breakpoints; they will be reset later by
7557 breakpoint_re_set. */
7558 case bp_overlay_event
:
7559 delete_breakpoint (b
);
7562 /* This breakpoint is special, it's set up when the inferior
7563 starts and we really don't want to touch it. */
7564 case bp_shlib_event
:
7566 /* Like bp_shlib_event, this breakpoint type is special.
7567 Once it is set up, we do not want to touch it. */
7568 case bp_thread_event
:
7570 /* Keep temporary breakpoints, which can be encountered when we step
7571 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7572 Otherwise these should have been blown away via the cleanup chain
7573 or by breakpoint_init_inferior when we rerun the executable. */
7576 case bp_watchpoint_scope
:
7578 case bp_step_resume
:
7580 case bp_longjmp_resume
:
7587 /* Re-set all breakpoints after symbols have been re-loaded. */
7589 breakpoint_re_set (void)
7591 struct breakpoint
*b
, *temp
;
7592 enum language save_language
;
7593 int save_input_radix
;
7595 save_language
= current_language
->la_language
;
7596 save_input_radix
= input_radix
;
7597 ALL_BREAKPOINTS_SAFE (b
, temp
)
7599 /* Format possible error msg */
7600 char *message
= xstrprintf ("Error in re-setting breakpoint %d: ",
7602 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7603 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7604 do_cleanups (cleanups
);
7606 set_language (save_language
);
7607 input_radix
= save_input_radix
;
7609 create_overlay_event_breakpoint ("_ovly_debug_event");
7612 /* Reset the thread number of this breakpoint:
7614 - If the breakpoint is for all threads, leave it as-is.
7615 - Else, reset it to the current thread for inferior_ptid. */
7617 breakpoint_re_set_thread (struct breakpoint
*b
)
7619 if (b
->thread
!= -1)
7621 if (in_thread_list (inferior_ptid
))
7622 b
->thread
= pid_to_thread_id (inferior_ptid
);
7626 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7627 If from_tty is nonzero, it prints a message to that effect,
7628 which ends with a period (no newline). */
7631 set_ignore_count (int bptnum
, int count
, int from_tty
)
7633 struct breakpoint
*b
;
7639 if (b
->number
== bptnum
)
7641 b
->ignore_count
= count
;
7645 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7647 else if (count
== 1)
7648 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7651 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7654 breakpoints_changed ();
7655 observer_notify_breakpoint_modified (b
->number
);
7659 error (_("No breakpoint number %d."), bptnum
);
7662 /* Clear the ignore counts of all breakpoints. */
7664 breakpoint_clear_ignore_counts (void)
7666 struct breakpoint
*b
;
7669 b
->ignore_count
= 0;
7672 /* Command to set ignore-count of breakpoint N to COUNT. */
7675 ignore_command (char *args
, int from_tty
)
7681 error_no_arg (_("a breakpoint number"));
7683 num
= get_number (&p
);
7685 error (_("bad breakpoint number: '%s'"), args
);
7687 error (_("Second argument (specified ignore-count) is missing."));
7689 set_ignore_count (num
,
7690 longest_to_int (value_as_long (parse_and_eval (p
))),
7693 printf_filtered ("\n");
7696 /* Call FUNCTION on each of the breakpoints
7697 whose numbers are given in ARGS. */
7700 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7705 struct breakpoint
*b
, *tmp
;
7709 error_no_arg (_("one or more breakpoint numbers"));
7716 num
= get_number_or_range (&p1
);
7719 warning (_("bad breakpoint number at or near '%s'"), p
);
7723 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7724 if (b
->number
== num
)
7726 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7729 if (related_breakpoint
)
7730 function (related_breakpoint
);
7734 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7740 static struct bp_location
*
7741 find_location_by_number (char *number
)
7743 char *dot
= strchr (number
, '.');
7747 struct breakpoint
*b
;
7748 struct bp_location
*loc
;
7753 bp_num
= get_number_or_range (&p1
);
7755 error (_("Bad breakpoint number '%s'"), number
);
7758 if (b
->number
== bp_num
)
7763 if (!b
|| b
->number
!= bp_num
)
7764 error (_("Bad breakpoint number '%s'"), number
);
7767 loc_num
= get_number_or_range (&p1
);
7769 error (_("Bad breakpoint location number '%s'"), number
);
7773 for (;loc_num
&& loc
; --loc_num
, loc
= loc
->next
)
7776 error (_("Bad breakpoint location number '%s'"), dot
+1);
7782 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7783 If from_tty is nonzero, it prints a message to that effect,
7784 which ends with a period (no newline). */
7787 disable_breakpoint (struct breakpoint
*bpt
)
7789 /* Never disable a watchpoint scope breakpoint; we want to
7790 hit them when we leave scope so we can delete both the
7791 watchpoint and its scope breakpoint at that time. */
7792 if (bpt
->type
== bp_watchpoint_scope
)
7795 /* You can't disable permanent breakpoints. */
7796 if (bpt
->enable_state
== bp_permanent
)
7799 bpt
->enable_state
= bp_disabled
;
7801 update_global_location_list (0);
7803 observer_notify_breakpoint_modified (bpt
->number
);
7807 disable_command (char *args
, int from_tty
)
7809 struct breakpoint
*bpt
;
7811 ALL_BREAKPOINTS (bpt
)
7815 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7820 case bp_catch_unload
:
7822 case bp_catch_vfork
:
7824 case bp_hardware_breakpoint
:
7826 case bp_hardware_watchpoint
:
7827 case bp_read_watchpoint
:
7828 case bp_access_watchpoint
:
7829 disable_breakpoint (bpt
);
7833 else if (strchr (args
, '.'))
7835 struct bp_location
*loc
= find_location_by_number (args
);
7838 update_global_location_list (0);
7841 map_breakpoint_numbers (args
, disable_breakpoint
);
7845 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7847 int target_resources_ok
, other_type_used
;
7850 if (bpt
->type
== bp_hardware_breakpoint
)
7853 i
= hw_breakpoint_used_count ();
7854 target_resources_ok
=
7855 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7857 if (target_resources_ok
== 0)
7858 error (_("No hardware breakpoint support in the target."));
7859 else if (target_resources_ok
< 0)
7860 error (_("Hardware breakpoints used exceeds limit."));
7863 if (bpt
->type
== bp_watchpoint
||
7864 bpt
->type
== bp_hardware_watchpoint
||
7865 bpt
->type
== bp_read_watchpoint
||
7866 bpt
->type
== bp_access_watchpoint
)
7868 struct frame_id saved_frame_id
;
7870 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7871 if (bpt
->exp_valid_block
!= NULL
)
7873 struct frame_info
*fr
=
7874 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7877 printf_filtered (_("\
7878 Cannot enable watchpoint %d because the block in which its expression\n\
7879 is valid is not currently in scope.\n"), bpt
->number
);
7886 value_free (bpt
->val
);
7887 mark
= value_mark ();
7888 fetch_watchpoint_value (bpt
->exp
, &bpt
->val
, NULL
, NULL
);
7890 release_value (bpt
->val
);
7893 if (bpt
->type
== bp_hardware_watchpoint
||
7894 bpt
->type
== bp_read_watchpoint
||
7895 bpt
->type
== bp_access_watchpoint
)
7897 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7898 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7900 /* Hack around 'unused var' error for some targets here */
7901 (void) mem_cnt
, (void) i
;
7902 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7903 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7904 /* we can consider of type is bp_hardware_watchpoint, convert to
7905 bp_watchpoint in the following condition */
7906 if (target_resources_ok
< 0)
7908 printf_filtered (_("\
7909 Cannot enable watchpoint %d because target watch resources\n\
7910 have been allocated for other watchpoints.\n"), bpt
->number
);
7911 value_free_to_mark (mark
);
7916 select_frame (frame_find_by_id (saved_frame_id
));
7917 value_free_to_mark (mark
);
7920 if (bpt
->enable_state
!= bp_permanent
)
7921 bpt
->enable_state
= bp_enabled
;
7922 bpt
->disposition
= disposition
;
7923 update_global_location_list (1);
7924 breakpoints_changed ();
7926 observer_notify_breakpoint_modified (bpt
->number
);
7931 enable_breakpoint (struct breakpoint
*bpt
)
7933 do_enable_breakpoint (bpt
, bpt
->disposition
);
7936 /* The enable command enables the specified breakpoints (or all defined
7937 breakpoints) so they once again become (or continue to be) effective
7938 in stopping the inferior. */
7941 enable_command (char *args
, int from_tty
)
7943 struct breakpoint
*bpt
;
7945 ALL_BREAKPOINTS (bpt
)
7949 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7954 case bp_catch_unload
:
7956 case bp_catch_vfork
:
7958 case bp_hardware_breakpoint
:
7960 case bp_hardware_watchpoint
:
7961 case bp_read_watchpoint
:
7962 case bp_access_watchpoint
:
7963 enable_breakpoint (bpt
);
7967 else if (strchr (args
, '.'))
7969 struct bp_location
*loc
= find_location_by_number (args
);
7972 update_global_location_list (1);
7975 map_breakpoint_numbers (args
, enable_breakpoint
);
7979 enable_once_breakpoint (struct breakpoint
*bpt
)
7981 do_enable_breakpoint (bpt
, disp_disable
);
7985 enable_once_command (char *args
, int from_tty
)
7987 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7991 enable_delete_breakpoint (struct breakpoint
*bpt
)
7993 do_enable_breakpoint (bpt
, disp_del
);
7997 enable_delete_command (char *args
, int from_tty
)
7999 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
8003 set_breakpoint_cmd (char *args
, int from_tty
)
8008 show_breakpoint_cmd (char *args
, int from_tty
)
8012 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
8014 struct symtabs_and_lines
8015 decode_line_spec_1 (char *string
, int funfirstline
)
8017 struct symtabs_and_lines sals
;
8019 error (_("Empty line specification."));
8020 if (default_breakpoint_valid
)
8021 sals
= decode_line_1 (&string
, funfirstline
,
8022 default_breakpoint_symtab
,
8023 default_breakpoint_line
,
8024 (char ***) NULL
, NULL
);
8026 sals
= decode_line_1 (&string
, funfirstline
,
8027 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
8029 error (_("Junk at end of line specification: %s"), string
);
8033 /* Create and insert a raw software breakpoint at PC. Return an
8034 identifier, which should be used to remove the breakpoint later.
8035 In general, places which call this should be using something on the
8036 breakpoint chain instead; this function should be eliminated
8040 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
8042 struct bp_target_info
*bp_tgt
;
8044 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
8045 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
8047 bp_tgt
->placed_address
= pc
;
8048 if (target_insert_breakpoint (bp_tgt
) != 0)
8050 /* Could not insert the breakpoint. */
8058 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
8061 deprecated_remove_raw_breakpoint (void *bp
)
8063 struct bp_target_info
*bp_tgt
= bp
;
8066 ret
= target_remove_breakpoint (bp_tgt
);
8072 /* One (or perhaps two) breakpoints used for software single stepping. */
8074 static void *single_step_breakpoints
[2];
8076 /* Create and insert a breakpoint for software single step. */
8079 insert_single_step_breakpoint (CORE_ADDR next_pc
)
8083 if (single_step_breakpoints
[0] == NULL
)
8084 bpt_p
= &single_step_breakpoints
[0];
8087 gdb_assert (single_step_breakpoints
[1] == NULL
);
8088 bpt_p
= &single_step_breakpoints
[1];
8091 /* NOTE drow/2006-04-11: A future improvement to this function would be
8092 to only create the breakpoints once, and actually put them on the
8093 breakpoint chain. That would let us use set_raw_breakpoint. We could
8094 adjust the addresses each time they were needed. Doing this requires
8095 corresponding changes elsewhere where single step breakpoints are
8096 handled, however. So, for now, we use this. */
8098 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
8100 error (_("Could not insert single-step breakpoint at 0x%s"),
8101 paddr_nz (next_pc
));
8104 /* Remove and delete any breakpoints used for software single step. */
8107 remove_single_step_breakpoints (void)
8109 gdb_assert (single_step_breakpoints
[0] != NULL
);
8111 /* See insert_single_step_breakpoint for more about this deprecated
8113 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
8114 single_step_breakpoints
[0] = NULL
;
8116 if (single_step_breakpoints
[1] != NULL
)
8118 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
8119 single_step_breakpoints
[1] = NULL
;
8123 /* Check whether a software single-step breakpoint is inserted at PC. */
8126 single_step_breakpoint_inserted_here_p (CORE_ADDR pc
)
8130 for (i
= 0; i
< 2; i
++)
8132 struct bp_target_info
*bp_tgt
= single_step_breakpoints
[i
];
8133 if (bp_tgt
&& bp_tgt
->placed_address
== pc
)
8141 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
8142 It is defined as a macro to prevent duplication.
8143 COMMAND should be a string constant containing the name of the command. */
8144 #define BREAK_ARGS_HELP(command) \
8145 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
8146 LOCATION may be a line number, function name, or \"*\" and an address.\n\
8147 If a line number is specified, break at start of code for that line.\n\
8148 If a function is specified, break at start of code for that function.\n\
8149 If an address is specified, break at that exact address.\n\
8150 With no LOCATION, uses current execution address of selected stack frame.\n\
8151 This is useful for breaking on return to a stack frame.\n\
8153 THREADNUM is the number from \"info threads\".\n\
8154 CONDITION is a boolean expression.\n\
8156 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
8158 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
8160 /* List of subcommands for "catch". */
8161 static struct cmd_list_element
*catch_cmdlist
;
8163 /* List of subcommands for "tcatch". */
8164 static struct cmd_list_element
*tcatch_cmdlist
;
8166 /* Like add_cmd, but add the command to both the "catch" and "tcatch"
8167 lists, and pass some additional user data to the command function. */
8169 add_catch_command (char *name
, char *docstring
,
8170 void (*sfunc
) (char *args
, int from_tty
,
8171 struct cmd_list_element
*command
),
8172 void *user_data_catch
,
8173 void *user_data_tcatch
)
8175 struct cmd_list_element
*command
;
8177 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8179 set_cmd_sfunc (command
, sfunc
);
8180 set_cmd_context (command
, user_data_catch
);
8182 command
= add_cmd (name
, class_breakpoint
, NULL
, docstring
,
8184 set_cmd_sfunc (command
, sfunc
);
8185 set_cmd_context (command
, user_data_tcatch
);
8189 _initialize_breakpoint (void)
8191 static struct cmd_list_element
*breakpoint_set_cmdlist
;
8192 static struct cmd_list_element
*breakpoint_show_cmdlist
;
8193 struct cmd_list_element
*c
;
8195 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
8197 breakpoint_chain
= 0;
8198 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
8199 before a breakpoint is set. */
8200 breakpoint_count
= 0;
8202 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
8203 Set ignore-count of breakpoint number N to COUNT.\n\
8204 Usage is `ignore N COUNT'."));
8206 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
8208 add_com ("commands", class_breakpoint
, commands_command
, _("\
8209 Set commands to be executed when a breakpoint is hit.\n\
8210 Give breakpoint number as argument after \"commands\".\n\
8211 With no argument, the targeted breakpoint is the last one set.\n\
8212 The commands themselves follow starting on the next line.\n\
8213 Type a line containing \"end\" to indicate the end of them.\n\
8214 Give \"silent\" as the first line to make the breakpoint silent;\n\
8215 then no output is printed when it is hit, except what the commands print."));
8217 add_com ("condition", class_breakpoint
, condition_command
, _("\
8218 Specify breakpoint number N to break only if COND is true.\n\
8219 Usage is `condition N COND', where N is an integer and COND is an\n\
8220 expression to be evaluated whenever breakpoint N is reached."));
8222 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
8223 Set a temporary breakpoint.\n\
8224 Like \"break\" except the breakpoint is only temporary,\n\
8225 so it will be deleted when hit. Equivalent to \"break\" followed\n\
8226 by using \"enable delete\" on the breakpoint number.\n\
8228 BREAK_ARGS_HELP ("tbreak")));
8229 set_cmd_completer (c
, location_completer
);
8231 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
8232 Set a hardware assisted breakpoint.\n\
8233 Like \"break\" except the breakpoint requires hardware support,\n\
8234 some target hardware may not have this support.\n\
8236 BREAK_ARGS_HELP ("hbreak")));
8237 set_cmd_completer (c
, location_completer
);
8239 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
8240 Set a temporary hardware assisted breakpoint.\n\
8241 Like \"hbreak\" except the breakpoint is only temporary,\n\
8242 so it will be deleted when hit.\n\
8244 BREAK_ARGS_HELP ("thbreak")));
8245 set_cmd_completer (c
, location_completer
);
8247 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
8248 Enable some breakpoints.\n\
8249 Give breakpoint numbers (separated by spaces) as arguments.\n\
8250 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8251 This is used to cancel the effect of the \"disable\" command.\n\
8252 With a subcommand you can enable temporarily."),
8253 &enablelist
, "enable ", 1, &cmdlist
);
8255 add_com ("ab", class_breakpoint
, enable_command
, _("\
8256 Enable some breakpoints.\n\
8257 Give breakpoint numbers (separated by spaces) as arguments.\n\
8258 With no subcommand, breakpoints are enabled until you command otherwise.\n\
8259 This is used to cancel the effect of the \"disable\" command.\n\
8260 With a subcommand you can enable temporarily."));
8262 add_com_alias ("en", "enable", class_breakpoint
, 1);
8264 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
8265 Enable some breakpoints.\n\
8266 Give breakpoint numbers (separated by spaces) as arguments.\n\
8267 This is used to cancel the effect of the \"disable\" command.\n\
8268 May be abbreviated to simply \"enable\".\n"),
8269 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
8271 add_cmd ("once", no_class
, enable_once_command
, _("\
8272 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8273 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8276 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8277 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8278 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8281 add_cmd ("delete", no_class
, enable_delete_command
, _("\
8282 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
8283 If a breakpoint is hit while enabled in this fashion, it is deleted."),
8286 add_cmd ("once", no_class
, enable_once_command
, _("\
8287 Enable breakpoints for one hit. Give breakpoint numbers.\n\
8288 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
8291 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
8292 Disable some breakpoints.\n\
8293 Arguments are breakpoint numbers with spaces in between.\n\
8294 To disable all breakpoints, give no argument.\n\
8295 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
8296 &disablelist
, "disable ", 1, &cmdlist
);
8297 add_com_alias ("dis", "disable", class_breakpoint
, 1);
8298 add_com_alias ("disa", "disable", class_breakpoint
, 1);
8300 add_com ("sb", class_breakpoint
, disable_command
, _("\
8301 Disable some breakpoints.\n\
8302 Arguments are breakpoint numbers with spaces in between.\n\
8303 To disable all breakpoints, give no argument.\n\
8304 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
8306 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
8307 Disable some breakpoints.\n\
8308 Arguments are breakpoint numbers with spaces in between.\n\
8309 To disable all breakpoints, give no argument.\n\
8310 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
8311 This command may be abbreviated \"disable\"."),
8314 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
8315 Delete some breakpoints or auto-display expressions.\n\
8316 Arguments are breakpoint numbers with spaces in between.\n\
8317 To delete all breakpoints, give no argument.\n\
8319 Also a prefix command for deletion of other GDB objects.\n\
8320 The \"unset\" command is also an alias for \"delete\"."),
8321 &deletelist
, "delete ", 1, &cmdlist
);
8322 add_com_alias ("d", "delete", class_breakpoint
, 1);
8323 add_com_alias ("del", "delete", class_breakpoint
, 1);
8325 add_com ("db", class_breakpoint
, delete_command
, _("\
8326 Delete some breakpoints.\n\
8327 Arguments are breakpoint numbers with spaces in between.\n\
8328 To delete all breakpoints, give no argument.\n"));
8330 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
8331 Delete some breakpoints or auto-display expressions.\n\
8332 Arguments are breakpoint numbers with spaces in between.\n\
8333 To delete all breakpoints, give no argument.\n\
8334 This command may be abbreviated \"delete\"."),
8337 add_com ("clear", class_breakpoint
, clear_command
, _("\
8338 Clear breakpoint at specified line or function.\n\
8339 Argument may be line number, function name, or \"*\" and an address.\n\
8340 If line number is specified, all breakpoints in that line are cleared.\n\
8341 If function is specified, breakpoints at beginning of function are cleared.\n\
8342 If an address is specified, breakpoints at that address are cleared.\n\
8344 With no argument, clears all breakpoints in the line that the selected frame\n\
8347 See also the \"delete\" command which clears breakpoints by number."));
8349 c
= add_com ("break", class_breakpoint
, break_command
, _("\
8350 Set breakpoint at specified line or function.\n"
8351 BREAK_ARGS_HELP ("break")));
8352 set_cmd_completer (c
, location_completer
);
8354 add_com_alias ("b", "break", class_run
, 1);
8355 add_com_alias ("br", "break", class_run
, 1);
8356 add_com_alias ("bre", "break", class_run
, 1);
8357 add_com_alias ("brea", "break", class_run
, 1);
8361 add_com_alias ("ba", "break", class_breakpoint
, 1);
8362 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
8367 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
8368 Break in function/address or break at a line in the current file."),
8369 &stoplist
, "stop ", 1, &cmdlist
);
8370 add_cmd ("in", class_breakpoint
, stopin_command
,
8371 _("Break in function or address."), &stoplist
);
8372 add_cmd ("at", class_breakpoint
, stopat_command
,
8373 _("Break at a line in the current file."), &stoplist
);
8374 add_com ("status", class_info
, breakpoints_info
, _("\
8375 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8376 The \"Type\" column indicates one of:\n\
8377 \tbreakpoint - normal breakpoint\n\
8378 \twatchpoint - watchpoint\n\
8379 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8380 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8381 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8382 address and file/line number respectively.\n\
8384 Convenience variable \"$_\" and default examine address for \"x\"\n\
8385 are set to the address of the last breakpoint listed unless the command\n\
8386 is prefixed with \"server \".\n\n\
8387 Convenience variable \"$bpnum\" contains the number of the last\n\
8391 add_info ("breakpoints", breakpoints_info
, _("\
8392 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8393 The \"Type\" column indicates one of:\n\
8394 \tbreakpoint - normal breakpoint\n\
8395 \twatchpoint - watchpoint\n\
8396 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8397 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8398 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8399 address and file/line number respectively.\n\
8401 Convenience variable \"$_\" and default examine address for \"x\"\n\
8402 are set to the address of the last breakpoint listed unless the command\n\
8403 is prefixed with \"server \".\n\n\
8404 Convenience variable \"$bpnum\" contains the number of the last\n\
8408 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
8409 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
8410 The \"Type\" column indicates one of:\n\
8411 \tbreakpoint - normal breakpoint\n\
8412 \twatchpoint - watchpoint\n\
8413 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8414 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8415 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8416 address and file/line number respectively.\n\
8418 Convenience variable \"$_\" and default examine address for \"x\"\n\
8419 are set to the address of the last breakpoint listed unless the command\n\
8420 is prefixed with \"server \".\n\n\
8421 Convenience variable \"$bpnum\" contains the number of the last\n\
8424 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
8425 Status of all breakpoints, or breakpoint number NUMBER.\n\
8426 The \"Type\" column indicates one of:\n\
8427 \tbreakpoint - normal breakpoint\n\
8428 \twatchpoint - watchpoint\n\
8429 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8430 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8431 \tuntil - internal breakpoint used by the \"until\" command\n\
8432 \tfinish - internal breakpoint used by the \"finish\" command\n\
8433 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8434 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8435 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8436 address and file/line number respectively.\n\
8438 Convenience variable \"$_\" and default examine address for \"x\"\n\
8439 are set to the address of the last breakpoint listed unless the command\n\
8440 is prefixed with \"server \".\n\n\
8441 Convenience variable \"$bpnum\" contains the number of the last\n\
8443 &maintenanceinfolist
);
8445 add_prefix_cmd ("catch", class_breakpoint
, catch_command
, _("\
8446 Set catchpoints to catch events."),
8447 &catch_cmdlist
, "catch ",
8448 0/*allow-unknown*/, &cmdlist
);
8450 add_prefix_cmd ("tcatch", class_breakpoint
, tcatch_command
, _("\
8451 Set temporary catchpoints to catch events."),
8452 &tcatch_cmdlist
, "tcatch ",
8453 0/*allow-unknown*/, &cmdlist
);
8455 /* Add catch and tcatch sub-commands. */
8456 add_catch_command ("catch", _("\
8457 Catch an exception, when caught.\n\
8458 With an argument, catch only exceptions with the given name."),
8459 catch_catch_command
,
8462 add_catch_command ("throw", _("\
8463 Catch an exception, when thrown.\n\
8464 With an argument, catch only exceptions with the given name."),
8465 catch_throw_command
,
8468 add_catch_command ("fork", _("Catch calls to fork."),
8469 catch_fork_command_1
,
8470 (void *) (uintptr_t) catch_fork_permanent
,
8471 (void *) (uintptr_t) catch_fork_temporary
);
8472 add_catch_command ("vfork", _("Catch calls to vfork."),
8473 catch_fork_command_1
,
8474 (void *) (uintptr_t) catch_vfork_permanent
,
8475 (void *) (uintptr_t) catch_vfork_temporary
);
8476 add_catch_command ("exec", _("Catch calls to exec."),
8477 catch_exec_command_1
,
8480 add_catch_command ("load", _("\
8481 Catch library loads.\n\
8482 With an argument, catch only loads of that library."),
8483 catch_load_command_1
,
8486 add_catch_command ("unload", _("\
8487 Catch library unloads.\n\
8488 With an argument, catch only unloads of that library."),
8489 catch_unload_command_1
,
8492 add_catch_command ("exception", _("\
8493 Catch Ada exceptions, when raised.\n\
8494 With an argument, catch only exceptions with the given name."),
8495 catch_ada_exception_command
,
8498 add_catch_command ("assert", _("\
8499 Catch failed Ada assertions, when raised.\n\
8500 With an argument, catch only exceptions with the given name."),
8501 catch_assert_command
,
8505 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8506 Set a watchpoint for an expression.\n\
8507 A watchpoint stops execution of your program whenever the value of\n\
8508 an expression changes."));
8509 set_cmd_completer (c
, expression_completer
);
8511 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8512 Set a read watchpoint for an expression.\n\
8513 A watchpoint stops execution of your program whenever the value of\n\
8514 an expression is read."));
8515 set_cmd_completer (c
, expression_completer
);
8517 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8518 Set a watchpoint for an expression.\n\
8519 A watchpoint stops execution of your program whenever the value of\n\
8520 an expression is either read or written."));
8521 set_cmd_completer (c
, expression_completer
);
8523 add_info ("watchpoints", breakpoints_info
,
8524 _("Synonym for ``info breakpoints''."));
8527 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8528 respond to changes - contrary to the description. */
8529 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8530 &can_use_hw_watchpoints
, _("\
8531 Set debugger's willingness to use watchpoint hardware."), _("\
8532 Show debugger's willingness to use watchpoint hardware."), _("\
8533 If zero, gdb will not use hardware for new watchpoints, even if\n\
8534 such is available. (However, any hardware watchpoints that were\n\
8535 created before setting this to nonzero, will continue to use watchpoint\n\
8538 show_can_use_hw_watchpoints
,
8539 &setlist
, &showlist
);
8541 can_use_hw_watchpoints
= 1;
8543 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8544 Breakpoint specific settings\n\
8545 Configure various breakpoint-specific variables such as\n\
8546 pending breakpoint behavior"),
8547 &breakpoint_set_cmdlist
, "set breakpoint ",
8548 0/*allow-unknown*/, &setlist
);
8549 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8550 Breakpoint specific settings\n\
8551 Configure various breakpoint-specific variables such as\n\
8552 pending breakpoint behavior"),
8553 &breakpoint_show_cmdlist
, "show breakpoint ",
8554 0/*allow-unknown*/, &showlist
);
8556 add_setshow_auto_boolean_cmd ("pending", no_class
,
8557 &pending_break_support
, _("\
8558 Set debugger's behavior regarding pending breakpoints."), _("\
8559 Show debugger's behavior regarding pending breakpoints."), _("\
8560 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8561 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8562 an error. If auto, an unrecognized breakpoint location results in a\n\
8563 user-query to see if a pending breakpoint should be created."),
8565 show_pending_break_support
,
8566 &breakpoint_set_cmdlist
,
8567 &breakpoint_show_cmdlist
);
8569 pending_break_support
= AUTO_BOOLEAN_AUTO
;
8571 add_setshow_boolean_cmd ("auto-hw", no_class
,
8572 &automatic_hardware_breakpoints
, _("\
8573 Set automatic usage of hardware breakpoints."), _("\
8574 Show automatic usage of hardware breakpoints."), _("\
8575 If set, the debugger will automatically use hardware breakpoints for\n\
8576 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\
8577 a warning will be emitted for such breakpoints."),
8579 show_automatic_hardware_breakpoints
,
8580 &breakpoint_set_cmdlist
,
8581 &breakpoint_show_cmdlist
);
8583 add_setshow_enum_cmd ("always-inserted", class_support
,
8584 always_inserted_enums
, &always_inserted_mode
, _("\
8585 Set mode for inserting breakpoints."), _("\
8586 Show mode for inserting breakpoints."), _("\
8587 When this mode is off, breakpoints are inserted in inferior when it is\n\
8588 resumed, and removed when execution stops. When this mode is on,\n\
8589 breakpoints are inserted immediately and removed only when the user\n\
8590 deletes the breakpoint. When this mode is auto (which is the default),\n\
8591 the behaviour depends on the non-stop setting (see help set non-stop).\n\
8592 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\
8593 behaves as if always-inserted mode is on; if gdb is controlling the\n\
8594 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."),
8596 &show_always_inserted_mode
,
8597 &breakpoint_set_cmdlist
,
8598 &breakpoint_show_cmdlist
);
8600 automatic_hardware_breakpoints
= 1;