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 read_memory_nobpt (CORE_ADDR memaddr
, gdb_byte
*myaddr
, unsigned len
)
645 struct bp_location
*b
;
646 CORE_ADDR bp_addr
= 0;
649 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
650 /* No breakpoints on this machine. */
651 return target_read_memory (memaddr
, myaddr
, len
);
655 if (b
->owner
->type
== bp_none
)
656 warning (_("reading through apparently deleted breakpoint #%d?"),
659 if (b
->loc_type
!= bp_loc_software_breakpoint
)
663 /* Addresses and length of the part of the breakpoint that
665 bp_addr
= b
->target_info
.placed_address
;
666 bp_size
= b
->target_info
.shadow_len
;
668 /* bp isn't valid, or doesn't shadow memory. */
670 if (bp_addr
+ bp_size
<= memaddr
)
671 /* The breakpoint is entirely before the chunk of memory we
674 if (bp_addr
>= memaddr
+ len
)
675 /* The breakpoint is entirely after the chunk of memory we are
678 /* Copy the breakpoint from the shadow contents, and recurse for
679 the things before and after. */
681 /* Offset within shadow_contents. */
684 if (bp_addr
< memaddr
)
686 /* Only copy the second part of the breakpoint. */
687 bp_size
-= memaddr
- bp_addr
;
688 bptoffset
= memaddr
- bp_addr
;
692 if (bp_addr
+ bp_size
> memaddr
+ len
)
694 /* Only copy the first part of the breakpoint. */
695 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
698 memcpy (myaddr
+ bp_addr
- memaddr
,
699 b
->target_info
.shadow_contents
+ bptoffset
, bp_size
);
701 if (bp_addr
> memaddr
)
703 /* Copy the section of memory before the breakpoint. */
704 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
709 if (bp_addr
+ bp_size
< memaddr
+ len
)
711 /* Copy the section of memory after the breakpoint. */
712 status
= read_memory_nobpt (bp_addr
+ bp_size
,
713 myaddr
+ bp_addr
+ bp_size
- memaddr
,
714 memaddr
+ len
- (bp_addr
+ bp_size
));
721 /* Nothing overlaps. Just call read_memory_noerr. */
722 return target_read_memory (memaddr
, myaddr
, len
);
726 /* A wrapper function for inserting catchpoints. */
728 insert_catchpoint (struct ui_out
*uo
, void *args
)
730 struct breakpoint
*b
= (struct breakpoint
*) args
;
736 target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
739 target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
742 target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
745 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
750 /* Helper routine: free the value chain for a breakpoint (watchpoint). */
752 static void free_valchain (struct bp_location
*b
)
757 /* Free the saved value chain. We will construct a new one
758 the next time the watchpoint is inserted. */
759 for (v
= b
->owner
->val_chain
; v
; v
= n
)
764 b
->owner
->val_chain
= NULL
;
767 /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint.
768 Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS,
769 PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems.
771 NOTE drow/2003-09-09: This routine could be broken down to an object-style
772 method for each breakpoint or catchpoint type. */
774 insert_bp_location (struct bp_location
*bpt
,
775 struct ui_file
*tmp_error_stream
,
776 int *disabled_breaks
, int *process_warning
,
777 int *hw_breakpoint_error
)
781 /* Permanent breakpoints cannot be inserted or removed. Disabled
782 breakpoints should not be inserted. */
783 if (!breakpoint_enabled (bpt
->owner
))
786 if (bpt
->inserted
|| bpt
->duplicate
)
789 /* Initialize the target-specific information. */
790 memset (&bpt
->target_info
, 0, sizeof (bpt
->target_info
));
791 bpt
->target_info
.placed_address
= bpt
->address
;
793 if (bpt
->loc_type
== bp_loc_software_breakpoint
794 || bpt
->loc_type
== bp_loc_hardware_breakpoint
)
796 /* First check to see if we have to handle an overlay. */
797 if (overlay_debugging
== ovly_off
798 || bpt
->section
== NULL
799 || !(section_is_overlay (bpt
->section
)))
801 /* No overlay handling: just set the breakpoint. */
803 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
804 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
806 val
= target_insert_breakpoint (&bpt
->target_info
);
810 /* This breakpoint is in an overlay section.
811 Shall we set a breakpoint at the LMA? */
812 if (!overlay_events_enabled
)
814 /* Yes -- overlay event support is not active,
815 so we must try to set a breakpoint at the LMA.
816 This will not work for a hardware breakpoint. */
817 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
818 warning (_("hardware breakpoint %d not supported in overlay!"),
822 CORE_ADDR addr
= overlay_unmapped_address (bpt
->address
,
824 /* Set a software (trap) breakpoint at the LMA. */
825 bpt
->overlay_target_info
= bpt
->target_info
;
826 bpt
->overlay_target_info
.placed_address
= addr
;
827 val
= target_insert_breakpoint (&bpt
->overlay_target_info
);
829 fprintf_unfiltered (tmp_error_stream
,
830 "Overlay breakpoint %d failed: in ROM?",
834 /* Shall we set a breakpoint at the VMA? */
835 if (section_is_mapped (bpt
->section
))
837 /* Yes. This overlay section is mapped into memory. */
838 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
839 val
= target_insert_hw_breakpoint (&bpt
->target_info
);
841 val
= target_insert_breakpoint (&bpt
->target_info
);
845 /* No. This breakpoint will not be inserted.
846 No error, but do not mark the bp as 'inserted'. */
853 /* Can't set the breakpoint. */
855 #if defined (DISABLE_UNSETTABLE_BREAK)
856 DISABLE_UNSETTABLE_BREAK (bpt
->address
)
858 solib_address (bpt
->address
)
862 /* See also: disable_breakpoints_in_shlibs. */
864 bpt
->owner
->enable_state
= bp_shlib_disabled
;
865 if (!*disabled_breaks
)
867 fprintf_unfiltered (tmp_error_stream
,
868 "Cannot insert breakpoint %d.\n",
870 fprintf_unfiltered (tmp_error_stream
,
871 "Temporarily disabling shared library breakpoints:\n");
873 *disabled_breaks
= 1;
874 fprintf_unfiltered (tmp_error_stream
,
875 "breakpoint #%d\n", bpt
->owner
->number
);
879 #ifdef ONE_PROCESS_WRITETEXT
880 *process_warning
= 1;
882 if (bpt
->loc_type
== bp_loc_hardware_breakpoint
)
884 *hw_breakpoint_error
= 1;
885 fprintf_unfiltered (tmp_error_stream
,
886 "Cannot insert hardware breakpoint %d.\n",
891 fprintf_unfiltered (tmp_error_stream
,
892 "Cannot insert breakpoint %d.\n",
894 fprintf_filtered (tmp_error_stream
,
895 "Error accessing memory address ");
896 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
897 fprintf_filtered (tmp_error_stream
, ": %s.\n",
898 safe_strerror (val
));
909 else if (bpt
->loc_type
== bp_loc_hardware_watchpoint
910 /* NOTE drow/2003-09-08: This state only exists for removing
911 watchpoints. It's not clear that it's necessary... */
912 && bpt
->owner
->disposition
!= disp_del_at_next_stop
)
914 /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints
915 based on the expression. Ideally this should happen at a higher level,
916 and there should be one bp_location for each computed address we
917 must watch. As soon as a many-to-one mapping is available I'll
920 int within_current_scope
;
921 struct value
*mark
= value_mark ();
923 struct frame_id saved_frame_id
;
925 /* Save the current frame's ID so we can restore it after
926 evaluating the watchpoint expression on its own frame. */
927 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression
928 took a frame parameter, so that we didn't have to change the
930 saved_frame_id
= get_frame_id (deprecated_selected_frame
);
932 /* Determine if the watchpoint is within scope. */
933 if (bpt
->owner
->exp_valid_block
== NULL
)
934 within_current_scope
= 1;
937 struct frame_info
*fi
;
938 fi
= frame_find_by_id (bpt
->owner
->watchpoint_frame
);
939 within_current_scope
= (fi
!= NULL
);
940 if (within_current_scope
)
944 if (within_current_scope
)
948 /* Evaluate the expression and cut the chain of values
949 produced off from the value chain.
951 Make sure the value returned isn't lazy; we use
952 laziness to determine what memory GDB actually needed
953 in order to compute the value of the expression. */
954 v
= evaluate_expression (bpt
->owner
->exp
);
956 value_release_to_mark (mark
);
958 bpt
->owner
->val_chain
= v
;
961 /* Look at each value on the value chain. */
962 for (; v
; v
= value_next (v
))
964 /* If it's a memory location, and GDB actually needed
965 its contents to evaluate the expression, then we
967 if (VALUE_LVAL (v
) == lval_memory
970 struct type
*vtype
= check_typedef (value_type (v
));
972 /* We only watch structs and arrays if user asked
973 for it explicitly, never if they just happen to
974 appear in the middle of some value chain. */
975 if (v
== bpt
->owner
->val_chain
976 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
977 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
982 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
983 len
= TYPE_LENGTH (value_type (v
));
985 if (bpt
->owner
->type
== bp_read_watchpoint
)
987 else if (bpt
->owner
->type
== bp_access_watchpoint
)
990 val
= target_insert_watchpoint (addr
, len
, type
);
993 /* Don't exit the loop, try to insert
994 every value on the value chain. That's
995 because we will be removing all the
996 watches below, and removing a
997 watchpoint we didn't insert could have
1005 /* Failure to insert a watchpoint on any memory value in the
1006 value chain brings us here. */
1009 remove_breakpoint (bpt
, mark_uninserted
);
1010 *hw_breakpoint_error
= 1;
1011 fprintf_unfiltered (tmp_error_stream
,
1012 "Could not insert hardware watchpoint %d.\n",
1013 bpt
->owner
->number
);
1019 printf_filtered (_("\
1020 Hardware watchpoint %d deleted because the program has left the block \n\
1021 in which its expression is valid.\n"),
1022 bpt
->owner
->number
);
1023 if (bpt
->owner
->related_breakpoint
)
1024 bpt
->owner
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1025 bpt
->owner
->disposition
= disp_del_at_next_stop
;
1028 /* Restore the selected frame. */
1029 select_frame (frame_find_by_id (saved_frame_id
));
1034 else if (ep_is_exception_catchpoint (bpt
->owner
))
1036 /* FIXME drow/2003-09-09: This code sets both a catchpoint and a
1037 breakpoint. Once again, it would be better if this was represented
1038 as two bp_locations. */
1040 /* If we get here, we must have a callback mechanism for exception
1041 events -- with g++ style embedded label support, we insert
1042 ordinary breakpoints and not catchpoints. */
1043 val
= target_insert_breakpoint (&bpt
->target_info
);
1046 /* Couldn't set breakpoint for some reason */
1047 fprintf_unfiltered (tmp_error_stream
,
1048 "Cannot insert catchpoint %d; disabling it.\n",
1049 bpt
->owner
->number
);
1050 fprintf_filtered (tmp_error_stream
,
1051 "Error accessing memory address ");
1052 deprecated_print_address_numeric (bpt
->address
, 1, tmp_error_stream
);
1053 fprintf_filtered (tmp_error_stream
, ": %s.\n",
1054 safe_strerror (val
));
1055 bpt
->owner
->enable_state
= bp_disabled
;
1059 /* Bp set, now make sure callbacks are enabled */
1060 /* Format possible error msg */
1061 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
1062 bpt
->owner
->number
);
1063 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
1065 args_for_catchpoint_enable args
;
1066 args
.kind
= bpt
->owner
->type
== bp_catch_catch
?
1067 EX_EVENT_CATCH
: EX_EVENT_THROW
;
1069 val
= catch_errors (cover_target_enable_exception_callback
,
1070 &args
, message
, RETURN_MASK_ALL
);
1071 do_cleanups (cleanups
);
1072 if (val
!= 0 && val
!= -1)
1075 /* Check if something went wrong; val == 0 can be ignored */
1078 /* something went wrong */
1079 fprintf_unfiltered (tmp_error_stream
,
1080 "Cannot insert catchpoint %d; disabling it.\n",
1081 bpt
->owner
->number
);
1082 bpt
->owner
->enable_state
= bp_disabled
;
1089 else if (bpt
->owner
->type
== bp_catch_fork
1090 || bpt
->owner
->type
== bp_catch_vfork
1091 || bpt
->owner
->type
== bp_catch_exec
)
1093 struct gdb_exception e
= catch_exception (uiout
, insert_catchpoint
,
1094 bpt
->owner
, RETURN_MASK_ERROR
);
1095 exception_fprintf (gdb_stderr
, e
, "warning: inserting catchpoint %d: ",
1096 bpt
->owner
->number
);
1098 bpt
->owner
->enable_state
= bp_disabled
;
1102 /* We've already printed an error message if there was a problem
1103 inserting this catchpoint, and we've disabled the catchpoint,
1104 so just return success. */
1111 /* insert_breakpoints is used when starting or continuing the program.
1112 remove_breakpoints is used when the program stops.
1113 Both return zero if successful,
1114 or an `errno' value if could not write the inferior. */
1117 insert_breakpoints (void)
1119 struct bp_location
*b
, *temp
;
1120 int return_val
= 0; /* return success code. */
1122 int disabled_breaks
= 0;
1123 int hw_breakpoint_error
= 0;
1124 int process_warning
= 0;
1126 struct ui_file
*tmp_error_stream
= mem_fileopen ();
1127 make_cleanup_ui_file_delete (tmp_error_stream
);
1129 /* Explicitly mark the warning -- this will only be printed if
1130 there was an error. */
1131 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
1133 ALL_BP_LOCATIONS_SAFE (b
, temp
)
1135 /* Permanent breakpoints cannot be inserted or removed. Disabled
1136 breakpoints should not be inserted. */
1137 if (!breakpoint_enabled (b
->owner
))
1140 /* There is no point inserting thread-specific breakpoints if the
1141 thread no longer exists. */
1142 if (b
->owner
->thread
!= -1
1143 && !valid_thread_id (b
->owner
->thread
))
1146 /* FIXME drow/2003-10-07: This code should be pushed elsewhere when
1147 hardware watchpoints are split into multiple loc breakpoints. */
1148 if ((b
->loc_type
== bp_loc_hardware_watchpoint
1149 || b
->owner
->type
== bp_watchpoint
) && !b
->owner
->val
)
1152 val
= evaluate_expression (b
->owner
->exp
);
1153 release_value (val
);
1154 if (value_lazy (val
))
1155 value_fetch_lazy (val
);
1156 b
->owner
->val
= val
;
1159 val
= insert_bp_location (b
, tmp_error_stream
,
1160 &disabled_breaks
, &process_warning
,
1161 &hw_breakpoint_error
);
1168 /* If a hardware breakpoint or watchpoint was inserted, add a
1169 message about possibly exhausted resources. */
1170 if (hw_breakpoint_error
)
1172 fprintf_unfiltered (tmp_error_stream
,
1173 "Could not insert hardware breakpoints:\n\
1174 You may have requested too many hardware breakpoints/watchpoints.\n");
1176 #ifdef ONE_PROCESS_WRITETEXT
1177 if (process_warning
)
1178 fprintf_unfiltered (tmp_error_stream
,
1179 "The same program may be running in another process.");
1181 target_terminal_ours_for_output ();
1182 error_stream (tmp_error_stream
);
1188 remove_breakpoints (void)
1190 struct bp_location
*b
;
1193 ALL_BP_LOCATIONS (b
)
1197 val
= remove_breakpoint (b
, mark_uninserted
);
1206 remove_hw_watchpoints (void)
1208 struct bp_location
*b
;
1211 ALL_BP_LOCATIONS (b
)
1213 if (b
->inserted
&& b
->loc_type
== bp_loc_hardware_watchpoint
)
1215 val
= remove_breakpoint (b
, mark_uninserted
);
1224 reattach_breakpoints (int pid
)
1226 struct bp_location
*b
;
1228 struct cleanup
*old_chain
= save_inferior_ptid ();
1230 /* Set inferior_ptid; remove_breakpoint uses this global. */
1231 inferior_ptid
= pid_to_ptid (pid
);
1232 ALL_BP_LOCATIONS (b
)
1236 remove_breakpoint (b
, mark_inserted
);
1237 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1238 val
= target_insert_hw_breakpoint (&b
->target_info
);
1240 val
= target_insert_breakpoint (&b
->target_info
);
1241 /* FIXME drow/2003-10-07: This doesn't handle any other kinds of
1242 breakpoints. It's wrong for watchpoints, for example. */
1245 do_cleanups (old_chain
);
1250 do_cleanups (old_chain
);
1255 update_breakpoints_after_exec (void)
1257 struct breakpoint
*b
;
1258 struct breakpoint
*temp
;
1260 /* Doing this first prevents the badness of having delete_breakpoint()
1261 write a breakpoint's current "shadow contents" to lift the bp. That
1262 shadow is NOT valid after an exec()! */
1263 mark_breakpoints_out ();
1265 ALL_BREAKPOINTS_SAFE (b
, temp
)
1267 /* Solib breakpoints must be explicitly reset after an exec(). */
1268 if (b
->type
== bp_shlib_event
)
1270 delete_breakpoint (b
);
1274 /* Thread event breakpoints must be set anew after an exec(),
1275 as must overlay event breakpoints. */
1276 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1278 delete_breakpoint (b
);
1282 /* Step-resume breakpoints are meaningless after an exec(). */
1283 if (b
->type
== bp_step_resume
)
1285 delete_breakpoint (b
);
1289 /* Ditto the sigtramp handler breakpoints. */
1290 if (b
->type
== bp_through_sigtramp
)
1292 delete_breakpoint (b
);
1296 /* Ditto the exception-handling catchpoints. */
1297 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1299 delete_breakpoint (b
);
1303 /* Don't delete an exec catchpoint, because else the inferior
1304 won't stop when it ought!
1306 Similarly, we probably ought to keep vfork catchpoints, 'cause
1307 on this target, we may not be able to stop when the vfork is
1308 seen, but only when the subsequent exec is seen. (And because
1309 deleting fork catchpoints here but not vfork catchpoints will
1310 seem mysterious to users, keep those too.)
1312 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1313 target address field, if any, is sufficient to have it be reset
1314 automagically. Certainly on HP-UX that's true.
1316 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1317 valid code address on some platforms (like the mn10300
1318 simulators). We shouldn't assign any special interpretation to
1319 a breakpoint with a zero address. And in fact, GDB doesn't ---
1320 I can't see what that comment above is talking about. As far
1321 as I can tell, setting the address of a
1322 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1323 is meaningless, since those are implemented with HP-UX kernel
1324 hackery, not by storing breakpoint instructions somewhere. */
1325 if ((b
->type
== bp_catch_exec
) ||
1326 (b
->type
== bp_catch_vfork
) ||
1327 (b
->type
== bp_catch_fork
))
1329 b
->loc
->address
= (CORE_ADDR
) 0;
1333 /* bp_finish is a special case. The only way we ought to be able
1334 to see one of these when an exec() has happened, is if the user
1335 caught a vfork, and then said "finish". Ordinarily a finish just
1336 carries them to the call-site of the current callee, by setting
1337 a temporary bp there and resuming. But in this case, the finish
1338 will carry them entirely through the vfork & exec.
1340 We don't want to allow a bp_finish to remain inserted now. But
1341 we can't safely delete it, 'cause finish_command has a handle to
1342 the bp on a bpstat, and will later want to delete it. There's a
1343 chance (and I've seen it happen) that if we delete the bp_finish
1344 here, that its storage will get reused by the time finish_command
1345 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1346 We really must allow finish_command to delete a bp_finish.
1348 In the absense of a general solution for the "how do we know
1349 it's safe to delete something others may have handles to?"
1350 problem, what we'll do here is just uninsert the bp_finish, and
1351 let finish_command delete it.
1353 (We know the bp_finish is "doomed" in the sense that it's
1354 momentary, and will be deleted as soon as finish_command sees
1355 the inferior stopped. So it doesn't matter that the bp's
1356 address is probably bogus in the new a.out, unlike e.g., the
1357 solib breakpoints.) */
1359 if (b
->type
== bp_finish
)
1364 /* Without a symbolic address, we have little hope of the
1365 pre-exec() address meaning the same thing in the post-exec()
1367 if (b
->addr_string
== NULL
)
1369 delete_breakpoint (b
);
1373 /* If this breakpoint has survived the above battery of checks, then
1374 it must have a symbolic address. Be sure that it gets reevaluated
1375 to a target address, rather than reusing the old evaluation.
1377 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1378 for bp_catch_exec and friends, I'm pretty sure this is entirely
1379 unnecessary. A call to breakpoint_re_set_one always recomputes
1380 the breakpoint's address from scratch, or deletes it if it can't.
1381 So I think this assignment could be deleted without effect. */
1382 b
->loc
->address
= (CORE_ADDR
) 0;
1384 /* FIXME what about longjmp breakpoints? Re-create them here? */
1385 create_overlay_event_breakpoint ("_ovly_debug_event");
1389 detach_breakpoints (int pid
)
1391 struct bp_location
*b
;
1393 struct cleanup
*old_chain
= save_inferior_ptid ();
1395 if (pid
== PIDGET (inferior_ptid
))
1396 error (_("Cannot detach breakpoints of inferior_ptid"));
1398 /* Set inferior_ptid; remove_breakpoint uses this global. */
1399 inferior_ptid
= pid_to_ptid (pid
);
1400 ALL_BP_LOCATIONS (b
)
1404 val
= remove_breakpoint (b
, mark_inserted
);
1407 do_cleanups (old_chain
);
1412 do_cleanups (old_chain
);
1417 remove_breakpoint (struct bp_location
*b
, insertion_state_t is
)
1421 if (b
->owner
->enable_state
== bp_permanent
)
1422 /* Permanent breakpoints cannot be inserted or removed. */
1425 if (b
->owner
->type
== bp_none
)
1426 warning (_("attempted to remove apparently deleted breakpoint #%d?"),
1429 if (b
->loc_type
== bp_loc_software_breakpoint
1430 || b
->loc_type
== bp_loc_hardware_breakpoint
)
1432 /* "Normal" instruction breakpoint: either the standard
1433 trap-instruction bp (bp_breakpoint), or a
1434 bp_hardware_breakpoint. */
1436 /* First check to see if we have to handle an overlay. */
1437 if (overlay_debugging
== ovly_off
1438 || b
->section
== NULL
1439 || !(section_is_overlay (b
->section
)))
1441 /* No overlay handling: just remove the breakpoint. */
1443 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1444 val
= target_remove_hw_breakpoint (&b
->target_info
);
1446 val
= target_remove_breakpoint (&b
->target_info
);
1450 /* This breakpoint is in an overlay section.
1451 Did we set a breakpoint at the LMA? */
1452 if (!overlay_events_enabled
)
1454 /* Yes -- overlay event support is not active, so we
1455 should have set a breakpoint at the LMA. Remove it.
1457 /* Ignore any failures: if the LMA is in ROM, we will
1458 have already warned when we failed to insert it. */
1459 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1460 target_remove_hw_breakpoint (&b
->overlay_target_info
);
1462 target_remove_breakpoint (&b
->overlay_target_info
);
1464 /* Did we set a breakpoint at the VMA?
1465 If so, we will have marked the breakpoint 'inserted'. */
1468 /* Yes -- remove it. Previously we did not bother to
1469 remove the breakpoint if the section had been
1470 unmapped, but let's not rely on that being safe. We
1471 don't know what the overlay manager might do. */
1472 if (b
->loc_type
== bp_loc_hardware_breakpoint
)
1473 val
= target_remove_hw_breakpoint (&b
->target_info
);
1475 val
= target_remove_breakpoint (&b
->target_info
);
1479 /* No -- not inserted, so no need to remove. No error. */
1485 b
->inserted
= (is
== mark_inserted
);
1487 else if (b
->loc_type
== bp_loc_hardware_watchpoint
1488 && breakpoint_enabled (b
->owner
)
1494 b
->inserted
= (is
== mark_inserted
);
1495 /* Walk down the saved value chain. */
1496 for (v
= b
->owner
->val_chain
; v
; v
= value_next (v
))
1498 /* For each memory reference remove the watchpoint
1500 if (VALUE_LVAL (v
) == lval_memory
1501 && ! value_lazy (v
))
1503 struct type
*vtype
= check_typedef (value_type (v
));
1505 if (v
== b
->owner
->val_chain
1506 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1507 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1512 addr
= VALUE_ADDRESS (v
) + value_offset (v
);
1513 len
= TYPE_LENGTH (value_type (v
));
1515 if (b
->owner
->type
== bp_read_watchpoint
)
1517 else if (b
->owner
->type
== bp_access_watchpoint
)
1520 val
= target_remove_watchpoint (addr
, len
, type
);
1527 /* Failure to remove any of the hardware watchpoints comes here. */
1528 if ((is
== mark_uninserted
) && (b
->inserted
))
1529 warning (_("Could not remove hardware watchpoint %d."),
1532 else if ((b
->owner
->type
== bp_catch_fork
||
1533 b
->owner
->type
== bp_catch_vfork
||
1534 b
->owner
->type
== bp_catch_exec
)
1535 && breakpoint_enabled (b
->owner
)
1539 switch (b
->owner
->type
)
1542 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1544 case bp_catch_vfork
:
1545 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1548 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1551 warning (_("Internal error, %s line %d."), __FILE__
, __LINE__
);
1556 b
->inserted
= (is
== mark_inserted
);
1558 else if ((b
->owner
->type
== bp_catch_catch
||
1559 b
->owner
->type
== bp_catch_throw
)
1560 && breakpoint_enabled (b
->owner
)
1563 val
= target_remove_breakpoint (&b
->target_info
);
1566 b
->inserted
= (is
== mark_inserted
);
1568 else if (ep_is_exception_catchpoint (b
->owner
)
1569 && b
->inserted
/* sometimes previous insert doesn't happen */
1570 && breakpoint_enabled (b
->owner
)
1573 val
= target_remove_breakpoint (&b
->target_info
);
1577 b
->inserted
= (is
== mark_inserted
);
1583 /* Clear the "inserted" flag in all breakpoints. */
1586 mark_breakpoints_out (void)
1588 struct bp_location
*bpt
;
1590 ALL_BP_LOCATIONS (bpt
)
1594 /* Clear the "inserted" flag in all breakpoints and delete any
1595 breakpoints which should go away between runs of the program.
1597 Plus other such housekeeping that has to be done for breakpoints
1600 Note: this function gets called at the end of a run (by
1601 generic_mourn_inferior) and when a run begins (by
1602 init_wait_for_inferior). */
1607 breakpoint_init_inferior (enum inf_context context
)
1609 struct breakpoint
*b
, *temp
;
1610 struct bp_location
*bpt
;
1611 static int warning_needed
= 0;
1613 ALL_BP_LOCATIONS (bpt
)
1616 ALL_BREAKPOINTS_SAFE (b
, temp
)
1621 case bp_watchpoint_scope
:
1623 /* If the call dummy breakpoint is at the entry point it will
1624 cause problems when the inferior is rerun, so we better
1627 Also get rid of scope breakpoints. */
1628 delete_breakpoint (b
);
1632 case bp_hardware_watchpoint
:
1633 case bp_read_watchpoint
:
1634 case bp_access_watchpoint
:
1636 /* Likewise for watchpoints on local expressions. */
1637 if (b
->exp_valid_block
!= NULL
)
1638 delete_breakpoint (b
);
1639 if (context
== inf_starting
)
1641 /* Reset val field to force reread of starting value
1642 in insert_breakpoints. */
1644 value_free (b
->val
);
1649 /* Likewise for exception catchpoints in dynamic-linked
1650 executables where required */
1651 if (ep_is_exception_catchpoint (b
)
1652 && deprecated_exception_catchpoints_are_fragile
)
1655 delete_breakpoint (b
);
1661 if (deprecated_exception_catchpoints_are_fragile
)
1662 deprecated_exception_support_initialized
= 0;
1664 /* Don't issue the warning unless it's really needed... */
1665 if (warning_needed
&& (context
!= inf_exited
))
1667 warning (_("Exception catchpoints from last run were deleted.\n"
1668 "You must reinsert them explicitly."));
1673 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1674 exists at PC. It returns ordinary_breakpoint_here if it's an
1675 ordinary breakpoint, or permanent_breakpoint_here if it's a
1676 permanent breakpoint.
1677 - When continuing from a location with an ordinary breakpoint, we
1678 actually single step once before calling insert_breakpoints.
1679 - When continuing from a localion with a permanent breakpoint, we
1680 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1681 the target, to advance the PC past the breakpoint. */
1683 enum breakpoint_here
1684 breakpoint_here_p (CORE_ADDR pc
)
1686 struct bp_location
*bpt
;
1687 int any_breakpoint_here
= 0;
1689 ALL_BP_LOCATIONS (bpt
)
1691 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1692 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1695 if ((breakpoint_enabled (bpt
->owner
)
1696 || bpt
->owner
->enable_state
== bp_permanent
)
1697 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1699 if (overlay_debugging
1700 && section_is_overlay (bpt
->section
)
1701 && !section_is_mapped (bpt
->section
))
1702 continue; /* unmapped overlay -- can't be a match */
1703 else if (bpt
->owner
->enable_state
== bp_permanent
)
1704 return permanent_breakpoint_here
;
1706 any_breakpoint_here
= 1;
1710 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1714 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1715 but it only returns true if there is actually a breakpoint inserted
1719 breakpoint_inserted_here_p (CORE_ADDR pc
)
1721 struct bp_location
*bpt
;
1723 ALL_BP_LOCATIONS (bpt
)
1725 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1726 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1730 && bpt
->address
== pc
) /* bp is inserted and matches pc */
1732 if (overlay_debugging
1733 && section_is_overlay (bpt
->section
)
1734 && !section_is_mapped (bpt
->section
))
1735 continue; /* unmapped overlay -- can't be a match */
1744 /* This function returns non-zero iff there is a software breakpoint
1748 software_breakpoint_inserted_here_p (CORE_ADDR pc
)
1750 struct bp_location
*bpt
;
1751 int any_breakpoint_here
= 0;
1753 ALL_BP_LOCATIONS (bpt
)
1755 if (bpt
->loc_type
!= bp_loc_software_breakpoint
)
1758 if ((breakpoint_enabled (bpt
->owner
)
1759 || bpt
->owner
->enable_state
== bp_permanent
)
1761 && bpt
->address
== pc
) /* bp is enabled and matches pc */
1763 if (overlay_debugging
1764 && section_is_overlay (bpt
->section
)
1765 && !section_is_mapped (bpt
->section
))
1766 continue; /* unmapped overlay -- can't be a match */
1775 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at
1776 PC is valid for process/thread PTID. */
1779 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1781 struct bp_location
*bpt
;
1784 thread
= pid_to_thread_id (ptid
);
1786 ALL_BP_LOCATIONS (bpt
)
1788 if (bpt
->loc_type
!= bp_loc_software_breakpoint
1789 && bpt
->loc_type
!= bp_loc_hardware_breakpoint
)
1792 if ((breakpoint_enabled (bpt
->owner
)
1793 || bpt
->owner
->enable_state
== bp_permanent
)
1794 && bpt
->address
== pc
1795 && (bpt
->owner
->thread
== -1 || bpt
->owner
->thread
== thread
))
1797 if (overlay_debugging
1798 && section_is_overlay (bpt
->section
)
1799 && !section_is_mapped (bpt
->section
))
1800 continue; /* unmapped overlay -- can't be a match */
1810 /* bpstat stuff. External routines' interfaces are documented
1814 ep_is_catchpoint (struct breakpoint
*ep
)
1817 (ep
->type
== bp_catch_load
)
1818 || (ep
->type
== bp_catch_unload
)
1819 || (ep
->type
== bp_catch_fork
)
1820 || (ep
->type
== bp_catch_vfork
)
1821 || (ep
->type
== bp_catch_exec
)
1822 || (ep
->type
== bp_catch_catch
)
1823 || (ep
->type
== bp_catch_throw
);
1825 /* ??rehrauer: Add more kinds here, as are implemented... */
1829 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1832 (ep
->type
== bp_catch_load
)
1833 || (ep
->type
== bp_catch_unload
);
1837 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1840 (ep
->type
== bp_catch_catch
)
1841 || (ep
->type
== bp_catch_throw
);
1844 /* Clear a bpstat so that it says we are not at any breakpoint.
1845 Also free any storage that is part of a bpstat. */
1848 bpstat_clear (bpstat
*bsp
)
1859 if (p
->old_val
!= NULL
)
1860 value_free (p
->old_val
);
1861 free_command_lines (&p
->commands
);
1868 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1869 is part of the bpstat is copied as well. */
1872 bpstat_copy (bpstat bs
)
1876 bpstat retval
= NULL
;
1881 for (; bs
!= NULL
; bs
= bs
->next
)
1883 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1884 memcpy (tmp
, bs
, sizeof (*tmp
));
1885 if (bs
->commands
!= NULL
)
1886 tmp
->commands
= copy_command_lines (bs
->commands
);
1887 if (bs
->old_val
!= NULL
)
1888 tmp
->old_val
= value_copy (bs
->old_val
);
1891 /* This is the first thing in the chain. */
1901 /* Find the bpstat associated with this breakpoint */
1904 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1909 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1911 if (bsp
->breakpoint_at
== breakpoint
)
1917 /* Find a step_resume breakpoint associated with this bpstat.
1918 (If there are multiple step_resume bp's on the list, this function
1919 will arbitrarily pick one.)
1921 It is an error to use this function if BPSTAT doesn't contain a
1922 step_resume breakpoint.
1924 See wait_for_inferior's use of this function. */
1926 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1930 gdb_assert (bsp
!= NULL
);
1932 current_thread
= pid_to_thread_id (inferior_ptid
);
1934 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1936 if ((bsp
->breakpoint_at
!= NULL
) &&
1937 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1938 (bsp
->breakpoint_at
->thread
== current_thread
||
1939 bsp
->breakpoint_at
->thread
== -1))
1940 return bsp
->breakpoint_at
;
1943 internal_error (__FILE__
, __LINE__
, _("No step_resume breakpoint found."));
1947 /* Return the breakpoint number of the first breakpoint we are stopped
1948 at. *BSP upon return is a bpstat which points to the remaining
1949 breakpoints stopped at (but which is not guaranteed to be good for
1950 anything but further calls to bpstat_num).
1951 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1954 bpstat_num (bpstat
*bsp
)
1956 struct breakpoint
*b
;
1959 return 0; /* No more breakpoint values */
1962 b
= (*bsp
)->breakpoint_at
;
1963 *bsp
= (*bsp
)->next
;
1965 return -1; /* breakpoint that's been deleted since */
1967 return b
->number
; /* We have its number */
1971 /* Modify BS so that the actions will not be performed. */
1974 bpstat_clear_actions (bpstat bs
)
1976 for (; bs
!= NULL
; bs
= bs
->next
)
1978 free_command_lines (&bs
->commands
);
1979 if (bs
->old_val
!= NULL
)
1981 value_free (bs
->old_val
);
1987 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1989 cleanup_executing_breakpoints (void *ignore
)
1991 executing_breakpoint_commands
= 0;
1994 /* Execute all the commands associated with all the breakpoints at this
1995 location. Any of these commands could cause the process to proceed
1996 beyond this point, etc. We look out for such changes by checking
1997 the global "breakpoint_proceeded" after each command. */
2000 bpstat_do_actions (bpstat
*bsp
)
2003 struct cleanup
*old_chain
;
2005 /* Avoid endless recursion if a `source' command is contained
2007 if (executing_breakpoint_commands
)
2010 executing_breakpoint_commands
= 1;
2011 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
2014 /* Note that (as of this writing), our callers all appear to
2015 be passing us the address of global stop_bpstat. And, if
2016 our calls to execute_control_command cause the inferior to
2017 proceed, that global (and hence, *bsp) will change.
2019 We must be careful to not touch *bsp unless the inferior
2020 has not proceeded. */
2022 /* This pointer will iterate over the list of bpstat's. */
2025 breakpoint_proceeded
= 0;
2026 for (; bs
!= NULL
; bs
= bs
->next
)
2028 struct command_line
*cmd
;
2029 struct cleanup
*this_cmd_tree_chain
;
2031 /* Take ownership of the BSP's command tree, if it has one.
2033 The command tree could legitimately contain commands like
2034 'step' and 'next', which call clear_proceed_status, which
2035 frees stop_bpstat's command tree. To make sure this doesn't
2036 free the tree we're executing out from under us, we need to
2037 take ownership of the tree ourselves. Since a given bpstat's
2038 commands are only executed once, we don't need to copy it; we
2039 can clear the pointer in the bpstat, and make sure we free
2040 the tree when we're done. */
2043 this_cmd_tree_chain
= make_cleanup_free_command_lines (&cmd
);
2047 execute_control_command (cmd
);
2049 if (breakpoint_proceeded
)
2055 /* We can free this command tree now. */
2056 do_cleanups (this_cmd_tree_chain
);
2058 if (breakpoint_proceeded
)
2059 /* The inferior is proceeded by the command; bomb out now.
2060 The bpstat chain has been blown away by wait_for_inferior.
2061 But since execution has stopped again, there is a new bpstat
2062 to look at, so start over. */
2065 do_cleanups (old_chain
);
2068 /* This is the normal print function for a bpstat. In the future,
2069 much of this logic could (should?) be moved to bpstat_stop_status,
2070 by having it set different print_it values.
2072 Current scheme: When we stop, bpstat_print() is called. It loops
2073 through the bpstat list of things causing this stop, calling the
2074 print_bp_stop_message function on each one. The behavior of the
2075 print_bp_stop_message function depends on the print_it field of
2076 bpstat. If such field so indicates, call this function here.
2078 Return values from this routine (ultimately used by bpstat_print()
2079 and normal_stop() to decide what to do):
2080 PRINT_NOTHING: Means we already printed all we needed to print,
2081 don't print anything else.
2082 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2083 that something to be followed by a location.
2084 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2085 that something to be followed by a location.
2086 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2089 static enum print_stop_action
2090 print_it_typical (bpstat bs
)
2092 struct cleanup
*old_chain
, *ui_out_chain
;
2093 struct ui_stream
*stb
;
2094 stb
= ui_out_stream_new (uiout
);
2095 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2096 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2097 which has since been deleted. */
2098 if (bs
->breakpoint_at
== NULL
)
2099 return PRINT_UNKNOWN
;
2101 switch (bs
->breakpoint_at
->type
)
2104 case bp_hardware_breakpoint
:
2105 if (bs
->breakpoint_at
->loc
->address
!= bs
->breakpoint_at
->loc
->requested_address
)
2106 breakpoint_adjustment_warning (bs
->breakpoint_at
->loc
->requested_address
,
2107 bs
->breakpoint_at
->loc
->address
,
2108 bs
->breakpoint_at
->number
, 1);
2109 annotate_breakpoint (bs
->breakpoint_at
->number
);
2110 ui_out_text (uiout
, "\nBreakpoint ");
2111 if (ui_out_is_mi_like_p (uiout
))
2112 ui_out_field_string (uiout
, "reason",
2113 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
2114 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2115 ui_out_text (uiout
, ", ");
2116 return PRINT_SRC_AND_LOC
;
2119 case bp_shlib_event
:
2120 /* Did we stop because the user set the stop_on_solib_events
2121 variable? (If so, we report this as a generic, "Stopped due
2122 to shlib event" message.) */
2123 printf_filtered (_("Stopped due to shared library event\n"));
2124 return PRINT_NOTHING
;
2127 case bp_thread_event
:
2128 /* Not sure how we will get here.
2129 GDB should not stop for these breakpoints. */
2130 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n"));
2131 return PRINT_NOTHING
;
2134 case bp_overlay_event
:
2135 /* By analogy with the thread event, GDB should not stop for these. */
2136 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n"));
2137 return PRINT_NOTHING
;
2141 annotate_catchpoint (bs
->breakpoint_at
->number
);
2142 printf_filtered (_("\nCatchpoint %d (loaded %s), "),
2143 bs
->breakpoint_at
->number
,
2144 bs
->breakpoint_at
->triggered_dll_pathname
);
2145 return PRINT_SRC_AND_LOC
;
2148 case bp_catch_unload
:
2149 annotate_catchpoint (bs
->breakpoint_at
->number
);
2150 printf_filtered (_("\nCatchpoint %d (unloaded %s), "),
2151 bs
->breakpoint_at
->number
,
2152 bs
->breakpoint_at
->triggered_dll_pathname
);
2153 return PRINT_SRC_AND_LOC
;
2157 annotate_catchpoint (bs
->breakpoint_at
->number
);
2158 printf_filtered (_("\nCatchpoint %d (forked process %d), "),
2159 bs
->breakpoint_at
->number
,
2160 bs
->breakpoint_at
->forked_inferior_pid
);
2161 return PRINT_SRC_AND_LOC
;
2164 case bp_catch_vfork
:
2165 annotate_catchpoint (bs
->breakpoint_at
->number
);
2166 printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
2167 bs
->breakpoint_at
->number
,
2168 bs
->breakpoint_at
->forked_inferior_pid
);
2169 return PRINT_SRC_AND_LOC
;
2173 annotate_catchpoint (bs
->breakpoint_at
->number
);
2174 printf_filtered (_("\nCatchpoint %d (exec'd %s), "),
2175 bs
->breakpoint_at
->number
,
2176 bs
->breakpoint_at
->exec_pathname
);
2177 return PRINT_SRC_AND_LOC
;
2180 case bp_catch_catch
:
2181 if (current_exception_event
&&
2182 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2184 annotate_catchpoint (bs
->breakpoint_at
->number
);
2185 printf_filtered (_("\nCatchpoint %d (exception caught), "),
2186 bs
->breakpoint_at
->number
);
2187 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2188 printf_filtered (_("throw location %s:%d, "),
2189 CURRENT_EXCEPTION_THROW_FILE
,
2190 CURRENT_EXCEPTION_THROW_LINE
);
2192 printf_filtered (_("throw location unknown, "));
2194 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2195 printf_filtered (_("catch location %s:%d\n"),
2196 CURRENT_EXCEPTION_CATCH_FILE
,
2197 CURRENT_EXCEPTION_CATCH_LINE
);
2199 printf_filtered (_("catch location unknown\n"));
2201 /* don't bother to print location frame info */
2202 return PRINT_SRC_ONLY
;
2206 /* really throw, some other bpstat will handle it */
2207 return PRINT_UNKNOWN
;
2211 case bp_catch_throw
:
2212 if (current_exception_event
&&
2213 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2215 annotate_catchpoint (bs
->breakpoint_at
->number
);
2216 printf_filtered (_("\nCatchpoint %d (exception thrown), "),
2217 bs
->breakpoint_at
->number
);
2218 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2219 printf_filtered (_("throw location %s:%d, "),
2220 CURRENT_EXCEPTION_THROW_FILE
,
2221 CURRENT_EXCEPTION_THROW_LINE
);
2223 printf_filtered (_("throw location unknown, "));
2225 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2226 printf_filtered (_("catch location %s:%d\n"),
2227 CURRENT_EXCEPTION_CATCH_FILE
,
2228 CURRENT_EXCEPTION_CATCH_LINE
);
2230 printf_filtered (_("catch location unknown\n"));
2232 /* don't bother to print location frame info */
2233 return PRINT_SRC_ONLY
;
2237 /* really catch, some other bpstat will handle it */
2238 return PRINT_UNKNOWN
;
2243 case bp_hardware_watchpoint
:
2244 if (bs
->old_val
!= NULL
)
2246 annotate_watchpoint (bs
->breakpoint_at
->number
);
2247 if (ui_out_is_mi_like_p (uiout
))
2250 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER
));
2251 mention (bs
->breakpoint_at
);
2252 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2253 ui_out_text (uiout
, "\nOld value = ");
2254 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2255 ui_out_field_stream (uiout
, "old", stb
);
2256 ui_out_text (uiout
, "\nNew value = ");
2257 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2258 ui_out_field_stream (uiout
, "new", stb
);
2259 do_cleanups (ui_out_chain
);
2260 ui_out_text (uiout
, "\n");
2261 value_free (bs
->old_val
);
2264 /* More than one watchpoint may have been triggered. */
2265 return PRINT_UNKNOWN
;
2268 case bp_read_watchpoint
:
2269 if (ui_out_is_mi_like_p (uiout
))
2272 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER
));
2273 mention (bs
->breakpoint_at
);
2274 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2275 ui_out_text (uiout
, "\nValue = ");
2276 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2277 ui_out_field_stream (uiout
, "value", stb
);
2278 do_cleanups (ui_out_chain
);
2279 ui_out_text (uiout
, "\n");
2280 return PRINT_UNKNOWN
;
2283 case bp_access_watchpoint
:
2284 if (bs
->old_val
!= NULL
)
2286 annotate_watchpoint (bs
->breakpoint_at
->number
);
2287 if (ui_out_is_mi_like_p (uiout
))
2290 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2291 mention (bs
->breakpoint_at
);
2292 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2293 ui_out_text (uiout
, "\nOld value = ");
2294 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2295 ui_out_field_stream (uiout
, "old", stb
);
2296 value_free (bs
->old_val
);
2298 ui_out_text (uiout
, "\nNew value = ");
2302 mention (bs
->breakpoint_at
);
2303 if (ui_out_is_mi_like_p (uiout
))
2306 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER
));
2307 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2308 ui_out_text (uiout
, "\nValue = ");
2310 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2311 ui_out_field_stream (uiout
, "new", stb
);
2312 do_cleanups (ui_out_chain
);
2313 ui_out_text (uiout
, "\n");
2314 return PRINT_UNKNOWN
;
2317 /* Fall through, we don't deal with these types of breakpoints
2321 if (ui_out_is_mi_like_p (uiout
))
2324 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED
));
2325 return PRINT_UNKNOWN
;
2329 if (ui_out_is_mi_like_p (uiout
))
2332 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED
));
2333 return PRINT_UNKNOWN
;
2338 case bp_longjmp_resume
:
2339 case bp_step_resume
:
2340 case bp_through_sigtramp
:
2341 case bp_watchpoint_scope
:
2344 return PRINT_UNKNOWN
;
2348 /* Generic routine for printing messages indicating why we
2349 stopped. The behavior of this function depends on the value
2350 'print_it' in the bpstat structure. Under some circumstances we
2351 may decide not to print anything here and delegate the task to
2354 static enum print_stop_action
2355 print_bp_stop_message (bpstat bs
)
2357 switch (bs
->print_it
)
2360 /* Nothing should be printed for this bpstat entry. */
2361 return PRINT_UNKNOWN
;
2365 /* We still want to print the frame, but we already printed the
2366 relevant messages. */
2367 return PRINT_SRC_AND_LOC
;
2370 case print_it_normal
:
2371 /* Normal case. Call the breakpoint's print_it method, or
2372 print_it_typical. */
2373 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2374 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2375 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2377 return print_it_typical (bs
);
2381 internal_error (__FILE__
, __LINE__
,
2382 _("print_bp_stop_message: unrecognized enum value"));
2387 /* Print a message indicating what happened. This is called from
2388 normal_stop(). The input to this routine is the head of the bpstat
2389 list - a list of the eventpoints that caused this stop. This
2390 routine calls the generic print routine for printing a message
2391 about reasons for stopping. This will print (for example) the
2392 "Breakpoint n," part of the output. The return value of this
2395 PRINT_UNKNOWN: Means we printed nothing
2396 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2397 code to print the location. An example is
2398 "Breakpoint 1, " which should be followed by
2400 PRINT_SRC_ONLY: Means we printed something, but there is no need
2401 to also print the location part of the message.
2402 An example is the catch/throw messages, which
2403 don't require a location appended to the end.
2404 PRINT_NOTHING: We have done some printing and we don't need any
2405 further info to be printed.*/
2407 enum print_stop_action
2408 bpstat_print (bpstat bs
)
2412 /* Maybe another breakpoint in the chain caused us to stop.
2413 (Currently all watchpoints go on the bpstat whether hit or not.
2414 That probably could (should) be changed, provided care is taken
2415 with respect to bpstat_explains_signal). */
2416 for (; bs
; bs
= bs
->next
)
2418 val
= print_bp_stop_message (bs
);
2419 if (val
== PRINT_SRC_ONLY
2420 || val
== PRINT_SRC_AND_LOC
2421 || val
== PRINT_NOTHING
)
2425 /* We reached the end of the chain, or we got a null BS to start
2426 with and nothing was printed. */
2427 return PRINT_UNKNOWN
;
2430 /* Evaluate the expression EXP and return 1 if value is zero.
2431 This is used inside a catch_errors to evaluate the breakpoint condition.
2432 The argument is a "struct expression *" that has been cast to char * to
2433 make it pass through catch_errors. */
2436 breakpoint_cond_eval (void *exp
)
2438 struct value
*mark
= value_mark ();
2439 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2440 value_free_to_mark (mark
);
2444 /* Allocate a new bpstat and chain it to the current one. */
2447 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2451 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2453 bs
->breakpoint_at
= b
;
2454 /* If the condition is false, etc., don't do the commands. */
2455 bs
->commands
= NULL
;
2457 bs
->print_it
= print_it_normal
;
2461 /* Possible return values for watchpoint_check (this can't be an enum
2462 because of check_errors). */
2463 /* The watchpoint has been deleted. */
2464 #define WP_DELETED 1
2465 /* The value has changed. */
2466 #define WP_VALUE_CHANGED 2
2467 /* The value has not changed. */
2468 #define WP_VALUE_NOT_CHANGED 3
2470 #define BP_TEMPFLAG 1
2471 #define BP_HARDWAREFLAG 2
2473 /* Check watchpoint condition. */
2476 watchpoint_check (void *p
)
2478 bpstat bs
= (bpstat
) p
;
2479 struct breakpoint
*b
;
2480 struct frame_info
*fr
;
2481 int within_current_scope
;
2483 b
= bs
->breakpoint_at
;
2485 if (b
->exp_valid_block
== NULL
)
2486 within_current_scope
= 1;
2489 /* There is no current frame at this moment. If we're going to have
2490 any chance of handling watchpoints on local variables, we'll need
2491 the frame chain (so we can determine if we're in scope). */
2492 reinit_frame_cache ();
2493 fr
= frame_find_by_id (b
->watchpoint_frame
);
2494 within_current_scope
= (fr
!= NULL
);
2495 /* in_function_epilogue_p() returns a non-zero value if we're still
2496 in the function but the stack frame has already been invalidated.
2497 Since we can't rely on the values of local variables after the
2498 stack has been destroyed, we are treating the watchpoint in that
2499 state as `not changed' without further checking.
2501 vinschen/2003-09-04: The former implementation left out the case
2502 that the watchpoint frame couldn't be found by frame_find_by_id()
2503 because the current PC is currently in an epilogue. Calling
2504 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2505 if ((!within_current_scope
|| fr
== get_current_frame ())
2506 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2507 return WP_VALUE_NOT_CHANGED
;
2508 if (fr
&& within_current_scope
)
2509 /* If we end up stopping, the current frame will get selected
2510 in normal_stop. So this call to select_frame won't affect
2515 if (within_current_scope
)
2517 /* We use value_{,free_to_}mark because it could be a
2518 *long* time before we return to the command level and
2519 call free_all_values. We can't call free_all_values because
2520 we might be in the middle of evaluating a function call. */
2522 struct value
*mark
= value_mark ();
2523 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2524 if (!value_equal (b
->val
, new_val
))
2526 release_value (new_val
);
2527 value_free_to_mark (mark
);
2528 bs
->old_val
= b
->val
;
2530 /* We will stop here */
2531 return WP_VALUE_CHANGED
;
2535 /* Nothing changed, don't do anything. */
2536 value_free_to_mark (mark
);
2537 /* We won't stop here */
2538 return WP_VALUE_NOT_CHANGED
;
2543 /* This seems like the only logical thing to do because
2544 if we temporarily ignored the watchpoint, then when
2545 we reenter the block in which it is valid it contains
2546 garbage (in the case of a function, it may have two
2547 garbage values, one before and one after the prologue).
2548 So we can't even detect the first assignment to it and
2549 watch after that (since the garbage may or may not equal
2550 the first value assigned). */
2551 /* We print all the stop information in print_it_typical(), but
2552 in this case, by the time we call print_it_typical() this bp
2553 will be deleted already. So we have no choice but print the
2554 information here. */
2555 if (ui_out_is_mi_like_p (uiout
))
2557 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE
));
2558 ui_out_text (uiout
, "\nWatchpoint ");
2559 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2560 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2561 which its expression is valid.\n");
2563 if (b
->related_breakpoint
)
2564 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2565 b
->disposition
= disp_del_at_next_stop
;
2571 /* Get a bpstat associated with having just stopped at address
2572 BP_ADDR in thread PTID. STOPPED_BY_WATCHPOINT is 1 if the
2573 target thinks we stopped due to a hardware watchpoint, 0 if we
2574 know we did not trigger a hardware watchpoint, and -1 if we do not know. */
2576 /* Determine whether we stopped at a breakpoint, etc, or whether we
2577 don't understand this stop. Result is a chain of bpstat's such that:
2579 if we don't understand the stop, the result is a null pointer.
2581 if we understand why we stopped, the result is not null.
2583 Each element of the chain refers to a particular breakpoint or
2584 watchpoint at which we have stopped. (We may have stopped for
2585 several reasons concurrently.)
2587 Each element of the chain has valid next, breakpoint_at,
2588 commands, FIXME??? fields. */
2591 bpstat_stop_status (CORE_ADDR bp_addr
, ptid_t ptid
, int stopped_by_watchpoint
)
2593 struct breakpoint
*b
, *temp
;
2594 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2595 int real_breakpoint
= 0;
2596 /* Root of the chain of bpstat's */
2597 struct bpstats root_bs
[1];
2598 /* Pointer to the last thing in the chain currently. */
2599 bpstat bs
= root_bs
;
2600 int thread_id
= pid_to_thread_id (ptid
);
2602 ALL_BREAKPOINTS_SAFE (b
, temp
)
2604 if (!breakpoint_enabled (b
) && b
->enable_state
!= bp_permanent
)
2607 if (b
->type
!= bp_watchpoint
2608 && b
->type
!= bp_hardware_watchpoint
2609 && b
->type
!= bp_read_watchpoint
2610 && b
->type
!= bp_access_watchpoint
2611 && b
->type
!= bp_hardware_breakpoint
2612 && b
->type
!= bp_catch_fork
2613 && b
->type
!= bp_catch_vfork
2614 && b
->type
!= bp_catch_exec
2615 && b
->type
!= bp_catch_catch
2616 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2618 if (b
->loc
->address
!= bp_addr
) /* address doesn't match */
2620 if (overlay_debugging
/* unmapped overlay section */
2621 && section_is_overlay (b
->loc
->section
)
2622 && !section_is_mapped (b
->loc
->section
))
2626 /* Continuable hardware watchpoints are treated as non-existent if the
2627 reason we stopped wasn't a hardware watchpoint (we didn't stop on
2628 some data address). Otherwise gdb won't stop on a break instruction
2629 in the code (not from a breakpoint) when a hardware watchpoint has
2632 if ((b
->type
== bp_hardware_watchpoint
2633 || b
->type
== bp_read_watchpoint
2634 || b
->type
== bp_access_watchpoint
)
2635 && !stopped_by_watchpoint
)
2638 if (b
->type
== bp_hardware_breakpoint
)
2640 if (b
->loc
->address
!= bp_addr
)
2642 if (overlay_debugging
/* unmapped overlay section */
2643 && section_is_overlay (b
->loc
->section
)
2644 && !section_is_mapped (b
->loc
->section
))
2648 /* Is this a catchpoint of a load or unload? If so, did we
2649 get a load or unload of the specified library? If not,
2651 if ((b
->type
== bp_catch_load
)
2652 #if defined(SOLIB_HAVE_LOAD_EVENT)
2653 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2654 || ((b
->dll_pathname
!= NULL
)
2655 && (strcmp (b
->dll_pathname
,
2656 SOLIB_LOADED_LIBRARY_PATHNAME (
2657 PIDGET (inferior_ptid
)))
2663 if ((b
->type
== bp_catch_unload
)
2664 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2665 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2666 || ((b
->dll_pathname
!= NULL
)
2667 && (strcmp (b
->dll_pathname
,
2668 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2669 PIDGET (inferior_ptid
)))
2675 if ((b
->type
== bp_catch_fork
)
2676 && !inferior_has_forked (PIDGET (inferior_ptid
),
2677 &b
->forked_inferior_pid
))
2680 if ((b
->type
== bp_catch_vfork
)
2681 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2682 &b
->forked_inferior_pid
))
2685 if ((b
->type
== bp_catch_exec
)
2686 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2689 if (ep_is_exception_catchpoint (b
) &&
2690 !(current_exception_event
= target_get_current_exception_event ()))
2693 /* Come here if it's a watchpoint, or if the break address matches */
2695 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2697 /* Watchpoints may change this, if not found to have triggered. */
2701 if (b
->type
== bp_watchpoint
||
2702 b
->type
== bp_hardware_watchpoint
)
2704 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2706 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2707 int e
= catch_errors (watchpoint_check
, bs
, message
,
2709 do_cleanups (cleanups
);
2713 /* We've already printed what needs to be printed. */
2714 /* Actually this is superfluous, because by the time we
2715 call print_it_typical() the wp will be already deleted,
2716 and the function will return immediately. */
2717 bs
->print_it
= print_it_done
;
2720 case WP_VALUE_CHANGED
:
2724 case WP_VALUE_NOT_CHANGED
:
2726 bs
->print_it
= print_it_noop
;
2733 /* Error from catch_errors. */
2734 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2735 if (b
->related_breakpoint
)
2736 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2737 b
->disposition
= disp_del_at_next_stop
;
2738 /* We've already printed what needs to be printed. */
2739 bs
->print_it
= print_it_done
;
2745 else if (b
->type
== bp_read_watchpoint
||
2746 b
->type
== bp_access_watchpoint
)
2752 if (!target_stopped_data_address (¤t_target
, &addr
))
2754 for (v
= b
->val_chain
; v
; v
= value_next (v
))
2756 if (VALUE_LVAL (v
) == lval_memory
2757 && ! value_lazy (v
))
2759 struct type
*vtype
= check_typedef (value_type (v
));
2761 if (v
== b
->val_chain
2762 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2763 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2767 vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
2768 /* Exact match not required. Within range is
2770 if (addr
>= vaddr
&&
2771 addr
< vaddr
+ TYPE_LENGTH (value_type (v
)))
2778 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2780 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2781 int e
= catch_errors (watchpoint_check
, bs
, message
,
2783 do_cleanups (cleanups
);
2787 /* We've already printed what needs to be printed. */
2788 bs
->print_it
= print_it_done
;
2791 case WP_VALUE_CHANGED
:
2792 if (b
->type
== bp_read_watchpoint
)
2794 /* Don't stop: read watchpoints shouldn't fire if
2795 the value has changed. This is for targets
2796 which cannot set read-only watchpoints. */
2797 bs
->print_it
= print_it_noop
;
2803 case WP_VALUE_NOT_CHANGED
:
2810 /* Error from catch_errors. */
2811 printf_filtered (_("Watchpoint %d deleted.\n"), b
->number
);
2812 if (b
->related_breakpoint
)
2813 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2814 b
->disposition
= disp_del_at_next_stop
;
2815 /* We've already printed what needs to be printed. */
2816 bs
->print_it
= print_it_done
;
2820 else /* found == 0 */
2822 /* This is a case where some watchpoint(s) triggered,
2823 but not at the address of this watchpoint (FOUND
2824 was left zero). So don't print anything for this
2826 bs
->print_it
= print_it_noop
;
2833 /* By definition, an encountered breakpoint is a triggered
2837 real_breakpoint
= 1;
2840 if (frame_id_p (b
->frame_id
)
2841 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2845 int value_is_zero
= 0;
2849 /* Need to select the frame, with all that implies
2850 so that the conditions will have the right context. */
2851 select_frame (get_current_frame ());
2853 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2854 "Error in testing breakpoint condition:\n",
2856 /* FIXME-someday, should give breakpoint # */
2859 if (b
->cond
&& value_is_zero
)
2862 /* Don't consider this a hit. */
2865 else if (b
->thread
!= -1 && b
->thread
!= thread_id
)
2868 /* Don't consider this a hit. */
2871 else if (b
->ignore_count
> 0)
2874 annotate_ignore_count_change ();
2879 /* We will stop here */
2880 if (b
->disposition
== disp_disable
)
2881 b
->enable_state
= bp_disabled
;
2884 bs
->commands
= b
->commands
;
2886 (strcmp ("silent", bs
->commands
->line
) == 0
2887 || (xdb_commands
&& strcmp ("Q", bs
->commands
->line
) == 0)))
2889 bs
->commands
= bs
->commands
->next
;
2892 bs
->commands
= copy_command_lines (bs
->commands
);
2895 /* Print nothing for this entry if we dont stop or if we dont print. */
2896 if (bs
->stop
== 0 || bs
->print
== 0)
2897 bs
->print_it
= print_it_noop
;
2900 bs
->next
= NULL
; /* Terminate the chain */
2901 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2903 /* The value of a hardware watchpoint hasn't changed, but the
2904 intermediate memory locations we are watching may have. */
2905 if (bs
&& !bs
->stop
&&
2906 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2907 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2908 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2910 remove_breakpoints ();
2911 insert_breakpoints ();
2916 /* Tell what to do about this bpstat. */
2918 bpstat_what (bpstat bs
)
2920 /* Classify each bpstat as one of the following. */
2923 /* This bpstat element has no effect on the main_action. */
2926 /* There was a watchpoint, stop but don't print. */
2929 /* There was a watchpoint, stop and print. */
2932 /* There was a breakpoint but we're not stopping. */
2935 /* There was a breakpoint, stop but don't print. */
2938 /* There was a breakpoint, stop and print. */
2941 /* We hit the longjmp breakpoint. */
2944 /* We hit the longjmp_resume breakpoint. */
2947 /* We hit the step_resume breakpoint. */
2950 /* We hit the through_sigtramp breakpoint. */
2953 /* We hit the shared library event breakpoint. */
2956 /* We caught a shared library event. */
2959 /* This is just used to count how many enums there are. */
2963 /* Here is the table which drives this routine. So that we can
2964 format it pretty, we define some abbreviations for the
2965 enum bpstat_what codes. */
2966 #define kc BPSTAT_WHAT_KEEP_CHECKING
2967 #define ss BPSTAT_WHAT_STOP_SILENT
2968 #define sn BPSTAT_WHAT_STOP_NOISY
2969 #define sgl BPSTAT_WHAT_SINGLE
2970 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2971 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2972 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2973 #define sr BPSTAT_WHAT_STEP_RESUME
2974 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2975 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2976 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2978 /* "Can't happen." Might want to print an error message.
2979 abort() is not out of the question, but chances are GDB is just
2980 a bit confused, not unusable. */
2981 #define err BPSTAT_WHAT_STOP_NOISY
2983 /* Given an old action and a class, come up with a new action. */
2984 /* One interesting property of this table is that wp_silent is the same
2985 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2986 after stopping, the check for whether to step over a breakpoint
2987 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2988 reference to how we stopped. We retain separate wp_silent and
2989 bp_silent codes in case we want to change that someday.
2991 Another possibly interesting property of this table is that
2992 there's a partial ordering, priority-like, of the actions. Once
2993 you've decided that some action is appropriate, you'll never go
2994 back and decide something of a lower priority is better. The
2997 kc < clr sgl shl shlr slr sn sr ss ts
2998 sgl < clrs shl shlr slr sn sr ss ts
2999 slr < err shl shlr sn sr ss ts
3000 clr < clrs err shl shlr sn sr ss ts
3001 clrs < err shl shlr sn sr ss ts
3002 ss < shl shlr sn sr ts
3009 What I think this means is that we don't need a damned table
3010 here. If you just put the rows and columns in the right order,
3011 it'd look awfully regular. We could simply walk the bpstat list
3012 and choose the highest priority action we find, with a little
3013 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
3014 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
3015 is messy anyway). */
3017 /* step_resume entries: a step resume breakpoint overrides another
3018 breakpoint of signal handling (see comment in wait_for_inferior
3019 at where we set the step_resume breakpoint). */
3020 /* We handle the through_sigtramp_breakpoint the same way; having both
3021 one of those and a step_resume_breakpoint is probably very rare (?). */
3023 static const enum bpstat_what_main_action
3024 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
3027 /* kc ss sn sgl slr clr clrs sr ts shl shlr
3030 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
3032 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
3034 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
3036 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
3038 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
3040 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
3042 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
3044 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
3046 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
3048 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
3050 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
3052 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
3067 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3068 struct bpstat_what retval
;
3070 retval
.call_dummy
= 0;
3071 for (; bs
!= NULL
; bs
= bs
->next
)
3073 enum class bs_class
= no_effect
;
3074 if (bs
->breakpoint_at
== NULL
)
3075 /* I suspect this can happen if it was a momentary breakpoint
3076 which has since been deleted. */
3078 switch (bs
->breakpoint_at
->type
)
3084 case bp_hardware_breakpoint
:
3090 bs_class
= bp_noisy
;
3092 bs_class
= bp_silent
;
3095 bs_class
= bp_nostop
;
3098 case bp_hardware_watchpoint
:
3099 case bp_read_watchpoint
:
3100 case bp_access_watchpoint
:
3104 bs_class
= wp_noisy
;
3106 bs_class
= wp_silent
;
3109 /* There was a watchpoint, but we're not stopping.
3110 This requires no further action. */
3111 bs_class
= no_effect
;
3114 bs_class
= long_jump
;
3116 case bp_longjmp_resume
:
3117 bs_class
= long_resume
;
3119 case bp_step_resume
:
3122 bs_class
= step_resume
;
3125 /* It is for the wrong frame. */
3126 bs_class
= bp_nostop
;
3128 case bp_through_sigtramp
:
3129 bs_class
= through_sig
;
3131 case bp_watchpoint_scope
:
3132 bs_class
= bp_nostop
;
3134 case bp_shlib_event
:
3135 bs_class
= shlib_event
;
3137 case bp_thread_event
:
3138 case bp_overlay_event
:
3139 bs_class
= bp_nostop
;
3142 case bp_catch_unload
:
3143 /* Only if this catchpoint triggered should we cause the
3144 step-out-of-dld behaviour. Otherwise, we ignore this
3147 bs_class
= catch_shlib_event
;
3149 bs_class
= no_effect
;
3152 case bp_catch_vfork
:
3157 bs_class
= bp_noisy
;
3159 bs_class
= bp_silent
;
3162 /* There was a catchpoint, but we're not stopping.
3163 This requires no further action. */
3164 bs_class
= no_effect
;
3166 case bp_catch_catch
:
3167 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3168 bs_class
= bp_nostop
;
3170 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3172 case bp_catch_throw
:
3173 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3174 bs_class
= bp_nostop
;
3176 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3179 /* Make sure the action is stop (silent or noisy),
3180 so infrun.c pops the dummy frame. */
3181 bs_class
= bp_silent
;
3182 retval
.call_dummy
= 1;
3185 current_action
= table
[(int) bs_class
][(int) current_action
];
3187 retval
.main_action
= current_action
;
3191 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3192 without hardware support). This isn't related to a specific bpstat,
3193 just to things like whether watchpoints are set. */
3196 bpstat_should_step (void)
3198 struct breakpoint
*b
;
3200 if (breakpoint_enabled (b
) && b
->type
== bp_watchpoint
)
3205 /* Nonzero if there are enabled hardware watchpoints. */
3207 bpstat_have_active_hw_watchpoints (void)
3209 struct bp_location
*bpt
;
3210 ALL_BP_LOCATIONS (bpt
)
3211 if (breakpoint_enabled (bpt
->owner
)
3213 && bpt
->loc_type
== bp_loc_hardware_watchpoint
)
3219 /* Given a bpstat that records zero or more triggered eventpoints, this
3220 function returns another bpstat which contains only the catchpoints
3221 on that first list, if any. */
3223 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3225 struct bpstats root_bs
[1];
3226 bpstat bs
= root_bs
;
3227 struct breakpoint
*ep
;
3230 bpstat_clear (cp_list
);
3231 root_bs
->next
= NULL
;
3233 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3235 /* Is this eventpoint a catchpoint? If not, ignore it. */
3236 ep
= ep_list
->breakpoint_at
;
3239 if ((ep
->type
!= bp_catch_load
) &&
3240 (ep
->type
!= bp_catch_unload
) &&
3241 (ep
->type
!= bp_catch_catch
) &&
3242 (ep
->type
!= bp_catch_throw
))
3243 /* pai: (temp) ADD fork/vfork here!! */
3246 /* Yes; add it to the list. */
3247 bs
= bpstat_alloc (ep
, bs
);
3252 #if defined(SOLIB_ADD)
3253 /* Also, for each triggered catchpoint, tag it with the name of
3254 the library that caused this trigger. (We copy the name now,
3255 because it's only guaranteed to be available NOW, when the
3256 catchpoint triggers. Clients who may wish to know the name
3257 later must get it from the catchpoint itself.) */
3258 if (ep
->triggered_dll_pathname
!= NULL
)
3259 xfree (ep
->triggered_dll_pathname
);
3260 if (ep
->type
== bp_catch_load
)
3261 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3262 PIDGET (inferior_ptid
));
3264 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3265 PIDGET (inferior_ptid
));
3267 dll_pathname
= NULL
;
3271 ep
->triggered_dll_pathname
= (char *)
3272 xmalloc (strlen (dll_pathname
) + 1);
3273 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3276 ep
->triggered_dll_pathname
= NULL
;
3282 /* Print B to gdb_stdout. */
3284 print_one_breakpoint (struct breakpoint
*b
,
3285 CORE_ADDR
*last_addr
)
3287 struct command_line
*l
;
3289 struct ep_type_description
3294 static struct ep_type_description bptypes
[] =
3296 {bp_none
, "?deleted?"},
3297 {bp_breakpoint
, "breakpoint"},
3298 {bp_hardware_breakpoint
, "hw breakpoint"},
3299 {bp_until
, "until"},
3300 {bp_finish
, "finish"},
3301 {bp_watchpoint
, "watchpoint"},
3302 {bp_hardware_watchpoint
, "hw watchpoint"},
3303 {bp_read_watchpoint
, "read watchpoint"},
3304 {bp_access_watchpoint
, "acc watchpoint"},
3305 {bp_longjmp
, "longjmp"},
3306 {bp_longjmp_resume
, "longjmp resume"},
3307 {bp_step_resume
, "step resume"},
3308 {bp_through_sigtramp
, "sigtramp"},
3309 {bp_watchpoint_scope
, "watchpoint scope"},
3310 {bp_call_dummy
, "call dummy"},
3311 {bp_shlib_event
, "shlib events"},
3312 {bp_thread_event
, "thread events"},
3313 {bp_overlay_event
, "overlay events"},
3314 {bp_catch_load
, "catch load"},
3315 {bp_catch_unload
, "catch unload"},
3316 {bp_catch_fork
, "catch fork"},
3317 {bp_catch_vfork
, "catch vfork"},
3318 {bp_catch_exec
, "catch exec"},
3319 {bp_catch_catch
, "catch catch"},
3320 {bp_catch_throw
, "catch throw"}
3323 static char *bpdisps
[] =
3324 {"del", "dstp", "dis", "keep"};
3325 static char bpenables
[] = "nynny";
3326 char wrap_indent
[80];
3327 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3328 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3329 struct cleanup
*bkpt_chain
;
3332 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3336 ui_out_field_int (uiout
, "number", b
->number
);
3340 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3341 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3342 internal_error (__FILE__
, __LINE__
,
3343 _("bptypes table does not describe type #%d."),
3345 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3349 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3353 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3354 ui_out_spaces (uiout
, 2);
3357 strcpy (wrap_indent
, " ");
3360 if (TARGET_ADDR_BIT
<= 32)
3361 strcat (wrap_indent
, " ");
3363 strcat (wrap_indent
, " ");
3366 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3367 b
->ops
->print_one (b
, last_addr
);
3372 internal_error (__FILE__
, __LINE__
,
3373 _("print_one_breakpoint: bp_none encountered\n"));
3377 case bp_hardware_watchpoint
:
3378 case bp_read_watchpoint
:
3379 case bp_access_watchpoint
:
3380 /* Field 4, the address, is omitted (which makes the columns
3381 not line up too nicely with the headers, but the effect
3382 is relatively readable). */
3384 ui_out_field_skip (uiout
, "addr");
3386 print_expression (b
->exp
, stb
->stream
);
3387 ui_out_field_stream (uiout
, "what", stb
);
3391 case bp_catch_unload
:
3392 /* Field 4, the address, is omitted (which makes the columns
3393 not line up too nicely with the headers, but the effect
3394 is relatively readable). */
3396 ui_out_field_skip (uiout
, "addr");
3398 if (b
->dll_pathname
== NULL
)
3400 ui_out_field_string (uiout
, "what", "<any library>");
3401 ui_out_spaces (uiout
, 1);
3405 ui_out_text (uiout
, "library \"");
3406 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3407 ui_out_text (uiout
, "\" ");
3412 case bp_catch_vfork
:
3413 /* Field 4, the address, is omitted (which makes the columns
3414 not line up too nicely with the headers, but the effect
3415 is relatively readable). */
3417 ui_out_field_skip (uiout
, "addr");
3419 if (b
->forked_inferior_pid
!= 0)
3421 ui_out_text (uiout
, "process ");
3422 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3423 ui_out_spaces (uiout
, 1);
3428 /* Field 4, the address, is omitted (which makes the columns
3429 not line up too nicely with the headers, but the effect
3430 is relatively readable). */
3432 ui_out_field_skip (uiout
, "addr");
3434 if (b
->exec_pathname
!= NULL
)
3436 ui_out_text (uiout
, "program \"");
3437 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3438 ui_out_text (uiout
, "\" ");
3442 case bp_catch_catch
:
3443 /* Field 4, the address, is omitted (which makes the columns
3444 not line up too nicely with the headers, but the effect
3445 is relatively readable). */
3447 ui_out_field_skip (uiout
, "addr");
3449 ui_out_field_string (uiout
, "what", "exception catch");
3450 ui_out_spaces (uiout
, 1);
3453 case bp_catch_throw
:
3454 /* Field 4, the address, is omitted (which makes the columns
3455 not line up too nicely with the headers, but the effect
3456 is relatively readable). */
3458 ui_out_field_skip (uiout
, "addr");
3460 ui_out_field_string (uiout
, "what", "exception throw");
3461 ui_out_spaces (uiout
, 1);
3465 case bp_hardware_breakpoint
:
3469 case bp_longjmp_resume
:
3470 case bp_step_resume
:
3471 case bp_through_sigtramp
:
3472 case bp_watchpoint_scope
:
3474 case bp_shlib_event
:
3475 case bp_thread_event
:
3476 case bp_overlay_event
:
3481 ui_out_field_string (uiout
, "addr", "<PENDING>");
3483 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
3486 *last_addr
= b
->loc
->address
;
3489 sym
= find_pc_sect_function (b
->loc
->address
, b
->loc
->section
);
3492 ui_out_text (uiout
, "in ");
3493 ui_out_field_string (uiout
, "func",
3494 SYMBOL_PRINT_NAME (sym
));
3495 ui_out_wrap_hint (uiout
, wrap_indent
);
3496 ui_out_text (uiout
, " at ");
3498 ui_out_field_string (uiout
, "file", b
->source_file
);
3499 ui_out_text (uiout
, ":");
3501 if (ui_out_is_mi_like_p (uiout
))
3503 struct symtab_and_line sal
= find_pc_line (b
->loc
->address
, 0);
3504 char *fullname
= symtab_to_fullname (sal
.symtab
);
3507 ui_out_field_string (uiout
, "fullname", fullname
);
3510 ui_out_field_int (uiout
, "line", b
->line_number
);
3512 else if (b
->pending
)
3514 ui_out_field_string (uiout
, "pending", b
->addr_string
);
3518 print_address_symbolic (b
->loc
->address
, stb
->stream
, demangle
, "");
3519 ui_out_field_stream (uiout
, "at", stb
);
3524 if (b
->thread
!= -1)
3526 /* FIXME: This seems to be redundant and lost here; see the
3527 "stop only in" line a little further down. */
3528 ui_out_text (uiout
, " thread ");
3529 ui_out_field_int (uiout
, "thread", b
->thread
);
3532 ui_out_text (uiout
, "\n");
3534 if (frame_id_p (b
->frame_id
))
3537 ui_out_text (uiout
, "\tstop only in stack frame at ");
3538 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3540 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3541 ui_out_text (uiout
, "\n");
3547 ui_out_text (uiout
, "\tstop only if ");
3548 print_expression (b
->cond
, stb
->stream
);
3549 ui_out_field_stream (uiout
, "cond", stb
);
3550 ui_out_text (uiout
, "\n");
3553 if (b
->pending
&& b
->cond_string
)
3556 ui_out_text (uiout
, "\tstop only if ");
3557 ui_out_field_string (uiout
, "cond", b
->cond_string
);
3558 ui_out_text (uiout
, "\n");
3561 if (b
->thread
!= -1)
3563 /* FIXME should make an annotation for this */
3564 ui_out_text (uiout
, "\tstop only in thread ");
3565 ui_out_field_int (uiout
, "thread", b
->thread
);
3566 ui_out_text (uiout
, "\n");
3569 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3571 /* FIXME should make an annotation for this */
3572 if (ep_is_catchpoint (b
))
3573 ui_out_text (uiout
, "\tcatchpoint");
3575 ui_out_text (uiout
, "\tbreakpoint");
3576 ui_out_text (uiout
, " already hit ");
3577 ui_out_field_int (uiout
, "times", b
->hit_count
);
3578 if (b
->hit_count
== 1)
3579 ui_out_text (uiout
, " time\n");
3581 ui_out_text (uiout
, " times\n");
3584 /* Output the count also if it is zero, but only if this is
3585 mi. FIXME: Should have a better test for this. */
3586 if (ui_out_is_mi_like_p (uiout
))
3587 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3588 ui_out_field_int (uiout
, "times", b
->hit_count
);
3590 if (b
->ignore_count
)
3593 ui_out_text (uiout
, "\tignore next ");
3594 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3595 ui_out_text (uiout
, " hits\n");
3598 if ((l
= b
->commands
))
3600 struct cleanup
*script_chain
;
3603 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3604 print_command_lines (uiout
, l
, 4);
3605 do_cleanups (script_chain
);
3607 do_cleanups (bkpt_chain
);
3608 do_cleanups (old_chain
);
3611 struct captured_breakpoint_query_args
3617 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3619 struct captured_breakpoint_query_args
*args
= data
;
3620 struct breakpoint
*b
;
3621 CORE_ADDR dummy_addr
= 0;
3624 if (args
->bnum
== b
->number
)
3626 print_one_breakpoint (b
, &dummy_addr
);
3634 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
, char **error_message
)
3636 struct captured_breakpoint_query_args args
;
3638 /* For the moment we don't trust print_one_breakpoint() to not throw
3640 return catch_exceptions_with_msg (uiout
, do_captured_breakpoint_query
, &args
,
3641 error_message
, RETURN_MASK_ALL
);
3644 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3645 catchpoints, et.al.). */
3648 user_settable_breakpoint (const struct breakpoint
*b
)
3650 return (b
->type
== bp_breakpoint
3651 || b
->type
== bp_catch_load
3652 || b
->type
== bp_catch_unload
3653 || b
->type
== bp_catch_fork
3654 || b
->type
== bp_catch_vfork
3655 || b
->type
== bp_catch_exec
3656 || b
->type
== bp_catch_catch
3657 || b
->type
== bp_catch_throw
3658 || b
->type
== bp_hardware_breakpoint
3659 || b
->type
== bp_watchpoint
3660 || b
->type
== bp_read_watchpoint
3661 || b
->type
== bp_access_watchpoint
3662 || b
->type
== bp_hardware_watchpoint
);
3665 /* Print information on user settable breakpoint (watchpoint, etc)
3666 number BNUM. If BNUM is -1 print all user settable breakpoints.
3667 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3670 breakpoint_1 (int bnum
, int allflag
)
3672 struct breakpoint
*b
;
3673 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3674 int nr_printable_breakpoints
;
3675 struct cleanup
*bkpttbl_chain
;
3677 /* Compute the number of rows in the table. */
3678 nr_printable_breakpoints
= 0;
3681 || bnum
== b
->number
)
3683 if (allflag
|| user_settable_breakpoint (b
))
3684 nr_printable_breakpoints
++;
3689 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3693 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3696 if (nr_printable_breakpoints
> 0)
3697 annotate_breakpoints_headers ();
3698 if (nr_printable_breakpoints
> 0)
3700 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3701 if (nr_printable_breakpoints
> 0)
3703 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3704 if (nr_printable_breakpoints
> 0)
3706 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3707 if (nr_printable_breakpoints
> 0)
3709 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3712 if (nr_printable_breakpoints
> 0)
3714 if (TARGET_ADDR_BIT
<= 32)
3715 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3717 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3719 if (nr_printable_breakpoints
> 0)
3721 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3722 ui_out_table_body (uiout
);
3723 if (nr_printable_breakpoints
> 0)
3724 annotate_breakpoints_table ();
3728 || bnum
== b
->number
)
3730 /* We only print out user settable breakpoints unless the
3732 if (allflag
|| user_settable_breakpoint (b
))
3733 print_one_breakpoint (b
, &last_addr
);
3736 do_cleanups (bkpttbl_chain
);
3738 if (nr_printable_breakpoints
== 0)
3741 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3743 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3748 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3749 that a comparison of an unsigned with -1 is always false. */
3750 if (last_addr
!= (CORE_ADDR
) -1)
3751 set_next_address (last_addr
);
3754 /* FIXME? Should this be moved up so that it is only called when
3755 there have been breakpoints? */
3756 annotate_breakpoints_table_end ();
3760 breakpoints_info (char *bnum_exp
, int from_tty
)
3765 bnum
= parse_and_eval_long (bnum_exp
);
3767 breakpoint_1 (bnum
, 0);
3771 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3776 bnum
= parse_and_eval_long (bnum_exp
);
3778 breakpoint_1 (bnum
, 1);
3781 /* Print a message describing any breakpoints set at PC. */
3784 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3787 struct breakpoint
*b
;
3790 if (b
->loc
->address
== pc
) /* address match / overlay match */
3791 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3796 printf_filtered (_("Note: breakpoint "));
3797 else /* if (others == ???) */
3798 printf_filtered (_("Note: breakpoints "));
3800 if (b
->loc
->address
== pc
) /* address match / overlay match */
3801 if (!b
->pending
&& (!overlay_debugging
|| b
->loc
->section
== section
))
3804 printf_filtered ("%d%s%s ",
3806 ((b
->enable_state
== bp_disabled
||
3807 b
->enable_state
== bp_shlib_disabled
||
3808 b
->enable_state
== bp_call_disabled
)
3810 : b
->enable_state
== bp_permanent
3814 : ((others
== 1) ? " and" : ""));
3816 printf_filtered (_("also set at pc "));
3817 deprecated_print_address_numeric (pc
, 1, gdb_stdout
);
3818 printf_filtered (".\n");
3822 /* Set the default place to put a breakpoint
3823 for the `break' command with no arguments. */
3826 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3829 default_breakpoint_valid
= valid
;
3830 default_breakpoint_address
= addr
;
3831 default_breakpoint_symtab
= symtab
;
3832 default_breakpoint_line
= line
;
3835 /* Return true iff it is meaningful to use the address member of
3836 BPT. For some breakpoint types, the address member is irrelevant
3837 and it makes no sense to attempt to compare it to other addresses
3838 (or use it for any other purpose either).
3840 More specifically, each of the following breakpoint types will always
3841 have a zero valued address and we don't want check_duplicates() to mark
3842 breakpoints of any of these types to be a duplicate of an actual
3843 breakpoint at address zero:
3846 bp_hardware_watchpoint
3848 bp_access_watchpoint
3855 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3857 enum bptype type
= bpt
->type
;
3859 return (type
!= bp_watchpoint
3860 && type
!= bp_hardware_watchpoint
3861 && type
!= bp_read_watchpoint
3862 && type
!= bp_access_watchpoint
3863 && type
!= bp_catch_exec
3864 && type
!= bp_longjmp_resume
3865 && type
!= bp_catch_fork
3866 && type
!= bp_catch_vfork
);
3869 /* Rescan breakpoints at the same address and section as BPT,
3870 marking the first one as "first" and any others as "duplicates".
3871 This is so that the bpt instruction is only inserted once.
3872 If we have a permanent breakpoint at the same place as BPT, make
3873 that one the official one, and the rest as duplicates. */
3876 check_duplicates (struct breakpoint
*bpt
)
3878 struct bp_location
*b
;
3880 struct bp_location
*perm_bp
= 0;
3881 CORE_ADDR address
= bpt
->loc
->address
;
3882 asection
*section
= bpt
->loc
->section
;
3884 if (! breakpoint_address_is_meaningful (bpt
))
3887 ALL_BP_LOCATIONS (b
)
3888 if (b
->owner
->enable_state
!= bp_disabled
3889 && b
->owner
->enable_state
!= bp_shlib_disabled
3890 && !b
->owner
->pending
3891 && b
->owner
->enable_state
!= bp_call_disabled
3892 && b
->address
== address
/* address / overlay match */
3893 && (!overlay_debugging
|| b
->section
== section
)
3894 && breakpoint_address_is_meaningful (b
->owner
))
3896 /* Have we found a permanent breakpoint? */
3897 if (b
->owner
->enable_state
== bp_permanent
)
3904 b
->duplicate
= count
> 1;
3907 /* If we found a permanent breakpoint at this address, go over the
3908 list again and declare all the other breakpoints there to be the
3912 perm_bp
->duplicate
= 0;
3914 /* Permanent breakpoint should always be inserted. */
3915 if (! perm_bp
->inserted
)
3916 internal_error (__FILE__
, __LINE__
,
3917 _("allegedly permanent breakpoint is not "
3918 "actually inserted"));
3920 ALL_BP_LOCATIONS (b
)
3923 if (b
->owner
->enable_state
!= bp_disabled
3924 && b
->owner
->enable_state
!= bp_shlib_disabled
3925 && !b
->owner
->pending
3926 && b
->owner
->enable_state
!= bp_call_disabled
3927 && b
->address
== address
/* address / overlay match */
3928 && (!overlay_debugging
|| b
->section
== section
)
3929 && breakpoint_address_is_meaningful (b
->owner
))
3932 internal_error (__FILE__
, __LINE__
,
3933 _("another breakpoint was inserted on top of "
3934 "a permanent breakpoint"));
3943 breakpoint_adjustment_warning (CORE_ADDR from_addr
, CORE_ADDR to_addr
,
3944 int bnum
, int have_bnum
)
3949 strcpy (astr1
, hex_string_custom ((unsigned long) from_addr
, 8));
3950 strcpy (astr2
, hex_string_custom ((unsigned long) to_addr
, 8));
3952 warning (_("Breakpoint %d address previously adjusted from %s to %s."),
3953 bnum
, astr1
, astr2
);
3955 warning (_("Breakpoint address adjusted from %s to %s."), astr1
, astr2
);
3958 /* Adjust a breakpoint's address to account for architectural constraints
3959 on breakpoint placement. Return the adjusted address. Note: Very
3960 few targets require this kind of adjustment. For most targets,
3961 this function is simply the identity function. */
3964 adjust_breakpoint_address (CORE_ADDR bpaddr
, enum bptype bptype
)
3966 if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3968 /* Very few targets need any kind of breakpoint adjustment. */
3971 else if (bptype
== bp_watchpoint
3972 || bptype
== bp_hardware_watchpoint
3973 || bptype
== bp_read_watchpoint
3974 || bptype
== bp_access_watchpoint
3975 || bptype
== bp_catch_fork
3976 || bptype
== bp_catch_vfork
3977 || bptype
== bp_catch_exec
)
3979 /* Watchpoints and the various bp_catch_* eventpoints should not
3980 have their addresses modified. */
3985 CORE_ADDR adjusted_bpaddr
;
3987 /* Some targets have architectural constraints on the placement
3988 of breakpoint instructions. Obtain the adjusted address. */
3989 adjusted_bpaddr
= gdbarch_adjust_breakpoint_address (current_gdbarch
,
3992 /* An adjusted breakpoint address can significantly alter
3993 a user's expectations. Print a warning if an adjustment
3995 if (adjusted_bpaddr
!= bpaddr
)
3996 breakpoint_adjustment_warning (bpaddr
, adjusted_bpaddr
, 0, 0);
3998 return adjusted_bpaddr
;
4002 /* Allocate a struct bp_location. */
4004 static struct bp_location
*
4005 allocate_bp_location (struct breakpoint
*bpt
, enum bptype bp_type
)
4007 struct bp_location
*loc
, *loc_p
;
4009 loc
= xmalloc (sizeof (struct bp_location
));
4010 memset (loc
, 0, sizeof (*loc
));
4020 case bp_longjmp_resume
:
4021 case bp_step_resume
:
4022 case bp_through_sigtramp
:
4023 case bp_watchpoint_scope
:
4025 case bp_shlib_event
:
4026 case bp_thread_event
:
4027 case bp_overlay_event
:
4029 case bp_catch_unload
:
4030 loc
->loc_type
= bp_loc_software_breakpoint
;
4032 case bp_hardware_breakpoint
:
4033 loc
->loc_type
= bp_loc_hardware_breakpoint
;
4035 case bp_hardware_watchpoint
:
4036 case bp_read_watchpoint
:
4037 case bp_access_watchpoint
:
4038 loc
->loc_type
= bp_loc_hardware_watchpoint
;
4042 case bp_catch_vfork
:
4044 case bp_catch_catch
:
4045 case bp_catch_throw
:
4046 loc
->loc_type
= bp_loc_other
;
4049 internal_error (__FILE__
, __LINE__
, _("unknown breakpoint type"));
4052 /* Add this breakpoint to the end of the chain. */
4054 loc_p
= bp_location_chain
;
4056 bp_location_chain
= loc
;
4060 loc_p
= loc_p
->next
;
4067 /* set_raw_breakpoint() is a low level routine for allocating and
4068 partially initializing a breakpoint of type BPTYPE. The newly
4069 created breakpoint's address, section, source file name, and line
4070 number are provided by SAL. The newly created and partially
4071 initialized breakpoint is added to the breakpoint chain and
4072 is also returned as the value of this function.
4074 It is expected that the caller will complete the initialization of
4075 the newly created breakpoint struct as well as output any status
4076 information regarding the creation of a new breakpoint. In
4077 particular, set_raw_breakpoint() does NOT set the breakpoint
4078 number! Care should be taken to not allow an error() to occur
4079 prior to completing the initialization of the breakpoint. If this
4080 should happen, a bogus breakpoint will be left on the chain. */
4083 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
4085 struct breakpoint
*b
, *b1
;
4087 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
4088 memset (b
, 0, sizeof (*b
));
4089 b
->loc
= allocate_bp_location (b
, bptype
);
4090 b
->loc
->requested_address
= sal
.pc
;
4091 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4093 if (sal
.symtab
== NULL
)
4094 b
->source_file
= NULL
;
4096 b
->source_file
= savestring (sal
.symtab
->filename
,
4097 strlen (sal
.symtab
->filename
));
4098 b
->loc
->section
= sal
.section
;
4100 b
->language
= current_language
->la_language
;
4101 b
->input_radix
= input_radix
;
4103 b
->line_number
= sal
.line
;
4104 b
->enable_state
= bp_enabled
;
4107 b
->ignore_count
= 0;
4109 b
->frame_id
= null_frame_id
;
4110 b
->dll_pathname
= NULL
;
4111 b
->triggered_dll_pathname
= NULL
;
4112 b
->forked_inferior_pid
= 0;
4113 b
->exec_pathname
= NULL
;
4117 /* Add this breakpoint to the end of the chain
4118 so that a list of breakpoints will come out in order
4119 of increasing numbers. */
4121 b1
= breakpoint_chain
;
4123 breakpoint_chain
= b
;
4131 check_duplicates (b
);
4132 breakpoints_changed ();
4138 /* Note that the breakpoint object B describes a permanent breakpoint
4139 instruction, hard-wired into the inferior's code. */
4141 make_breakpoint_permanent (struct breakpoint
*b
)
4143 b
->enable_state
= bp_permanent
;
4145 /* By definition, permanent breakpoints are already present in the code. */
4146 b
->loc
->inserted
= 1;
4149 static struct breakpoint
*
4150 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
4152 static int internal_breakpoint_number
= -1;
4153 struct symtab_and_line sal
;
4154 struct breakpoint
*b
;
4156 init_sal (&sal
); /* initialize to zeroes */
4159 sal
.section
= find_pc_overlay (sal
.pc
);
4161 b
= set_raw_breakpoint (sal
, type
);
4162 b
->number
= internal_breakpoint_number
--;
4163 b
->disposition
= disp_donttouch
;
4170 create_longjmp_breakpoint (char *func_name
)
4172 struct breakpoint
*b
;
4173 struct minimal_symbol
*m
;
4175 if (func_name
== NULL
)
4176 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
4179 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4182 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
4185 b
->enable_state
= bp_disabled
;
4188 b
->addr_string
= xstrdup (func_name
);
4191 /* Call this routine when stepping and nexting to enable a breakpoint
4192 if we do a longjmp(). When we hit that breakpoint, call
4193 set_longjmp_resume_breakpoint() to figure out where we are going. */
4196 enable_longjmp_breakpoint (void)
4198 struct breakpoint
*b
;
4201 if (b
->type
== bp_longjmp
)
4203 b
->enable_state
= bp_enabled
;
4204 check_duplicates (b
);
4209 disable_longjmp_breakpoint (void)
4211 struct breakpoint
*b
;
4214 if (b
->type
== bp_longjmp
4215 || b
->type
== bp_longjmp_resume
)
4217 b
->enable_state
= bp_disabled
;
4218 check_duplicates (b
);
4223 create_overlay_event_breakpoint (char *func_name
)
4225 struct breakpoint
*b
;
4226 struct minimal_symbol
*m
;
4228 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
)) == NULL
)
4231 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4233 b
->addr_string
= xstrdup (func_name
);
4235 if (overlay_debugging
== ovly_auto
)
4237 b
->enable_state
= bp_enabled
;
4238 overlay_events_enabled
= 1;
4242 b
->enable_state
= bp_disabled
;
4243 overlay_events_enabled
= 0;
4248 enable_overlay_breakpoints (void)
4250 struct breakpoint
*b
;
4253 if (b
->type
== bp_overlay_event
)
4255 b
->enable_state
= bp_enabled
;
4256 check_duplicates (b
);
4257 overlay_events_enabled
= 1;
4262 disable_overlay_breakpoints (void)
4264 struct breakpoint
*b
;
4267 if (b
->type
== bp_overlay_event
)
4269 b
->enable_state
= bp_disabled
;
4270 check_duplicates (b
);
4271 overlay_events_enabled
= 0;
4276 create_thread_event_breakpoint (CORE_ADDR address
)
4278 struct breakpoint
*b
;
4280 b
= create_internal_breakpoint (address
, bp_thread_event
);
4282 b
->enable_state
= bp_enabled
;
4283 /* addr_string has to be used or breakpoint_re_set will delete me. */
4284 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4290 remove_thread_event_breakpoints (void)
4292 struct breakpoint
*b
, *temp
;
4294 ALL_BREAKPOINTS_SAFE (b
, temp
)
4295 if (b
->type
== bp_thread_event
)
4296 delete_breakpoint (b
);
4299 struct captured_parse_breakpoint_args
4302 struct symtabs_and_lines
*sals_p
;
4303 char ***addr_string_p
;
4307 struct lang_and_radix
4313 /* Cleanup helper routine to restore the current language and
4316 do_restore_lang_radix_cleanup (void *old
)
4318 struct lang_and_radix
*p
= old
;
4319 set_language (p
->lang
);
4320 input_radix
= p
->radix
;
4323 /* Try and resolve a pending breakpoint. */
4325 resolve_pending_breakpoint (struct breakpoint
*b
)
4327 /* Try and reparse the breakpoint in case the shared library
4329 struct symtabs_and_lines sals
;
4330 struct symtab_and_line pending_sal
;
4331 char **cond_string
= (char **) NULL
;
4332 char *copy_arg
= b
->addr_string
;
4337 struct ui_file
*old_gdb_stderr
;
4338 struct lang_and_radix old_lr
;
4339 struct cleanup
*old_chain
;
4341 /* Set language, input-radix, then reissue breakpoint command.
4342 Ensure the language and input-radix are restored afterwards. */
4343 old_lr
.lang
= current_language
->la_language
;
4344 old_lr
.radix
= input_radix
;
4345 old_chain
= make_cleanup (do_restore_lang_radix_cleanup
, &old_lr
);
4347 set_language (b
->language
);
4348 input_radix
= b
->input_radix
;
4349 rc
= break_command_1 (b
->addr_string
, b
->flag
, b
->from_tty
, b
);
4351 if (rc
== GDB_RC_OK
)
4352 /* Pending breakpoint has been resolved. */
4353 printf_filtered (_("Pending breakpoint \"%s\" resolved\n"), b
->addr_string
);
4355 do_cleanups (old_chain
);
4360 remove_solib_event_breakpoints (void)
4362 struct breakpoint
*b
, *temp
;
4364 ALL_BREAKPOINTS_SAFE (b
, temp
)
4365 if (b
->type
== bp_shlib_event
)
4366 delete_breakpoint (b
);
4370 create_solib_event_breakpoint (CORE_ADDR address
)
4372 struct breakpoint
*b
;
4374 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4378 /* Disable any breakpoints that are on code in shared libraries. Only
4379 apply to enabled breakpoints, disabled ones can just stay disabled. */
4382 disable_breakpoints_in_shlibs (int silent
)
4384 struct breakpoint
*b
;
4385 int disabled_shlib_breaks
= 0;
4387 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4390 if (((b
->type
== bp_breakpoint
) || (b
->type
== bp_hardware_breakpoint
))
4391 && breakpoint_enabled (b
) && !b
->loc
->duplicate
4393 && PC_SOLIB (b
->loc
->address
)
4395 && solib_address (b
->loc
->address
)
4399 b
->enable_state
= bp_shlib_disabled
;
4402 if (!disabled_shlib_breaks
)
4404 target_terminal_ours_for_output ();
4405 warning (_("Temporarily disabling shared library breakpoints:"));
4407 disabled_shlib_breaks
= 1;
4408 warning (_("breakpoint #%d "), b
->number
);
4414 /* Disable any breakpoints that are in in an unloaded shared library. Only
4415 apply to enabled breakpoints, disabled ones can just stay disabled. */
4418 disable_breakpoints_in_unloaded_shlib (struct so_list
*solib
)
4420 struct breakpoint
*b
;
4421 int disabled_shlib_breaks
= 0;
4423 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4426 if ((b
->loc
->loc_type
== bp_loc_hardware_breakpoint
4427 || b
->loc
->loc_type
== bp_loc_software_breakpoint
)
4428 && breakpoint_enabled (b
) && !b
->loc
->duplicate
)
4431 char *so_name
= PC_SOLIB (b
->loc
->address
);
4433 char *so_name
= solib_address (b
->loc
->address
);
4435 if (so_name
&& !strcmp (so_name
, solib
->so_name
))
4437 b
->enable_state
= bp_shlib_disabled
;
4438 /* At this point, we cannot rely on remove_breakpoint
4439 succeeding so we must mark the breakpoint as not inserted
4440 to prevent future errors occurring in remove_breakpoints. */
4441 b
->loc
->inserted
= 0;
4442 if (!disabled_shlib_breaks
)
4444 target_terminal_ours_for_output ();
4445 warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""),
4448 disabled_shlib_breaks
= 1;
4454 /* Try to reenable any breakpoints in shared libraries. */
4456 re_enable_breakpoints_in_shlibs (void)
4458 struct breakpoint
*b
, *tmp
;
4460 ALL_BREAKPOINTS_SAFE (b
, tmp
)
4462 if (b
->enable_state
== bp_shlib_disabled
)
4467 /* Do not reenable the breakpoint if the shared library is
4468 still not mapped in. */
4470 lib
= PC_SOLIB (b
->loc
->address
);
4472 lib
= solib_address (b
->loc
->address
);
4474 if (lib
!= NULL
&& target_read_memory (b
->loc
->address
, buf
, 1) == 0)
4475 b
->enable_state
= bp_enabled
;
4477 else if (b
->pending
&& (b
->enable_state
== bp_enabled
))
4479 if (resolve_pending_breakpoint (b
) == GDB_RC_OK
)
4480 delete_breakpoint (b
);
4486 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4487 char *cond_string
, enum bptype bp_kind
)
4489 struct breakpoint
*b
;
4490 struct symtabs_and_lines sals
;
4491 struct cleanup
*old_chain
;
4492 struct cleanup
*canonical_strings_chain
= NULL
;
4493 char *addr_start
= hookname
;
4494 char *addr_end
= NULL
;
4495 char **canonical
= (char **) NULL
;
4496 int thread
= -1; /* All threads. */
4498 /* Set a breakpoint on the specified hook. */
4499 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
,
4500 0, &canonical
, NULL
);
4501 addr_end
= hookname
;
4503 if (sals
.nelts
== 0)
4505 warning (_("Unable to set a breakpoint on dynamic linker callback.\n"
4506 "Suggest linking with /opt/langtools/lib/end.o.\n"
4507 "GDB will be unable to track shl_load/shl_unload calls."));
4510 if (sals
.nelts
!= 1)
4512 warning (_("Unable to set unique breakpoint on dynamic linker callback.\n"
4513 "GDB will be unable to track shl_load/shl_unload calls."));
4517 /* Make sure that all storage allocated in decode_line_1 gets freed
4518 in case the following errors out. */
4519 old_chain
= make_cleanup (xfree
, sals
.sals
);
4520 if (canonical
!= (char **) NULL
)
4522 make_cleanup (xfree
, canonical
);
4523 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4524 if (canonical
[0] != NULL
)
4525 make_cleanup (xfree
, canonical
[0]);
4528 resolve_sal_pc (&sals
.sals
[0]);
4530 /* Remove the canonical strings from the cleanup, they are needed below. */
4531 if (canonical
!= (char **) NULL
)
4532 discard_cleanups (canonical_strings_chain
);
4534 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4535 set_breakpoint_count (breakpoint_count
+ 1);
4536 b
->number
= breakpoint_count
;
4538 b
->cond_string
= (cond_string
== NULL
) ?
4539 NULL
: savestring (cond_string
, strlen (cond_string
));
4542 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4543 b
->addr_string
= canonical
[0];
4544 else if (addr_start
)
4545 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4547 b
->enable_state
= bp_enabled
;
4548 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4550 if (dll_pathname
== NULL
)
4551 b
->dll_pathname
= NULL
;
4554 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4555 strcpy (b
->dll_pathname
, dll_pathname
);
4559 do_cleanups (old_chain
);
4563 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4564 char *dll_pathname
, char *cond_string
)
4566 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4567 cond_string
, bp_catch_load
);
4571 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4572 char *dll_pathname
, char *cond_string
)
4574 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4575 cond_string
, bp_catch_unload
);
4579 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4580 enum bptype bp_kind
)
4582 struct symtab_and_line sal
;
4583 struct breakpoint
*b
;
4584 int thread
= -1; /* All threads. */
4591 b
= set_raw_breakpoint (sal
, bp_kind
);
4592 set_breakpoint_count (breakpoint_count
+ 1);
4593 b
->number
= breakpoint_count
;
4595 b
->cond_string
= (cond_string
== NULL
) ?
4596 NULL
: savestring (cond_string
, strlen (cond_string
));
4598 b
->addr_string
= NULL
;
4599 b
->enable_state
= bp_enabled
;
4600 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4601 b
->forked_inferior_pid
= 0;
4607 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4609 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4613 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4615 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4619 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4621 struct symtab_and_line sal
;
4622 struct breakpoint
*b
;
4623 int thread
= -1; /* All threads. */
4630 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4631 set_breakpoint_count (breakpoint_count
+ 1);
4632 b
->number
= breakpoint_count
;
4634 b
->cond_string
= (cond_string
== NULL
) ?
4635 NULL
: savestring (cond_string
, strlen (cond_string
));
4637 b
->addr_string
= NULL
;
4638 b
->enable_state
= bp_enabled
;
4639 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4645 hw_breakpoint_used_count (void)
4647 struct breakpoint
*b
;
4652 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4660 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4662 struct breakpoint
*b
;
4665 *other_type_used
= 0;
4668 if (breakpoint_enabled (b
))
4670 if (b
->type
== type
)
4672 else if ((b
->type
== bp_hardware_watchpoint
||
4673 b
->type
== bp_read_watchpoint
||
4674 b
->type
== bp_access_watchpoint
))
4675 *other_type_used
= 1;
4681 /* Call this after hitting the longjmp() breakpoint. Use this to set
4682 a new breakpoint at the target of the jmp_buf.
4684 FIXME - This ought to be done by setting a temporary breakpoint
4685 that gets deleted automatically... */
4688 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4690 struct breakpoint
*b
;
4693 if (b
->type
== bp_longjmp_resume
)
4695 b
->loc
->requested_address
= pc
;
4696 b
->loc
->address
= adjust_breakpoint_address (b
->loc
->requested_address
,
4698 b
->enable_state
= bp_enabled
;
4699 b
->frame_id
= frame_id
;
4700 check_duplicates (b
);
4706 disable_watchpoints_before_interactive_call_start (void)
4708 struct breakpoint
*b
;
4712 if (((b
->type
== bp_watchpoint
)
4713 || (b
->type
== bp_hardware_watchpoint
)
4714 || (b
->type
== bp_read_watchpoint
)
4715 || (b
->type
== bp_access_watchpoint
)
4716 || ep_is_exception_catchpoint (b
))
4717 && breakpoint_enabled (b
))
4719 b
->enable_state
= bp_call_disabled
;
4720 check_duplicates (b
);
4726 enable_watchpoints_after_interactive_call_stop (void)
4728 struct breakpoint
*b
;
4732 if (((b
->type
== bp_watchpoint
)
4733 || (b
->type
== bp_hardware_watchpoint
)
4734 || (b
->type
== bp_read_watchpoint
)
4735 || (b
->type
== bp_access_watchpoint
)
4736 || ep_is_exception_catchpoint (b
))
4737 && (b
->enable_state
== bp_call_disabled
))
4739 b
->enable_state
= bp_enabled
;
4740 check_duplicates (b
);
4746 /* Set a breakpoint that will evaporate an end of command
4747 at address specified by SAL.
4748 Restrict it to frame FRAME if FRAME is nonzero. */
4751 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4754 struct breakpoint
*b
;
4755 b
= set_raw_breakpoint (sal
, type
);
4756 b
->enable_state
= bp_enabled
;
4757 b
->disposition
= disp_donttouch
;
4758 b
->frame_id
= frame_id
;
4760 /* If we're debugging a multi-threaded program, then we
4761 want momentary breakpoints to be active in only a
4762 single thread of control. */
4763 if (in_thread_list (inferior_ptid
))
4764 b
->thread
= pid_to_thread_id (inferior_ptid
);
4770 /* Tell the user we have just set a breakpoint B. */
4773 mention (struct breakpoint
*b
)
4776 struct cleanup
*old_chain
, *ui_out_chain
;
4777 struct ui_stream
*stb
;
4779 stb
= ui_out_stream_new (uiout
);
4780 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4782 /* FIXME: This is misplaced; mention() is called by things (like
4783 hitting a watchpoint) other than breakpoint creation. It should
4784 be possible to clean this up and at the same time replace the
4785 random calls to breakpoint_changed with this hook, as has already
4786 been done for deprecated_delete_breakpoint_hook and so on. */
4787 if (deprecated_create_breakpoint_hook
)
4788 deprecated_create_breakpoint_hook (b
);
4789 breakpoint_create_event (b
->number
);
4791 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4792 b
->ops
->print_mention (b
);
4797 printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b
->number
);
4800 ui_out_text (uiout
, "Watchpoint ");
4801 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4802 ui_out_field_int (uiout
, "number", b
->number
);
4803 ui_out_text (uiout
, ": ");
4804 print_expression (b
->exp
, stb
->stream
);
4805 ui_out_field_stream (uiout
, "exp", stb
);
4806 do_cleanups (ui_out_chain
);
4808 case bp_hardware_watchpoint
:
4809 ui_out_text (uiout
, "Hardware watchpoint ");
4810 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4811 ui_out_field_int (uiout
, "number", b
->number
);
4812 ui_out_text (uiout
, ": ");
4813 print_expression (b
->exp
, stb
->stream
);
4814 ui_out_field_stream (uiout
, "exp", stb
);
4815 do_cleanups (ui_out_chain
);
4817 case bp_read_watchpoint
:
4818 ui_out_text (uiout
, "Hardware read watchpoint ");
4819 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4820 ui_out_field_int (uiout
, "number", b
->number
);
4821 ui_out_text (uiout
, ": ");
4822 print_expression (b
->exp
, stb
->stream
);
4823 ui_out_field_stream (uiout
, "exp", stb
);
4824 do_cleanups (ui_out_chain
);
4826 case bp_access_watchpoint
:
4827 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4828 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4829 ui_out_field_int (uiout
, "number", b
->number
);
4830 ui_out_text (uiout
, ": ");
4831 print_expression (b
->exp
, stb
->stream
);
4832 ui_out_field_stream (uiout
, "exp", stb
);
4833 do_cleanups (ui_out_chain
);
4836 if (ui_out_is_mi_like_p (uiout
))
4841 printf_filtered (_("Breakpoint %d"), b
->number
);
4844 case bp_hardware_breakpoint
:
4845 if (ui_out_is_mi_like_p (uiout
))
4850 printf_filtered (_("Hardware assisted breakpoint %d"), b
->number
);
4854 case bp_catch_unload
:
4855 printf_filtered (_("Catchpoint %d (%s %s)"),
4857 (b
->type
== bp_catch_load
) ? "load" : "unload",
4858 (b
->dll_pathname
!= NULL
) ?
4859 b
->dll_pathname
: "<any library>");
4862 case bp_catch_vfork
:
4863 printf_filtered (_("Catchpoint %d (%s)"),
4865 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4868 printf_filtered (_("Catchpoint %d (exec)"),
4871 case bp_catch_catch
:
4872 case bp_catch_throw
:
4873 printf_filtered (_("Catchpoint %d (%s)"),
4875 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4881 case bp_longjmp_resume
:
4882 case bp_step_resume
:
4883 case bp_through_sigtramp
:
4885 case bp_watchpoint_scope
:
4886 case bp_shlib_event
:
4887 case bp_thread_event
:
4888 case bp_overlay_event
:
4894 /* i18n: cagney/2005-02-11: Below needs to be merged into a
4898 printf_filtered (_(" (%s) pending."), b
->addr_string
);
4902 if (addressprint
|| b
->source_file
== NULL
)
4904 printf_filtered (" at ");
4905 deprecated_print_address_numeric (b
->loc
->address
, 1, gdb_stdout
);
4908 printf_filtered (": file %s, line %d.",
4909 b
->source_file
, b
->line_number
);
4912 do_cleanups (old_chain
);
4913 if (ui_out_is_mi_like_p (uiout
))
4915 printf_filtered ("\n");
4919 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4920 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4921 COND[i] and COND_STRING[i] values.
4923 The parameter PENDING_BP points to a pending breakpoint that is
4924 the basis of the breakpoints currently being created. The pending
4925 breakpoint may contain a separate condition string or commands
4926 that were added after the initial pending breakpoint was created.
4928 NOTE: If the function succeeds, the caller is expected to cleanup
4929 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4930 array contents). If the function fails (error() is called), the
4931 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4932 COND and SALS arrays and each of those arrays contents. */
4935 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4936 struct expression
**cond
, char **cond_string
,
4937 enum bptype type
, enum bpdisp disposition
,
4938 int thread
, int ignore_count
, int from_tty
,
4939 struct breakpoint
*pending_bp
)
4941 if (type
== bp_hardware_breakpoint
)
4943 int i
= hw_breakpoint_used_count ();
4944 int target_resources_ok
=
4945 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4947 if (target_resources_ok
== 0)
4948 error (_("No hardware breakpoint support in the target."));
4949 else if (target_resources_ok
< 0)
4950 error (_("Hardware breakpoints used exceeds limit."));
4953 /* Now set all the breakpoints. */
4956 for (i
= 0; i
< sals
.nelts
; i
++)
4958 struct breakpoint
*b
;
4959 struct symtab_and_line sal
= sals
.sals
[i
];
4962 describe_other_breakpoints (sal
.pc
, sal
.section
);
4964 b
= set_raw_breakpoint (sal
, type
);
4965 set_breakpoint_count (breakpoint_count
+ 1);
4966 b
->number
= breakpoint_count
;
4970 b
->addr_string
= addr_string
[i
];
4972 /* addr_string has to be used or breakpoint_re_set will delete
4974 b
->addr_string
= xstrprintf ("*0x%s", paddr (b
->loc
->address
));
4975 b
->cond_string
= cond_string
[i
];
4976 b
->ignore_count
= ignore_count
;
4977 b
->enable_state
= bp_enabled
;
4978 b
->disposition
= disposition
;
4979 /* If resolving a pending breakpoint, a check must be made to see if
4980 the user has specified a new condition or commands for the
4981 breakpoint. A new condition will override any condition that was
4982 initially specified with the initial breakpoint command. */
4986 if (pending_bp
->cond_string
)
4988 arg
= pending_bp
->cond_string
;
4989 b
->cond_string
= savestring (arg
, strlen (arg
));
4990 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->loc
->address
), 0);
4992 error (_("Junk at end of pending breakpoint condition expression"));
4994 /* If there are commands associated with the breakpoint, they should
4996 if (pending_bp
->commands
)
4997 b
->commands
= copy_command_lines (pending_bp
->commands
);
4999 /* We have to copy over the ignore_count and thread as well. */
5000 b
->ignore_count
= pending_bp
->ignore_count
;
5001 b
->thread
= pending_bp
->thread
;
5008 /* Parse ARG which is assumed to be a SAL specification possibly
5009 followed by conditionals. On return, SALS contains an array of SAL
5010 addresses found. ADDR_STRING contains a vector of (canonical)
5011 address strings. ARG points to the end of the SAL. */
5014 parse_breakpoint_sals (char **address
,
5015 struct symtabs_and_lines
*sals
,
5016 char ***addr_string
,
5019 char *addr_start
= *address
;
5020 *addr_string
= NULL
;
5021 /* If no arg given, or if first arg is 'if ', use the default
5023 if ((*address
) == NULL
5024 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
5026 if (default_breakpoint_valid
)
5028 struct symtab_and_line sal
;
5029 init_sal (&sal
); /* initialize to zeroes */
5030 sals
->sals
= (struct symtab_and_line
*)
5031 xmalloc (sizeof (struct symtab_and_line
));
5032 sal
.pc
= default_breakpoint_address
;
5033 sal
.line
= default_breakpoint_line
;
5034 sal
.symtab
= default_breakpoint_symtab
;
5035 sal
.section
= find_pc_overlay (sal
.pc
);
5036 sals
->sals
[0] = sal
;
5040 error (_("No default breakpoint address now."));
5044 /* Force almost all breakpoints to be in terms of the
5045 current_source_symtab (which is decode_line_1's default). This
5046 should produce the results we want almost all of the time while
5047 leaving default_breakpoint_* alone.
5048 ObjC: However, don't match an Objective-C method name which
5049 may have a '+' or '-' succeeded by a '[' */
5051 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
5053 if (default_breakpoint_valid
5055 || ((strchr ("+-", (*address
)[0]) != NULL
)
5056 && ((*address
)[1] != '['))))
5057 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
5058 default_breakpoint_line
, addr_string
,
5061 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0,
5062 addr_string
, not_found_ptr
);
5064 /* For any SAL that didn't have a canonical string, fill one in. */
5065 if (sals
->nelts
> 0 && *addr_string
== NULL
)
5066 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
5067 if (addr_start
!= (*address
))
5070 for (i
= 0; i
< sals
->nelts
; i
++)
5072 /* Add the string if not present. */
5073 if ((*addr_string
)[i
] == NULL
)
5074 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
5080 /* Convert each SAL into a real PC. Verify that the PC can be
5081 inserted as a breakpoint. If it can't throw an error. */
5084 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
5088 for (i
= 0; i
< sals
->nelts
; i
++)
5090 resolve_sal_pc (&sals
->sals
[i
]);
5092 /* It's possible for the PC to be nonzero, but still an illegal
5093 value on some targets.
5095 For example, on HP-UX if you start gdb, and before running the
5096 inferior you try to set a breakpoint on a shared library function
5097 "foo" where the inferior doesn't call "foo" directly but does
5098 pass its address to another function call, then we do find a
5099 minimal symbol for the "foo", but it's address is invalid.
5100 (Appears to be an index into a table that the loader sets up
5101 when the inferior is run.)
5103 Give the target a chance to bless sals.sals[i].pc before we
5104 try to make a breakpoint for it. */
5105 #ifdef DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE
5106 if (DEPRECATED_PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
5108 if (address
== NULL
)
5109 error (_("Cannot break without a running program."));
5111 error (_("Cannot break on %s without a running program."),
5119 do_captured_parse_breakpoint (struct ui_out
*ui
, void *data
)
5121 struct captured_parse_breakpoint_args
*args
= data
;
5123 parse_breakpoint_sals (args
->arg_p
, args
->sals_p
, args
->addr_string_p
,
5124 args
->not_found_ptr
);
5127 /* Set a breakpoint according to ARG (function, linenum or *address)
5128 flag: first bit : 0 non-temporary, 1 temporary.
5129 second bit : 0 normal breakpoint, 1 hardware breakpoint.
5131 PENDING_BP is non-NULL when this function is being called to resolve
5132 a pending breakpoint. */
5135 break_command_1 (char *arg
, int flag
, int from_tty
, struct breakpoint
*pending_bp
)
5137 struct gdb_exception e
;
5138 int tempflag
, hardwareflag
;
5139 struct symtabs_and_lines sals
;
5140 struct expression
**cond
= 0;
5141 struct symtab_and_line pending_sal
;
5142 char **cond_string
= (char **) NULL
;
5145 char *addr_start
= arg
;
5147 struct cleanup
*old_chain
;
5148 struct cleanup
*breakpoint_chain
= NULL
;
5149 struct captured_parse_breakpoint_args parse_args
;
5153 int ignore_count
= 0;
5156 hardwareflag
= flag
& BP_HARDWAREFLAG
;
5157 tempflag
= flag
& BP_TEMPFLAG
;
5163 parse_args
.arg_p
= &arg
;
5164 parse_args
.sals_p
= &sals
;
5165 parse_args
.addr_string_p
= &addr_string
;
5166 parse_args
.not_found_ptr
= ¬_found
;
5168 e
= catch_exception (uiout
, do_captured_parse_breakpoint
,
5169 &parse_args
, RETURN_MASK_ALL
);
5171 /* If caller is interested in rc value from parse, set value. */
5175 exception_print (gdb_stderr
, e
);
5180 case NOT_FOUND_ERROR
:
5181 /* If called to resolve pending breakpoint, just return
5186 exception_print (gdb_stderr
, e
);
5188 /* If pending breakpoint support is turned off, throw
5191 if (pending_break_support
== AUTO_BOOLEAN_FALSE
)
5192 deprecated_throw_reason (RETURN_ERROR
);
5194 /* If pending breakpoint support is auto query and the user
5195 selects no, then simply return the error code. */
5196 if (pending_break_support
== AUTO_BOOLEAN_AUTO
&&
5197 !nquery ("Make breakpoint pending on future shared library load? "))
5200 /* At this point, either the user was queried about setting
5201 a pending breakpoint and selected yes, or pending
5202 breakpoint behavior is on and thus a pending breakpoint
5203 is defaulted on behalf of the user. */
5204 copy_arg
= xstrdup (addr_start
);
5205 addr_string
= ©_arg
;
5207 sals
.sals
= &pending_sal
;
5212 exception_print (gdb_stderr
, e
);
5220 /* Create a chain of things that always need to be cleaned up. */
5221 old_chain
= make_cleanup (null_cleanup
, 0);
5225 /* Make sure that all storage allocated to SALS gets freed. */
5226 make_cleanup (xfree
, sals
.sals
);
5228 /* Cleanup the addr_string array but not its contents. */
5229 make_cleanup (xfree
, addr_string
);
5232 /* Allocate space for all the cond expressions. */
5233 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5234 make_cleanup (xfree
, cond
);
5236 /* Allocate space for all the cond strings. */
5237 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5238 make_cleanup (xfree
, cond_string
);
5240 /* ----------------------------- SNIP -----------------------------
5241 Anything added to the cleanup chain beyond this point is assumed
5242 to be part of a breakpoint. If the breakpoint create succeeds
5243 then the memory is not reclaimed. */
5244 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5246 /* Mark the contents of the addr_string for cleanup. These go on
5247 the breakpoint_chain and only occure if the breakpoint create
5249 for (i
= 0; i
< sals
.nelts
; i
++)
5251 if (addr_string
[i
] != NULL
)
5252 make_cleanup (xfree
, addr_string
[i
]);
5255 /* Resolve all line numbers to PC's and verify that the addresses
5256 are ok for the target. */
5258 breakpoint_sals_to_pc (&sals
, addr_start
);
5260 /* Verify that condition can be parsed, before setting any
5261 breakpoints. Allocate a separate condition expression for each
5263 thread
= -1; /* No specific thread yet */
5266 for (i
= 0; i
< sals
.nelts
; i
++)
5273 char *cond_start
= NULL
;
5274 char *cond_end
= NULL
;
5275 while (*tok
== ' ' || *tok
== '\t')
5280 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5283 toklen
= end_tok
- tok
;
5285 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5287 tok
= cond_start
= end_tok
+ 1;
5288 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
),
5290 make_cleanup (xfree
, cond
[i
]);
5292 cond_string
[i
] = savestring (cond_start
,
5293 cond_end
- cond_start
);
5294 make_cleanup (xfree
, cond_string
[i
]);
5296 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
5302 thread
= strtol (tok
, &tok
, 0);
5304 error (_("Junk after thread keyword."));
5305 if (!valid_thread_id (thread
))
5306 error (_("Unknown thread %d."), thread
);
5309 error (_("Junk at end of arguments."));
5312 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5313 hardwareflag
? bp_hardware_breakpoint
5315 tempflag
? disp_del
: disp_donttouch
,
5316 thread
, ignore_count
, from_tty
,
5321 struct symtab_and_line sal
;
5322 struct breakpoint
*b
;
5327 make_cleanup (xfree
, copy_arg
);
5329 b
= set_raw_breakpoint (sal
, hardwareflag
? bp_hardware_breakpoint
5331 set_breakpoint_count (breakpoint_count
+ 1);
5332 b
->number
= breakpoint_count
;
5335 b
->addr_string
= *addr_string
;
5336 b
->cond_string
= *cond_string
;
5337 b
->ignore_count
= ignore_count
;
5339 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
5340 b
->from_tty
= from_tty
;
5346 warning (_("Multiple breakpoints were set.\n"
5347 "Use the \"delete\" command to delete unwanted breakpoints."));
5348 /* That's it. Discard the cleanups for data inserted into the
5350 discard_cleanups (breakpoint_chain
);
5351 /* But cleanup everything else. */
5352 do_cleanups (old_chain
);
5357 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
5358 linenum or *address) with COND and IGNORE_COUNT. */
5360 struct captured_breakpoint_args
5371 do_captured_breakpoint (struct ui_out
*uiout
, void *data
)
5373 struct captured_breakpoint_args
*args
= data
;
5374 struct symtabs_and_lines sals
;
5375 struct expression
**cond
;
5376 struct cleanup
*old_chain
;
5377 struct cleanup
*breakpoint_chain
= NULL
;
5384 /* Parse the source and lines spec. Delay check that the expression
5385 didn't contain trailing garbage until after cleanups are in
5389 address_end
= args
->address
;
5391 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
, 0);
5396 /* Create a chain of things at always need to be cleaned up. */
5397 old_chain
= make_cleanup (null_cleanup
, 0);
5399 /* Always have a addr_string array, even if it is empty. */
5400 make_cleanup (xfree
, addr_string
);
5402 /* Make sure that all storage allocated to SALS gets freed. */
5403 make_cleanup (xfree
, sals
.sals
);
5405 /* Allocate space for all the cond expressions. */
5406 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
5407 make_cleanup (xfree
, cond
);
5409 /* Allocate space for all the cond strings. */
5410 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
5411 make_cleanup (xfree
, cond_string
);
5413 /* ----------------------------- SNIP -----------------------------
5414 Anything added to the cleanup chain beyond this point is assumed
5415 to be part of a breakpoint. If the breakpoint create goes
5416 through then that memory is not cleaned up. */
5417 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
5419 /* Mark the contents of the addr_string for cleanup. These go on
5420 the breakpoint_chain and only occure if the breakpoint create
5422 for (i
= 0; i
< sals
.nelts
; i
++)
5424 if (addr_string
[i
] != NULL
)
5425 make_cleanup (xfree
, addr_string
[i
]);
5428 /* Wait until now before checking for garbage at the end of the
5429 address. That way cleanups can take care of freeing any
5431 if (*address_end
!= '\0')
5432 error (_("Garbage %s following breakpoint address"), address_end
);
5434 /* Resolve all line numbers to PC's. */
5435 breakpoint_sals_to_pc (&sals
, args
->address
);
5437 /* Verify that conditions can be parsed, before setting any
5439 for (i
= 0; i
< sals
.nelts
; i
++)
5441 if (args
->condition
!= NULL
)
5443 char *tok
= args
->condition
;
5444 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
5446 error (_("Garbage %s follows condition"), tok
);
5447 make_cleanup (xfree
, cond
[i
]);
5448 cond_string
[i
] = xstrdup (args
->condition
);
5452 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
5453 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
5454 args
->tempflag
? disp_del
: disp_donttouch
,
5455 args
->thread
, args
->ignore_count
, 0/*from-tty*/,
5456 NULL
/*pending_bp*/);
5458 /* That's it. Discard the cleanups for data inserted into the
5460 discard_cleanups (breakpoint_chain
);
5461 /* But cleanup everything else. */
5462 do_cleanups (old_chain
);
5467 gdb_breakpoint (char *address
, char *condition
,
5468 int hardwareflag
, int tempflag
,
5469 int thread
, int ignore_count
,
5470 char **error_message
)
5472 struct captured_breakpoint_args args
;
5473 args
.address
= address
;
5474 args
.condition
= condition
;
5475 args
.hardwareflag
= hardwareflag
;
5476 args
.tempflag
= tempflag
;
5477 args
.thread
= thread
;
5478 args
.ignore_count
= ignore_count
;
5479 return catch_exceptions_with_msg (uiout
, do_captured_breakpoint
, &args
,
5480 error_message
, RETURN_MASK_ALL
);
5484 /* Helper function for break_command_1 and disassemble_command. */
5487 resolve_sal_pc (struct symtab_and_line
*sal
)
5491 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5493 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5494 error (_("No line %d in file \"%s\"."),
5495 sal
->line
, sal
->symtab
->filename
);
5499 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5501 struct blockvector
*bv
;
5506 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5509 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5510 sym
= block_function (b
);
5513 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5514 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5518 /* It really is worthwhile to have the section, so we'll just
5519 have to look harder. This case can be executed if we have
5520 line numbers but no functions (as can happen in assembly
5523 struct minimal_symbol
*msym
;
5525 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5527 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5534 break_command (char *arg
, int from_tty
)
5536 break_command_1 (arg
, 0, from_tty
, NULL
);
5540 tbreak_command (char *arg
, int from_tty
)
5542 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
, NULL
);
5546 hbreak_command (char *arg
, int from_tty
)
5548 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
, NULL
);
5552 thbreak_command (char *arg
, int from_tty
)
5554 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
, NULL
);
5558 stop_command (char *arg
, int from_tty
)
5560 printf_filtered (_("Specify the type of breakpoint to set.\n\
5561 Usage: stop in <function | address>\n\
5562 stop at <line>\n"));
5566 stopin_command (char *arg
, int from_tty
)
5570 if (arg
== (char *) NULL
)
5572 else if (*arg
!= '*')
5577 /* look for a ':'. If this is a line number specification, then
5578 say it is bad, otherwise, it should be an address or
5579 function/method name */
5580 while (*argptr
&& !hasColon
)
5582 hasColon
= (*argptr
== ':');
5587 badInput
= (*argptr
!= ':'); /* Not a class::method */
5589 badInput
= isdigit (*arg
); /* a simple line number */
5593 printf_filtered (_("Usage: stop in <function | address>\n"));
5595 break_command_1 (arg
, 0, from_tty
, NULL
);
5599 stopat_command (char *arg
, int from_tty
)
5603 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5610 /* look for a ':'. If there is a '::' then get out, otherwise
5611 it is probably a line number. */
5612 while (*argptr
&& !hasColon
)
5614 hasColon
= (*argptr
== ':');
5619 badInput
= (*argptr
== ':'); /* we have class::method */
5621 badInput
= !isdigit (*arg
); /* not a line number */
5625 printf_filtered (_("Usage: stop at <line>\n"));
5627 break_command_1 (arg
, 0, from_tty
, NULL
);
5630 /* accessflag: hw_write: watch write,
5631 hw_read: watch read,
5632 hw_access: watch access (read or write) */
5634 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5636 struct breakpoint
*b
;
5637 struct symtab_and_line sal
;
5638 struct expression
*exp
;
5639 struct block
*exp_valid_block
;
5640 struct value
*val
, *mark
;
5641 struct frame_info
*frame
;
5642 struct frame_info
*prev_frame
= NULL
;
5643 char *exp_start
= NULL
;
5644 char *exp_end
= NULL
;
5645 char *tok
, *end_tok
;
5647 char *cond_start
= NULL
;
5648 char *cond_end
= NULL
;
5649 struct expression
*cond
= NULL
;
5650 int i
, other_type_used
, target_resources_ok
= 0;
5651 enum bptype bp_type
;
5654 init_sal (&sal
); /* initialize to zeroes */
5656 /* Parse arguments. */
5657 innermost_block
= NULL
;
5659 exp
= parse_exp_1 (&arg
, 0, 0);
5661 exp_valid_block
= innermost_block
;
5662 mark
= value_mark ();
5663 val
= evaluate_expression (exp
);
5664 release_value (val
);
5665 if (value_lazy (val
))
5666 value_fetch_lazy (val
);
5669 while (*tok
== ' ' || *tok
== '\t')
5673 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5676 toklen
= end_tok
- tok
;
5677 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5679 tok
= cond_start
= end_tok
+ 1;
5680 cond
= parse_exp_1 (&tok
, 0, 0);
5684 error (_("Junk at end of command."));
5686 if (accessflag
== hw_read
)
5687 bp_type
= bp_read_watchpoint
;
5688 else if (accessflag
== hw_access
)
5689 bp_type
= bp_access_watchpoint
;
5691 bp_type
= bp_hardware_watchpoint
;
5693 mem_cnt
= can_use_hardware_watchpoint (val
);
5694 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5695 error (_("Expression cannot be implemented with read/access watchpoint."));
5698 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5699 target_resources_ok
=
5700 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5702 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5703 error (_("Target does not support this type of hardware watchpoint."));
5705 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5706 error (_("Target can only support one kind of HW watchpoint at a time."));
5709 #if defined(HPUXHPPA)
5710 /* On HP-UX if you set a h/w
5711 watchpoint before the "run" command, the inferior dies with a e.g.,
5712 SIGILL once you start it. I initially believed this was due to a
5713 bad interaction between page protection traps and the initial
5714 startup sequence by the dynamic linker.
5716 However, I tried avoiding that by having HP-UX's implementation of
5717 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5718 yet, which forced slow watches before a "run" or "attach", and it
5719 still fails somewhere in the startup code.
5721 Until I figure out what's happening, I'm disallowing watches altogether
5722 before the "run" or "attach" command. We'll tell the user they must
5723 set watches after getting the program started. */
5724 if (!target_has_execution
)
5726 warning (_("can't do that without a running program; try \"break main\"), \"run\" first");
5729 #endif /* HPUXHPPA */
5731 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5732 watchpoint could not be set. */
5733 if (!mem_cnt
|| target_resources_ok
<= 0)
5734 bp_type
= bp_watchpoint
;
5736 /* Now set up the breakpoint. */
5737 b
= set_raw_breakpoint (sal
, bp_type
);
5738 set_breakpoint_count (breakpoint_count
+ 1);
5739 b
->number
= breakpoint_count
;
5740 b
->disposition
= disp_donttouch
;
5742 b
->exp_valid_block
= exp_valid_block
;
5743 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5747 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5751 frame
= block_innermost_frame (exp_valid_block
);
5754 prev_frame
= get_prev_frame (frame
);
5755 b
->watchpoint_frame
= get_frame_id (frame
);
5759 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5762 /* If the expression is "local", then set up a "watchpoint scope"
5763 breakpoint at the point where we've left the scope of the watchpoint
5765 if (innermost_block
)
5769 struct breakpoint
*scope_breakpoint
;
5770 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5771 bp_watchpoint_scope
);
5773 scope_breakpoint
->enable_state
= bp_enabled
;
5775 /* Automatically delete the breakpoint when it hits. */
5776 scope_breakpoint
->disposition
= disp_del
;
5778 /* Only break in the proper frame (help with recursion). */
5779 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5781 /* Set the address at which we will stop. */
5782 scope_breakpoint
->loc
->requested_address
5783 = get_frame_pc (prev_frame
);
5784 scope_breakpoint
->loc
->address
5785 = adjust_breakpoint_address (scope_breakpoint
->loc
->requested_address
,
5786 scope_breakpoint
->type
);
5788 /* The scope breakpoint is related to the watchpoint. We
5789 will need to act on them together. */
5790 b
->related_breakpoint
= scope_breakpoint
;
5793 value_free_to_mark (mark
);
5797 /* Return count of locations need to be watched and can be handled
5798 in hardware. If the watchpoint can not be handled
5799 in hardware return zero. */
5802 can_use_hardware_watchpoint (struct value
*v
)
5804 int found_memory_cnt
= 0;
5805 struct value
*head
= v
;
5807 /* Did the user specifically forbid us to use hardware watchpoints? */
5808 if (!can_use_hw_watchpoints
)
5811 /* Make sure that the value of the expression depends only upon
5812 memory contents, and values computed from them within GDB. If we
5813 find any register references or function calls, we can't use a
5814 hardware watchpoint.
5816 The idea here is that evaluating an expression generates a series
5817 of values, one holding the value of every subexpression. (The
5818 expression a*b+c has five subexpressions: a, b, a*b, c, and
5819 a*b+c.) GDB's values hold almost enough information to establish
5820 the criteria given above --- they identify memory lvalues,
5821 register lvalues, computed values, etcetera. So we can evaluate
5822 the expression, and then scan the chain of values that leaves
5823 behind to decide whether we can detect any possible change to the
5824 expression's final value using only hardware watchpoints.
5826 However, I don't think that the values returned by inferior
5827 function calls are special in any way. So this function may not
5828 notice that an expression involving an inferior function call
5829 can't be watched with hardware watchpoints. FIXME. */
5830 for (; v
; v
= value_next (v
))
5832 if (VALUE_LVAL (v
) == lval_memory
)
5835 /* A lazy memory lvalue is one that GDB never needed to fetch;
5836 we either just used its address (e.g., `a' in `a.b') or
5837 we never needed it at all (e.g., `a' in `a,b'). */
5841 /* Ahh, memory we actually used! Check if we can cover
5842 it with hardware watchpoints. */
5843 struct type
*vtype
= check_typedef (value_type (v
));
5845 /* We only watch structs and arrays if user asked for it
5846 explicitly, never if they just happen to appear in a
5847 middle of some value chain. */
5849 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5850 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5852 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + value_offset (v
);
5853 int len
= TYPE_LENGTH (value_type (v
));
5855 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5862 else if (VALUE_LVAL (v
) != not_lval
5863 && deprecated_value_modifiable (v
) == 0)
5864 return 0; /* ??? What does this represent? */
5865 else if (VALUE_LVAL (v
) == lval_register
)
5866 return 0; /* cannot watch a register with a HW watchpoint */
5869 /* The expression itself looks suitable for using a hardware
5870 watchpoint, but give the target machine a chance to reject it. */
5871 return found_memory_cnt
;
5875 watch_command_wrapper (char *arg
, int from_tty
)
5877 watch_command (arg
, from_tty
);
5881 watch_command (char *arg
, int from_tty
)
5883 watch_command_1 (arg
, hw_write
, from_tty
);
5887 rwatch_command_wrapper (char *arg
, int from_tty
)
5889 rwatch_command (arg
, from_tty
);
5893 rwatch_command (char *arg
, int from_tty
)
5895 watch_command_1 (arg
, hw_read
, from_tty
);
5899 awatch_command_wrapper (char *arg
, int from_tty
)
5901 awatch_command (arg
, from_tty
);
5905 awatch_command (char *arg
, int from_tty
)
5907 watch_command_1 (arg
, hw_access
, from_tty
);
5911 /* Helper routines for the until_command routine in infcmd.c. Here
5912 because it uses the mechanisms of breakpoints. */
5914 /* This function is called by fetch_inferior_event via the
5915 cmd_continuation pointer, to complete the until command. It takes
5916 care of cleaning up the temporary breakpoints set up by the until
5919 until_break_command_continuation (struct continuation_arg
*arg
)
5921 struct cleanup
*cleanups
;
5923 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5924 do_exec_cleanups (cleanups
);
5928 until_break_command (char *arg
, int from_tty
, int anywhere
)
5930 struct symtabs_and_lines sals
;
5931 struct symtab_and_line sal
;
5932 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5933 struct breakpoint
*breakpoint
;
5934 struct cleanup
*old_chain
;
5935 struct continuation_arg
*arg1
;
5938 clear_proceed_status ();
5940 /* Set a breakpoint where the user wants it and at return from
5943 if (default_breakpoint_valid
)
5944 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5945 default_breakpoint_line
, (char ***) NULL
, NULL
);
5947 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5948 0, (char ***) NULL
, NULL
);
5950 if (sals
.nelts
!= 1)
5951 error (_("Couldn't get information on specified line."));
5954 xfree (sals
.sals
); /* malloc'd, so freed */
5957 error (_("Junk at end of arguments."));
5959 resolve_sal_pc (&sal
);
5962 /* If the user told us to continue until a specified location,
5963 we don't specify a frame at which we need to stop. */
5964 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5966 /* Otherwise, specify the current frame, because we want to stop only
5967 at the very same frame. */
5968 breakpoint
= set_momentary_breakpoint (sal
,
5969 get_frame_id (deprecated_selected_frame
),
5972 if (!target_can_async_p ())
5973 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5975 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5977 /* If we are running asynchronously, and the target supports async
5978 execution, we are not waiting for the target to stop, in the call
5979 tp proceed, below. This means that we cannot delete the
5980 brekpoints until the target has actually stopped. The only place
5981 where we get a chance to do that is in fetch_inferior_event, so
5982 we must set things up for that. */
5984 if (target_can_async_p ())
5986 /* In this case the arg for the continuation is just the point
5987 in the exec_cleanups chain from where to start doing
5988 cleanups, because all the continuation does is the cleanups in
5989 the exec_cleanup_chain. */
5991 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5993 arg1
->data
.pointer
= old_chain
;
5995 add_continuation (until_break_command_continuation
, arg1
);
5998 /* Keep within the current frame, or in frames called by the current
6002 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
6003 sal
.pc
= get_frame_pc (prev_frame
);
6004 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
6006 if (!target_can_async_p ())
6007 make_cleanup_delete_breakpoint (breakpoint
);
6009 make_exec_cleanup_delete_breakpoint (breakpoint
);
6012 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
6013 /* Do the cleanups now, anly if we are not running asynchronously,
6014 of if we are, but the target is still synchronous. */
6015 if (!target_can_async_p ())
6016 do_cleanups (old_chain
);
6020 ep_skip_leading_whitespace (char **s
)
6022 if ((s
== NULL
) || (*s
== NULL
))
6024 while (isspace (**s
))
6028 /* This function examines a string, and attempts to find a token
6029 that might be an event name in the leading characters. If a
6030 possible match is found, a pointer to the last character of
6031 the token is returned. Else, NULL is returned. */
6034 ep_find_event_name_end (char *arg
)
6037 char *event_name_end
= NULL
;
6039 /* If we could depend upon the presense of strrpbrk, we'd use that... */
6043 /* We break out of the loop when we find a token delimiter.
6044 Basically, we're looking for alphanumerics and underscores;
6045 anything else delimites the token. */
6048 if (!isalnum (*s
) && (*s
!= '_'))
6054 return event_name_end
;
6058 /* This function attempts to parse an optional "if <cond>" clause
6059 from the arg string. If one is not found, it returns NULL.
6061 Else, it returns a pointer to the condition string. (It does not
6062 attempt to evaluate the string against a particular block.) And,
6063 it updates arg to point to the first character following the parsed
6064 if clause in the arg string. */
6067 ep_parse_optional_if_clause (char **arg
)
6071 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
6074 /* Skip the "if" keyword. */
6077 /* Skip any extra leading whitespace, and record the start of the
6078 condition string. */
6079 ep_skip_leading_whitespace (arg
);
6082 /* Assume that the condition occupies the remainder of the arg string. */
6083 (*arg
) += strlen (cond_string
);
6088 /* This function attempts to parse an optional filename from the arg
6089 string. If one is not found, it returns NULL.
6091 Else, it returns a pointer to the parsed filename. (This function
6092 makes no attempt to verify that a file of that name exists, or is
6093 accessible.) And, it updates arg to point to the first character
6094 following the parsed filename in the arg string.
6096 Note that clients needing to preserve the returned filename for
6097 future access should copy it to their own buffers. */
6099 ep_parse_optional_filename (char **arg
)
6101 static char filename
[1024];
6106 if ((*arg_p
== '\0') || isspace (*arg_p
))
6124 /* Commands to deal with catching events, such as signals, exceptions,
6125 process start/exit, etc. */
6129 catch_fork
, catch_vfork
6134 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
6137 char *cond_string
= NULL
;
6139 ep_skip_leading_whitespace (&arg
);
6141 /* The allowed syntax is:
6143 catch [v]fork if <cond>
6145 First, check if there's an if clause. */
6146 cond_string
= ep_parse_optional_if_clause (&arg
);
6148 if ((*arg
!= '\0') && !isspace (*arg
))
6149 error (_("Junk at end of arguments."));
6151 /* If this target supports it, create a fork or vfork catchpoint
6152 and enable reporting of such events. */
6156 create_fork_event_catchpoint (tempflag
, cond_string
);
6159 create_vfork_event_catchpoint (tempflag
, cond_string
);
6162 error (_("unsupported or unknown fork kind; cannot catch it"));
6168 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
6170 char *cond_string
= NULL
;
6172 ep_skip_leading_whitespace (&arg
);
6174 /* The allowed syntax is:
6176 catch exec if <cond>
6178 First, check if there's an if clause. */
6179 cond_string
= ep_parse_optional_if_clause (&arg
);
6181 if ((*arg
!= '\0') && !isspace (*arg
))
6182 error (_("Junk at end of arguments."));
6184 /* If this target supports it, create an exec catchpoint
6185 and enable reporting of such events. */
6186 create_exec_event_catchpoint (tempflag
, cond_string
);
6190 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6192 char *dll_pathname
= NULL
;
6193 char *cond_string
= NULL
;
6195 ep_skip_leading_whitespace (&arg
);
6197 /* The allowed syntax is:
6199 catch load if <cond>
6200 catch load <filename>
6201 catch load <filename> if <cond>
6203 The user is not allowed to specify the <filename> after an
6206 We'll ignore the pathological case of a file named "if".
6208 First, check if there's an if clause. If so, then there
6209 cannot be a filename. */
6210 cond_string
= ep_parse_optional_if_clause (&arg
);
6212 /* If there was an if clause, then there cannot be a filename.
6213 Else, there might be a filename and an if clause. */
6214 if (cond_string
== NULL
)
6216 dll_pathname
= ep_parse_optional_filename (&arg
);
6217 ep_skip_leading_whitespace (&arg
);
6218 cond_string
= ep_parse_optional_if_clause (&arg
);
6221 if ((*arg
!= '\0') && !isspace (*arg
))
6222 error (_("Junk at end of arguments."));
6224 /* Create a load breakpoint that only triggers when a load of
6225 the specified dll (or any dll, if no pathname was specified)
6227 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6228 dll_pathname
, cond_string
);
6232 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6234 char *dll_pathname
= NULL
;
6235 char *cond_string
= NULL
;
6237 ep_skip_leading_whitespace (&arg
);
6239 /* The allowed syntax is:
6241 catch unload if <cond>
6242 catch unload <filename>
6243 catch unload <filename> if <cond>
6245 The user is not allowed to specify the <filename> after an
6248 We'll ignore the pathological case of a file named "if".
6250 First, check if there's an if clause. If so, then there
6251 cannot be a filename. */
6252 cond_string
= ep_parse_optional_if_clause (&arg
);
6254 /* If there was an if clause, then there cannot be a filename.
6255 Else, there might be a filename and an if clause. */
6256 if (cond_string
== NULL
)
6258 dll_pathname
= ep_parse_optional_filename (&arg
);
6259 ep_skip_leading_whitespace (&arg
);
6260 cond_string
= ep_parse_optional_if_clause (&arg
);
6263 if ((*arg
!= '\0') && !isspace (*arg
))
6264 error (_("Junk at end of arguments."));
6266 /* Create an unload breakpoint that only triggers when an unload of
6267 the specified dll (or any dll, if no pathname was specified)
6269 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6270 dll_pathname
, cond_string
);
6273 /* Commands to deal with catching exceptions. */
6275 /* Set a breakpoint at the specified callback routine for an
6276 exception event callback */
6279 create_exception_catchpoint (int tempflag
, char *cond_string
,
6280 enum exception_event_kind ex_event
,
6281 struct symtab_and_line
*sal
)
6283 struct breakpoint
*b
;
6284 int thread
= -1; /* All threads. */
6287 if (!sal
) /* no exception support? */
6292 case EX_EVENT_THROW
:
6293 bptype
= bp_catch_throw
;
6295 case EX_EVENT_CATCH
:
6296 bptype
= bp_catch_catch
;
6298 default: /* error condition */
6299 error (_("Internal error -- invalid catchpoint kind"));
6302 b
= set_raw_breakpoint (*sal
, bptype
);
6303 set_breakpoint_count (breakpoint_count
+ 1);
6304 b
->number
= breakpoint_count
;
6306 b
->cond_string
= (cond_string
== NULL
) ?
6307 NULL
: savestring (cond_string
, strlen (cond_string
));
6309 b
->addr_string
= NULL
;
6310 b
->enable_state
= bp_enabled
;
6311 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6315 static enum print_stop_action
6316 print_exception_catchpoint (struct breakpoint
*b
)
6318 annotate_catchpoint (b
->number
);
6320 if (strstr (b
->addr_string
, "throw") != NULL
)
6321 printf_filtered (_("\nCatchpoint %d (exception thrown)\n"),
6324 printf_filtered (_("\nCatchpoint %d (exception caught)\n"),
6327 return PRINT_SRC_AND_LOC
;
6331 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6336 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
6339 *last_addr
= b
->loc
->address
;
6340 if (strstr (b
->addr_string
, "throw") != NULL
)
6341 ui_out_field_string (uiout
, "what", "exception throw");
6343 ui_out_field_string (uiout
, "what", "exception catch");
6347 print_mention_exception_catchpoint (struct breakpoint
*b
)
6349 if (strstr (b
->addr_string
, "throw") != NULL
)
6350 printf_filtered (_("Catchpoint %d (throw)"), b
->number
);
6352 printf_filtered (_("Catchpoint %d (catch)"), b
->number
);
6355 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6356 print_exception_catchpoint
,
6357 print_one_exception_catchpoint
,
6358 print_mention_exception_catchpoint
6362 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6363 enum exception_event_kind ex_event
, int from_tty
)
6365 char *trigger_func_name
, *nameptr
;
6366 struct symtabs_and_lines sals
;
6367 struct breakpoint
*b
;
6369 if (ex_event
== EX_EVENT_CATCH
)
6370 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6372 trigger_func_name
= xstrdup ("__cxa_throw");
6374 nameptr
= trigger_func_name
;
6375 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
, NULL
);
6376 if (sals
.nelts
== 0)
6378 xfree (trigger_func_name
);
6382 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6383 set_breakpoint_count (breakpoint_count
+ 1);
6384 b
->number
= breakpoint_count
;
6386 b
->cond_string
= (cond_string
== NULL
) ?
6387 NULL
: savestring (cond_string
, strlen (cond_string
));
6389 b
->addr_string
= trigger_func_name
;
6390 b
->enable_state
= bp_enabled
;
6391 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6392 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6399 /* Deal with "catch catch" and "catch throw" commands */
6402 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6403 int tempflag
, int from_tty
)
6405 char *cond_string
= NULL
;
6406 struct symtab_and_line
*sal
= NULL
;
6408 ep_skip_leading_whitespace (&arg
);
6410 cond_string
= ep_parse_optional_if_clause (&arg
);
6412 if ((*arg
!= '\0') && !isspace (*arg
))
6413 error (_("Junk at end of arguments."));
6415 if ((ex_event
!= EX_EVENT_THROW
) &&
6416 (ex_event
!= EX_EVENT_CATCH
))
6417 error (_("Unsupported or unknown exception event; cannot catch it"));
6419 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6422 /* See if we can find a callback routine */
6423 sal
= target_enable_exception_callback (ex_event
, 1);
6427 /* We have callbacks from the runtime system for exceptions.
6428 Set a breakpoint on the sal found, if no errors */
6429 if (sal
!= (struct symtab_and_line
*) -1)
6430 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6432 return; /* something went wrong with setting up callbacks */
6435 warning (_("Unsupported with this platform/compiler combination."));
6438 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6439 inside a catch_errors */
6442 cover_target_enable_exception_callback (void *arg
)
6444 args_for_catchpoint_enable
*args
= arg
;
6445 struct symtab_and_line
*sal
;
6446 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6449 else if (sal
== (struct symtab_and_line
*) -1)
6452 return 1; /*is valid */
6456 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6459 /* The first argument may be an event name, such as "start" or "load".
6460 If so, then handle it as such. If it doesn't match an event name,
6461 then attempt to interpret it as an exception name. (This latter is
6462 the v4.16-and-earlier GDB meaning of the "catch" command.)
6464 First, try to find the bounds of what might be an event name. */
6465 char *arg1_start
= arg
;
6469 if (arg1_start
== NULL
)
6471 /* Old behaviour was to use pre-v-4.16 syntax */
6472 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6474 /* Now, this is not allowed */
6475 error (_("Catch requires an event name."));
6478 arg1_end
= ep_find_event_name_end (arg1_start
);
6479 if (arg1_end
== NULL
)
6480 error (_("catch requires an event"));
6481 arg1_length
= arg1_end
+ 1 - arg1_start
;
6483 /* Try to match what we found against known event names. */
6484 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6486 error (_("Catch of signal not yet implemented"));
6488 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6490 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6491 tempflag
, from_tty
);
6493 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6495 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6496 tempflag
, from_tty
);
6498 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6500 error (_("Catch of thread_start not yet implemented"));
6502 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6504 error (_("Catch of thread_exit not yet implemented"));
6506 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6508 error (_("Catch of thread_join not yet implemented"));
6510 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6512 error (_("Catch of start not yet implemented"));
6514 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6516 error (_("Catch of exit not yet implemented"));
6518 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6520 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6522 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6524 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6526 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6528 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6530 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6532 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6534 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6536 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6538 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6540 error (_("Catch of stop not yet implemented"));
6543 /* This doesn't appear to be an event name */
6547 /* Pre-v.4.16 behaviour was to treat the argument
6548 as the name of an exception */
6549 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6550 /* Now this is not allowed */
6551 error (_("Unknown event kind specified for catch"));
6556 /* Used by the gui, could be made a worker for other things. */
6559 set_breakpoint_sal (struct symtab_and_line sal
)
6561 struct breakpoint
*b
;
6562 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6563 set_breakpoint_count (breakpoint_count
+ 1);
6564 b
->number
= breakpoint_count
;
6571 catch_command (char *arg
, int from_tty
)
6573 catch_command_1 (arg
, 0, from_tty
);
6578 tcatch_command (char *arg
, int from_tty
)
6580 catch_command_1 (arg
, 1, from_tty
);
6583 /* Delete breakpoints by address or line. */
6586 clear_command (char *arg
, int from_tty
)
6588 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6590 struct symtabs_and_lines sals
;
6591 struct symtab_and_line sal
;
6596 sals
= decode_line_spec (arg
, 1);
6601 sals
.sals
= (struct symtab_and_line
*)
6602 xmalloc (sizeof (struct symtab_and_line
));
6603 make_cleanup (xfree
, sals
.sals
);
6604 init_sal (&sal
); /* initialize to zeroes */
6605 sal
.line
= default_breakpoint_line
;
6606 sal
.symtab
= default_breakpoint_symtab
;
6607 sal
.pc
= default_breakpoint_address
;
6608 if (sal
.symtab
== 0)
6609 error (_("No source file specified."));
6617 /* For each line spec given, delete bps which correspond
6618 to it. Do it in two passes, solely to preserve the current
6619 behavior that from_tty is forced true if we delete more than
6623 for (i
= 0; i
< sals
.nelts
; i
++)
6625 /* If exact pc given, clear bpts at that pc.
6626 If line given (pc == 0), clear all bpts on specified line.
6627 If defaulting, clear all bpts on default line
6630 defaulting sal.pc != 0 tests to do
6635 1 0 <can't happen> */
6640 /* Find all matching breakpoints, remove them from the
6641 breakpoint chain, and add them to the 'found' chain. */
6642 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6644 /* Are we going to delete b? */
6645 if (b
->type
!= bp_none
6646 && b
->type
!= bp_watchpoint
6647 && b
->type
!= bp_hardware_watchpoint
6648 && b
->type
!= bp_read_watchpoint
6649 && b
->type
!= bp_access_watchpoint
6650 /* Not if b is a watchpoint of any sort... */
6651 && (((sal
.pc
&& (b
->loc
->address
== sal
.pc
))
6652 && (!section_is_overlay (b
->loc
->section
)
6653 || b
->loc
->section
== sal
.section
))
6654 /* Yes, if sal.pc matches b (modulo overlays). */
6655 || ((default_match
|| (0 == sal
.pc
))
6656 && b
->source_file
!= NULL
6657 && sal
.symtab
!= NULL
6658 && strcmp (b
->source_file
, sal
.symtab
->filename
) == 0
6659 && b
->line_number
== sal
.line
)))
6660 /* Yes, if sal source file and line matches b. */
6662 /* Remove it from breakpoint_chain... */
6663 if (b
== breakpoint_chain
)
6665 /* b is at the head of the list */
6666 breakpoint_chain
= b
->next
;
6670 prev
->next
= b
->next
;
6672 /* And add it to 'found' chain. */
6678 /* Keep b, and keep a pointer to it. */
6683 /* Now go thru the 'found' chain and delete them. */
6687 error (_("No breakpoint at %s."), arg
);
6689 error (_("No breakpoint at this line."));
6693 from_tty
= 1; /* Always report if deleted more than one */
6697 printf_unfiltered (_("Deleted breakpoint "));
6699 printf_unfiltered (_("Deleted breakpoints "));
6701 breakpoints_changed ();
6705 printf_unfiltered ("%d ", found
->number
);
6707 delete_breakpoint (found
);
6711 putchar_unfiltered ('\n');
6714 /* Delete breakpoint in BS if they are `delete' breakpoints and
6715 all breakpoints that are marked for deletion, whether hit or not.
6716 This is called after any breakpoint is hit, or after errors. */
6719 breakpoint_auto_delete (bpstat bs
)
6721 struct breakpoint
*b
, *temp
;
6723 for (; bs
; bs
= bs
->next
)
6724 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6726 delete_breakpoint (bs
->breakpoint_at
);
6728 ALL_BREAKPOINTS_SAFE (b
, temp
)
6730 if (b
->disposition
== disp_del_at_next_stop
)
6731 delete_breakpoint (b
);
6735 /* Delete a breakpoint and clean up all traces of it in the data
6739 delete_breakpoint (struct breakpoint
*bpt
)
6741 struct breakpoint
*b
;
6743 struct bp_location
*loc
;
6745 gdb_assert (bpt
!= NULL
);
6747 /* Has this bp already been deleted? This can happen because multiple
6748 lists can hold pointers to bp's. bpstat lists are especial culprits.
6750 One example of this happening is a watchpoint's scope bp. When the
6751 scope bp triggers, we notice that the watchpoint is out of scope, and
6752 delete it. We also delete its scope bp. But the scope bp is marked
6753 "auto-deleting", and is already on a bpstat. That bpstat is then
6754 checked for auto-deleting bp's, which are deleted.
6756 A real solution to this problem might involve reference counts in bp's,
6757 and/or giving them pointers back to their referencing bpstat's, and
6758 teaching delete_breakpoint to only free a bp's storage when no more
6759 references were extent. A cheaper bandaid was chosen. */
6760 if (bpt
->type
== bp_none
)
6763 if (deprecated_delete_breakpoint_hook
)
6764 deprecated_delete_breakpoint_hook (bpt
);
6765 breakpoint_delete_event (bpt
->number
);
6767 if (bpt
->loc
->inserted
)
6768 remove_breakpoint (bpt
->loc
, mark_inserted
);
6770 free_valchain (bpt
->loc
);
6772 if (breakpoint_chain
== bpt
)
6773 breakpoint_chain
= bpt
->next
;
6775 if (bp_location_chain
== bpt
->loc
)
6776 bp_location_chain
= bpt
->loc
->next
;
6778 /* If we have callback-style exception catchpoints, don't go through
6779 the adjustments to the C++ runtime library etc. if the inferior
6780 isn't actually running. target_enable_exception_callback for a
6781 null target ops vector gives an undesirable error message, so we
6782 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6783 exceptions are supported in this way, it's OK for now. FIXME */
6784 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6786 /* Format possible error msg */
6787 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6789 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6790 args_for_catchpoint_enable args
;
6791 args
.kind
= bpt
->type
== bp_catch_catch
?
6792 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6794 catch_errors (cover_target_enable_exception_callback
, &args
,
6795 message
, RETURN_MASK_ALL
);
6796 do_cleanups (cleanups
);
6803 b
->next
= bpt
->next
;
6807 ALL_BP_LOCATIONS (loc
)
6808 if (loc
->next
== bpt
->loc
)
6810 loc
->next
= bpt
->loc
->next
;
6814 check_duplicates (bpt
);
6815 /* If this breakpoint was inserted, and there is another breakpoint
6816 at the same address, we need to insert the other breakpoint. */
6817 if (bpt
->loc
->inserted
6818 && bpt
->type
!= bp_hardware_watchpoint
6819 && bpt
->type
!= bp_read_watchpoint
6820 && bpt
->type
!= bp_access_watchpoint
6821 && bpt
->type
!= bp_catch_fork
6822 && bpt
->type
!= bp_catch_vfork
6823 && bpt
->type
!= bp_catch_exec
)
6826 if (b
->loc
->address
== bpt
->loc
->address
6827 && b
->loc
->section
== bpt
->loc
->section
6828 && !b
->loc
->duplicate
6829 && b
->enable_state
!= bp_disabled
6830 && b
->enable_state
!= bp_shlib_disabled
6832 && b
->enable_state
!= bp_call_disabled
)
6836 /* We should never reach this point if there is a permanent
6837 breakpoint at the same address as the one being deleted.
6838 If there is a permanent breakpoint somewhere, it should
6839 always be the only one inserted. */
6840 if (b
->enable_state
== bp_permanent
)
6841 internal_error (__FILE__
, __LINE__
,
6842 _("another breakpoint was inserted on top of "
6843 "a permanent breakpoint"));
6845 memset (&b
->loc
->target_info
, 0, sizeof (b
->loc
->target_info
));
6846 b
->loc
->target_info
.placed_address
= b
->loc
->address
;
6847 if (b
->type
== bp_hardware_breakpoint
)
6848 val
= target_insert_hw_breakpoint (&b
->loc
->target_info
);
6850 val
= target_insert_breakpoint (&b
->loc
->target_info
);
6852 /* If there was an error in the insert, print a message, then stop execution. */
6855 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6856 make_cleanup_ui_file_delete (tmp_error_stream
);
6859 if (b
->type
== bp_hardware_breakpoint
)
6861 fprintf_unfiltered (tmp_error_stream
,
6862 "Cannot insert hardware breakpoint %d.\n"
6863 "You may have requested too many hardware breakpoints.\n",
6868 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6869 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6870 deprecated_print_address_numeric (b
->loc
->address
, 1, tmp_error_stream
);
6871 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6872 safe_strerror (val
));
6875 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6876 target_terminal_ours_for_output ();
6877 error_stream(tmp_error_stream
);
6880 b
->loc
->inserted
= 1;
6884 free_command_lines (&bpt
->commands
);
6887 if (bpt
->cond_string
!= NULL
)
6888 xfree (bpt
->cond_string
);
6889 if (bpt
->addr_string
!= NULL
)
6890 xfree (bpt
->addr_string
);
6891 if (bpt
->exp
!= NULL
)
6893 if (bpt
->exp_string
!= NULL
)
6894 xfree (bpt
->exp_string
);
6895 if (bpt
->val
!= NULL
)
6896 value_free (bpt
->val
);
6897 if (bpt
->source_file
!= NULL
)
6898 xfree (bpt
->source_file
);
6899 if (bpt
->dll_pathname
!= NULL
)
6900 xfree (bpt
->dll_pathname
);
6901 if (bpt
->triggered_dll_pathname
!= NULL
)
6902 xfree (bpt
->triggered_dll_pathname
);
6903 if (bpt
->exec_pathname
!= NULL
)
6904 xfree (bpt
->exec_pathname
);
6906 /* Be sure no bpstat's are pointing at it after it's been freed. */
6907 /* FIXME, how can we find all bpstat's?
6908 We just check stop_bpstat for now. */
6909 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6910 if (bs
->breakpoint_at
== bpt
)
6912 bs
->breakpoint_at
= NULL
;
6914 /* bs->commands will be freed later. */
6916 /* On the chance that someone will soon try again to delete this same
6917 bp, we mark it as deleted before freeing its storage. */
6918 bpt
->type
= bp_none
;
6925 do_delete_breakpoint_cleanup (void *b
)
6927 delete_breakpoint (b
);
6931 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6933 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6937 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6939 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6943 delete_command (char *arg
, int from_tty
)
6945 struct breakpoint
*b
, *temp
;
6951 int breaks_to_delete
= 0;
6953 /* Delete all breakpoints if no argument.
6954 Do not delete internal or call-dummy breakpoints, these
6955 have to be deleted with an explicit breakpoint number argument. */
6958 if (b
->type
!= bp_call_dummy
&&
6959 b
->type
!= bp_shlib_event
&&
6960 b
->type
!= bp_thread_event
&&
6961 b
->type
!= bp_overlay_event
&&
6963 breaks_to_delete
= 1;
6966 /* Ask user only if there are some breakpoints to delete. */
6968 || (breaks_to_delete
&& query (_("Delete all breakpoints? "))))
6970 ALL_BREAKPOINTS_SAFE (b
, temp
)
6972 if (b
->type
!= bp_call_dummy
&&
6973 b
->type
!= bp_shlib_event
&&
6974 b
->type
!= bp_thread_event
&&
6975 b
->type
!= bp_overlay_event
&&
6977 delete_breakpoint (b
);
6982 map_breakpoint_numbers (arg
, delete_breakpoint
);
6985 /* Reset a breakpoint given it's struct breakpoint * BINT.
6986 The value we return ends up being the return value from catch_errors.
6987 Unused in this case. */
6990 breakpoint_re_set_one (void *bint
)
6992 /* get past catch_errs */
6993 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6997 int *not_found_ptr
= NULL
;
6998 struct symtabs_and_lines sals
;
7000 enum enable_state save_enable
;
7005 warning (_("attempted to reset apparently deleted breakpoint #%d?"),
7009 case bp_hardware_breakpoint
:
7011 case bp_catch_unload
:
7012 if (b
->addr_string
== NULL
)
7014 /* Anything without a string can't be re-set. */
7015 delete_breakpoint (b
);
7018 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
7020 ``And a hack it is, although Apple's Darwin version of GDB
7021 contains an almost identical hack to implement a "future
7022 break" command. It seems to work in many real world cases,
7023 but it is easy to come up with a test case where the patch
7024 doesn't help at all.''
7026 ``It seems that the way GDB implements breakpoints - in -
7027 shared - libraries was designed for a.out shared library
7028 systems (SunOS 4) where shared libraries were loaded at a
7029 fixed address in memory. Since ELF shared libraries can (and
7030 will) be loaded at any address in memory, things break.
7031 Fixing this is not trivial. Therefore, I'm not sure whether
7032 we should add this hack to the branch only. I cannot
7033 guarantee that things will be fixed on the trunk in the near
7036 In case we have a problem, disable this breakpoint. We'll
7037 restore its status if we succeed. Don't disable a
7038 shlib_disabled breakpoint though. There's a fair chance we
7039 can't re-set it if the shared library it's in hasn't been
7045 save_enable
= b
->enable_state
;
7046 if (b
->enable_state
!= bp_shlib_disabled
)
7047 b
->enable_state
= bp_disabled
;
7049 /* If resetting a shlib-disabled breakpoint, we don't want to
7050 see an error message if it is not found since we will expect
7051 this to occur until the shared library is finally reloaded.
7052 We accomplish this by giving decode_line_1 a pointer to use
7053 for silent notification that the symbol is not found. */
7054 not_found_ptr
= ¬_found
;
7056 set_language (b
->language
);
7057 input_radix
= b
->input_radix
;
7059 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
,
7061 for (i
= 0; i
< sals
.nelts
; i
++)
7063 resolve_sal_pc (&sals
.sals
[i
]);
7065 /* Reparse conditions, they might contain references to the
7067 if (b
->cond_string
!= NULL
)
7073 /* Avoid re-freeing b->exp if an error during the call
7077 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
7080 /* We need to re-set the breakpoint if the address changes... */
7081 if (b
->loc
->address
!= sals
.sals
[i
].pc
7082 /* ...or new and old breakpoints both have source files, and
7083 the source file name or the line number changes... */
7084 || (b
->source_file
!= NULL
7085 && sals
.sals
[i
].symtab
!= NULL
7086 && (strcmp (b
->source_file
, sals
.sals
[i
].symtab
->filename
) != 0
7087 || b
->line_number
!= sals
.sals
[i
].line
)
7089 /* ...or we switch between having a source file and not having
7091 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
7094 if (b
->source_file
!= NULL
)
7095 xfree (b
->source_file
);
7096 if (sals
.sals
[i
].symtab
== NULL
)
7097 b
->source_file
= NULL
;
7100 savestring (sals
.sals
[i
].symtab
->filename
,
7101 strlen (sals
.sals
[i
].symtab
->filename
));
7102 b
->line_number
= sals
.sals
[i
].line
;
7103 b
->loc
->requested_address
= sals
.sals
[i
].pc
;
7105 = adjust_breakpoint_address (b
->loc
->requested_address
,
7108 /* Used to check for duplicates here, but that can
7109 cause trouble, as it doesn't check for disabled
7114 /* Might be better to do this just once per breakpoint_re_set,
7115 rather than once for every breakpoint. */
7116 breakpoints_changed ();
7118 b
->loc
->section
= sals
.sals
[i
].section
;
7119 b
->enable_state
= save_enable
; /* Restore it, this worked. */
7122 /* Now that this is re-enabled, check_duplicates
7124 check_duplicates (b
);
7131 case bp_hardware_watchpoint
:
7132 case bp_read_watchpoint
:
7133 case bp_access_watchpoint
:
7134 innermost_block
= NULL
;
7135 /* The issue arises of what context to evaluate this in. The
7136 same one as when it was set, but what does that mean when
7137 symbols have been re-read? We could save the filename and
7138 functionname, but if the context is more local than that, the
7139 best we could do would be something like how many levels deep
7140 and which index at that particular level, but that's going to
7141 be less stable than filenames or function names. */
7143 /* So for now, just use a global context. */
7147 /* Avoid re-freeing b->exp if an error during the call to
7148 parse_expression. */
7151 b
->exp
= parse_expression (b
->exp_string
);
7152 b
->exp_valid_block
= innermost_block
;
7153 mark
= value_mark ();
7156 value_free (b
->val
);
7157 /* Avoid re-freeing b->val if an error during the call to
7158 evaluate_expression. */
7161 b
->val
= evaluate_expression (b
->exp
);
7162 release_value (b
->val
);
7163 if (value_lazy (b
->val
) && breakpoint_enabled (b
))
7164 value_fetch_lazy (b
->val
);
7166 if (b
->cond_string
!= NULL
)
7172 /* Avoid re-freeing b->exp if an error during the call
7176 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7178 if (breakpoint_enabled (b
))
7180 value_free_to_mark (mark
);
7182 case bp_catch_catch
:
7183 case bp_catch_throw
:
7185 /* We needn't really do anything to reset these, since the mask
7186 that requests them is unaffected by e.g., new libraries being
7189 case bp_catch_vfork
:
7194 printf_filtered (_("Deleting unknown breakpoint type %d\n"), b
->type
);
7196 /* Delete longjmp and overlay event breakpoints; they will be
7197 reset later by breakpoint_re_set. */
7199 case bp_longjmp_resume
:
7200 case bp_overlay_event
:
7201 delete_breakpoint (b
);
7204 /* This breakpoint is special, it's set up when the inferior
7205 starts and we really don't want to touch it. */
7206 case bp_shlib_event
:
7208 /* Like bp_shlib_event, this breakpoint type is special.
7209 Once it is set up, we do not want to touch it. */
7210 case bp_thread_event
:
7212 /* Keep temporary breakpoints, which can be encountered when we step
7213 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7214 Otherwise these should have been blown away via the cleanup chain
7215 or by breakpoint_init_inferior when we rerun the executable. */
7218 case bp_watchpoint_scope
:
7220 case bp_step_resume
:
7227 /* Re-set all breakpoints after symbols have been re-loaded. */
7229 breakpoint_re_set (void)
7231 struct breakpoint
*b
, *temp
;
7232 enum language save_language
;
7233 int save_input_radix
;
7235 save_language
= current_language
->la_language
;
7236 save_input_radix
= input_radix
;
7237 ALL_BREAKPOINTS_SAFE (b
, temp
)
7239 /* Format possible error msg */
7240 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
7242 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
7243 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7244 do_cleanups (cleanups
);
7246 set_language (save_language
);
7247 input_radix
= save_input_radix
;
7249 if (GET_LONGJMP_TARGET_P ())
7251 create_longjmp_breakpoint ("longjmp");
7252 create_longjmp_breakpoint ("_longjmp");
7253 create_longjmp_breakpoint ("siglongjmp");
7254 create_longjmp_breakpoint ("_siglongjmp");
7255 create_longjmp_breakpoint (NULL
);
7258 create_overlay_event_breakpoint ("_ovly_debug_event");
7261 /* Reset the thread number of this breakpoint:
7263 - If the breakpoint is for all threads, leave it as-is.
7264 - Else, reset it to the current thread for inferior_ptid. */
7266 breakpoint_re_set_thread (struct breakpoint
*b
)
7268 if (b
->thread
!= -1)
7270 if (in_thread_list (inferior_ptid
))
7271 b
->thread
= pid_to_thread_id (inferior_ptid
);
7275 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7276 If from_tty is nonzero, it prints a message to that effect,
7277 which ends with a period (no newline). */
7280 set_ignore_count (int bptnum
, int count
, int from_tty
)
7282 struct breakpoint
*b
;
7288 if (b
->number
== bptnum
)
7290 b
->ignore_count
= count
;
7294 printf_filtered (_("Will stop next time breakpoint %d is reached."),
7296 else if (count
== 1)
7297 printf_filtered (_("Will ignore next crossing of breakpoint %d."),
7300 printf_filtered (_("Will ignore next %d crossings of breakpoint %d."),
7303 breakpoints_changed ();
7304 breakpoint_modify_event (b
->number
);
7308 error (_("No breakpoint number %d."), bptnum
);
7311 /* Clear the ignore counts of all breakpoints. */
7313 breakpoint_clear_ignore_counts (void)
7315 struct breakpoint
*b
;
7318 b
->ignore_count
= 0;
7321 /* Command to set ignore-count of breakpoint N to COUNT. */
7324 ignore_command (char *args
, int from_tty
)
7330 error_no_arg (_("a breakpoint number"));
7332 num
= get_number (&p
);
7334 error (_("bad breakpoint number: '%s'"), args
);
7336 error (_("Second argument (specified ignore-count) is missing."));
7338 set_ignore_count (num
,
7339 longest_to_int (value_as_long (parse_and_eval (p
))),
7342 printf_filtered ("\n");
7345 /* Call FUNCTION on each of the breakpoints
7346 whose numbers are given in ARGS. */
7349 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7354 struct breakpoint
*b
, *tmp
;
7358 error_no_arg (_("one or more breakpoint numbers"));
7365 num
= get_number_or_range (&p1
);
7368 warning (_("bad breakpoint number at or near '%s'"), p
);
7372 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7373 if (b
->number
== num
)
7375 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7378 if (related_breakpoint
)
7379 function (related_breakpoint
);
7383 printf_unfiltered (_("No breakpoint number %d.\n"), num
);
7389 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7390 If from_tty is nonzero, it prints a message to that effect,
7391 which ends with a period (no newline). */
7394 disable_breakpoint (struct breakpoint
*bpt
)
7396 /* Never disable a watchpoint scope breakpoint; we want to
7397 hit them when we leave scope so we can delete both the
7398 watchpoint and its scope breakpoint at that time. */
7399 if (bpt
->type
== bp_watchpoint_scope
)
7402 /* You can't disable permanent breakpoints. */
7403 if (bpt
->enable_state
== bp_permanent
)
7406 bpt
->enable_state
= bp_disabled
;
7408 check_duplicates (bpt
);
7410 if (deprecated_modify_breakpoint_hook
)
7411 deprecated_modify_breakpoint_hook (bpt
);
7412 breakpoint_modify_event (bpt
->number
);
7416 disable_command (char *args
, int from_tty
)
7418 struct breakpoint
*bpt
;
7420 ALL_BREAKPOINTS (bpt
)
7424 warning (_("attempted to disable apparently deleted breakpoint #%d?"),
7429 case bp_catch_unload
:
7431 case bp_catch_vfork
:
7433 case bp_catch_catch
:
7434 case bp_catch_throw
:
7435 case bp_hardware_breakpoint
:
7437 case bp_hardware_watchpoint
:
7438 case bp_read_watchpoint
:
7439 case bp_access_watchpoint
:
7440 disable_breakpoint (bpt
);
7445 map_breakpoint_numbers (args
, disable_breakpoint
);
7449 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7451 int target_resources_ok
, other_type_used
;
7454 if (bpt
->type
== bp_hardware_breakpoint
)
7457 i
= hw_breakpoint_used_count ();
7458 target_resources_ok
=
7459 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7461 if (target_resources_ok
== 0)
7462 error (_("No hardware breakpoint support in the target."));
7463 else if (target_resources_ok
< 0)
7464 error (_("Hardware breakpoints used exceeds limit."));
7469 if (bpt
->enable_state
!= bp_enabled
)
7471 /* When enabling a pending breakpoint, we need to check if the breakpoint
7472 is resolvable since shared libraries could have been loaded
7473 after the breakpoint was disabled. */
7474 breakpoints_changed ();
7475 if (resolve_pending_breakpoint (bpt
) == GDB_RC_OK
)
7477 delete_breakpoint (bpt
);
7480 bpt
->enable_state
= bp_enabled
;
7481 bpt
->disposition
= disposition
;
7484 else /* Not a pending breakpoint. */
7486 if (bpt
->enable_state
!= bp_permanent
)
7487 bpt
->enable_state
= bp_enabled
;
7488 bpt
->disposition
= disposition
;
7489 check_duplicates (bpt
);
7490 breakpoints_changed ();
7492 if (bpt
->type
== bp_watchpoint
||
7493 bpt
->type
== bp_hardware_watchpoint
||
7494 bpt
->type
== bp_read_watchpoint
||
7495 bpt
->type
== bp_access_watchpoint
)
7497 struct frame_id saved_frame_id
;
7499 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
7500 if (bpt
->exp_valid_block
!= NULL
)
7502 struct frame_info
*fr
=
7503 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7506 printf_filtered (_("\
7507 Cannot enable watchpoint %d because the block in which its expression\n\
7508 is valid is not currently in scope.\n"), bpt
->number
);
7509 bpt
->enable_state
= bp_disabled
;
7515 value_free (bpt
->val
);
7516 mark
= value_mark ();
7517 bpt
->val
= evaluate_expression (bpt
->exp
);
7518 release_value (bpt
->val
);
7519 if (value_lazy (bpt
->val
))
7520 value_fetch_lazy (bpt
->val
);
7522 if (bpt
->type
== bp_hardware_watchpoint
||
7523 bpt
->type
== bp_read_watchpoint
||
7524 bpt
->type
== bp_access_watchpoint
)
7526 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7527 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7529 /* Hack around 'unused var' error for some targets here */
7531 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7532 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7533 /* we can consider of type is bp_hardware_watchpoint, convert to
7534 bp_watchpoint in the following condition */
7535 if (target_resources_ok
< 0)
7537 printf_filtered (_("\
7538 Cannot enable watchpoint %d because target watch resources\n\
7539 have been allocated for other watchpoints.\n"), bpt
->number
);
7540 bpt
->enable_state
= bp_disabled
;
7541 value_free_to_mark (mark
);
7546 select_frame (frame_find_by_id (saved_frame_id
));
7547 value_free_to_mark (mark
);
7551 if (deprecated_modify_breakpoint_hook
)
7552 deprecated_modify_breakpoint_hook (bpt
);
7553 breakpoint_modify_event (bpt
->number
);
7557 enable_breakpoint (struct breakpoint
*bpt
)
7559 do_enable_breakpoint (bpt
, bpt
->disposition
);
7562 /* The enable command enables the specified breakpoints (or all defined
7563 breakpoints) so they once again become (or continue to be) effective
7564 in stopping the inferior. */
7567 enable_command (char *args
, int from_tty
)
7569 struct breakpoint
*bpt
;
7571 ALL_BREAKPOINTS (bpt
)
7575 warning (_("attempted to enable apparently deleted breakpoint #%d?"),
7580 case bp_catch_unload
:
7582 case bp_catch_vfork
:
7584 case bp_catch_catch
:
7585 case bp_catch_throw
:
7586 case bp_hardware_breakpoint
:
7588 case bp_hardware_watchpoint
:
7589 case bp_read_watchpoint
:
7590 case bp_access_watchpoint
:
7591 enable_breakpoint (bpt
);
7596 map_breakpoint_numbers (args
, enable_breakpoint
);
7600 enable_once_breakpoint (struct breakpoint
*bpt
)
7602 do_enable_breakpoint (bpt
, disp_disable
);
7606 enable_once_command (char *args
, int from_tty
)
7608 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7612 enable_delete_breakpoint (struct breakpoint
*bpt
)
7614 do_enable_breakpoint (bpt
, disp_del
);
7618 enable_delete_command (char *args
, int from_tty
)
7620 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7624 set_breakpoint_cmd (char *args
, int from_tty
)
7629 show_breakpoint_cmd (char *args
, int from_tty
)
7633 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7635 struct symtabs_and_lines
7636 decode_line_spec_1 (char *string
, int funfirstline
)
7638 struct symtabs_and_lines sals
;
7640 error (_("Empty line specification."));
7641 if (default_breakpoint_valid
)
7642 sals
= decode_line_1 (&string
, funfirstline
,
7643 default_breakpoint_symtab
,
7644 default_breakpoint_line
,
7645 (char ***) NULL
, NULL
);
7647 sals
= decode_line_1 (&string
, funfirstline
,
7648 (struct symtab
*) NULL
, 0, (char ***) NULL
, NULL
);
7650 error (_("Junk at end of line specification: %s"), string
);
7654 /* Create and insert a raw software breakpoint at PC. Return an
7655 identifier, which should be used to remove the breakpoint later.
7656 In general, places which call this should be using something on the
7657 breakpoint chain instead; this function should be eliminated
7661 deprecated_insert_raw_breakpoint (CORE_ADDR pc
)
7663 struct bp_target_info
*bp_tgt
;
7665 bp_tgt
= xmalloc (sizeof (struct bp_target_info
));
7666 memset (bp_tgt
, 0, sizeof (struct bp_target_info
));
7668 bp_tgt
->placed_address
= pc
;
7669 if (target_insert_breakpoint (bp_tgt
) != 0)
7671 /* Could not insert the breakpoint. */
7679 /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */
7682 deprecated_remove_raw_breakpoint (void *bp
)
7684 struct bp_target_info
*bp_tgt
= bp
;
7687 ret
= target_remove_breakpoint (bp_tgt
);
7693 /* One (or perhaps two) breakpoints used for software single stepping. */
7695 static void *single_step_breakpoints
[2];
7697 /* Create and insert a breakpoint for software single step. */
7700 insert_single_step_breakpoint (CORE_ADDR next_pc
)
7704 if (single_step_breakpoints
[0] == NULL
)
7705 bpt_p
= &single_step_breakpoints
[0];
7708 gdb_assert (single_step_breakpoints
[1] == NULL
);
7709 bpt_p
= &single_step_breakpoints
[1];
7712 /* NOTE drow/2006-04-11: A future improvement to this function would be
7713 to only create the breakpoints once, and actually put them on the
7714 breakpoint chain. That would let us use set_raw_breakpoint. We could
7715 adjust the addresses each time they were needed. Doing this requires
7716 corresponding changes elsewhere where single step breakpoints are
7717 handled, however. So, for now, we use this. */
7719 *bpt_p
= deprecated_insert_raw_breakpoint (next_pc
);
7721 error (_("Could not insert single-step breakpoint at 0x%s"),
7722 paddr_nz (next_pc
));
7725 /* Remove and delete any breakpoints used for software single step. */
7728 remove_single_step_breakpoints (void)
7730 gdb_assert (single_step_breakpoints
[0] != NULL
);
7732 /* See insert_single_step_breakpoint for more about this deprecated
7734 deprecated_remove_raw_breakpoint (single_step_breakpoints
[0]);
7735 single_step_breakpoints
[0] = NULL
;
7737 if (single_step_breakpoints
[1] != NULL
)
7739 deprecated_remove_raw_breakpoint (single_step_breakpoints
[1]);
7740 single_step_breakpoints
[1] = NULL
;
7745 /* This help string is used for the break, hbreak, tbreak and thbreak commands.
7746 It is defined as a macro to prevent duplication.
7747 COMMAND should be a string constant containing the name of the command. */
7748 #define BREAK_ARGS_HELP(command) \
7749 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\
7750 LOCATION may be a line number, function name, or \"*\" and an address.\n\
7751 If a line number is specified, break at start of code for that line.\n\
7752 If a function is specified, break at start of code for that function.\n\
7753 If an address is specified, break at that exact address.\n\
7754 With no LOCATION, uses current execution address of selected stack frame.\n\
7755 This is useful for breaking on return to a stack frame.\n\
7757 THREADNUM is the number from \"info threads\".\n\
7758 CONDITION is a boolean expression.\n\
7760 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7762 Do \"help breakpoints\" for info on other commands dealing with breakpoints."
7765 _initialize_breakpoint (void)
7767 static struct cmd_list_element
*breakpoint_set_cmdlist
;
7768 static struct cmd_list_element
*breakpoint_show_cmdlist
;
7769 struct cmd_list_element
*c
;
7771 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib
);
7773 breakpoint_chain
= 0;
7774 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7775 before a breakpoint is set. */
7776 breakpoint_count
= 0;
7778 add_com ("ignore", class_breakpoint
, ignore_command
, _("\
7779 Set ignore-count of breakpoint number N to COUNT.\n\
7780 Usage is `ignore N COUNT'."));
7782 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7784 add_com ("commands", class_breakpoint
, commands_command
, _("\
7785 Set commands to be executed when a breakpoint is hit.\n\
7786 Give breakpoint number as argument after \"commands\".\n\
7787 With no argument, the targeted breakpoint is the last one set.\n\
7788 The commands themselves follow starting on the next line.\n\
7789 Type a line containing \"end\" to indicate the end of them.\n\
7790 Give \"silent\" as the first line to make the breakpoint silent;\n\
7791 then no output is printed when it is hit, except what the commands print."));
7793 add_com ("condition", class_breakpoint
, condition_command
, _("\
7794 Specify breakpoint number N to break only if COND is true.\n\
7795 Usage is `condition N COND', where N is an integer and COND is an\n\
7796 expression to be evaluated whenever breakpoint N is reached."));
7798 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
, _("\
7799 Set a temporary breakpoint.\n\
7800 Like \"break\" except the breakpoint is only temporary,\n\
7801 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7802 by using \"enable delete\" on the breakpoint number.\n\
7804 BREAK_ARGS_HELP ("tbreak")));
7805 set_cmd_completer (c
, location_completer
);
7807 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
, _("\
7808 Set a hardware assisted breakpoint.\n\
7809 Like \"break\" except the breakpoint requires hardware support,\n\
7810 some target hardware may not have this support.\n\
7812 BREAK_ARGS_HELP ("hbreak")));
7813 set_cmd_completer (c
, location_completer
);
7815 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
, _("\
7816 Set a temporary hardware assisted breakpoint.\n\
7817 Like \"hbreak\" except the breakpoint is only temporary,\n\
7818 so it will be deleted when hit.\n\
7820 BREAK_ARGS_HELP ("thbreak")));
7821 set_cmd_completer (c
, location_completer
);
7823 add_prefix_cmd ("enable", class_breakpoint
, enable_command
, _("\
7824 Enable some breakpoints.\n\
7825 Give breakpoint numbers (separated by spaces) as arguments.\n\
7826 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7827 This is used to cancel the effect of the \"disable\" command.\n\
7828 With a subcommand you can enable temporarily."),
7829 &enablelist
, "enable ", 1, &cmdlist
);
7831 add_com ("ab", class_breakpoint
, enable_command
, _("\
7832 Enable some breakpoints.\n\
7833 Give breakpoint numbers (separated by spaces) as arguments.\n\
7834 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7835 This is used to cancel the effect of the \"disable\" command.\n\
7836 With a subcommand you can enable temporarily."));
7838 add_com_alias ("en", "enable", class_breakpoint
, 1);
7840 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
, _("\
7841 Enable some breakpoints.\n\
7842 Give breakpoint numbers (separated by spaces) as arguments.\n\
7843 This is used to cancel the effect of the \"disable\" command.\n\
7844 May be abbreviated to simply \"enable\".\n"),
7845 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7847 add_cmd ("once", no_class
, enable_once_command
, _("\
7848 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7849 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7852 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7853 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7854 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7857 add_cmd ("delete", no_class
, enable_delete_command
, _("\
7858 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7859 If a breakpoint is hit while enabled in this fashion, it is deleted."),
7862 add_cmd ("once", no_class
, enable_once_command
, _("\
7863 Enable breakpoints for one hit. Give breakpoint numbers.\n\
7864 If a breakpoint is hit while enabled in this fashion, it becomes disabled."),
7867 add_prefix_cmd ("disable", class_breakpoint
, disable_command
, _("\
7868 Disable some breakpoints.\n\
7869 Arguments are breakpoint numbers with spaces in between.\n\
7870 To disable all breakpoints, give no argument.\n\
7871 A disabled breakpoint is not forgotten, but has no effect until reenabled."),
7872 &disablelist
, "disable ", 1, &cmdlist
);
7873 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7874 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7876 add_com ("sb", class_breakpoint
, disable_command
, _("\
7877 Disable some breakpoints.\n\
7878 Arguments are breakpoint numbers with spaces in between.\n\
7879 To disable all breakpoints, give no argument.\n\
7880 A disabled breakpoint is not forgotten, but has no effect until reenabled."));
7882 add_cmd ("breakpoints", class_alias
, disable_command
, _("\
7883 Disable some breakpoints.\n\
7884 Arguments are breakpoint numbers with spaces in between.\n\
7885 To disable all breakpoints, give no argument.\n\
7886 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7887 This command may be abbreviated \"disable\"."),
7890 add_prefix_cmd ("delete", class_breakpoint
, delete_command
, _("\
7891 Delete some breakpoints or auto-display expressions.\n\
7892 Arguments are breakpoint numbers with spaces in between.\n\
7893 To delete all breakpoints, give no argument.\n\
7895 Also a prefix command for deletion of other GDB objects.\n\
7896 The \"unset\" command is also an alias for \"delete\"."),
7897 &deletelist
, "delete ", 1, &cmdlist
);
7898 add_com_alias ("d", "delete", class_breakpoint
, 1);
7899 add_com_alias ("del", "delete", class_breakpoint
, 1);
7901 add_com ("db", class_breakpoint
, delete_command
, _("\
7902 Delete some breakpoints.\n\
7903 Arguments are breakpoint numbers with spaces in between.\n\
7904 To delete all breakpoints, give no argument.\n"));
7906 add_cmd ("breakpoints", class_alias
, delete_command
, _("\
7907 Delete some breakpoints or auto-display expressions.\n\
7908 Arguments are breakpoint numbers with spaces in between.\n\
7909 To delete all breakpoints, give no argument.\n\
7910 This command may be abbreviated \"delete\"."),
7913 add_com ("clear", class_breakpoint
, clear_command
, _("\
7914 Clear breakpoint at specified line or function.\n\
7915 Argument may be line number, function name, or \"*\" and an address.\n\
7916 If line number is specified, all breakpoints in that line are cleared.\n\
7917 If function is specified, breakpoints at beginning of function are cleared.\n\
7918 If an address is specified, breakpoints at that address are cleared.\n\
7920 With no argument, clears all breakpoints in the line that the selected frame\n\
7923 See also the \"delete\" command which clears breakpoints by number."));
7925 c
= add_com ("break", class_breakpoint
, break_command
, _("\
7926 Set breakpoint at specified line or function.\n"
7927 BREAK_ARGS_HELP ("break")));
7928 set_cmd_completer (c
, location_completer
);
7930 add_com_alias ("b", "break", class_run
, 1);
7931 add_com_alias ("br", "break", class_run
, 1);
7932 add_com_alias ("bre", "break", class_run
, 1);
7933 add_com_alias ("brea", "break", class_run
, 1);
7937 add_com_alias ("ba", "break", class_breakpoint
, 1);
7938 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7943 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
, _("\
7944 Break in function/address or break at a line in the current file."),
7945 &stoplist
, "stop ", 1, &cmdlist
);
7946 add_cmd ("in", class_breakpoint
, stopin_command
,
7947 _("Break in function or address."), &stoplist
);
7948 add_cmd ("at", class_breakpoint
, stopat_command
,
7949 _("Break at a line in the current file."), &stoplist
);
7950 add_com ("status", class_info
, breakpoints_info
, _("\
7951 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7952 The \"Type\" column indicates one of:\n\
7953 \tbreakpoint - normal breakpoint\n\
7954 \twatchpoint - watchpoint\n\
7955 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7956 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7957 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7958 address and file/line number respectively.\n\
7960 Convenience variable \"$_\" and default examine address for \"x\"\n\
7961 are set to the address of the last breakpoint listed.\n\n\
7962 Convenience variable \"$bpnum\" contains the number of the last\n\
7966 add_info ("breakpoints", breakpoints_info
, _("\
7967 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7968 The \"Type\" column indicates one of:\n\
7969 \tbreakpoint - normal breakpoint\n\
7970 \twatchpoint - watchpoint\n\
7971 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7972 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7973 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7974 address and file/line number respectively.\n\
7976 Convenience variable \"$_\" and default examine address for \"x\"\n\
7977 are set to the address of the last breakpoint listed.\n\n\
7978 Convenience variable \"$bpnum\" contains the number of the last\n\
7982 add_com ("lb", class_breakpoint
, breakpoints_info
, _("\
7983 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7984 The \"Type\" column indicates one of:\n\
7985 \tbreakpoint - normal breakpoint\n\
7986 \twatchpoint - watchpoint\n\
7987 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7988 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7989 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7990 address and file/line number respectively.\n\
7992 Convenience variable \"$_\" and default examine address for \"x\"\n\
7993 are set to the address of the last breakpoint listed.\n\n\
7994 Convenience variable \"$bpnum\" contains the number of the last\n\
7997 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
, _("\
7998 Status of all breakpoints, or breakpoint number NUMBER.\n\
7999 The \"Type\" column indicates one of:\n\
8000 \tbreakpoint - normal breakpoint\n\
8001 \twatchpoint - watchpoint\n\
8002 \tlongjmp - internal breakpoint used to step through longjmp()\n\
8003 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
8004 \tuntil - internal breakpoint used by the \"until\" command\n\
8005 \tfinish - internal breakpoint used by the \"finish\" command\n\
8006 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
8007 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
8008 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
8009 address and file/line number respectively.\n\
8011 Convenience variable \"$_\" and default examine address for \"x\"\n\
8012 are set to the address of the last breakpoint listed.\n\
8014 Convenience variable \"$bpnum\" contains the number of the last\n\
8016 &maintenanceinfolist
);
8018 add_com ("catch", class_breakpoint
, catch_command
, _("\
8019 Set catchpoints to catch events.\n\
8020 Raised signals may be caught:\n\
8021 \tcatch signal - all signals\n\
8022 \tcatch signal <signame> - a particular signal\n\
8023 Raised exceptions may be caught:\n\
8024 \tcatch throw - all exceptions, when thrown\n\
8025 \tcatch throw <exceptname> - a particular exception, when thrown\n\
8026 \tcatch catch - all exceptions, when caught\n\
8027 \tcatch catch <exceptname> - a particular exception, when caught\n\
8028 Thread or process events may be caught:\n\
8029 \tcatch thread_start - any threads, just after creation\n\
8030 \tcatch thread_exit - any threads, just before expiration\n\
8031 \tcatch thread_join - any threads, just after joins\n\
8032 Process events may be caught:\n\
8033 \tcatch start - any processes, just after creation\n\
8034 \tcatch exit - any processes, just before expiration\n\
8035 \tcatch fork - calls to fork()\n\
8036 \tcatch vfork - calls to vfork()\n\
8037 \tcatch exec - calls to exec()\n\
8038 Dynamically-linked library events may be caught:\n\
8039 \tcatch load - loads of any library\n\
8040 \tcatch load <libname> - loads of a particular library\n\
8041 \tcatch unload - unloads of any library\n\
8042 \tcatch unload <libname> - unloads of a particular library\n\
8043 The act of your program's execution stopping may also be caught:\n\
8045 C++ exceptions may be caught:\n\
8046 \tcatch throw - all exceptions, when thrown\n\
8047 \tcatch catch - all exceptions, when caught\n\
8049 Do \"help set follow-fork-mode\" for info on debugging your program\n\
8050 after a fork or vfork is caught.\n\n\
8051 Do \"help breakpoints\" for info on other commands dealing with breakpoints."));
8053 add_com ("tcatch", class_breakpoint
, tcatch_command
, _("\
8054 Set temporary catchpoints to catch events.\n\
8055 Args like \"catch\" command.\n\
8056 Like \"catch\" except the catchpoint is only temporary,\n\
8057 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
8058 by using \"enable delete\" on the catchpoint number."));
8060 c
= add_com ("watch", class_breakpoint
, watch_command
, _("\
8061 Set a watchpoint for an expression.\n\
8062 A watchpoint stops execution of your program whenever the value of\n\
8063 an expression changes."));
8064 set_cmd_completer (c
, location_completer
);
8066 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
, _("\
8067 Set a read watchpoint for an expression.\n\
8068 A watchpoint stops execution of your program whenever the value of\n\
8069 an expression is read."));
8070 set_cmd_completer (c
, location_completer
);
8072 c
= add_com ("awatch", class_breakpoint
, awatch_command
, _("\
8073 Set a watchpoint for an expression.\n\
8074 A watchpoint stops execution of your program whenever the value of\n\
8075 an expression is either read or written."));
8076 set_cmd_completer (c
, location_completer
);
8078 add_info ("watchpoints", breakpoints_info
,
8079 _("Synonym for ``info breakpoints''."));
8082 /* XXX: cagney/2005-02-23: This should be a boolean, and should
8083 respond to changes - contrary to the description. */
8084 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support
,
8085 &can_use_hw_watchpoints
, _("\
8086 Set debugger's willingness to use watchpoint hardware."), _("\
8087 Show debugger's willingness to use watchpoint hardware."), _("\
8088 If zero, gdb will not use hardware for new watchpoints, even if\n\
8089 such is available. (However, any hardware watchpoints that were\n\
8090 created before setting this to nonzero, will continue to use watchpoint\n\
8093 show_can_use_hw_watchpoints
,
8094 &setlist
, &showlist
);
8096 can_use_hw_watchpoints
= 1;
8098 add_prefix_cmd ("breakpoint", class_maintenance
, set_breakpoint_cmd
, _("\
8099 Breakpoint specific settings\n\
8100 Configure various breakpoint-specific variables such as\n\
8101 pending breakpoint behavior"),
8102 &breakpoint_set_cmdlist
, "set breakpoint ",
8103 0/*allow-unknown*/, &setlist
);
8104 add_prefix_cmd ("breakpoint", class_maintenance
, show_breakpoint_cmd
, _("\
8105 Breakpoint specific settings\n\
8106 Configure various breakpoint-specific variables such as\n\
8107 pending breakpoint behavior"),
8108 &breakpoint_show_cmdlist
, "show breakpoint ",
8109 0/*allow-unknown*/, &showlist
);
8111 add_setshow_auto_boolean_cmd ("pending", no_class
,
8112 &pending_break_support
, _("\
8113 Set debugger's behavior regarding pending breakpoints."), _("\
8114 Show debugger's behavior regarding pending breakpoints."), _("\
8115 If on, an unrecognized breakpoint location will cause gdb to create a\n\
8116 pending breakpoint. If off, an unrecognized breakpoint location results in\n\
8117 an error. If auto, an unrecognized breakpoint location results in a\n\
8118 user-query to see if a pending breakpoint should be created."),
8120 show_pending_break_support
,
8121 &breakpoint_set_cmdlist
,
8122 &breakpoint_show_cmdlist
);
8124 pending_break_support
= AUTO_BOOLEAN_AUTO
;