1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
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., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, 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"
53 #include "gdb-events.h"
55 /* Prototypes for local functions. */
57 static void until_break_command_continuation (struct continuation_arg
*arg
);
59 static void catch_command_1 (char *, int, int);
61 static void enable_delete_command (char *, int);
63 static void enable_delete_breakpoint (struct breakpoint
*);
65 static void enable_once_command (char *, int);
67 static void enable_once_breakpoint (struct breakpoint
*);
69 static void disable_command (char *, int);
71 static void enable_command (char *, int);
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
75 static void ignore_command (char *, int);
77 static int breakpoint_re_set_one (void *);
79 static void clear_command (char *, int);
81 static void catch_command (char *, int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value
*);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
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 describe_other_breakpoints (CORE_ADDR
, asection
*);
102 static void breakpoints_info (char *, int);
104 static void breakpoint_1 (int, int);
106 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
108 static int breakpoint_cond_eval (void *);
110 static void cleanup_executing_breakpoints (void *);
112 static void commands_command (char *, int);
114 static void condition_command (char *, int);
116 static int get_number_trailer (char **, int);
118 void set_breakpoint_count (int);
127 static int remove_breakpoint (struct breakpoint
*, insertion_state_t
);
129 static enum print_stop_action
print_it_typical (bpstat
);
131 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
135 enum exception_event_kind kind
;
138 args_for_catchpoint_enable
;
140 static int watchpoint_check (void *);
142 static int cover_target_enable_exception_callback (void *);
144 static void maintenance_info_breakpoints (char *, int);
146 static void create_longjmp_breakpoint (char *);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype
, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
166 static void solib_load_unload_1 (char *hookname
,
169 char *cond_string
, enum bptype bp_kind
);
171 static void create_fork_vfork_event_catchpoint (int tempflag
,
173 enum bptype bp_kind
);
175 static void break_at_finish_at_depth_command_1 (char *arg
,
176 int flag
, int from_tty
);
178 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
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 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
196 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
197 enum exception_event_kind ex_event
,
198 struct symtab_and_line
*sal
);
200 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
201 char *arg
, int tempflag
, int from_tty
);
203 static void tcatch_command (char *arg
, int from_tty
);
205 static void ep_skip_leading_whitespace (char **s
);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints
;
213 void _initialize_breakpoint (void);
215 extern int addressprint
; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands
;
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled
;
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
234 /* True if SHIFT_INST_REGS defined, false otherwise. */
236 int must_shift_inst_regs
=
237 #if defined(SHIFT_INST_REGS)
244 /* True if breakpoint hit counts should be displayed in breakpoint info. */
246 int show_breakpoint_hit_counts
= 1;
248 /* Chain of all breakpoints defined. */
250 struct breakpoint
*breakpoint_chain
;
252 /* Number of last breakpoint made. */
254 int breakpoint_count
;
256 /* Pointer to current exception event record */
257 static struct exception_event_record
*current_exception_event
;
259 /* Indicator of whether exception catchpoints should be nuked
260 between runs of a program */
261 int exception_catchpoints_are_fragile
= 0;
263 /* Indicator of when exception catchpoints set-up should be
264 reinitialized -- e.g. when program is re-run */
265 int exception_support_initialized
= 0;
267 /* This function returns a pointer to the string representation of the
268 pathname of the dynamically-linked library that has just been
271 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
272 or undefined results are guaranteed.
274 This string's contents are only valid immediately after the
275 inferior has stopped in the dynamic linker hook, and becomes
276 invalid as soon as the inferior is continued. Clients should make
277 a copy of this string if they wish to continue the inferior and
278 then access the string. */
280 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
281 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
284 /* This function returns a pointer to the string representation of the
285 pathname of the dynamically-linked library that has just been
288 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
289 TRUE, or undefined results are guaranteed.
291 This string's contents are only valid immediately after the
292 inferior has stopped in the dynamic linker hook, and becomes
293 invalid as soon as the inferior is continued. Clients should make
294 a copy of this string if they wish to continue the inferior and
295 then access the string. */
297 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
298 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
301 /* This function is called by the "catch load" command. It allows the
302 debugger to be notified by the dynamic linker when a specified
303 library file (or any library file, if filename is NULL) is loaded. */
305 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
306 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
307 error ("catch of library loads not yet implemented on this platform")
310 /* This function is called by the "catch unload" command. It allows
311 the debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is
315 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
316 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library unloads not yet implemented on this platform")
320 /* Set breakpoint count to NUM. */
323 set_breakpoint_count (int num
)
325 breakpoint_count
= num
;
326 set_internalvar (lookup_internalvar ("bpnum"),
327 value_from_longest (builtin_type_int
, (LONGEST
) num
));
330 /* Used in run_command to zero the hit count when a new run starts. */
333 clear_breakpoint_hit_counts (void)
335 struct breakpoint
*b
;
341 /* Default address, symtab and line to put a breakpoint at
342 for "break" command with no arg.
343 if default_breakpoint_valid is zero, the other three are
344 not valid, and "break" with no arg is an error.
346 This set by print_stack_frame, which calls set_default_breakpoint. */
348 int default_breakpoint_valid
;
349 CORE_ADDR default_breakpoint_address
;
350 struct symtab
*default_breakpoint_symtab
;
351 int default_breakpoint_line
;
353 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
354 Advance *PP after the string and any trailing whitespace.
356 Currently the string can either be a number or "$" followed by the name
357 of a convenience variable. Making it an expression wouldn't work well
358 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
360 TRAILER is a character which can be found after the number; most
361 commonly this is `-'. If you don't want a trailer, use \0. */
363 get_number_trailer (char **pp
, int trailer
)
365 int retval
= 0; /* default */
369 /* Empty line means refer to the last breakpoint. */
370 return breakpoint_count
;
373 /* Make a copy of the name, so we can null-terminate it
374 to pass to lookup_internalvar(). */
379 while (isalnum (*p
) || *p
== '_')
381 varname
= (char *) alloca (p
- start
+ 1);
382 strncpy (varname
, start
, p
- start
);
383 varname
[p
- start
] = '\0';
384 val
= value_of_internalvar (lookup_internalvar (varname
));
385 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
386 retval
= (int) value_as_long (val
);
389 printf_filtered ("Convenience variable must have integer value.\n");
397 while (*p
>= '0' && *p
<= '9')
400 /* There is no number here. (e.g. "cond a == b"). */
402 /* Skip non-numeric token */
403 while (*p
&& !isspace((int) *p
))
405 /* Return zero, which caller must interpret as error. */
411 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
413 /* Trailing junk: return 0 and let caller print error msg. */
414 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
425 /* Like get_number_trailer, but don't allow a trailer. */
427 get_number (char **pp
)
429 return get_number_trailer (pp
, '\0');
432 /* Parse a number or a range.
433 * A number will be of the form handled by get_number.
434 * A range will be of the form <number1> - <number2>, and
435 * will represent all the integers between number1 and number2,
438 * While processing a range, this fuction is called iteratively;
439 * At each call it will return the next value in the range.
441 * At the beginning of parsing a range, the char pointer PP will
442 * be advanced past <number1> and left pointing at the '-' token.
443 * Subsequent calls will not advance the pointer until the range
444 * is completed. The call that completes the range will advance
445 * pointer PP past <number2>.
449 get_number_or_range (char **pp
)
451 static int last_retval
, end_value
;
452 static char *end_ptr
;
453 static int in_range
= 0;
457 /* Default case: pp is pointing either to a solo number,
458 or to the first number of a range. */
459 last_retval
= get_number_trailer (pp
, '-');
464 /* This is the start of a range (<number1> - <number2>).
465 Skip the '-', parse and remember the second number,
466 and also remember the end of the final token. */
470 while (isspace ((int) *end_ptr
))
471 end_ptr
++; /* skip white space */
472 end_value
= get_number (temp
);
473 if (end_value
< last_retval
)
475 error ("inverted range");
477 else if (end_value
== last_retval
)
479 /* degenerate range (number1 == number2). Advance the
480 token pointer so that the range will be treated as a
489 error ("negative value");
492 /* pp points to the '-' that betokens a range. All
493 number-parsing has already been done. Return the next
494 integer value (one greater than the saved previous value).
495 Do not advance the token pointer 'pp' until the end of range
498 if (++last_retval
== end_value
)
500 /* End of range reached; advance token pointer. */
510 /* condition N EXP -- set break condition of breakpoint N to EXP. */
513 condition_command (char *arg
, int from_tty
)
515 register struct breakpoint
*b
;
520 error_no_arg ("breakpoint number");
523 bnum
= get_number (&p
);
525 error ("Bad breakpoint argument: '%s'", arg
);
528 if (b
->number
== bnum
)
535 if (b
->cond_string
!= NULL
)
536 xfree (b
->cond_string
);
541 b
->cond_string
= NULL
;
543 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
548 /* I don't know if it matters whether this is the string the user
549 typed in or the decompiled expression. */
550 b
->cond_string
= savestring (arg
, strlen (arg
));
551 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
553 error ("Junk at end of expression");
555 breakpoints_changed ();
556 breakpoint_modify_event (b
->number
);
560 error ("No breakpoint number %d.", bnum
);
565 commands_command (char *arg
, int from_tty
)
567 register struct breakpoint
*b
;
570 struct command_line
*l
;
572 /* If we allowed this, we would have problems with when to
573 free the storage, if we change the commands currently
576 if (executing_breakpoint_commands
)
577 error ("Can't use the \"commands\" command among a breakpoint's commands.");
580 bnum
= get_number (&p
);
583 error ("Unexpected extra arguments following breakpoint number.");
586 if (b
->number
== bnum
)
590 "Type commands for when breakpoint %d is hit, one per line.",
592 l
= read_command_lines (tmpbuf
, from_tty
);
593 free_command_lines (&b
->commands
);
595 breakpoints_changed ();
596 breakpoint_modify_event (b
->number
);
599 error ("No breakpoint number %d.", bnum
);
602 /* Like target_read_memory() but if breakpoints are inserted, return
603 the shadow contents instead of the breakpoints themselves.
605 Read "memory data" from whatever target or inferior we have.
606 Returns zero if successful, errno value if not. EIO is used
607 for address out of bounds. If breakpoints are inserted, returns
608 shadow contents, not the breakpoints themselves. From breakpoint.c. */
611 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
614 struct breakpoint
*b
;
615 CORE_ADDR bp_addr
= 0;
618 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
619 /* No breakpoints on this machine. */
620 return target_read_memory (memaddr
, myaddr
, len
);
624 if (b
->type
== bp_none
)
625 warning ("reading through apparently deleted breakpoint #%d?",
628 /* memory breakpoint? */
629 if (b
->type
== bp_watchpoint
630 || b
->type
== bp_hardware_watchpoint
631 || b
->type
== bp_read_watchpoint
632 || b
->type
== bp_access_watchpoint
)
637 /* Addresses and length of the part of the breakpoint that
639 /* XXXX The m68k, sh and h8300 have different local and remote
640 breakpoint values. BREAKPOINT_FROM_PC still manages to
641 correctly determine the breakpoints memory address and size
642 for these targets. */
643 bp_addr
= b
->address
;
645 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
650 if (bp_addr
+ bp_size
<= memaddr
)
651 /* The breakpoint is entirely before the chunk of memory we
654 if (bp_addr
>= memaddr
+ len
)
655 /* The breakpoint is entirely after the chunk of memory we are
658 /* Copy the breakpoint from the shadow contents, and recurse for
659 the things before and after. */
661 /* Offset within shadow_contents. */
664 if (bp_addr
< memaddr
)
666 /* Only copy the second part of the breakpoint. */
667 bp_size
-= memaddr
- bp_addr
;
668 bptoffset
= memaddr
- bp_addr
;
672 if (bp_addr
+ bp_size
> memaddr
+ len
)
674 /* Only copy the first part of the breakpoint. */
675 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
678 memcpy (myaddr
+ bp_addr
- memaddr
,
679 b
->shadow_contents
+ bptoffset
, bp_size
);
681 if (bp_addr
> memaddr
)
683 /* Copy the section of memory before the breakpoint. */
684 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
689 if (bp_addr
+ bp_size
< memaddr
+ len
)
691 /* Copy the section of memory after the breakpoint. */
692 status
= read_memory_nobpt (bp_addr
+ bp_size
,
693 myaddr
+ bp_addr
+ bp_size
- memaddr
,
694 memaddr
+ len
- (bp_addr
+ bp_size
));
701 /* Nothing overlaps. Just call read_memory_noerr. */
702 return target_read_memory (memaddr
, myaddr
, len
);
706 /* A wrapper function for inserting catchpoints. */
708 insert_catchpoint (struct ui_out
*uo
, void *args
)
710 struct breakpoint
*b
= (struct breakpoint
*) args
;
716 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
719 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
722 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
725 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
730 throw_exception (RETURN_ERROR
);
735 /* insert_breakpoints is used when starting or continuing the program.
736 remove_breakpoints is used when the program stops.
737 Both return zero if successful,
738 or an `errno' value if could not write the inferior. */
741 insert_breakpoints (void)
743 register struct breakpoint
*b
, *temp
;
744 int return_val
= 0; /* return success code. */
746 int disabled_breaks
= 0;
747 int hw_breakpoint_error
= 0;
748 #ifdef ONE_PROCESS_WRITETEXT
749 int process_warning
= 0;
752 static char message1
[] = "Error inserting catchpoint %d:\n";
753 static char message
[sizeof (message1
) + 30];
755 struct ui_file
*tmp_error_stream
= mem_fileopen ();
756 make_cleanup_ui_file_delete (tmp_error_stream
);
758 /* Explicitly mark the warning -- this will only be printed if
759 there was an error. */
760 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
762 ALL_BREAKPOINTS_SAFE (b
, temp
)
764 /* Permanent breakpoints cannot be inserted or removed. Disabled
765 breakpoints should not be inserted. */
766 if (b
->enable_state
!= bp_enabled
)
769 if ((b
->type
== bp_watchpoint
770 || b
->type
== bp_hardware_watchpoint
771 || b
->type
== bp_read_watchpoint
772 || b
->type
== bp_access_watchpoint
) && (!b
->val
))
775 val
= evaluate_expression (b
->exp
);
777 if (VALUE_LAZY (val
))
778 value_fetch_lazy (val
);
781 if (b
->type
!= bp_watchpoint
782 && b
->type
!= bp_hardware_watchpoint
783 && b
->type
!= bp_read_watchpoint
784 && b
->type
!= bp_access_watchpoint
785 && b
->type
!= bp_catch_fork
786 && b
->type
!= bp_catch_vfork
787 && b
->type
!= bp_catch_exec
788 && b
->type
!= bp_catch_throw
789 && b
->type
!= bp_catch_catch
793 /* "Normal" instruction breakpoint: either the standard
794 trap-instruction bp (bp_breakpoint), or a
795 bp_hardware_breakpoint. */
797 /* First check to see if we have to handle an overlay. */
798 if (overlay_debugging
== ovly_off
799 || b
->section
== NULL
800 || !(section_is_overlay (b
->section
)))
802 /* No overlay handling: just set the breakpoint. */
804 if (b
->type
== bp_hardware_breakpoint
)
805 val
= target_insert_hw_breakpoint (b
->address
,
808 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
812 /* This breakpoint is in an overlay section.
813 Shall we set a breakpoint at the LMA? */
814 if (!overlay_events_enabled
)
816 /* Yes -- overlay event support is not active,
817 so we must try to set a breakpoint at the LMA.
818 This will not work for a hardware breakpoint. */
819 if (b
->type
== bp_hardware_breakpoint
)
820 warning ("hardware breakpoint %d not supported in overlay!\n",
824 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
826 /* Set a software (trap) breakpoint at the LMA. */
827 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
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 (b
->section
))
837 /* Yes. This overlay section is mapped into memory. */
838 if (b
->type
== bp_hardware_breakpoint
)
839 val
= target_insert_hw_breakpoint (b
->address
,
842 val
= target_insert_breakpoint (b
->address
,
847 /* No. This breakpoint will not be inserted.
848 No error, but do not mark the bp as 'inserted'. */
855 /* Can't set the breakpoint. */
856 #if defined (DISABLE_UNSETTABLE_BREAK)
857 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
859 /* See also: disable_breakpoints_in_shlibs. */
861 b
->enable_state
= bp_shlib_disabled
;
862 if (!disabled_breaks
)
864 fprintf_unfiltered (tmp_error_stream
,
865 "Cannot insert breakpoint %d.\n",
867 fprintf_unfiltered (tmp_error_stream
,
868 "Temporarily disabling shared library breakpoints:\n");
871 fprintf_unfiltered (tmp_error_stream
,
872 "breakpoint #%d\n", b
->number
);
877 #ifdef ONE_PROCESS_WRITETEXT
880 if (b
->type
== bp_hardware_breakpoint
)
882 hw_breakpoint_error
= 1;
883 fprintf_unfiltered (tmp_error_stream
,
884 "Cannot insert hardware breakpoint %d.\n",
889 fprintf_unfiltered (tmp_error_stream
,
890 "Cannot insert breakpoint %d.\n",
892 fprintf_filtered (tmp_error_stream
,
893 "Error accessing memory address ");
894 print_address_numeric (b
->address
, 1, tmp_error_stream
);
895 fprintf_filtered (tmp_error_stream
, ": %s.\n",
896 safe_strerror (val
));
905 return_val
= val
; /* remember failure */
907 else if (ep_is_exception_catchpoint (b
)
912 /* If we get here, we must have a callback mechanism for exception
913 events -- with g++ style embedded label support, we insert
914 ordinary breakpoints and not catchpoints. */
915 /* Format possible error message */
916 sprintf (message
, message1
, b
->number
);
918 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
921 /* Couldn't set breakpoint for some reason */
922 fprintf_unfiltered (tmp_error_stream
,
923 "Cannot insert catchpoint %d; disabling it.\n",
925 fprintf_filtered (tmp_error_stream
,
926 "Error accessing memory address ");
927 print_address_numeric (b
->address
, 1, tmp_error_stream
);
928 fprintf_filtered (tmp_error_stream
, ": %s.\n",
929 safe_strerror (val
));
930 b
->enable_state
= bp_disabled
;
934 /* Bp set, now make sure callbacks are enabled */
936 args_for_catchpoint_enable args
;
937 args
.kind
= b
->type
== bp_catch_catch
?
938 EX_EVENT_CATCH
: EX_EVENT_THROW
;
940 val
= catch_errors (cover_target_enable_exception_callback
,
942 message
, RETURN_MASK_ALL
);
943 if (val
!= 0 && val
!= -1)
947 /* Check if something went wrong; val == 0 can be ignored */
950 /* something went wrong */
951 fprintf_unfiltered (tmp_error_stream
,
952 "Cannot insert catchpoint %d; disabling it.\n",
954 b
->enable_state
= bp_disabled
;
959 return_val
= val
; /* remember failure */
962 else if ((b
->type
== bp_hardware_watchpoint
||
963 b
->type
== bp_read_watchpoint
||
964 b
->type
== bp_access_watchpoint
)
965 && b
->disposition
!= disp_del_at_next_stop
969 struct frame_info
*saved_frame
;
970 int saved_level
, within_current_scope
;
971 struct value
*mark
= value_mark ();
974 /* Save the current frame and level so we can restore it after
975 evaluating the watchpoint expression on its own frame. */
976 saved_frame
= deprecated_selected_frame
;
977 saved_level
= frame_relative_level (deprecated_selected_frame
);
979 /* Determine if the watchpoint is within scope. */
980 if (b
->exp_valid_block
== NULL
)
981 within_current_scope
= 1;
984 struct frame_info
*fi
;
985 fi
= frame_find_by_id (b
->watchpoint_frame
);
986 within_current_scope
= (fi
!= NULL
);
987 if (within_current_scope
)
991 if (within_current_scope
)
993 /* Evaluate the expression and cut the chain of values
994 produced off from the value chain.
996 Make sure the value returned isn't lazy; we use
997 laziness to determine what memory GDB actually needed
998 in order to compute the value of the expression. */
999 v
= evaluate_expression (b
->exp
);
1001 value_release_to_mark (mark
);
1006 /* Look at each value on the value chain. */
1007 for (; v
; v
= v
->next
)
1009 /* If it's a memory location, and GDB actually needed
1010 its contents to evaluate the expression, then we
1012 if (VALUE_LVAL (v
) == lval_memory
1013 && ! VALUE_LAZY (v
))
1015 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1017 /* We only watch structs and arrays if user asked
1018 for it explicitly, never if they just happen to
1019 appear in the middle of some value chain. */
1020 if (v
== b
->val_chain
1021 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1022 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1027 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1028 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1030 if (b
->type
== bp_read_watchpoint
)
1032 else if (b
->type
== bp_access_watchpoint
)
1035 val
= target_insert_watchpoint (addr
, len
, type
);
1038 /* Don't exit the loop, try to insert
1039 every value on the value chain. That's
1040 because we will be removing all the
1041 watches below, and removing a
1042 watchpoint we didn't insert could have
1050 /* Failure to insert a watchpoint on any memory value in the
1051 value chain brings us here. */
1054 remove_breakpoint (b
, mark_uninserted
);
1055 hw_breakpoint_error
= 1;
1056 fprintf_unfiltered (tmp_error_stream
,
1057 "Could not insert hardware watchpoint %d.\n",
1064 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
1065 printf_filtered ("because the program has left the block \n");
1066 printf_filtered ("in which its expression is valid.\n");
1067 if (b
->related_breakpoint
)
1068 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1069 b
->disposition
= disp_del_at_next_stop
;
1072 /* Restore the frame and level. */
1073 if ((saved_frame
!= deprecated_selected_frame
) ||
1074 (saved_level
!= frame_relative_level (deprecated_selected_frame
)))
1075 select_frame (saved_frame
);
1078 return_val
= val
; /* remember failure */
1080 else if ((b
->type
== bp_catch_fork
1081 || b
->type
== bp_catch_vfork
1082 || b
->type
== bp_catch_exec
)
1088 sprintf (prefix
, "warning: inserting catchpoint %d: ", b
->number
);
1089 val
= catch_exceptions (uiout
, insert_catchpoint
, b
, prefix
,
1092 b
->enable_state
= bp_disabled
;
1100 /* If a hardware breakpoint or watchpoint was inserted, add a
1101 message about possibly exhausted resources. */
1102 if (hw_breakpoint_error
)
1104 fprintf_unfiltered (tmp_error_stream
,
1105 "Could not insert hardware breakpoints:\n\
1106 You may have requested too many hardware breakpoints/watchpoints.\n");
1108 #ifdef ONE_PROCESS_WRITETEXT
1109 if (process_warning
)
1110 fprintf_unfiltered (tmp_error_stream
,
1111 "The same program may be running in another process.");
1113 target_terminal_ours_for_output ();
1114 error_stream (tmp_error_stream
);
1120 remove_breakpoints (void)
1122 register struct breakpoint
*b
;
1129 val
= remove_breakpoint (b
, mark_uninserted
);
1138 remove_hw_watchpoints (void)
1140 register struct breakpoint
*b
;
1146 && (b
->type
== bp_hardware_watchpoint
1147 || b
->type
== bp_read_watchpoint
1148 || b
->type
== bp_access_watchpoint
))
1150 val
= remove_breakpoint (b
, mark_uninserted
);
1159 reattach_breakpoints (int pid
)
1161 register struct breakpoint
*b
;
1163 struct cleanup
*old_chain
= save_inferior_ptid ();
1165 /* Set inferior_ptid; remove_breakpoint uses this global. */
1166 inferior_ptid
= pid_to_ptid (pid
);
1171 remove_breakpoint (b
, mark_inserted
);
1172 if (b
->type
== bp_hardware_breakpoint
)
1173 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1175 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1178 do_cleanups (old_chain
);
1183 do_cleanups (old_chain
);
1188 update_breakpoints_after_exec (void)
1190 struct breakpoint
*b
;
1191 struct breakpoint
*temp
;
1193 /* Doing this first prevents the badness of having delete_breakpoint()
1194 write a breakpoint's current "shadow contents" to lift the bp. That
1195 shadow is NOT valid after an exec()! */
1196 mark_breakpoints_out ();
1198 ALL_BREAKPOINTS_SAFE (b
, temp
)
1200 /* Solib breakpoints must be explicitly reset after an exec(). */
1201 if (b
->type
== bp_shlib_event
)
1203 delete_breakpoint (b
);
1207 /* Thread event breakpoints must be set anew after an exec(),
1208 as must overlay event breakpoints. */
1209 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1211 delete_breakpoint (b
);
1215 /* Step-resume breakpoints are meaningless after an exec(). */
1216 if (b
->type
== bp_step_resume
)
1218 delete_breakpoint (b
);
1222 /* Ditto the sigtramp handler breakpoints. */
1223 if (b
->type
== bp_through_sigtramp
)
1225 delete_breakpoint (b
);
1229 /* Ditto the exception-handling catchpoints. */
1230 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1232 delete_breakpoint (b
);
1236 /* Don't delete an exec catchpoint, because else the inferior
1237 won't stop when it ought!
1239 Similarly, we probably ought to keep vfork catchpoints, 'cause
1240 on this target, we may not be able to stop when the vfork is
1241 seen, but only when the subsequent exec is seen. (And because
1242 deleting fork catchpoints here but not vfork catchpoints will
1243 seem mysterious to users, keep those too.)
1245 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1246 target address field, if any, is sufficient to have it be reset
1247 automagically. Certainly on HP-UX that's true.
1249 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1250 valid code address on some platforms (like the OBSOLETE mn10200
1251 and mn10300 simulators). We shouldn't assign any special
1252 interpretation to a breakpoint with a zero address. And in
1253 fact, GDB doesn't --- I can't see what that comment above is
1254 talking about. As far as I can tell, setting the address of a
1255 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1256 is meaningless, since those are implemented with HP-UX kernel
1257 hackery, not by storing breakpoint instructions somewhere. */
1258 if ((b
->type
== bp_catch_exec
) ||
1259 (b
->type
== bp_catch_vfork
) ||
1260 (b
->type
== bp_catch_fork
))
1262 b
->address
= (CORE_ADDR
) NULL
;
1266 /* bp_finish is a special case. The only way we ought to be able
1267 to see one of these when an exec() has happened, is if the user
1268 caught a vfork, and then said "finish". Ordinarily a finish just
1269 carries them to the call-site of the current callee, by setting
1270 a temporary bp there and resuming. But in this case, the finish
1271 will carry them entirely through the vfork & exec.
1273 We don't want to allow a bp_finish to remain inserted now. But
1274 we can't safely delete it, 'cause finish_command has a handle to
1275 the bp on a bpstat, and will later want to delete it. There's a
1276 chance (and I've seen it happen) that if we delete the bp_finish
1277 here, that its storage will get reused by the time finish_command
1278 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1279 We really must allow finish_command to delete a bp_finish.
1281 In the absense of a general solution for the "how do we know
1282 it's safe to delete something others may have handles to?"
1283 problem, what we'll do here is just uninsert the bp_finish, and
1284 let finish_command delete it.
1286 (We know the bp_finish is "doomed" in the sense that it's
1287 momentary, and will be deleted as soon as finish_command sees
1288 the inferior stopped. So it doesn't matter that the bp's
1289 address is probably bogus in the new a.out, unlike e.g., the
1290 solib breakpoints.) */
1292 if (b
->type
== bp_finish
)
1297 /* Without a symbolic address, we have little hope of the
1298 pre-exec() address meaning the same thing in the post-exec()
1300 if (b
->addr_string
== NULL
)
1302 delete_breakpoint (b
);
1306 /* If this breakpoint has survived the above battery of checks, then
1307 it must have a symbolic address. Be sure that it gets reevaluated
1308 to a target address, rather than reusing the old evaluation.
1310 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1311 for bp_catch_exec and friends, I'm pretty sure this is entirely
1312 unnecessary. A call to breakpoint_re_set_one always recomputes
1313 the breakpoint's address from scratch, or deletes it if it can't.
1314 So I think this assignment could be deleted without effect. */
1315 b
->address
= (CORE_ADDR
) NULL
;
1317 /* FIXME what about longjmp breakpoints? Re-create them here? */
1318 create_overlay_event_breakpoint ("_ovly_debug_event");
1322 detach_breakpoints (int pid
)
1324 register struct breakpoint
*b
;
1326 struct cleanup
*old_chain
= save_inferior_ptid ();
1328 if (pid
== PIDGET (inferior_ptid
))
1329 error ("Cannot detach breakpoints of inferior_ptid");
1331 /* Set inferior_ptid; remove_breakpoint uses this global. */
1332 inferior_ptid
= pid_to_ptid (pid
);
1337 val
= remove_breakpoint (b
, mark_inserted
);
1340 do_cleanups (old_chain
);
1345 do_cleanups (old_chain
);
1350 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1354 if (b
->enable_state
== bp_permanent
)
1355 /* Permanent breakpoints cannot be inserted or removed. */
1358 if (b
->type
== bp_none
)
1359 warning ("attempted to remove apparently deleted breakpoint #%d?",
1362 if (b
->type
!= bp_watchpoint
1363 && b
->type
!= bp_hardware_watchpoint
1364 && b
->type
!= bp_read_watchpoint
1365 && b
->type
!= bp_access_watchpoint
1366 && b
->type
!= bp_catch_fork
1367 && b
->type
!= bp_catch_vfork
1368 && b
->type
!= bp_catch_exec
1369 && b
->type
!= bp_catch_catch
1370 && b
->type
!= bp_catch_throw
)
1372 /* "Normal" instruction breakpoint: either the standard
1373 trap-instruction bp (bp_breakpoint), or a
1374 bp_hardware_breakpoint. */
1376 /* First check to see if we have to handle an overlay. */
1377 if (overlay_debugging
== ovly_off
1378 || b
->section
== NULL
1379 || !(section_is_overlay (b
->section
)))
1381 /* No overlay handling: just remove the breakpoint. */
1383 if (b
->type
== bp_hardware_breakpoint
)
1384 val
= target_remove_hw_breakpoint (b
->address
,
1385 b
->shadow_contents
);
1387 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1391 /* This breakpoint is in an overlay section.
1392 Did we set a breakpoint at the LMA? */
1393 if (!overlay_events_enabled
)
1395 /* Yes -- overlay event support is not active, so we
1396 should have set a breakpoint at the LMA. Remove it.
1398 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1400 /* Ignore any failures: if the LMA is in ROM, we will
1401 have already warned when we failed to insert it. */
1402 if (b
->type
!= bp_hardware_breakpoint
)
1403 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1405 target_remove_breakpoint (addr
, b
->shadow_contents
);
1407 /* Did we set a breakpoint at the VMA?
1408 If so, we will have marked the breakpoint 'inserted'. */
1411 /* Yes -- remove it. Previously we did not bother to
1412 remove the breakpoint if the section had been
1413 unmapped, but let's not rely on that being safe. We
1414 don't know what the overlay manager might do. */
1415 if (b
->type
== bp_hardware_breakpoint
)
1416 val
= target_remove_hw_breakpoint (b
->address
,
1417 b
->shadow_contents
);
1419 val
= target_remove_breakpoint (b
->address
,
1420 b
->shadow_contents
);
1424 /* No -- not inserted, so no need to remove. No error. */
1430 b
->inserted
= (is
== mark_inserted
);
1432 else if ((b
->type
== bp_hardware_watchpoint
||
1433 b
->type
== bp_read_watchpoint
||
1434 b
->type
== bp_access_watchpoint
)
1435 && b
->enable_state
== bp_enabled
1441 b
->inserted
= (is
== mark_inserted
);
1442 /* Walk down the saved value chain. */
1443 for (v
= b
->val_chain
; v
; v
= v
->next
)
1445 /* For each memory reference remove the watchpoint
1447 if (VALUE_LVAL (v
) == lval_memory
1448 && ! VALUE_LAZY (v
))
1450 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1452 if (v
== b
->val_chain
1453 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1454 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1459 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1460 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1462 if (b
->type
== bp_read_watchpoint
)
1464 else if (b
->type
== bp_access_watchpoint
)
1467 val
= target_remove_watchpoint (addr
, len
, type
);
1474 /* Failure to remove any of the hardware watchpoints comes here. */
1475 if ((is
== mark_uninserted
) && (b
->inserted
))
1476 warning ("Could not remove hardware watchpoint %d.",
1479 /* Free the saved value chain. We will construct a new one
1480 the next time the watchpoint is inserted. */
1481 for (v
= b
->val_chain
; v
; v
= n
)
1486 b
->val_chain
= NULL
;
1488 else if ((b
->type
== bp_catch_fork
||
1489 b
->type
== bp_catch_vfork
||
1490 b
->type
== bp_catch_exec
)
1491 && b
->enable_state
== bp_enabled
1498 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1500 case bp_catch_vfork
:
1501 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1504 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1507 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1512 b
->inserted
= (is
== mark_inserted
);
1514 else if ((b
->type
== bp_catch_catch
||
1515 b
->type
== bp_catch_throw
)
1516 && b
->enable_state
== bp_enabled
1520 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1523 b
->inserted
= (is
== mark_inserted
);
1525 else if (ep_is_exception_catchpoint (b
)
1526 && b
->inserted
/* sometimes previous insert doesn't happen */
1527 && b
->enable_state
== bp_enabled
1531 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1535 b
->inserted
= (is
== mark_inserted
);
1541 /* Clear the "inserted" flag in all breakpoints. */
1544 mark_breakpoints_out (void)
1546 register struct breakpoint
*b
;
1552 /* Clear the "inserted" flag in all breakpoints and delete any
1553 breakpoints which should go away between runs of the program.
1555 Plus other such housekeeping that has to be done for breakpoints
1558 Note: this function gets called at the end of a run (by
1559 generic_mourn_inferior) and when a run begins (by
1560 init_wait_for_inferior). */
1565 breakpoint_init_inferior (enum inf_context context
)
1567 register struct breakpoint
*b
, *temp
;
1568 static int warning_needed
= 0;
1570 ALL_BREAKPOINTS_SAFE (b
, temp
)
1577 case bp_watchpoint_scope
:
1579 /* If the call dummy breakpoint is at the entry point it will
1580 cause problems when the inferior is rerun, so we better
1583 Also get rid of scope breakpoints. */
1584 delete_breakpoint (b
);
1588 case bp_hardware_watchpoint
:
1589 case bp_read_watchpoint
:
1590 case bp_access_watchpoint
:
1592 /* Likewise for watchpoints on local expressions. */
1593 if (b
->exp_valid_block
!= NULL
)
1594 delete_breakpoint (b
);
1595 if (context
== inf_starting
)
1597 /* Reset val field to force reread of starting value
1598 in insert_breakpoints. */
1600 value_free (b
->val
);
1605 /* Likewise for exception catchpoints in dynamic-linked
1606 executables where required */
1607 if (ep_is_exception_catchpoint (b
) &&
1608 exception_catchpoints_are_fragile
)
1611 delete_breakpoint (b
);
1617 if (exception_catchpoints_are_fragile
)
1618 exception_support_initialized
= 0;
1620 /* Don't issue the warning unless it's really needed... */
1621 if (warning_needed
&& (context
!= inf_exited
))
1623 warning ("Exception catchpoints from last run were deleted.");
1624 warning ("You must reinsert them explicitly.");
1629 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1630 exists at PC. It returns ordinary_breakpoint_here if it's an
1631 ordinary breakpoint, or permanent_breakpoint_here if it's a
1632 permanent breakpoint.
1633 - When continuing from a location with an ordinary breakpoint, we
1634 actually single step once before calling insert_breakpoints.
1635 - When continuing from a localion with a permanent breakpoint, we
1636 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1637 the target, to advance the PC past the breakpoint. */
1639 enum breakpoint_here
1640 breakpoint_here_p (CORE_ADDR pc
)
1642 register struct breakpoint
*b
;
1643 int any_breakpoint_here
= 0;
1646 if ((b
->enable_state
== bp_enabled
1647 || b
->enable_state
== bp_permanent
)
1648 && b
->address
== pc
) /* bp is enabled and matches pc */
1650 if (overlay_debugging
1651 && section_is_overlay (b
->section
)
1652 && !section_is_mapped (b
->section
))
1653 continue; /* unmapped overlay -- can't be a match */
1654 else if (b
->enable_state
== bp_permanent
)
1655 return permanent_breakpoint_here
;
1657 any_breakpoint_here
= 1;
1660 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1664 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1665 but it only returns true if there is actually a breakpoint inserted
1669 breakpoint_inserted_here_p (CORE_ADDR pc
)
1671 register struct breakpoint
*b
;
1675 && b
->address
== pc
) /* bp is inserted and matches pc */
1677 if (overlay_debugging
1678 && section_is_overlay (b
->section
)
1679 && !section_is_mapped (b
->section
))
1680 continue; /* unmapped overlay -- can't be a match */
1688 /* Return nonzero if FRAME is a dummy frame. We can't use
1689 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1690 take too much time, at least using frame_register() on the 68k.
1691 This means that for this function to work right a port must use the
1692 bp_call_dummy breakpoint. */
1695 deprecated_frame_in_dummy (struct frame_info
*frame
)
1697 struct breakpoint
*b
;
1699 /* This function is used by two files: get_frame_type(), after first
1700 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1701 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1702 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES
);
1706 if (b
->type
== bp_call_dummy
1707 && frame_id_eq (b
->frame_id
, get_frame_id (frame
))
1708 /* We need to check the PC as well as the frame on the sparc,
1709 for signals.exp in the testsuite. */
1710 && (get_frame_pc (frame
)
1712 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * DEPRECATED_REGISTER_SIZE
))
1713 && get_frame_pc (frame
) <= b
->address
)
1719 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1720 PC is valid for process/thread PID. */
1723 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1725 struct breakpoint
*b
;
1728 thread
= pid_to_thread_id (ptid
);
1731 if (b
->enable_state
!= bp_disabled
1732 && b
->enable_state
!= bp_shlib_disabled
1733 && b
->enable_state
!= bp_call_disabled
1735 && (b
->thread
== -1 || b
->thread
== thread
))
1737 if (overlay_debugging
1738 && section_is_overlay (b
->section
)
1739 && !section_is_mapped (b
->section
))
1740 continue; /* unmapped overlay -- can't be a match */
1749 /* bpstat stuff. External routines' interfaces are documented
1753 ep_is_catchpoint (struct breakpoint
*ep
)
1756 (ep
->type
== bp_catch_load
)
1757 || (ep
->type
== bp_catch_unload
)
1758 || (ep
->type
== bp_catch_fork
)
1759 || (ep
->type
== bp_catch_vfork
)
1760 || (ep
->type
== bp_catch_exec
)
1761 || (ep
->type
== bp_catch_catch
)
1762 || (ep
->type
== bp_catch_throw
);
1764 /* ??rehrauer: Add more kinds here, as are implemented... */
1768 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1771 (ep
->type
== bp_catch_load
)
1772 || (ep
->type
== bp_catch_unload
);
1776 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1779 (ep
->type
== bp_catch_catch
)
1780 || (ep
->type
== bp_catch_throw
);
1783 /* Clear a bpstat so that it says we are not at any breakpoint.
1784 Also free any storage that is part of a bpstat. */
1787 bpstat_clear (bpstat
*bsp
)
1798 if (p
->old_val
!= NULL
)
1799 value_free (p
->old_val
);
1800 free_command_lines (&p
->commands
);
1807 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1808 is part of the bpstat is copied as well. */
1811 bpstat_copy (bpstat bs
)
1815 bpstat retval
= NULL
;
1820 for (; bs
!= NULL
; bs
= bs
->next
)
1822 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1823 memcpy (tmp
, bs
, sizeof (*tmp
));
1824 if (bs
->commands
!= NULL
)
1825 tmp
->commands
= copy_command_lines (bs
->commands
);
1826 if (bs
->old_val
!= NULL
)
1827 tmp
->old_val
= value_copy (bs
->old_val
);
1830 /* This is the first thing in the chain. */
1840 /* Find the bpstat associated with this breakpoint */
1843 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1848 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1850 if (bsp
->breakpoint_at
== breakpoint
)
1856 /* Find a step_resume breakpoint associated with this bpstat.
1857 (If there are multiple step_resume bp's on the list, this function
1858 will arbitrarily pick one.)
1860 It is an error to use this function if BPSTAT doesn't contain a
1861 step_resume breakpoint.
1863 See wait_for_inferior's use of this function. */
1865 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1870 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1872 current_thread
= pid_to_thread_id (inferior_ptid
);
1874 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1876 if ((bsp
->breakpoint_at
!= NULL
) &&
1877 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1878 (bsp
->breakpoint_at
->thread
== current_thread
||
1879 bsp
->breakpoint_at
->thread
== -1))
1880 return bsp
->breakpoint_at
;
1883 error ("Internal error (no step_resume breakpoint found)");
1887 /* Return the breakpoint number of the first breakpoint we are stopped
1888 at. *BSP upon return is a bpstat which points to the remaining
1889 breakpoints stopped at (but which is not guaranteed to be good for
1890 anything but further calls to bpstat_num).
1891 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1894 bpstat_num (bpstat
*bsp
)
1896 struct breakpoint
*b
;
1899 return 0; /* No more breakpoint values */
1902 b
= (*bsp
)->breakpoint_at
;
1903 *bsp
= (*bsp
)->next
;
1905 return -1; /* breakpoint that's been deleted since */
1907 return b
->number
; /* We have its number */
1911 /* Modify BS so that the actions will not be performed. */
1914 bpstat_clear_actions (bpstat bs
)
1916 for (; bs
!= NULL
; bs
= bs
->next
)
1918 free_command_lines (&bs
->commands
);
1919 if (bs
->old_val
!= NULL
)
1921 value_free (bs
->old_val
);
1927 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1930 cleanup_executing_breakpoints (void *ignore
)
1932 executing_breakpoint_commands
= 0;
1935 /* Execute all the commands associated with all the breakpoints at this
1936 location. Any of these commands could cause the process to proceed
1937 beyond this point, etc. We look out for such changes by checking
1938 the global "breakpoint_proceeded" after each command. */
1941 bpstat_do_actions (bpstat
*bsp
)
1944 struct cleanup
*old_chain
;
1945 struct command_line
*cmd
;
1947 /* Avoid endless recursion if a `source' command is contained
1949 if (executing_breakpoint_commands
)
1952 executing_breakpoint_commands
= 1;
1953 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1956 /* Note that (as of this writing), our callers all appear to
1957 be passing us the address of global stop_bpstat. And, if
1958 our calls to execute_control_command cause the inferior to
1959 proceed, that global (and hence, *bsp) will change.
1961 We must be careful to not touch *bsp unless the inferior
1962 has not proceeded. */
1964 /* This pointer will iterate over the list of bpstat's. */
1967 breakpoint_proceeded
= 0;
1968 for (; bs
!= NULL
; bs
= bs
->next
)
1973 execute_control_command (cmd
);
1975 if (breakpoint_proceeded
)
1980 if (breakpoint_proceeded
)
1981 /* The inferior is proceeded by the command; bomb out now.
1982 The bpstat chain has been blown away by wait_for_inferior.
1983 But since execution has stopped again, there is a new bpstat
1984 to look at, so start over. */
1987 free_command_lines (&bs
->commands
);
1989 do_cleanups (old_chain
);
1992 /* This is the normal print function for a bpstat. In the future,
1993 much of this logic could (should?) be moved to bpstat_stop_status,
1994 by having it set different print_it values.
1996 Current scheme: When we stop, bpstat_print() is called. It loops
1997 through the bpstat list of things causing this stop, calling the
1998 print_bp_stop_message function on each one. The behavior of the
1999 print_bp_stop_message function depends on the print_it field of
2000 bpstat. If such field so indicates, call this function here.
2002 Return values from this routine (ultimately used by bpstat_print()
2003 and normal_stop() to decide what to do):
2004 PRINT_NOTHING: Means we already printed all we needed to print,
2005 don't print anything else.
2006 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2007 that something to be followed by a location.
2008 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2009 that something to be followed by a location.
2010 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2013 static enum print_stop_action
2014 print_it_typical (bpstat bs
)
2016 struct cleanup
*old_chain
, *ui_out_chain
;
2017 struct ui_stream
*stb
;
2018 stb
= ui_out_stream_new (uiout
);
2019 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2020 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2021 which has since been deleted. */
2022 if (bs
->breakpoint_at
== NULL
)
2023 return PRINT_UNKNOWN
;
2025 switch (bs
->breakpoint_at
->type
)
2028 case bp_hardware_breakpoint
:
2029 annotate_breakpoint (bs
->breakpoint_at
->number
);
2030 ui_out_text (uiout
, "\nBreakpoint ");
2031 if (ui_out_is_mi_like_p (uiout
))
2032 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
2033 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2034 ui_out_text (uiout
, ", ");
2035 return PRINT_SRC_AND_LOC
;
2038 case bp_shlib_event
:
2039 /* Did we stop because the user set the stop_on_solib_events
2040 variable? (If so, we report this as a generic, "Stopped due
2041 to shlib event" message.) */
2042 printf_filtered ("Stopped due to shared library event\n");
2043 return PRINT_NOTHING
;
2046 case bp_thread_event
:
2047 /* Not sure how we will get here.
2048 GDB should not stop for these breakpoints. */
2049 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2050 return PRINT_NOTHING
;
2053 case bp_overlay_event
:
2054 /* By analogy with the thread event, GDB should not stop for these. */
2055 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2056 return PRINT_NOTHING
;
2060 annotate_catchpoint (bs
->breakpoint_at
->number
);
2061 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2062 printf_filtered ("loaded");
2063 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2064 return PRINT_SRC_AND_LOC
;
2067 case bp_catch_unload
:
2068 annotate_catchpoint (bs
->breakpoint_at
->number
);
2069 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2070 printf_filtered ("unloaded");
2071 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2072 return PRINT_SRC_AND_LOC
;
2076 annotate_catchpoint (bs
->breakpoint_at
->number
);
2077 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2078 printf_filtered ("forked");
2079 printf_filtered (" process %d), ",
2080 bs
->breakpoint_at
->forked_inferior_pid
);
2081 return PRINT_SRC_AND_LOC
;
2084 case bp_catch_vfork
:
2085 annotate_catchpoint (bs
->breakpoint_at
->number
);
2086 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2087 printf_filtered ("vforked");
2088 printf_filtered (" process %d), ",
2089 bs
->breakpoint_at
->forked_inferior_pid
);
2090 return PRINT_SRC_AND_LOC
;
2094 annotate_catchpoint (bs
->breakpoint_at
->number
);
2095 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2096 bs
->breakpoint_at
->number
,
2097 bs
->breakpoint_at
->exec_pathname
);
2098 return PRINT_SRC_AND_LOC
;
2101 case bp_catch_catch
:
2102 if (current_exception_event
&&
2103 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2105 annotate_catchpoint (bs
->breakpoint_at
->number
);
2106 printf_filtered ("\nCatchpoint %d (exception caught), ",
2107 bs
->breakpoint_at
->number
);
2108 printf_filtered ("throw location ");
2109 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2110 printf_filtered ("%s:%d",
2111 CURRENT_EXCEPTION_THROW_FILE
,
2112 CURRENT_EXCEPTION_THROW_LINE
);
2114 printf_filtered ("unknown");
2116 printf_filtered (", catch location ");
2117 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2118 printf_filtered ("%s:%d",
2119 CURRENT_EXCEPTION_CATCH_FILE
,
2120 CURRENT_EXCEPTION_CATCH_LINE
);
2122 printf_filtered ("unknown");
2124 printf_filtered ("\n");
2125 /* don't bother to print location frame info */
2126 return PRINT_SRC_ONLY
;
2130 /* really throw, some other bpstat will handle it */
2131 return PRINT_UNKNOWN
;
2135 case bp_catch_throw
:
2136 if (current_exception_event
&&
2137 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2139 annotate_catchpoint (bs
->breakpoint_at
->number
);
2140 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2141 bs
->breakpoint_at
->number
);
2142 printf_filtered ("throw location ");
2143 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2144 printf_filtered ("%s:%d",
2145 CURRENT_EXCEPTION_THROW_FILE
,
2146 CURRENT_EXCEPTION_THROW_LINE
);
2148 printf_filtered ("unknown");
2150 printf_filtered (", catch location ");
2151 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2152 printf_filtered ("%s:%d",
2153 CURRENT_EXCEPTION_CATCH_FILE
,
2154 CURRENT_EXCEPTION_CATCH_LINE
);
2156 printf_filtered ("unknown");
2158 printf_filtered ("\n");
2159 /* don't bother to print location frame info */
2160 return PRINT_SRC_ONLY
;
2164 /* really catch, some other bpstat will handle it */
2165 return PRINT_UNKNOWN
;
2170 case bp_hardware_watchpoint
:
2171 if (bs
->old_val
!= NULL
)
2173 annotate_watchpoint (bs
->breakpoint_at
->number
);
2174 if (ui_out_is_mi_like_p (uiout
))
2175 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2176 mention (bs
->breakpoint_at
);
2177 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2178 ui_out_text (uiout
, "\nOld value = ");
2179 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2180 ui_out_field_stream (uiout
, "old", stb
);
2181 ui_out_text (uiout
, "\nNew value = ");
2182 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2183 ui_out_field_stream (uiout
, "new", stb
);
2184 do_cleanups (ui_out_chain
);
2185 ui_out_text (uiout
, "\n");
2186 value_free (bs
->old_val
);
2189 /* More than one watchpoint may have been triggered. */
2190 return PRINT_UNKNOWN
;
2193 case bp_read_watchpoint
:
2194 if (ui_out_is_mi_like_p (uiout
))
2195 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2196 mention (bs
->breakpoint_at
);
2197 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2198 ui_out_text (uiout
, "\nValue = ");
2199 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2200 ui_out_field_stream (uiout
, "value", stb
);
2201 do_cleanups (ui_out_chain
);
2202 ui_out_text (uiout
, "\n");
2203 return PRINT_UNKNOWN
;
2206 case bp_access_watchpoint
:
2207 if (bs
->old_val
!= NULL
)
2209 annotate_watchpoint (bs
->breakpoint_at
->number
);
2210 if (ui_out_is_mi_like_p (uiout
))
2211 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2212 mention (bs
->breakpoint_at
);
2213 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2214 ui_out_text (uiout
, "\nOld value = ");
2215 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2216 ui_out_field_stream (uiout
, "old", stb
);
2217 value_free (bs
->old_val
);
2219 ui_out_text (uiout
, "\nNew value = ");
2223 mention (bs
->breakpoint_at
);
2224 if (ui_out_is_mi_like_p (uiout
))
2225 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2226 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2227 ui_out_text (uiout
, "\nValue = ");
2229 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2230 ui_out_field_stream (uiout
, "new", stb
);
2231 do_cleanups (ui_out_chain
);
2232 ui_out_text (uiout
, "\n");
2233 return PRINT_UNKNOWN
;
2236 /* Fall through, we don't deal with these types of breakpoints
2240 if (ui_out_is_mi_like_p (uiout
))
2241 ui_out_field_string (uiout
, "reason", "function-finished");
2242 return PRINT_UNKNOWN
;
2246 if (ui_out_is_mi_like_p (uiout
))
2247 ui_out_field_string (uiout
, "reason", "location-reached");
2248 return PRINT_UNKNOWN
;
2253 case bp_longjmp_resume
:
2254 case bp_step_resume
:
2255 case bp_through_sigtramp
:
2256 case bp_watchpoint_scope
:
2259 return PRINT_UNKNOWN
;
2263 /* Generic routine for printing messages indicating why we
2264 stopped. The behavior of this function depends on the value
2265 'print_it' in the bpstat structure. Under some circumstances we
2266 may decide not to print anything here and delegate the task to
2269 static enum print_stop_action
2270 print_bp_stop_message (bpstat bs
)
2272 switch (bs
->print_it
)
2275 /* Nothing should be printed for this bpstat entry. */
2276 return PRINT_UNKNOWN
;
2280 /* We still want to print the frame, but we already printed the
2281 relevant messages. */
2282 return PRINT_SRC_AND_LOC
;
2285 case print_it_normal
:
2286 /* Normal case. Call the breakpoint's print_it method, or
2287 print_it_typical. */
2288 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2289 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2290 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2292 return print_it_typical (bs
);
2296 internal_error (__FILE__
, __LINE__
,
2297 "print_bp_stop_message: unrecognized enum value");
2302 /* Print a message indicating what happened. This is called from
2303 normal_stop(). The input to this routine is the head of the bpstat
2304 list - a list of the eventpoints that caused this stop. This
2305 routine calls the generic print routine for printing a message
2306 about reasons for stopping. This will print (for example) the
2307 "Breakpoint n," part of the output. The return value of this
2310 PRINT_UNKNOWN: Means we printed nothing
2311 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2312 code to print the location. An example is
2313 "Breakpoint 1, " which should be followed by
2315 PRINT_SRC_ONLY: Means we printed something, but there is no need
2316 to also print the location part of the message.
2317 An example is the catch/throw messages, which
2318 don't require a location appended to the end.
2319 PRINT_NOTHING: We have done some printing and we don't need any
2320 further info to be printed.*/
2322 enum print_stop_action
2323 bpstat_print (bpstat bs
)
2327 /* Maybe another breakpoint in the chain caused us to stop.
2328 (Currently all watchpoints go on the bpstat whether hit or not.
2329 That probably could (should) be changed, provided care is taken
2330 with respect to bpstat_explains_signal). */
2331 for (; bs
; bs
= bs
->next
)
2333 val
= print_bp_stop_message (bs
);
2334 if (val
== PRINT_SRC_ONLY
2335 || val
== PRINT_SRC_AND_LOC
2336 || val
== PRINT_NOTHING
)
2340 /* We reached the end of the chain, or we got a null BS to start
2341 with and nothing was printed. */
2342 return PRINT_UNKNOWN
;
2345 /* Evaluate the expression EXP and return 1 if value is zero.
2346 This is used inside a catch_errors to evaluate the breakpoint condition.
2347 The argument is a "struct expression *" that has been cast to char * to
2348 make it pass through catch_errors. */
2351 breakpoint_cond_eval (void *exp
)
2353 struct value
*mark
= value_mark ();
2354 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2355 value_free_to_mark (mark
);
2359 /* Allocate a new bpstat and chain it to the current one. */
2362 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2366 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2368 bs
->breakpoint_at
= b
;
2369 /* If the condition is false, etc., don't do the commands. */
2370 bs
->commands
= NULL
;
2372 bs
->print_it
= print_it_normal
;
2376 /* Possible return values for watchpoint_check (this can't be an enum
2377 because of check_errors). */
2378 /* The watchpoint has been deleted. */
2379 #define WP_DELETED 1
2380 /* The value has changed. */
2381 #define WP_VALUE_CHANGED 2
2382 /* The value has not changed. */
2383 #define WP_VALUE_NOT_CHANGED 3
2385 #define BP_TEMPFLAG 1
2386 #define BP_HARDWAREFLAG 2
2388 /* Check watchpoint condition. */
2391 watchpoint_check (void *p
)
2393 bpstat bs
= (bpstat
) p
;
2394 struct breakpoint
*b
;
2395 struct frame_info
*fr
;
2396 int within_current_scope
;
2398 b
= bs
->breakpoint_at
;
2400 if (b
->exp_valid_block
== NULL
)
2401 within_current_scope
= 1;
2404 /* There is no current frame at this moment. If we're going to have
2405 any chance of handling watchpoints on local variables, we'll need
2406 the frame chain (so we can determine if we're in scope). */
2407 reinit_frame_cache ();
2408 fr
= frame_find_by_id (b
->watchpoint_frame
);
2409 within_current_scope
= (fr
!= NULL
);
2410 /* in_function_epilogue_p() returns a non-zero value if we're still
2411 in the function but the stack frame has already been invalidated.
2412 Since we can't rely on the values of local variables after the
2413 stack has been destroyed, we are treating the watchpoint in that
2414 state as `not changed' without further checking. */
2415 if (within_current_scope
&& fr
== get_current_frame ()
2416 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2417 return WP_VALUE_NOT_CHANGED
;
2418 if (within_current_scope
)
2419 /* If we end up stopping, the current frame will get selected
2420 in normal_stop. So this call to select_frame won't affect
2425 if (within_current_scope
)
2427 /* We use value_{,free_to_}mark because it could be a
2428 *long* time before we return to the command level and
2429 call free_all_values. We can't call free_all_values because
2430 we might be in the middle of evaluating a function call. */
2432 struct value
*mark
= value_mark ();
2433 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2434 if (!value_equal (b
->val
, new_val
))
2436 release_value (new_val
);
2437 value_free_to_mark (mark
);
2438 bs
->old_val
= b
->val
;
2440 /* We will stop here */
2441 return WP_VALUE_CHANGED
;
2445 /* Nothing changed, don't do anything. */
2446 value_free_to_mark (mark
);
2447 /* We won't stop here */
2448 return WP_VALUE_NOT_CHANGED
;
2453 /* This seems like the only logical thing to do because
2454 if we temporarily ignored the watchpoint, then when
2455 we reenter the block in which it is valid it contains
2456 garbage (in the case of a function, it may have two
2457 garbage values, one before and one after the prologue).
2458 So we can't even detect the first assignment to it and
2459 watch after that (since the garbage may or may not equal
2460 the first value assigned). */
2461 /* We print all the stop information in print_it_typical(), but
2462 in this case, by the time we call print_it_typical() this bp
2463 will be deleted already. So we have no choice but print the
2464 information here. */
2465 if (ui_out_is_mi_like_p (uiout
))
2466 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2467 ui_out_text (uiout
, "\nWatchpoint ");
2468 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2469 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2470 which its expression is valid.\n");
2472 if (b
->related_breakpoint
)
2473 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2474 b
->disposition
= disp_del_at_next_stop
;
2480 /* Get a bpstat associated with having just stopped at address *PC
2481 and frame address CORE_ADDRESS. Update *PC to point at the
2482 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2483 if this is known to not be a real breakpoint (it could still be a
2484 watchpoint, though). */
2486 /* Determine whether we stopped at a breakpoint, etc, or whether we
2487 don't understand this stop. Result is a chain of bpstat's such that:
2489 if we don't understand the stop, the result is a null pointer.
2491 if we understand why we stopped, the result is not null.
2493 Each element of the chain refers to a particular breakpoint or
2494 watchpoint at which we have stopped. (We may have stopped for
2495 several reasons concurrently.)
2497 Each element of the chain has valid next, breakpoint_at,
2498 commands, FIXME??? fields. */
2501 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_sw_breakpoint
)
2503 register struct breakpoint
*b
, *temp
;
2505 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2506 int real_breakpoint
= 0;
2507 /* Root of the chain of bpstat's */
2508 struct bpstats root_bs
[1];
2509 /* Pointer to the last thing in the chain currently. */
2510 bpstat bs
= root_bs
;
2511 static char message1
[] =
2512 "Error evaluating expression for watchpoint %d\n";
2513 char message
[sizeof (message1
) + 30 /* slop */ ];
2515 /* Get the address where the breakpoint would have been. The
2516 "not_a_sw_breakpoint" argument is meant to distinguish between a
2517 breakpoint trap event and a trace/singlestep trap event. For a
2518 trace/singlestep trap event, we would not want to subtract
2519 DECR_PC_AFTER_BREAK from the PC. */
2521 bp_addr
= *pc
- (not_a_sw_breakpoint
? 0 : DECR_PC_AFTER_BREAK
);
2523 ALL_BREAKPOINTS_SAFE (b
, temp
)
2525 if (b
->enable_state
== bp_disabled
2526 || b
->enable_state
== bp_shlib_disabled
2527 || b
->enable_state
== bp_call_disabled
)
2530 if (b
->type
!= bp_watchpoint
2531 && b
->type
!= bp_hardware_watchpoint
2532 && b
->type
!= bp_read_watchpoint
2533 && b
->type
!= bp_access_watchpoint
2534 && b
->type
!= bp_hardware_breakpoint
2535 && b
->type
!= bp_catch_fork
2536 && b
->type
!= bp_catch_vfork
2537 && b
->type
!= bp_catch_exec
2538 && b
->type
!= bp_catch_catch
2539 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2541 if (b
->address
!= bp_addr
) /* address doesn't match */
2543 if (overlay_debugging
/* unmapped overlay section */
2544 && section_is_overlay (b
->section
)
2545 && !section_is_mapped (b
->section
))
2549 if (b
->type
== bp_hardware_breakpoint
)
2551 if (b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2553 if (overlay_debugging
/* unmapped overlay section */
2554 && section_is_overlay (b
->section
)
2555 && !section_is_mapped (b
->section
))
2559 /* Is this a catchpoint of a load or unload? If so, did we
2560 get a load or unload of the specified library? If not,
2562 if ((b
->type
== bp_catch_load
)
2563 #if defined(SOLIB_HAVE_LOAD_EVENT)
2564 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2565 || ((b
->dll_pathname
!= NULL
)
2566 && (strcmp (b
->dll_pathname
,
2567 SOLIB_LOADED_LIBRARY_PATHNAME (
2568 PIDGET (inferior_ptid
)))
2574 if ((b
->type
== bp_catch_unload
)
2575 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2576 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2577 || ((b
->dll_pathname
!= NULL
)
2578 && (strcmp (b
->dll_pathname
,
2579 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2580 PIDGET (inferior_ptid
)))
2586 if ((b
->type
== bp_catch_fork
)
2587 && !inferior_has_forked (PIDGET (inferior_ptid
),
2588 &b
->forked_inferior_pid
))
2591 if ((b
->type
== bp_catch_vfork
)
2592 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2593 &b
->forked_inferior_pid
))
2596 if ((b
->type
== bp_catch_exec
)
2597 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2600 if (ep_is_exception_catchpoint (b
) &&
2601 !(current_exception_event
= target_get_current_exception_event ()))
2604 /* Come here if it's a watchpoint, or if the break address matches */
2606 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2608 /* Watchpoints may change this, if not found to have triggered. */
2612 sprintf (message
, message1
, b
->number
);
2613 if (b
->type
== bp_watchpoint
||
2614 b
->type
== bp_hardware_watchpoint
)
2616 switch (catch_errors (watchpoint_check
, bs
, message
,
2620 /* We've already printed what needs to be printed. */
2621 /* Actually this is superfluous, because by the time we
2622 call print_it_typical() the wp will be already deleted,
2623 and the function will return immediately. */
2624 bs
->print_it
= print_it_done
;
2627 case WP_VALUE_CHANGED
:
2631 case WP_VALUE_NOT_CHANGED
:
2633 bs
->print_it
= print_it_noop
;
2640 /* Error from catch_errors. */
2641 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2642 if (b
->related_breakpoint
)
2643 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2644 b
->disposition
= disp_del_at_next_stop
;
2645 /* We've already printed what needs to be printed. */
2646 bs
->print_it
= print_it_done
;
2652 else if (b
->type
== bp_read_watchpoint
||
2653 b
->type
== bp_access_watchpoint
)
2659 addr
= target_stopped_data_address ();
2662 for (v
= b
->val_chain
; v
; v
= v
->next
)
2664 if (VALUE_LVAL (v
) == lval_memory
2665 && ! VALUE_LAZY (v
))
2667 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2669 if (v
== b
->val_chain
2670 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2671 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2675 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2676 /* Exact match not required. Within range is
2678 if (addr
>= vaddr
&&
2679 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2685 switch (catch_errors (watchpoint_check
, bs
, message
,
2689 /* We've already printed what needs to be printed. */
2690 bs
->print_it
= print_it_done
;
2693 case WP_VALUE_CHANGED
:
2694 if (b
->type
== bp_read_watchpoint
)
2696 /* Don't stop: read watchpoints shouldn't fire if
2697 the value has changed. This is for targets which
2698 cannot set read-only watchpoints. */
2699 bs
->print_it
= print_it_noop
;
2705 case WP_VALUE_NOT_CHANGED
:
2712 /* Error from catch_errors. */
2713 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2714 if (b
->related_breakpoint
)
2715 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2716 b
->disposition
= disp_del_at_next_stop
;
2717 /* We've already printed what needs to be printed. */
2718 bs
->print_it
= print_it_done
;
2721 else /* found == 0 */
2723 /* This is a case where some watchpoint(s) triggered,
2724 but not at the address of this watchpoint (FOUND
2725 was left zero). So don't print anything for this
2727 bs
->print_it
= print_it_noop
;
2734 /* By definition, an encountered breakpoint is a triggered
2738 real_breakpoint
= 1;
2741 if (frame_id_p (b
->frame_id
)
2742 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2746 int value_is_zero
= 0;
2750 /* Need to select the frame, with all that implies
2751 so that the conditions will have the right context. */
2752 select_frame (get_current_frame ());
2754 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2755 "Error in testing breakpoint condition:\n",
2757 /* FIXME-someday, should give breakpoint # */
2760 if (b
->cond
&& value_is_zero
)
2763 /* Don't consider this a hit. */
2766 else if (b
->ignore_count
> 0)
2769 annotate_ignore_count_change ();
2774 /* We will stop here */
2775 if (b
->disposition
== disp_disable
)
2776 b
->enable_state
= bp_disabled
;
2779 bs
->commands
= b
->commands
;
2781 (STREQ ("silent", bs
->commands
->line
) ||
2782 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2784 bs
->commands
= bs
->commands
->next
;
2787 bs
->commands
= copy_command_lines (bs
->commands
);
2790 /* Print nothing for this entry if we dont stop or if we dont print. */
2791 if (bs
->stop
== 0 || bs
->print
== 0)
2792 bs
->print_it
= print_it_noop
;
2795 bs
->next
= NULL
; /* Terminate the chain */
2796 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2798 if (real_breakpoint
&& bs
)
2800 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2802 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2804 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2810 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2813 #if defined (SHIFT_INST_REGS)
2815 #else /* No SHIFT_INST_REGS. */
2817 #endif /* No SHIFT_INST_REGS. */
2822 /* The value of a hardware watchpoint hasn't changed, but the
2823 intermediate memory locations we are watching may have. */
2824 if (bs
&& !bs
->stop
&&
2825 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2826 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2827 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2829 remove_breakpoints ();
2830 insert_breakpoints ();
2835 /* Tell what to do about this bpstat. */
2837 bpstat_what (bpstat bs
)
2839 /* Classify each bpstat as one of the following. */
2842 /* This bpstat element has no effect on the main_action. */
2845 /* There was a watchpoint, stop but don't print. */
2848 /* There was a watchpoint, stop and print. */
2851 /* There was a breakpoint but we're not stopping. */
2854 /* There was a breakpoint, stop but don't print. */
2857 /* There was a breakpoint, stop and print. */
2860 /* We hit the longjmp breakpoint. */
2863 /* We hit the longjmp_resume breakpoint. */
2866 /* We hit the step_resume breakpoint. */
2869 /* We hit the through_sigtramp breakpoint. */
2872 /* We hit the shared library event breakpoint. */
2875 /* We caught a shared library event. */
2878 /* This is just used to count how many enums there are. */
2882 /* Here is the table which drives this routine. So that we can
2883 format it pretty, we define some abbreviations for the
2884 enum bpstat_what codes. */
2885 #define kc BPSTAT_WHAT_KEEP_CHECKING
2886 #define ss BPSTAT_WHAT_STOP_SILENT
2887 #define sn BPSTAT_WHAT_STOP_NOISY
2888 #define sgl BPSTAT_WHAT_SINGLE
2889 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2890 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2891 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2892 #define sr BPSTAT_WHAT_STEP_RESUME
2893 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2894 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2895 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2897 /* "Can't happen." Might want to print an error message.
2898 abort() is not out of the question, but chances are GDB is just
2899 a bit confused, not unusable. */
2900 #define err BPSTAT_WHAT_STOP_NOISY
2902 /* Given an old action and a class, come up with a new action. */
2903 /* One interesting property of this table is that wp_silent is the same
2904 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2905 after stopping, the check for whether to step over a breakpoint
2906 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2907 reference to how we stopped. We retain separate wp_silent and
2908 bp_silent codes in case we want to change that someday.
2910 Another possibly interesting property of this table is that
2911 there's a partial ordering, priority-like, of the actions. Once
2912 you've decided that some action is appropriate, you'll never go
2913 back and decide something of a lower priority is better. The
2916 kc < clr sgl shl shlr slr sn sr ss ts
2917 sgl < clrs shl shlr slr sn sr ss ts
2918 slr < err shl shlr sn sr ss ts
2919 clr < clrs err shl shlr sn sr ss ts
2920 clrs < err shl shlr sn sr ss ts
2921 ss < shl shlr sn sr ts
2928 What I think this means is that we don't need a damned table
2929 here. If you just put the rows and columns in the right order,
2930 it'd look awfully regular. We could simply walk the bpstat list
2931 and choose the highest priority action we find, with a little
2932 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2933 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2934 is messy anyway). */
2936 /* step_resume entries: a step resume breakpoint overrides another
2937 breakpoint of signal handling (see comment in wait_for_inferior
2938 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2939 /* We handle the through_sigtramp_breakpoint the same way; having both
2940 one of those and a step_resume_breakpoint is probably very rare (?). */
2942 static const enum bpstat_what_main_action
2943 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2946 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2949 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2951 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2953 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2955 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2957 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2959 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2961 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2963 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2965 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2967 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2969 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2971 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2986 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
2987 struct bpstat_what retval
;
2989 retval
.call_dummy
= 0;
2990 for (; bs
!= NULL
; bs
= bs
->next
)
2992 enum class bs_class
= no_effect
;
2993 if (bs
->breakpoint_at
== NULL
)
2994 /* I suspect this can happen if it was a momentary breakpoint
2995 which has since been deleted. */
2997 switch (bs
->breakpoint_at
->type
)
3003 case bp_hardware_breakpoint
:
3009 bs_class
= bp_noisy
;
3011 bs_class
= bp_silent
;
3014 bs_class
= bp_nostop
;
3017 case bp_hardware_watchpoint
:
3018 case bp_read_watchpoint
:
3019 case bp_access_watchpoint
:
3023 bs_class
= wp_noisy
;
3025 bs_class
= wp_silent
;
3028 /* There was a watchpoint, but we're not stopping.
3029 This requires no further action. */
3030 bs_class
= no_effect
;
3033 bs_class
= long_jump
;
3035 case bp_longjmp_resume
:
3036 bs_class
= long_resume
;
3038 case bp_step_resume
:
3041 bs_class
= step_resume
;
3044 /* It is for the wrong frame. */
3045 bs_class
= bp_nostop
;
3047 case bp_through_sigtramp
:
3048 bs_class
= through_sig
;
3050 case bp_watchpoint_scope
:
3051 bs_class
= bp_nostop
;
3053 case bp_shlib_event
:
3054 bs_class
= shlib_event
;
3056 case bp_thread_event
:
3057 case bp_overlay_event
:
3058 bs_class
= bp_nostop
;
3061 case bp_catch_unload
:
3062 /* Only if this catchpoint triggered should we cause the
3063 step-out-of-dld behaviour. Otherwise, we ignore this
3066 bs_class
= catch_shlib_event
;
3068 bs_class
= no_effect
;
3071 case bp_catch_vfork
:
3076 bs_class
= bp_noisy
;
3078 bs_class
= bp_silent
;
3081 /* There was a catchpoint, but we're not stopping.
3082 This requires no further action. */
3083 bs_class
= no_effect
;
3085 case bp_catch_catch
:
3086 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3087 bs_class
= bp_nostop
;
3089 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3091 case bp_catch_throw
:
3092 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3093 bs_class
= bp_nostop
;
3095 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3098 /* Make sure the action is stop (silent or noisy),
3099 so infrun.c pops the dummy frame. */
3100 bs_class
= bp_silent
;
3101 retval
.call_dummy
= 1;
3104 current_action
= table
[(int) bs_class
][(int) current_action
];
3106 retval
.main_action
= current_action
;
3110 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3111 without hardware support). This isn't related to a specific bpstat,
3112 just to things like whether watchpoints are set. */
3115 bpstat_should_step (void)
3117 struct breakpoint
*b
;
3119 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3124 /* Nonzero if there are enabled hardware watchpoints. */
3126 bpstat_have_active_hw_watchpoints (void)
3128 struct breakpoint
*b
;
3130 if ((b
->enable_state
== bp_enabled
) &&
3132 ((b
->type
== bp_hardware_watchpoint
) ||
3133 (b
->type
== bp_read_watchpoint
) ||
3134 (b
->type
== bp_access_watchpoint
)))
3140 /* Given a bpstat that records zero or more triggered eventpoints, this
3141 function returns another bpstat which contains only the catchpoints
3142 on that first list, if any. */
3144 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3146 struct bpstats root_bs
[1];
3147 bpstat bs
= root_bs
;
3148 struct breakpoint
*ep
;
3151 bpstat_clear (cp_list
);
3152 root_bs
->next
= NULL
;
3154 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3156 /* Is this eventpoint a catchpoint? If not, ignore it. */
3157 ep
= ep_list
->breakpoint_at
;
3160 if ((ep
->type
!= bp_catch_load
) &&
3161 (ep
->type
!= bp_catch_unload
) &&
3162 (ep
->type
!= bp_catch_catch
) &&
3163 (ep
->type
!= bp_catch_throw
))
3164 /* pai: (temp) ADD fork/vfork here!! */
3167 /* Yes; add it to the list. */
3168 bs
= bpstat_alloc (ep
, bs
);
3173 #if defined(SOLIB_ADD)
3174 /* Also, for each triggered catchpoint, tag it with the name of
3175 the library that caused this trigger. (We copy the name now,
3176 because it's only guaranteed to be available NOW, when the
3177 catchpoint triggers. Clients who may wish to know the name
3178 later must get it from the catchpoint itself.) */
3179 if (ep
->triggered_dll_pathname
!= NULL
)
3180 xfree (ep
->triggered_dll_pathname
);
3181 if (ep
->type
== bp_catch_load
)
3182 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3183 PIDGET (inferior_ptid
));
3185 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3186 PIDGET (inferior_ptid
));
3188 dll_pathname
= NULL
;
3192 ep
->triggered_dll_pathname
= (char *)
3193 xmalloc (strlen (dll_pathname
) + 1);
3194 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3197 ep
->triggered_dll_pathname
= NULL
;
3203 /* Print B to gdb_stdout. */
3205 print_one_breakpoint (struct breakpoint
*b
,
3206 CORE_ADDR
*last_addr
)
3208 register struct command_line
*l
;
3209 register struct symbol
*sym
;
3210 struct ep_type_description
3215 static struct ep_type_description bptypes
[] =
3217 {bp_none
, "?deleted?"},
3218 {bp_breakpoint
, "breakpoint"},
3219 {bp_hardware_breakpoint
, "hw breakpoint"},
3220 {bp_until
, "until"},
3221 {bp_finish
, "finish"},
3222 {bp_watchpoint
, "watchpoint"},
3223 {bp_hardware_watchpoint
, "hw watchpoint"},
3224 {bp_read_watchpoint
, "read watchpoint"},
3225 {bp_access_watchpoint
, "acc watchpoint"},
3226 {bp_longjmp
, "longjmp"},
3227 {bp_longjmp_resume
, "longjmp resume"},
3228 {bp_step_resume
, "step resume"},
3229 {bp_through_sigtramp
, "sigtramp"},
3230 {bp_watchpoint_scope
, "watchpoint scope"},
3231 {bp_call_dummy
, "call dummy"},
3232 {bp_shlib_event
, "shlib events"},
3233 {bp_thread_event
, "thread events"},
3234 {bp_overlay_event
, "overlay events"},
3235 {bp_catch_load
, "catch load"},
3236 {bp_catch_unload
, "catch unload"},
3237 {bp_catch_fork
, "catch fork"},
3238 {bp_catch_vfork
, "catch vfork"},
3239 {bp_catch_exec
, "catch exec"},
3240 {bp_catch_catch
, "catch catch"},
3241 {bp_catch_throw
, "catch throw"}
3244 static char *bpdisps
[] =
3245 {"del", "dstp", "dis", "keep"};
3246 static char bpenables
[] = "nynny";
3247 char wrap_indent
[80];
3248 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3249 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3250 struct cleanup
*bkpt_chain
;
3253 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3257 ui_out_field_int (uiout
, "number", b
->number
);
3261 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3262 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3263 internal_error (__FILE__
, __LINE__
,
3264 "bptypes table does not describe type #%d.",
3266 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3270 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3274 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3275 ui_out_spaces (uiout
, 2);
3278 strcpy (wrap_indent
, " ");
3281 if (TARGET_ADDR_BIT
<= 32)
3282 strcat (wrap_indent
, " ");
3284 strcat (wrap_indent
, " ");
3287 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3288 b
->ops
->print_one (b
, last_addr
);
3293 internal_error (__FILE__
, __LINE__
,
3294 "print_one_breakpoint: bp_none encountered\n");
3298 case bp_hardware_watchpoint
:
3299 case bp_read_watchpoint
:
3300 case bp_access_watchpoint
:
3301 /* Field 4, the address, is omitted (which makes the columns
3302 not line up too nicely with the headers, but the effect
3303 is relatively readable). */
3305 ui_out_field_skip (uiout
, "addr");
3307 print_expression (b
->exp
, stb
->stream
);
3308 ui_out_field_stream (uiout
, "what", stb
);
3312 case bp_catch_unload
:
3313 /* Field 4, the address, is omitted (which makes the columns
3314 not line up too nicely with the headers, but the effect
3315 is relatively readable). */
3317 ui_out_field_skip (uiout
, "addr");
3319 if (b
->dll_pathname
== NULL
)
3321 ui_out_field_string (uiout
, "what", "<any library>");
3322 ui_out_spaces (uiout
, 1);
3326 ui_out_text (uiout
, "library \"");
3327 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3328 ui_out_text (uiout
, "\" ");
3333 case bp_catch_vfork
:
3334 /* Field 4, the address, is omitted (which makes the columns
3335 not line up too nicely with the headers, but the effect
3336 is relatively readable). */
3338 ui_out_field_skip (uiout
, "addr");
3340 if (b
->forked_inferior_pid
!= 0)
3342 ui_out_text (uiout
, "process ");
3343 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3344 ui_out_spaces (uiout
, 1);
3348 /* Field 4, the address, is omitted (which makes the columns
3349 not line up too nicely with the headers, but the effect
3350 is relatively readable). */
3352 ui_out_field_skip (uiout
, "addr");
3354 if (b
->exec_pathname
!= NULL
)
3356 ui_out_text (uiout
, "program \"");
3357 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3358 ui_out_text (uiout
, "\" ");
3362 case bp_catch_catch
:
3363 /* Field 4, the address, is omitted (which makes the columns
3364 not line up too nicely with the headers, but the effect
3365 is relatively readable). */
3367 ui_out_field_skip (uiout
, "addr");
3369 ui_out_field_string (uiout
, "what", "exception catch");
3370 ui_out_spaces (uiout
, 1);
3373 case bp_catch_throw
:
3374 /* Field 4, the address, is omitted (which makes the columns
3375 not line up too nicely with the headers, but the effect
3376 is relatively readable). */
3378 ui_out_field_skip (uiout
, "addr");
3380 ui_out_field_string (uiout
, "what", "exception throw");
3381 ui_out_spaces (uiout
, 1);
3385 case bp_hardware_breakpoint
:
3389 case bp_longjmp_resume
:
3390 case bp_step_resume
:
3391 case bp_through_sigtramp
:
3392 case bp_watchpoint_scope
:
3394 case bp_shlib_event
:
3395 case bp_thread_event
:
3396 case bp_overlay_event
:
3400 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3403 *last_addr
= b
->address
;
3406 sym
= find_pc_sect_function (b
->address
, b
->section
);
3409 ui_out_text (uiout
, "in ");
3410 ui_out_field_string (uiout
, "func",
3411 SYMBOL_PRINT_NAME (sym
));
3412 ui_out_wrap_hint (uiout
, wrap_indent
);
3413 ui_out_text (uiout
, " at ");
3415 ui_out_field_string (uiout
, "file", b
->source_file
);
3416 ui_out_text (uiout
, ":");
3417 ui_out_field_int (uiout
, "line", b
->line_number
);
3421 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3422 ui_out_field_stream (uiout
, "at", stb
);
3427 if (b
->thread
!= -1)
3429 /* FIXME: This seems to be redundant and lost here; see the
3430 "stop only in" line a little further down. */
3431 ui_out_text (uiout
, " thread ");
3432 ui_out_field_int (uiout
, "thread", b
->thread
);
3435 ui_out_text (uiout
, "\n");
3437 if (frame_id_p (b
->frame_id
))
3440 ui_out_text (uiout
, "\tstop only in stack frame at ");
3441 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3443 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3444 ui_out_text (uiout
, "\n");
3450 ui_out_text (uiout
, "\tstop only if ");
3451 print_expression (b
->cond
, stb
->stream
);
3452 ui_out_field_stream (uiout
, "cond", stb
);
3453 ui_out_text (uiout
, "\n");
3456 if (b
->thread
!= -1)
3458 /* FIXME should make an annotation for this */
3459 ui_out_text (uiout
, "\tstop only in thread ");
3460 ui_out_field_int (uiout
, "thread", b
->thread
);
3461 ui_out_text (uiout
, "\n");
3464 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3466 /* FIXME should make an annotation for this */
3467 if (ep_is_catchpoint (b
))
3468 ui_out_text (uiout
, "\tcatchpoint");
3470 ui_out_text (uiout
, "\tbreakpoint");
3471 ui_out_text (uiout
, " already hit ");
3472 ui_out_field_int (uiout
, "times", b
->hit_count
);
3473 if (b
->hit_count
== 1)
3474 ui_out_text (uiout
, " time\n");
3476 ui_out_text (uiout
, " times\n");
3479 /* Output the count also if it is zero, but only if this is
3480 mi. FIXME: Should have a better test for this. */
3481 if (ui_out_is_mi_like_p (uiout
))
3482 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3483 ui_out_field_int (uiout
, "times", b
->hit_count
);
3485 if (b
->ignore_count
)
3488 ui_out_text (uiout
, "\tignore next ");
3489 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3490 ui_out_text (uiout
, " hits\n");
3493 if ((l
= b
->commands
))
3495 struct cleanup
*script_chain
;
3498 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3499 print_command_lines (uiout
, l
, 4);
3500 do_cleanups (script_chain
);
3502 do_cleanups (bkpt_chain
);
3503 do_cleanups (old_chain
);
3506 struct captured_breakpoint_query_args
3512 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3514 struct captured_breakpoint_query_args
*args
= data
;
3515 register struct breakpoint
*b
;
3516 CORE_ADDR dummy_addr
= 0;
3519 if (args
->bnum
== b
->number
)
3521 print_one_breakpoint (b
, &dummy_addr
);
3529 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3531 struct captured_breakpoint_query_args args
;
3533 /* For the moment we don't trust print_one_breakpoint() to not throw
3535 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3536 NULL
, RETURN_MASK_ALL
);
3539 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3540 catchpoints, et.al.). */
3543 user_settable_breakpoint (const struct breakpoint
*b
)
3545 return (b
->type
== bp_breakpoint
3546 || b
->type
== bp_catch_load
3547 || b
->type
== bp_catch_unload
3548 || b
->type
== bp_catch_fork
3549 || b
->type
== bp_catch_vfork
3550 || b
->type
== bp_catch_exec
3551 || b
->type
== bp_catch_catch
3552 || b
->type
== bp_catch_throw
3553 || b
->type
== bp_hardware_breakpoint
3554 || b
->type
== bp_watchpoint
3555 || b
->type
== bp_read_watchpoint
3556 || b
->type
== bp_access_watchpoint
3557 || b
->type
== bp_hardware_watchpoint
);
3560 /* Print information on user settable breakpoint (watchpoint, etc)
3561 number BNUM. If BNUM is -1 print all user settable breakpoints.
3562 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3565 breakpoint_1 (int bnum
, int allflag
)
3567 register struct breakpoint
*b
;
3568 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3569 int nr_printable_breakpoints
;
3570 struct cleanup
*bkpttbl_chain
;
3572 /* Compute the number of rows in the table. */
3573 nr_printable_breakpoints
= 0;
3576 || bnum
== b
->number
)
3578 if (allflag
|| user_settable_breakpoint (b
))
3579 nr_printable_breakpoints
++;
3584 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3588 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3591 if (nr_printable_breakpoints
> 0)
3592 annotate_breakpoints_headers ();
3593 if (nr_printable_breakpoints
> 0)
3595 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3596 if (nr_printable_breakpoints
> 0)
3598 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3599 if (nr_printable_breakpoints
> 0)
3601 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3602 if (nr_printable_breakpoints
> 0)
3604 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3607 if (nr_printable_breakpoints
> 0)
3609 if (TARGET_ADDR_BIT
<= 32)
3610 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3612 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3614 if (nr_printable_breakpoints
> 0)
3616 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3617 ui_out_table_body (uiout
);
3618 if (nr_printable_breakpoints
> 0)
3619 annotate_breakpoints_table ();
3623 || bnum
== b
->number
)
3625 /* We only print out user settable breakpoints unless the
3627 if (allflag
|| user_settable_breakpoint (b
))
3628 print_one_breakpoint (b
, &last_addr
);
3631 do_cleanups (bkpttbl_chain
);
3633 if (nr_printable_breakpoints
== 0)
3636 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3638 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3643 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3644 that a comparison of an unsigned with -1 is always false. */
3645 if (last_addr
!= (CORE_ADDR
) -1)
3646 set_next_address (last_addr
);
3649 /* FIXME? Should this be moved up so that it is only called when
3650 there have been breakpoints? */
3651 annotate_breakpoints_table_end ();
3656 breakpoints_info (char *bnum_exp
, int from_tty
)
3661 bnum
= parse_and_eval_long (bnum_exp
);
3663 breakpoint_1 (bnum
, 0);
3668 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3673 bnum
= parse_and_eval_long (bnum_exp
);
3675 breakpoint_1 (bnum
, 1);
3678 /* Print a message describing any breakpoints set at PC. */
3681 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3683 register int others
= 0;
3684 register struct breakpoint
*b
;
3687 if (b
->address
== pc
) /* address match / overlay match */
3688 if (!overlay_debugging
|| b
->section
== section
)
3692 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3694 if (b
->address
== pc
) /* address match / overlay match */
3695 if (!overlay_debugging
|| b
->section
== section
)
3698 printf_filtered ("%d%s%s ",
3700 ((b
->enable_state
== bp_disabled
||
3701 b
->enable_state
== bp_shlib_disabled
||
3702 b
->enable_state
== bp_call_disabled
)
3704 : b
->enable_state
== bp_permanent
3708 : ((others
== 1) ? " and" : ""));
3710 printf_filtered ("also set at pc ");
3711 print_address_numeric (pc
, 1, gdb_stdout
);
3712 printf_filtered (".\n");
3716 /* Set the default place to put a breakpoint
3717 for the `break' command with no arguments. */
3720 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3723 default_breakpoint_valid
= valid
;
3724 default_breakpoint_address
= addr
;
3725 default_breakpoint_symtab
= symtab
;
3726 default_breakpoint_line
= line
;
3729 /* Return true iff it is meaningful to use the address member of
3730 BPT. For some breakpoint types, the address member is irrelevant
3731 and it makes no sense to attempt to compare it to other addresses
3732 (or use it for any other purpose either).
3734 More specifically, each of the following breakpoint types will always
3735 have a zero valued address and we don't want check_duplicates() to mark
3736 breakpoints of any of these types to be a duplicate of an actual
3737 breakpoint at address zero:
3740 bp_hardware_watchpoint
3742 bp_access_watchpoint
3749 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3751 enum bptype type
= bpt
->type
;
3753 return (type
!= bp_watchpoint
3754 && type
!= bp_hardware_watchpoint
3755 && type
!= bp_read_watchpoint
3756 && type
!= bp_access_watchpoint
3757 && type
!= bp_catch_exec
3758 && type
!= bp_longjmp_resume
3759 && type
!= bp_catch_fork
3760 && type
!= bp_catch_vfork
);
3763 /* Rescan breakpoints at the same address and section as BPT,
3764 marking the first one as "first" and any others as "duplicates".
3765 This is so that the bpt instruction is only inserted once.
3766 If we have a permanent breakpoint at the same place as BPT, make
3767 that one the official one, and the rest as duplicates. */
3770 check_duplicates (struct breakpoint
*bpt
)
3772 register struct breakpoint
*b
;
3773 register int count
= 0;
3774 struct breakpoint
*perm_bp
= 0;
3775 CORE_ADDR address
= bpt
->address
;
3776 asection
*section
= bpt
->section
;
3778 if (! breakpoint_address_is_meaningful (bpt
))
3782 if (b
->enable_state
!= bp_disabled
3783 && b
->enable_state
!= bp_shlib_disabled
3784 && b
->enable_state
!= bp_call_disabled
3785 && b
->address
== address
/* address / overlay match */
3786 && (!overlay_debugging
|| b
->section
== section
)
3787 && breakpoint_address_is_meaningful (b
))
3789 /* Have we found a permanent breakpoint? */
3790 if (b
->enable_state
== bp_permanent
)
3797 b
->duplicate
= count
> 1;
3800 /* If we found a permanent breakpoint at this address, go over the
3801 list again and declare all the other breakpoints there to be the
3805 perm_bp
->duplicate
= 0;
3807 /* Permanent breakpoint should always be inserted. */
3808 if (! perm_bp
->inserted
)
3809 internal_error (__FILE__
, __LINE__
,
3810 "allegedly permanent breakpoint is not "
3811 "actually inserted");
3817 internal_error (__FILE__
, __LINE__
,
3818 "another breakpoint was inserted on top of "
3819 "a permanent breakpoint");
3821 if (b
->enable_state
!= bp_disabled
3822 && b
->enable_state
!= bp_shlib_disabled
3823 && b
->enable_state
!= bp_call_disabled
3824 && b
->address
== address
/* address / overlay match */
3825 && (!overlay_debugging
|| b
->section
== section
)
3826 && breakpoint_address_is_meaningful (b
))
3832 /* set_raw_breakpoint() is a low level routine for allocating and
3833 partially initializing a breakpoint of type BPTYPE. The newly
3834 created breakpoint's address, section, source file name, and line
3835 number are provided by SAL. The newly created and partially
3836 initialized breakpoint is added to the breakpoint chain and
3837 is also returned as the value of this function.
3839 It is expected that the caller will complete the initialization of
3840 the newly created breakpoint struct as well as output any status
3841 information regarding the creation of a new breakpoint. In
3842 particular, set_raw_breakpoint() does NOT set the breakpoint
3843 number! Care should be taken to not allow an error() to occur
3844 prior to completing the initialization of the breakpoint. If this
3845 should happen, a bogus breakpoint will be left on the chain. */
3848 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3850 register struct breakpoint
*b
, *b1
;
3852 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3853 memset (b
, 0, sizeof (*b
));
3854 b
->address
= sal
.pc
;
3855 if (sal
.symtab
== NULL
)
3856 b
->source_file
= NULL
;
3858 b
->source_file
= savestring (sal
.symtab
->filename
,
3859 strlen (sal
.symtab
->filename
));
3860 b
->section
= sal
.section
;
3862 b
->language
= current_language
->la_language
;
3863 b
->input_radix
= input_radix
;
3865 b
->line_number
= sal
.line
;
3866 b
->enable_state
= bp_enabled
;
3869 b
->ignore_count
= 0;
3871 b
->frame_id
= null_frame_id
;
3872 b
->dll_pathname
= NULL
;
3873 b
->triggered_dll_pathname
= NULL
;
3874 b
->forked_inferior_pid
= 0;
3875 b
->exec_pathname
= NULL
;
3878 /* Add this breakpoint to the end of the chain
3879 so that a list of breakpoints will come out in order
3880 of increasing numbers. */
3882 b1
= breakpoint_chain
;
3884 breakpoint_chain
= b
;
3892 check_duplicates (b
);
3893 breakpoints_changed ();
3899 /* Note that the breakpoint object B describes a permanent breakpoint
3900 instruction, hard-wired into the inferior's code. */
3902 make_breakpoint_permanent (struct breakpoint
*b
)
3904 b
->enable_state
= bp_permanent
;
3906 /* By definition, permanent breakpoints are already present in the code. */
3910 static struct breakpoint
*
3911 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3913 static int internal_breakpoint_number
= -1;
3914 struct symtab_and_line sal
;
3915 struct breakpoint
*b
;
3917 init_sal (&sal
); /* initialize to zeroes */
3920 sal
.section
= find_pc_overlay (sal
.pc
);
3922 b
= set_raw_breakpoint (sal
, type
);
3923 b
->number
= internal_breakpoint_number
--;
3924 b
->disposition
= disp_donttouch
;
3931 create_longjmp_breakpoint (char *func_name
)
3933 struct breakpoint
*b
;
3934 struct minimal_symbol
*m
;
3936 if (func_name
== NULL
)
3937 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3940 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3943 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3946 b
->enable_state
= bp_disabled
;
3949 b
->addr_string
= xstrdup (func_name
);
3952 /* Call this routine when stepping and nexting to enable a breakpoint
3953 if we do a longjmp(). When we hit that breakpoint, call
3954 set_longjmp_resume_breakpoint() to figure out where we are going. */
3957 enable_longjmp_breakpoint (void)
3959 register struct breakpoint
*b
;
3962 if (b
->type
== bp_longjmp
)
3964 b
->enable_state
= bp_enabled
;
3965 check_duplicates (b
);
3970 disable_longjmp_breakpoint (void)
3972 register struct breakpoint
*b
;
3975 if (b
->type
== bp_longjmp
3976 || b
->type
== bp_longjmp_resume
)
3978 b
->enable_state
= bp_disabled
;
3979 check_duplicates (b
);
3984 create_overlay_event_breakpoint (char *func_name
)
3986 struct breakpoint
*b
;
3987 struct minimal_symbol
*m
;
3989 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3992 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
3994 b
->addr_string
= xstrdup (func_name
);
3996 if (overlay_debugging
== ovly_auto
)
3998 b
->enable_state
= bp_enabled
;
3999 overlay_events_enabled
= 1;
4003 b
->enable_state
= bp_disabled
;
4004 overlay_events_enabled
= 0;
4009 enable_overlay_breakpoints (void)
4011 register struct breakpoint
*b
;
4014 if (b
->type
== bp_overlay_event
)
4016 b
->enable_state
= bp_enabled
;
4017 check_duplicates (b
);
4018 overlay_events_enabled
= 1;
4023 disable_overlay_breakpoints (void)
4025 register struct breakpoint
*b
;
4028 if (b
->type
== bp_overlay_event
)
4030 b
->enable_state
= bp_disabled
;
4031 check_duplicates (b
);
4032 overlay_events_enabled
= 0;
4037 create_thread_event_breakpoint (CORE_ADDR address
)
4039 struct breakpoint
*b
;
4041 b
= create_internal_breakpoint (address
, bp_thread_event
);
4043 b
->enable_state
= bp_enabled
;
4044 /* addr_string has to be used or breakpoint_re_set will delete me. */
4045 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->address
));
4051 remove_thread_event_breakpoints (void)
4053 struct breakpoint
*b
, *temp
;
4055 ALL_BREAKPOINTS_SAFE (b
, temp
)
4056 if (b
->type
== bp_thread_event
)
4057 delete_breakpoint (b
);
4062 remove_solib_event_breakpoints (void)
4064 register struct breakpoint
*b
, *temp
;
4066 ALL_BREAKPOINTS_SAFE (b
, temp
)
4067 if (b
->type
== bp_shlib_event
)
4068 delete_breakpoint (b
);
4072 create_solib_event_breakpoint (CORE_ADDR address
)
4074 struct breakpoint
*b
;
4076 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4080 /* Disable any breakpoints that are on code in shared libraries. Only
4081 apply to enabled breakpoints, disabled ones can just stay disabled. */
4084 disable_breakpoints_in_shlibs (int silent
)
4086 struct breakpoint
*b
;
4087 int disabled_shlib_breaks
= 0;
4089 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4092 #if defined (PC_SOLIB)
4093 if (((b
->type
== bp_breakpoint
) ||
4094 (b
->type
== bp_hardware_breakpoint
)) &&
4095 b
->enable_state
== bp_enabled
&&
4097 PC_SOLIB (b
->address
))
4099 b
->enable_state
= bp_shlib_disabled
;
4102 if (!disabled_shlib_breaks
)
4104 target_terminal_ours_for_output ();
4105 warning ("Temporarily disabling shared library breakpoints:");
4107 disabled_shlib_breaks
= 1;
4108 warning ("breakpoint #%d ", b
->number
);
4115 /* Try to reenable any breakpoints in shared libraries. */
4117 re_enable_breakpoints_in_shlibs (void)
4119 struct breakpoint
*b
;
4122 if (b
->enable_state
== bp_shlib_disabled
)
4126 /* Do not reenable the breakpoint if the shared library
4127 is still not mapped in. */
4128 if (target_read_memory (b
->address
, buf
, 1) == 0)
4129 b
->enable_state
= bp_enabled
;
4136 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4137 char *cond_string
, enum bptype bp_kind
)
4139 struct breakpoint
*b
;
4140 struct symtabs_and_lines sals
;
4141 struct cleanup
*old_chain
;
4142 struct cleanup
*canonical_strings_chain
= NULL
;
4143 char *addr_start
= hookname
;
4144 char *addr_end
= NULL
;
4145 char **canonical
= (char **) NULL
;
4146 int thread
= -1; /* All threads. */
4148 /* Set a breakpoint on the specified hook. */
4149 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4150 addr_end
= hookname
;
4152 if (sals
.nelts
== 0)
4154 warning ("Unable to set a breakpoint on dynamic linker callback.");
4155 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4156 warning ("GDB will be unable to track shl_load/shl_unload calls");
4159 if (sals
.nelts
!= 1)
4161 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4162 warning ("GDB will be unable to track shl_load/shl_unload calls");
4166 /* Make sure that all storage allocated in decode_line_1 gets freed
4167 in case the following errors out. */
4168 old_chain
= make_cleanup (xfree
, sals
.sals
);
4169 if (canonical
!= (char **) NULL
)
4171 make_cleanup (xfree
, canonical
);
4172 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4173 if (canonical
[0] != NULL
)
4174 make_cleanup (xfree
, canonical
[0]);
4177 resolve_sal_pc (&sals
.sals
[0]);
4179 /* Remove the canonical strings from the cleanup, they are needed below. */
4180 if (canonical
!= (char **) NULL
)
4181 discard_cleanups (canonical_strings_chain
);
4183 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4184 set_breakpoint_count (breakpoint_count
+ 1);
4185 b
->number
= breakpoint_count
;
4187 b
->cond_string
= (cond_string
== NULL
) ?
4188 NULL
: savestring (cond_string
, strlen (cond_string
));
4191 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4192 b
->addr_string
= canonical
[0];
4193 else if (addr_start
)
4194 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4196 b
->enable_state
= bp_enabled
;
4197 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4199 if (dll_pathname
== NULL
)
4200 b
->dll_pathname
= NULL
;
4203 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4204 strcpy (b
->dll_pathname
, dll_pathname
);
4208 do_cleanups (old_chain
);
4212 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4213 char *dll_pathname
, char *cond_string
)
4215 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4216 cond_string
, bp_catch_load
);
4220 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4221 char *dll_pathname
, char *cond_string
)
4223 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4224 cond_string
, bp_catch_unload
);
4228 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4229 enum bptype bp_kind
)
4231 struct symtab_and_line sal
;
4232 struct breakpoint
*b
;
4233 int thread
= -1; /* All threads. */
4240 b
= set_raw_breakpoint (sal
, bp_kind
);
4241 set_breakpoint_count (breakpoint_count
+ 1);
4242 b
->number
= breakpoint_count
;
4244 b
->cond_string
= (cond_string
== NULL
) ?
4245 NULL
: savestring (cond_string
, strlen (cond_string
));
4247 b
->addr_string
= NULL
;
4248 b
->enable_state
= bp_enabled
;
4249 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4250 b
->forked_inferior_pid
= 0;
4256 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4258 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4262 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4264 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4268 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4270 struct symtab_and_line sal
;
4271 struct breakpoint
*b
;
4272 int thread
= -1; /* All threads. */
4279 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4280 set_breakpoint_count (breakpoint_count
+ 1);
4281 b
->number
= breakpoint_count
;
4283 b
->cond_string
= (cond_string
== NULL
) ?
4284 NULL
: savestring (cond_string
, strlen (cond_string
));
4286 b
->addr_string
= NULL
;
4287 b
->enable_state
= bp_enabled
;
4288 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4294 hw_breakpoint_used_count (void)
4296 register struct breakpoint
*b
;
4301 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4309 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4311 register struct breakpoint
*b
;
4314 *other_type_used
= 0;
4317 if (b
->enable_state
== bp_enabled
)
4319 if (b
->type
== type
)
4321 else if ((b
->type
== bp_hardware_watchpoint
||
4322 b
->type
== bp_read_watchpoint
||
4323 b
->type
== bp_access_watchpoint
)
4324 && b
->enable_state
== bp_enabled
)
4325 *other_type_used
= 1;
4331 /* Call this after hitting the longjmp() breakpoint. Use this to set
4332 a new breakpoint at the target of the jmp_buf.
4334 FIXME - This ought to be done by setting a temporary breakpoint
4335 that gets deleted automatically... */
4338 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4340 register struct breakpoint
*b
;
4343 if (b
->type
== bp_longjmp_resume
)
4346 b
->enable_state
= bp_enabled
;
4347 b
->frame_id
= frame_id
;
4348 check_duplicates (b
);
4354 disable_watchpoints_before_interactive_call_start (void)
4356 struct breakpoint
*b
;
4360 if (((b
->type
== bp_watchpoint
)
4361 || (b
->type
== bp_hardware_watchpoint
)
4362 || (b
->type
== bp_read_watchpoint
)
4363 || (b
->type
== bp_access_watchpoint
)
4364 || ep_is_exception_catchpoint (b
))
4365 && (b
->enable_state
== bp_enabled
))
4367 b
->enable_state
= bp_call_disabled
;
4368 check_duplicates (b
);
4374 enable_watchpoints_after_interactive_call_stop (void)
4376 struct breakpoint
*b
;
4380 if (((b
->type
== bp_watchpoint
)
4381 || (b
->type
== bp_hardware_watchpoint
)
4382 || (b
->type
== bp_read_watchpoint
)
4383 || (b
->type
== bp_access_watchpoint
)
4384 || ep_is_exception_catchpoint (b
))
4385 && (b
->enable_state
== bp_call_disabled
))
4387 b
->enable_state
= bp_enabled
;
4388 check_duplicates (b
);
4394 /* Set a breakpoint that will evaporate an end of command
4395 at address specified by SAL.
4396 Restrict it to frame FRAME if FRAME is nonzero. */
4399 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4402 register struct breakpoint
*b
;
4403 b
= set_raw_breakpoint (sal
, type
);
4404 b
->enable_state
= bp_enabled
;
4405 b
->disposition
= disp_donttouch
;
4406 b
->frame_id
= frame_id
;
4408 /* If we're debugging a multi-threaded program, then we
4409 want momentary breakpoints to be active in only a
4410 single thread of control. */
4411 if (in_thread_list (inferior_ptid
))
4412 b
->thread
= pid_to_thread_id (inferior_ptid
);
4418 /* Tell the user we have just set a breakpoint B. */
4421 mention (struct breakpoint
*b
)
4424 struct cleanup
*old_chain
, *ui_out_chain
;
4425 struct ui_stream
*stb
;
4427 stb
= ui_out_stream_new (uiout
);
4428 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4430 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4431 watchpoint) other than breakpoint creation. It should be possible to
4432 clean this up and at the same time replace the random calls to
4433 breakpoint_changed with this hook, as has already been done for
4434 delete_breakpoint_hook and so on. */
4435 if (create_breakpoint_hook
)
4436 create_breakpoint_hook (b
);
4437 breakpoint_create_event (b
->number
);
4439 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4440 b
->ops
->print_mention (b
);
4445 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4448 ui_out_text (uiout
, "Watchpoint ");
4449 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4450 ui_out_field_int (uiout
, "number", b
->number
);
4451 ui_out_text (uiout
, ": ");
4452 print_expression (b
->exp
, stb
->stream
);
4453 ui_out_field_stream (uiout
, "exp", stb
);
4454 do_cleanups (ui_out_chain
);
4456 case bp_hardware_watchpoint
:
4457 ui_out_text (uiout
, "Hardware watchpoint ");
4458 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4459 ui_out_field_int (uiout
, "number", b
->number
);
4460 ui_out_text (uiout
, ": ");
4461 print_expression (b
->exp
, stb
->stream
);
4462 ui_out_field_stream (uiout
, "exp", stb
);
4463 do_cleanups (ui_out_chain
);
4465 case bp_read_watchpoint
:
4466 ui_out_text (uiout
, "Hardware read watchpoint ");
4467 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4468 ui_out_field_int (uiout
, "number", b
->number
);
4469 ui_out_text (uiout
, ": ");
4470 print_expression (b
->exp
, stb
->stream
);
4471 ui_out_field_stream (uiout
, "exp", stb
);
4472 do_cleanups (ui_out_chain
);
4474 case bp_access_watchpoint
:
4475 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4476 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4477 ui_out_field_int (uiout
, "number", b
->number
);
4478 ui_out_text (uiout
, ": ");
4479 print_expression (b
->exp
, stb
->stream
);
4480 ui_out_field_stream (uiout
, "exp", stb
);
4481 do_cleanups (ui_out_chain
);
4484 if (ui_out_is_mi_like_p (uiout
))
4489 printf_filtered ("Breakpoint %d", b
->number
);
4492 case bp_hardware_breakpoint
:
4493 if (ui_out_is_mi_like_p (uiout
))
4498 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4502 case bp_catch_unload
:
4503 printf_filtered ("Catchpoint %d (%s %s)",
4505 (b
->type
== bp_catch_load
) ? "load" : "unload",
4506 (b
->dll_pathname
!= NULL
) ?
4507 b
->dll_pathname
: "<any library>");
4510 case bp_catch_vfork
:
4511 printf_filtered ("Catchpoint %d (%s)",
4513 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4516 printf_filtered ("Catchpoint %d (exec)",
4519 case bp_catch_catch
:
4520 case bp_catch_throw
:
4521 printf_filtered ("Catchpoint %d (%s)",
4523 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4529 case bp_longjmp_resume
:
4530 case bp_step_resume
:
4531 case bp_through_sigtramp
:
4533 case bp_watchpoint_scope
:
4534 case bp_shlib_event
:
4535 case bp_thread_event
:
4536 case bp_overlay_event
:
4542 if (addressprint
|| b
->source_file
== NULL
)
4544 printf_filtered (" at ");
4545 print_address_numeric (b
->address
, 1, gdb_stdout
);
4548 printf_filtered (": file %s, line %d.",
4549 b
->source_file
, b
->line_number
);
4551 do_cleanups (old_chain
);
4552 if (ui_out_is_mi_like_p (uiout
))
4554 printf_filtered ("\n");
4558 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4559 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4560 COND[i] and COND_STRING[i] values.
4562 NOTE: If the function succeeds, the caller is expected to cleanup
4563 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4564 array contents). If the function fails (error() is called), the
4565 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4566 COND and SALS arrays and each of those arrays contents. */
4569 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4570 struct expression
**cond
, char **cond_string
,
4571 enum bptype type
, enum bpdisp disposition
,
4572 int thread
, int ignore_count
, int from_tty
)
4574 if (type
== bp_hardware_breakpoint
)
4576 int i
= hw_breakpoint_used_count ();
4577 int target_resources_ok
=
4578 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4580 if (target_resources_ok
== 0)
4581 error ("No hardware breakpoint support in the target.");
4582 else if (target_resources_ok
< 0)
4583 error ("Hardware breakpoints used exceeds limit.");
4586 /* Now set all the breakpoints. */
4589 for (i
= 0; i
< sals
.nelts
; i
++)
4591 struct breakpoint
*b
;
4592 struct symtab_and_line sal
= sals
.sals
[i
];
4595 describe_other_breakpoints (sal
.pc
, sal
.section
);
4597 b
= set_raw_breakpoint (sal
, type
);
4598 set_breakpoint_count (breakpoint_count
+ 1);
4599 b
->number
= breakpoint_count
;
4603 b
->addr_string
= addr_string
[i
];
4605 /* addr_string has to be used or breakpoint_re_set will delete
4607 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->address
));
4608 b
->cond_string
= cond_string
[i
];
4609 b
->ignore_count
= ignore_count
;
4610 b
->enable_state
= bp_enabled
;
4611 b
->disposition
= disposition
;
4617 /* Parse ARG which is assumed to be a SAL specification possibly
4618 followed by conditionals. On return, SALS contains an array of SAL
4619 addresses found. ADDR_STRING contains a vector of (canonical)
4620 address strings. ARG points to the end of the SAL. */
4623 parse_breakpoint_sals (char **address
,
4624 struct symtabs_and_lines
*sals
,
4625 char ***addr_string
)
4627 char *addr_start
= *address
;
4628 *addr_string
= NULL
;
4629 /* If no arg given, or if first arg is 'if ', use the default
4631 if ((*address
) == NULL
4632 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4634 if (default_breakpoint_valid
)
4636 struct symtab_and_line sal
;
4637 init_sal (&sal
); /* initialize to zeroes */
4638 sals
->sals
= (struct symtab_and_line
*)
4639 xmalloc (sizeof (struct symtab_and_line
));
4640 sal
.pc
= default_breakpoint_address
;
4641 sal
.line
= default_breakpoint_line
;
4642 sal
.symtab
= default_breakpoint_symtab
;
4643 sal
.section
= find_pc_overlay (sal
.pc
);
4644 sals
->sals
[0] = sal
;
4648 error ("No default breakpoint address now.");
4652 /* Force almost all breakpoints to be in terms of the
4653 current_source_symtab (which is decode_line_1's default). This
4654 should produce the results we want almost all of the time while
4655 leaving default_breakpoint_* alone.
4656 ObjC: However, don't match an Objective-C method name which
4657 may have a '+' or '-' succeeded by a '[' */
4659 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
4661 if (default_breakpoint_valid
4663 || ((strchr ("+-", (*address
)[0]) != NULL
)
4664 && ((*address
)[1] != '['))))
4665 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4666 default_breakpoint_line
, addr_string
);
4668 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4670 /* For any SAL that didn't have a canonical string, fill one in. */
4671 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4672 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4673 if (addr_start
!= (*address
))
4676 for (i
= 0; i
< sals
->nelts
; i
++)
4678 /* Add the string if not present. */
4679 if ((*addr_string
)[i
] == NULL
)
4680 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4686 /* Convert each SAL into a real PC. Verify that the PC can be
4687 inserted as a breakpoint. If it can't throw an error. */
4690 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4694 for (i
= 0; i
< sals
->nelts
; i
++)
4696 resolve_sal_pc (&sals
->sals
[i
]);
4698 /* It's possible for the PC to be nonzero, but still an illegal
4699 value on some targets.
4701 For example, on HP-UX if you start gdb, and before running the
4702 inferior you try to set a breakpoint on a shared library function
4703 "foo" where the inferior doesn't call "foo" directly but does
4704 pass its address to another function call, then we do find a
4705 minimal symbol for the "foo", but it's address is invalid.
4706 (Appears to be an index into a table that the loader sets up
4707 when the inferior is run.)
4709 Give the target a chance to bless sals.sals[i].pc before we
4710 try to make a breakpoint for it. */
4711 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4713 if (address
== NULL
)
4714 error ("Cannot break without a running program.");
4716 error ("Cannot break on %s without a running program.",
4722 /* Set a breakpoint according to ARG (function, linenum or *address)
4723 flag: first bit : 0 non-temporary, 1 temporary.
4724 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4727 break_command_1 (char *arg
, int flag
, int from_tty
)
4729 int tempflag
, hardwareflag
;
4730 struct symtabs_and_lines sals
;
4731 register struct expression
**cond
= 0;
4732 /* Pointers in arg to the start, and one past the end, of the
4734 char **cond_string
= (char **) NULL
;
4735 char *addr_start
= arg
;
4737 struct cleanup
*old_chain
;
4738 struct cleanup
*breakpoint_chain
= NULL
;
4741 int ignore_count
= 0;
4743 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4744 tempflag
= flag
& BP_TEMPFLAG
;
4749 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4754 /* Create a chain of things that always need to be cleaned up. */
4755 old_chain
= make_cleanup (null_cleanup
, 0);
4757 /* Make sure that all storage allocated to SALS gets freed. */
4758 make_cleanup (xfree
, sals
.sals
);
4760 /* Cleanup the addr_string array but not its contents. */
4761 make_cleanup (xfree
, addr_string
);
4763 /* Allocate space for all the cond expressions. */
4764 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4765 make_cleanup (xfree
, cond
);
4767 /* Allocate space for all the cond strings. */
4768 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4769 make_cleanup (xfree
, cond_string
);
4771 /* ----------------------------- SNIP -----------------------------
4772 Anything added to the cleanup chain beyond this point is assumed
4773 to be part of a breakpoint. If the breakpoint create succeeds
4774 then the memory is not reclaimed. */
4775 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4777 /* Mark the contents of the addr_string for cleanup. These go on
4778 the breakpoint_chain and only occure if the breakpoint create
4780 for (i
= 0; i
< sals
.nelts
; i
++)
4782 if (addr_string
[i
] != NULL
)
4783 make_cleanup (xfree
, addr_string
[i
]);
4786 /* Resolve all line numbers to PC's and verify that the addresses
4787 are ok for the target. */
4788 breakpoint_sals_to_pc (&sals
, addr_start
);
4790 /* Verify that condition can be parsed, before setting any
4791 breakpoints. Allocate a separate condition expression for each
4793 thread
= -1; /* No specific thread yet */
4794 for (i
= 0; i
< sals
.nelts
; i
++)
4801 char *cond_start
= NULL
;
4802 char *cond_end
= NULL
;
4803 while (*tok
== ' ' || *tok
== '\t')
4808 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4811 toklen
= end_tok
- tok
;
4813 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4815 tok
= cond_start
= end_tok
+ 1;
4816 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4817 make_cleanup (xfree
, cond
[i
]);
4819 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4820 make_cleanup (xfree
, cond_string
[i
]);
4822 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4828 thread
= strtol (tok
, &tok
, 0);
4830 error ("Junk after thread keyword.");
4831 if (!valid_thread_id (thread
))
4832 error ("Unknown thread %d\n", thread
);
4835 error ("Junk at end of arguments.");
4839 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4840 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4841 tempflag
? disp_del
: disp_donttouch
,
4842 thread
, ignore_count
, from_tty
);
4846 warning ("Multiple breakpoints were set.");
4847 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4849 /* That's it. Discard the cleanups for data inserted into the
4851 discard_cleanups (breakpoint_chain
);
4852 /* But cleanup everything else. */
4853 do_cleanups (old_chain
);
4856 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4857 linenum or *address) with COND and IGNORE_COUNT. */
4859 struct captured_breakpoint_args
4870 do_captured_breakpoint (void *data
)
4872 struct captured_breakpoint_args
*args
= data
;
4873 struct symtabs_and_lines sals
;
4874 register struct expression
**cond
;
4875 struct cleanup
*old_chain
;
4876 struct cleanup
*breakpoint_chain
= NULL
;
4883 /* Parse the source and lines spec. Delay check that the expression
4884 didn't contain trailing garbage until after cleanups are in
4888 address_end
= args
->address
;
4890 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4895 /* Create a chain of things at always need to be cleaned up. */
4896 old_chain
= make_cleanup (null_cleanup
, 0);
4898 /* Always have a addr_string array, even if it is empty. */
4899 make_cleanup (xfree
, addr_string
);
4901 /* Make sure that all storage allocated to SALS gets freed. */
4902 make_cleanup (xfree
, sals
.sals
);
4904 /* Allocate space for all the cond expressions. */
4905 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4906 make_cleanup (xfree
, cond
);
4908 /* Allocate space for all the cond strings. */
4909 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4910 make_cleanup (xfree
, cond_string
);
4912 /* ----------------------------- SNIP -----------------------------
4913 Anything added to the cleanup chain beyond this point is assumed
4914 to be part of a breakpoint. If the breakpoint create goes
4915 through then that memory is not cleaned up. */
4916 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4918 /* Mark the contents of the addr_string for cleanup. These go on
4919 the breakpoint_chain and only occure if the breakpoint create
4921 for (i
= 0; i
< sals
.nelts
; i
++)
4923 if (addr_string
[i
] != NULL
)
4924 make_cleanup (xfree
, addr_string
[i
]);
4927 /* Wait until now before checking for garbage at the end of the
4928 address. That way cleanups can take care of freeing any
4930 if (*address_end
!= '\0')
4931 error ("Garbage %s following breakpoint address", address_end
);
4933 /* Resolve all line numbers to PC's. */
4934 breakpoint_sals_to_pc (&sals
, args
->address
);
4936 /* Verify that conditions can be parsed, before setting any
4938 for (i
= 0; i
< sals
.nelts
; i
++)
4940 if (args
->condition
!= NULL
)
4942 char *tok
= args
->condition
;
4943 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4945 error ("Garbage %s follows condition", tok
);
4946 make_cleanup (xfree
, cond
[i
]);
4947 cond_string
[i
] = xstrdup (args
->condition
);
4951 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4952 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4953 args
->tempflag
? disp_del
: disp_donttouch
,
4954 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4956 /* That's it. Discard the cleanups for data inserted into the
4958 discard_cleanups (breakpoint_chain
);
4959 /* But cleanup everything else. */
4960 do_cleanups (old_chain
);
4965 gdb_breakpoint (char *address
, char *condition
,
4966 int hardwareflag
, int tempflag
,
4967 int thread
, int ignore_count
)
4969 struct captured_breakpoint_args args
;
4970 args
.address
= address
;
4971 args
.condition
= condition
;
4972 args
.hardwareflag
= hardwareflag
;
4973 args
.tempflag
= tempflag
;
4974 args
.thread
= thread
;
4975 args
.ignore_count
= ignore_count
;
4976 return catch_errors (do_captured_breakpoint
, &args
,
4977 NULL
, RETURN_MASK_ALL
);
4982 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4984 struct frame_info
*frame
;
4985 CORE_ADDR low
, high
, selected_pc
= 0;
4986 char *extra_args
= NULL
;
4989 int extra_args_len
= 0, if_arg
= 0;
4992 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4995 if (default_breakpoint_valid
)
4997 if (deprecated_selected_frame
)
4999 selected_pc
= get_frame_pc (deprecated_selected_frame
);
5004 error ("No selected frame.");
5007 error ("No default breakpoint address now.");
5011 extra_args
= strchr (arg
, ' ');
5015 extra_args_len
= strlen (extra_args
);
5016 level_arg
= (char *) xmalloc (extra_args
- arg
);
5017 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5018 level_arg
[extra_args
- arg
- 1] = '\0';
5022 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5023 strcpy (level_arg
, arg
);
5026 frame
= parse_frame_specification (level_arg
);
5028 selected_pc
= get_frame_pc (frame
);
5035 extra_args_len
= strlen (arg
);
5040 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5042 addr_string
= (char *) xmalloc (26 + extra_args_len
);
5044 sprintf (addr_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5046 sprintf (addr_string
, "*0x%s", paddr_nz (high
));
5047 break_command_1 (addr_string
, flag
, from_tty
);
5048 xfree (addr_string
);
5051 error ("No function contains the specified address");
5054 error ("Unable to set breakpoint at procedure exit");
5059 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5061 char *addr_string
, *break_string
, *beg_addr_string
;
5062 CORE_ADDR low
, high
;
5063 struct symtabs_and_lines sals
;
5064 struct symtab_and_line sal
;
5065 struct cleanup
*old_chain
;
5066 char *extra_args
= NULL
;
5067 int extra_args_len
= 0;
5071 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5073 if (default_breakpoint_valid
)
5075 if (deprecated_selected_frame
)
5077 addr_string
= (char *) xmalloc (15);
5078 sprintf (addr_string
, "*0x%s",
5079 paddr_nz (get_frame_pc (deprecated_selected_frame
)));
5084 error ("No selected frame.");
5087 error ("No default breakpoint address now.");
5091 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5092 strcpy (addr_string
, arg
);
5098 extra_args_len
= strlen (arg
);
5102 /* get the stuff after the function name or address */
5103 extra_args
= strchr (arg
, ' ');
5107 extra_args_len
= strlen (extra_args
);
5114 beg_addr_string
= addr_string
;
5115 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5118 xfree (beg_addr_string
);
5119 old_chain
= make_cleanup (xfree
, sals
.sals
);
5120 for (i
= 0; (i
< sals
.nelts
); i
++)
5123 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5125 break_string
= (char *) xmalloc (extra_args_len
+ 26);
5127 sprintf (break_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5129 sprintf (break_string
, "*0x%s", paddr_nz (high
));
5130 break_command_1 (break_string
, flag
, from_tty
);
5131 xfree (break_string
);
5134 error ("No function contains the specified address");
5138 warning ("Multiple breakpoints were set.\n");
5139 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5141 do_cleanups (old_chain
);
5145 /* Helper function for break_command_1 and disassemble_command. */
5148 resolve_sal_pc (struct symtab_and_line
*sal
)
5152 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5154 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5155 error ("No line %d in file \"%s\".",
5156 sal
->line
, sal
->symtab
->filename
);
5160 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5162 struct blockvector
*bv
;
5167 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5170 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5171 sym
= block_function (b
);
5174 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5175 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5179 /* It really is worthwhile to have the section, so we'll just
5180 have to look harder. This case can be executed if we have
5181 line numbers but no functions (as can happen in assembly
5184 struct minimal_symbol
*msym
;
5186 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5188 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5195 break_command (char *arg
, int from_tty
)
5197 break_command_1 (arg
, 0, from_tty
);
5201 break_at_finish_command (char *arg
, int from_tty
)
5203 break_at_finish_command_1 (arg
, 0, from_tty
);
5207 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5209 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5213 tbreak_command (char *arg
, int from_tty
)
5215 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5219 tbreak_at_finish_command (char *arg
, int from_tty
)
5221 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5225 hbreak_command (char *arg
, int from_tty
)
5227 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5231 thbreak_command (char *arg
, int from_tty
)
5233 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5237 stop_command (char *arg
, int from_tty
)
5239 printf_filtered ("Specify the type of breakpoint to set.\n\
5240 Usage: stop in <function | address>\n\
5245 stopin_command (char *arg
, int from_tty
)
5249 if (arg
== (char *) NULL
)
5251 else if (*arg
!= '*')
5256 /* look for a ':'. If this is a line number specification, then
5257 say it is bad, otherwise, it should be an address or
5258 function/method name */
5259 while (*argptr
&& !hasColon
)
5261 hasColon
= (*argptr
== ':');
5266 badInput
= (*argptr
!= ':'); /* Not a class::method */
5268 badInput
= isdigit (*arg
); /* a simple line number */
5272 printf_filtered ("Usage: stop in <function | address>\n");
5274 break_command_1 (arg
, 0, from_tty
);
5278 stopat_command (char *arg
, int from_tty
)
5282 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5289 /* look for a ':'. If there is a '::' then get out, otherwise
5290 it is probably a line number. */
5291 while (*argptr
&& !hasColon
)
5293 hasColon
= (*argptr
== ':');
5298 badInput
= (*argptr
== ':'); /* we have class::method */
5300 badInput
= !isdigit (*arg
); /* not a line number */
5304 printf_filtered ("Usage: stop at <line>\n");
5306 break_command_1 (arg
, 0, from_tty
);
5310 /* accessflag: hw_write: watch write,
5311 hw_read: watch read,
5312 hw_access: watch access (read or write) */
5314 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5316 struct breakpoint
*b
;
5317 struct symtab_and_line sal
;
5318 struct expression
*exp
;
5319 struct block
*exp_valid_block
;
5320 struct value
*val
, *mark
;
5321 struct frame_info
*frame
;
5322 struct frame_info
*prev_frame
= NULL
;
5323 char *exp_start
= NULL
;
5324 char *exp_end
= NULL
;
5325 char *tok
, *end_tok
;
5327 char *cond_start
= NULL
;
5328 char *cond_end
= NULL
;
5329 struct expression
*cond
= NULL
;
5330 int i
, other_type_used
, target_resources_ok
= 0;
5331 enum bptype bp_type
;
5334 init_sal (&sal
); /* initialize to zeroes */
5336 /* Parse arguments. */
5337 innermost_block
= NULL
;
5339 exp
= parse_exp_1 (&arg
, 0, 0);
5341 exp_valid_block
= innermost_block
;
5342 mark
= value_mark ();
5343 val
= evaluate_expression (exp
);
5344 release_value (val
);
5345 if (VALUE_LAZY (val
))
5346 value_fetch_lazy (val
);
5349 while (*tok
== ' ' || *tok
== '\t')
5353 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5356 toklen
= end_tok
- tok
;
5357 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5359 tok
= cond_start
= end_tok
+ 1;
5360 cond
= parse_exp_1 (&tok
, 0, 0);
5364 error ("Junk at end of command.");
5366 if (accessflag
== hw_read
)
5367 bp_type
= bp_read_watchpoint
;
5368 else if (accessflag
== hw_access
)
5369 bp_type
= bp_access_watchpoint
;
5371 bp_type
= bp_hardware_watchpoint
;
5373 mem_cnt
= can_use_hardware_watchpoint (val
);
5374 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5375 error ("Expression cannot be implemented with read/access watchpoint.");
5378 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5379 target_resources_ok
=
5380 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5382 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5383 error ("Target does not support this type of hardware watchpoint.");
5385 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5386 error ("Target can only support one kind of HW watchpoint at a time.");
5389 #if defined(HPUXHPPA)
5390 /* On HP-UX if you set a h/w
5391 watchpoint before the "run" command, the inferior dies with a e.g.,
5392 SIGILL once you start it. I initially believed this was due to a
5393 bad interaction between page protection traps and the initial
5394 startup sequence by the dynamic linker.
5396 However, I tried avoiding that by having HP-UX's implementation of
5397 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5398 yet, which forced slow watches before a "run" or "attach", and it
5399 still fails somewhere in the startup code.
5401 Until I figure out what's happening, I'm disallowing watches altogether
5402 before the "run" or "attach" command. We'll tell the user they must
5403 set watches after getting the program started. */
5404 if (!target_has_execution
)
5406 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5409 #endif /* HPUXHPPA */
5411 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5412 watchpoint could not be set. */
5413 if (!mem_cnt
|| target_resources_ok
<= 0)
5414 bp_type
= bp_watchpoint
;
5416 /* Now set up the breakpoint. */
5417 b
= set_raw_breakpoint (sal
, bp_type
);
5418 set_breakpoint_count (breakpoint_count
+ 1);
5419 b
->number
= breakpoint_count
;
5420 b
->disposition
= disp_donttouch
;
5422 b
->exp_valid_block
= exp_valid_block
;
5423 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5427 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5431 frame
= block_innermost_frame (exp_valid_block
);
5434 prev_frame
= get_prev_frame (frame
);
5435 b
->watchpoint_frame
= get_frame_id (frame
);
5439 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5442 /* If the expression is "local", then set up a "watchpoint scope"
5443 breakpoint at the point where we've left the scope of the watchpoint
5445 if (innermost_block
)
5449 struct breakpoint
*scope_breakpoint
;
5450 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5451 bp_watchpoint_scope
);
5453 scope_breakpoint
->enable_state
= bp_enabled
;
5455 /* Automatically delete the breakpoint when it hits. */
5456 scope_breakpoint
->disposition
= disp_del
;
5458 /* Only break in the proper frame (help with recursion). */
5459 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5461 /* Set the address at which we will stop. */
5462 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5464 /* The scope breakpoint is related to the watchpoint. We
5465 will need to act on them together. */
5466 b
->related_breakpoint
= scope_breakpoint
;
5469 value_free_to_mark (mark
);
5473 /* Return count of locations need to be watched and can be handled
5474 in hardware. If the watchpoint can not be handled
5475 in hardware return zero. */
5477 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5478 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5479 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5482 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5483 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5484 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5488 can_use_hardware_watchpoint (struct value
*v
)
5490 int found_memory_cnt
= 0;
5491 struct value
*head
= v
;
5493 /* Did the user specifically forbid us to use hardware watchpoints? */
5494 if (!can_use_hw_watchpoints
)
5497 /* Make sure that the value of the expression depends only upon
5498 memory contents, and values computed from them within GDB. If we
5499 find any register references or function calls, we can't use a
5500 hardware watchpoint.
5502 The idea here is that evaluating an expression generates a series
5503 of values, one holding the value of every subexpression. (The
5504 expression a*b+c has five subexpressions: a, b, a*b, c, and
5505 a*b+c.) GDB's values hold almost enough information to establish
5506 the criteria given above --- they identify memory lvalues,
5507 register lvalues, computed values, etcetera. So we can evaluate
5508 the expression, and then scan the chain of values that leaves
5509 behind to decide whether we can detect any possible change to the
5510 expression's final value using only hardware watchpoints.
5512 However, I don't think that the values returned by inferior
5513 function calls are special in any way. So this function may not
5514 notice that an expression involving an inferior function call
5515 can't be watched with hardware watchpoints. FIXME. */
5516 for (; v
; v
= v
->next
)
5518 if (VALUE_LVAL (v
) == lval_memory
)
5521 /* A lazy memory lvalue is one that GDB never needed to fetch;
5522 we either just used its address (e.g., `a' in `a.b') or
5523 we never needed it at all (e.g., `a' in `a,b'). */
5527 /* Ahh, memory we actually used! Check if we can cover
5528 it with hardware watchpoints. */
5529 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5531 /* We only watch structs and arrays if user asked for it
5532 explicitly, never if they just happen to appear in a
5533 middle of some value chain. */
5535 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5536 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5538 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5539 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5541 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5548 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5549 return 0; /* ??? What does this represent? */
5550 else if (v
->lval
== lval_register
)
5551 return 0; /* cannot watch a register with a HW watchpoint */
5554 /* The expression itself looks suitable for using a hardware
5555 watchpoint, but give the target machine a chance to reject it. */
5556 return found_memory_cnt
;
5560 watch_command_wrapper (char *arg
, int from_tty
)
5562 watch_command (arg
, from_tty
);
5566 watch_command (char *arg
, int from_tty
)
5568 watch_command_1 (arg
, hw_write
, from_tty
);
5572 rwatch_command_wrapper (char *arg
, int from_tty
)
5574 rwatch_command (arg
, from_tty
);
5578 rwatch_command (char *arg
, int from_tty
)
5580 watch_command_1 (arg
, hw_read
, from_tty
);
5584 awatch_command_wrapper (char *arg
, int from_tty
)
5586 awatch_command (arg
, from_tty
);
5590 awatch_command (char *arg
, int from_tty
)
5592 watch_command_1 (arg
, hw_access
, from_tty
);
5596 /* Helper routines for the until_command routine in infcmd.c. Here
5597 because it uses the mechanisms of breakpoints. */
5599 /* This function is called by fetch_inferior_event via the
5600 cmd_continuation pointer, to complete the until command. It takes
5601 care of cleaning up the temporary breakpoints set up by the until
5604 until_break_command_continuation (struct continuation_arg
*arg
)
5606 struct cleanup
*cleanups
;
5608 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5609 do_exec_cleanups (cleanups
);
5614 until_break_command (char *arg
, int from_tty
, int anywhere
)
5616 struct symtabs_and_lines sals
;
5617 struct symtab_and_line sal
;
5618 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5619 struct breakpoint
*breakpoint
;
5620 struct cleanup
*old_chain
;
5621 struct continuation_arg
*arg1
;
5624 clear_proceed_status ();
5626 /* Set a breakpoint where the user wants it and at return from
5629 if (default_breakpoint_valid
)
5630 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5631 default_breakpoint_line
, (char ***) NULL
);
5633 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5634 0, (char ***) NULL
);
5636 if (sals
.nelts
!= 1)
5637 error ("Couldn't get information on specified line.");
5640 xfree (sals
.sals
); /* malloc'd, so freed */
5643 error ("Junk at end of arguments.");
5645 resolve_sal_pc (&sal
);
5648 /* If the user told us to continue until a specified location,
5649 we don't specify a frame at which we need to stop. */
5650 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5652 /* Otherwise, specify the current frame, because we want to stop only
5653 at the very same frame. */
5654 breakpoint
= set_momentary_breakpoint (sal
,
5655 get_frame_id (deprecated_selected_frame
),
5658 if (!event_loop_p
|| !target_can_async_p ())
5659 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5661 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5663 /* If we are running asynchronously, and the target supports async
5664 execution, we are not waiting for the target to stop, in the call
5665 tp proceed, below. This means that we cannot delete the
5666 brekpoints until the target has actually stopped. The only place
5667 where we get a chance to do that is in fetch_inferior_event, so
5668 we must set things up for that. */
5670 if (event_loop_p
&& target_can_async_p ())
5672 /* In this case the arg for the continuation is just the point
5673 in the exec_cleanups chain from where to start doing
5674 cleanups, because all the continuation does is the cleanups in
5675 the exec_cleanup_chain. */
5677 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5679 arg1
->data
.pointer
= old_chain
;
5681 add_continuation (until_break_command_continuation
, arg1
);
5684 /* Keep within the current frame, or in frames called by the current
5688 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
5689 sal
.pc
= get_frame_pc (prev_frame
);
5690 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
5692 if (!event_loop_p
|| !target_can_async_p ())
5693 make_cleanup_delete_breakpoint (breakpoint
);
5695 make_exec_cleanup_delete_breakpoint (breakpoint
);
5698 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5699 /* Do the cleanups now, anly if we are not running asynchronously,
5700 of if we are, but the target is still synchronous. */
5701 if (!event_loop_p
|| !target_can_async_p ())
5702 do_cleanups (old_chain
);
5706 /* These aren't used; I don't konw what they were for. */
5707 /* Set a breakpoint at the catch clause for NAME. */
5709 catch_breakpoint (char *name
)
5714 disable_catch_breakpoint (void)
5719 delete_catch_breakpoint (void)
5724 enable_catch_breakpoint (void)
5730 ep_skip_leading_whitespace (char **s
)
5732 if ((s
== NULL
) || (*s
== NULL
))
5734 while (isspace (**s
))
5738 /* This function examines a string, and attempts to find a token
5739 that might be an event name in the leading characters. If a
5740 possible match is found, a pointer to the last character of
5741 the token is returned. Else, NULL is returned. */
5744 ep_find_event_name_end (char *arg
)
5747 char *event_name_end
= NULL
;
5749 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5753 /* We break out of the loop when we find a token delimiter.
5754 Basically, we're looking for alphanumerics and underscores;
5755 anything else delimites the token. */
5758 if (!isalnum (*s
) && (*s
!= '_'))
5764 return event_name_end
;
5768 /* This function attempts to parse an optional "if <cond>" clause
5769 from the arg string. If one is not found, it returns NULL.
5771 Else, it returns a pointer to the condition string. (It does not
5772 attempt to evaluate the string against a particular block.) And,
5773 it updates arg to point to the first character following the parsed
5774 if clause in the arg string. */
5777 ep_parse_optional_if_clause (char **arg
)
5781 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5784 /* Skip the "if" keyword. */
5787 /* Skip any extra leading whitespace, and record the start of the
5788 condition string. */
5789 ep_skip_leading_whitespace (arg
);
5792 /* Assume that the condition occupies the remainder of the arg string. */
5793 (*arg
) += strlen (cond_string
);
5798 /* This function attempts to parse an optional filename from the arg
5799 string. If one is not found, it returns NULL.
5801 Else, it returns a pointer to the parsed filename. (This function
5802 makes no attempt to verify that a file of that name exists, or is
5803 accessible.) And, it updates arg to point to the first character
5804 following the parsed filename in the arg string.
5806 Note that clients needing to preserve the returned filename for
5807 future access should copy it to their own buffers. */
5809 ep_parse_optional_filename (char **arg
)
5811 static char filename
[1024];
5816 if ((*arg_p
== '\0') || isspace (*arg_p
))
5834 /* Commands to deal with catching events, such as signals, exceptions,
5835 process start/exit, etc. */
5839 catch_fork
, catch_vfork
5843 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5844 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5845 char *arg
, int tempflag
, int from_tty
);
5848 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5851 char *cond_string
= NULL
;
5853 ep_skip_leading_whitespace (&arg
);
5855 /* The allowed syntax is:
5857 catch [v]fork if <cond>
5859 First, check if there's an if clause. */
5860 cond_string
= ep_parse_optional_if_clause (&arg
);
5862 if ((*arg
!= '\0') && !isspace (*arg
))
5863 error ("Junk at end of arguments.");
5865 /* If this target supports it, create a fork or vfork catchpoint
5866 and enable reporting of such events. */
5870 create_fork_event_catchpoint (tempflag
, cond_string
);
5873 create_vfork_event_catchpoint (tempflag
, cond_string
);
5876 error ("unsupported or unknown fork kind; cannot catch it");
5882 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5884 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5886 char *cond_string
= NULL
;
5888 ep_skip_leading_whitespace (&arg
);
5890 /* The allowed syntax is:
5892 catch exec if <cond>
5894 First, check if there's an if clause. */
5895 cond_string
= ep_parse_optional_if_clause (&arg
);
5897 if ((*arg
!= '\0') && !isspace (*arg
))
5898 error ("Junk at end of arguments.");
5900 /* If this target supports it, create an exec catchpoint
5901 and enable reporting of such events. */
5902 create_exec_event_catchpoint (tempflag
, cond_string
);
5906 #if defined(SOLIB_ADD)
5908 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
5910 char *dll_pathname
= NULL
;
5911 char *cond_string
= NULL
;
5913 ep_skip_leading_whitespace (&arg
);
5915 /* The allowed syntax is:
5917 catch load if <cond>
5918 catch load <filename>
5919 catch load <filename> if <cond>
5921 The user is not allowed to specify the <filename> after an
5924 We'll ignore the pathological case of a file named "if".
5926 First, check if there's an if clause. If so, then there
5927 cannot be a filename. */
5928 cond_string
= ep_parse_optional_if_clause (&arg
);
5930 /* If there was an if clause, then there cannot be a filename.
5931 Else, there might be a filename and an if clause. */
5932 if (cond_string
== NULL
)
5934 dll_pathname
= ep_parse_optional_filename (&arg
);
5935 ep_skip_leading_whitespace (&arg
);
5936 cond_string
= ep_parse_optional_if_clause (&arg
);
5939 if ((*arg
!= '\0') && !isspace (*arg
))
5940 error ("Junk at end of arguments.");
5942 /* Create a load breakpoint that only triggers when a load of
5943 the specified dll (or any dll, if no pathname was specified)
5945 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5946 dll_pathname
, cond_string
);
5950 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
5952 char *dll_pathname
= NULL
;
5953 char *cond_string
= NULL
;
5955 ep_skip_leading_whitespace (&arg
);
5957 /* The allowed syntax is:
5959 catch unload if <cond>
5960 catch unload <filename>
5961 catch unload <filename> if <cond>
5963 The user is not allowed to specify the <filename> after an
5966 We'll ignore the pathological case of a file named "if".
5968 First, check if there's an if clause. If so, then there
5969 cannot be a filename. */
5970 cond_string
= ep_parse_optional_if_clause (&arg
);
5972 /* If there was an if clause, then there cannot be a filename.
5973 Else, there might be a filename and an if clause. */
5974 if (cond_string
== NULL
)
5976 dll_pathname
= ep_parse_optional_filename (&arg
);
5977 ep_skip_leading_whitespace (&arg
);
5978 cond_string
= ep_parse_optional_if_clause (&arg
);
5981 if ((*arg
!= '\0') && !isspace (*arg
))
5982 error ("Junk at end of arguments.");
5984 /* Create an unload breakpoint that only triggers when an unload of
5985 the specified dll (or any dll, if no pathname was specified)
5987 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5988 dll_pathname
, cond_string
);
5990 #endif /* SOLIB_ADD */
5992 /* Commands to deal with catching exceptions. */
5994 /* Set a breakpoint at the specified callback routine for an
5995 exception event callback */
5998 create_exception_catchpoint (int tempflag
, char *cond_string
,
5999 enum exception_event_kind ex_event
,
6000 struct symtab_and_line
*sal
)
6002 struct breakpoint
*b
;
6003 int thread
= -1; /* All threads. */
6006 if (!sal
) /* no exception support? */
6011 case EX_EVENT_THROW
:
6012 bptype
= bp_catch_throw
;
6014 case EX_EVENT_CATCH
:
6015 bptype
= bp_catch_catch
;
6017 default: /* error condition */
6018 error ("Internal error -- invalid catchpoint kind");
6021 b
= set_raw_breakpoint (*sal
, bptype
);
6022 set_breakpoint_count (breakpoint_count
+ 1);
6023 b
->number
= breakpoint_count
;
6025 b
->cond_string
= (cond_string
== NULL
) ?
6026 NULL
: savestring (cond_string
, strlen (cond_string
));
6028 b
->addr_string
= NULL
;
6029 b
->enable_state
= bp_enabled
;
6030 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6034 static enum print_stop_action
6035 print_exception_catchpoint (struct breakpoint
*b
)
6037 annotate_catchpoint (b
->number
);
6039 if (strstr (b
->addr_string
, "throw") != NULL
)
6040 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6043 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6046 return PRINT_SRC_AND_LOC
;
6050 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6055 ui_out_field_core_addr (uiout
, "addr", b
->address
);
6058 *last_addr
= b
->address
;
6059 if (strstr (b
->addr_string
, "throw") != NULL
)
6060 ui_out_field_string (uiout
, "what", "exception throw");
6062 ui_out_field_string (uiout
, "what", "exception catch");
6066 print_mention_exception_catchpoint (struct breakpoint
*b
)
6068 if (strstr (b
->addr_string
, "throw") != NULL
)
6069 printf_filtered ("Catchpoint %d (throw)", b
->number
);
6071 printf_filtered ("Catchpoint %d (catch)", b
->number
);
6074 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6075 print_exception_catchpoint
,
6076 print_one_exception_catchpoint
,
6077 print_mention_exception_catchpoint
6081 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6082 enum exception_event_kind ex_event
, int from_tty
)
6084 char *trigger_func_name
, *nameptr
;
6085 struct symtabs_and_lines sals
;
6086 struct breakpoint
*b
;
6088 if (ex_event
== EX_EVENT_CATCH
)
6089 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6091 trigger_func_name
= xstrdup ("__cxa_throw");
6093 nameptr
= trigger_func_name
;
6094 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
);
6095 if (sals
.nelts
== 0)
6097 xfree (trigger_func_name
);
6101 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6102 set_breakpoint_count (breakpoint_count
+ 1);
6103 b
->number
= breakpoint_count
;
6105 b
->cond_string
= (cond_string
== NULL
) ?
6106 NULL
: savestring (cond_string
, strlen (cond_string
));
6108 b
->addr_string
= trigger_func_name
;
6109 b
->enable_state
= bp_enabled
;
6110 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6111 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6118 /* Deal with "catch catch" and "catch throw" commands */
6121 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6122 int tempflag
, int from_tty
)
6124 char *cond_string
= NULL
;
6125 struct symtab_and_line
*sal
= NULL
;
6127 ep_skip_leading_whitespace (&arg
);
6129 cond_string
= ep_parse_optional_if_clause (&arg
);
6131 if ((*arg
!= '\0') && !isspace (*arg
))
6132 error ("Junk at end of arguments.");
6134 if ((ex_event
!= EX_EVENT_THROW
) &&
6135 (ex_event
!= EX_EVENT_CATCH
))
6136 error ("Unsupported or unknown exception event; cannot catch it");
6138 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6141 /* See if we can find a callback routine */
6142 sal
= target_enable_exception_callback (ex_event
, 1);
6146 /* We have callbacks from the runtime system for exceptions.
6147 Set a breakpoint on the sal found, if no errors */
6148 if (sal
!= (struct symtab_and_line
*) -1)
6149 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6151 return; /* something went wrong with setting up callbacks */
6154 warning ("Unsupported with this platform/compiler combination.");
6157 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6158 inside a catch_errors */
6161 cover_target_enable_exception_callback (void *arg
)
6163 args_for_catchpoint_enable
*args
= arg
;
6164 struct symtab_and_line
*sal
;
6165 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6168 else if (sal
== (struct symtab_and_line
*) -1)
6171 return 1; /*is valid */
6175 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6178 /* The first argument may be an event name, such as "start" or "load".
6179 If so, then handle it as such. If it doesn't match an event name,
6180 then attempt to interpret it as an exception name. (This latter is
6181 the v4.16-and-earlier GDB meaning of the "catch" command.)
6183 First, try to find the bounds of what might be an event name. */
6184 char *arg1_start
= arg
;
6188 if (arg1_start
== NULL
)
6190 /* Old behaviour was to use pre-v-4.16 syntax */
6191 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6193 /* Now, this is not allowed */
6194 error ("Catch requires an event name.");
6197 arg1_end
= ep_find_event_name_end (arg1_start
);
6198 if (arg1_end
== NULL
)
6199 error ("catch requires an event");
6200 arg1_length
= arg1_end
+ 1 - arg1_start
;
6202 /* Try to match what we found against known event names. */
6203 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6205 error ("Catch of signal not yet implemented");
6207 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6209 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6210 tempflag
, from_tty
);
6212 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6214 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6215 tempflag
, from_tty
);
6217 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6219 error ("Catch of thread_start not yet implemented");
6221 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6223 error ("Catch of thread_exit not yet implemented");
6225 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6227 error ("Catch of thread_join not yet implemented");
6229 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6231 error ("Catch of start not yet implemented");
6233 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6235 error ("Catch of exit not yet implemented");
6237 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6239 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6240 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6242 error ("Catch of fork not yet implemented");
6245 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6247 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6248 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6250 error ("Catch of vfork not yet implemented");
6253 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6255 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6256 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6258 error ("Catch of exec not yet implemented");
6261 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6263 #if defined(SOLIB_ADD)
6264 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6266 error ("Catch of load not implemented");
6269 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6271 #if defined(SOLIB_ADD)
6272 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6274 error ("Catch of load not implemented");
6277 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6279 error ("Catch of stop not yet implemented");
6282 /* This doesn't appear to be an event name */
6286 /* Pre-v.4.16 behaviour was to treat the argument
6287 as the name of an exception */
6288 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6289 /* Now this is not allowed */
6290 error ("Unknown event kind specified for catch");
6295 /* Used by the gui, could be made a worker for other things. */
6298 set_breakpoint_sal (struct symtab_and_line sal
)
6300 struct breakpoint
*b
;
6301 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6302 set_breakpoint_count (breakpoint_count
+ 1);
6303 b
->number
= breakpoint_count
;
6310 /* These aren't used; I don't know what they were for. */
6311 /* Disable breakpoints on all catch clauses described in ARGS. */
6313 disable_catch (char *args
)
6315 /* Map the disable command to catch clauses described in ARGS. */
6318 /* Enable breakpoints on all catch clauses described in ARGS. */
6320 enable_catch (char *args
)
6322 /* Map the disable command to catch clauses described in ARGS. */
6325 /* Delete breakpoints on all catch clauses in the active scope. */
6327 delete_catch (char *args
)
6329 /* Map the delete command to catch clauses described in ARGS. */
6334 catch_command (char *arg
, int from_tty
)
6336 catch_command_1 (arg
, 0, from_tty
);
6341 tcatch_command (char *arg
, int from_tty
)
6343 catch_command_1 (arg
, 1, from_tty
);
6346 /* Delete breakpoints by address or line. */
6349 clear_command (char *arg
, int from_tty
)
6351 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6353 struct symtabs_and_lines sals
;
6354 struct symtab_and_line sal
;
6359 sals
= decode_line_spec (arg
, 1);
6364 sals
.sals
= (struct symtab_and_line
*)
6365 xmalloc (sizeof (struct symtab_and_line
));
6366 make_cleanup (xfree
, sals
.sals
);
6367 init_sal (&sal
); /* initialize to zeroes */
6368 sal
.line
= default_breakpoint_line
;
6369 sal
.symtab
= default_breakpoint_symtab
;
6370 sal
.pc
= default_breakpoint_address
;
6371 if (sal
.symtab
== 0)
6372 error ("No source file specified.");
6380 /* For each line spec given, delete bps which correspond
6381 to it. Do it in two passes, solely to preserve the current
6382 behavior that from_tty is forced true if we delete more than
6386 for (i
= 0; i
< sals
.nelts
; i
++)
6388 /* If exact pc given, clear bpts at that pc.
6389 If line given (pc == 0), clear all bpts on specified line.
6390 If defaulting, clear all bpts on default line
6393 defaulting sal.pc != 0 tests to do
6398 1 0 <can't happen> */
6403 /* Find all matching breakpoints, remove them from the
6404 breakpoint chain, and add them to the 'found' chain. */
6405 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6407 /* Are we going to delete b? */
6408 if (b
->type
!= bp_none
6409 && b
->type
!= bp_watchpoint
6410 && b
->type
!= bp_hardware_watchpoint
6411 && b
->type
!= bp_read_watchpoint
6412 && b
->type
!= bp_access_watchpoint
6413 /* Not if b is a watchpoint of any sort... */
6414 && (((sal
.pc
&& (b
->address
== sal
.pc
))
6415 && (!section_is_overlay (b
->section
)
6416 || b
->section
== sal
.section
))
6417 /* Yes, if sal.pc matches b (modulo overlays). */
6418 || ((default_match
|| (0 == sal
.pc
))
6419 && b
->source_file
!= NULL
6420 && sal
.symtab
!= NULL
6421 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6422 && b
->line_number
== sal
.line
)))
6423 /* Yes, if sal source file and line matches b. */
6425 /* Remove it from breakpoint_chain... */
6426 if (b
== breakpoint_chain
)
6428 /* b is at the head of the list */
6429 breakpoint_chain
= b
->next
;
6433 prev
->next
= b
->next
;
6435 /* And add it to 'found' chain. */
6441 /* Keep b, and keep a pointer to it. */
6446 /* Now go thru the 'found' chain and delete them. */
6450 error ("No breakpoint at %s.", arg
);
6452 error ("No breakpoint at this line.");
6456 from_tty
= 1; /* Always report if deleted more than one */
6458 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6459 breakpoints_changed ();
6463 printf_unfiltered ("%d ", found
->number
);
6465 delete_breakpoint (found
);
6469 putchar_unfiltered ('\n');
6472 /* Delete breakpoint in BS if they are `delete' breakpoints and
6473 all breakpoints that are marked for deletion, whether hit or not.
6474 This is called after any breakpoint is hit, or after errors. */
6477 breakpoint_auto_delete (bpstat bs
)
6479 struct breakpoint
*b
, *temp
;
6481 for (; bs
; bs
= bs
->next
)
6482 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6484 delete_breakpoint (bs
->breakpoint_at
);
6486 ALL_BREAKPOINTS_SAFE (b
, temp
)
6488 if (b
->disposition
== disp_del_at_next_stop
)
6489 delete_breakpoint (b
);
6493 /* Delete a breakpoint and clean up all traces of it in the data
6497 delete_breakpoint (struct breakpoint
*bpt
)
6499 register struct breakpoint
*b
;
6503 error ("Internal error (attempted to delete a NULL breakpoint)");
6506 /* Has this bp already been deleted? This can happen because multiple
6507 lists can hold pointers to bp's. bpstat lists are especial culprits.
6509 One example of this happening is a watchpoint's scope bp. When the
6510 scope bp triggers, we notice that the watchpoint is out of scope, and
6511 delete it. We also delete its scope bp. But the scope bp is marked
6512 "auto-deleting", and is already on a bpstat. That bpstat is then
6513 checked for auto-deleting bp's, which are deleted.
6515 A real solution to this problem might involve reference counts in bp's,
6516 and/or giving them pointers back to their referencing bpstat's, and
6517 teaching delete_breakpoint to only free a bp's storage when no more
6518 references were extent. A cheaper bandaid was chosen. */
6519 if (bpt
->type
== bp_none
)
6522 if (delete_breakpoint_hook
)
6523 delete_breakpoint_hook (bpt
);
6524 breakpoint_delete_event (bpt
->number
);
6527 remove_breakpoint (bpt
, mark_inserted
);
6529 if (breakpoint_chain
== bpt
)
6530 breakpoint_chain
= bpt
->next
;
6532 /* If we have callback-style exception catchpoints, don't go through
6533 the adjustments to the C++ runtime library etc. if the inferior
6534 isn't actually running. target_enable_exception_callback for a
6535 null target ops vector gives an undesirable error message, so we
6536 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6537 exceptions are supported in this way, it's OK for now. FIXME */
6538 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6540 static char message1
[] = "Error in deleting catchpoint %d:\n";
6541 static char message
[sizeof (message1
) + 30];
6542 args_for_catchpoint_enable args
;
6544 /* Format possible error msg */
6545 sprintf (message
, message1
, bpt
->number
);
6546 args
.kind
= bpt
->type
== bp_catch_catch
?
6547 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6549 catch_errors (cover_target_enable_exception_callback
, &args
,
6550 message
, RETURN_MASK_ALL
);
6557 b
->next
= bpt
->next
;
6561 check_duplicates (bpt
);
6562 /* If this breakpoint was inserted, and there is another breakpoint
6563 at the same address, we need to insert the other breakpoint. */
6565 && bpt
->type
!= bp_hardware_watchpoint
6566 && bpt
->type
!= bp_read_watchpoint
6567 && bpt
->type
!= bp_access_watchpoint
6568 && bpt
->type
!= bp_catch_fork
6569 && bpt
->type
!= bp_catch_vfork
6570 && bpt
->type
!= bp_catch_exec
)
6573 if (b
->address
== bpt
->address
6574 && b
->section
== bpt
->section
6576 && b
->enable_state
!= bp_disabled
6577 && b
->enable_state
!= bp_shlib_disabled
6578 && b
->enable_state
!= bp_call_disabled
)
6582 /* We should never reach this point if there is a permanent
6583 breakpoint at the same address as the one being deleted.
6584 If there is a permanent breakpoint somewhere, it should
6585 always be the only one inserted. */
6586 if (b
->enable_state
== bp_permanent
)
6587 internal_error (__FILE__
, __LINE__
,
6588 "another breakpoint was inserted on top of "
6589 "a permanent breakpoint");
6591 if (b
->type
== bp_hardware_breakpoint
)
6592 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6594 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6596 /* If there was an error in the insert, print a message, then stop execution. */
6599 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6600 make_cleanup_ui_file_delete (tmp_error_stream
);
6603 if (b
->type
== bp_hardware_breakpoint
)
6605 fprintf_unfiltered (tmp_error_stream
,
6606 "Cannot insert hardware breakpoint %d.\n"
6607 "You may have requested too many hardware breakpoints.\n",
6612 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6613 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6614 print_address_numeric (b
->address
, 1, tmp_error_stream
);
6615 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6616 safe_strerror (val
));
6619 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6620 target_terminal_ours_for_output ();
6621 error_stream(tmp_error_stream
);
6628 free_command_lines (&bpt
->commands
);
6631 if (bpt
->cond_string
!= NULL
)
6632 xfree (bpt
->cond_string
);
6633 if (bpt
->addr_string
!= NULL
)
6634 xfree (bpt
->addr_string
);
6635 if (bpt
->exp
!= NULL
)
6637 if (bpt
->exp_string
!= NULL
)
6638 xfree (bpt
->exp_string
);
6639 if (bpt
->val
!= NULL
)
6640 value_free (bpt
->val
);
6641 if (bpt
->source_file
!= NULL
)
6642 xfree (bpt
->source_file
);
6643 if (bpt
->dll_pathname
!= NULL
)
6644 xfree (bpt
->dll_pathname
);
6645 if (bpt
->triggered_dll_pathname
!= NULL
)
6646 xfree (bpt
->triggered_dll_pathname
);
6647 if (bpt
->exec_pathname
!= NULL
)
6648 xfree (bpt
->exec_pathname
);
6650 /* Be sure no bpstat's are pointing at it after it's been freed. */
6651 /* FIXME, how can we find all bpstat's?
6652 We just check stop_bpstat for now. */
6653 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6654 if (bs
->breakpoint_at
== bpt
)
6656 bs
->breakpoint_at
= NULL
;
6658 /* bs->commands will be freed later. */
6660 /* On the chance that someone will soon try again to delete this same
6661 bp, we mark it as deleted before freeing its storage. */
6662 bpt
->type
= bp_none
;
6668 do_delete_breakpoint_cleanup (void *b
)
6670 delete_breakpoint (b
);
6674 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6676 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6680 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6682 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6686 delete_command (char *arg
, int from_tty
)
6688 struct breakpoint
*b
, *temp
;
6694 int breaks_to_delete
= 0;
6696 /* Delete all breakpoints if no argument.
6697 Do not delete internal or call-dummy breakpoints, these
6698 have to be deleted with an explicit breakpoint number argument. */
6701 if (b
->type
!= bp_call_dummy
&&
6702 b
->type
!= bp_shlib_event
&&
6703 b
->type
!= bp_thread_event
&&
6704 b
->type
!= bp_overlay_event
&&
6706 breaks_to_delete
= 1;
6709 /* Ask user only if there are some breakpoints to delete. */
6711 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6713 ALL_BREAKPOINTS_SAFE (b
, temp
)
6715 if (b
->type
!= bp_call_dummy
&&
6716 b
->type
!= bp_shlib_event
&&
6717 b
->type
!= bp_thread_event
&&
6718 b
->type
!= bp_overlay_event
&&
6720 delete_breakpoint (b
);
6725 map_breakpoint_numbers (arg
, delete_breakpoint
);
6728 /* Reset a breakpoint given it's struct breakpoint * BINT.
6729 The value we return ends up being the return value from catch_errors.
6730 Unused in this case. */
6733 breakpoint_re_set_one (void *bint
)
6735 /* get past catch_errs */
6736 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6739 struct symtabs_and_lines sals
;
6741 enum enable_state save_enable
;
6746 warning ("attempted to reset apparently deleted breakpoint #%d?",
6750 case bp_hardware_breakpoint
:
6752 case bp_catch_unload
:
6753 if (b
->addr_string
== NULL
)
6755 /* Anything without a string can't be re-set. */
6756 delete_breakpoint (b
);
6759 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6761 ``And a hack it is, although Apple's Darwin version of GDB
6762 contains an almost identical hack to implement a "future
6763 break" command. It seems to work in many real world cases,
6764 but it is easy to come up with a test case where the patch
6765 doesn't help at all.''
6767 ``It seems that the way GDB implements breakpoints - in -
6768 shared - libraries was designed for a.out shared library
6769 systems (SunOS 4) where shared libraries were loaded at a
6770 fixed address in memory. Since ELF shared libraries can (and
6771 will) be loaded at any address in memory, things break.
6772 Fixing this is not trivial. Therefore, I'm not sure whether
6773 we should add this hack to the branch only. I cannot
6774 guarantee that things will be fixed on the trunk in the near
6777 In case we have a problem, disable this breakpoint. We'll
6778 restore its status if we succeed. Don't disable a
6779 shlib_disabled breakpoint though. There's a fair chance we
6780 can't re-set it if the shared library it's in hasn't been
6782 save_enable
= b
->enable_state
;
6783 if (b
->enable_state
!= bp_shlib_disabled
)
6784 b
->enable_state
= bp_disabled
;
6786 set_language (b
->language
);
6787 input_radix
= b
->input_radix
;
6789 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6790 for (i
= 0; i
< sals
.nelts
; i
++)
6792 resolve_sal_pc (&sals
.sals
[i
]);
6794 /* Reparse conditions, they might contain references to the
6796 if (b
->cond_string
!= NULL
)
6801 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6804 /* We need to re-set the breakpoint if the address changes... */
6805 if (b
->address
!= sals
.sals
[i
].pc
6806 /* ...or new and old breakpoints both have source files, and
6807 the source file name or the line number changes... */
6808 || (b
->source_file
!= NULL
6809 && sals
.sals
[i
].symtab
!= NULL
6810 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6811 || b
->line_number
!= sals
.sals
[i
].line
)
6813 /* ...or we switch between having a source file and not having
6815 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6818 if (b
->source_file
!= NULL
)
6819 xfree (b
->source_file
);
6820 if (sals
.sals
[i
].symtab
== NULL
)
6821 b
->source_file
= NULL
;
6824 savestring (sals
.sals
[i
].symtab
->filename
,
6825 strlen (sals
.sals
[i
].symtab
->filename
));
6826 b
->line_number
= sals
.sals
[i
].line
;
6827 b
->address
= sals
.sals
[i
].pc
;
6829 /* Used to check for duplicates here, but that can
6830 cause trouble, as it doesn't check for disabled
6835 /* Might be better to do this just once per breakpoint_re_set,
6836 rather than once for every breakpoint. */
6837 breakpoints_changed ();
6839 b
->section
= sals
.sals
[i
].section
;
6840 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6843 /* Now that this is re-enabled, check_duplicates
6845 check_duplicates (b
);
6852 case bp_hardware_watchpoint
:
6853 case bp_read_watchpoint
:
6854 case bp_access_watchpoint
:
6855 innermost_block
= NULL
;
6856 /* The issue arises of what context to evaluate this in. The
6857 same one as when it was set, but what does that mean when
6858 symbols have been re-read? We could save the filename and
6859 functionname, but if the context is more local than that, the
6860 best we could do would be something like how many levels deep
6861 and which index at that particular level, but that's going to
6862 be less stable than filenames or function names. */
6864 /* So for now, just use a global context. */
6867 b
->exp
= parse_expression (b
->exp_string
);
6868 b
->exp_valid_block
= innermost_block
;
6869 mark
= value_mark ();
6871 value_free (b
->val
);
6872 b
->val
= evaluate_expression (b
->exp
);
6873 release_value (b
->val
);
6874 if (VALUE_LAZY (b
->val
) && b
->enable_state
== bp_enabled
)
6875 value_fetch_lazy (b
->val
);
6877 if (b
->cond_string
!= NULL
)
6882 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
6884 if (b
->enable_state
== bp_enabled
)
6886 value_free_to_mark (mark
);
6888 case bp_catch_catch
:
6889 case bp_catch_throw
:
6891 /* We needn't really do anything to reset these, since the mask
6892 that requests them is unaffected by e.g., new libraries being
6895 case bp_catch_vfork
:
6900 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
6902 /* Delete longjmp and overlay event breakpoints; they will be
6903 reset later by breakpoint_re_set. */
6905 case bp_longjmp_resume
:
6906 case bp_overlay_event
:
6907 delete_breakpoint (b
);
6910 /* This breakpoint is special, it's set up when the inferior
6911 starts and we really don't want to touch it. */
6912 case bp_shlib_event
:
6914 /* Like bp_shlib_event, this breakpoint type is special.
6915 Once it is set up, we do not want to touch it. */
6916 case bp_thread_event
:
6918 /* Keep temporary breakpoints, which can be encountered when we step
6919 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6920 Otherwise these should have been blown away via the cleanup chain
6921 or by breakpoint_init_inferior when we rerun the executable. */
6924 case bp_watchpoint_scope
:
6926 case bp_step_resume
:
6933 /* Re-set all breakpoints after symbols have been re-loaded. */
6935 breakpoint_re_set (void)
6937 struct breakpoint
*b
, *temp
;
6938 enum language save_language
;
6939 int save_input_radix
;
6940 static char message1
[] = "Error in re-setting breakpoint %d:\n";
6941 char message
[sizeof (message1
) + 30 /* slop */ ];
6943 save_language
= current_language
->la_language
;
6944 save_input_radix
= input_radix
;
6945 ALL_BREAKPOINTS_SAFE (b
, temp
)
6947 /* Format possible error msg */
6948 sprintf (message
, message1
, b
->number
);
6949 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
6951 set_language (save_language
);
6952 input_radix
= save_input_radix
;
6954 if (GET_LONGJMP_TARGET_P ())
6956 create_longjmp_breakpoint ("longjmp");
6957 create_longjmp_breakpoint ("_longjmp");
6958 create_longjmp_breakpoint ("siglongjmp");
6959 create_longjmp_breakpoint ("_siglongjmp");
6960 create_longjmp_breakpoint (NULL
);
6963 create_overlay_event_breakpoint ("_ovly_debug_event");
6966 /* Reset the thread number of this breakpoint:
6968 - If the breakpoint is for all threads, leave it as-is.
6969 - Else, reset it to the current thread for inferior_ptid. */
6971 breakpoint_re_set_thread (struct breakpoint
*b
)
6973 if (b
->thread
!= -1)
6975 if (in_thread_list (inferior_ptid
))
6976 b
->thread
= pid_to_thread_id (inferior_ptid
);
6980 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6981 If from_tty is nonzero, it prints a message to that effect,
6982 which ends with a period (no newline). */
6985 set_ignore_count (int bptnum
, int count
, int from_tty
)
6987 register struct breakpoint
*b
;
6993 if (b
->number
== bptnum
)
6995 b
->ignore_count
= count
;
6999 printf_filtered ("Will stop next time breakpoint %d is reached.",
7001 else if (count
== 1)
7002 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7005 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7008 breakpoints_changed ();
7009 breakpoint_modify_event (b
->number
);
7013 error ("No breakpoint number %d.", bptnum
);
7016 /* Clear the ignore counts of all breakpoints. */
7018 breakpoint_clear_ignore_counts (void)
7020 struct breakpoint
*b
;
7023 b
->ignore_count
= 0;
7026 /* Command to set ignore-count of breakpoint N to COUNT. */
7029 ignore_command (char *args
, int from_tty
)
7035 error_no_arg ("a breakpoint number");
7037 num
= get_number (&p
);
7039 error ("bad breakpoint number: '%s'", args
);
7041 error ("Second argument (specified ignore-count) is missing.");
7043 set_ignore_count (num
,
7044 longest_to_int (value_as_long (parse_and_eval (p
))),
7047 printf_filtered ("\n");
7050 /* Call FUNCTION on each of the breakpoints
7051 whose numbers are given in ARGS. */
7054 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7056 register char *p
= args
;
7059 register struct breakpoint
*b
, *tmp
;
7063 error_no_arg ("one or more breakpoint numbers");
7070 num
= get_number_or_range (&p1
);
7073 warning ("bad breakpoint number at or near '%s'", p
);
7077 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7078 if (b
->number
== num
)
7080 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7083 if (related_breakpoint
)
7084 function (related_breakpoint
);
7088 printf_unfiltered ("No breakpoint number %d.\n", num
);
7094 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7095 If from_tty is nonzero, it prints a message to that effect,
7096 which ends with a period (no newline). */
7099 disable_breakpoint (struct breakpoint
*bpt
)
7101 /* Never disable a watchpoint scope breakpoint; we want to
7102 hit them when we leave scope so we can delete both the
7103 watchpoint and its scope breakpoint at that time. */
7104 if (bpt
->type
== bp_watchpoint_scope
)
7107 /* You can't disable permanent breakpoints. */
7108 if (bpt
->enable_state
== bp_permanent
)
7111 bpt
->enable_state
= bp_disabled
;
7113 check_duplicates (bpt
);
7115 if (modify_breakpoint_hook
)
7116 modify_breakpoint_hook (bpt
);
7117 breakpoint_modify_event (bpt
->number
);
7122 disable_command (char *args
, int from_tty
)
7124 register struct breakpoint
*bpt
;
7126 ALL_BREAKPOINTS (bpt
)
7130 warning ("attempted to disable apparently deleted breakpoint #%d?",
7135 case bp_catch_unload
:
7137 case bp_catch_vfork
:
7139 case bp_catch_catch
:
7140 case bp_catch_throw
:
7141 case bp_hardware_breakpoint
:
7143 case bp_hardware_watchpoint
:
7144 case bp_read_watchpoint
:
7145 case bp_access_watchpoint
:
7146 disable_breakpoint (bpt
);
7151 map_breakpoint_numbers (args
, disable_breakpoint
);
7155 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7157 struct frame_info
*save_selected_frame
= NULL
;
7158 int save_selected_frame_level
= -1;
7159 int target_resources_ok
, other_type_used
;
7162 if (bpt
->type
== bp_hardware_breakpoint
)
7165 i
= hw_breakpoint_used_count ();
7166 target_resources_ok
=
7167 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7169 if (target_resources_ok
== 0)
7170 error ("No hardware breakpoint support in the target.");
7171 else if (target_resources_ok
< 0)
7172 error ("Hardware breakpoints used exceeds limit.");
7175 if (bpt
->enable_state
!= bp_permanent
)
7176 bpt
->enable_state
= bp_enabled
;
7177 bpt
->disposition
= disposition
;
7178 check_duplicates (bpt
);
7179 breakpoints_changed ();
7181 if (bpt
->type
== bp_watchpoint
||
7182 bpt
->type
== bp_hardware_watchpoint
||
7183 bpt
->type
== bp_read_watchpoint
||
7184 bpt
->type
== bp_access_watchpoint
)
7186 if (bpt
->exp_valid_block
!= NULL
)
7188 struct frame_info
*fr
=
7189 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7193 Cannot enable watchpoint %d because the block in which its expression\n\
7194 is valid is not currently in scope.\n", bpt
->number
);
7195 bpt
->enable_state
= bp_disabled
;
7199 save_selected_frame
= deprecated_selected_frame
;
7200 save_selected_frame_level
= frame_relative_level (deprecated_selected_frame
);
7204 value_free (bpt
->val
);
7205 mark
= value_mark ();
7206 bpt
->val
= evaluate_expression (bpt
->exp
);
7207 release_value (bpt
->val
);
7208 if (VALUE_LAZY (bpt
->val
))
7209 value_fetch_lazy (bpt
->val
);
7211 if (bpt
->type
== bp_hardware_watchpoint
||
7212 bpt
->type
== bp_read_watchpoint
||
7213 bpt
->type
== bp_access_watchpoint
)
7215 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7216 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7218 /* Hack around 'unused var' error for some targets here */
7220 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7221 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7222 /* we can consider of type is bp_hardware_watchpoint, convert to
7223 bp_watchpoint in the following condition */
7224 if (target_resources_ok
< 0)
7227 Cannot enable watchpoint %d because target watch resources\n\
7228 have been allocated for other watchpoints.\n", bpt
->number
);
7229 bpt
->enable_state
= bp_disabled
;
7230 value_free_to_mark (mark
);
7235 if (save_selected_frame_level
>= 0)
7236 select_frame (save_selected_frame
);
7237 value_free_to_mark (mark
);
7239 if (modify_breakpoint_hook
)
7240 modify_breakpoint_hook (bpt
);
7241 breakpoint_modify_event (bpt
->number
);
7245 enable_breakpoint (struct breakpoint
*bpt
)
7247 do_enable_breakpoint (bpt
, bpt
->disposition
);
7250 /* The enable command enables the specified breakpoints (or all defined
7251 breakpoints) so they once again become (or continue to be) effective
7252 in stopping the inferior. */
7256 enable_command (char *args
, int from_tty
)
7258 register struct breakpoint
*bpt
;
7260 ALL_BREAKPOINTS (bpt
)
7264 warning ("attempted to enable apparently deleted breakpoint #%d?",
7269 case bp_catch_unload
:
7271 case bp_catch_vfork
:
7273 case bp_catch_catch
:
7274 case bp_catch_throw
:
7275 case bp_hardware_breakpoint
:
7277 case bp_hardware_watchpoint
:
7278 case bp_read_watchpoint
:
7279 case bp_access_watchpoint
:
7280 enable_breakpoint (bpt
);
7285 map_breakpoint_numbers (args
, enable_breakpoint
);
7289 enable_once_breakpoint (struct breakpoint
*bpt
)
7291 do_enable_breakpoint (bpt
, disp_disable
);
7296 enable_once_command (char *args
, int from_tty
)
7298 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7302 enable_delete_breakpoint (struct breakpoint
*bpt
)
7304 do_enable_breakpoint (bpt
, disp_del
);
7309 enable_delete_command (char *args
, int from_tty
)
7311 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7314 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7316 struct symtabs_and_lines
7317 decode_line_spec_1 (char *string
, int funfirstline
)
7319 struct symtabs_and_lines sals
;
7321 error ("Empty line specification.");
7322 if (default_breakpoint_valid
)
7323 sals
= decode_line_1 (&string
, funfirstline
,
7324 default_breakpoint_symtab
,
7325 default_breakpoint_line
,
7328 sals
= decode_line_1 (&string
, funfirstline
,
7329 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7331 error ("Junk at end of line specification: %s", string
);
7336 _initialize_breakpoint (void)
7338 struct cmd_list_element
*c
;
7340 breakpoint_chain
= 0;
7341 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7342 before a breakpoint is set. */
7343 breakpoint_count
= 0;
7345 add_com ("ignore", class_breakpoint
, ignore_command
,
7346 "Set ignore-count of breakpoint number N to COUNT.\n\
7347 Usage is `ignore N COUNT'.");
7349 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7351 add_com ("commands", class_breakpoint
, commands_command
,
7352 "Set commands to be executed when a breakpoint is hit.\n\
7353 Give breakpoint number as argument after \"commands\".\n\
7354 With no argument, the targeted breakpoint is the last one set.\n\
7355 The commands themselves follow starting on the next line.\n\
7356 Type a line containing \"end\" to indicate the end of them.\n\
7357 Give \"silent\" as the first line to make the breakpoint silent;\n\
7358 then no output is printed when it is hit, except what the commands print.");
7360 add_com ("condition", class_breakpoint
, condition_command
,
7361 "Specify breakpoint number N to break only if COND is true.\n\
7362 Usage is `condition N COND', where N is an integer and COND is an\n\
7363 expression to be evaluated whenever breakpoint N is reached.");
7365 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7366 "Set a temporary breakpoint. Args like \"break\" command.\n\
7367 Like \"break\" except the breakpoint is only temporary,\n\
7368 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7369 by using \"enable delete\" on the breakpoint number.");
7370 set_cmd_completer (c
, location_completer
);
7372 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7373 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7374 Like \"break\" except the breakpoint requires hardware support,\n\
7375 some target hardware may not have this support.");
7376 set_cmd_completer (c
, location_completer
);
7378 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7379 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7380 Like \"hbreak\" except the breakpoint is only temporary,\n\
7381 so it will be deleted when hit.");
7382 set_cmd_completer (c
, location_completer
);
7384 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7385 "Enable some breakpoints.\n\
7386 Give breakpoint numbers (separated by spaces) as arguments.\n\
7387 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7388 This is used to cancel the effect of the \"disable\" command.\n\
7389 With a subcommand you can enable temporarily.",
7390 &enablelist
, "enable ", 1, &cmdlist
);
7392 add_com ("ab", class_breakpoint
, enable_command
,
7393 "Enable some breakpoints.\n\
7394 Give breakpoint numbers (separated by spaces) as arguments.\n\
7395 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7396 This is used to cancel the effect of the \"disable\" command.\n\
7397 With a subcommand you can enable temporarily.");
7399 add_com_alias ("en", "enable", class_breakpoint
, 1);
7401 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7402 "Enable some breakpoints.\n\
7403 Give breakpoint numbers (separated by spaces) as arguments.\n\
7404 This is used to cancel the effect of the \"disable\" command.\n\
7405 May be abbreviated to simply \"enable\".\n",
7406 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7408 add_cmd ("once", no_class
, enable_once_command
,
7409 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7410 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7413 add_cmd ("delete", no_class
, enable_delete_command
,
7414 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7415 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7418 add_cmd ("delete", no_class
, enable_delete_command
,
7419 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7420 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7423 add_cmd ("once", no_class
, enable_once_command
,
7424 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7425 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7428 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7429 "Disable some breakpoints.\n\
7430 Arguments are breakpoint numbers with spaces in between.\n\
7431 To disable all breakpoints, give no argument.\n\
7432 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7433 &disablelist
, "disable ", 1, &cmdlist
);
7434 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7435 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7437 add_com ("sb", class_breakpoint
, disable_command
,
7438 "Disable some breakpoints.\n\
7439 Arguments are breakpoint numbers with spaces in between.\n\
7440 To disable all breakpoints, give no argument.\n\
7441 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7443 add_cmd ("breakpoints", class_alias
, disable_command
,
7444 "Disable some breakpoints.\n\
7445 Arguments are breakpoint numbers with spaces in between.\n\
7446 To disable all breakpoints, give no argument.\n\
7447 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7448 This command may be abbreviated \"disable\".",
7451 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7452 "Delete some breakpoints or auto-display expressions.\n\
7453 Arguments are breakpoint numbers with spaces in between.\n\
7454 To delete all breakpoints, give no argument.\n\
7456 Also a prefix command for deletion of other GDB objects.\n\
7457 The \"unset\" command is also an alias for \"delete\".",
7458 &deletelist
, "delete ", 1, &cmdlist
);
7459 add_com_alias ("d", "delete", class_breakpoint
, 1);
7461 add_com ("db", class_breakpoint
, delete_command
,
7462 "Delete some breakpoints.\n\
7463 Arguments are breakpoint numbers with spaces in between.\n\
7464 To delete all breakpoints, give no argument.\n");
7466 add_cmd ("breakpoints", class_alias
, delete_command
,
7467 "Delete some breakpoints or auto-display expressions.\n\
7468 Arguments are breakpoint numbers with spaces in between.\n\
7469 To delete all breakpoints, give no argument.\n\
7470 This command may be abbreviated \"delete\".",
7473 add_com ("clear", class_breakpoint
, clear_command
,
7474 concat ("Clear breakpoint at specified line or function.\n\
7475 Argument may be line number, function name, or \"*\" and an address.\n\
7476 If line number is specified, all breakpoints in that line are cleared.\n\
7477 If function is specified, breakpoints at beginning of function are cleared.\n\
7478 If an address is specified, breakpoints at that address are cleared.\n\n",
7479 "With no argument, clears all breakpoints in the line that the selected frame\n\
7482 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7484 c
= add_com ("break", class_breakpoint
, break_command
,
7485 concat ("Set breakpoint at specified line or function.\n\
7486 Argument may be line number, function name, or \"*\" and an address.\n\
7487 If line number is specified, break at start of code for that line.\n\
7488 If function is specified, break at start of code for that function.\n\
7489 If an address is specified, break at that exact address.\n",
7490 "With no arg, uses current execution address of selected stack frame.\n\
7491 This is useful for breaking on return to a stack frame.\n\
7493 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7495 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7496 set_cmd_completer (c
, location_completer
);
7498 add_com_alias ("b", "break", class_run
, 1);
7499 add_com_alias ("br", "break", class_run
, 1);
7500 add_com_alias ("bre", "break", class_run
, 1);
7501 add_com_alias ("brea", "break", class_run
, 1);
7505 add_com_alias ("ba", "break", class_breakpoint
, 1);
7506 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7511 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7512 "Break in function/address or break at a line in the current file.",
7513 &stoplist
, "stop ", 1, &cmdlist
);
7514 add_cmd ("in", class_breakpoint
, stopin_command
,
7515 "Break in function or address.\n", &stoplist
);
7516 add_cmd ("at", class_breakpoint
, stopat_command
,
7517 "Break at a line in the current file.\n", &stoplist
);
7518 add_com ("status", class_info
, breakpoints_info
,
7519 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7520 The \"Type\" column indicates one of:\n\
7521 \tbreakpoint - normal breakpoint\n\
7522 \twatchpoint - watchpoint\n\
7523 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7524 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7525 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7526 address and file/line number respectively.\n\n",
7527 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7528 are set to the address of the last breakpoint listed.\n\n\
7529 Convenience variable \"$bpnum\" contains the number of the last\n\
7530 breakpoint set.", NULL
));
7533 add_info ("breakpoints", breakpoints_info
,
7534 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7535 The \"Type\" column indicates one of:\n\
7536 \tbreakpoint - normal breakpoint\n\
7537 \twatchpoint - watchpoint\n\
7538 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7539 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7540 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7541 address and file/line number respectively.\n\n",
7542 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7543 are set to the address of the last breakpoint listed.\n\n\
7544 Convenience variable \"$bpnum\" contains the number of the last\n\
7545 breakpoint set.", NULL
));
7548 add_com ("lb", class_breakpoint
, breakpoints_info
,
7549 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7550 The \"Type\" column indicates one of:\n\
7551 \tbreakpoint - normal breakpoint\n\
7552 \twatchpoint - watchpoint\n\
7553 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7554 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7555 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7556 address and file/line number respectively.\n\n",
7557 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7558 are set to the address of the last breakpoint listed.\n\n\
7559 Convenience variable \"$bpnum\" contains the number of the last\n\
7560 breakpoint set.", NULL
));
7562 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7563 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7564 The \"Type\" column indicates one of:\n\
7565 \tbreakpoint - normal breakpoint\n\
7566 \twatchpoint - watchpoint\n\
7567 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7568 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7569 \tuntil - internal breakpoint used by the \"until\" command\n\
7570 \tfinish - internal breakpoint used by the \"finish\" command\n",
7571 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7572 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7573 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7574 address and file/line number respectively.\n\n",
7575 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7576 are set to the address of the last breakpoint listed.\n\n\
7577 Convenience variable \"$bpnum\" contains the number of the last\n\
7578 breakpoint set.", NULL
),
7579 &maintenanceinfolist
);
7581 add_com ("catch", class_breakpoint
, catch_command
,
7582 "Set catchpoints to catch events.\n\
7583 Raised signals may be caught:\n\
7584 \tcatch signal - all signals\n\
7585 \tcatch signal <signame> - a particular signal\n\
7586 Raised exceptions may be caught:\n\
7587 \tcatch throw - all exceptions, when thrown\n\
7588 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7589 \tcatch catch - all exceptions, when caught\n\
7590 \tcatch catch <exceptname> - a particular exception, when caught\n\
7591 Thread or process events may be caught:\n\
7592 \tcatch thread_start - any threads, just after creation\n\
7593 \tcatch thread_exit - any threads, just before expiration\n\
7594 \tcatch thread_join - any threads, just after joins\n\
7595 Process events may be caught:\n\
7596 \tcatch start - any processes, just after creation\n\
7597 \tcatch exit - any processes, just before expiration\n\
7598 \tcatch fork - calls to fork()\n\
7599 \tcatch vfork - calls to vfork()\n\
7600 \tcatch exec - calls to exec()\n\
7601 Dynamically-linked library events may be caught:\n\
7602 \tcatch load - loads of any library\n\
7603 \tcatch load <libname> - loads of a particular library\n\
7604 \tcatch unload - unloads of any library\n\
7605 \tcatch unload <libname> - unloads of a particular library\n\
7606 The act of your program's execution stopping may also be caught:\n\
7608 C++ exceptions may be caught:\n\
7609 \tcatch throw - all exceptions, when thrown\n\
7610 \tcatch catch - all exceptions, when caught\n\
7612 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7613 after a fork or vfork is caught.\n\n\
7614 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7616 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7617 "Set temporary catchpoints to catch events.\n\
7618 Args like \"catch\" command.\n\
7619 Like \"catch\" except the catchpoint is only temporary,\n\
7620 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7621 by using \"enable delete\" on the catchpoint number.");
7623 c
= add_com ("watch", class_breakpoint
, watch_command
,
7624 "Set a watchpoint for an expression.\n\
7625 A watchpoint stops execution of your program whenever the value of\n\
7626 an expression changes.");
7627 set_cmd_completer (c
, location_completer
);
7629 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7630 "Set a read watchpoint for an expression.\n\
7631 A watchpoint stops execution of your program whenever the value of\n\
7632 an expression is read.");
7633 set_cmd_completer (c
, location_completer
);
7635 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7636 "Set a watchpoint for an expression.\n\
7637 A watchpoint stops execution of your program whenever the value of\n\
7638 an expression is either read or written.");
7639 set_cmd_completer (c
, location_completer
);
7641 add_info ("watchpoints", breakpoints_info
,
7642 "Synonym for ``info breakpoints''.");
7645 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7646 (char *) &can_use_hw_watchpoints
,
7647 "Set debugger's willingness to use watchpoint hardware.\n\
7648 If zero, gdb will not use hardware for new watchpoints, even if\n\
7649 such is available. (However, any hardware watchpoints that were\n\
7650 created before setting this to nonzero, will continue to use watchpoint\n\
7653 add_show_from_set (c
, &showlist
);
7655 can_use_hw_watchpoints
= 1;