1 /* Everything about breakpoints, for GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
5 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 2 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, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
55 #include "exceptions.h"
57 #include "gdb-events.h"
58 #include "mi/mi-common.h"
60 /* Prototypes for local functions. */
62 static void until_break_command_continuation (struct continuation_arg
*arg
);
64 static void catch_command_1 (char *, int, int);
66 static void enable_delete_command (char *, int);
68 static void enable_delete_breakpoint (struct breakpoint
*);
70 static void enable_once_command (char *, int);
72 static void enable_once_breakpoint (struct breakpoint
*);
74 static void disable_command (char *, int);
76 static void enable_command (char *, int);
78 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
80 static void ignore_command (char *, int);
82 static int breakpoint_re_set_one (void *);
84 static void clear_command (char *, int);
86 static void catch_command (char *, int);
88 static void watch_command (char *, int);
90 static int can_use_hardware_watchpoint (struct value
*);
92 static int break_command_1 (char *, int, int, struct breakpoint
*);
94 static void mention (struct breakpoint
*);
96 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
98 static void check_duplicates (struct breakpoint
*);
100 static void breakpoint_adjustment_warning (CORE_ADDR
, CORE_ADDR
, int, int);
102 static CORE_ADDR
adjust_breakpoint_address (CORE_ADDR bpaddr
,
105 static void describe_other_breakpoints (CORE_ADDR
, asection
*);
107 static void breakpoints_info (char *, int);
109 static void breakpoint_1 (int, int);
111 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
113 static int breakpoint_cond_eval (void *);
115 static void cleanup_executing_breakpoints (void *);
117 static void commands_command (char *, int);
119 static void condition_command (char *, int);
121 static int get_number_trailer (char **, int);
123 void set_breakpoint_count (int);
132 static int remove_breakpoint (struct bp_location
*, insertion_state_t
);
134 static enum print_stop_action
print_it_typical (bpstat
);
136 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
140 enum exception_event_kind kind
;
143 args_for_catchpoint_enable
;
145 static int watchpoint_check (void *);
147 static int cover_target_enable_exception_callback (void *);
149 static void maintenance_info_breakpoints (char *, int);
151 static void create_longjmp_breakpoint (char *);
153 static void create_overlay_event_breakpoint (char *);
155 static int hw_breakpoint_used_count (void);
157 static int hw_watchpoint_used_count (enum bptype
, int *);
159 static void hbreak_command (char *, int);
161 static void thbreak_command (char *, int);
163 static void watch_command_1 (char *, int, int);
165 static void rwatch_command (char *, int);
167 static void awatch_command (char *, int);
169 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
171 static void solib_load_unload_1 (char *hookname
,
174 char *cond_string
, enum bptype bp_kind
);
176 static void create_fork_vfork_event_catchpoint (int tempflag
,
178 enum bptype bp_kind
);
180 static void stop_command (char *arg
, int from_tty
);
182 static void stopin_command (char *arg
, int from_tty
);
184 static void stopat_command (char *arg
, int from_tty
);
186 static char *ep_find_event_name_end (char *arg
);
188 static char *ep_parse_optional_if_clause (char **arg
);
190 static char *ep_parse_optional_filename (char **arg
);
192 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
193 enum exception_event_kind ex_event
,
194 struct symtab_and_line
*sal
);
196 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
197 char *arg
, int tempflag
, int from_tty
);
199 static void tcatch_command (char *arg
, int from_tty
);
201 static void ep_skip_leading_whitespace (char **s
);
203 /* Prototypes for exported functions. */
205 /* If FALSE, gdb will not use hardware support for watchpoints, even
206 if such is available. */
207 static int can_use_hw_watchpoints
;
210 show_can_use_hw_watchpoints (struct ui_file
*file
, int from_tty
,
211 struct cmd_list_element
*c
,
214 fprintf_filtered (file
, _("\
215 Debugger's willingness to use watchpoint hardware is %s.\n"),
219 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints.
220 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints
221 for unrecognized breakpoint locations.
222 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */
223 static enum auto_boolean pending_break_support
;
225 show_pending_break_support (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
,
229 fprintf_filtered (file
, _("\
230 Debugger's behavior regarding pending breakpoints is %s.\n"),
234 void _initialize_breakpoint (void);
236 extern int addressprint
; /* Print machine addresses? */
238 /* Are we executing breakpoint commands? */
239 static int executing_breakpoint_commands
;
241 /* Are overlay event breakpoints enabled? */
242 static int overlay_events_enabled
;
244 /* Walk the following statement or block through all breakpoints.
245 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
248 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
250 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
251 for (B = breakpoint_chain; \
252 B ? (TMP=B->next, 1): 0; \
255 /* Similar iterators for the low-level breakpoints. */
257 #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next)
259 #define ALL_BP_LOCATIONS_SAFE(B,TMP) \
260 for (B = bp_location_chain; \
261 B ? (TMP=B->next, 1): 0; \
264 /* True if breakpoint hit counts should be displayed in breakpoint info. */
266 int show_breakpoint_hit_counts
= 1;
268 /* Chains of all breakpoints defined. */
270 struct breakpoint
*breakpoint_chain
;
272 struct bp_location
*bp_location_chain
;
274 /* Number of last breakpoint made. */
276 int breakpoint_count
;
278 /* Pointer to current exception event record */
279 static struct exception_event_record
*current_exception_event
;
281 /* Indicator of whether exception catchpoints should be nuked between
282 runs of a program. */
283 int deprecated_exception_catchpoints_are_fragile
= 0;
285 /* Indicator of when exception catchpoints set-up should be
286 reinitialized -- e.g. when program is re-run. */
287 int deprecated_exception_support_initialized
= 0;
289 /* This function returns a pointer to the string representation of the
290 pathname of the dynamically-linked library that has just been
293 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
294 or undefined results are guaranteed.
296 This string's contents are only valid immediately after the
297 inferior has stopped in the dynamic linker hook, and becomes
298 invalid as soon as the inferior is continued. Clients should make
299 a copy of this string if they wish to continue the inferior and
300 then access the string. */
302 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
303 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
306 /* This function returns a pointer to the string representation of the
307 pathname of the dynamically-linked library that has just been
310 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
311 TRUE, or undefined results are guaranteed.
313 This string's contents are only valid immediately after the
314 inferior has stopped in the dynamic linker hook, and becomes
315 invalid as soon as the inferior is continued. Clients should make
316 a copy of this string if they wish to continue the inferior and
317 then access the string. */
319 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
320 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
323 /* This function is called by the "catch load" command. It allows the
324 debugger to be notified by the dynamic linker when a specified
325 library file (or any library file, if filename is NULL) is loaded. */
327 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
328 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
329 error (_("catch of library loads not yet implemented on this platform"))
332 /* This function is called by the "catch unload" command. It allows
333 the debugger to be notified by the dynamic linker when a specified
334 library file (or any library file, if filename is NULL) is
337 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
338 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid, tempflag, filename, cond_string) \
339 error (_("catch of library unloads not yet implemented on this platform"))
342 /* Return whether a breakpoint is an active enabled breakpoint. */
344 breakpoint_enabled (struct breakpoint
*b
)
346 return (b
->enable_state
== bp_enabled
&& !b
->pending
);
349 /* Set breakpoint count to NUM. */
352 set_breakpoint_count (int num
)
354 breakpoint_count
= num
;
355 set_internalvar (lookup_internalvar ("bpnum"),
356 value_from_longest (builtin_type_int
, (LONGEST
) num
));
359 /* Used in run_command to zero the hit count when a new run starts. */
362 clear_breakpoint_hit_counts (void)
364 struct breakpoint
*b
;
370 /* Default address, symtab and line to put a breakpoint at
371 for "break" command with no arg.
372 if default_breakpoint_valid is zero, the other three are
373 not valid, and "break" with no arg is an error.
375 This set by print_stack_frame, which calls set_default_breakpoint. */
377 int default_breakpoint_valid
;
378 CORE_ADDR default_breakpoint_address
;
379 struct symtab
*default_breakpoint_symtab
;
380 int default_breakpoint_line
;
382 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
383 Advance *PP after the string and any trailing whitespace.
385 Currently the string can either be a number or "$" followed by the name
386 of a convenience variable. Making it an expression wouldn't work well
387 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
389 TRAILER is a character which can be found after the number; most
390 commonly this is `-'. If you don't want a trailer, use \0. */
392 get_number_trailer (char **pp
, int trailer
)
394 int retval
= 0; /* default */
398 /* Empty line means refer to the last breakpoint. */
399 return breakpoint_count
;
402 /* Make a copy of the name, so we can null-terminate it
403 to pass to lookup_internalvar(). */
408 while (isalnum (*p
) || *p
== '_')
410 varname
= (char *) alloca (p
- start
+ 1);
411 strncpy (varname
, start
, p
- start
);
412 varname
[p
- start
] = '\0';
413 val
= value_of_internalvar (lookup_internalvar (varname
));
414 if (TYPE_CODE (value_type (val
)) == TYPE_CODE_INT
)
415 retval
= (int) value_as_long (val
);
418 printf_filtered (_("Convenience variable must have integer value.\n"));
426 while (*p
>= '0' && *p
<= '9')
429 /* There is no number here. (e.g. "cond a == b"). */
431 /* Skip non-numeric token */
432 while (*p
&& !isspace((int) *p
))
434 /* Return zero, which caller must interpret as error. */
440 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
442 /* Trailing junk: return 0 and let caller print error msg. */
443 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
454 /* Like get_number_trailer, but don't allow a trailer. */
456 get_number (char **pp
)
458 return get_number_trailer (pp
, '\0');
461 /* Parse a number or a range.
462 * A number will be of the form handled by get_number.
463 * A range will be of the form <number1> - <number2>, and
464 * will represent all the integers between number1 and number2,
467 * While processing a range, this fuction is called iteratively;
468 * At each call it will return the next value in the range.
470 * At the beginning of parsing a range, the char pointer PP will
471 * be advanced past <number1> and left pointing at the '-' token.
472 * Subsequent calls will not advance the pointer until the range
473 * is completed. The call that completes the range will advance
474 * pointer PP past <number2>.
478 get_number_or_range (char **pp
)
480 static int last_retval
, end_value
;
481 static char *end_ptr
;
482 static int in_range
= 0;
486 /* Default case: pp is pointing either to a solo number,
487 or to the first number of a range. */
488 last_retval
= get_number_trailer (pp
, '-');
493 /* This is the start of a range (<number1> - <number2>).
494 Skip the '-', parse and remember the second number,
495 and also remember the end of the final token. */
499 while (isspace ((int) *end_ptr
))
500 end_ptr
++; /* skip white space */
501 end_value
= get_number (temp
);
502 if (end_value
< last_retval
)
504 error (_("inverted range"));
506 else if (end_value
== last_retval
)
508 /* degenerate range (number1 == number2). Advance the
509 token pointer so that the range will be treated as a
518 error (_("negative value"));
521 /* pp points to the '-' that betokens a range. All
522 number-parsing has already been done. Return the next
523 integer value (one greater than the saved previous value).
524 Do not advance the token pointer 'pp' until the end of range
527 if (++last_retval
== end_value
)
529 /* End of range reached; advance token pointer. */
539 /* condition N EXP -- set break condition of breakpoint N to EXP. */
542 condition_command (char *arg
, int from_tty
)
544 struct breakpoint
*b
;
549 error_no_arg (_("breakpoint number"));
552 bnum
= get_number (&p
);
554 error (_("Bad breakpoint argument: '%s'"), arg
);
557 if (b
->number
== bnum
)
564 if (b
->cond_string
!= NULL
)
565 xfree (b
->cond_string
);
570 b
->cond_string
= NULL
;
572 printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum
);
577 /* I don't know if it matters whether this is the string the user
578 typed in or the decompiled expression. */
579 b
->cond_string
= savestring (arg
, strlen (arg
));
582 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
584 error (_("Junk at end of expression"));
587 breakpoints_changed ();
588 breakpoint_modify_event (b
->number
);
592 error (_("No breakpoint number %d."), bnum
);
596 commands_command (char *arg
, int from_tty
)
598 struct breakpoint
*b
;
601 struct command_line
*l
;
603 /* If we allowed this, we would have problems with when to
604 free the storage, if we change the commands currently
607 if (executing_breakpoint_commands
)
608 error (_("Can't use the \"commands\" command among a breakpoint's commands."));
611 bnum
= get_number (&p
);
614 error (_("Unexpected extra arguments following breakpoint number."));
617 if (b
->number
== bnum
)
619 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
621 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
622 l
= read_command_lines (tmpbuf
, from_tty
);
623 do_cleanups (cleanups
);
624 free_command_lines (&b
->commands
);
626 breakpoints_changed ();
627 breakpoint_modify_event (b
->number
);
630 error (_("No breakpoint number %d."), bnum
);
633 /* Like target_read_memory() but if breakpoints are inserted, return
634 the shadow contents instead of the breakpoints themselves.
636 Read "memory data" from whatever target or inferior we have.
637 Returns zero if successful, errno value if not. EIO is used
638 for address out of bounds. If breakpoints are inserted, returns
639 shadow contents, not the breakpoints themselves. From breakpoint.c. */
642 deprecated_read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
,
646 struct bp_location
*b
;
647 CORE_ADDR bp_addr
= 0;
650 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
651 /* No breakpoints on this machine. */
652 return target_read_memory (memaddr
, myaddr
, len
);
656 if (b
->owner
->type
== bp_none
)
657 warning (_("reading through apparently deleted breakpoint #%d?"),
660 if (b
->loc_type
!= bp_loc_software_breakpoint
)
664 /* Addresses and length of the part of the breakpoint that
666 bp_addr
= b
->target_info
.placed_address
;
667 bp_size
= b
->target_info
.shadow_len
;
669 /* bp isn't valid, or doesn't shadow memory. */
671 if (bp_addr
+ bp_size
<= memaddr
)
672 /* The breakpoint is entirely before the chunk of memory we
675 if (bp_addr
>= memaddr
+ len
)
676 /* The breakpoint is entirely after the chunk of memory we are
679 /* Copy the breakpoint from the shadow contents, and recurse for
680 the things before and after. */
682 /* Offset within shadow_contents. */
685 if (bp_addr
< memaddr
)
687 /* Only copy the second part of the breakpoint. */
688 bp_size
-= memaddr
- bp_addr
;
689 bptoffset
= memaddr
- bp_addr
;
693 if (bp_addr
+ bp_size
> memaddr
+ len
)
695 /* Only copy the first part of the breakpoint. */
696 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
699 memcpy (myaddr
+ bp_addr
- memaddr
,
700 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
702 if (bp_addr
> memaddr
)
704 /* Copy the section of memory before the breakpoint. */
705 status
= deprecated_read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
710 if (bp_addr
+ bp_size
< memaddr
+ len
)
712 /* Copy the section of memory after the breakpoint. */
713 status
= deprecated_read_memory_nobpt (bp_addr
+ bp_size
,
714 myaddr
+ bp_addr
+ bp_size
- memaddr
,
715 memaddr
+ len
- (bp_addr
+ bp_size
));
722 /* Nothing overlaps. Just call read_memory_noerr. */
723 return target_read_memory (memaddr
, myaddr
, len
);
727 /* A wrapper function for inserting catchpoints. */
729 insert_catchpoint (struct ui_out
*uo
, void *args
)
731 struct breakpoint
*b
= (struct breakpoint
*) args
;
737 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
740 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
743 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
746 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
751 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
753 static void free_valchain (struct bp_location
*b
)
758 /* Free the saved value chain. We will construct a new one
759 the next time the watchpoint is inserted. */
760 for (v
= b
->owner
->val_chain
; v
; v
= n
)
765 b
->owner
->val_chain
= NULL
;
768 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
769 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
770 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
772 NOTE drow/2003-09-09: This routine could be broken down to an object-style
773 method for each breakpoint or catchpoint type. */
775 insert_bp_location (struct bp_location
*bpt
,
776 struct ui_file
*tmp_error_stream
,
777 int *disabled_breaks
, int *process_warning
,
778 int *hw_breakpoint_error
)
782 /* Permanent breakpoints cannot be inserted or removed. Disabled
783 breakpoints should not be inserted. */
784 if (!breakpoint_enabled (bpt
->owner
))
787 if (bpt
->inserted
|| bpt
->duplicate
)
790 /* Initialize the target-specific information. */
791 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
792 bpt
->target_info
.placed_address
= bpt
->address
;
794 if (bpt
->loc_type
== bp_loc_software_breakpoint
795 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
797 /* First check to see if we have to handle an overlay. */
798 if (overlay_debugging
== ovly_off
799 || bpt
->section
== NULL
800 || !(section_is_overlay (bpt
->section
)))
802 /* No overlay handling: just set the breakpoint. */
804 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
805 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
807 val
= target_insert_breakpoint (&bpt
->target_info
);
811 /* This breakpoint is in an overlay section.
812 Shall we set a breakpoint at the LMA? */
813 if (!overlay_events_enabled
)
815 /* Yes -- overlay event support is not active,
816 so we must try to set a breakpoint at the LMA.
817 This will not work for a hardware breakpoint. */
818 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
819 warning (_("hardware breakpoint %d not supported in overlay!"),
823 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
825 /* Set a software (trap) breakpoint at the LMA. */
826 bpt
->overlay_target_info
= bpt
->target_info
;
827 bpt
->overlay_target_info
.placed_address
= addr
;
828 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
830 fprintf_unfiltered (tmp_error_stream
,
831 "Overlay breakpoint %d failed: in ROM?",
835 /* Shall we set a breakpoint at the VMA? */
836 if (section_is_mapped (bpt
->section
))
838 /* Yes. This overlay section is mapped into memory. */
839 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
840 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
842 val
= target_insert_breakpoint (&bpt
->target_info
);
846 /* No. This breakpoint will not be inserted.
847 No error, but do not mark the bp as 'inserted'. */
854 /* Can't set the breakpoint. */
856 #if defined (DISABLE_UNSETTABLE_BREAK)
857 DISABLE_UNSETTABLE_BREAK (bpt
->address
)
859 solib_address (bpt
->address
)
863 /* See also: disable_breakpoints_in_shlibs. */
865 bpt
->owner
->enable_state
= bp_shlib_disabled
;
866 if (!*disabled_breaks
)
868 fprintf_unfiltered (tmp_error_stream
,
869 "Cannot insert breakpoint %d.\n",
871 fprintf_unfiltered (tmp_error_stream
,
872 "Temporarily disabling shared library breakpoints:\n");
874 *disabled_breaks
= 1;
875 fprintf_unfiltered (tmp_error_stream
,
876 "breakpoint #%d\n", bpt
->owner
->number
);
880 #ifdef ONE_PROCESS_WRITETEXT
881 *process_warning
= 1;
883 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
885 *hw_breakpoint_error
= 1;
886 fprintf_unfiltered (tmp_error_stream
,
887 "Cannot insert hardware breakpoint %d.\n",
892 fprintf_unfiltered (tmp_error_stream
,
893 "Cannot insert breakpoint %d.\n",
895 fprintf_filtered (tmp_error_stream
,
896 "Error accessing memory address ");
897 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
898 fprintf_filtered (tmp_error_stream
, ": %s.\n",
899 safe_strerror (val
));
910 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
911 /* NOTE drow/2003-09-08: This state only exists for removing
912 watchpoints. It's not clear that it's necessary... */
913 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
915 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
916 based on the expression. Ideally this should happen at a higher level,
917 and there should be one bp_location for each computed address we
918 must watch. As soon as a many-to-one mapping is available I'll
921 int within_current_scope
;
922 struct value
*mark
= value_mark ();
924 struct frame_id saved_frame_id
;
926 /* Save the current frame's ID so we can restore it after
927 evaluating the watchpoint expression on its own frame. */
928 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
929 took a frame parameter, so that we didn't have to change the
931 saved_frame_id
= get_frame_id (deprecated_selected_frame
);
933 /* Determine if the watchpoint is within scope. */
934 if (bpt
->owner
->exp_valid_block
== NULL
)
935 within_current_scope
= 1;
938 struct frame_info
*fi
;
939 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
940 within_current_scope
= (fi
!= NULL
);
941 if (within_current_scope
)
945 if (within_current_scope
)
949 /* Evaluate the expression and cut the chain of values
950 produced off from the value chain.
952 Make sure the value returned isn't lazy; we use
953 laziness to determine what memory GDB actually needed
954 in order to compute the value of the expression. */
955 v
= evaluate_expression (bpt
->owner
->exp
);
957 value_release_to_mark (mark
);
959 bpt
->owner
->val_chain
= v
;
962 /* Look at each value on the value chain. */
963 for (; v
; v
= value_next (v
))
965 /* If it's a memory location, and GDB actually needed
966 its contents to evaluate the expression, then we
968 if (VALUE_LVAL (v
) == lval_memory
971 struct type
*vtype
= check_typedef (value_type (v
));
973 /* We only watch structs and arrays if user asked
974 for it explicitly, never if they just happen to
975 appear in the middle of some value chain. */
976 if (v
== bpt
->owner
->val_chain
977 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
978 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
983 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
984 len
= TYPE_LENGTH (value_type (v
));
986 if (bpt
->owner
->type
== bp_read_watchpoint
)
988 else if (bpt
->owner
->type
== bp_access_watchpoint
)
991 val
= target_insert_watchpoint (addr
, len
, type
);
994 /* Don't exit the loop, try to insert
995 every value on the value chain. That's
996 because we will be removing all the
997 watches below, and removing a
998 watchpoint we didn't insert could have
1006 /* Failure to insert a watchpoint on any memory value in the
1007 value chain brings us here. */
1010 remove_breakpoint (bpt
, mark_uninserted
);
1011 *hw_breakpoint_error
= 1;
1012 fprintf_unfiltered (tmp_error_stream
,
1013 "Could not insert hardware watchpoint %d.\n",
1014 bpt
->owner
->number
);
1020 printf_filtered (_("\
1021 Hardware watchpoint %d deleted because the program has left the block \n\
1022 in which its expression is valid.\n"),
1023 bpt
->owner
->number
);
1024 if (bpt
->owner
->related_breakpoint
)
1025 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1026 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1029 /* Restore the selected frame. */
1030 select_frame (frame_find_by_id (saved_frame_id
));
1035 else if (ep_is_exception_catchpoint (bpt
->owner
))
1037 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1038 breakpoint. Once again, it would be better if this was represented
1039 as two bp_locations. */
1041 /* If we get here, we must have a callback mechanism for exception
1042 events -- with g++ style embedded label support, we insert
1043 ordinary breakpoints and not catchpoints. */
1044 val
= target_insert_breakpoint (&bpt
->target_info
);
1047 /* Couldn't set breakpoint for some reason */
1048 fprintf_unfiltered (tmp_error_stream
,
1049 "Cannot insert catchpoint %d; disabling it.\n",
1050 bpt
->owner
->number
);
1051 fprintf_filtered (tmp_error_stream
,
1052 "Error accessing memory address ");
1053 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1054 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1055 safe_strerror (val
));
1056 bpt
->owner
->enable_state
= bp_disabled
;
1060 /* Bp set, now make sure callbacks are enabled */
1061 /* Format possible error msg */
1062 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1063 bpt
->owner
->number
);
1064 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1066 args_for_catchpoint_enable args
;
1067 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1068 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1070 val
= catch_errors (cover_target_enable_exception_callback
,
1071 &args
, message
, RETURN_MASK_ALL
);
1072 do_cleanups (cleanups
);
1073 if (val
!= 0 && val
!= -1)
1076 /* Check if something went wrong; val == 0 can be ignored */
1079 /* something went wrong */
1080 fprintf_unfiltered (tmp_error_stream
,
1081 "Cannot insert catchpoint %d; disabling it.\n",
1082 bpt
->owner
->number
);
1083 bpt
->owner
->enable_state
= bp_disabled
;
1090 else if (bpt
->owner
->type
== bp_catch_fork
1091 || bpt
->owner
->type
== bp_catch_vfork
1092 || bpt
->owner
->type
== bp_catch_exec
)
1094 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1095 bpt
->owner
, RETURN_MASK_ERROR
);
1096 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1097 bpt
->owner
->number
);
1099 bpt
->owner
->enable_state
= bp_disabled
;
1103 /* We've already printed an error message if there was a problem
1104 inserting this catchpoint, and we've disabled the catchpoint,
1105 so just return success. */
1112 /* insert_breakpoints is used when starting or continuing the program.
1113 remove_breakpoints is used when the program stops.
1114 Both return zero if successful,
1115 or an `errno' value if could not write the inferior. */
1118 insert_breakpoints (void)
1120 struct bp_location
*b
, *temp
;
1121 int return_val
= 0; /* return success code. */
1123 int disabled_breaks
= 0;
1124 int hw_breakpoint_error
= 0;
1125 int process_warning
= 0;
1127 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1128 make_cleanup_ui_file_delete (tmp_error_stream
);
1130 /* Explicitly mark the warning -- this will only be printed if
1131 there was an error. */
1132 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1134 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1136 /* Permanent breakpoints cannot be inserted or removed. Disabled
1137 breakpoints should not be inserted. */
1138 if (!breakpoint_enabled (b
->owner
))
1141 /* There is no point inserting thread-specific breakpoints if the
1142 thread no longer exists. */
1143 if (b
->owner
->thread
!= -1
1144 && !valid_thread_id (b
->owner
->thread
))
1147 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1148 hardware watchpoints are split into multiple loc breakpoints. */
1149 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1150 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1153 val
= evaluate_expression (b
->owner
->exp
);
1154 release_value (val
);
1155 if (value_lazy (val
))
1156 value_fetch_lazy (val
);
1157 b
->owner
->val
= val
;
1160 val
= insert_bp_location (b
, tmp_error_stream
,
1161 &disabled_breaks
, &process_warning
,
1162 &hw_breakpoint_error
);
1169 /* If a hardware breakpoint or watchpoint was inserted, add a
1170 message about possibly exhausted resources. */
1171 if (hw_breakpoint_error
)
1173 fprintf_unfiltered (tmp_error_stream
,
1174 "Could not insert hardware breakpoints:\n\
1175 You may have requested too many hardware breakpoints/watchpoints.\n");
1177 #ifdef ONE_PROCESS_WRITETEXT
1178 if (process_warning
)
1179 fprintf_unfiltered (tmp_error_stream
,
1180 "The same program may be running in another process.");
1182 target_terminal_ours_for_output ();
1183 error_stream (tmp_error_stream
);
1189 remove_breakpoints (void)
1191 struct bp_location
*b
;
1194 ALL_BP_LOCATIONS (b
)
1198 val
= remove_breakpoint (b
, mark_uninserted
);
1207 remove_hw_watchpoints (void)
1209 struct bp_location
*b
;
1212 ALL_BP_LOCATIONS (b
)
1214 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1216 val
= remove_breakpoint (b
, mark_uninserted
);
1225 reattach_breakpoints (int pid
)
1227 struct bp_location
*b
;
1229 struct cleanup
*old_chain
= save_inferior_ptid ();
1231 /* Set inferior_ptid; remove_breakpoint uses this global. */
1232 inferior_ptid
= pid_to_ptid (pid
);
1233 ALL_BP_LOCATIONS (b
)
1237 remove_breakpoint (b
, mark_inserted
);
1238 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1239 val
= target_insert_hw_breakpoint (&b
->target_info
);
1241 val
= target_insert_breakpoint (&b
->target_info
);
1242 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1243 breakpoints. It's wrong for watchpoints, for example. */
1246 do_cleanups (old_chain
);
1251 do_cleanups (old_chain
);
1256 update_breakpoints_after_exec (void)
1258 struct breakpoint
*b
;
1259 struct breakpoint
*temp
;
1261 /* Doing this first prevents the badness of having delete_breakpoint()
1262 write a breakpoint's current "shadow contents" to lift the bp. That
1263 shadow is NOT valid after an exec()! */
1264 mark_breakpoints_out ();
1266 ALL_BREAKPOINTS_SAFE (b
, temp
)
1268 /* Solib breakpoints must be explicitly reset after an exec(). */
1269 if (b
->type
== bp_shlib_event
)
1271 delete_breakpoint (b
);
1275 /* Thread event breakpoints must be set anew after an exec(),
1276 as must overlay event breakpoints. */
1277 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1279 delete_breakpoint (b
);
1283 /* Step-resume breakpoints are meaningless after an exec(). */
1284 if (b
->type
== bp_step_resume
)
1286 delete_breakpoint (b
);
1290 /* Ditto the sigtramp handler breakpoints. */
1291 if (b
->type
== bp_through_sigtramp
)
1293 delete_breakpoint (b
);
1297 /* Ditto the exception-handling catchpoints. */
1298 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1300 delete_breakpoint (b
);
1304 /* Don't delete an exec catchpoint, because else the inferior
1305 won't stop when it ought!
1307 Similarly, we probably ought to keep vfork catchpoints, 'cause
1308 on this target, we may not be able to stop when the vfork is
1309 seen, but only when the subsequent exec is seen. (And because
1310 deleting fork catchpoints here but not vfork catchpoints will
1311 seem mysterious to users, keep those too.)
1313 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1314 target address field, if any, is sufficient to have it be reset
1315 automagically. Certainly on HP-UX that's true.
1317 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1318 valid code address on some platforms (like the mn10300
1319 simulators). We shouldn't assign any special interpretation to
1320 a breakpoint with a zero address. And in fact, GDB doesn't ---
1321 I can't see what that comment above is talking about. As far
1322 as I can tell, setting the address of a
1323 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1324 is meaningless, since those are implemented with HP-UX kernel
1325 hackery, not by storing breakpoint instructions somewhere. */
1326 if ((b
->type
== bp_catch_exec
) ||
1327 (b
->type
== bp_catch_vfork
) ||
1328 (b
->type
== bp_catch_fork
))
1330 b
->loc
->address
= (CORE_ADDR
) NULL
;
1334 /* bp_finish is a special case. The only way we ought to be able
1335 to see one of these when an exec() has happened, is if the user
1336 caught a vfork, and then said "finish". Ordinarily a finish just
1337 carries them to the call-site of the current callee, by setting
1338 a temporary bp there and resuming. But in this case, the finish
1339 will carry them entirely through the vfork & exec.
1341 We don't want to allow a bp_finish to remain inserted now. But
1342 we can't safely delete it, 'cause finish_command has a handle to
1343 the bp on a bpstat, and will later want to delete it. There's a
1344 chance (and I've seen it happen) that if we delete the bp_finish
1345 here, that its storage will get reused by the time finish_command
1346 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1347 We really must allow finish_command to delete a bp_finish.
1349 In the absense of a general solution for the "how do we know
1350 it's safe to delete something others may have handles to?"
1351 problem, what we'll do here is just uninsert the bp_finish, and
1352 let finish_command delete it.
1354 (We know the bp_finish is "doomed" in the sense that it's
1355 momentary, and will be deleted as soon as finish_command sees
1356 the inferior stopped. So it doesn't matter that the bp's
1357 address is probably bogus in the new a.out, unlike e.g., the
1358 solib breakpoints.) */
1360 if (b
->type
== bp_finish
)
1365 /* Without a symbolic address, we have little hope of the
1366 pre-exec() address meaning the same thing in the post-exec()
1368 if (b
->addr_string
== NULL
)
1370 delete_breakpoint (b
);
1374 /* If this breakpoint has survived the above battery of checks, then
1375 it must have a symbolic address. Be sure that it gets reevaluated
1376 to a target address, rather than reusing the old evaluation.
1378 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1379 for bp_catch_exec and friends, I'm pretty sure this is entirely
1380 unnecessary. A call to breakpoint_re_set_one always recomputes
1381 the breakpoint's address from scratch, or deletes it if it can't.
1382 So I think this assignment could be deleted without effect. */
1383 b
->loc
->address
= (CORE_ADDR
) NULL
;
1385 /* FIXME what about longjmp breakpoints? Re-create them here? */
1386 create_overlay_event_breakpoint ("_ovly_debug_event");
1390 detach_breakpoints (int pid
)
1392 struct bp_location
*b
;
1394 struct cleanup
*old_chain
= save_inferior_ptid ();
1396 if (pid
== PIDGET (inferior_ptid
))
1397 error (_("Cannot detach breakpoints of inferior_ptid"));
1399 /* Set inferior_ptid; remove_breakpoint uses this global. */
1400 inferior_ptid
= pid_to_ptid (pid
);
1401 ALL_BP_LOCATIONS (b
)
1405 val
= remove_breakpoint (b
, mark_inserted
);
1408 do_cleanups (old_chain
);
1413 do_cleanups (old_chain
);
1418 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1422 if (b
->owner
->enable_state
== bp_permanent
)
1423 /* Permanent breakpoints cannot be inserted or removed. */
1426 if (b
->owner
->type
== bp_none
)
1427 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1430 if (b
->loc_type
== bp_loc_software_breakpoint
1431 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1433 /* "Normal" instruction breakpoint: either the standard
1434 trap-instruction bp (bp_breakpoint), or a
1435 bp_hardware_breakpoint. */
1437 /* First check to see if we have to handle an overlay. */
1438 if (overlay_debugging
== ovly_off
1439 || b
->section
== NULL
1440 || !(section_is_overlay (b
->section
)))
1442 /* No overlay handling: just remove the breakpoint. */
1444 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1445 val
= target_remove_hw_breakpoint (&b
->target_info
);
1447 val
= target_remove_breakpoint (&b
->target_info
);
1451 /* This breakpoint is in an overlay section.
1452 Did we set a breakpoint at the LMA? */
1453 if (!overlay_events_enabled
)
1455 /* Yes -- overlay event support is not active, so we
1456 should have set a breakpoint at the LMA. Remove it.
1458 /* Ignore any failures: if the LMA is in ROM, we will
1459 have already warned when we failed to insert it. */
1460 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1461 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1463 target_remove_breakpoint (&b
->overlay_target_info
);
1465 /* Did we set a breakpoint at the VMA?
1466 If so, we will have marked the breakpoint 'inserted'. */
1469 /* Yes -- remove it. Previously we did not bother to
1470 remove the breakpoint if the section had been
1471 unmapped, but let's not rely on that being safe. We
1472 don't know what the overlay manager might do. */
1473 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1474 val
= target_remove_hw_breakpoint (&b
->target_info
);
1476 val
= target_remove_breakpoint (&b
->target_info
);
1480 /* No -- not inserted, so no need to remove. No error. */
1486 b
->inserted
= (is
== mark_inserted
);
1488 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1489 && breakpoint_enabled (b
->owner
)
1495 b
->inserted
= (is
== mark_inserted
);
1496 /* Walk down the saved value chain. */
1497 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1499 /* For each memory reference remove the watchpoint
1501 if (VALUE_LVAL (v
) == lval_memory
1502 && ! value_lazy (v
))
1504 struct type
*vtype
= check_typedef (value_type (v
));
1506 if (v
== b
->owner
->val_chain
1507 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1508 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1513 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1514 len
= TYPE_LENGTH (value_type (v
));
1516 if (b
->owner
->type
== bp_read_watchpoint
)
1518 else if (b
->owner
->type
== bp_access_watchpoint
)
1521 val
= target_remove_watchpoint (addr
, len
, type
);
1528 /* Failure to remove any of the hardware watchpoints comes here. */
1529 if ((is
== mark_uninserted
) && (b
->inserted
))
1530 warning (_("Could not remove hardware watchpoint %d."),
1533 else if ((b
->owner
->type
== bp_catch_fork
||
1534 b
->owner
->type
== bp_catch_vfork
||
1535 b
->owner
->type
== bp_catch_exec
)
1536 && breakpoint_enabled (b
->owner
)
1540 switch (b
->owner
->type
)
1543 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1545 case bp_catch_vfork
:
1546 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1549 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1552 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1557 b
->inserted
= (is
== mark_inserted
);
1559 else if ((b
->owner
->type
== bp_catch_catch
||
1560 b
->owner
->type
== bp_catch_throw
)
1561 && breakpoint_enabled (b
->owner
)
1564 val
= target_remove_breakpoint (&b
->target_info
);
1567 b
->inserted
= (is
== mark_inserted
);
1569 else if (ep_is_exception_catchpoint (b
->owner
)
1570 && b
->inserted
/* sometimes previous insert doesn't happen */
1571 && breakpoint_enabled (b
->owner
)
1574 val
= target_remove_breakpoint (&b
->target_info
);
1578 b
->inserted
= (is
== mark_inserted
);
1584 /* Clear the "inserted" flag in all breakpoints. */
1587 mark_breakpoints_out (void)
1589 struct bp_location
*bpt
;
1591 ALL_BP_LOCATIONS (bpt
)
1595 /* Clear the "inserted" flag in all breakpoints and delete any
1596 breakpoints which should go away between runs of the program.
1598 Plus other such housekeeping that has to be done for breakpoints
1601 Note: this function gets called at the end of a run (by
1602 generic_mourn_inferior) and when a run begins (by
1603 init_wait_for_inferior). */
1608 breakpoint_init_inferior (enum inf_context context
)
1610 struct breakpoint
*b
, *temp
;
1611 struct bp_location
*bpt
;
1612 static int warning_needed
= 0;
1614 ALL_BP_LOCATIONS (bpt
)
1617 ALL_BREAKPOINTS_SAFE (b
, temp
)
1622 case bp_watchpoint_scope
:
1624 /* If the call dummy breakpoint is at the entry point it will
1625 cause problems when the inferior is rerun, so we better
1628 Also get rid of scope breakpoints. */
1629 delete_breakpoint (b
);
1633 case bp_hardware_watchpoint
:
1634 case bp_read_watchpoint
:
1635 case bp_access_watchpoint
:
1637 /* Likewise for watchpoints on local expressions. */
1638 if (b
->exp_valid_block
!= NULL
)
1639 delete_breakpoint (b
);
1640 if (context
== inf_starting
)
1642 /* Reset val field to force reread of starting value
1643 in insert_breakpoints. */
1645 value_free (b
->val
);
1650 /* Likewise for exception catchpoints in dynamic-linked
1651 executables where required */
1652 if (ep_is_exception_catchpoint (b
)
1653 && deprecated_exception_catchpoints_are_fragile
)
1656 delete_breakpoint (b
);
1662 if (deprecated_exception_catchpoints_are_fragile
)
1663 deprecated_exception_support_initialized
= 0;
1665 /* Don't issue the warning unless it's really needed... */
1666 if (warning_needed
&& (context
!= inf_exited
))
1668 warning (_("Exception catchpoints from last run were deleted.\n"
1669 "You must reinsert them explicitly."));
1674 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1675 exists at PC. It returns ordinary_breakpoint_here if it's an
1676 ordinary breakpoint, or permanent_breakpoint_here if it's a
1677 permanent breakpoint.
1678 - When continuing from a location with an ordinary breakpoint, we
1679 actually single step once before calling insert_breakpoints.
1680 - When continuing from a localion with a permanent breakpoint, we
1681 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1682 the target, to advance the PC past the breakpoint. */
1684 enum breakpoint_here
1685 breakpoint_here_p (CORE_ADDR pc
)
1687 struct bp_location
*bpt
;
1688 int any_breakpoint_here
= 0;
1690 ALL_BP_LOCATIONS (bpt
)
1692 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1693 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1696 if ((breakpoint_enabled (bpt
->owner
)
1697 || bpt
->owner
->enable_state
== bp_permanent
)
1698 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1700 if (overlay_debugging
1701 && section_is_overlay (bpt
->section
)
1702 && !section_is_mapped (bpt
->section
))
1703 continue; /* unmapped overlay -- can't be a match */
1704 else if (bpt
->owner
->enable_state
== bp_permanent
)
1705 return permanent_breakpoint_here
;
1707 any_breakpoint_here
= 1;
1711 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1715 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1716 but it only returns true if there is actually a breakpoint inserted
1720 breakpoint_inserted_here_p (CORE_ADDR pc
)
1722 struct bp_location
*bpt
;
1724 ALL_BP_LOCATIONS (bpt
)
1726 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1727 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1731 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1733 if (overlay_debugging
1734 && section_is_overlay (bpt
->section
)
1735 && !section_is_mapped (bpt
->section
))
1736 continue; /* unmapped overlay -- can't be a match */
1745 /* This function returns non-zero iff there is a software breakpoint
1749 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1751 struct bp_location
*bpt
;
1752 int any_breakpoint_here
= 0;
1754 ALL_BP_LOCATIONS (bpt
)
1756 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1759 if ((breakpoint_enabled (bpt
->owner
)
1760 || bpt
->owner
->enable_state
== bp_permanent
)
1762 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1764 if (overlay_debugging
1765 && section_is_overlay (bpt
->section
)
1766 && !section_is_mapped (bpt
->section
))
1767 continue; /* unmapped overlay -- can't be a match */
1776 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1777 PC is valid for process/thread PTID. */
1780 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1782 struct bp_location
*bpt
;
1785 thread
= pid_to_thread_id (ptid
);
1787 ALL_BP_LOCATIONS (bpt
)
1789 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1790 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1793 if ((breakpoint_enabled (bpt
->owner
)
1794 || bpt
->owner
->enable_state
== bp_permanent
)
1795 && bpt
->address
== pc
1796 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1798 if (overlay_debugging
1799 && section_is_overlay (bpt
->section
)
1800 && !section_is_mapped (bpt
->section
))
1801 continue; /* unmapped overlay -- can't be a match */
1811 /* bpstat stuff. External routines' interfaces are documented
1815 ep_is_catchpoint (struct breakpoint
*ep
)
1818 (ep
->type
== bp_catch_load
)
1819 || (ep
->type
== bp_catch_unload
)
1820 || (ep
->type
== bp_catch_fork
)
1821 || (ep
->type
== bp_catch_vfork
)
1822 || (ep
->type
== bp_catch_exec
)
1823 || (ep
->type
== bp_catch_catch
)
1824 || (ep
->type
== bp_catch_throw
);
1826 /* ??rehrauer: Add more kinds here, as are implemented... */
1830 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1833 (ep
->type
== bp_catch_load
)
1834 || (ep
->type
== bp_catch_unload
);
1838 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1841 (ep
->type
== bp_catch_catch
)
1842 || (ep
->type
== bp_catch_throw
);
1845 /* Clear a bpstat so that it says we are not at any breakpoint.
1846 Also free any storage that is part of a bpstat. */
1849 bpstat_clear (bpstat
*bsp
)
1860 if (p
->old_val
!= NULL
)
1861 value_free (p
->old_val
);
1862 free_command_lines (&p
->commands
);
1869 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1870 is part of the bpstat is copied as well. */
1873 bpstat_copy (bpstat bs
)
1877 bpstat retval
= NULL
;
1882 for (; bs
!= NULL
; bs
= bs
->next
)
1884 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1885 memcpy (tmp
, bs
, sizeof (*tmp
));
1886 if (bs
->commands
!= NULL
)
1887 tmp
->commands
= copy_command_lines (bs
->commands
);
1888 if (bs
->old_val
!= NULL
)
1889 tmp
->old_val
= value_copy (bs
->old_val
);
1892 /* This is the first thing in the chain. */
1902 /* Find the bpstat associated with this breakpoint */
1905 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1910 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1912 if (bsp
->breakpoint_at
== breakpoint
)
1918 /* Find a step_resume breakpoint associated with this bpstat.
1919 (If there are multiple step_resume bp's on the list, this function
1920 will arbitrarily pick one.)
1922 It is an error to use this function if BPSTAT doesn't contain a
1923 step_resume breakpoint.
1925 See wait_for_inferior's use of this function. */
1927 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1931 gdb_assert (bsp
!= NULL
);
1933 current_thread
= pid_to_thread_id (inferior_ptid
);
1935 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1937 if ((bsp
->breakpoint_at
!= NULL
) &&
1938 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1939 (bsp
->breakpoint_at
->thread
== current_thread
||
1940 bsp
->breakpoint_at
->thread
== -1))
1941 return bsp
->breakpoint_at
;
1944 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
1948 /* Return the breakpoint number of the first breakpoint we are stopped
1949 at. *BSP upon return is a bpstat which points to the remaining
1950 breakpoints stopped at (but which is not guaranteed to be good for
1951 anything but further calls to bpstat_num).
1952 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1955 bpstat_num (bpstat
*bsp
)
1957 struct breakpoint
*b
;
1960 return 0; /* No more breakpoint values */
1963 b
= (*bsp
)->breakpoint_at
;
1964 *bsp
= (*bsp
)->next
;
1966 return -1; /* breakpoint that's been deleted since */
1968 return b
->number
; /* We have its number */
1972 /* Modify BS so that the actions will not be performed. */
1975 bpstat_clear_actions (bpstat bs
)
1977 for (; bs
!= NULL
; bs
= bs
->next
)
1979 free_command_lines (&bs
->commands
);
1980 if (bs
->old_val
!= NULL
)
1982 value_free (bs
->old_val
);
1988 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1990 cleanup_executing_breakpoints (void *ignore
)
1992 executing_breakpoint_commands
= 0;
1995 /* Execute all the commands associated with all the breakpoints at this
1996 location. Any of these commands could cause the process to proceed
1997 beyond this point, etc. We look out for such changes by checking
1998 the global "breakpoint_proceeded" after each command. */
2001 bpstat_do_actions (bpstat
*bsp
)
2004 struct cleanup
*old_chain
;
2006 /* Avoid endless recursion if a `source' command is contained
2008 if (executing_breakpoint_commands
)
2011 executing_breakpoint_commands
= 1;
2012 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2015 /* Note that (as of this writing), our callers all appear to
2016 be passing us the address of global stop_bpstat. And, if
2017 our calls to execute_control_command cause the inferior to
2018 proceed, that global (and hence, *bsp) will change.
2020 We must be careful to not touch *bsp unless the inferior
2021 has not proceeded. */
2023 /* This pointer will iterate over the list of bpstat's. */
2026 breakpoint_proceeded
= 0;
2027 for (; bs
!= NULL
; bs
= bs
->next
)
2029 struct command_line
*cmd
;
2030 struct cleanup
*this_cmd_tree_chain
;
2032 /* Take ownership of the BSP's command tree, if it has one.
2034 The command tree could legitimately contain commands like
2035 'step' and 'next', which call clear_proceed_status, which
2036 frees stop_bpstat's command tree. To make sure this doesn't
2037 free the tree we're executing out from under us, we need to
2038 take ownership of the tree ourselves. Since a given bpstat's
2039 commands are only executed once, we don't need to copy it; we
2040 can clear the pointer in the bpstat, and make sure we free
2041 the tree when we're done. */
2044 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2048 execute_control_command (cmd
);
2050 if (breakpoint_proceeded
)
2056 /* We can free this command tree now. */
2057 do_cleanups (this_cmd_tree_chain
);
2059 if (breakpoint_proceeded
)
2060 /* The inferior is proceeded by the command; bomb out now.
2061 The bpstat chain has been blown away by wait_for_inferior.
2062 But since execution has stopped again, there is a new bpstat
2063 to look at, so start over. */
2066 do_cleanups (old_chain
);
2069 /* This is the normal print function for a bpstat. In the future,
2070 much of this logic could (should?) be moved to bpstat_stop_status,
2071 by having it set different print_it values.
2073 Current scheme: When we stop, bpstat_print() is called. It loops
2074 through the bpstat list of things causing this stop, calling the
2075 print_bp_stop_message function on each one. The behavior of the
2076 print_bp_stop_message function depends on the print_it field of
2077 bpstat. If such field so indicates, call this function here.
2079 Return values from this routine (ultimately used by bpstat_print()
2080 and normal_stop() to decide what to do):
2081 PRINT_NOTHING: Means we already printed all we needed to print,
2082 don't print anything else.
2083 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2084 that something to be followed by a location.
2085 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2086 that something to be followed by a location.
2087 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2090 static enum print_stop_action
2091 print_it_typical (bpstat bs
)
2093 struct cleanup
*old_chain
, *ui_out_chain
;
2094 struct ui_stream
*stb
;
2095 stb
= ui_out_stream_new (uiout
);
2096 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2097 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2098 which has since been deleted. */
2099 if (bs
->breakpoint_at
== NULL
)
2100 return PRINT_UNKNOWN
;
2102 switch (bs
->breakpoint_at
->type
)
2105 case bp_hardware_breakpoint
:
2106 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2107 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2108 bs
->breakpoint_at
->loc
->address
,
2109 bs
->breakpoint_at
->number
, 1);
2110 annotate_breakpoint (bs
->breakpoint_at
->number
);
2111 ui_out_text (uiout
, "\nBreakpoint ");
2112 if (ui_out_is_mi_like_p (uiout
))
2113 ui_out_field_string (uiout
, "reason",
2114 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2115 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2116 ui_out_text (uiout
, ", ");
2117 return PRINT_SRC_AND_LOC
;
2120 case bp_shlib_event
:
2121 /* Did we stop because the user set the stop_on_solib_events
2122 variable? (If so, we report this as a generic, "Stopped due
2123 to shlib event" message.) */
2124 printf_filtered (_("Stopped due to shared library event\n"));
2125 return PRINT_NOTHING
;
2128 case bp_thread_event
:
2129 /* Not sure how we will get here.
2130 GDB should not stop for these breakpoints. */
2131 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2132 return PRINT_NOTHING
;
2135 case bp_overlay_event
:
2136 /* By analogy with the thread event, GDB should not stop for these. */
2137 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2138 return PRINT_NOTHING
;
2142 annotate_catchpoint (bs
->breakpoint_at
->number
);
2143 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2144 bs
->breakpoint_at
->number
,
2145 bs
->breakpoint_at
->triggered_dll_pathname
);
2146 return PRINT_SRC_AND_LOC
;
2149 case bp_catch_unload
:
2150 annotate_catchpoint (bs
->breakpoint_at
->number
);
2151 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2152 bs
->breakpoint_at
->number
,
2153 bs
->breakpoint_at
->triggered_dll_pathname
);
2154 return PRINT_SRC_AND_LOC
;
2158 annotate_catchpoint (bs
->breakpoint_at
->number
);
2159 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2160 bs
->breakpoint_at
->number
,
2161 bs
->breakpoint_at
->forked_inferior_pid
);
2162 return PRINT_SRC_AND_LOC
;
2165 case bp_catch_vfork
:
2166 annotate_catchpoint (bs
->breakpoint_at
->number
);
2167 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2168 bs
->breakpoint_at
->number
,
2169 bs
->breakpoint_at
->forked_inferior_pid
);
2170 return PRINT_SRC_AND_LOC
;
2174 annotate_catchpoint (bs
->breakpoint_at
->number
);
2175 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2176 bs
->breakpoint_at
->number
,
2177 bs
->breakpoint_at
->exec_pathname
);
2178 return PRINT_SRC_AND_LOC
;
2181 case bp_catch_catch
:
2182 if (current_exception_event
&&
2183 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2185 annotate_catchpoint (bs
->breakpoint_at
->number
);
2186 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2187 bs
->breakpoint_at
->number
);
2188 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2189 printf_filtered (_("throw location %s:%d, "),
2190 CURRENT_EXCEPTION_THROW_FILE
,
2191 CURRENT_EXCEPTION_THROW_LINE
);
2193 printf_filtered (_("throw location unknown, "));
2195 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2196 printf_filtered (_("catch location %s:%d\n"),
2197 CURRENT_EXCEPTION_CATCH_FILE
,
2198 CURRENT_EXCEPTION_CATCH_LINE
);
2200 printf_filtered (_("catch location unknown\n"));
2202 /* don't bother to print location frame info */
2203 return PRINT_SRC_ONLY
;
2207 /* really throw, some other bpstat will handle it */
2208 return PRINT_UNKNOWN
;
2212 case bp_catch_throw
:
2213 if (current_exception_event
&&
2214 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2216 annotate_catchpoint (bs
->breakpoint_at
->number
);
2217 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2218 bs
->breakpoint_at
->number
);
2219 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2220 printf_filtered (_("throw location %s:%d, "),
2221 CURRENT_EXCEPTION_THROW_FILE
,
2222 CURRENT_EXCEPTION_THROW_LINE
);
2224 printf_filtered (_("throw location unknown, "));
2226 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2227 printf_filtered (_("catch location %s:%d\n"),
2228 CURRENT_EXCEPTION_CATCH_FILE
,
2229 CURRENT_EXCEPTION_CATCH_LINE
);
2231 printf_filtered (_("catch location unknown\n"));
2233 /* don't bother to print location frame info */
2234 return PRINT_SRC_ONLY
;
2238 /* really catch, some other bpstat will handle it */
2239 return PRINT_UNKNOWN
;
2244 case bp_hardware_watchpoint
:
2245 if (bs
->old_val
!= NULL
)
2247 annotate_watchpoint (bs
->breakpoint_at
->number
);
2248 if (ui_out_is_mi_like_p (uiout
))
2251 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2252 mention (bs
->breakpoint_at
);
2253 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2254 ui_out_text (uiout
, "\nOld value = ");
2255 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2256 ui_out_field_stream (uiout
, "old", stb
);
2257 ui_out_text (uiout
, "\nNew value = ");
2258 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2259 ui_out_field_stream (uiout
, "new", stb
);
2260 do_cleanups (ui_out_chain
);
2261 ui_out_text (uiout
, "\n");
2262 value_free (bs
->old_val
);
2265 /* More than one watchpoint may have been triggered. */
2266 return PRINT_UNKNOWN
;
2269 case bp_read_watchpoint
:
2270 if (ui_out_is_mi_like_p (uiout
))
2273 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2274 mention (bs
->breakpoint_at
);
2275 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2276 ui_out_text (uiout
, "\nValue = ");
2277 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2278 ui_out_field_stream (uiout
, "value", stb
);
2279 do_cleanups (ui_out_chain
);
2280 ui_out_text (uiout
, "\n");
2281 return PRINT_UNKNOWN
;
2284 case bp_access_watchpoint
:
2285 if (bs
->old_val
!= NULL
)
2287 annotate_watchpoint (bs
->breakpoint_at
->number
);
2288 if (ui_out_is_mi_like_p (uiout
))
2291 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2292 mention (bs
->breakpoint_at
);
2293 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2294 ui_out_text (uiout
, "\nOld value = ");
2295 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2296 ui_out_field_stream (uiout
, "old", stb
);
2297 value_free (bs
->old_val
);
2299 ui_out_text (uiout
, "\nNew value = ");
2303 mention (bs
->breakpoint_at
);
2304 if (ui_out_is_mi_like_p (uiout
))
2307 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2308 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2309 ui_out_text (uiout
, "\nValue = ");
2311 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2312 ui_out_field_stream (uiout
, "new", stb
);
2313 do_cleanups (ui_out_chain
);
2314 ui_out_text (uiout
, "\n");
2315 return PRINT_UNKNOWN
;
2318 /* Fall through, we don't deal with these types of breakpoints
2322 if (ui_out_is_mi_like_p (uiout
))
2325 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2326 return PRINT_UNKNOWN
;
2330 if (ui_out_is_mi_like_p (uiout
))
2331 ui_out_field_string (uiout
, "reason", "location-reached");
2332 return PRINT_UNKNOWN
;
2337 case bp_longjmp_resume
:
2338 case bp_step_resume
:
2339 case bp_through_sigtramp
:
2340 case bp_watchpoint_scope
:
2343 return PRINT_UNKNOWN
;
2347 /* Generic routine for printing messages indicating why we
2348 stopped. The behavior of this function depends on the value
2349 'print_it' in the bpstat structure. Under some circumstances we
2350 may decide not to print anything here and delegate the task to
2353 static enum print_stop_action
2354 print_bp_stop_message (bpstat bs
)
2356 switch (bs
->print_it
)
2359 /* Nothing should be printed for this bpstat entry. */
2360 return PRINT_UNKNOWN
;
2364 /* We still want to print the frame, but we already printed the
2365 relevant messages. */
2366 return PRINT_SRC_AND_LOC
;
2369 case print_it_normal
:
2370 /* Normal case. Call the breakpoint's print_it method, or
2371 print_it_typical. */
2372 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2373 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2374 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2376 return print_it_typical (bs
);
2380 internal_error (__FILE__
, __LINE__
,
2381 _("print_bp_stop_message: unrecognized enum value"));
2386 /* Print a message indicating what happened. This is called from
2387 normal_stop(). The input to this routine is the head of the bpstat
2388 list - a list of the eventpoints that caused this stop. This
2389 routine calls the generic print routine for printing a message
2390 about reasons for stopping. This will print (for example) the
2391 "Breakpoint n," part of the output. The return value of this
2394 PRINT_UNKNOWN: Means we printed nothing
2395 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2396 code to print the location. An example is
2397 "Breakpoint 1, " which should be followed by
2399 PRINT_SRC_ONLY: Means we printed something, but there is no need
2400 to also print the location part of the message.
2401 An example is the catch/throw messages, which
2402 don't require a location appended to the end.
2403 PRINT_NOTHING: We have done some printing and we don't need any
2404 further info to be printed.*/
2406 enum print_stop_action
2407 bpstat_print (bpstat bs
)
2411 /* Maybe another breakpoint in the chain caused us to stop.
2412 (Currently all watchpoints go on the bpstat whether hit or not.
2413 That probably could (should) be changed, provided care is taken
2414 with respect to bpstat_explains_signal). */
2415 for (; bs
; bs
= bs
->next
)
2417 val
= print_bp_stop_message (bs
);
2418 if (val
== PRINT_SRC_ONLY
2419 || val
== PRINT_SRC_AND_LOC
2420 || val
== PRINT_NOTHING
)
2424 /* We reached the end of the chain, or we got a null BS to start
2425 with and nothing was printed. */
2426 return PRINT_UNKNOWN
;
2429 /* Evaluate the expression EXP and return 1 if value is zero.
2430 This is used inside a catch_errors to evaluate the breakpoint condition.
2431 The argument is a "struct expression *" that has been cast to char * to
2432 make it pass through catch_errors. */
2435 breakpoint_cond_eval (void *exp
)
2437 struct value
*mark
= value_mark ();
2438 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2439 value_free_to_mark (mark
);
2443 /* Allocate a new bpstat and chain it to the current one. */
2446 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2450 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2452 bs
->breakpoint_at
= b
;
2453 /* If the condition is false, etc., don't do the commands. */
2454 bs
->commands
= NULL
;
2456 bs
->print_it
= print_it_normal
;
2460 /* Possible return values for watchpoint_check (this can't be an enum
2461 because of check_errors). */
2462 /* The watchpoint has been deleted. */
2463 #define WP_DELETED 1
2464 /* The value has changed. */
2465 #define WP_VALUE_CHANGED 2
2466 /* The value has not changed. */
2467 #define WP_VALUE_NOT_CHANGED 3
2469 #define BP_TEMPFLAG 1
2470 #define BP_HARDWAREFLAG 2
2472 /* Check watchpoint condition. */
2475 watchpoint_check (void *p
)
2477 bpstat bs
= (bpstat
) p
;
2478 struct breakpoint
*b
;
2479 struct frame_info
*fr
;
2480 int within_current_scope
;
2482 b
= bs
->breakpoint_at
;
2484 if (b
->exp_valid_block
== NULL
)
2485 within_current_scope
= 1;
2488 /* There is no current frame at this moment. If we're going to have
2489 any chance of handling watchpoints on local variables, we'll need
2490 the frame chain (so we can determine if we're in scope). */
2491 reinit_frame_cache ();
2492 fr
= frame_find_by_id (b
->watchpoint_frame
);
2493 within_current_scope
= (fr
!= NULL
);
2494 /* in_function_epilogue_p() returns a non-zero value if we're still
2495 in the function but the stack frame has already been invalidated.
2496 Since we can't rely on the values of local variables after the
2497 stack has been destroyed, we are treating the watchpoint in that
2498 state as `not changed' without further checking.
2500 vinschen/2003-09-04: The former implementation left out the case
2501 that the watchpoint frame couldn't be found by frame_find_by_id()
2502 because the current PC is currently in an epilogue. Calling
2503 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2504 if ((!within_current_scope
|| fr
== get_current_frame ())
2505 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2506 return WP_VALUE_NOT_CHANGED
;
2507 if (fr
&& within_current_scope
)
2508 /* If we end up stopping, the current frame will get selected
2509 in normal_stop. So this call to select_frame won't affect
2514 if (within_current_scope
)
2516 /* We use value_{,free_to_}mark because it could be a
2517 *long* time before we return to the command level and
2518 call free_all_values. We can't call free_all_values because
2519 we might be in the middle of evaluating a function call. */
2521 struct value
*mark
= value_mark ();
2522 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2523 if (!value_equal (b
->val
, new_val
))
2525 release_value (new_val
);
2526 value_free_to_mark (mark
);
2527 bs
->old_val
= b
->val
;
2529 /* We will stop here */
2530 return WP_VALUE_CHANGED
;
2534 /* Nothing changed, don't do anything. */
2535 value_free_to_mark (mark
);
2536 /* We won't stop here */
2537 return WP_VALUE_NOT_CHANGED
;
2542 /* This seems like the only logical thing to do because
2543 if we temporarily ignored the watchpoint, then when
2544 we reenter the block in which it is valid it contains
2545 garbage (in the case of a function, it may have two
2546 garbage values, one before and one after the prologue).
2547 So we can't even detect the first assignment to it and
2548 watch after that (since the garbage may or may not equal
2549 the first value assigned). */
2550 /* We print all the stop information in print_it_typical(), but
2551 in this case, by the time we call print_it_typical() this bp
2552 will be deleted already. So we have no choice but print the
2553 information here. */
2554 if (ui_out_is_mi_like_p (uiout
))
2556 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2557 ui_out_text (uiout
, "\nWatchpoint ");
2558 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2559 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2560 which its expression is valid.\n");
2562 if (b
->related_breakpoint
)
2563 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2564 b
->disposition
= disp_del_at_next_stop
;
2570 /* Get a bpstat associated with having just stopped at address
2571 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2572 target thinks we stopped due to a hardware watchpoint, 0 if we
2573 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2575 /* Determine whether we stopped at a breakpoint, etc, or whether we
2576 don't understand this stop. Result is a chain of bpstat's such that:
2578 if we don't understand the stop, the result is a null pointer.
2580 if we understand why we stopped, the result is not null.
2582 Each element of the chain refers to a particular breakpoint or
2583 watchpoint at which we have stopped. (We may have stopped for
2584 several reasons concurrently.)
2586 Each element of the chain has valid next, breakpoint_at,
2587 commands, FIXME??? fields. */
2590 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2592 struct breakpoint
*b
, *temp
;
2593 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2594 int real_breakpoint
= 0;
2595 /* Root of the chain of bpstat's */
2596 struct bpstats root_bs
[1];
2597 /* Pointer to the last thing in the chain currently. */
2598 bpstat bs
= root_bs
;
2599 int thread_id
= pid_to_thread_id (ptid
);
2601 ALL_BREAKPOINTS_SAFE (b
, temp
)
2603 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2606 if (b
->type
!= bp_watchpoint
2607 && b
->type
!= bp_hardware_watchpoint
2608 && b
->type
!= bp_read_watchpoint
2609 && b
->type
!= bp_access_watchpoint
2610 && b
->type
!= bp_hardware_breakpoint
2611 && b
->type
!= bp_catch_fork
2612 && b
->type
!= bp_catch_vfork
2613 && b
->type
!= bp_catch_exec
2614 && b
->type
!= bp_catch_catch
2615 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2617 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2619 if (overlay_debugging
/* unmapped overlay section */
2620 && section_is_overlay (b
->loc
->section
)
2621 && !section_is_mapped (b
->loc
->section
))
2625 /* Continuable hardware watchpoints are treated as non-existent if the
2626 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2627 some data address). Otherwise gdb won't stop on a break instruction
2628 in the code (not from a breakpoint) when a hardware watchpoint has
2631 if ((b
->type
== bp_hardware_watchpoint
2632 || b
->type
== bp_read_watchpoint
2633 || b
->type
== bp_access_watchpoint
)
2634 && !stopped_by_watchpoint
)
2637 if (b
->type
== bp_hardware_breakpoint
)
2639 if (b
->loc
->address
!= bp_addr
)
2641 if (overlay_debugging
/* unmapped overlay section */
2642 && section_is_overlay (b
->loc
->section
)
2643 && !section_is_mapped (b
->loc
->section
))
2647 /* Is this a catchpoint of a load or unload? If so, did we
2648 get a load or unload of the specified library? If not,
2650 if ((b
->type
== bp_catch_load
)
2651 #if defined(SOLIB_HAVE_LOAD_EVENT)
2652 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2653 || ((b
->dll_pathname
!= NULL
)
2654 && (strcmp (b
->dll_pathname
,
2655 SOLIB_LOADED_LIBRARY_PATHNAME (
2656 PIDGET (inferior_ptid
)))
2662 if ((b
->type
== bp_catch_unload
)
2663 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2664 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2665 || ((b
->dll_pathname
!= NULL
)
2666 && (strcmp (b
->dll_pathname
,
2667 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2668 PIDGET (inferior_ptid
)))
2674 if ((b
->type
== bp_catch_fork
)
2675 && !inferior_has_forked (PIDGET (inferior_ptid
),
2676 &b
->forked_inferior_pid
))
2679 if ((b
->type
== bp_catch_vfork
)
2680 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2681 &b
->forked_inferior_pid
))
2684 if ((b
->type
== bp_catch_exec
)
2685 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2688 if (ep_is_exception_catchpoint (b
) &&
2689 !(current_exception_event
= target_get_current_exception_event ()))
2692 /* Come here if it's a watchpoint, or if the break address matches */
2694 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2696 /* Watchpoints may change this, if not found to have triggered. */
2700 if (b
->type
== bp_watchpoint
||
2701 b
->type
== bp_hardware_watchpoint
)
2703 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2705 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2706 int e
= catch_errors (watchpoint_check
, bs
, message
,
2708 do_cleanups (cleanups
);
2712 /* We've already printed what needs to be printed. */
2713 /* Actually this is superfluous, because by the time we
2714 call print_it_typical() the wp will be already deleted,
2715 and the function will return immediately. */
2716 bs
->print_it
= print_it_done
;
2719 case WP_VALUE_CHANGED
:
2723 case WP_VALUE_NOT_CHANGED
:
2725 bs
->print_it
= print_it_noop
;
2732 /* Error from catch_errors. */
2733 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2734 if (b
->related_breakpoint
)
2735 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2736 b
->disposition
= disp_del_at_next_stop
;
2737 /* We've already printed what needs to be printed. */
2738 bs
->print_it
= print_it_done
;
2744 else if (b
->type
== bp_read_watchpoint
||
2745 b
->type
== bp_access_watchpoint
)
2751 if (!target_stopped_data_address (¤t_target
, &addr
))
2753 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2755 if (VALUE_LVAL (v
) == lval_memory
2756 && ! value_lazy (v
))
2758 struct type
*vtype
= check_typedef (value_type (v
));
2760 if (v
== b
->val_chain
2761 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2762 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2766 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2767 /* Exact match not required. Within range is
2769 if (addr
>= vaddr
&&
2770 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2777 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2779 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2780 int e
= catch_errors (watchpoint_check
, bs
, message
,
2782 do_cleanups (cleanups
);
2786 /* We've already printed what needs to be printed. */
2787 bs
->print_it
= print_it_done
;
2790 case WP_VALUE_CHANGED
:
2791 if (b
->type
== bp_read_watchpoint
)
2793 /* Don't stop: read watchpoints shouldn't fire if
2794 the value has changed. This is for targets
2795 which cannot set read-only watchpoints. */
2796 bs
->print_it
= print_it_noop
;
2802 case WP_VALUE_NOT_CHANGED
:
2809 /* Error from catch_errors. */
2810 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2811 if (b
->related_breakpoint
)
2812 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2813 b
->disposition
= disp_del_at_next_stop
;
2814 /* We've already printed what needs to be printed. */
2815 bs
->print_it
= print_it_done
;
2819 else /* found == 0 */
2821 /* This is a case where some watchpoint(s) triggered,
2822 but not at the address of this watchpoint (FOUND
2823 was left zero). So don't print anything for this
2825 bs
->print_it
= print_it_noop
;
2832 /* By definition, an encountered breakpoint is a triggered
2836 real_breakpoint
= 1;
2839 if (frame_id_p (b
->frame_id
)
2840 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2844 int value_is_zero
= 0;
2848 /* Need to select the frame, with all that implies
2849 so that the conditions will have the right context. */
2850 select_frame (get_current_frame ());
2852 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2853 "Error in testing breakpoint condition:\n",
2855 /* FIXME-someday, should give breakpoint # */
2858 if (b
->cond
&& value_is_zero
)
2861 /* Don't consider this a hit. */
2864 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2867 /* Don't consider this a hit. */
2870 else if (b
->ignore_count
> 0)
2873 annotate_ignore_count_change ();
2878 /* We will stop here */
2879 if (b
->disposition
== disp_disable
)
2880 b
->enable_state
= bp_disabled
;
2883 bs
->commands
= b
->commands
;
2885 (strcmp ("silent", bs
->commands
->line
) == 0
2886 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2888 bs
->commands
= bs
->commands
->next
;
2891 bs
->commands
= copy_command_lines (bs
->commands
);
2894 /* Print nothing for this entry if we dont stop or if we dont print. */
2895 if (bs
->stop
== 0 || bs
->print
== 0)
2896 bs
->print_it
= print_it_noop
;
2899 bs
->next
= NULL
; /* Terminate the chain */
2900 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2902 /* The value of a hardware watchpoint hasn't changed, but the
2903 intermediate memory locations we are watching may have. */
2904 if (bs
&& !bs
->stop
&&
2905 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2906 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2907 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2909 remove_breakpoints ();
2910 insert_breakpoints ();
2915 /* Tell what to do about this bpstat. */
2917 bpstat_what (bpstat bs
)
2919 /* Classify each bpstat as one of the following. */
2922 /* This bpstat element has no effect on the main_action. */
2925 /* There was a watchpoint, stop but don't print. */
2928 /* There was a watchpoint, stop and print. */
2931 /* There was a breakpoint but we're not stopping. */
2934 /* There was a breakpoint, stop but don't print. */
2937 /* There was a breakpoint, stop and print. */
2940 /* We hit the longjmp breakpoint. */
2943 /* We hit the longjmp_resume breakpoint. */
2946 /* We hit the step_resume breakpoint. */
2949 /* We hit the through_sigtramp breakpoint. */
2952 /* We hit the shared library event breakpoint. */
2955 /* We caught a shared library event. */
2958 /* This is just used to count how many enums there are. */
2962 /* Here is the table which drives this routine. So that we can
2963 format it pretty, we define some abbreviations for the
2964 enum bpstat_what codes. */
2965 #define kc BPSTAT_WHAT_KEEP_CHECKING
2966 #define ss BPSTAT_WHAT_STOP_SILENT
2967 #define sn BPSTAT_WHAT_STOP_NOISY
2968 #define sgl BPSTAT_WHAT_SINGLE
2969 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2970 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2971 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2972 #define sr BPSTAT_WHAT_STEP_RESUME
2973 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2974 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2975 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2977 /* "Can't happen." Might want to print an error message.
2978 abort() is not out of the question, but chances are GDB is just
2979 a bit confused, not unusable. */
2980 #define err BPSTAT_WHAT_STOP_NOISY
2982 /* Given an old action and a class, come up with a new action. */
2983 /* One interesting property of this table is that wp_silent is the same
2984 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2985 after stopping, the check for whether to step over a breakpoint
2986 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2987 reference to how we stopped. We retain separate wp_silent and
2988 bp_silent codes in case we want to change that someday.
2990 Another possibly interesting property of this table is that
2991 there's a partial ordering, priority-like, of the actions. Once
2992 you've decided that some action is appropriate, you'll never go
2993 back and decide something of a lower priority is better. The
2996 kc < clr sgl shl shlr slr sn sr ss ts
2997 sgl < clrs shl shlr slr sn sr ss ts
2998 slr < err shl shlr sn sr ss ts
2999 clr < clrs err shl shlr sn sr ss ts
3000 clrs < err shl shlr sn sr ss ts
3001 ss < shl shlr sn sr ts
3008 What I think this means is that we don't need a damned table
3009 here. If you just put the rows and columns in the right order,
3010 it'd look awfully regular. We could simply walk the bpstat list
3011 and choose the highest priority action we find, with a little
3012 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3013 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3014 is messy anyway). */
3016 /* step_resume entries: a step resume breakpoint overrides another
3017 breakpoint of signal handling (see comment in wait_for_inferior
3018 at where we set the step_resume breakpoint). */
3019 /* We handle the through_sigtramp_breakpoint the same way; having both
3020 one of those and a step_resume_breakpoint is probably very rare (?). */
3022 static const enum bpstat_what_main_action
3023 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3026 /* kc ss sn sgl slr clr clrs sr ts shl shlr
3029 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
3031 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
3033 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
3035 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
3037 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
3039 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
3041 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
3043 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
3045 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
3047 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
3049 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
3051 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
3066 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3067 struct bpstat_what retval
;
3069 retval
.call_dummy
= 0;
3070 for (; bs
!= NULL
; bs
= bs
->next
)
3072 enum class bs_class
= no_effect
;
3073 if (bs
->breakpoint_at
== NULL
)
3074 /* I suspect this can happen if it was a momentary breakpoint
3075 which has since been deleted. */
3077 switch (bs
->breakpoint_at
->type
)
3083 case bp_hardware_breakpoint
:
3089 bs_class
= bp_noisy
;
3091 bs_class
= bp_silent
;
3094 bs_class
= bp_nostop
;
3097 case bp_hardware_watchpoint
:
3098 case bp_read_watchpoint
:
3099 case bp_access_watchpoint
:
3103 bs_class
= wp_noisy
;
3105 bs_class
= wp_silent
;
3108 /* There was a watchpoint, but we're not stopping.
3109 This requires no further action. */
3110 bs_class
= no_effect
;
3113 bs_class
= long_jump
;
3115 case bp_longjmp_resume
:
3116 bs_class
= long_resume
;
3118 case bp_step_resume
:
3121 bs_class
= step_resume
;
3124 /* It is for the wrong frame. */
3125 bs_class
= bp_nostop
;
3127 case bp_through_sigtramp
:
3128 bs_class
= through_sig
;
3130 case bp_watchpoint_scope
:
3131 bs_class
= bp_nostop
;
3133 case bp_shlib_event
:
3134 bs_class
= shlib_event
;
3136 case bp_thread_event
:
3137 case bp_overlay_event
:
3138 bs_class
= bp_nostop
;
3141 case bp_catch_unload
:
3142 /* Only if this catchpoint triggered should we cause the
3143 step-out-of-dld behaviour. Otherwise, we ignore this
3146 bs_class
= catch_shlib_event
;
3148 bs_class
= no_effect
;
3151 case bp_catch_vfork
:
3156 bs_class
= bp_noisy
;
3158 bs_class
= bp_silent
;
3161 /* There was a catchpoint, but we're not stopping.
3162 This requires no further action. */
3163 bs_class
= no_effect
;
3165 case bp_catch_catch
:
3166 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3167 bs_class
= bp_nostop
;
3169 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3171 case bp_catch_throw
:
3172 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3173 bs_class
= bp_nostop
;
3175 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3178 /* Make sure the action is stop (silent or noisy),
3179 so infrun.c pops the dummy frame. */
3180 bs_class
= bp_silent
;
3181 retval
.call_dummy
= 1;
3184 current_action
= table
[(int) bs_class
][(int) current_action
];
3186 retval
.main_action
= current_action
;
3190 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3191 without hardware support). This isn't related to a specific bpstat,
3192 just to things like whether watchpoints are set. */
3195 bpstat_should_step (void)
3197 struct breakpoint
*b
;
3199 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3204 /* Nonzero if there are enabled hardware watchpoints. */
3206 bpstat_have_active_hw_watchpoints (void)
3208 struct bp_location
*bpt
;
3209 ALL_BP_LOCATIONS (bpt
)
3210 if (breakpoint_enabled (bpt
->owner
)
3212 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3218 /* Given a bpstat that records zero or more triggered eventpoints, this
3219 function returns another bpstat which contains only the catchpoints
3220 on that first list, if any. */
3222 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3224 struct bpstats root_bs
[1];
3225 bpstat bs
= root_bs
;
3226 struct breakpoint
*ep
;
3229 bpstat_clear (cp_list
);
3230 root_bs
->next
= NULL
;
3232 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3234 /* Is this eventpoint a catchpoint? If not, ignore it. */
3235 ep
= ep_list
->breakpoint_at
;
3238 if ((ep
->type
!= bp_catch_load
) &&
3239 (ep
->type
!= bp_catch_unload
) &&
3240 (ep
->type
!= bp_catch_catch
) &&
3241 (ep
->type
!= bp_catch_throw
))
3242 /* pai: (temp) ADD fork/vfork here!! */
3245 /* Yes; add it to the list. */
3246 bs
= bpstat_alloc (ep
, bs
);
3251 #if defined(SOLIB_ADD)
3252 /* Also, for each triggered catchpoint, tag it with the name of
3253 the library that caused this trigger. (We copy the name now,
3254 because it's only guaranteed to be available NOW, when the
3255 catchpoint triggers. Clients who may wish to know the name
3256 later must get it from the catchpoint itself.) */
3257 if (ep
->triggered_dll_pathname
!= NULL
)
3258 xfree (ep
->triggered_dll_pathname
);
3259 if (ep
->type
== bp_catch_load
)
3260 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3261 PIDGET (inferior_ptid
));
3263 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3264 PIDGET (inferior_ptid
));
3266 dll_pathname
= NULL
;
3270 ep
->triggered_dll_pathname
= (char *)
3271 xmalloc (strlen (dll_pathname
) + 1);
3272 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3275 ep
->triggered_dll_pathname
= NULL
;
3281 /* Print B to gdb_stdout. */
3283 print_one_breakpoint (struct breakpoint
*b
,
3284 CORE_ADDR
*last_addr
)
3286 struct command_line
*l
;
3288 struct ep_type_description
3293 static struct ep_type_description bptypes
[] =
3295 {bp_none
, "?deleted?"},
3296 {bp_breakpoint
, "breakpoint"},
3297 {bp_hardware_breakpoint
, "hw breakpoint"},
3298 {bp_until
, "until"},
3299 {bp_finish
, "finish"},
3300 {bp_watchpoint
, "watchpoint"},
3301 {bp_hardware_watchpoint
, "hw watchpoint"},
3302 {bp_read_watchpoint
, "read watchpoint"},
3303 {bp_access_watchpoint
, "acc watchpoint"},
3304 {bp_longjmp
, "longjmp"},
3305 {bp_longjmp_resume
, "longjmp resume"},
3306 {bp_step_resume
, "step resume"},
3307 {bp_through_sigtramp
, "sigtramp"},
3308 {bp_watchpoint_scope
, "watchpoint scope"},
3309 {bp_call_dummy
, "call dummy"},
3310 {bp_shlib_event
, "shlib events"},
3311 {bp_thread_event
, "thread events"},
3312 {bp_overlay_event
, "overlay events"},
3313 {bp_catch_load
, "catch load"},
3314 {bp_catch_unload
, "catch unload"},
3315 {bp_catch_fork
, "catch fork"},
3316 {bp_catch_vfork
, "catch vfork"},
3317 {bp_catch_exec
, "catch exec"},
3318 {bp_catch_catch
, "catch catch"},
3319 {bp_catch_throw
, "catch throw"}
3322 static char *bpdisps
[] =
3323 {"del", "dstp", "dis", "keep"};
3324 static char bpenables
[] = "nynny";
3325 char wrap_indent
[80];
3326 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3327 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3328 struct cleanup
*bkpt_chain
;
3331 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3335 ui_out_field_int (uiout
, "number", b
->number
);
3339 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3340 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3341 internal_error (__FILE__
, __LINE__
,
3342 _("bptypes table does not describe type #%d."),
3344 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3348 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3352 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3353 ui_out_spaces (uiout
, 2);
3356 strcpy (wrap_indent
, " ");
3359 if (TARGET_ADDR_BIT
<= 32)
3360 strcat (wrap_indent
, " ");
3362 strcat (wrap_indent
, " ");
3365 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3366 b
->ops
->print_one (b
, last_addr
);
3371 internal_error (__FILE__
, __LINE__
,
3372 _("print_one_breakpoint: bp_none encountered\n"));
3376 case bp_hardware_watchpoint
:
3377 case bp_read_watchpoint
:
3378 case bp_access_watchpoint
:
3379 /* Field 4, the address, is omitted (which makes the columns
3380 not line up too nicely with the headers, but the effect
3381 is relatively readable). */
3383 ui_out_field_skip (uiout
, "addr");
3385 print_expression (b
->exp
, stb
->stream
);
3386 ui_out_field_stream (uiout
, "what", stb
);
3390 case bp_catch_unload
:
3391 /* Field 4, the address, is omitted (which makes the columns
3392 not line up too nicely with the headers, but the effect
3393 is relatively readable). */
3395 ui_out_field_skip (uiout
, "addr");
3397 if (b
->dll_pathname
== NULL
)
3399 ui_out_field_string (uiout
, "what", "<any library>");
3400 ui_out_spaces (uiout
, 1);
3404 ui_out_text (uiout
, "library \"");
3405 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3406 ui_out_text (uiout
, "\" ");
3411 case bp_catch_vfork
:
3412 /* Field 4, the address, is omitted (which makes the columns
3413 not line up too nicely with the headers, but the effect
3414 is relatively readable). */
3416 ui_out_field_skip (uiout
, "addr");
3418 if (b
->forked_inferior_pid
!= 0)
3420 ui_out_text (uiout
, "process ");
3421 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3422 ui_out_spaces (uiout
, 1);
3427 /* Field 4, the address, is omitted (which makes the columns
3428 not line up too nicely with the headers, but the effect
3429 is relatively readable). */
3431 ui_out_field_skip (uiout
, "addr");
3433 if (b
->exec_pathname
!= NULL
)
3435 ui_out_text (uiout
, "program \"");
3436 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3437 ui_out_text (uiout
, "\" ");
3441 case bp_catch_catch
:
3442 /* Field 4, the address, is omitted (which makes the columns
3443 not line up too nicely with the headers, but the effect
3444 is relatively readable). */
3446 ui_out_field_skip (uiout
, "addr");
3448 ui_out_field_string (uiout
, "what", "exception catch");
3449 ui_out_spaces (uiout
, 1);
3452 case bp_catch_throw
:
3453 /* Field 4, the address, is omitted (which makes the columns
3454 not line up too nicely with the headers, but the effect
3455 is relatively readable). */
3457 ui_out_field_skip (uiout
, "addr");
3459 ui_out_field_string (uiout
, "what", "exception throw");
3460 ui_out_spaces (uiout
, 1);
3464 case bp_hardware_breakpoint
:
3468 case bp_longjmp_resume
:
3469 case bp_step_resume
:
3470 case bp_through_sigtramp
:
3471 case bp_watchpoint_scope
:
3473 case bp_shlib_event
:
3474 case bp_thread_event
:
3475 case bp_overlay_event
:
3480 ui_out_field_string (uiout
, "addr", "<PENDING>");
3482 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3485 *last_addr
= b
->loc
->address
;
3488 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3491 ui_out_text (uiout
, "in ");
3492 ui_out_field_string (uiout
, "func",
3493 SYMBOL_PRINT_NAME (sym
));
3494 ui_out_wrap_hint (uiout
, wrap_indent
);
3495 ui_out_text (uiout
, " at ");
3497 ui_out_field_string (uiout
, "file", b
->source_file
);
3498 ui_out_text (uiout
, ":");
3500 if (ui_out_is_mi_like_p (uiout
))
3502 struct symtab_and_line sal
= find_pc_line (b
->loc
->address
, 0);
3503 char *fullname
= symtab_to_fullname (sal
.symtab
);
3506 ui_out_field_string (uiout
, "fullname", fullname
);
3509 ui_out_field_int (uiout
, "line", b
->line_number
);
3511 else if (b
->pending
)
3513 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3517 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3518 ui_out_field_stream (uiout
, "at", stb
);
3523 if (b
->thread
!= -1)
3525 /* FIXME: This seems to be redundant and lost here; see the
3526 "stop only in" line a little further down. */
3527 ui_out_text (uiout
, " thread ");
3528 ui_out_field_int (uiout
, "thread", b
->thread
);
3531 ui_out_text (uiout
, "\n");
3533 if (frame_id_p (b
->frame_id
))
3536 ui_out_text (uiout
, "\tstop only in stack frame at ");
3537 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3539 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3540 ui_out_text (uiout
, "\n");
3546 ui_out_text (uiout
, "\tstop only if ");
3547 print_expression (b
->cond
, stb
->stream
);
3548 ui_out_field_stream (uiout
, "cond", stb
);
3549 ui_out_text (uiout
, "\n");
3552 if (b
->pending
&& b
->cond_string
)
3555 ui_out_text (uiout
, "\tstop only if ");
3556 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3557 ui_out_text (uiout
, "\n");
3560 if (b
->thread
!= -1)
3562 /* FIXME should make an annotation for this */
3563 ui_out_text (uiout
, "\tstop only in thread ");
3564 ui_out_field_int (uiout
, "thread", b
->thread
);
3565 ui_out_text (uiout
, "\n");
3568 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3570 /* FIXME should make an annotation for this */
3571 if (ep_is_catchpoint (b
))
3572 ui_out_text (uiout
, "\tcatchpoint");
3574 ui_out_text (uiout
, "\tbreakpoint");
3575 ui_out_text (uiout
, " already hit ");
3576 ui_out_field_int (uiout
, "times", b
->hit_count
);
3577 if (b
->hit_count
== 1)
3578 ui_out_text (uiout
, " time\n");
3580 ui_out_text (uiout
, " times\n");
3583 /* Output the count also if it is zero, but only if this is
3584 mi. FIXME: Should have a better test for this. */
3585 if (ui_out_is_mi_like_p (uiout
))
3586 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3587 ui_out_field_int (uiout
, "times", b
->hit_count
);
3589 if (b
->ignore_count
)
3592 ui_out_text (uiout
, "\tignore next ");
3593 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3594 ui_out_text (uiout
, " hits\n");
3597 if ((l
= b
->commands
))
3599 struct cleanup
*script_chain
;
3602 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3603 print_command_lines (uiout
, l
, 4);
3604 do_cleanups (script_chain
);
3606 do_cleanups (bkpt_chain
);
3607 do_cleanups (old_chain
);
3610 struct captured_breakpoint_query_args
3616 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3618 struct captured_breakpoint_query_args
*args
= data
;
3619 struct breakpoint
*b
;
3620 CORE_ADDR dummy_addr
= 0;
3623 if (args
->bnum
== b
->number
)
3625 print_one_breakpoint (b
, &dummy_addr
);
3633 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3635 struct captured_breakpoint_query_args args
;
3637 /* For the moment we don't trust print_one_breakpoint() to not throw
3639 return catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3640 error_message
, RETURN_MASK_ALL
);
3643 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3644 catchpoints, et.al.). */
3647 user_settable_breakpoint (const struct breakpoint
*b
)
3649 return (b
->type
== bp_breakpoint
3650 || b
->type
== bp_catch_load
3651 || b
->type
== bp_catch_unload
3652 || b
->type
== bp_catch_fork
3653 || b
->type
== bp_catch_vfork
3654 || b
->type
== bp_catch_exec
3655 || b
->type
== bp_catch_catch
3656 || b
->type
== bp_catch_throw
3657 || b
->type
== bp_hardware_breakpoint
3658 || b
->type
== bp_watchpoint
3659 || b
->type
== bp_read_watchpoint
3660 || b
->type
== bp_access_watchpoint
3661 || b
->type
== bp_hardware_watchpoint
);
3664 /* Print information on user settable breakpoint (watchpoint, etc)
3665 number BNUM. If BNUM is -1 print all user settable breakpoints.
3666 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3669 breakpoint_1 (int bnum
, int allflag
)
3671 struct breakpoint
*b
;
3672 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3673 int nr_printable_breakpoints
;
3674 struct cleanup
*bkpttbl_chain
;
3676 /* Compute the number of rows in the table. */
3677 nr_printable_breakpoints
= 0;
3680 || bnum
== b
->number
)
3682 if (allflag
|| user_settable_breakpoint (b
))
3683 nr_printable_breakpoints
++;
3688 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3692 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3695 if (nr_printable_breakpoints
> 0)
3696 annotate_breakpoints_headers ();
3697 if (nr_printable_breakpoints
> 0)
3699 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3700 if (nr_printable_breakpoints
> 0)
3702 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3703 if (nr_printable_breakpoints
> 0)
3705 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3706 if (nr_printable_breakpoints
> 0)
3708 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3711 if (nr_printable_breakpoints
> 0)
3713 if (TARGET_ADDR_BIT
<= 32)
3714 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3716 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3718 if (nr_printable_breakpoints
> 0)
3720 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3721 ui_out_table_body (uiout
);
3722 if (nr_printable_breakpoints
> 0)
3723 annotate_breakpoints_table ();
3727 || bnum
== b
->number
)
3729 /* We only print out user settable breakpoints unless the
3731 if (allflag
|| user_settable_breakpoint (b
))
3732 print_one_breakpoint (b
, &last_addr
);
3735 do_cleanups (bkpttbl_chain
);
3737 if (nr_printable_breakpoints
== 0)
3740 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3742 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3747 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3748 that a comparison of an unsigned with -1 is always false. */
3749 if (last_addr
!= (CORE_ADDR
) -1)
3750 set_next_address (last_addr
);
3753 /* FIXME? Should this be moved up so that it is only called when
3754 there have been breakpoints? */
3755 annotate_breakpoints_table_end ();
3759 breakpoints_info (char *bnum_exp
, int from_tty
)
3764 bnum
= parse_and_eval_long (bnum_exp
);
3766 breakpoint_1 (bnum
, 0);
3770 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3775 bnum
= parse_and_eval_long (bnum_exp
);
3777 breakpoint_1 (bnum
, 1);
3780 /* Print a message describing any breakpoints set at PC. */
3783 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3786 struct breakpoint
*b
;
3789 if (b
->loc
->address
== pc
) /* address match / overlay match */
3790 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3795 printf_filtered (_("Note: breakpoint "));
3796 else /* if (others == ???) */
3797 printf_filtered (_("Note: breakpoints "));
3799 if (b
->loc
->address
== pc
) /* address match / overlay match */
3800 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3803 printf_filtered ("%d%s%s ",
3805 ((b
->enable_state
== bp_disabled
||
3806 b
->enable_state
== bp_shlib_disabled
||
3807 b
->enable_state
== bp_call_disabled
)
3809 : b
->enable_state
== bp_permanent
3813 : ((others
== 1) ? " and" : ""));
3815 printf_filtered (_("also set at pc "));
3816 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
3817 printf_filtered (".\n");
3821 /* Set the default place to put a breakpoint
3822 for the `break' command with no arguments. */
3825 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3828 default_breakpoint_valid
= valid
;
3829 default_breakpoint_address
= addr
;
3830 default_breakpoint_symtab
= symtab
;
3831 default_breakpoint_line
= line
;
3834 /* Return true iff it is meaningful to use the address member of
3835 BPT. For some breakpoint types, the address member is irrelevant
3836 and it makes no sense to attempt to compare it to other addresses
3837 (or use it for any other purpose either).
3839 More specifically, each of the following breakpoint types will always
3840 have a zero valued address and we don't want check_duplicates() to mark
3841 breakpoints of any of these types to be a duplicate of an actual
3842 breakpoint at address zero:
3845 bp_hardware_watchpoint
3847 bp_access_watchpoint
3854 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3856 enum bptype type
= bpt
->type
;
3858 return (type
!= bp_watchpoint
3859 && type
!= bp_hardware_watchpoint
3860 && type
!= bp_read_watchpoint
3861 && type
!= bp_access_watchpoint
3862 && type
!= bp_catch_exec
3863 && type
!= bp_longjmp_resume
3864 && type
!= bp_catch_fork
3865 && type
!= bp_catch_vfork
);
3868 /* Rescan breakpoints at the same address and section as BPT,
3869 marking the first one as "first" and any others as "duplicates".
3870 This is so that the bpt instruction is only inserted once.
3871 If we have a permanent breakpoint at the same place as BPT, make
3872 that one the official one, and the rest as duplicates. */
3875 check_duplicates (struct breakpoint
*bpt
)
3877 struct bp_location
*b
;
3879 struct bp_location
*perm_bp
= 0;
3880 CORE_ADDR address
= bpt
->loc
->address
;
3881 asection
*section
= bpt
->loc
->section
;
3883 if (! breakpoint_address_is_meaningful (bpt
))
3886 ALL_BP_LOCATIONS (b
)
3887 if (b
->owner
->enable_state
!= bp_disabled
3888 && b
->owner
->enable_state
!= bp_shlib_disabled
3889 && !b
->owner
->pending
3890 && b
->owner
->enable_state
!= bp_call_disabled
3891 && b
->address
== address
/* address / overlay match */
3892 && (!overlay_debugging
|| b
->section
== section
)
3893 && breakpoint_address_is_meaningful (b
->owner
))
3895 /* Have we found a permanent breakpoint? */
3896 if (b
->owner
->enable_state
== bp_permanent
)
3903 b
->duplicate
= count
> 1;
3906 /* If we found a permanent breakpoint at this address, go over the
3907 list again and declare all the other breakpoints there to be the
3911 perm_bp
->duplicate
= 0;
3913 /* Permanent breakpoint should always be inserted. */
3914 if (! perm_bp
->inserted
)
3915 internal_error (__FILE__
, __LINE__
,
3916 _("allegedly permanent breakpoint is not "
3917 "actually inserted"));
3919 ALL_BP_LOCATIONS (b
)
3922 if (b
->owner
->enable_state
!= bp_disabled
3923 && b
->owner
->enable_state
!= bp_shlib_disabled
3924 && !b
->owner
->pending
3925 && b
->owner
->enable_state
!= bp_call_disabled
3926 && b
->address
== address
/* address / overlay match */
3927 && (!overlay_debugging
|| b
->section
== section
)
3928 && breakpoint_address_is_meaningful (b
->owner
))
3931 internal_error (__FILE__
, __LINE__
,
3932 _("another breakpoint was inserted on top of "
3933 "a permanent breakpoint"));
3942 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3943 int bnum
, int have_bnum
)
3948 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3949 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3951 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3952 bnum
, astr1
, astr2
);
3954 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
3957 /* Adjust a breakpoint's address to account for architectural constraints
3958 on breakpoint placement. Return the adjusted address. Note: Very
3959 few targets require this kind of adjustment. For most targets,
3960 this function is simply the identity function. */
3963 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
3965 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3967 /* Very few targets need any kind of breakpoint adjustment. */
3970 else if (bptype
== bp_watchpoint
3971 || bptype
== bp_hardware_watchpoint
3972 || bptype
== bp_read_watchpoint
3973 || bptype
== bp_access_watchpoint
3974 || bptype
== bp_catch_fork
3975 || bptype
== bp_catch_vfork
3976 || bptype
== bp_catch_exec
)
3978 /* Watchpoints and the various bp_catch_* eventpoints should not
3979 have their addresses modified. */
3984 CORE_ADDR adjusted_bpaddr
;
3986 /* Some targets have architectural constraints on the placement
3987 of breakpoint instructions. Obtain the adjusted address. */
3988 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
3991 /* An adjusted breakpoint address can significantly alter
3992 a user's expectations. Print a warning if an adjustment
3994 if (adjusted_bpaddr
!= bpaddr
)
3995 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
3997 return adjusted_bpaddr
;
4001 /* Allocate a struct bp_location. */
4003 static struct bp_location
*
4004 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4006 struct bp_location
*loc
, *loc_p
;
4008 loc
= xmalloc (sizeof (struct bp_location
));
4009 memset (loc
, 0, sizeof (*loc
));
4019 case bp_longjmp_resume
:
4020 case bp_step_resume
:
4021 case bp_through_sigtramp
:
4022 case bp_watchpoint_scope
:
4024 case bp_shlib_event
:
4025 case bp_thread_event
:
4026 case bp_overlay_event
:
4028 case bp_catch_unload
:
4029 loc
->loc_type
= bp_loc_software_breakpoint
;
4031 case bp_hardware_breakpoint
:
4032 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4034 case bp_hardware_watchpoint
:
4035 case bp_read_watchpoint
:
4036 case bp_access_watchpoint
:
4037 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4041 case bp_catch_vfork
:
4043 case bp_catch_catch
:
4044 case bp_catch_throw
:
4045 loc
->loc_type
= bp_loc_other
;
4048 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4051 /* Add this breakpoint to the end of the chain. */
4053 loc_p
= bp_location_chain
;
4055 bp_location_chain
= loc
;
4059 loc_p
= loc_p
->next
;
4066 /* set_raw_breakpoint() is a low level routine for allocating and
4067 partially initializing a breakpoint of type BPTYPE. The newly
4068 created breakpoint's address, section, source file name, and line
4069 number are provided by SAL. The newly created and partially
4070 initialized breakpoint is added to the breakpoint chain and
4071 is also returned as the value of this function.
4073 It is expected that the caller will complete the initialization of
4074 the newly created breakpoint struct as well as output any status
4075 information regarding the creation of a new breakpoint. In
4076 particular, set_raw_breakpoint() does NOT set the breakpoint
4077 number! Care should be taken to not allow an error() to occur
4078 prior to completing the initialization of the breakpoint. If this
4079 should happen, a bogus breakpoint will be left on the chain. */
4082 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4084 struct breakpoint
*b
, *b1
;
4086 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4087 memset (b
, 0, sizeof (*b
));
4088 b
->loc
= allocate_bp_location (b
, bptype
);
4089 b
->loc
->requested_address
= sal
.pc
;
4090 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4092 if (sal
.symtab
== NULL
)
4093 b
->source_file
= NULL
;
4095 b
->source_file
= savestring (sal
.symtab
->filename
,
4096 strlen (sal
.symtab
->filename
));
4097 b
->loc
->section
= sal
.section
;
4099 b
->language
= current_language
->la_language
;
4100 b
->input_radix
= input_radix
;
4102 b
->line_number
= sal
.line
;
4103 b
->enable_state
= bp_enabled
;
4106 b
->ignore_count
= 0;
4108 b
->frame_id
= null_frame_id
;
4109 b
->dll_pathname
= NULL
;
4110 b
->triggered_dll_pathname
= NULL
;
4111 b
->forked_inferior_pid
= 0;
4112 b
->exec_pathname
= NULL
;
4116 /* Add this breakpoint to the end of the chain
4117 so that a list of breakpoints will come out in order
4118 of increasing numbers. */
4120 b1
= breakpoint_chain
;
4122 breakpoint_chain
= b
;
4130 check_duplicates (b
);
4131 breakpoints_changed ();
4137 /* Note that the breakpoint object B describes a permanent breakpoint
4138 instruction, hard-wired into the inferior's code. */
4140 make_breakpoint_permanent (struct breakpoint
*b
)
4142 b
->enable_state
= bp_permanent
;
4144 /* By definition, permanent breakpoints are already present in the code. */
4145 b
->loc
->inserted
= 1;
4148 static struct breakpoint
*
4149 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4151 static int internal_breakpoint_number
= -1;
4152 struct symtab_and_line sal
;
4153 struct breakpoint
*b
;
4155 init_sal (&sal
); /* initialize to zeroes */
4158 sal
.section
= find_pc_overlay (sal
.pc
);
4160 b
= set_raw_breakpoint (sal
, type
);
4161 b
->number
= internal_breakpoint_number
--;
4162 b
->disposition
= disp_donttouch
;
4169 create_longjmp_breakpoint (char *func_name
)
4171 struct breakpoint
*b
;
4172 struct minimal_symbol
*m
;
4174 if (func_name
== NULL
)
4175 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4178 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4181 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4184 b
->enable_state
= bp_disabled
;
4187 b
->addr_string
= xstrdup (func_name
);
4190 /* Call this routine when stepping and nexting to enable a breakpoint
4191 if we do a longjmp(). When we hit that breakpoint, call
4192 set_longjmp_resume_breakpoint() to figure out where we are going. */
4195 enable_longjmp_breakpoint (void)
4197 struct breakpoint
*b
;
4200 if (b
->type
== bp_longjmp
)
4202 b
->enable_state
= bp_enabled
;
4203 check_duplicates (b
);
4208 disable_longjmp_breakpoint (void)
4210 struct breakpoint
*b
;
4213 if (b
->type
== bp_longjmp
4214 || b
->type
== bp_longjmp_resume
)
4216 b
->enable_state
= bp_disabled
;
4217 check_duplicates (b
);
4222 create_overlay_event_breakpoint (char *func_name
)
4224 struct breakpoint
*b
;
4225 struct minimal_symbol
*m
;
4227 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4230 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4232 b
->addr_string
= xstrdup (func_name
);
4234 if (overlay_debugging
== ovly_auto
)
4236 b
->enable_state
= bp_enabled
;
4237 overlay_events_enabled
= 1;
4241 b
->enable_state
= bp_disabled
;
4242 overlay_events_enabled
= 0;
4247 enable_overlay_breakpoints (void)
4249 struct breakpoint
*b
;
4252 if (b
->type
== bp_overlay_event
)
4254 b
->enable_state
= bp_enabled
;
4255 check_duplicates (b
);
4256 overlay_events_enabled
= 1;
4261 disable_overlay_breakpoints (void)
4263 struct breakpoint
*b
;
4266 if (b
->type
== bp_overlay_event
)
4268 b
->enable_state
= bp_disabled
;
4269 check_duplicates (b
);
4270 overlay_events_enabled
= 0;
4275 create_thread_event_breakpoint (CORE_ADDR address
)
4277 struct breakpoint
*b
;
4279 b
= create_internal_breakpoint (address
, bp_thread_event
);
4281 b
->enable_state
= bp_enabled
;
4282 /* addr_string has to be used or breakpoint_re_set will delete me. */
4283 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4289 remove_thread_event_breakpoints (void)
4291 struct breakpoint
*b
, *temp
;
4293 ALL_BREAKPOINTS_SAFE (b
, temp
)
4294 if (b
->type
== bp_thread_event
)
4295 delete_breakpoint (b
);
4298 struct captured_parse_breakpoint_args
4301 struct symtabs_and_lines
*sals_p
;
4302 char ***addr_string_p
;
4306 struct lang_and_radix
4312 /* Cleanup helper routine to restore the current language and
4315 do_restore_lang_radix_cleanup (void *old
)
4317 struct lang_and_radix
*p
= old
;
4318 set_language (p
->lang
);
4319 input_radix
= p
->radix
;
4322 /* Try and resolve a pending breakpoint. */
4324 resolve_pending_breakpoint (struct breakpoint
*b
)
4326 /* Try and reparse the breakpoint in case the shared library
4328 struct symtabs_and_lines sals
;
4329 struct symtab_and_line pending_sal
;
4330 char **cond_string
= (char **) NULL
;
4331 char *copy_arg
= b
->addr_string
;
4336 struct ui_file
*old_gdb_stderr
;
4337 struct lang_and_radix old_lr
;
4338 struct cleanup
*old_chain
;
4340 /* Set language, input-radix, then reissue breakpoint command.
4341 Ensure the language and input-radix are restored afterwards. */
4342 old_lr
.lang
= current_language
->la_language
;
4343 old_lr
.radix
= input_radix
;
4344 old_chain
= make_cleanup (do_restore_lang_radix_cleanup
, &old_lr
);
4346 set_language (b
->language
);
4347 input_radix
= b
->input_radix
;
4348 rc
= break_command_1 (b
->addr_string
, b
->flag
, b
->from_tty
, b
);
4350 if (rc
== GDB_RC_OK
)
4351 /* Pending breakpoint has been resolved. */
4352 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b
->addr_string
);
4354 do_cleanups (old_chain
);
4359 remove_solib_event_breakpoints (void)
4361 struct breakpoint
*b
, *temp
;
4363 ALL_BREAKPOINTS_SAFE (b
, temp
)
4364 if (b
->type
== bp_shlib_event
)
4365 delete_breakpoint (b
);
4369 create_solib_event_breakpoint (CORE_ADDR address
)
4371 struct breakpoint
*b
;
4373 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4377 /* Disable any breakpoints that are on code in shared libraries. Only
4378 apply to enabled breakpoints, disabled ones can just stay disabled. */
4381 disable_breakpoints_in_shlibs (int silent
)
4383 struct breakpoint
*b
;
4384 int disabled_shlib_breaks
= 0;
4386 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4389 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4390 && breakpoint_enabled (b
) && !b
->loc
->duplicate
4392 && PC_SOLIB (b
->loc
->address
)
4394 && solib_address (b
->loc
->address
)
4398 b
->enable_state
= bp_shlib_disabled
;
4401 if (!disabled_shlib_breaks
)
4403 target_terminal_ours_for_output ();
4404 warning (_("Temporarily disabling shared library breakpoints:"));
4406 disabled_shlib_breaks
= 1;
4407 warning (_("breakpoint #%d "), b
->number
);
4413 /* Disable any breakpoints that are in in an unloaded shared library. Only
4414 apply to enabled breakpoints, disabled ones can just stay disabled. */
4417 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4419 struct breakpoint
*b
;
4420 int disabled_shlib_breaks
= 0;
4422 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4425 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4426 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4427 && breakpoint_enabled (b
) && !b
->loc
->duplicate
)
4430 char *so_name
= PC_SOLIB (b
->loc
->address
);
4432 char *so_name
= solib_address (b
->loc
->address
);
4434 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4436 b
->enable_state
= bp_shlib_disabled
;
4437 /* At this point, we cannot rely on remove_breakpoint
4438 succeeding so we must mark the breakpoint as not inserted
4439 to prevent future errors occurring in remove_breakpoints. */
4440 b
->loc
->inserted
= 0;
4441 if (!disabled_shlib_breaks
)
4443 target_terminal_ours_for_output ();
4444 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4447 disabled_shlib_breaks
= 1;
4453 /* Try to reenable any breakpoints in shared libraries. */
4455 re_enable_breakpoints_in_shlibs (void)
4457 struct breakpoint
*b
, *tmp
;
4459 ALL_BREAKPOINTS_SAFE (b
, tmp
)
4461 if (b
->enable_state
== bp_shlib_disabled
)
4466 /* Do not reenable the breakpoint if the shared library is
4467 still not mapped in. */
4469 lib
= PC_SOLIB (b
->loc
->address
);
4471 lib
= solib_address (b
->loc
->address
);
4473 if (lib
!= NULL
&& target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4474 b
->enable_state
= bp_enabled
;
4476 else if (b
->pending
&& (b
->enable_state
== bp_enabled
))
4478 if (resolve_pending_breakpoint (b
) == GDB_RC_OK
)
4479 delete_breakpoint (b
);
4485 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4486 char *cond_string
, enum bptype bp_kind
)
4488 struct breakpoint
*b
;
4489 struct symtabs_and_lines sals
;
4490 struct cleanup
*old_chain
;
4491 struct cleanup
*canonical_strings_chain
= NULL
;
4492 char *addr_start
= hookname
;
4493 char *addr_end
= NULL
;
4494 char **canonical
= (char **) NULL
;
4495 int thread
= -1; /* All threads. */
4497 /* Set a breakpoint on the specified hook. */
4498 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
,
4499 0, &canonical
, NULL
);
4500 addr_end
= hookname
;
4502 if (sals
.nelts
== 0)
4504 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4505 "Suggest linking with /opt/langtools/lib/end.o.\n"
4506 "GDB will be unable to track shl_load/shl_unload calls."));
4509 if (sals
.nelts
!= 1)
4511 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4512 "GDB will be unable to track shl_load/shl_unload calls."));
4516 /* Make sure that all storage allocated in decode_line_1 gets freed
4517 in case the following errors out. */
4518 old_chain
= make_cleanup (xfree
, sals
.sals
);
4519 if (canonical
!= (char **) NULL
)
4521 make_cleanup (xfree
, canonical
);
4522 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4523 if (canonical
[0] != NULL
)
4524 make_cleanup (xfree
, canonical
[0]);
4527 resolve_sal_pc (&sals
.sals
[0]);
4529 /* Remove the canonical strings from the cleanup, they are needed below. */
4530 if (canonical
!= (char **) NULL
)
4531 discard_cleanups (canonical_strings_chain
);
4533 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4534 set_breakpoint_count (breakpoint_count
+ 1);
4535 b
->number
= breakpoint_count
;
4537 b
->cond_string
= (cond_string
== NULL
) ?
4538 NULL
: savestring (cond_string
, strlen (cond_string
));
4541 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4542 b
->addr_string
= canonical
[0];
4543 else if (addr_start
)
4544 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4546 b
->enable_state
= bp_enabled
;
4547 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4549 if (dll_pathname
== NULL
)
4550 b
->dll_pathname
= NULL
;
4553 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4554 strcpy (b
->dll_pathname
, dll_pathname
);
4558 do_cleanups (old_chain
);
4562 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4563 char *dll_pathname
, char *cond_string
)
4565 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4566 cond_string
, bp_catch_load
);
4570 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4571 char *dll_pathname
, char *cond_string
)
4573 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4574 cond_string
, bp_catch_unload
);
4578 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4579 enum bptype bp_kind
)
4581 struct symtab_and_line sal
;
4582 struct breakpoint
*b
;
4583 int thread
= -1; /* All threads. */
4590 b
= set_raw_breakpoint (sal
, bp_kind
);
4591 set_breakpoint_count (breakpoint_count
+ 1);
4592 b
->number
= breakpoint_count
;
4594 b
->cond_string
= (cond_string
== NULL
) ?
4595 NULL
: savestring (cond_string
, strlen (cond_string
));
4597 b
->addr_string
= NULL
;
4598 b
->enable_state
= bp_enabled
;
4599 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4600 b
->forked_inferior_pid
= 0;
4606 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4608 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4612 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4614 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4618 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4620 struct symtab_and_line sal
;
4621 struct breakpoint
*b
;
4622 int thread
= -1; /* All threads. */
4629 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4630 set_breakpoint_count (breakpoint_count
+ 1);
4631 b
->number
= breakpoint_count
;
4633 b
->cond_string
= (cond_string
== NULL
) ?
4634 NULL
: savestring (cond_string
, strlen (cond_string
));
4636 b
->addr_string
= NULL
;
4637 b
->enable_state
= bp_enabled
;
4638 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4644 hw_breakpoint_used_count (void)
4646 struct breakpoint
*b
;
4651 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4659 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4661 struct breakpoint
*b
;
4664 *other_type_used
= 0;
4667 if (breakpoint_enabled (b
))
4669 if (b
->type
== type
)
4671 else if ((b
->type
== bp_hardware_watchpoint
||
4672 b
->type
== bp_read_watchpoint
||
4673 b
->type
== bp_access_watchpoint
))
4674 *other_type_used
= 1;
4680 /* Call this after hitting the longjmp() breakpoint. Use this to set
4681 a new breakpoint at the target of the jmp_buf.
4683 FIXME - This ought to be done by setting a temporary breakpoint
4684 that gets deleted automatically... */
4687 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4689 struct breakpoint
*b
;
4692 if (b
->type
== bp_longjmp_resume
)
4694 b
->loc
->requested_address
= pc
;
4695 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4697 b
->enable_state
= bp_enabled
;
4698 b
->frame_id
= frame_id
;
4699 check_duplicates (b
);
4705 disable_watchpoints_before_interactive_call_start (void)
4707 struct breakpoint
*b
;
4711 if (((b
->type
== bp_watchpoint
)
4712 || (b
->type
== bp_hardware_watchpoint
)
4713 || (b
->type
== bp_read_watchpoint
)
4714 || (b
->type
== bp_access_watchpoint
)
4715 || ep_is_exception_catchpoint (b
))
4716 && breakpoint_enabled (b
))
4718 b
->enable_state
= bp_call_disabled
;
4719 check_duplicates (b
);
4725 enable_watchpoints_after_interactive_call_stop (void)
4727 struct breakpoint
*b
;
4731 if (((b
->type
== bp_watchpoint
)
4732 || (b
->type
== bp_hardware_watchpoint
)
4733 || (b
->type
== bp_read_watchpoint
)
4734 || (b
->type
== bp_access_watchpoint
)
4735 || ep_is_exception_catchpoint (b
))
4736 && (b
->enable_state
== bp_call_disabled
))
4738 b
->enable_state
= bp_enabled
;
4739 check_duplicates (b
);
4745 /* Set a breakpoint that will evaporate an end of command
4746 at address specified by SAL.
4747 Restrict it to frame FRAME if FRAME is nonzero. */
4750 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4753 struct breakpoint
*b
;
4754 b
= set_raw_breakpoint (sal
, type
);
4755 b
->enable_state
= bp_enabled
;
4756 b
->disposition
= disp_donttouch
;
4757 b
->frame_id
= frame_id
;
4759 /* If we're debugging a multi-threaded program, then we
4760 want momentary breakpoints to be active in only a
4761 single thread of control. */
4762 if (in_thread_list (inferior_ptid
))
4763 b
->thread
= pid_to_thread_id (inferior_ptid
);
4769 /* Tell the user we have just set a breakpoint B. */
4772 mention (struct breakpoint
*b
)
4775 struct cleanup
*old_chain
, *ui_out_chain
;
4776 struct ui_stream
*stb
;
4778 stb
= ui_out_stream_new (uiout
);
4779 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4781 /* FIXME: This is misplaced; mention() is called by things (like
4782 hitting a watchpoint) other than breakpoint creation. It should
4783 be possible to clean this up and at the same time replace the
4784 random calls to breakpoint_changed with this hook, as has already
4785 been done for deprecated_delete_breakpoint_hook and so on. */
4786 if (deprecated_create_breakpoint_hook
)
4787 deprecated_create_breakpoint_hook (b
);
4788 breakpoint_create_event (b
->number
);
4790 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4791 b
->ops
->print_mention (b
);
4796 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4799 ui_out_text (uiout
, "Watchpoint ");
4800 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4801 ui_out_field_int (uiout
, "number", b
->number
);
4802 ui_out_text (uiout
, ": ");
4803 print_expression (b
->exp
, stb
->stream
);
4804 ui_out_field_stream (uiout
, "exp", stb
);
4805 do_cleanups (ui_out_chain
);
4807 case bp_hardware_watchpoint
:
4808 ui_out_text (uiout
, "Hardware watchpoint ");
4809 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4810 ui_out_field_int (uiout
, "number", b
->number
);
4811 ui_out_text (uiout
, ": ");
4812 print_expression (b
->exp
, stb
->stream
);
4813 ui_out_field_stream (uiout
, "exp", stb
);
4814 do_cleanups (ui_out_chain
);
4816 case bp_read_watchpoint
:
4817 ui_out_text (uiout
, "Hardware read watchpoint ");
4818 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4819 ui_out_field_int (uiout
, "number", b
->number
);
4820 ui_out_text (uiout
, ": ");
4821 print_expression (b
->exp
, stb
->stream
);
4822 ui_out_field_stream (uiout
, "exp", stb
);
4823 do_cleanups (ui_out_chain
);
4825 case bp_access_watchpoint
:
4826 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4827 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4828 ui_out_field_int (uiout
, "number", b
->number
);
4829 ui_out_text (uiout
, ": ");
4830 print_expression (b
->exp
, stb
->stream
);
4831 ui_out_field_stream (uiout
, "exp", stb
);
4832 do_cleanups (ui_out_chain
);
4835 if (ui_out_is_mi_like_p (uiout
))
4840 printf_filtered (_("Breakpoint %d"), b
->number
);
4843 case bp_hardware_breakpoint
:
4844 if (ui_out_is_mi_like_p (uiout
))
4849 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4853 case bp_catch_unload
:
4854 printf_filtered (_("Catchpoint %d (%s %s)"),
4856 (b
->type
== bp_catch_load
) ? "load" : "unload",
4857 (b
->dll_pathname
!= NULL
) ?
4858 b
->dll_pathname
: "<any library>");
4861 case bp_catch_vfork
:
4862 printf_filtered (_("Catchpoint %d (%s)"),
4864 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4867 printf_filtered (_("Catchpoint %d (exec)"),
4870 case bp_catch_catch
:
4871 case bp_catch_throw
:
4872 printf_filtered (_("Catchpoint %d (%s)"),
4874 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4880 case bp_longjmp_resume
:
4881 case bp_step_resume
:
4882 case bp_through_sigtramp
:
4884 case bp_watchpoint_scope
:
4885 case bp_shlib_event
:
4886 case bp_thread_event
:
4887 case bp_overlay_event
:
4893 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4897 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4901 if (addressprint
|| b
->source_file
== NULL
)
4903 printf_filtered (" at ");
4904 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4907 printf_filtered (": file %s, line %d.",
4908 b
->source_file
, b
->line_number
);
4911 do_cleanups (old_chain
);
4912 if (ui_out_is_mi_like_p (uiout
))
4914 printf_filtered ("\n");
4918 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4919 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4920 COND[i] and COND_STRING[i] values.
4922 The parameter PENDING_BP points to a pending breakpoint that is
4923 the basis of the breakpoints currently being created. The pending
4924 breakpoint may contain a separate condition string or commands
4925 that were added after the initial pending breakpoint was created.
4927 NOTE: If the function succeeds, the caller is expected to cleanup
4928 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4929 array contents). If the function fails (error() is called), the
4930 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4931 COND and SALS arrays and each of those arrays contents. */
4934 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4935 struct expression
**cond
, char **cond_string
,
4936 enum bptype type
, enum bpdisp disposition
,
4937 int thread
, int ignore_count
, int from_tty
,
4938 struct breakpoint
*pending_bp
)
4940 if (type
== bp_hardware_breakpoint
)
4942 int i
= hw_breakpoint_used_count ();
4943 int target_resources_ok
=
4944 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4946 if (target_resources_ok
== 0)
4947 error (_("No hardware breakpoint support in the target."));
4948 else if (target_resources_ok
< 0)
4949 error (_("Hardware breakpoints used exceeds limit."));
4952 /* Now set all the breakpoints. */
4955 for (i
= 0; i
< sals
.nelts
; i
++)
4957 struct breakpoint
*b
;
4958 struct symtab_and_line sal
= sals
.sals
[i
];
4961 describe_other_breakpoints (sal
.pc
, sal
.section
);
4963 b
= set_raw_breakpoint (sal
, type
);
4964 set_breakpoint_count (breakpoint_count
+ 1);
4965 b
->number
= breakpoint_count
;
4969 b
->addr_string
= addr_string
[i
];
4971 /* addr_string has to be used or breakpoint_re_set will delete
4973 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4974 b
->cond_string
= cond_string
[i
];
4975 b
->ignore_count
= ignore_count
;
4976 b
->enable_state
= bp_enabled
;
4977 b
->disposition
= disposition
;
4978 /* If resolving a pending breakpoint, a check must be made to see if
4979 the user has specified a new condition or commands for the
4980 breakpoint. A new condition will override any condition that was
4981 initially specified with the initial breakpoint command. */
4985 if (pending_bp
->cond_string
)
4987 arg
= pending_bp
->cond_string
;
4988 b
->cond_string
= savestring (arg
, strlen (arg
));
4989 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
4991 error (_("Junk at end of pending breakpoint condition expression"));
4993 /* If there are commands associated with the breakpoint, they should
4995 if (pending_bp
->commands
)
4996 b
->commands
= copy_command_lines (pending_bp
->commands
);
4998 /* We have to copy over the ignore_count and thread as well. */
4999 b
->ignore_count
= pending_bp
->ignore_count
;
5000 b
->thread
= pending_bp
->thread
;
5007 /* Parse ARG which is assumed to be a SAL specification possibly
5008 followed by conditionals. On return, SALS contains an array of SAL
5009 addresses found. ADDR_STRING contains a vector of (canonical)
5010 address strings. ARG points to the end of the SAL. */
5013 parse_breakpoint_sals (char **address
,
5014 struct symtabs_and_lines
*sals
,
5015 char ***addr_string
,
5018 char *addr_start
= *address
;
5019 *addr_string
= NULL
;
5020 /* If no arg given, or if first arg is 'if ', use the default
5022 if ((*address
) == NULL
5023 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5025 if (default_breakpoint_valid
)
5027 struct symtab_and_line sal
;
5028 init_sal (&sal
); /* initialize to zeroes */
5029 sals
->sals
= (struct symtab_and_line
*)
5030 xmalloc (sizeof (struct symtab_and_line
));
5031 sal
.pc
= default_breakpoint_address
;
5032 sal
.line
= default_breakpoint_line
;
5033 sal
.symtab
= default_breakpoint_symtab
;
5034 sal
.section
= find_pc_overlay (sal
.pc
);
5035 sals
->sals
[0] = sal
;
5039 error (_("No default breakpoint address now."));
5043 /* Force almost all breakpoints to be in terms of the
5044 current_source_symtab (which is decode_line_1's default). This
5045 should produce the results we want almost all of the time while
5046 leaving default_breakpoint_* alone.
5047 ObjC: However, don't match an Objective-C method name which
5048 may have a '+' or '-' succeeded by a '[' */
5050 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5052 if (default_breakpoint_valid
5054 || ((strchr ("+-", (*address
)[0]) != NULL
)
5055 && ((*address
)[1] != '['))))
5056 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5057 default_breakpoint_line
, addr_string
,
5060 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5061 addr_string
, not_found_ptr
);
5063 /* For any SAL that didn't have a canonical string, fill one in. */
5064 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5065 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5066 if (addr_start
!= (*address
))
5069 for (i
= 0; i
< sals
->nelts
; i
++)
5071 /* Add the string if not present. */
5072 if ((*addr_string
)[i
] == NULL
)
5073 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5079 /* Convert each SAL into a real PC. Verify that the PC can be
5080 inserted as a breakpoint. If it can't throw an error. */
5083 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5087 for (i
= 0; i
< sals
->nelts
; i
++)
5089 resolve_sal_pc (&sals
->sals
[i
]);
5091 /* It's possible for the PC to be nonzero, but still an illegal
5092 value on some targets.
5094 For example, on HP-UX if you start gdb, and before running the
5095 inferior you try to set a breakpoint on a shared library function
5096 "foo" where the inferior doesn't call "foo" directly but does
5097 pass its address to another function call, then we do find a
5098 minimal symbol for the "foo", but it's address is invalid.
5099 (Appears to be an index into a table that the loader sets up
5100 when the inferior is run.)
5102 Give the target a chance to bless sals.sals[i].pc before we
5103 try to make a breakpoint for it. */
5104 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5105 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5107 if (address
== NULL
)
5108 error (_("Cannot break without a running program."));
5110 error (_("Cannot break on %s without a running program."),
5118 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5120 struct captured_parse_breakpoint_args
*args
= data
;
5122 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5123 args
->not_found_ptr
);
5126 /* Set a breakpoint according to ARG (function, linenum or *address)
5127 flag: first bit : 0 non-temporary, 1 temporary.
5128 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5130 PENDING_BP is non-NULL when this function is being called to resolve
5131 a pending breakpoint. */
5134 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5136 struct gdb_exception e
;
5137 int tempflag
, hardwareflag
;
5138 struct symtabs_and_lines sals
;
5139 struct expression
**cond
= 0;
5140 struct symtab_and_line pending_sal
;
5141 char **cond_string
= (char **) NULL
;
5144 char *addr_start
= arg
;
5146 struct cleanup
*old_chain
;
5147 struct cleanup
*breakpoint_chain
= NULL
;
5148 struct captured_parse_breakpoint_args parse_args
;
5152 int ignore_count
= 0;
5155 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5156 tempflag
= flag
& BP_TEMPFLAG
;
5162 parse_args
.arg_p
= &arg
;
5163 parse_args
.sals_p
= &sals
;
5164 parse_args
.addr_string_p
= &addr_string
;
5165 parse_args
.not_found_ptr
= ¬_found
;
5167 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5168 &parse_args
, RETURN_MASK_ALL
);
5170 /* If caller is interested in rc value from parse, set value. */
5174 exception_print (gdb_stderr
, e
);
5179 case NOT_FOUND_ERROR
:
5180 /* If called to resolve pending breakpoint, just return
5185 exception_print (gdb_stderr
, e
);
5187 /* If pending breakpoint support is turned off, throw
5190 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5191 deprecated_throw_reason (RETURN_ERROR
);
5193 /* If pending breakpoint support is auto query and the user
5194 selects no, then simply return the error code. */
5195 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5196 !nquery ("Make breakpoint pending on future shared library load? "))
5199 /* At this point, either the user was queried about setting
5200 a pending breakpoint and selected yes, or pending
5201 breakpoint behavior is on and thus a pending breakpoint
5202 is defaulted on behalf of the user. */
5203 copy_arg
= xstrdup (addr_start
);
5204 addr_string
= ©_arg
;
5206 sals
.sals
= &pending_sal
;
5211 exception_print (gdb_stderr
, e
);
5219 /* Create a chain of things that always need to be cleaned up. */
5220 old_chain
= make_cleanup (null_cleanup
, 0);
5224 /* Make sure that all storage allocated to SALS gets freed. */
5225 make_cleanup (xfree
, sals
.sals
);
5227 /* Cleanup the addr_string array but not its contents. */
5228 make_cleanup (xfree
, addr_string
);
5231 /* Allocate space for all the cond expressions. */
5232 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5233 make_cleanup (xfree
, cond
);
5235 /* Allocate space for all the cond strings. */
5236 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5237 make_cleanup (xfree
, cond_string
);
5239 /* ----------------------------- SNIP -----------------------------
5240 Anything added to the cleanup chain beyond this point is assumed
5241 to be part of a breakpoint. If the breakpoint create succeeds
5242 then the memory is not reclaimed. */
5243 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5245 /* Mark the contents of the addr_string for cleanup. These go on
5246 the breakpoint_chain and only occure if the breakpoint create
5248 for (i
= 0; i
< sals
.nelts
; i
++)
5250 if (addr_string
[i
] != NULL
)
5251 make_cleanup (xfree
, addr_string
[i
]);
5254 /* Resolve all line numbers to PC's and verify that the addresses
5255 are ok for the target. */
5257 breakpoint_sals_to_pc (&sals
, addr_start
);
5259 /* Verify that condition can be parsed, before setting any
5260 breakpoints. Allocate a separate condition expression for each
5262 thread
= -1; /* No specific thread yet */
5265 for (i
= 0; i
< sals
.nelts
; i
++)
5272 char *cond_start
= NULL
;
5273 char *cond_end
= NULL
;
5274 while (*tok
== ' ' || *tok
== '\t')
5279 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5282 toklen
= end_tok
- tok
;
5284 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5286 tok
= cond_start
= end_tok
+ 1;
5287 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
),
5289 make_cleanup (xfree
, cond
[i
]);
5291 cond_string
[i
] = savestring (cond_start
,
5292 cond_end
- cond_start
);
5293 make_cleanup (xfree
, cond_string
[i
]);
5295 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5301 thread
= strtol (tok
, &tok
, 0);
5303 error (_("Junk after thread keyword."));
5304 if (!valid_thread_id (thread
))
5305 error (_("Unknown thread %d."), thread
);
5308 error (_("Junk at end of arguments."));
5311 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5312 hardwareflag
? bp_hardware_breakpoint
5314 tempflag
? disp_del
: disp_donttouch
,
5315 thread
, ignore_count
, from_tty
,
5320 struct symtab_and_line sal
;
5321 struct breakpoint
*b
;
5326 make_cleanup (xfree
, copy_arg
);
5328 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5330 set_breakpoint_count (breakpoint_count
+ 1);
5331 b
->number
= breakpoint_count
;
5334 b
->addr_string
= *addr_string
;
5335 b
->cond_string
= *cond_string
;
5336 b
->ignore_count
= ignore_count
;
5338 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5339 b
->from_tty
= from_tty
;
5345 warning (_("Multiple breakpoints were set.\n"
5346 "Use the \"delete\" command to delete unwanted breakpoints."));
5347 /* That's it. Discard the cleanups for data inserted into the
5349 discard_cleanups (breakpoint_chain
);
5350 /* But cleanup everything else. */
5351 do_cleanups (old_chain
);
5356 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5357 linenum or *address) with COND and IGNORE_COUNT. */
5359 struct captured_breakpoint_args
5370 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5372 struct captured_breakpoint_args
*args
= data
;
5373 struct symtabs_and_lines sals
;
5374 struct expression
**cond
;
5375 struct cleanup
*old_chain
;
5376 struct cleanup
*breakpoint_chain
= NULL
;
5383 /* Parse the source and lines spec. Delay check that the expression
5384 didn't contain trailing garbage until after cleanups are in
5388 address_end
= args
->address
;
5390 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5395 /* Create a chain of things at always need to be cleaned up. */
5396 old_chain
= make_cleanup (null_cleanup
, 0);
5398 /* Always have a addr_string array, even if it is empty. */
5399 make_cleanup (xfree
, addr_string
);
5401 /* Make sure that all storage allocated to SALS gets freed. */
5402 make_cleanup (xfree
, sals
.sals
);
5404 /* Allocate space for all the cond expressions. */
5405 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5406 make_cleanup (xfree
, cond
);
5408 /* Allocate space for all the cond strings. */
5409 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5410 make_cleanup (xfree
, cond_string
);
5412 /* ----------------------------- SNIP -----------------------------
5413 Anything added to the cleanup chain beyond this point is assumed
5414 to be part of a breakpoint. If the breakpoint create goes
5415 through then that memory is not cleaned up. */
5416 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5418 /* Mark the contents of the addr_string for cleanup. These go on
5419 the breakpoint_chain and only occure if the breakpoint create
5421 for (i
= 0; i
< sals
.nelts
; i
++)
5423 if (addr_string
[i
] != NULL
)
5424 make_cleanup (xfree
, addr_string
[i
]);
5427 /* Wait until now before checking for garbage at the end of the
5428 address. That way cleanups can take care of freeing any
5430 if (*address_end
!= '\0')
5431 error (_("Garbage %s following breakpoint address"), address_end
);
5433 /* Resolve all line numbers to PC's. */
5434 breakpoint_sals_to_pc (&sals
, args
->address
);
5436 /* Verify that conditions can be parsed, before setting any
5438 for (i
= 0; i
< sals
.nelts
; i
++)
5440 if (args
->condition
!= NULL
)
5442 char *tok
= args
->condition
;
5443 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5445 error (_("Garbage %s follows condition"), tok
);
5446 make_cleanup (xfree
, cond
[i
]);
5447 cond_string
[i
] = xstrdup (args
->condition
);
5451 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5452 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5453 args
->tempflag
? disp_del
: disp_donttouch
,
5454 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5455 NULL
/*pending_bp*/);
5457 /* That's it. Discard the cleanups for data inserted into the
5459 discard_cleanups (breakpoint_chain
);
5460 /* But cleanup everything else. */
5461 do_cleanups (old_chain
);
5466 gdb_breakpoint (char *address
, char *condition
,
5467 int hardwareflag
, int tempflag
,
5468 int thread
, int ignore_count
,
5469 char **error_message
)
5471 struct captured_breakpoint_args args
;
5472 args
.address
= address
;
5473 args
.condition
= condition
;
5474 args
.hardwareflag
= hardwareflag
;
5475 args
.tempflag
= tempflag
;
5476 args
.thread
= thread
;
5477 args
.ignore_count
= ignore_count
;
5478 return catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5479 error_message
, RETURN_MASK_ALL
);
5483 /* Helper function for break_command_1 and disassemble_command. */
5486 resolve_sal_pc (struct symtab_and_line
*sal
)
5490 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5492 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5493 error (_("No line %d in file \"%s\"."),
5494 sal
->line
, sal
->symtab
->filename
);
5498 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5500 struct blockvector
*bv
;
5505 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5508 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5509 sym
= block_function (b
);
5512 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5513 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5517 /* It really is worthwhile to have the section, so we'll just
5518 have to look harder. This case can be executed if we have
5519 line numbers but no functions (as can happen in assembly
5522 struct minimal_symbol
*msym
;
5524 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5526 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5533 break_command (char *arg
, int from_tty
)
5535 break_command_1 (arg
, 0, from_tty
, NULL
);
5539 tbreak_command (char *arg
, int from_tty
)
5541 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5545 hbreak_command (char *arg
, int from_tty
)
5547 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5551 thbreak_command (char *arg
, int from_tty
)
5553 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5557 stop_command (char *arg
, int from_tty
)
5559 printf_filtered (_("Specify the type of breakpoint to set.\n\
5560 Usage: stop in <function | address>\n\
5561 stop at <line>\n"));
5565 stopin_command (char *arg
, int from_tty
)
5569 if (arg
== (char *) NULL
)
5571 else if (*arg
!= '*')
5576 /* look for a ':'. If this is a line number specification, then
5577 say it is bad, otherwise, it should be an address or
5578 function/method name */
5579 while (*argptr
&& !hasColon
)
5581 hasColon
= (*argptr
== ':');
5586 badInput
= (*argptr
!= ':'); /* Not a class::method */
5588 badInput
= isdigit (*arg
); /* a simple line number */
5592 printf_filtered (_("Usage: stop in <function | address>\n"));
5594 break_command_1 (arg
, 0, from_tty
, NULL
);
5598 stopat_command (char *arg
, int from_tty
)
5602 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5609 /* look for a ':'. If there is a '::' then get out, otherwise
5610 it is probably a line number. */
5611 while (*argptr
&& !hasColon
)
5613 hasColon
= (*argptr
== ':');
5618 badInput
= (*argptr
== ':'); /* we have class::method */
5620 badInput
= !isdigit (*arg
); /* not a line number */
5624 printf_filtered (_("Usage: stop at <line>\n"));
5626 break_command_1 (arg
, 0, from_tty
, NULL
);
5629 /* accessflag: hw_write: watch write,
5630 hw_read: watch read,
5631 hw_access: watch access (read or write) */
5633 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5635 struct breakpoint
*b
;
5636 struct symtab_and_line sal
;
5637 struct expression
*exp
;
5638 struct block
*exp_valid_block
;
5639 struct value
*val
, *mark
;
5640 struct frame_info
*frame
;
5641 struct frame_info
*prev_frame
= NULL
;
5642 char *exp_start
= NULL
;
5643 char *exp_end
= NULL
;
5644 char *tok
, *end_tok
;
5646 char *cond_start
= NULL
;
5647 char *cond_end
= NULL
;
5648 struct expression
*cond
= NULL
;
5649 int i
, other_type_used
, target_resources_ok
= 0;
5650 enum bptype bp_type
;
5653 init_sal (&sal
); /* initialize to zeroes */
5655 /* Parse arguments. */
5656 innermost_block
= NULL
;
5658 exp
= parse_exp_1 (&arg
, 0, 0);
5660 exp_valid_block
= innermost_block
;
5661 mark
= value_mark ();
5662 val
= evaluate_expression (exp
);
5663 release_value (val
);
5664 if (value_lazy (val
))
5665 value_fetch_lazy (val
);
5668 while (*tok
== ' ' || *tok
== '\t')
5672 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5675 toklen
= end_tok
- tok
;
5676 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5678 tok
= cond_start
= end_tok
+ 1;
5679 cond
= parse_exp_1 (&tok
, 0, 0);
5683 error (_("Junk at end of command."));
5685 if (accessflag
== hw_read
)
5686 bp_type
= bp_read_watchpoint
;
5687 else if (accessflag
== hw_access
)
5688 bp_type
= bp_access_watchpoint
;
5690 bp_type
= bp_hardware_watchpoint
;
5692 mem_cnt
= can_use_hardware_watchpoint (val
);
5693 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5694 error (_("Expression cannot be implemented with read/access watchpoint."));
5697 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5698 target_resources_ok
=
5699 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5701 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5702 error (_("Target does not support this type of hardware watchpoint."));
5704 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5705 error (_("Target can only support one kind of HW watchpoint at a time."));
5708 #if defined(HPUXHPPA)
5709 /* On HP-UX if you set a h/w
5710 watchpoint before the "run" command, the inferior dies with a e.g.,
5711 SIGILL once you start it. I initially believed this was due to a
5712 bad interaction between page protection traps and the initial
5713 startup sequence by the dynamic linker.
5715 However, I tried avoiding that by having HP-UX's implementation of
5716 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5717 yet, which forced slow watches before a "run" or "attach", and it
5718 still fails somewhere in the startup code.
5720 Until I figure out what's happening, I'm disallowing watches altogether
5721 before the "run" or "attach" command. We'll tell the user they must
5722 set watches after getting the program started. */
5723 if (!target_has_execution
)
5725 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5728 #endif /* HPUXHPPA */
5730 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5731 watchpoint could not be set. */
5732 if (!mem_cnt
|| target_resources_ok
<= 0)
5733 bp_type
= bp_watchpoint
;
5735 /* Now set up the breakpoint. */
5736 b
= set_raw_breakpoint (sal
, bp_type
);
5737 set_breakpoint_count (breakpoint_count
+ 1);
5738 b
->number
= breakpoint_count
;
5739 b
->disposition
= disp_donttouch
;
5741 b
->exp_valid_block
= exp_valid_block
;
5742 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5746 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5750 frame
= block_innermost_frame (exp_valid_block
);
5753 prev_frame
= get_prev_frame (frame
);
5754 b
->watchpoint_frame
= get_frame_id (frame
);
5758 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5761 /* If the expression is "local", then set up a "watchpoint scope"
5762 breakpoint at the point where we've left the scope of the watchpoint
5764 if (innermost_block
)
5768 struct breakpoint
*scope_breakpoint
;
5769 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5770 bp_watchpoint_scope
);
5772 scope_breakpoint
->enable_state
= bp_enabled
;
5774 /* Automatically delete the breakpoint when it hits. */
5775 scope_breakpoint
->disposition
= disp_del
;
5777 /* Only break in the proper frame (help with recursion). */
5778 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5780 /* Set the address at which we will stop. */
5781 scope_breakpoint
->loc
->requested_address
5782 = get_frame_pc (prev_frame
);
5783 scope_breakpoint
->loc
->address
5784 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5785 scope_breakpoint
->type
);
5787 /* The scope breakpoint is related to the watchpoint. We
5788 will need to act on them together. */
5789 b
->related_breakpoint
= scope_breakpoint
;
5792 value_free_to_mark (mark
);
5796 /* Return count of locations need to be watched and can be handled
5797 in hardware. If the watchpoint can not be handled
5798 in hardware return zero. */
5801 can_use_hardware_watchpoint (struct value
*v
)
5803 int found_memory_cnt
= 0;
5804 struct value
*head
= v
;
5806 /* Did the user specifically forbid us to use hardware watchpoints? */
5807 if (!can_use_hw_watchpoints
)
5810 /* Make sure that the value of the expression depends only upon
5811 memory contents, and values computed from them within GDB. If we
5812 find any register references or function calls, we can't use a
5813 hardware watchpoint.
5815 The idea here is that evaluating an expression generates a series
5816 of values, one holding the value of every subexpression. (The
5817 expression a*b+c has five subexpressions: a, b, a*b, c, and
5818 a*b+c.) GDB's values hold almost enough information to establish
5819 the criteria given above --- they identify memory lvalues,
5820 register lvalues, computed values, etcetera. So we can evaluate
5821 the expression, and then scan the chain of values that leaves
5822 behind to decide whether we can detect any possible change to the
5823 expression's final value using only hardware watchpoints.
5825 However, I don't think that the values returned by inferior
5826 function calls are special in any way. So this function may not
5827 notice that an expression involving an inferior function call
5828 can't be watched with hardware watchpoints. FIXME. */
5829 for (; v
; v
= value_next (v
))
5831 if (VALUE_LVAL (v
) == lval_memory
)
5834 /* A lazy memory lvalue is one that GDB never needed to fetch;
5835 we either just used its address (e.g., `a' in `a.b') or
5836 we never needed it at all (e.g., `a' in `a,b'). */
5840 /* Ahh, memory we actually used! Check if we can cover
5841 it with hardware watchpoints. */
5842 struct type
*vtype
= check_typedef (value_type (v
));
5844 /* We only watch structs and arrays if user asked for it
5845 explicitly, never if they just happen to appear in a
5846 middle of some value chain. */
5848 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5849 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5851 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5852 int len
= TYPE_LENGTH (value_type (v
));
5854 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5861 else if (VALUE_LVAL (v
) != not_lval
5862 && deprecated_value_modifiable (v
) == 0)
5863 return 0; /* ??? What does this represent? */
5864 else if (VALUE_LVAL (v
) == lval_register
)
5865 return 0; /* cannot watch a register with a HW watchpoint */
5868 /* The expression itself looks suitable for using a hardware
5869 watchpoint, but give the target machine a chance to reject it. */
5870 return found_memory_cnt
;
5874 watch_command_wrapper (char *arg
, int from_tty
)
5876 watch_command (arg
, from_tty
);
5880 watch_command (char *arg
, int from_tty
)
5882 watch_command_1 (arg
, hw_write
, from_tty
);
5886 rwatch_command_wrapper (char *arg
, int from_tty
)
5888 rwatch_command (arg
, from_tty
);
5892 rwatch_command (char *arg
, int from_tty
)
5894 watch_command_1 (arg
, hw_read
, from_tty
);
5898 awatch_command_wrapper (char *arg
, int from_tty
)
5900 awatch_command (arg
, from_tty
);
5904 awatch_command (char *arg
, int from_tty
)
5906 watch_command_1 (arg
, hw_access
, from_tty
);
5910 /* Helper routines for the until_command routine in infcmd.c. Here
5911 because it uses the mechanisms of breakpoints. */
5913 /* This function is called by fetch_inferior_event via the
5914 cmd_continuation pointer, to complete the until command. It takes
5915 care of cleaning up the temporary breakpoints set up by the until
5918 until_break_command_continuation (struct continuation_arg
*arg
)
5920 struct cleanup
*cleanups
;
5922 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5923 do_exec_cleanups (cleanups
);
5927 until_break_command (char *arg
, int from_tty
, int anywhere
)
5929 struct symtabs_and_lines sals
;
5930 struct symtab_and_line sal
;
5931 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5932 struct breakpoint
*breakpoint
;
5933 struct cleanup
*old_chain
;
5934 struct continuation_arg
*arg1
;
5937 clear_proceed_status ();
5939 /* Set a breakpoint where the user wants it and at return from
5942 if (default_breakpoint_valid
)
5943 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5944 default_breakpoint_line
, (char ***) NULL
, NULL
);
5946 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5947 0, (char ***) NULL
, NULL
);
5949 if (sals
.nelts
!= 1)
5950 error (_("Couldn't get information on specified line."));
5953 xfree (sals
.sals
); /* malloc'd, so freed */
5956 error (_("Junk at end of arguments."));
5958 resolve_sal_pc (&sal
);
5961 /* If the user told us to continue until a specified location,
5962 we don't specify a frame at which we need to stop. */
5963 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5965 /* Otherwise, specify the current frame, because we want to stop only
5966 at the very same frame. */
5967 breakpoint
= set_momentary_breakpoint (sal
,
5968 get_frame_id (deprecated_selected_frame
),
5971 if (!target_can_async_p ())
5972 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5974 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5976 /* If we are running asynchronously, and the target supports async
5977 execution, we are not waiting for the target to stop, in the call
5978 tp proceed, below. This means that we cannot delete the
5979 brekpoints until the target has actually stopped. The only place
5980 where we get a chance to do that is in fetch_inferior_event, so
5981 we must set things up for that. */
5983 if (target_can_async_p ())
5985 /* In this case the arg for the continuation is just the point
5986 in the exec_cleanups chain from where to start doing
5987 cleanups, because all the continuation does is the cleanups in
5988 the exec_cleanup_chain. */
5990 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5992 arg1
->data
.pointer
= old_chain
;
5994 add_continuation (until_break_command_continuation
, arg1
);
5997 /* Keep within the current frame, or in frames called by the current
6001 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6002 sal
.pc
= get_frame_pc (prev_frame
);
6003 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6005 if (!target_can_async_p ())
6006 make_cleanup_delete_breakpoint (breakpoint
);
6008 make_exec_cleanup_delete_breakpoint (breakpoint
);
6011 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6012 /* Do the cleanups now, anly if we are not running asynchronously,
6013 of if we are, but the target is still synchronous. */
6014 if (!target_can_async_p ())
6015 do_cleanups (old_chain
);
6019 ep_skip_leading_whitespace (char **s
)
6021 if ((s
== NULL
) || (*s
== NULL
))
6023 while (isspace (**s
))
6027 /* This function examines a string, and attempts to find a token
6028 that might be an event name in the leading characters. If a
6029 possible match is found, a pointer to the last character of
6030 the token is returned. Else, NULL is returned. */
6033 ep_find_event_name_end (char *arg
)
6036 char *event_name_end
= NULL
;
6038 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6042 /* We break out of the loop when we find a token delimiter.
6043 Basically, we're looking for alphanumerics and underscores;
6044 anything else delimites the token. */
6047 if (!isalnum (*s
) && (*s
!= '_'))
6053 return event_name_end
;
6057 /* This function attempts to parse an optional "if <cond>" clause
6058 from the arg string. If one is not found, it returns NULL.
6060 Else, it returns a pointer to the condition string. (It does not
6061 attempt to evaluate the string against a particular block.) And,
6062 it updates arg to point to the first character following the parsed
6063 if clause in the arg string. */
6066 ep_parse_optional_if_clause (char **arg
)
6070 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6073 /* Skip the "if" keyword. */
6076 /* Skip any extra leading whitespace, and record the start of the
6077 condition string. */
6078 ep_skip_leading_whitespace (arg
);
6081 /* Assume that the condition occupies the remainder of the arg string. */
6082 (*arg
) += strlen (cond_string
);
6087 /* This function attempts to parse an optional filename from the arg
6088 string. If one is not found, it returns NULL.
6090 Else, it returns a pointer to the parsed filename. (This function
6091 makes no attempt to verify that a file of that name exists, or is
6092 accessible.) And, it updates arg to point to the first character
6093 following the parsed filename in the arg string.
6095 Note that clients needing to preserve the returned filename for
6096 future access should copy it to their own buffers. */
6098 ep_parse_optional_filename (char **arg
)
6100 static char filename
[1024];
6105 if ((*arg_p
== '\0') || isspace (*arg_p
))
6123 /* Commands to deal with catching events, such as signals, exceptions,
6124 process start/exit, etc. */
6128 catch_fork
, catch_vfork
6133 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6136 char *cond_string
= NULL
;
6138 ep_skip_leading_whitespace (&arg
);
6140 /* The allowed syntax is:
6142 catch [v]fork if <cond>
6144 First, check if there's an if clause. */
6145 cond_string
= ep_parse_optional_if_clause (&arg
);
6147 if ((*arg
!= '\0') && !isspace (*arg
))
6148 error (_("Junk at end of arguments."));
6150 /* If this target supports it, create a fork or vfork catchpoint
6151 and enable reporting of such events. */
6155 create_fork_event_catchpoint (tempflag
, cond_string
);
6158 create_vfork_event_catchpoint (tempflag
, cond_string
);
6161 error (_("unsupported or unknown fork kind; cannot catch it"));
6167 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6169 char *cond_string
= NULL
;
6171 ep_skip_leading_whitespace (&arg
);
6173 /* The allowed syntax is:
6175 catch exec if <cond>
6177 First, check if there's an if clause. */
6178 cond_string
= ep_parse_optional_if_clause (&arg
);
6180 if ((*arg
!= '\0') && !isspace (*arg
))
6181 error (_("Junk at end of arguments."));
6183 /* If this target supports it, create an exec catchpoint
6184 and enable reporting of such events. */
6185 create_exec_event_catchpoint (tempflag
, cond_string
);
6189 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6191 char *dll_pathname
= NULL
;
6192 char *cond_string
= NULL
;
6194 ep_skip_leading_whitespace (&arg
);
6196 /* The allowed syntax is:
6198 catch load if <cond>
6199 catch load <filename>
6200 catch load <filename> if <cond>
6202 The user is not allowed to specify the <filename> after an
6205 We'll ignore the pathological case of a file named "if".
6207 First, check if there's an if clause. If so, then there
6208 cannot be a filename. */
6209 cond_string
= ep_parse_optional_if_clause (&arg
);
6211 /* If there was an if clause, then there cannot be a filename.
6212 Else, there might be a filename and an if clause. */
6213 if (cond_string
== NULL
)
6215 dll_pathname
= ep_parse_optional_filename (&arg
);
6216 ep_skip_leading_whitespace (&arg
);
6217 cond_string
= ep_parse_optional_if_clause (&arg
);
6220 if ((*arg
!= '\0') && !isspace (*arg
))
6221 error (_("Junk at end of arguments."));
6223 /* Create a load breakpoint that only triggers when a load of
6224 the specified dll (or any dll, if no pathname was specified)
6226 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6227 dll_pathname
, cond_string
);
6231 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6233 char *dll_pathname
= NULL
;
6234 char *cond_string
= NULL
;
6236 ep_skip_leading_whitespace (&arg
);
6238 /* The allowed syntax is:
6240 catch unload if <cond>
6241 catch unload <filename>
6242 catch unload <filename> if <cond>
6244 The user is not allowed to specify the <filename> after an
6247 We'll ignore the pathological case of a file named "if".
6249 First, check if there's an if clause. If so, then there
6250 cannot be a filename. */
6251 cond_string
= ep_parse_optional_if_clause (&arg
);
6253 /* If there was an if clause, then there cannot be a filename.
6254 Else, there might be a filename and an if clause. */
6255 if (cond_string
== NULL
)
6257 dll_pathname
= ep_parse_optional_filename (&arg
);
6258 ep_skip_leading_whitespace (&arg
);
6259 cond_string
= ep_parse_optional_if_clause (&arg
);
6262 if ((*arg
!= '\0') && !isspace (*arg
))
6263 error (_("Junk at end of arguments."));
6265 /* Create an unload breakpoint that only triggers when an unload of
6266 the specified dll (or any dll, if no pathname was specified)
6268 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6269 dll_pathname
, cond_string
);
6272 /* Commands to deal with catching exceptions. */
6274 /* Set a breakpoint at the specified callback routine for an
6275 exception event callback */
6278 create_exception_catchpoint (int tempflag
, char *cond_string
,
6279 enum exception_event_kind ex_event
,
6280 struct symtab_and_line
*sal
)
6282 struct breakpoint
*b
;
6283 int thread
= -1; /* All threads. */
6286 if (!sal
) /* no exception support? */
6291 case EX_EVENT_THROW
:
6292 bptype
= bp_catch_throw
;
6294 case EX_EVENT_CATCH
:
6295 bptype
= bp_catch_catch
;
6297 default: /* error condition */
6298 error (_("Internal error -- invalid catchpoint kind"));
6301 b
= set_raw_breakpoint (*sal
, bptype
);
6302 set_breakpoint_count (breakpoint_count
+ 1);
6303 b
->number
= breakpoint_count
;
6305 b
->cond_string
= (cond_string
== NULL
) ?
6306 NULL
: savestring (cond_string
, strlen (cond_string
));
6308 b
->addr_string
= NULL
;
6309 b
->enable_state
= bp_enabled
;
6310 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6314 static enum print_stop_action
6315 print_exception_catchpoint (struct breakpoint
*b
)
6317 annotate_catchpoint (b
->number
);
6319 if (strstr (b
->addr_string
, "throw") != NULL
)
6320 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6323 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6326 return PRINT_SRC_AND_LOC
;
6330 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6335 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6338 *last_addr
= b
->loc
->address
;
6339 if (strstr (b
->addr_string
, "throw") != NULL
)
6340 ui_out_field_string (uiout
, "what", "exception throw");
6342 ui_out_field_string (uiout
, "what", "exception catch");
6346 print_mention_exception_catchpoint (struct breakpoint
*b
)
6348 if (strstr (b
->addr_string
, "throw") != NULL
)
6349 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6351 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6354 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6355 print_exception_catchpoint
,
6356 print_one_exception_catchpoint
,
6357 print_mention_exception_catchpoint
6361 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6362 enum exception_event_kind ex_event
, int from_tty
)
6364 char *trigger_func_name
, *nameptr
;
6365 struct symtabs_and_lines sals
;
6366 struct breakpoint
*b
;
6368 if (ex_event
== EX_EVENT_CATCH
)
6369 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6371 trigger_func_name
= xstrdup ("__cxa_throw");
6373 nameptr
= trigger_func_name
;
6374 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6375 if (sals
.nelts
== 0)
6377 xfree (trigger_func_name
);
6381 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6382 set_breakpoint_count (breakpoint_count
+ 1);
6383 b
->number
= breakpoint_count
;
6385 b
->cond_string
= (cond_string
== NULL
) ?
6386 NULL
: savestring (cond_string
, strlen (cond_string
));
6388 b
->addr_string
= trigger_func_name
;
6389 b
->enable_state
= bp_enabled
;
6390 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6391 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6398 /* Deal with "catch catch" and "catch throw" commands */
6401 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6402 int tempflag
, int from_tty
)
6404 char *cond_string
= NULL
;
6405 struct symtab_and_line
*sal
= NULL
;
6407 ep_skip_leading_whitespace (&arg
);
6409 cond_string
= ep_parse_optional_if_clause (&arg
);
6411 if ((*arg
!= '\0') && !isspace (*arg
))
6412 error (_("Junk at end of arguments."));
6414 if ((ex_event
!= EX_EVENT_THROW
) &&
6415 (ex_event
!= EX_EVENT_CATCH
))
6416 error (_("Unsupported or unknown exception event; cannot catch it"));
6418 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6421 /* See if we can find a callback routine */
6422 sal
= target_enable_exception_callback (ex_event
, 1);
6426 /* We have callbacks from the runtime system for exceptions.
6427 Set a breakpoint on the sal found, if no errors */
6428 if (sal
!= (struct symtab_and_line
*) -1)
6429 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6431 return; /* something went wrong with setting up callbacks */
6434 warning (_("Unsupported with this platform/compiler combination."));
6437 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6438 inside a catch_errors */
6441 cover_target_enable_exception_callback (void *arg
)
6443 args_for_catchpoint_enable
*args
= arg
;
6444 struct symtab_and_line
*sal
;
6445 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6448 else if (sal
== (struct symtab_and_line
*) -1)
6451 return 1; /*is valid */
6455 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6458 /* The first argument may be an event name, such as "start" or "load".
6459 If so, then handle it as such. If it doesn't match an event name,
6460 then attempt to interpret it as an exception name. (This latter is
6461 the v4.16-and-earlier GDB meaning of the "catch" command.)
6463 First, try to find the bounds of what might be an event name. */
6464 char *arg1_start
= arg
;
6468 if (arg1_start
== NULL
)
6470 /* Old behaviour was to use pre-v-4.16 syntax */
6471 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6473 /* Now, this is not allowed */
6474 error (_("Catch requires an event name."));
6477 arg1_end
= ep_find_event_name_end (arg1_start
);
6478 if (arg1_end
== NULL
)
6479 error (_("catch requires an event"));
6480 arg1_length
= arg1_end
+ 1 - arg1_start
;
6482 /* Try to match what we found against known event names. */
6483 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6485 error (_("Catch of signal not yet implemented"));
6487 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6489 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6490 tempflag
, from_tty
);
6492 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6494 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6495 tempflag
, from_tty
);
6497 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6499 error (_("Catch of thread_start not yet implemented"));
6501 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6503 error (_("Catch of thread_exit not yet implemented"));
6505 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6507 error (_("Catch of thread_join not yet implemented"));
6509 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6511 error (_("Catch of start not yet implemented"));
6513 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6515 error (_("Catch of exit not yet implemented"));
6517 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6519 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6521 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6523 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6525 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6527 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6529 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6531 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6533 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6535 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6537 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6539 error (_("Catch of stop not yet implemented"));
6542 /* This doesn't appear to be an event name */
6546 /* Pre-v.4.16 behaviour was to treat the argument
6547 as the name of an exception */
6548 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6549 /* Now this is not allowed */
6550 error (_("Unknown event kind specified for catch"));
6555 /* Used by the gui, could be made a worker for other things. */
6558 set_breakpoint_sal (struct symtab_and_line sal
)
6560 struct breakpoint
*b
;
6561 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6562 set_breakpoint_count (breakpoint_count
+ 1);
6563 b
->number
= breakpoint_count
;
6570 catch_command (char *arg
, int from_tty
)
6572 catch_command_1 (arg
, 0, from_tty
);
6577 tcatch_command (char *arg
, int from_tty
)
6579 catch_command_1 (arg
, 1, from_tty
);
6582 /* Delete breakpoints by address or line. */
6585 clear_command (char *arg
, int from_tty
)
6587 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6589 struct symtabs_and_lines sals
;
6590 struct symtab_and_line sal
;
6595 sals
= decode_line_spec (arg
, 1);
6600 sals
.sals
= (struct symtab_and_line
*)
6601 xmalloc (sizeof (struct symtab_and_line
));
6602 make_cleanup (xfree
, sals
.sals
);
6603 init_sal (&sal
); /* initialize to zeroes */
6604 sal
.line
= default_breakpoint_line
;
6605 sal
.symtab
= default_breakpoint_symtab
;
6606 sal
.pc
= default_breakpoint_address
;
6607 if (sal
.symtab
== 0)
6608 error (_("No source file specified."));
6616 /* For each line spec given, delete bps which correspond
6617 to it. Do it in two passes, solely to preserve the current
6618 behavior that from_tty is forced true if we delete more than
6622 for (i
= 0; i
< sals
.nelts
; i
++)
6624 /* If exact pc given, clear bpts at that pc.
6625 If line given (pc == 0), clear all bpts on specified line.
6626 If defaulting, clear all bpts on default line
6629 defaulting sal.pc != 0 tests to do
6634 1 0 <can't happen> */
6639 /* Find all matching breakpoints, remove them from the
6640 breakpoint chain, and add them to the 'found' chain. */
6641 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6643 /* Are we going to delete b? */
6644 if (b
->type
!= bp_none
6645 && b
->type
!= bp_watchpoint
6646 && b
->type
!= bp_hardware_watchpoint
6647 && b
->type
!= bp_read_watchpoint
6648 && b
->type
!= bp_access_watchpoint
6649 /* Not if b is a watchpoint of any sort... */
6650 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6651 && (!section_is_overlay (b
->loc
->section
)
6652 || b
->loc
->section
== sal
.section
))
6653 /* Yes, if sal.pc matches b (modulo overlays). */
6654 || ((default_match
|| (0 == sal
.pc
))
6655 && b
->source_file
!= NULL
6656 && sal
.symtab
!= NULL
6657 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6658 && b
->line_number
== sal
.line
)))
6659 /* Yes, if sal source file and line matches b. */
6661 /* Remove it from breakpoint_chain... */
6662 if (b
== breakpoint_chain
)
6664 /* b is at the head of the list */
6665 breakpoint_chain
= b
->next
;
6669 prev
->next
= b
->next
;
6671 /* And add it to 'found' chain. */
6677 /* Keep b, and keep a pointer to it. */
6682 /* Now go thru the 'found' chain and delete them. */
6686 error (_("No breakpoint at %s."), arg
);
6688 error (_("No breakpoint at this line."));
6692 from_tty
= 1; /* Always report if deleted more than one */
6696 printf_unfiltered (_("Deleted breakpoint "));
6698 printf_unfiltered (_("Deleted breakpoints "));
6700 breakpoints_changed ();
6704 printf_unfiltered ("%d ", found
->number
);
6706 delete_breakpoint (found
);
6710 putchar_unfiltered ('\n');
6713 /* Delete breakpoint in BS if they are `delete' breakpoints and
6714 all breakpoints that are marked for deletion, whether hit or not.
6715 This is called after any breakpoint is hit, or after errors. */
6718 breakpoint_auto_delete (bpstat bs
)
6720 struct breakpoint
*b
, *temp
;
6722 for (; bs
; bs
= bs
->next
)
6723 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6725 delete_breakpoint (bs
->breakpoint_at
);
6727 ALL_BREAKPOINTS_SAFE (b
, temp
)
6729 if (b
->disposition
== disp_del_at_next_stop
)
6730 delete_breakpoint (b
);
6734 /* Delete a breakpoint and clean up all traces of it in the data
6738 delete_breakpoint (struct breakpoint
*bpt
)
6740 struct breakpoint
*b
;
6742 struct bp_location
*loc
;
6744 gdb_assert (bpt
!= NULL
);
6746 /* Has this bp already been deleted? This can happen because multiple
6747 lists can hold pointers to bp's. bpstat lists are especial culprits.
6749 One example of this happening is a watchpoint's scope bp. When the
6750 scope bp triggers, we notice that the watchpoint is out of scope, and
6751 delete it. We also delete its scope bp. But the scope bp is marked
6752 "auto-deleting", and is already on a bpstat. That bpstat is then
6753 checked for auto-deleting bp's, which are deleted.
6755 A real solution to this problem might involve reference counts in bp's,
6756 and/or giving them pointers back to their referencing bpstat's, and
6757 teaching delete_breakpoint to only free a bp's storage when no more
6758 references were extent. A cheaper bandaid was chosen. */
6759 if (bpt
->type
== bp_none
)
6762 if (deprecated_delete_breakpoint_hook
)
6763 deprecated_delete_breakpoint_hook (bpt
);
6764 breakpoint_delete_event (bpt
->number
);
6766 if (bpt
->loc
->inserted
)
6767 remove_breakpoint (bpt
->loc
, mark_inserted
);
6769 free_valchain (bpt
->loc
);
6771 if (breakpoint_chain
== bpt
)
6772 breakpoint_chain
= bpt
->next
;
6774 if (bp_location_chain
== bpt
->loc
)
6775 bp_location_chain
= bpt
->loc
->next
;
6777 /* If we have callback-style exception catchpoints, don't go through
6778 the adjustments to the C++ runtime library etc. if the inferior
6779 isn't actually running. target_enable_exception_callback for a
6780 null target ops vector gives an undesirable error message, so we
6781 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6782 exceptions are supported in this way, it's OK for now. FIXME */
6783 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6785 /* Format possible error msg */
6786 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6788 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6789 args_for_catchpoint_enable args
;
6790 args
.kind
= bpt
->type
== bp_catch_catch
?
6791 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6793 catch_errors (cover_target_enable_exception_callback
, &args
,
6794 message
, RETURN_MASK_ALL
);
6795 do_cleanups (cleanups
);
6802 b
->next
= bpt
->next
;
6806 ALL_BP_LOCATIONS (loc
)
6807 if (loc
->next
== bpt
->loc
)
6809 loc
->next
= bpt
->loc
->next
;
6813 check_duplicates (bpt
);
6814 /* If this breakpoint was inserted, and there is another breakpoint
6815 at the same address, we need to insert the other breakpoint. */
6816 if (bpt
->loc
->inserted
6817 && bpt
->type
!= bp_hardware_watchpoint
6818 && bpt
->type
!= bp_read_watchpoint
6819 && bpt
->type
!= bp_access_watchpoint
6820 && bpt
->type
!= bp_catch_fork
6821 && bpt
->type
!= bp_catch_vfork
6822 && bpt
->type
!= bp_catch_exec
)
6825 if (b
->loc
->address
== bpt
->loc
->address
6826 && b
->loc
->section
== bpt
->loc
->section
6827 && !b
->loc
->duplicate
6828 && b
->enable_state
!= bp_disabled
6829 && b
->enable_state
!= bp_shlib_disabled
6831 && b
->enable_state
!= bp_call_disabled
)
6835 /* We should never reach this point if there is a permanent
6836 breakpoint at the same address as the one being deleted.
6837 If there is a permanent breakpoint somewhere, it should
6838 always be the only one inserted. */
6839 if (b
->enable_state
== bp_permanent
)
6840 internal_error (__FILE__
, __LINE__
,
6841 _("another breakpoint was inserted on top of "
6842 "a permanent breakpoint"));
6844 memset (&b
->loc
->target_info
, 0, sizeof (b
->loc
->target_info
));
6845 b
->loc
->target_info
.placed_address
= b
->loc
->address
;
6846 if (b
->type
== bp_hardware_breakpoint
)
6847 val
= target_insert_hw_breakpoint (&b
->loc
->target_info
);
6849 val
= target_insert_breakpoint (&b
->loc
->target_info
);
6851 /* If there was an error in the insert, print a message, then stop execution. */
6854 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6855 make_cleanup_ui_file_delete (tmp_error_stream
);
6858 if (b
->type
== bp_hardware_breakpoint
)
6860 fprintf_unfiltered (tmp_error_stream
,
6861 "Cannot insert hardware breakpoint %d.\n"
6862 "You may have requested too many hardware breakpoints.\n",
6867 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6868 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6869 deprecated_print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
6870 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6871 safe_strerror (val
));
6874 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6875 target_terminal_ours_for_output ();
6876 error_stream(tmp_error_stream
);
6879 b
->loc
->inserted
= 1;
6883 free_command_lines (&bpt
->commands
);
6886 if (bpt
->cond_string
!= NULL
)
6887 xfree (bpt
->cond_string
);
6888 if (bpt
->addr_string
!= NULL
)
6889 xfree (bpt
->addr_string
);
6890 if (bpt
->exp
!= NULL
)
6892 if (bpt
->exp_string
!= NULL
)
6893 xfree (bpt
->exp_string
);
6894 if (bpt
->val
!= NULL
)
6895 value_free (bpt
->val
);
6896 if (bpt
->source_file
!= NULL
)
6897 xfree (bpt
->source_file
);
6898 if (bpt
->dll_pathname
!= NULL
)
6899 xfree (bpt
->dll_pathname
);
6900 if (bpt
->triggered_dll_pathname
!= NULL
)
6901 xfree (bpt
->triggered_dll_pathname
);
6902 if (bpt
->exec_pathname
!= NULL
)
6903 xfree (bpt
->exec_pathname
);
6905 /* Be sure no bpstat's are pointing at it after it's been freed. */
6906 /* FIXME, how can we find all bpstat's?
6907 We just check stop_bpstat for now. */
6908 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6909 if (bs
->breakpoint_at
== bpt
)
6911 bs
->breakpoint_at
= NULL
;
6913 /* bs->commands will be freed later. */
6915 /* On the chance that someone will soon try again to delete this same
6916 bp, we mark it as deleted before freeing its storage. */
6917 bpt
->type
= bp_none
;
6924 do_delete_breakpoint_cleanup (void *b
)
6926 delete_breakpoint (b
);
6930 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6932 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6936 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6938 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6942 delete_command (char *arg
, int from_tty
)
6944 struct breakpoint
*b
, *temp
;
6950 int breaks_to_delete
= 0;
6952 /* Delete all breakpoints if no argument.
6953 Do not delete internal or call-dummy breakpoints, these
6954 have to be deleted with an explicit breakpoint number argument. */
6957 if (b
->type
!= bp_call_dummy
&&
6958 b
->type
!= bp_shlib_event
&&
6959 b
->type
!= bp_thread_event
&&
6960 b
->type
!= bp_overlay_event
&&
6962 breaks_to_delete
= 1;
6965 /* Ask user only if there are some breakpoints to delete. */
6967 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
6969 ALL_BREAKPOINTS_SAFE (b
, temp
)
6971 if (b
->type
!= bp_call_dummy
&&
6972 b
->type
!= bp_shlib_event
&&
6973 b
->type
!= bp_thread_event
&&
6974 b
->type
!= bp_overlay_event
&&
6976 delete_breakpoint (b
);
6981 map_breakpoint_numbers (arg
, delete_breakpoint
);
6984 /* Reset a breakpoint given it's struct breakpoint * BINT.
6985 The value we return ends up being the return value from catch_errors.
6986 Unused in this case. */
6989 breakpoint_re_set_one (void *bint
)
6991 /* get past catch_errs */
6992 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6996 int *not_found_ptr
= NULL
;
6997 struct symtabs_and_lines sals
;
6999 enum enable_state save_enable
;
7004 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7008 case bp_hardware_breakpoint
:
7010 case bp_catch_unload
:
7011 if (b
->addr_string
== NULL
)
7013 /* Anything without a string can't be re-set. */
7014 delete_breakpoint (b
);
7017 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7019 ``And a hack it is, although Apple's Darwin version of GDB
7020 contains an almost identical hack to implement a "future
7021 break" command. It seems to work in many real world cases,
7022 but it is easy to come up with a test case where the patch
7023 doesn't help at all.''
7025 ``It seems that the way GDB implements breakpoints - in -
7026 shared - libraries was designed for a.out shared library
7027 systems (SunOS 4) where shared libraries were loaded at a
7028 fixed address in memory. Since ELF shared libraries can (and
7029 will) be loaded at any address in memory, things break.
7030 Fixing this is not trivial. Therefore, I'm not sure whether
7031 we should add this hack to the branch only. I cannot
7032 guarantee that things will be fixed on the trunk in the near
7035 In case we have a problem, disable this breakpoint. We'll
7036 restore its status if we succeed. Don't disable a
7037 shlib_disabled breakpoint though. There's a fair chance we
7038 can't re-set it if the shared library it's in hasn't been
7044 save_enable
= b
->enable_state
;
7045 if (b
->enable_state
!= bp_shlib_disabled
)
7046 b
->enable_state
= bp_disabled
;
7048 /* If resetting a shlib-disabled breakpoint, we don't want to
7049 see an error message if it is not found since we will expect
7050 this to occur until the shared library is finally reloaded.
7051 We accomplish this by giving decode_line_1 a pointer to use
7052 for silent notification that the symbol is not found. */
7053 not_found_ptr
= ¬_found
;
7055 set_language (b
->language
);
7056 input_radix
= b
->input_radix
;
7058 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7060 for (i
= 0; i
< sals
.nelts
; i
++)
7062 resolve_sal_pc (&sals
.sals
[i
]);
7064 /* Reparse conditions, they might contain references to the
7066 if (b
->cond_string
!= NULL
)
7072 /* Avoid re-freeing b->exp if an error during the call
7076 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7079 /* We need to re-set the breakpoint if the address changes... */
7080 if (b
->loc
->address
!= sals
.sals
[i
].pc
7081 /* ...or new and old breakpoints both have source files, and
7082 the source file name or the line number changes... */
7083 || (b
->source_file
!= NULL
7084 && sals
.sals
[i
].symtab
!= NULL
7085 && (strcmp (b
->source_file
, sals
.sals
[i
].symtab
->filename
) != 0
7086 || b
->line_number
!= sals
.sals
[i
].line
)
7088 /* ...or we switch between having a source file and not having
7090 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7093 if (b
->source_file
!= NULL
)
7094 xfree (b
->source_file
);
7095 if (sals
.sals
[i
].symtab
== NULL
)
7096 b
->source_file
= NULL
;
7099 savestring (sals
.sals
[i
].symtab
->filename
,
7100 strlen (sals
.sals
[i
].symtab
->filename
));
7101 b
->line_number
= sals
.sals
[i
].line
;
7102 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
7104 = adjust_breakpoint_address (b
->loc
->requested_address
,
7107 /* Used to check for duplicates here, but that can
7108 cause trouble, as it doesn't check for disabled
7113 /* Might be better to do this just once per breakpoint_re_set,
7114 rather than once for every breakpoint. */
7115 breakpoints_changed ();
7117 b
->loc
->section
= sals
.sals
[i
].section
;
7118 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7121 /* Now that this is re-enabled, check_duplicates
7123 check_duplicates (b
);
7130 case bp_hardware_watchpoint
:
7131 case bp_read_watchpoint
:
7132 case bp_access_watchpoint
:
7133 innermost_block
= NULL
;
7134 /* The issue arises of what context to evaluate this in. The
7135 same one as when it was set, but what does that mean when
7136 symbols have been re-read? We could save the filename and
7137 functionname, but if the context is more local than that, the
7138 best we could do would be something like how many levels deep
7139 and which index at that particular level, but that's going to
7140 be less stable than filenames or function names. */
7142 /* So for now, just use a global context. */
7146 /* Avoid re-freeing b->exp if an error during the call to
7147 parse_expression. */
7150 b
->exp
= parse_expression (b
->exp_string
);
7151 b
->exp_valid_block
= innermost_block
;
7152 mark
= value_mark ();
7155 value_free (b
->val
);
7156 /* Avoid re-freeing b->val if an error during the call to
7157 evaluate_expression. */
7160 b
->val
= evaluate_expression (b
->exp
);
7161 release_value (b
->val
);
7162 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7163 value_fetch_lazy (b
->val
);
7165 if (b
->cond_string
!= NULL
)
7171 /* Avoid re-freeing b->exp if an error during the call
7175 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7177 if (breakpoint_enabled (b
))
7179 value_free_to_mark (mark
);
7181 case bp_catch_catch
:
7182 case bp_catch_throw
:
7184 /* We needn't really do anything to reset these, since the mask
7185 that requests them is unaffected by e.g., new libraries being
7188 case bp_catch_vfork
:
7193 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7195 /* Delete longjmp and overlay event breakpoints; they will be
7196 reset later by breakpoint_re_set. */
7198 case bp_longjmp_resume
:
7199 case bp_overlay_event
:
7200 delete_breakpoint (b
);
7203 /* This breakpoint is special, it's set up when the inferior
7204 starts and we really don't want to touch it. */
7205 case bp_shlib_event
:
7207 /* Like bp_shlib_event, this breakpoint type is special.
7208 Once it is set up, we do not want to touch it. */
7209 case bp_thread_event
:
7211 /* Keep temporary breakpoints, which can be encountered when we step
7212 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7213 Otherwise these should have been blown away via the cleanup chain
7214 or by breakpoint_init_inferior when we rerun the executable. */
7217 case bp_watchpoint_scope
:
7219 case bp_step_resume
:
7226 /* Re-set all breakpoints after symbols have been re-loaded. */
7228 breakpoint_re_set (void)
7230 struct breakpoint
*b
, *temp
;
7231 enum language save_language
;
7232 int save_input_radix
;
7234 save_language
= current_language
->la_language
;
7235 save_input_radix
= input_radix
;
7236 ALL_BREAKPOINTS_SAFE (b
, temp
)
7238 /* Format possible error msg */
7239 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7241 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7242 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7243 do_cleanups (cleanups
);
7245 set_language (save_language
);
7246 input_radix
= save_input_radix
;
7248 if (GET_LONGJMP_TARGET_P ())
7250 create_longjmp_breakpoint ("longjmp");
7251 create_longjmp_breakpoint ("_longjmp");
7252 create_longjmp_breakpoint ("siglongjmp");
7253 create_longjmp_breakpoint ("_siglongjmp");
7254 create_longjmp_breakpoint (NULL
);
7257 create_overlay_event_breakpoint ("_ovly_debug_event");
7260 /* Reset the thread number of this breakpoint:
7262 - If the breakpoint is for all threads, leave it as-is.
7263 - Else, reset it to the current thread for inferior_ptid. */
7265 breakpoint_re_set_thread (struct breakpoint
*b
)
7267 if (b
->thread
!= -1)
7269 if (in_thread_list (inferior_ptid
))
7270 b
->thread
= pid_to_thread_id (inferior_ptid
);
7274 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7275 If from_tty is nonzero, it prints a message to that effect,
7276 which ends with a period (no newline). */
7279 set_ignore_count (int bptnum
, int count
, int from_tty
)
7281 struct breakpoint
*b
;
7287 if (b
->number
== bptnum
)
7289 b
->ignore_count
= count
;
7293 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7295 else if (count
== 1)
7296 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7299 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7302 breakpoints_changed ();
7303 breakpoint_modify_event (b
->number
);
7307 error (_("No breakpoint number %d."), bptnum
);
7310 /* Clear the ignore counts of all breakpoints. */
7312 breakpoint_clear_ignore_counts (void)
7314 struct breakpoint
*b
;
7317 b
->ignore_count
= 0;
7320 /* Command to set ignore-count of breakpoint N to COUNT. */
7323 ignore_command (char *args
, int from_tty
)
7329 error_no_arg (_("a breakpoint number"));
7331 num
= get_number (&p
);
7333 error (_("bad breakpoint number: '%s'"), args
);
7335 error (_("Second argument (specified ignore-count) is missing."));
7337 set_ignore_count (num
,
7338 longest_to_int (value_as_long (parse_and_eval (p
))),
7341 printf_filtered ("\n");
7344 /* Call FUNCTION on each of the breakpoints
7345 whose numbers are given in ARGS. */
7348 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7353 struct breakpoint
*b
, *tmp
;
7357 error_no_arg (_("one or more breakpoint numbers"));
7364 num
= get_number_or_range (&p1
);
7367 warning (_("bad breakpoint number at or near '%s'"), p
);
7371 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7372 if (b
->number
== num
)
7374 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7377 if (related_breakpoint
)
7378 function (related_breakpoint
);
7382 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7388 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7389 If from_tty is nonzero, it prints a message to that effect,
7390 which ends with a period (no newline). */
7393 disable_breakpoint (struct breakpoint
*bpt
)
7395 /* Never disable a watchpoint scope breakpoint; we want to
7396 hit them when we leave scope so we can delete both the
7397 watchpoint and its scope breakpoint at that time. */
7398 if (bpt
->type
== bp_watchpoint_scope
)
7401 /* You can't disable permanent breakpoints. */
7402 if (bpt
->enable_state
== bp_permanent
)
7405 bpt
->enable_state
= bp_disabled
;
7407 check_duplicates (bpt
);
7409 if (deprecated_modify_breakpoint_hook
)
7410 deprecated_modify_breakpoint_hook (bpt
);
7411 breakpoint_modify_event (bpt
->number
);
7415 disable_command (char *args
, int from_tty
)
7417 struct breakpoint
*bpt
;
7419 ALL_BREAKPOINTS (bpt
)
7423 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7428 case bp_catch_unload
:
7430 case bp_catch_vfork
:
7432 case bp_catch_catch
:
7433 case bp_catch_throw
:
7434 case bp_hardware_breakpoint
:
7436 case bp_hardware_watchpoint
:
7437 case bp_read_watchpoint
:
7438 case bp_access_watchpoint
:
7439 disable_breakpoint (bpt
);
7444 map_breakpoint_numbers (args
, disable_breakpoint
);
7448 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7450 int target_resources_ok
, other_type_used
;
7453 if (bpt
->type
== bp_hardware_breakpoint
)
7456 i
= hw_breakpoint_used_count ();
7457 target_resources_ok
=
7458 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7460 if (target_resources_ok
== 0)
7461 error (_("No hardware breakpoint support in the target."));
7462 else if (target_resources_ok
< 0)
7463 error (_("Hardware breakpoints used exceeds limit."));
7468 if (bpt
->enable_state
!= bp_enabled
)
7470 /* When enabling a pending breakpoint, we need to check if the breakpoint
7471 is resolvable since shared libraries could have been loaded
7472 after the breakpoint was disabled. */
7473 breakpoints_changed ();
7474 if (resolve_pending_breakpoint (bpt
) == GDB_RC_OK
)
7476 delete_breakpoint (bpt
);
7479 bpt
->enable_state
= bp_enabled
;
7480 bpt
->disposition
= disposition
;
7483 else /* Not a pending breakpoint. */
7485 if (bpt
->enable_state
!= bp_permanent
)
7486 bpt
->enable_state
= bp_enabled
;
7487 bpt
->disposition
= disposition
;
7488 check_duplicates (bpt
);
7489 breakpoints_changed ();
7491 if (bpt
->type
== bp_watchpoint
||
7492 bpt
->type
== bp_hardware_watchpoint
||
7493 bpt
->type
== bp_read_watchpoint
||
7494 bpt
->type
== bp_access_watchpoint
)
7496 struct frame_id saved_frame_id
;
7498 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7499 if (bpt
->exp_valid_block
!= NULL
)
7501 struct frame_info
*fr
=
7502 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7505 printf_filtered (_("\
7506 Cannot enable watchpoint %d because the block in which its expression\n\
7507 is valid is not currently in scope.\n"), bpt
->number
);
7508 bpt
->enable_state
= bp_disabled
;
7514 value_free (bpt
->val
);
7515 mark
= value_mark ();
7516 bpt
->val
= evaluate_expression (bpt
->exp
);
7517 release_value (bpt
->val
);
7518 if (value_lazy (bpt
->val
))
7519 value_fetch_lazy (bpt
->val
);
7521 if (bpt
->type
== bp_hardware_watchpoint
||
7522 bpt
->type
== bp_read_watchpoint
||
7523 bpt
->type
== bp_access_watchpoint
)
7525 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7526 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7528 /* Hack around 'unused var' error for some targets here */
7530 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7531 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7532 /* we can consider of type is bp_hardware_watchpoint, convert to
7533 bp_watchpoint in the following condition */
7534 if (target_resources_ok
< 0)
7536 printf_filtered (_("\
7537 Cannot enable watchpoint %d because target watch resources\n\
7538 have been allocated for other watchpoints.\n"), bpt
->number
);
7539 bpt
->enable_state
= bp_disabled
;
7540 value_free_to_mark (mark
);
7545 select_frame (frame_find_by_id (saved_frame_id
));
7546 value_free_to_mark (mark
);
7550 if (deprecated_modify_breakpoint_hook
)
7551 deprecated_modify_breakpoint_hook (bpt
);
7552 breakpoint_modify_event (bpt
->number
);
7556 enable_breakpoint (struct breakpoint
*bpt
)
7558 do_enable_breakpoint (bpt
, bpt
->disposition
);
7561 /* The enable command enables the specified breakpoints (or all defined
7562 breakpoints) so they once again become (or continue to be) effective
7563 in stopping the inferior. */
7566 enable_command (char *args
, int from_tty
)
7568 struct breakpoint
*bpt
;
7570 ALL_BREAKPOINTS (bpt
)
7574 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7579 case bp_catch_unload
:
7581 case bp_catch_vfork
:
7583 case bp_catch_catch
:
7584 case bp_catch_throw
:
7585 case bp_hardware_breakpoint
:
7587 case bp_hardware_watchpoint
:
7588 case bp_read_watchpoint
:
7589 case bp_access_watchpoint
:
7590 enable_breakpoint (bpt
);
7595 map_breakpoint_numbers (args
, enable_breakpoint
);
7599 enable_once_breakpoint (struct breakpoint
*bpt
)
7601 do_enable_breakpoint (bpt
, disp_disable
);
7605 enable_once_command (char *args
, int from_tty
)
7607 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7611 enable_delete_breakpoint (struct breakpoint
*bpt
)
7613 do_enable_breakpoint (bpt
, disp_del
);
7617 enable_delete_command (char *args
, int from_tty
)
7619 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7623 set_breakpoint_cmd (char *args
, int from_tty
)
7628 show_breakpoint_cmd (char *args
, int from_tty
)
7632 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7634 struct symtabs_and_lines
7635 decode_line_spec_1 (char *string
, int funfirstline
)
7637 struct symtabs_and_lines sals
;
7639 error (_("Empty line specification."));
7640 if (default_breakpoint_valid
)
7641 sals
= decode_line_1 (&string
, funfirstline
,
7642 default_breakpoint_symtab
,
7643 default_breakpoint_line
,
7644 (char ***) NULL
, NULL
);
7646 sals
= decode_line_1 (&string
, funfirstline
,
7647 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7649 error (_("Junk at end of line specification: %s"), string
);
7653 /* Create and insert a raw software breakpoint at PC. Return an
7654 identifier, which should be used to remove the breakpoint later.
7655 In general, places which call this should be using something on the
7656 breakpoint chain instead; this function should be eliminated
7660 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7662 struct bp_target_info
*bp_tgt
;
7664 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7665 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7667 bp_tgt
->placed_address
= pc
;
7668 if (target_insert_breakpoint (bp_tgt
) != 0)
7670 /* Could not insert the breakpoint. */
7678 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7681 deprecated_remove_raw_breakpoint (void *bp
)
7683 struct bp_target_info
*bp_tgt
= bp
;
7686 ret
= target_remove_breakpoint (bp_tgt
);
7692 /* One (or perhaps two) breakpoints used for software single stepping. */
7694 static void *single_step_breakpoints
[2];
7696 /* Create and insert a breakpoint for software single step. */
7699 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7703 if (single_step_breakpoints
[0] == NULL
)
7704 bpt_p
= &single_step_breakpoints
[0];
7707 gdb_assert (single_step_breakpoints
[1] == NULL
);
7708 bpt_p
= &single_step_breakpoints
[1];
7711 /* NOTE drow/2006-04-11: A future improvement to this function would be
7712 to only create the breakpoints once, and actually put them on the
7713 breakpoint chain. That would let us use set_raw_breakpoint. We could
7714 adjust the addresses each time they were needed. Doing this requires
7715 corresponding changes elsewhere where single step breakpoints are
7716 handled, however. So, for now, we use this. */
7718 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7720 error (_("Could not insert single-step breakpoint at 0x%s"),
7721 paddr_nz (next_pc
));
7724 /* Remove and delete any breakpoints used for software single step. */
7727 remove_single_step_breakpoints (void)
7729 gdb_assert (single_step_breakpoints
[0] != NULL
);
7731 /* See insert_single_step_breakpoint for more about this deprecated
7733 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7734 single_step_breakpoints
[0] = NULL
;
7736 if (single_step_breakpoints
[1] != NULL
)
7738 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7739 single_step_breakpoints
[1] = NULL
;
7744 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7745 It is defined as a macro to prevent duplication.
7746 COMMAND should be a string constant containing the name of the command. */
7747 #define BREAK_ARGS_HELP(command) \
7748 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7749 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7750 If a line number is specified, break at start of code for that line.\n\
7751 If a function is specified, break at start of code for that function.\n\
7752 If an address is specified, break at that exact address.\n\
7753 With no LOCATION, uses current execution address of selected stack frame.\n\
7754 This is useful for breaking on return to a stack frame.\n\
7756 THREADNUM is the number from \"info threads\".\n\
7757 CONDITION is a boolean expression.\n\
7759 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7761 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7764 _initialize_breakpoint (void)
7766 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7767 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7768 struct cmd_list_element
*c
;
7770 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7772 breakpoint_chain
= 0;
7773 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7774 before a breakpoint is set. */
7775 breakpoint_count
= 0;
7777 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7778 Set ignore-count of breakpoint number N to COUNT.\n\
7779 Usage is `ignore N COUNT'."));
7781 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7783 add_com ("commands", class_breakpoint
, commands_command
, _("\
7784 Set commands to be executed when a breakpoint is hit.\n\
7785 Give breakpoint number as argument after \"commands\".\n\
7786 With no argument, the targeted breakpoint is the last one set.\n\
7787 The commands themselves follow starting on the next line.\n\
7788 Type a line containing \"end\" to indicate the end of them.\n\
7789 Give \"silent\" as the first line to make the breakpoint silent;\n\
7790 then no output is printed when it is hit, except what the commands print."));
7792 add_com ("condition", class_breakpoint
, condition_command
, _("\
7793 Specify breakpoint number N to break only if COND is true.\n\
7794 Usage is `condition N COND', where N is an integer and COND is an\n\
7795 expression to be evaluated whenever breakpoint N is reached."));
7797 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
7798 Set a temporary breakpoint.\n\
7799 Like \"break\" except the breakpoint is only temporary,\n\
7800 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7801 by using \"enable delete\" on the breakpoint number.\n\
7803 BREAK_ARGS_HELP ("tbreak")));
7804 set_cmd_completer (c
, location_completer
);
7806 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
7807 Set a hardware assisted breakpoint.\n\
7808 Like \"break\" except the breakpoint requires hardware support,\n\
7809 some target hardware may not have this support.\n\
7811 BREAK_ARGS_HELP ("hbreak")));
7812 set_cmd_completer (c
, location_completer
);
7814 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
7815 Set a temporary hardware assisted breakpoint.\n\
7816 Like \"hbreak\" except the breakpoint is only temporary,\n\
7817 so it will be deleted when hit.\n\
7819 BREAK_ARGS_HELP ("thbreak")));
7820 set_cmd_completer (c
, location_completer
);
7822 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
7823 Enable some breakpoints.\n\
7824 Give breakpoint numbers (separated by spaces) as arguments.\n\
7825 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7826 This is used to cancel the effect of the \"disable\" command.\n\
7827 With a subcommand you can enable temporarily."),
7828 &enablelist
, "enable ", 1, &cmdlist
);
7830 add_com ("ab", class_breakpoint
, enable_command
, _("\
7831 Enable some breakpoints.\n\
7832 Give breakpoint numbers (separated by spaces) as arguments.\n\
7833 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7834 This is used to cancel the effect of the \"disable\" command.\n\
7835 With a subcommand you can enable temporarily."));
7837 add_com_alias ("en", "enable", class_breakpoint
, 1);
7839 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
7840 Enable some breakpoints.\n\
7841 Give breakpoint numbers (separated by spaces) as arguments.\n\
7842 This is used to cancel the effect of the \"disable\" command.\n\
7843 May be abbreviated to simply \"enable\".\n"),
7844 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7846 add_cmd ("once", no_class
, enable_once_command
, _("\
7847 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7848 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7851 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7852 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7853 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7856 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7857 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7858 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7861 add_cmd ("once", no_class
, enable_once_command
, _("\
7862 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7863 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7866 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
7867 Disable some breakpoints.\n\
7868 Arguments are breakpoint numbers with spaces in between.\n\
7869 To disable all breakpoints, give no argument.\n\
7870 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
7871 &disablelist
, "disable ", 1, &cmdlist
);
7872 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7873 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7875 add_com ("sb", class_breakpoint
, disable_command
, _("\
7876 Disable some breakpoints.\n\
7877 Arguments are breakpoint numbers with spaces in between.\n\
7878 To disable all breakpoints, give no argument.\n\
7879 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
7881 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
7882 Disable some breakpoints.\n\
7883 Arguments are breakpoint numbers with spaces in between.\n\
7884 To disable all breakpoints, give no argument.\n\
7885 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7886 This command may be abbreviated \"disable\"."),
7889 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
7890 Delete some breakpoints or auto-display expressions.\n\
7891 Arguments are breakpoint numbers with spaces in between.\n\
7892 To delete all breakpoints, give no argument.\n\
7894 Also a prefix command for deletion of other GDB objects.\n\
7895 The \"unset\" command is also an alias for \"delete\"."),
7896 &deletelist
, "delete ", 1, &cmdlist
);
7897 add_com_alias ("d", "delete", class_breakpoint
, 1);
7898 add_com_alias ("del", "delete", class_breakpoint
, 1);
7900 add_com ("db", class_breakpoint
, delete_command
, _("\
7901 Delete some breakpoints.\n\
7902 Arguments are breakpoint numbers with spaces in between.\n\
7903 To delete all breakpoints, give no argument.\n"));
7905 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
7906 Delete some breakpoints or auto-display expressions.\n\
7907 Arguments are breakpoint numbers with spaces in between.\n\
7908 To delete all breakpoints, give no argument.\n\
7909 This command may be abbreviated \"delete\"."),
7912 add_com ("clear", class_breakpoint
, clear_command
, _("\
7913 Clear breakpoint at specified line or function.\n\
7914 Argument may be line number, function name, or \"*\" and an address.\n\
7915 If line number is specified, all breakpoints in that line are cleared.\n\
7916 If function is specified, breakpoints at beginning of function are cleared.\n\
7917 If an address is specified, breakpoints at that address are cleared.\n\
7919 With no argument, clears all breakpoints in the line that the selected frame\n\
7922 See also the \"delete\" command which clears breakpoints by number."));
7924 c
= add_com ("break", class_breakpoint
, break_command
, _("\
7925 Set breakpoint at specified line or function.\n"
7926 BREAK_ARGS_HELP ("break")));
7927 set_cmd_completer (c
, location_completer
);
7929 add_com_alias ("b", "break", class_run
, 1);
7930 add_com_alias ("br", "break", class_run
, 1);
7931 add_com_alias ("bre", "break", class_run
, 1);
7932 add_com_alias ("brea", "break", class_run
, 1);
7936 add_com_alias ("ba", "break", class_breakpoint
, 1);
7937 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7942 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
7943 Break in function/address or break at a line in the current file."),
7944 &stoplist
, "stop ", 1, &cmdlist
);
7945 add_cmd ("in", class_breakpoint
, stopin_command
,
7946 _("Break in function or address."), &stoplist
);
7947 add_cmd ("at", class_breakpoint
, stopat_command
,
7948 _("Break at a line in the current file."), &stoplist
);
7949 add_com ("status", class_info
, breakpoints_info
, _("\
7950 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7951 The \"Type\" column indicates one of:\n\
7952 \tbreakpoint - normal breakpoint\n\
7953 \twatchpoint - watchpoint\n\
7954 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7955 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7956 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7957 address and file/line number respectively.\n\
7959 Convenience variable \"$_\" and default examine address for \"x\"\n\
7960 are set to the address of the last breakpoint listed.\n\n\
7961 Convenience variable \"$bpnum\" contains the number of the last\n\
7965 add_info ("breakpoints", breakpoints_info
, _("\
7966 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7967 The \"Type\" column indicates one of:\n\
7968 \tbreakpoint - normal breakpoint\n\
7969 \twatchpoint - watchpoint\n\
7970 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7971 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7972 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7973 address and file/line number respectively.\n\
7975 Convenience variable \"$_\" and default examine address for \"x\"\n\
7976 are set to the address of the last breakpoint listed.\n\n\
7977 Convenience variable \"$bpnum\" contains the number of the last\n\
7981 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
7982 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7983 The \"Type\" column indicates one of:\n\
7984 \tbreakpoint - normal breakpoint\n\
7985 \twatchpoint - watchpoint\n\
7986 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7987 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7988 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7989 address and file/line number respectively.\n\
7991 Convenience variable \"$_\" and default examine address for \"x\"\n\
7992 are set to the address of the last breakpoint listed.\n\n\
7993 Convenience variable \"$bpnum\" contains the number of the last\n\
7996 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
7997 Status of all breakpoints, or breakpoint number NUMBER.\n\
7998 The \"Type\" column indicates one of:\n\
7999 \tbreakpoint - normal breakpoint\n\
8000 \twatchpoint - watchpoint\n\
8001 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8002 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8003 \tuntil - internal breakpoint used by the \"until\" command\n\
8004 \tfinish - internal breakpoint used by the \"finish\" command\n\
8005 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8006 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8007 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8008 address and file/line number respectively.\n\
8010 Convenience variable \"$_\" and default examine address for \"x\"\n\
8011 are set to the address of the last breakpoint listed.\n\
8013 Convenience variable \"$bpnum\" contains the number of the last\n\
8015 &maintenanceinfolist
);
8017 add_com ("catch", class_breakpoint
, catch_command
, _("\
8018 Set catchpoints to catch events.\n\
8019 Raised signals may be caught:\n\
8020 \tcatch signal - all signals\n\
8021 \tcatch signal <signame> - a particular signal\n\
8022 Raised exceptions may be caught:\n\
8023 \tcatch throw - all exceptions, when thrown\n\
8024 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8025 \tcatch catch - all exceptions, when caught\n\
8026 \tcatch catch <exceptname> - a particular exception, when caught\n\
8027 Thread or process events may be caught:\n\
8028 \tcatch thread_start - any threads, just after creation\n\
8029 \tcatch thread_exit - any threads, just before expiration\n\
8030 \tcatch thread_join - any threads, just after joins\n\
8031 Process events may be caught:\n\
8032 \tcatch start - any processes, just after creation\n\
8033 \tcatch exit - any processes, just before expiration\n\
8034 \tcatch fork - calls to fork()\n\
8035 \tcatch vfork - calls to vfork()\n\
8036 \tcatch exec - calls to exec()\n\
8037 Dynamically-linked library events may be caught:\n\
8038 \tcatch load - loads of any library\n\
8039 \tcatch load <libname> - loads of a particular library\n\
8040 \tcatch unload - unloads of any library\n\
8041 \tcatch unload <libname> - unloads of a particular library\n\
8042 The act of your program's execution stopping may also be caught:\n\
8044 C++ exceptions may be caught:\n\
8045 \tcatch throw - all exceptions, when thrown\n\
8046 \tcatch catch - all exceptions, when caught\n\
8048 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8049 after a fork or vfork is caught.\n\n\
8050 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8052 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8053 Set temporary catchpoints to catch events.\n\
8054 Args like \"catch\" command.\n\
8055 Like \"catch\" except the catchpoint is only temporary,\n\
8056 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8057 by using \"enable delete\" on the catchpoint number."));
8059 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8060 Set a watchpoint for an expression.\n\
8061 A watchpoint stops execution of your program whenever the value of\n\
8062 an expression changes."));
8063 set_cmd_completer (c
, location_completer
);
8065 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8066 Set a read watchpoint for an expression.\n\
8067 A watchpoint stops execution of your program whenever the value of\n\
8068 an expression is read."));
8069 set_cmd_completer (c
, location_completer
);
8071 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8072 Set a watchpoint for an expression.\n\
8073 A watchpoint stops execution of your program whenever the value of\n\
8074 an expression is either read or written."));
8075 set_cmd_completer (c
, location_completer
);
8077 add_info ("watchpoints", breakpoints_info
,
8078 _("Synonym for ``info breakpoints''."));
8081 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8082 respond to changes - contrary to the description. */
8083 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8084 &can_use_hw_watchpoints
, _("\
8085 Set debugger's willingness to use watchpoint hardware."), _("\
8086 Show debugger's willingness to use watchpoint hardware."), _("\
8087 If zero, gdb will not use hardware for new watchpoints, even if\n\
8088 such is available. (However, any hardware watchpoints that were\n\
8089 created before setting this to nonzero, will continue to use watchpoint\n\
8092 show_can_use_hw_watchpoints
,
8093 &setlist
, &showlist
);
8095 can_use_hw_watchpoints
= 1;
8097 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8098 Breakpoint specific settings\n\
8099 Configure various breakpoint-specific variables such as\n\
8100 pending breakpoint behavior"),
8101 &breakpoint_set_cmdlist
, "set breakpoint ",
8102 0/*allow-unknown*/, &setlist
);
8103 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8104 Breakpoint specific settings\n\
8105 Configure various breakpoint-specific variables such as\n\
8106 pending breakpoint behavior"),
8107 &breakpoint_show_cmdlist
, "show breakpoint ",
8108 0/*allow-unknown*/, &showlist
);
8110 add_setshow_auto_boolean_cmd ("pending", no_class
,
8111 &pending_break_support
, _("\
8112 Set debugger's behavior regarding pending breakpoints."), _("\
8113 Show debugger's behavior regarding pending breakpoints."), _("\
8114 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8115 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8116 an error. If auto, an unrecognized breakpoint location results in a\n\
8117 user-query to see if a pending breakpoint should be created."),
8119 show_pending_break_support
,
8120 &breakpoint_set_cmdlist
,
8121 &breakpoint_show_cmdlist
);
8123 pending_break_support
= AUTO_BOOLEAN_AUTO
;