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 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
);
564 commands_command (char *arg
, int from_tty
)
566 struct breakpoint
*b
;
569 struct command_line
*l
;
571 /* If we allowed this, we would have problems with when to
572 free the storage, if we change the commands currently
575 if (executing_breakpoint_commands
)
576 error ("Can't use the \"commands\" command among a breakpoint's commands.");
579 bnum
= get_number (&p
);
582 error ("Unexpected extra arguments following breakpoint number.");
585 if (b
->number
== bnum
)
587 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
589 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
590 l
= read_command_lines (tmpbuf
, from_tty
);
591 do_cleanups (cleanups
);
592 free_command_lines (&b
->commands
);
594 breakpoints_changed ();
595 breakpoint_modify_event (b
->number
);
598 error ("No breakpoint number %d.", bnum
);
601 /* Like target_read_memory() but if breakpoints are inserted, return
602 the shadow contents instead of the breakpoints themselves.
604 Read "memory data" from whatever target or inferior we have.
605 Returns zero if successful, errno value if not. EIO is used
606 for address out of bounds. If breakpoints are inserted, returns
607 shadow contents, not the breakpoints themselves. From breakpoint.c. */
610 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
613 struct breakpoint
*b
;
614 CORE_ADDR bp_addr
= 0;
617 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
618 /* No breakpoints on this machine. */
619 return target_read_memory (memaddr
, myaddr
, len
);
623 if (b
->type
== bp_none
)
624 warning ("reading through apparently deleted breakpoint #%d?",
627 /* memory breakpoint? */
628 if (b
->type
== bp_watchpoint
629 || b
->type
== bp_hardware_watchpoint
630 || b
->type
== bp_read_watchpoint
631 || b
->type
== bp_access_watchpoint
)
636 /* Addresses and length of the part of the breakpoint that
638 /* XXXX The m68k, sh and h8300 have different local and remote
639 breakpoint values. BREAKPOINT_FROM_PC still manages to
640 correctly determine the breakpoints memory address and size
641 for these targets. */
642 bp_addr
= b
->address
;
644 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
649 if (bp_addr
+ bp_size
<= memaddr
)
650 /* The breakpoint is entirely before the chunk of memory we
653 if (bp_addr
>= memaddr
+ len
)
654 /* The breakpoint is entirely after the chunk of memory we are
657 /* Copy the breakpoint from the shadow contents, and recurse for
658 the things before and after. */
660 /* Offset within shadow_contents. */
663 if (bp_addr
< memaddr
)
665 /* Only copy the second part of the breakpoint. */
666 bp_size
-= memaddr
- bp_addr
;
667 bptoffset
= memaddr
- bp_addr
;
671 if (bp_addr
+ bp_size
> memaddr
+ len
)
673 /* Only copy the first part of the breakpoint. */
674 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
677 memcpy (myaddr
+ bp_addr
- memaddr
,
678 b
->shadow_contents
+ bptoffset
, bp_size
);
680 if (bp_addr
> memaddr
)
682 /* Copy the section of memory before the breakpoint. */
683 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
688 if (bp_addr
+ bp_size
< memaddr
+ len
)
690 /* Copy the section of memory after the breakpoint. */
691 status
= read_memory_nobpt (bp_addr
+ bp_size
,
692 myaddr
+ bp_addr
+ bp_size
- memaddr
,
693 memaddr
+ len
- (bp_addr
+ bp_size
));
700 /* Nothing overlaps. Just call read_memory_noerr. */
701 return target_read_memory (memaddr
, myaddr
, len
);
705 /* A wrapper function for inserting catchpoints. */
707 insert_catchpoint (struct ui_out
*uo
, void *args
)
709 struct breakpoint
*b
= (struct breakpoint
*) args
;
715 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
718 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
721 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
724 internal_error (__FILE__
, __LINE__
, "unknown breakpoint type");
729 throw_exception (RETURN_ERROR
);
734 /* insert_breakpoints is used when starting or continuing the program.
735 remove_breakpoints is used when the program stops.
736 Both return zero if successful,
737 or an `errno' value if could not write the inferior. */
740 insert_breakpoints (void)
742 struct breakpoint
*b
, *temp
;
743 int return_val
= 0; /* return success code. */
745 int disabled_breaks
= 0;
746 int hw_breakpoint_error
= 0;
747 #ifdef ONE_PROCESS_WRITETEXT
748 int process_warning
= 0;
751 struct ui_file
*tmp_error_stream
= mem_fileopen ();
752 make_cleanup_ui_file_delete (tmp_error_stream
);
754 /* Explicitly mark the warning -- this will only be printed if
755 there was an error. */
756 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
758 ALL_BREAKPOINTS_SAFE (b
, temp
)
760 /* Permanent breakpoints cannot be inserted or removed. Disabled
761 breakpoints should not be inserted. */
762 if (b
->enable_state
!= bp_enabled
)
765 if ((b
->type
== bp_watchpoint
766 || b
->type
== bp_hardware_watchpoint
767 || b
->type
== bp_read_watchpoint
768 || b
->type
== bp_access_watchpoint
) && (!b
->val
))
771 val
= evaluate_expression (b
->exp
);
773 if (VALUE_LAZY (val
))
774 value_fetch_lazy (val
);
777 if (b
->type
!= bp_watchpoint
778 && b
->type
!= bp_hardware_watchpoint
779 && b
->type
!= bp_read_watchpoint
780 && b
->type
!= bp_access_watchpoint
781 && b
->type
!= bp_catch_fork
782 && b
->type
!= bp_catch_vfork
783 && b
->type
!= bp_catch_exec
784 && b
->type
!= bp_catch_throw
785 && b
->type
!= bp_catch_catch
789 /* "Normal" instruction breakpoint: either the standard
790 trap-instruction bp (bp_breakpoint), or a
791 bp_hardware_breakpoint. */
793 /* First check to see if we have to handle an overlay. */
794 if (overlay_debugging
== ovly_off
795 || b
->section
== NULL
796 || !(section_is_overlay (b
->section
)))
798 /* No overlay handling: just set the breakpoint. */
800 if (b
->type
== bp_hardware_breakpoint
)
801 val
= target_insert_hw_breakpoint (b
->address
,
804 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
808 /* This breakpoint is in an overlay section.
809 Shall we set a breakpoint at the LMA? */
810 if (!overlay_events_enabled
)
812 /* Yes -- overlay event support is not active,
813 so we must try to set a breakpoint at the LMA.
814 This will not work for a hardware breakpoint. */
815 if (b
->type
== bp_hardware_breakpoint
)
816 warning ("hardware breakpoint %d not supported in overlay!\n",
820 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
822 /* Set a software (trap) breakpoint at the LMA. */
823 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
825 fprintf_unfiltered (tmp_error_stream
,
826 "Overlay breakpoint %d failed: in ROM?",
830 /* Shall we set a breakpoint at the VMA? */
831 if (section_is_mapped (b
->section
))
833 /* Yes. This overlay section is mapped into memory. */
834 if (b
->type
== bp_hardware_breakpoint
)
835 val
= target_insert_hw_breakpoint (b
->address
,
838 val
= target_insert_breakpoint (b
->address
,
843 /* No. This breakpoint will not be inserted.
844 No error, but do not mark the bp as 'inserted'. */
851 /* Can't set the breakpoint. */
852 #if defined (DISABLE_UNSETTABLE_BREAK)
853 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
855 /* See also: disable_breakpoints_in_shlibs. */
857 b
->enable_state
= bp_shlib_disabled
;
858 if (!disabled_breaks
)
860 fprintf_unfiltered (tmp_error_stream
,
861 "Cannot insert breakpoint %d.\n",
863 fprintf_unfiltered (tmp_error_stream
,
864 "Temporarily disabling shared library breakpoints:\n");
867 fprintf_unfiltered (tmp_error_stream
,
868 "breakpoint #%d\n", b
->number
);
873 #ifdef ONE_PROCESS_WRITETEXT
876 if (b
->type
== bp_hardware_breakpoint
)
878 hw_breakpoint_error
= 1;
879 fprintf_unfiltered (tmp_error_stream
,
880 "Cannot insert hardware breakpoint %d.\n",
885 fprintf_unfiltered (tmp_error_stream
,
886 "Cannot insert breakpoint %d.\n",
888 fprintf_filtered (tmp_error_stream
,
889 "Error accessing memory address ");
890 print_address_numeric (b
->address
, 1, tmp_error_stream
);
891 fprintf_filtered (tmp_error_stream
, ": %s.\n",
892 safe_strerror (val
));
901 return_val
= val
; /* remember failure */
903 else if (ep_is_exception_catchpoint (b
)
908 /* If we get here, we must have a callback mechanism for exception
909 events -- with g++ style embedded label support, we insert
910 ordinary breakpoints and not catchpoints. */
911 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
914 /* Couldn't set breakpoint for some reason */
915 fprintf_unfiltered (tmp_error_stream
,
916 "Cannot insert catchpoint %d; disabling it.\n",
918 fprintf_filtered (tmp_error_stream
,
919 "Error accessing memory address ");
920 print_address_numeric (b
->address
, 1, tmp_error_stream
);
921 fprintf_filtered (tmp_error_stream
, ": %s.\n",
922 safe_strerror (val
));
923 b
->enable_state
= bp_disabled
;
927 /* Bp set, now make sure callbacks are enabled */
928 /* Format possible error msg */
929 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
931 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
933 args_for_catchpoint_enable args
;
934 args
.kind
= b
->type
== bp_catch_catch
?
935 EX_EVENT_CATCH
: EX_EVENT_THROW
;
937 val
= catch_errors (cover_target_enable_exception_callback
,
938 &args
, message
, RETURN_MASK_ALL
);
939 do_cleanups (cleanups
);
940 if (val
!= 0 && val
!= -1)
944 /* Check if something went wrong; val == 0 can be ignored */
947 /* something went wrong */
948 fprintf_unfiltered (tmp_error_stream
,
949 "Cannot insert catchpoint %d; disabling it.\n",
951 b
->enable_state
= bp_disabled
;
956 return_val
= val
; /* remember failure */
959 else if ((b
->type
== bp_hardware_watchpoint
||
960 b
->type
== bp_read_watchpoint
||
961 b
->type
== bp_access_watchpoint
)
962 && b
->disposition
!= disp_del_at_next_stop
966 struct frame_info
*saved_frame
;
967 int saved_level
, within_current_scope
;
968 struct value
*mark
= value_mark ();
971 /* Save the current frame and level so we can restore it after
972 evaluating the watchpoint expression on its own frame. */
973 saved_frame
= deprecated_selected_frame
;
974 saved_level
= frame_relative_level (deprecated_selected_frame
);
976 /* Determine if the watchpoint is within scope. */
977 if (b
->exp_valid_block
== NULL
)
978 within_current_scope
= 1;
981 struct frame_info
*fi
;
982 fi
= frame_find_by_id (b
->watchpoint_frame
);
983 within_current_scope
= (fi
!= NULL
);
984 if (within_current_scope
)
988 if (within_current_scope
)
990 /* Evaluate the expression and cut the chain of values
991 produced off from the value chain.
993 Make sure the value returned isn't lazy; we use
994 laziness to determine what memory GDB actually needed
995 in order to compute the value of the expression. */
996 v
= evaluate_expression (b
->exp
);
998 value_release_to_mark (mark
);
1003 /* Look at each value on the value chain. */
1004 for (; v
; v
= v
->next
)
1006 /* If it's a memory location, and GDB actually needed
1007 its contents to evaluate the expression, then we
1009 if (VALUE_LVAL (v
) == lval_memory
1010 && ! VALUE_LAZY (v
))
1012 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1014 /* We only watch structs and arrays if user asked
1015 for it explicitly, never if they just happen to
1016 appear in the middle of some value chain. */
1017 if (v
== b
->val_chain
1018 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1019 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1024 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1025 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1027 if (b
->type
== bp_read_watchpoint
)
1029 else if (b
->type
== bp_access_watchpoint
)
1032 val
= target_insert_watchpoint (addr
, len
, type
);
1035 /* Don't exit the loop, try to insert
1036 every value on the value chain. That's
1037 because we will be removing all the
1038 watches below, and removing a
1039 watchpoint we didn't insert could have
1047 /* Failure to insert a watchpoint on any memory value in the
1048 value chain brings us here. */
1051 remove_breakpoint (b
, mark_uninserted
);
1052 hw_breakpoint_error
= 1;
1053 fprintf_unfiltered (tmp_error_stream
,
1054 "Could not insert hardware watchpoint %d.\n",
1061 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
1062 printf_filtered ("because the program has left the block \n");
1063 printf_filtered ("in which its expression is valid.\n");
1064 if (b
->related_breakpoint
)
1065 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1066 b
->disposition
= disp_del_at_next_stop
;
1069 /* Restore the frame and level. */
1070 if ((saved_frame
!= deprecated_selected_frame
) ||
1071 (saved_level
!= frame_relative_level (deprecated_selected_frame
)))
1072 select_frame (saved_frame
);
1075 return_val
= val
; /* remember failure */
1077 else if ((b
->type
== bp_catch_fork
1078 || b
->type
== bp_catch_vfork
1079 || b
->type
== bp_catch_exec
)
1083 char *prefix
= xstrprintf ("warning: inserting catchpoint %d: ",
1085 struct cleanup
*cleanups
= make_cleanup (xfree
, prefix
);
1086 val
= catch_exceptions (uiout
, insert_catchpoint
, b
, prefix
,
1088 do_cleanups (cleanups
);
1090 b
->enable_state
= bp_disabled
;
1098 /* If a hardware breakpoint or watchpoint was inserted, add a
1099 message about possibly exhausted resources. */
1100 if (hw_breakpoint_error
)
1102 fprintf_unfiltered (tmp_error_stream
,
1103 "Could not insert hardware breakpoints:\n\
1104 You may have requested too many hardware breakpoints/watchpoints.\n");
1106 #ifdef ONE_PROCESS_WRITETEXT
1107 if (process_warning
)
1108 fprintf_unfiltered (tmp_error_stream
,
1109 "The same program may be running in another process.");
1111 target_terminal_ours_for_output ();
1112 error_stream (tmp_error_stream
);
1118 remove_breakpoints (void)
1120 struct breakpoint
*b
;
1127 val
= remove_breakpoint (b
, mark_uninserted
);
1136 remove_hw_watchpoints (void)
1138 struct breakpoint
*b
;
1144 && (b
->type
== bp_hardware_watchpoint
1145 || b
->type
== bp_read_watchpoint
1146 || b
->type
== bp_access_watchpoint
))
1148 val
= remove_breakpoint (b
, mark_uninserted
);
1157 reattach_breakpoints (int pid
)
1159 struct breakpoint
*b
;
1161 struct cleanup
*old_chain
= save_inferior_ptid ();
1163 /* Set inferior_ptid; remove_breakpoint uses this global. */
1164 inferior_ptid
= pid_to_ptid (pid
);
1169 remove_breakpoint (b
, mark_inserted
);
1170 if (b
->type
== bp_hardware_breakpoint
)
1171 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1173 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1176 do_cleanups (old_chain
);
1181 do_cleanups (old_chain
);
1186 update_breakpoints_after_exec (void)
1188 struct breakpoint
*b
;
1189 struct breakpoint
*temp
;
1191 /* Doing this first prevents the badness of having delete_breakpoint()
1192 write a breakpoint's current "shadow contents" to lift the bp. That
1193 shadow is NOT valid after an exec()! */
1194 mark_breakpoints_out ();
1196 ALL_BREAKPOINTS_SAFE (b
, temp
)
1198 /* Solib breakpoints must be explicitly reset after an exec(). */
1199 if (b
->type
== bp_shlib_event
)
1201 delete_breakpoint (b
);
1205 /* Thread event breakpoints must be set anew after an exec(),
1206 as must overlay event breakpoints. */
1207 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1209 delete_breakpoint (b
);
1213 /* Step-resume breakpoints are meaningless after an exec(). */
1214 if (b
->type
== bp_step_resume
)
1216 delete_breakpoint (b
);
1220 /* Ditto the sigtramp handler breakpoints. */
1221 if (b
->type
== bp_through_sigtramp
)
1223 delete_breakpoint (b
);
1227 /* Ditto the exception-handling catchpoints. */
1228 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1230 delete_breakpoint (b
);
1234 /* Don't delete an exec catchpoint, because else the inferior
1235 won't stop when it ought!
1237 Similarly, we probably ought to keep vfork catchpoints, 'cause
1238 on this target, we may not be able to stop when the vfork is
1239 seen, but only when the subsequent exec is seen. (And because
1240 deleting fork catchpoints here but not vfork catchpoints will
1241 seem mysterious to users, keep those too.)
1243 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1244 target address field, if any, is sufficient to have it be reset
1245 automagically. Certainly on HP-UX that's true.
1247 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1248 valid code address on some platforms (like the mn10300
1249 simulators). We shouldn't assign any special interpretation to
1250 a breakpoint with a zero address. And in fact, GDB doesn't ---
1251 I can't see what that comment above is talking about. As far
1252 as I can tell, setting the address of a
1253 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1254 is meaningless, since those are implemented with HP-UX kernel
1255 hackery, not by storing breakpoint instructions somewhere. */
1256 if ((b
->type
== bp_catch_exec
) ||
1257 (b
->type
== bp_catch_vfork
) ||
1258 (b
->type
== bp_catch_fork
))
1260 b
->address
= (CORE_ADDR
) NULL
;
1264 /* bp_finish is a special case. The only way we ought to be able
1265 to see one of these when an exec() has happened, is if the user
1266 caught a vfork, and then said "finish". Ordinarily a finish just
1267 carries them to the call-site of the current callee, by setting
1268 a temporary bp there and resuming. But in this case, the finish
1269 will carry them entirely through the vfork & exec.
1271 We don't want to allow a bp_finish to remain inserted now. But
1272 we can't safely delete it, 'cause finish_command has a handle to
1273 the bp on a bpstat, and will later want to delete it. There's a
1274 chance (and I've seen it happen) that if we delete the bp_finish
1275 here, that its storage will get reused by the time finish_command
1276 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1277 We really must allow finish_command to delete a bp_finish.
1279 In the absense of a general solution for the "how do we know
1280 it's safe to delete something others may have handles to?"
1281 problem, what we'll do here is just uninsert the bp_finish, and
1282 let finish_command delete it.
1284 (We know the bp_finish is "doomed" in the sense that it's
1285 momentary, and will be deleted as soon as finish_command sees
1286 the inferior stopped. So it doesn't matter that the bp's
1287 address is probably bogus in the new a.out, unlike e.g., the
1288 solib breakpoints.) */
1290 if (b
->type
== bp_finish
)
1295 /* Without a symbolic address, we have little hope of the
1296 pre-exec() address meaning the same thing in the post-exec()
1298 if (b
->addr_string
== NULL
)
1300 delete_breakpoint (b
);
1304 /* If this breakpoint has survived the above battery of checks, then
1305 it must have a symbolic address. Be sure that it gets reevaluated
1306 to a target address, rather than reusing the old evaluation.
1308 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1309 for bp_catch_exec and friends, I'm pretty sure this is entirely
1310 unnecessary. A call to breakpoint_re_set_one always recomputes
1311 the breakpoint's address from scratch, or deletes it if it can't.
1312 So I think this assignment could be deleted without effect. */
1313 b
->address
= (CORE_ADDR
) NULL
;
1315 /* FIXME what about longjmp breakpoints? Re-create them here? */
1316 create_overlay_event_breakpoint ("_ovly_debug_event");
1320 detach_breakpoints (int pid
)
1322 struct breakpoint
*b
;
1324 struct cleanup
*old_chain
= save_inferior_ptid ();
1326 if (pid
== PIDGET (inferior_ptid
))
1327 error ("Cannot detach breakpoints of inferior_ptid");
1329 /* Set inferior_ptid; remove_breakpoint uses this global. */
1330 inferior_ptid
= pid_to_ptid (pid
);
1335 val
= remove_breakpoint (b
, mark_inserted
);
1338 do_cleanups (old_chain
);
1343 do_cleanups (old_chain
);
1348 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1352 if (b
->enable_state
== bp_permanent
)
1353 /* Permanent breakpoints cannot be inserted or removed. */
1356 if (b
->type
== bp_none
)
1357 warning ("attempted to remove apparently deleted breakpoint #%d?",
1360 if (b
->type
!= bp_watchpoint
1361 && b
->type
!= bp_hardware_watchpoint
1362 && b
->type
!= bp_read_watchpoint
1363 && b
->type
!= bp_access_watchpoint
1364 && b
->type
!= bp_catch_fork
1365 && b
->type
!= bp_catch_vfork
1366 && b
->type
!= bp_catch_exec
1367 && b
->type
!= bp_catch_catch
1368 && b
->type
!= bp_catch_throw
)
1370 /* "Normal" instruction breakpoint: either the standard
1371 trap-instruction bp (bp_breakpoint), or a
1372 bp_hardware_breakpoint. */
1374 /* First check to see if we have to handle an overlay. */
1375 if (overlay_debugging
== ovly_off
1376 || b
->section
== NULL
1377 || !(section_is_overlay (b
->section
)))
1379 /* No overlay handling: just remove the breakpoint. */
1381 if (b
->type
== bp_hardware_breakpoint
)
1382 val
= target_remove_hw_breakpoint (b
->address
,
1383 b
->shadow_contents
);
1385 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1389 /* This breakpoint is in an overlay section.
1390 Did we set a breakpoint at the LMA? */
1391 if (!overlay_events_enabled
)
1393 /* Yes -- overlay event support is not active, so we
1394 should have set a breakpoint at the LMA. Remove it.
1396 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1398 /* Ignore any failures: if the LMA is in ROM, we will
1399 have already warned when we failed to insert it. */
1400 if (b
->type
!= bp_hardware_breakpoint
)
1401 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1403 target_remove_breakpoint (addr
, b
->shadow_contents
);
1405 /* Did we set a breakpoint at the VMA?
1406 If so, we will have marked the breakpoint 'inserted'. */
1409 /* Yes -- remove it. Previously we did not bother to
1410 remove the breakpoint if the section had been
1411 unmapped, but let's not rely on that being safe. We
1412 don't know what the overlay manager might do. */
1413 if (b
->type
== bp_hardware_breakpoint
)
1414 val
= target_remove_hw_breakpoint (b
->address
,
1415 b
->shadow_contents
);
1417 val
= target_remove_breakpoint (b
->address
,
1418 b
->shadow_contents
);
1422 /* No -- not inserted, so no need to remove. No error. */
1428 b
->inserted
= (is
== mark_inserted
);
1430 else if ((b
->type
== bp_hardware_watchpoint
||
1431 b
->type
== bp_read_watchpoint
||
1432 b
->type
== bp_access_watchpoint
)
1433 && b
->enable_state
== bp_enabled
1439 b
->inserted
= (is
== mark_inserted
);
1440 /* Walk down the saved value chain. */
1441 for (v
= b
->val_chain
; v
; v
= v
->next
)
1443 /* For each memory reference remove the watchpoint
1445 if (VALUE_LVAL (v
) == lval_memory
1446 && ! VALUE_LAZY (v
))
1448 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1450 if (v
== b
->val_chain
1451 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1452 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1457 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1458 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1460 if (b
->type
== bp_read_watchpoint
)
1462 else if (b
->type
== bp_access_watchpoint
)
1465 val
= target_remove_watchpoint (addr
, len
, type
);
1472 /* Failure to remove any of the hardware watchpoints comes here. */
1473 if ((is
== mark_uninserted
) && (b
->inserted
))
1474 warning ("Could not remove hardware watchpoint %d.",
1477 /* Free the saved value chain. We will construct a new one
1478 the next time the watchpoint is inserted. */
1479 for (v
= b
->val_chain
; v
; v
= n
)
1484 b
->val_chain
= NULL
;
1486 else if ((b
->type
== bp_catch_fork
||
1487 b
->type
== bp_catch_vfork
||
1488 b
->type
== bp_catch_exec
)
1489 && b
->enable_state
== bp_enabled
1496 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1498 case bp_catch_vfork
:
1499 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1502 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1505 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1510 b
->inserted
= (is
== mark_inserted
);
1512 else if ((b
->type
== bp_catch_catch
||
1513 b
->type
== bp_catch_throw
)
1514 && b
->enable_state
== bp_enabled
1518 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1521 b
->inserted
= (is
== mark_inserted
);
1523 else if (ep_is_exception_catchpoint (b
)
1524 && b
->inserted
/* sometimes previous insert doesn't happen */
1525 && b
->enable_state
== bp_enabled
1529 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1533 b
->inserted
= (is
== mark_inserted
);
1539 /* Clear the "inserted" flag in all breakpoints. */
1542 mark_breakpoints_out (void)
1544 struct breakpoint
*b
;
1550 /* Clear the "inserted" flag in all breakpoints and delete any
1551 breakpoints which should go away between runs of the program.
1553 Plus other such housekeeping that has to be done for breakpoints
1556 Note: this function gets called at the end of a run (by
1557 generic_mourn_inferior) and when a run begins (by
1558 init_wait_for_inferior). */
1563 breakpoint_init_inferior (enum inf_context context
)
1565 struct breakpoint
*b
, *temp
;
1566 static int warning_needed
= 0;
1568 ALL_BREAKPOINTS_SAFE (b
, temp
)
1575 case bp_watchpoint_scope
:
1577 /* If the call dummy breakpoint is at the entry point it will
1578 cause problems when the inferior is rerun, so we better
1581 Also get rid of scope breakpoints. */
1582 delete_breakpoint (b
);
1586 case bp_hardware_watchpoint
:
1587 case bp_read_watchpoint
:
1588 case bp_access_watchpoint
:
1590 /* Likewise for watchpoints on local expressions. */
1591 if (b
->exp_valid_block
!= NULL
)
1592 delete_breakpoint (b
);
1593 if (context
== inf_starting
)
1595 /* Reset val field to force reread of starting value
1596 in insert_breakpoints. */
1598 value_free (b
->val
);
1603 /* Likewise for exception catchpoints in dynamic-linked
1604 executables where required */
1605 if (ep_is_exception_catchpoint (b
) &&
1606 exception_catchpoints_are_fragile
)
1609 delete_breakpoint (b
);
1615 if (exception_catchpoints_are_fragile
)
1616 exception_support_initialized
= 0;
1618 /* Don't issue the warning unless it's really needed... */
1619 if (warning_needed
&& (context
!= inf_exited
))
1621 warning ("Exception catchpoints from last run were deleted.");
1622 warning ("You must reinsert them explicitly.");
1627 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1628 exists at PC. It returns ordinary_breakpoint_here if it's an
1629 ordinary breakpoint, or permanent_breakpoint_here if it's a
1630 permanent breakpoint.
1631 - When continuing from a location with an ordinary breakpoint, we
1632 actually single step once before calling insert_breakpoints.
1633 - When continuing from a localion with a permanent breakpoint, we
1634 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1635 the target, to advance the PC past the breakpoint. */
1637 enum breakpoint_here
1638 breakpoint_here_p (CORE_ADDR pc
)
1640 struct breakpoint
*b
;
1641 int any_breakpoint_here
= 0;
1644 if ((b
->enable_state
== bp_enabled
1645 || b
->enable_state
== bp_permanent
)
1646 && b
->address
== pc
) /* bp is enabled and matches pc */
1648 if (overlay_debugging
1649 && section_is_overlay (b
->section
)
1650 && !section_is_mapped (b
->section
))
1651 continue; /* unmapped overlay -- can't be a match */
1652 else if (b
->enable_state
== bp_permanent
)
1653 return permanent_breakpoint_here
;
1655 any_breakpoint_here
= 1;
1658 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1662 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1663 but it only returns true if there is actually a breakpoint inserted
1667 breakpoint_inserted_here_p (CORE_ADDR pc
)
1669 struct breakpoint
*b
;
1673 && b
->address
== pc
) /* bp is inserted and matches pc */
1675 if (overlay_debugging
1676 && section_is_overlay (b
->section
)
1677 && !section_is_mapped (b
->section
))
1678 continue; /* unmapped overlay -- can't be a match */
1686 /* Return nonzero if FRAME is a dummy frame. We can't use
1687 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1688 take too much time, at least using frame_register() on the 68k.
1689 This means that for this function to work right a port must use the
1690 bp_call_dummy breakpoint. */
1693 deprecated_frame_in_dummy (struct frame_info
*frame
)
1695 struct breakpoint
*b
;
1697 /* This function is used by two files: get_frame_type(), after first
1698 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1699 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1700 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES
);
1704 if (b
->type
== bp_call_dummy
1705 && frame_id_eq (b
->frame_id
, get_frame_id (frame
))
1706 /* We need to check the PC as well as the frame on the sparc,
1707 for signals.exp in the testsuite. */
1708 && (get_frame_pc (frame
)
1710 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * DEPRECATED_REGISTER_SIZE
))
1711 && get_frame_pc (frame
) <= b
->address
)
1717 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1718 PC is valid for process/thread PID. */
1721 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1723 struct breakpoint
*b
;
1726 thread
= pid_to_thread_id (ptid
);
1729 if (b
->enable_state
!= bp_disabled
1730 && b
->enable_state
!= bp_shlib_disabled
1731 && b
->enable_state
!= bp_call_disabled
1733 && (b
->thread
== -1 || b
->thread
== thread
))
1735 if (overlay_debugging
1736 && section_is_overlay (b
->section
)
1737 && !section_is_mapped (b
->section
))
1738 continue; /* unmapped overlay -- can't be a match */
1747 /* bpstat stuff. External routines' interfaces are documented
1751 ep_is_catchpoint (struct breakpoint
*ep
)
1754 (ep
->type
== bp_catch_load
)
1755 || (ep
->type
== bp_catch_unload
)
1756 || (ep
->type
== bp_catch_fork
)
1757 || (ep
->type
== bp_catch_vfork
)
1758 || (ep
->type
== bp_catch_exec
)
1759 || (ep
->type
== bp_catch_catch
)
1760 || (ep
->type
== bp_catch_throw
);
1762 /* ??rehrauer: Add more kinds here, as are implemented... */
1766 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1769 (ep
->type
== bp_catch_load
)
1770 || (ep
->type
== bp_catch_unload
);
1774 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1777 (ep
->type
== bp_catch_catch
)
1778 || (ep
->type
== bp_catch_throw
);
1781 /* Clear a bpstat so that it says we are not at any breakpoint.
1782 Also free any storage that is part of a bpstat. */
1785 bpstat_clear (bpstat
*bsp
)
1796 if (p
->old_val
!= NULL
)
1797 value_free (p
->old_val
);
1798 free_command_lines (&p
->commands
);
1805 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1806 is part of the bpstat is copied as well. */
1809 bpstat_copy (bpstat bs
)
1813 bpstat retval
= NULL
;
1818 for (; bs
!= NULL
; bs
= bs
->next
)
1820 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1821 memcpy (tmp
, bs
, sizeof (*tmp
));
1822 if (bs
->commands
!= NULL
)
1823 tmp
->commands
= copy_command_lines (bs
->commands
);
1824 if (bs
->old_val
!= NULL
)
1825 tmp
->old_val
= value_copy (bs
->old_val
);
1828 /* This is the first thing in the chain. */
1838 /* Find the bpstat associated with this breakpoint */
1841 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1846 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1848 if (bsp
->breakpoint_at
== breakpoint
)
1854 /* Find a step_resume breakpoint associated with this bpstat.
1855 (If there are multiple step_resume bp's on the list, this function
1856 will arbitrarily pick one.)
1858 It is an error to use this function if BPSTAT doesn't contain a
1859 step_resume breakpoint.
1861 See wait_for_inferior's use of this function. */
1863 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1868 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1870 current_thread
= pid_to_thread_id (inferior_ptid
);
1872 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1874 if ((bsp
->breakpoint_at
!= NULL
) &&
1875 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1876 (bsp
->breakpoint_at
->thread
== current_thread
||
1877 bsp
->breakpoint_at
->thread
== -1))
1878 return bsp
->breakpoint_at
;
1881 error ("Internal error (no step_resume breakpoint found)");
1885 /* Return the breakpoint number of the first breakpoint we are stopped
1886 at. *BSP upon return is a bpstat which points to the remaining
1887 breakpoints stopped at (but which is not guaranteed to be good for
1888 anything but further calls to bpstat_num).
1889 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1892 bpstat_num (bpstat
*bsp
)
1894 struct breakpoint
*b
;
1897 return 0; /* No more breakpoint values */
1900 b
= (*bsp
)->breakpoint_at
;
1901 *bsp
= (*bsp
)->next
;
1903 return -1; /* breakpoint that's been deleted since */
1905 return b
->number
; /* We have its number */
1909 /* Modify BS so that the actions will not be performed. */
1912 bpstat_clear_actions (bpstat bs
)
1914 for (; bs
!= NULL
; bs
= bs
->next
)
1916 free_command_lines (&bs
->commands
);
1917 if (bs
->old_val
!= NULL
)
1919 value_free (bs
->old_val
);
1925 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1927 cleanup_executing_breakpoints (void *ignore
)
1929 executing_breakpoint_commands
= 0;
1932 /* Execute all the commands associated with all the breakpoints at this
1933 location. Any of these commands could cause the process to proceed
1934 beyond this point, etc. We look out for such changes by checking
1935 the global "breakpoint_proceeded" after each command. */
1938 bpstat_do_actions (bpstat
*bsp
)
1941 struct cleanup
*old_chain
;
1942 struct command_line
*cmd
;
1944 /* Avoid endless recursion if a `source' command is contained
1946 if (executing_breakpoint_commands
)
1949 executing_breakpoint_commands
= 1;
1950 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1953 /* Note that (as of this writing), our callers all appear to
1954 be passing us the address of global stop_bpstat. And, if
1955 our calls to execute_control_command cause the inferior to
1956 proceed, that global (and hence, *bsp) will change.
1958 We must be careful to not touch *bsp unless the inferior
1959 has not proceeded. */
1961 /* This pointer will iterate over the list of bpstat's. */
1964 breakpoint_proceeded
= 0;
1965 for (; bs
!= NULL
; bs
= bs
->next
)
1970 execute_control_command (cmd
);
1972 if (breakpoint_proceeded
)
1977 if (breakpoint_proceeded
)
1978 /* The inferior is proceeded by the command; bomb out now.
1979 The bpstat chain has been blown away by wait_for_inferior.
1980 But since execution has stopped again, there is a new bpstat
1981 to look at, so start over. */
1984 free_command_lines (&bs
->commands
);
1986 do_cleanups (old_chain
);
1989 /* This is the normal print function for a bpstat. In the future,
1990 much of this logic could (should?) be moved to bpstat_stop_status,
1991 by having it set different print_it values.
1993 Current scheme: When we stop, bpstat_print() is called. It loops
1994 through the bpstat list of things causing this stop, calling the
1995 print_bp_stop_message function on each one. The behavior of the
1996 print_bp_stop_message function depends on the print_it field of
1997 bpstat. If such field so indicates, call this function here.
1999 Return values from this routine (ultimately used by bpstat_print()
2000 and normal_stop() to decide what to do):
2001 PRINT_NOTHING: Means we already printed all we needed to print,
2002 don't print anything else.
2003 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2004 that something to be followed by a location.
2005 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2006 that something to be followed by a location.
2007 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2010 static enum print_stop_action
2011 print_it_typical (bpstat bs
)
2013 struct cleanup
*old_chain
, *ui_out_chain
;
2014 struct ui_stream
*stb
;
2015 stb
= ui_out_stream_new (uiout
);
2016 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2017 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2018 which has since been deleted. */
2019 if (bs
->breakpoint_at
== NULL
)
2020 return PRINT_UNKNOWN
;
2022 switch (bs
->breakpoint_at
->type
)
2025 case bp_hardware_breakpoint
:
2026 annotate_breakpoint (bs
->breakpoint_at
->number
);
2027 ui_out_text (uiout
, "\nBreakpoint ");
2028 if (ui_out_is_mi_like_p (uiout
))
2029 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
2030 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2031 ui_out_text (uiout
, ", ");
2032 return PRINT_SRC_AND_LOC
;
2035 case bp_shlib_event
:
2036 /* Did we stop because the user set the stop_on_solib_events
2037 variable? (If so, we report this as a generic, "Stopped due
2038 to shlib event" message.) */
2039 printf_filtered ("Stopped due to shared library event\n");
2040 return PRINT_NOTHING
;
2043 case bp_thread_event
:
2044 /* Not sure how we will get here.
2045 GDB should not stop for these breakpoints. */
2046 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2047 return PRINT_NOTHING
;
2050 case bp_overlay_event
:
2051 /* By analogy with the thread event, GDB should not stop for these. */
2052 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2053 return PRINT_NOTHING
;
2057 annotate_catchpoint (bs
->breakpoint_at
->number
);
2058 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2059 printf_filtered ("loaded");
2060 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2061 return PRINT_SRC_AND_LOC
;
2064 case bp_catch_unload
:
2065 annotate_catchpoint (bs
->breakpoint_at
->number
);
2066 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2067 printf_filtered ("unloaded");
2068 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2069 return PRINT_SRC_AND_LOC
;
2073 annotate_catchpoint (bs
->breakpoint_at
->number
);
2074 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2075 printf_filtered ("forked");
2076 printf_filtered (" process %d), ",
2077 bs
->breakpoint_at
->forked_inferior_pid
);
2078 return PRINT_SRC_AND_LOC
;
2081 case bp_catch_vfork
:
2082 annotate_catchpoint (bs
->breakpoint_at
->number
);
2083 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2084 printf_filtered ("vforked");
2085 printf_filtered (" process %d), ",
2086 bs
->breakpoint_at
->forked_inferior_pid
);
2087 return PRINT_SRC_AND_LOC
;
2091 annotate_catchpoint (bs
->breakpoint_at
->number
);
2092 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2093 bs
->breakpoint_at
->number
,
2094 bs
->breakpoint_at
->exec_pathname
);
2095 return PRINT_SRC_AND_LOC
;
2098 case bp_catch_catch
:
2099 if (current_exception_event
&&
2100 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2102 annotate_catchpoint (bs
->breakpoint_at
->number
);
2103 printf_filtered ("\nCatchpoint %d (exception caught), ",
2104 bs
->breakpoint_at
->number
);
2105 printf_filtered ("throw location ");
2106 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2107 printf_filtered ("%s:%d",
2108 CURRENT_EXCEPTION_THROW_FILE
,
2109 CURRENT_EXCEPTION_THROW_LINE
);
2111 printf_filtered ("unknown");
2113 printf_filtered (", catch location ");
2114 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2115 printf_filtered ("%s:%d",
2116 CURRENT_EXCEPTION_CATCH_FILE
,
2117 CURRENT_EXCEPTION_CATCH_LINE
);
2119 printf_filtered ("unknown");
2121 printf_filtered ("\n");
2122 /* don't bother to print location frame info */
2123 return PRINT_SRC_ONLY
;
2127 /* really throw, some other bpstat will handle it */
2128 return PRINT_UNKNOWN
;
2132 case bp_catch_throw
:
2133 if (current_exception_event
&&
2134 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2136 annotate_catchpoint (bs
->breakpoint_at
->number
);
2137 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2138 bs
->breakpoint_at
->number
);
2139 printf_filtered ("throw location ");
2140 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2141 printf_filtered ("%s:%d",
2142 CURRENT_EXCEPTION_THROW_FILE
,
2143 CURRENT_EXCEPTION_THROW_LINE
);
2145 printf_filtered ("unknown");
2147 printf_filtered (", catch location ");
2148 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2149 printf_filtered ("%s:%d",
2150 CURRENT_EXCEPTION_CATCH_FILE
,
2151 CURRENT_EXCEPTION_CATCH_LINE
);
2153 printf_filtered ("unknown");
2155 printf_filtered ("\n");
2156 /* don't bother to print location frame info */
2157 return PRINT_SRC_ONLY
;
2161 /* really catch, some other bpstat will handle it */
2162 return PRINT_UNKNOWN
;
2167 case bp_hardware_watchpoint
:
2168 if (bs
->old_val
!= NULL
)
2170 annotate_watchpoint (bs
->breakpoint_at
->number
);
2171 if (ui_out_is_mi_like_p (uiout
))
2172 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2173 mention (bs
->breakpoint_at
);
2174 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2175 ui_out_text (uiout
, "\nOld value = ");
2176 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2177 ui_out_field_stream (uiout
, "old", stb
);
2178 ui_out_text (uiout
, "\nNew value = ");
2179 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2180 ui_out_field_stream (uiout
, "new", stb
);
2181 do_cleanups (ui_out_chain
);
2182 ui_out_text (uiout
, "\n");
2183 value_free (bs
->old_val
);
2186 /* More than one watchpoint may have been triggered. */
2187 return PRINT_UNKNOWN
;
2190 case bp_read_watchpoint
:
2191 if (ui_out_is_mi_like_p (uiout
))
2192 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2193 mention (bs
->breakpoint_at
);
2194 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2195 ui_out_text (uiout
, "\nValue = ");
2196 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2197 ui_out_field_stream (uiout
, "value", stb
);
2198 do_cleanups (ui_out_chain
);
2199 ui_out_text (uiout
, "\n");
2200 return PRINT_UNKNOWN
;
2203 case bp_access_watchpoint
:
2204 if (bs
->old_val
!= NULL
)
2206 annotate_watchpoint (bs
->breakpoint_at
->number
);
2207 if (ui_out_is_mi_like_p (uiout
))
2208 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2209 mention (bs
->breakpoint_at
);
2210 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2211 ui_out_text (uiout
, "\nOld value = ");
2212 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2213 ui_out_field_stream (uiout
, "old", stb
);
2214 value_free (bs
->old_val
);
2216 ui_out_text (uiout
, "\nNew value = ");
2220 mention (bs
->breakpoint_at
);
2221 if (ui_out_is_mi_like_p (uiout
))
2222 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2223 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2224 ui_out_text (uiout
, "\nValue = ");
2226 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2227 ui_out_field_stream (uiout
, "new", stb
);
2228 do_cleanups (ui_out_chain
);
2229 ui_out_text (uiout
, "\n");
2230 return PRINT_UNKNOWN
;
2233 /* Fall through, we don't deal with these types of breakpoints
2237 if (ui_out_is_mi_like_p (uiout
))
2238 ui_out_field_string (uiout
, "reason", "function-finished");
2239 return PRINT_UNKNOWN
;
2243 if (ui_out_is_mi_like_p (uiout
))
2244 ui_out_field_string (uiout
, "reason", "location-reached");
2245 return PRINT_UNKNOWN
;
2250 case bp_longjmp_resume
:
2251 case bp_step_resume
:
2252 case bp_through_sigtramp
:
2253 case bp_watchpoint_scope
:
2256 return PRINT_UNKNOWN
;
2260 /* Generic routine for printing messages indicating why we
2261 stopped. The behavior of this function depends on the value
2262 'print_it' in the bpstat structure. Under some circumstances we
2263 may decide not to print anything here and delegate the task to
2266 static enum print_stop_action
2267 print_bp_stop_message (bpstat bs
)
2269 switch (bs
->print_it
)
2272 /* Nothing should be printed for this bpstat entry. */
2273 return PRINT_UNKNOWN
;
2277 /* We still want to print the frame, but we already printed the
2278 relevant messages. */
2279 return PRINT_SRC_AND_LOC
;
2282 case print_it_normal
:
2283 /* Normal case. Call the breakpoint's print_it method, or
2284 print_it_typical. */
2285 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2286 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2287 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2289 return print_it_typical (bs
);
2293 internal_error (__FILE__
, __LINE__
,
2294 "print_bp_stop_message: unrecognized enum value");
2299 /* Print a message indicating what happened. This is called from
2300 normal_stop(). The input to this routine is the head of the bpstat
2301 list - a list of the eventpoints that caused this stop. This
2302 routine calls the generic print routine for printing a message
2303 about reasons for stopping. This will print (for example) the
2304 "Breakpoint n," part of the output. The return value of this
2307 PRINT_UNKNOWN: Means we printed nothing
2308 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2309 code to print the location. An example is
2310 "Breakpoint 1, " which should be followed by
2312 PRINT_SRC_ONLY: Means we printed something, but there is no need
2313 to also print the location part of the message.
2314 An example is the catch/throw messages, which
2315 don't require a location appended to the end.
2316 PRINT_NOTHING: We have done some printing and we don't need any
2317 further info to be printed.*/
2319 enum print_stop_action
2320 bpstat_print (bpstat bs
)
2324 /* Maybe another breakpoint in the chain caused us to stop.
2325 (Currently all watchpoints go on the bpstat whether hit or not.
2326 That probably could (should) be changed, provided care is taken
2327 with respect to bpstat_explains_signal). */
2328 for (; bs
; bs
= bs
->next
)
2330 val
= print_bp_stop_message (bs
);
2331 if (val
== PRINT_SRC_ONLY
2332 || val
== PRINT_SRC_AND_LOC
2333 || val
== PRINT_NOTHING
)
2337 /* We reached the end of the chain, or we got a null BS to start
2338 with and nothing was printed. */
2339 return PRINT_UNKNOWN
;
2342 /* Evaluate the expression EXP and return 1 if value is zero.
2343 This is used inside a catch_errors to evaluate the breakpoint condition.
2344 The argument is a "struct expression *" that has been cast to char * to
2345 make it pass through catch_errors. */
2348 breakpoint_cond_eval (void *exp
)
2350 struct value
*mark
= value_mark ();
2351 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2352 value_free_to_mark (mark
);
2356 /* Allocate a new bpstat and chain it to the current one. */
2359 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2363 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2365 bs
->breakpoint_at
= b
;
2366 /* If the condition is false, etc., don't do the commands. */
2367 bs
->commands
= NULL
;
2369 bs
->print_it
= print_it_normal
;
2373 /* Possible return values for watchpoint_check (this can't be an enum
2374 because of check_errors). */
2375 /* The watchpoint has been deleted. */
2376 #define WP_DELETED 1
2377 /* The value has changed. */
2378 #define WP_VALUE_CHANGED 2
2379 /* The value has not changed. */
2380 #define WP_VALUE_NOT_CHANGED 3
2382 #define BP_TEMPFLAG 1
2383 #define BP_HARDWAREFLAG 2
2385 /* Check watchpoint condition. */
2388 watchpoint_check (void *p
)
2390 bpstat bs
= (bpstat
) p
;
2391 struct breakpoint
*b
;
2392 struct frame_info
*fr
;
2393 int within_current_scope
;
2395 struct frame_id current_frame_id
;
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.
2416 vinschen/2003-09-04: The former implementation left out the case
2417 that the watchpoint frame couldn't be found by frame_find_by_id()
2418 because the current PC is currently in an epilogue. Calling
2419 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2420 if ((!within_current_scope
|| fr
== get_current_frame ())
2421 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2422 return WP_VALUE_NOT_CHANGED
;
2423 if (fr
&& within_current_scope
)
2424 /* If we end up stopping, the current frame will get selected
2425 in normal_stop. So this call to select_frame won't affect
2430 if (within_current_scope
)
2432 /* We use value_{,free_to_}mark because it could be a
2433 *long* time before we return to the command level and
2434 call free_all_values. We can't call free_all_values because
2435 we might be in the middle of evaluating a function call. */
2437 struct value
*mark
= value_mark ();
2438 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2439 if (!value_equal (b
->val
, new_val
))
2441 release_value (new_val
);
2442 value_free_to_mark (mark
);
2443 bs
->old_val
= b
->val
;
2445 /* We will stop here */
2446 return WP_VALUE_CHANGED
;
2450 /* Nothing changed, don't do anything. */
2451 value_free_to_mark (mark
);
2452 /* We won't stop here */
2453 return WP_VALUE_NOT_CHANGED
;
2458 /* This seems like the only logical thing to do because
2459 if we temporarily ignored the watchpoint, then when
2460 we reenter the block in which it is valid it contains
2461 garbage (in the case of a function, it may have two
2462 garbage values, one before and one after the prologue).
2463 So we can't even detect the first assignment to it and
2464 watch after that (since the garbage may or may not equal
2465 the first value assigned). */
2466 /* We print all the stop information in print_it_typical(), but
2467 in this case, by the time we call print_it_typical() this bp
2468 will be deleted already. So we have no choice but print the
2469 information here. */
2470 if (ui_out_is_mi_like_p (uiout
))
2471 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2472 ui_out_text (uiout
, "\nWatchpoint ");
2473 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2474 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2475 which its expression is valid.\n");
2477 if (b
->related_breakpoint
)
2478 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2479 b
->disposition
= disp_del_at_next_stop
;
2485 /* Get a bpstat associated with having just stopped at address *PC
2486 and frame address CORE_ADDRESS. Update *PC to point at the
2487 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2488 if this is known to not be a real breakpoint (it could still be a
2489 watchpoint, though). */
2491 /* Determine whether we stopped at a breakpoint, etc, or whether we
2492 don't understand this stop. Result is a chain of bpstat's such that:
2494 if we don't understand the stop, the result is a null pointer.
2496 if we understand why we stopped, the result is not null.
2498 Each element of the chain refers to a particular breakpoint or
2499 watchpoint at which we have stopped. (We may have stopped for
2500 several reasons concurrently.)
2502 Each element of the chain has valid next, breakpoint_at,
2503 commands, FIXME??? fields. */
2506 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_sw_breakpoint
)
2508 struct breakpoint
*b
, *temp
;
2510 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2511 int real_breakpoint
= 0;
2512 /* Root of the chain of bpstat's */
2513 struct bpstats root_bs
[1];
2514 /* Pointer to the last thing in the chain currently. */
2515 bpstat bs
= root_bs
;
2517 /* Get the address where the breakpoint would have been. The
2518 "not_a_sw_breakpoint" argument is meant to distinguish between a
2519 breakpoint trap event and a trace/singlestep trap event. For a
2520 trace/singlestep trap event, we would not want to subtract
2521 DECR_PC_AFTER_BREAK from the PC. */
2523 bp_addr
= *pc
- (not_a_sw_breakpoint
? 0 : DECR_PC_AFTER_BREAK
);
2525 ALL_BREAKPOINTS_SAFE (b
, temp
)
2527 if (b
->enable_state
== bp_disabled
2528 || b
->enable_state
== bp_shlib_disabled
2529 || b
->enable_state
== bp_call_disabled
)
2532 if (b
->type
!= bp_watchpoint
2533 && b
->type
!= bp_hardware_watchpoint
2534 && b
->type
!= bp_read_watchpoint
2535 && b
->type
!= bp_access_watchpoint
2536 && b
->type
!= bp_hardware_breakpoint
2537 && b
->type
!= bp_catch_fork
2538 && b
->type
!= bp_catch_vfork
2539 && b
->type
!= bp_catch_exec
2540 && b
->type
!= bp_catch_catch
2541 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2543 if (b
->address
!= bp_addr
) /* address doesn't match */
2545 if (overlay_debugging
/* unmapped overlay section */
2546 && section_is_overlay (b
->section
)
2547 && !section_is_mapped (b
->section
))
2551 if (b
->type
== bp_hardware_breakpoint
)
2553 if (b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2555 if (overlay_debugging
/* unmapped overlay section */
2556 && section_is_overlay (b
->section
)
2557 && !section_is_mapped (b
->section
))
2561 /* Is this a catchpoint of a load or unload? If so, did we
2562 get a load or unload of the specified library? If not,
2564 if ((b
->type
== bp_catch_load
)
2565 #if defined(SOLIB_HAVE_LOAD_EVENT)
2566 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2567 || ((b
->dll_pathname
!= NULL
)
2568 && (strcmp (b
->dll_pathname
,
2569 SOLIB_LOADED_LIBRARY_PATHNAME (
2570 PIDGET (inferior_ptid
)))
2576 if ((b
->type
== bp_catch_unload
)
2577 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2578 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2579 || ((b
->dll_pathname
!= NULL
)
2580 && (strcmp (b
->dll_pathname
,
2581 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2582 PIDGET (inferior_ptid
)))
2588 if ((b
->type
== bp_catch_fork
)
2589 && !inferior_has_forked (PIDGET (inferior_ptid
),
2590 &b
->forked_inferior_pid
))
2593 if ((b
->type
== bp_catch_vfork
)
2594 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2595 &b
->forked_inferior_pid
))
2598 if ((b
->type
== bp_catch_exec
)
2599 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2602 if (ep_is_exception_catchpoint (b
) &&
2603 !(current_exception_event
= target_get_current_exception_event ()))
2606 /* Come here if it's a watchpoint, or if the break address matches */
2608 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2610 /* Watchpoints may change this, if not found to have triggered. */
2614 if (b
->type
== bp_watchpoint
||
2615 b
->type
== bp_hardware_watchpoint
)
2617 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2619 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2620 int e
= catch_errors (watchpoint_check
, bs
, message
,
2622 do_cleanups (cleanups
);
2626 /* We've already printed what needs to be printed. */
2627 /* Actually this is superfluous, because by the time we
2628 call print_it_typical() the wp will be already deleted,
2629 and the function will return immediately. */
2630 bs
->print_it
= print_it_done
;
2633 case WP_VALUE_CHANGED
:
2637 case WP_VALUE_NOT_CHANGED
:
2639 bs
->print_it
= print_it_noop
;
2646 /* Error from catch_errors. */
2647 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2648 if (b
->related_breakpoint
)
2649 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2650 b
->disposition
= disp_del_at_next_stop
;
2651 /* We've already printed what needs to be printed. */
2652 bs
->print_it
= print_it_done
;
2658 else if (b
->type
== bp_read_watchpoint
||
2659 b
->type
== bp_access_watchpoint
)
2665 addr
= target_stopped_data_address ();
2668 for (v
= b
->val_chain
; v
; v
= v
->next
)
2670 if (VALUE_LVAL (v
) == lval_memory
2671 && ! VALUE_LAZY (v
))
2673 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2675 if (v
== b
->val_chain
2676 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2677 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2681 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2682 /* Exact match not required. Within range is
2684 if (addr
>= vaddr
&&
2685 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2692 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2694 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2695 int e
= catch_errors (watchpoint_check
, bs
, message
,
2697 do_cleanups (cleanups
);
2701 /* We've already printed what needs to be printed. */
2702 bs
->print_it
= print_it_done
;
2705 case WP_VALUE_CHANGED
:
2706 if (b
->type
== bp_read_watchpoint
)
2708 /* Don't stop: read watchpoints shouldn't fire if
2709 the value has changed. This is for targets
2710 which cannot set read-only watchpoints. */
2711 bs
->print_it
= print_it_noop
;
2717 case WP_VALUE_NOT_CHANGED
:
2724 /* Error from catch_errors. */
2725 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2726 if (b
->related_breakpoint
)
2727 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2728 b
->disposition
= disp_del_at_next_stop
;
2729 /* We've already printed what needs to be printed. */
2730 bs
->print_it
= print_it_done
;
2734 else /* found == 0 */
2736 /* This is a case where some watchpoint(s) triggered,
2737 but not at the address of this watchpoint (FOUND
2738 was left zero). So don't print anything for this
2740 bs
->print_it
= print_it_noop
;
2747 /* By definition, an encountered breakpoint is a triggered
2751 real_breakpoint
= 1;
2754 if (frame_id_p (b
->frame_id
)
2755 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2759 int value_is_zero
= 0;
2763 /* Need to select the frame, with all that implies
2764 so that the conditions will have the right context. */
2765 select_frame (get_current_frame ());
2767 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2768 "Error in testing breakpoint condition:\n",
2770 /* FIXME-someday, should give breakpoint # */
2773 if (b
->cond
&& value_is_zero
)
2776 /* Don't consider this a hit. */
2779 else if (b
->ignore_count
> 0)
2782 annotate_ignore_count_change ();
2787 /* We will stop here */
2788 if (b
->disposition
== disp_disable
)
2789 b
->enable_state
= bp_disabled
;
2792 bs
->commands
= b
->commands
;
2794 (STREQ ("silent", bs
->commands
->line
) ||
2795 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2797 bs
->commands
= bs
->commands
->next
;
2800 bs
->commands
= copy_command_lines (bs
->commands
);
2803 /* Print nothing for this entry if we dont stop or if we dont print. */
2804 if (bs
->stop
== 0 || bs
->print
== 0)
2805 bs
->print_it
= print_it_noop
;
2808 bs
->next
= NULL
; /* Terminate the chain */
2809 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2811 if (real_breakpoint
&& bs
)
2813 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2815 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2817 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2823 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2826 #if defined (SHIFT_INST_REGS)
2828 #else /* No SHIFT_INST_REGS. */
2830 #endif /* No SHIFT_INST_REGS. */
2835 /* The value of a hardware watchpoint hasn't changed, but the
2836 intermediate memory locations we are watching may have. */
2837 if (bs
&& !bs
->stop
&&
2838 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2839 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2840 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2842 remove_breakpoints ();
2843 insert_breakpoints ();
2848 /* Tell what to do about this bpstat. */
2850 bpstat_what (bpstat bs
)
2852 /* Classify each bpstat as one of the following. */
2855 /* This bpstat element has no effect on the main_action. */
2858 /* There was a watchpoint, stop but don't print. */
2861 /* There was a watchpoint, stop and print. */
2864 /* There was a breakpoint but we're not stopping. */
2867 /* There was a breakpoint, stop but don't print. */
2870 /* There was a breakpoint, stop and print. */
2873 /* We hit the longjmp breakpoint. */
2876 /* We hit the longjmp_resume breakpoint. */
2879 /* We hit the step_resume breakpoint. */
2882 /* We hit the through_sigtramp breakpoint. */
2885 /* We hit the shared library event breakpoint. */
2888 /* We caught a shared library event. */
2891 /* This is just used to count how many enums there are. */
2895 /* Here is the table which drives this routine. So that we can
2896 format it pretty, we define some abbreviations for the
2897 enum bpstat_what codes. */
2898 #define kc BPSTAT_WHAT_KEEP_CHECKING
2899 #define ss BPSTAT_WHAT_STOP_SILENT
2900 #define sn BPSTAT_WHAT_STOP_NOISY
2901 #define sgl BPSTAT_WHAT_SINGLE
2902 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2903 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2904 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2905 #define sr BPSTAT_WHAT_STEP_RESUME
2906 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2907 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2908 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2910 /* "Can't happen." Might want to print an error message.
2911 abort() is not out of the question, but chances are GDB is just
2912 a bit confused, not unusable. */
2913 #define err BPSTAT_WHAT_STOP_NOISY
2915 /* Given an old action and a class, come up with a new action. */
2916 /* One interesting property of this table is that wp_silent is the same
2917 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2918 after stopping, the check for whether to step over a breakpoint
2919 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2920 reference to how we stopped. We retain separate wp_silent and
2921 bp_silent codes in case we want to change that someday.
2923 Another possibly interesting property of this table is that
2924 there's a partial ordering, priority-like, of the actions. Once
2925 you've decided that some action is appropriate, you'll never go
2926 back and decide something of a lower priority is better. The
2929 kc < clr sgl shl shlr slr sn sr ss ts
2930 sgl < clrs shl shlr slr sn sr ss ts
2931 slr < err shl shlr sn sr ss ts
2932 clr < clrs err shl shlr sn sr ss ts
2933 clrs < err shl shlr sn sr ss ts
2934 ss < shl shlr sn sr ts
2941 What I think this means is that we don't need a damned table
2942 here. If you just put the rows and columns in the right order,
2943 it'd look awfully regular. We could simply walk the bpstat list
2944 and choose the highest priority action we find, with a little
2945 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2946 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2947 is messy anyway). */
2949 /* step_resume entries: a step resume breakpoint overrides another
2950 breakpoint of signal handling (see comment in wait_for_inferior
2951 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2952 /* We handle the through_sigtramp_breakpoint the same way; having both
2953 one of those and a step_resume_breakpoint is probably very rare (?). */
2955 static const enum bpstat_what_main_action
2956 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2959 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2962 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2964 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2966 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2968 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2970 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2972 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2974 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2976 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2978 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2980 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2982 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2984 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2999 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3000 struct bpstat_what retval
;
3002 retval
.call_dummy
= 0;
3003 for (; bs
!= NULL
; bs
= bs
->next
)
3005 enum class bs_class
= no_effect
;
3006 if (bs
->breakpoint_at
== NULL
)
3007 /* I suspect this can happen if it was a momentary breakpoint
3008 which has since been deleted. */
3010 switch (bs
->breakpoint_at
->type
)
3016 case bp_hardware_breakpoint
:
3022 bs_class
= bp_noisy
;
3024 bs_class
= bp_silent
;
3027 bs_class
= bp_nostop
;
3030 case bp_hardware_watchpoint
:
3031 case bp_read_watchpoint
:
3032 case bp_access_watchpoint
:
3036 bs_class
= wp_noisy
;
3038 bs_class
= wp_silent
;
3041 /* There was a watchpoint, but we're not stopping.
3042 This requires no further action. */
3043 bs_class
= no_effect
;
3046 bs_class
= long_jump
;
3048 case bp_longjmp_resume
:
3049 bs_class
= long_resume
;
3051 case bp_step_resume
:
3054 bs_class
= step_resume
;
3057 /* It is for the wrong frame. */
3058 bs_class
= bp_nostop
;
3060 case bp_through_sigtramp
:
3061 bs_class
= through_sig
;
3063 case bp_watchpoint_scope
:
3064 bs_class
= bp_nostop
;
3066 case bp_shlib_event
:
3067 bs_class
= shlib_event
;
3069 case bp_thread_event
:
3070 case bp_overlay_event
:
3071 bs_class
= bp_nostop
;
3074 case bp_catch_unload
:
3075 /* Only if this catchpoint triggered should we cause the
3076 step-out-of-dld behaviour. Otherwise, we ignore this
3079 bs_class
= catch_shlib_event
;
3081 bs_class
= no_effect
;
3084 case bp_catch_vfork
:
3089 bs_class
= bp_noisy
;
3091 bs_class
= bp_silent
;
3094 /* There was a catchpoint, but we're not stopping.
3095 This requires no further action. */
3096 bs_class
= no_effect
;
3098 case bp_catch_catch
:
3099 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3100 bs_class
= bp_nostop
;
3102 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3104 case bp_catch_throw
:
3105 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3106 bs_class
= bp_nostop
;
3108 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3111 /* Make sure the action is stop (silent or noisy),
3112 so infrun.c pops the dummy frame. */
3113 bs_class
= bp_silent
;
3114 retval
.call_dummy
= 1;
3117 current_action
= table
[(int) bs_class
][(int) current_action
];
3119 retval
.main_action
= current_action
;
3123 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3124 without hardware support). This isn't related to a specific bpstat,
3125 just to things like whether watchpoints are set. */
3128 bpstat_should_step (void)
3130 struct breakpoint
*b
;
3132 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3137 /* Nonzero if there are enabled hardware watchpoints. */
3139 bpstat_have_active_hw_watchpoints (void)
3141 struct breakpoint
*b
;
3143 if ((b
->enable_state
== bp_enabled
) &&
3145 ((b
->type
== bp_hardware_watchpoint
) ||
3146 (b
->type
== bp_read_watchpoint
) ||
3147 (b
->type
== bp_access_watchpoint
)))
3153 /* Given a bpstat that records zero or more triggered eventpoints, this
3154 function returns another bpstat which contains only the catchpoints
3155 on that first list, if any. */
3157 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3159 struct bpstats root_bs
[1];
3160 bpstat bs
= root_bs
;
3161 struct breakpoint
*ep
;
3164 bpstat_clear (cp_list
);
3165 root_bs
->next
= NULL
;
3167 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3169 /* Is this eventpoint a catchpoint? If not, ignore it. */
3170 ep
= ep_list
->breakpoint_at
;
3173 if ((ep
->type
!= bp_catch_load
) &&
3174 (ep
->type
!= bp_catch_unload
) &&
3175 (ep
->type
!= bp_catch_catch
) &&
3176 (ep
->type
!= bp_catch_throw
))
3177 /* pai: (temp) ADD fork/vfork here!! */
3180 /* Yes; add it to the list. */
3181 bs
= bpstat_alloc (ep
, bs
);
3186 #if defined(SOLIB_ADD)
3187 /* Also, for each triggered catchpoint, tag it with the name of
3188 the library that caused this trigger. (We copy the name now,
3189 because it's only guaranteed to be available NOW, when the
3190 catchpoint triggers. Clients who may wish to know the name
3191 later must get it from the catchpoint itself.) */
3192 if (ep
->triggered_dll_pathname
!= NULL
)
3193 xfree (ep
->triggered_dll_pathname
);
3194 if (ep
->type
== bp_catch_load
)
3195 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3196 PIDGET (inferior_ptid
));
3198 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3199 PIDGET (inferior_ptid
));
3201 dll_pathname
= NULL
;
3205 ep
->triggered_dll_pathname
= (char *)
3206 xmalloc (strlen (dll_pathname
) + 1);
3207 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3210 ep
->triggered_dll_pathname
= NULL
;
3216 /* Print B to gdb_stdout. */
3218 print_one_breakpoint (struct breakpoint
*b
,
3219 CORE_ADDR
*last_addr
)
3221 struct command_line
*l
;
3223 struct ep_type_description
3228 static struct ep_type_description bptypes
[] =
3230 {bp_none
, "?deleted?"},
3231 {bp_breakpoint
, "breakpoint"},
3232 {bp_hardware_breakpoint
, "hw breakpoint"},
3233 {bp_until
, "until"},
3234 {bp_finish
, "finish"},
3235 {bp_watchpoint
, "watchpoint"},
3236 {bp_hardware_watchpoint
, "hw watchpoint"},
3237 {bp_read_watchpoint
, "read watchpoint"},
3238 {bp_access_watchpoint
, "acc watchpoint"},
3239 {bp_longjmp
, "longjmp"},
3240 {bp_longjmp_resume
, "longjmp resume"},
3241 {bp_step_resume
, "step resume"},
3242 {bp_through_sigtramp
, "sigtramp"},
3243 {bp_watchpoint_scope
, "watchpoint scope"},
3244 {bp_call_dummy
, "call dummy"},
3245 {bp_shlib_event
, "shlib events"},
3246 {bp_thread_event
, "thread events"},
3247 {bp_overlay_event
, "overlay events"},
3248 {bp_catch_load
, "catch load"},
3249 {bp_catch_unload
, "catch unload"},
3250 {bp_catch_fork
, "catch fork"},
3251 {bp_catch_vfork
, "catch vfork"},
3252 {bp_catch_exec
, "catch exec"},
3253 {bp_catch_catch
, "catch catch"},
3254 {bp_catch_throw
, "catch throw"}
3257 static char *bpdisps
[] =
3258 {"del", "dstp", "dis", "keep"};
3259 static char bpenables
[] = "nynny";
3260 char wrap_indent
[80];
3261 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3262 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3263 struct cleanup
*bkpt_chain
;
3266 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3270 ui_out_field_int (uiout
, "number", b
->number
);
3274 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3275 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3276 internal_error (__FILE__
, __LINE__
,
3277 "bptypes table does not describe type #%d.",
3279 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3283 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3287 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3288 ui_out_spaces (uiout
, 2);
3291 strcpy (wrap_indent
, " ");
3294 if (TARGET_ADDR_BIT
<= 32)
3295 strcat (wrap_indent
, " ");
3297 strcat (wrap_indent
, " ");
3300 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3301 b
->ops
->print_one (b
, last_addr
);
3306 internal_error (__FILE__
, __LINE__
,
3307 "print_one_breakpoint: bp_none encountered\n");
3311 case bp_hardware_watchpoint
:
3312 case bp_read_watchpoint
:
3313 case bp_access_watchpoint
:
3314 /* Field 4, the address, is omitted (which makes the columns
3315 not line up too nicely with the headers, but the effect
3316 is relatively readable). */
3318 ui_out_field_skip (uiout
, "addr");
3320 print_expression (b
->exp
, stb
->stream
);
3321 ui_out_field_stream (uiout
, "what", stb
);
3325 case bp_catch_unload
:
3326 /* Field 4, the address, is omitted (which makes the columns
3327 not line up too nicely with the headers, but the effect
3328 is relatively readable). */
3330 ui_out_field_skip (uiout
, "addr");
3332 if (b
->dll_pathname
== NULL
)
3334 ui_out_field_string (uiout
, "what", "<any library>");
3335 ui_out_spaces (uiout
, 1);
3339 ui_out_text (uiout
, "library \"");
3340 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3341 ui_out_text (uiout
, "\" ");
3346 case bp_catch_vfork
:
3347 /* Field 4, the address, is omitted (which makes the columns
3348 not line up too nicely with the headers, but the effect
3349 is relatively readable). */
3351 ui_out_field_skip (uiout
, "addr");
3353 if (b
->forked_inferior_pid
!= 0)
3355 ui_out_text (uiout
, "process ");
3356 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3357 ui_out_spaces (uiout
, 1);
3361 /* Field 4, the address, is omitted (which makes the columns
3362 not line up too nicely with the headers, but the effect
3363 is relatively readable). */
3365 ui_out_field_skip (uiout
, "addr");
3367 if (b
->exec_pathname
!= NULL
)
3369 ui_out_text (uiout
, "program \"");
3370 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3371 ui_out_text (uiout
, "\" ");
3375 case bp_catch_catch
:
3376 /* Field 4, the address, is omitted (which makes the columns
3377 not line up too nicely with the headers, but the effect
3378 is relatively readable). */
3380 ui_out_field_skip (uiout
, "addr");
3382 ui_out_field_string (uiout
, "what", "exception catch");
3383 ui_out_spaces (uiout
, 1);
3386 case bp_catch_throw
:
3387 /* Field 4, the address, is omitted (which makes the columns
3388 not line up too nicely with the headers, but the effect
3389 is relatively readable). */
3391 ui_out_field_skip (uiout
, "addr");
3393 ui_out_field_string (uiout
, "what", "exception throw");
3394 ui_out_spaces (uiout
, 1);
3398 case bp_hardware_breakpoint
:
3402 case bp_longjmp_resume
:
3403 case bp_step_resume
:
3404 case bp_through_sigtramp
:
3405 case bp_watchpoint_scope
:
3407 case bp_shlib_event
:
3408 case bp_thread_event
:
3409 case bp_overlay_event
:
3413 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3416 *last_addr
= b
->address
;
3419 sym
= find_pc_sect_function (b
->address
, b
->section
);
3422 ui_out_text (uiout
, "in ");
3423 ui_out_field_string (uiout
, "func",
3424 SYMBOL_PRINT_NAME (sym
));
3425 ui_out_wrap_hint (uiout
, wrap_indent
);
3426 ui_out_text (uiout
, " at ");
3428 ui_out_field_string (uiout
, "file", b
->source_file
);
3429 ui_out_text (uiout
, ":");
3430 ui_out_field_int (uiout
, "line", b
->line_number
);
3434 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3435 ui_out_field_stream (uiout
, "at", stb
);
3440 if (b
->thread
!= -1)
3442 /* FIXME: This seems to be redundant and lost here; see the
3443 "stop only in" line a little further down. */
3444 ui_out_text (uiout
, " thread ");
3445 ui_out_field_int (uiout
, "thread", b
->thread
);
3448 ui_out_text (uiout
, "\n");
3450 if (frame_id_p (b
->frame_id
))
3453 ui_out_text (uiout
, "\tstop only in stack frame at ");
3454 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3456 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3457 ui_out_text (uiout
, "\n");
3463 ui_out_text (uiout
, "\tstop only if ");
3464 print_expression (b
->cond
, stb
->stream
);
3465 ui_out_field_stream (uiout
, "cond", stb
);
3466 ui_out_text (uiout
, "\n");
3469 if (b
->thread
!= -1)
3471 /* FIXME should make an annotation for this */
3472 ui_out_text (uiout
, "\tstop only in thread ");
3473 ui_out_field_int (uiout
, "thread", b
->thread
);
3474 ui_out_text (uiout
, "\n");
3477 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3479 /* FIXME should make an annotation for this */
3480 if (ep_is_catchpoint (b
))
3481 ui_out_text (uiout
, "\tcatchpoint");
3483 ui_out_text (uiout
, "\tbreakpoint");
3484 ui_out_text (uiout
, " already hit ");
3485 ui_out_field_int (uiout
, "times", b
->hit_count
);
3486 if (b
->hit_count
== 1)
3487 ui_out_text (uiout
, " time\n");
3489 ui_out_text (uiout
, " times\n");
3492 /* Output the count also if it is zero, but only if this is
3493 mi. FIXME: Should have a better test for this. */
3494 if (ui_out_is_mi_like_p (uiout
))
3495 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3496 ui_out_field_int (uiout
, "times", b
->hit_count
);
3498 if (b
->ignore_count
)
3501 ui_out_text (uiout
, "\tignore next ");
3502 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3503 ui_out_text (uiout
, " hits\n");
3506 if ((l
= b
->commands
))
3508 struct cleanup
*script_chain
;
3511 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3512 print_command_lines (uiout
, l
, 4);
3513 do_cleanups (script_chain
);
3515 do_cleanups (bkpt_chain
);
3516 do_cleanups (old_chain
);
3519 struct captured_breakpoint_query_args
3525 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3527 struct captured_breakpoint_query_args
*args
= data
;
3528 struct breakpoint
*b
;
3529 CORE_ADDR dummy_addr
= 0;
3532 if (args
->bnum
== b
->number
)
3534 print_one_breakpoint (b
, &dummy_addr
);
3542 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3544 struct captured_breakpoint_query_args args
;
3546 /* For the moment we don't trust print_one_breakpoint() to not throw
3548 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3549 NULL
, RETURN_MASK_ALL
);
3552 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3553 catchpoints, et.al.). */
3556 user_settable_breakpoint (const struct breakpoint
*b
)
3558 return (b
->type
== bp_breakpoint
3559 || b
->type
== bp_catch_load
3560 || b
->type
== bp_catch_unload
3561 || b
->type
== bp_catch_fork
3562 || b
->type
== bp_catch_vfork
3563 || b
->type
== bp_catch_exec
3564 || b
->type
== bp_catch_catch
3565 || b
->type
== bp_catch_throw
3566 || b
->type
== bp_hardware_breakpoint
3567 || b
->type
== bp_watchpoint
3568 || b
->type
== bp_read_watchpoint
3569 || b
->type
== bp_access_watchpoint
3570 || b
->type
== bp_hardware_watchpoint
);
3573 /* Print information on user settable breakpoint (watchpoint, etc)
3574 number BNUM. If BNUM is -1 print all user settable breakpoints.
3575 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3578 breakpoint_1 (int bnum
, int allflag
)
3580 struct breakpoint
*b
;
3581 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3582 int nr_printable_breakpoints
;
3583 struct cleanup
*bkpttbl_chain
;
3585 /* Compute the number of rows in the table. */
3586 nr_printable_breakpoints
= 0;
3589 || bnum
== b
->number
)
3591 if (allflag
|| user_settable_breakpoint (b
))
3592 nr_printable_breakpoints
++;
3597 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3601 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3604 if (nr_printable_breakpoints
> 0)
3605 annotate_breakpoints_headers ();
3606 if (nr_printable_breakpoints
> 0)
3608 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3609 if (nr_printable_breakpoints
> 0)
3611 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3612 if (nr_printable_breakpoints
> 0)
3614 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3615 if (nr_printable_breakpoints
> 0)
3617 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3620 if (nr_printable_breakpoints
> 0)
3622 if (TARGET_ADDR_BIT
<= 32)
3623 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3625 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3627 if (nr_printable_breakpoints
> 0)
3629 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3630 ui_out_table_body (uiout
);
3631 if (nr_printable_breakpoints
> 0)
3632 annotate_breakpoints_table ();
3636 || bnum
== b
->number
)
3638 /* We only print out user settable breakpoints unless the
3640 if (allflag
|| user_settable_breakpoint (b
))
3641 print_one_breakpoint (b
, &last_addr
);
3644 do_cleanups (bkpttbl_chain
);
3646 if (nr_printable_breakpoints
== 0)
3649 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3651 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3656 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3657 that a comparison of an unsigned with -1 is always false. */
3658 if (last_addr
!= (CORE_ADDR
) -1)
3659 set_next_address (last_addr
);
3662 /* FIXME? Should this be moved up so that it is only called when
3663 there have been breakpoints? */
3664 annotate_breakpoints_table_end ();
3668 breakpoints_info (char *bnum_exp
, int from_tty
)
3673 bnum
= parse_and_eval_long (bnum_exp
);
3675 breakpoint_1 (bnum
, 0);
3679 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3684 bnum
= parse_and_eval_long (bnum_exp
);
3686 breakpoint_1 (bnum
, 1);
3689 /* Print a message describing any breakpoints set at PC. */
3692 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3695 struct breakpoint
*b
;
3698 if (b
->address
== pc
) /* address match / overlay match */
3699 if (!overlay_debugging
|| b
->section
== section
)
3703 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3705 if (b
->address
== pc
) /* address match / overlay match */
3706 if (!overlay_debugging
|| b
->section
== section
)
3709 printf_filtered ("%d%s%s ",
3711 ((b
->enable_state
== bp_disabled
||
3712 b
->enable_state
== bp_shlib_disabled
||
3713 b
->enable_state
== bp_call_disabled
)
3715 : b
->enable_state
== bp_permanent
3719 : ((others
== 1) ? " and" : ""));
3721 printf_filtered ("also set at pc ");
3722 print_address_numeric (pc
, 1, gdb_stdout
);
3723 printf_filtered (".\n");
3727 /* Set the default place to put a breakpoint
3728 for the `break' command with no arguments. */
3731 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3734 default_breakpoint_valid
= valid
;
3735 default_breakpoint_address
= addr
;
3736 default_breakpoint_symtab
= symtab
;
3737 default_breakpoint_line
= line
;
3740 /* Return true iff it is meaningful to use the address member of
3741 BPT. For some breakpoint types, the address member is irrelevant
3742 and it makes no sense to attempt to compare it to other addresses
3743 (or use it for any other purpose either).
3745 More specifically, each of the following breakpoint types will always
3746 have a zero valued address and we don't want check_duplicates() to mark
3747 breakpoints of any of these types to be a duplicate of an actual
3748 breakpoint at address zero:
3751 bp_hardware_watchpoint
3753 bp_access_watchpoint
3760 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3762 enum bptype type
= bpt
->type
;
3764 return (type
!= bp_watchpoint
3765 && type
!= bp_hardware_watchpoint
3766 && type
!= bp_read_watchpoint
3767 && type
!= bp_access_watchpoint
3768 && type
!= bp_catch_exec
3769 && type
!= bp_longjmp_resume
3770 && type
!= bp_catch_fork
3771 && type
!= bp_catch_vfork
);
3774 /* Rescan breakpoints at the same address and section as BPT,
3775 marking the first one as "first" and any others as "duplicates".
3776 This is so that the bpt instruction is only inserted once.
3777 If we have a permanent breakpoint at the same place as BPT, make
3778 that one the official one, and the rest as duplicates. */
3781 check_duplicates (struct breakpoint
*bpt
)
3783 struct breakpoint
*b
;
3785 struct breakpoint
*perm_bp
= 0;
3786 CORE_ADDR address
= bpt
->address
;
3787 asection
*section
= bpt
->section
;
3789 if (! breakpoint_address_is_meaningful (bpt
))
3793 if (b
->enable_state
!= bp_disabled
3794 && b
->enable_state
!= bp_shlib_disabled
3795 && b
->enable_state
!= bp_call_disabled
3796 && b
->address
== address
/* address / overlay match */
3797 && (!overlay_debugging
|| b
->section
== section
)
3798 && breakpoint_address_is_meaningful (b
))
3800 /* Have we found a permanent breakpoint? */
3801 if (b
->enable_state
== bp_permanent
)
3808 b
->duplicate
= count
> 1;
3811 /* If we found a permanent breakpoint at this address, go over the
3812 list again and declare all the other breakpoints there to be the
3816 perm_bp
->duplicate
= 0;
3818 /* Permanent breakpoint should always be inserted. */
3819 if (! perm_bp
->inserted
)
3820 internal_error (__FILE__
, __LINE__
,
3821 "allegedly permanent breakpoint is not "
3822 "actually inserted");
3828 internal_error (__FILE__
, __LINE__
,
3829 "another breakpoint was inserted on top of "
3830 "a permanent breakpoint");
3832 if (b
->enable_state
!= bp_disabled
3833 && b
->enable_state
!= bp_shlib_disabled
3834 && b
->enable_state
!= bp_call_disabled
3835 && b
->address
== address
/* address / overlay match */
3836 && (!overlay_debugging
|| b
->section
== section
)
3837 && breakpoint_address_is_meaningful (b
))
3843 /* set_raw_breakpoint() is a low level routine for allocating and
3844 partially initializing a breakpoint of type BPTYPE. The newly
3845 created breakpoint's address, section, source file name, and line
3846 number are provided by SAL. The newly created and partially
3847 initialized breakpoint is added to the breakpoint chain and
3848 is also returned as the value of this function.
3850 It is expected that the caller will complete the initialization of
3851 the newly created breakpoint struct as well as output any status
3852 information regarding the creation of a new breakpoint. In
3853 particular, set_raw_breakpoint() does NOT set the breakpoint
3854 number! Care should be taken to not allow an error() to occur
3855 prior to completing the initialization of the breakpoint. If this
3856 should happen, a bogus breakpoint will be left on the chain. */
3859 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3861 struct breakpoint
*b
, *b1
;
3863 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3864 memset (b
, 0, sizeof (*b
));
3865 b
->address
= sal
.pc
;
3866 if (sal
.symtab
== NULL
)
3867 b
->source_file
= NULL
;
3869 b
->source_file
= savestring (sal
.symtab
->filename
,
3870 strlen (sal
.symtab
->filename
));
3871 b
->section
= sal
.section
;
3873 b
->language
= current_language
->la_language
;
3874 b
->input_radix
= input_radix
;
3876 b
->line_number
= sal
.line
;
3877 b
->enable_state
= bp_enabled
;
3880 b
->ignore_count
= 0;
3882 b
->frame_id
= null_frame_id
;
3883 b
->dll_pathname
= NULL
;
3884 b
->triggered_dll_pathname
= NULL
;
3885 b
->forked_inferior_pid
= 0;
3886 b
->exec_pathname
= NULL
;
3889 /* Add this breakpoint to the end of the chain
3890 so that a list of breakpoints will come out in order
3891 of increasing numbers. */
3893 b1
= breakpoint_chain
;
3895 breakpoint_chain
= b
;
3903 check_duplicates (b
);
3904 breakpoints_changed ();
3910 /* Note that the breakpoint object B describes a permanent breakpoint
3911 instruction, hard-wired into the inferior's code. */
3913 make_breakpoint_permanent (struct breakpoint
*b
)
3915 b
->enable_state
= bp_permanent
;
3917 /* By definition, permanent breakpoints are already present in the code. */
3921 static struct breakpoint
*
3922 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3924 static int internal_breakpoint_number
= -1;
3925 struct symtab_and_line sal
;
3926 struct breakpoint
*b
;
3928 init_sal (&sal
); /* initialize to zeroes */
3931 sal
.section
= find_pc_overlay (sal
.pc
);
3933 b
= set_raw_breakpoint (sal
, type
);
3934 b
->number
= internal_breakpoint_number
--;
3935 b
->disposition
= disp_donttouch
;
3942 create_longjmp_breakpoint (char *func_name
)
3944 struct breakpoint
*b
;
3945 struct minimal_symbol
*m
;
3947 if (func_name
== NULL
)
3948 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3951 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3954 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3957 b
->enable_state
= bp_disabled
;
3960 b
->addr_string
= xstrdup (func_name
);
3963 /* Call this routine when stepping and nexting to enable a breakpoint
3964 if we do a longjmp(). When we hit that breakpoint, call
3965 set_longjmp_resume_breakpoint() to figure out where we are going. */
3968 enable_longjmp_breakpoint (void)
3970 struct breakpoint
*b
;
3973 if (b
->type
== bp_longjmp
)
3975 b
->enable_state
= bp_enabled
;
3976 check_duplicates (b
);
3981 disable_longjmp_breakpoint (void)
3983 struct breakpoint
*b
;
3986 if (b
->type
== bp_longjmp
3987 || b
->type
== bp_longjmp_resume
)
3989 b
->enable_state
= bp_disabled
;
3990 check_duplicates (b
);
3995 create_overlay_event_breakpoint (char *func_name
)
3997 struct breakpoint
*b
;
3998 struct minimal_symbol
*m
;
4000 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
4003 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4005 b
->addr_string
= xstrdup (func_name
);
4007 if (overlay_debugging
== ovly_auto
)
4009 b
->enable_state
= bp_enabled
;
4010 overlay_events_enabled
= 1;
4014 b
->enable_state
= bp_disabled
;
4015 overlay_events_enabled
= 0;
4020 enable_overlay_breakpoints (void)
4022 struct breakpoint
*b
;
4025 if (b
->type
== bp_overlay_event
)
4027 b
->enable_state
= bp_enabled
;
4028 check_duplicates (b
);
4029 overlay_events_enabled
= 1;
4034 disable_overlay_breakpoints (void)
4036 struct breakpoint
*b
;
4039 if (b
->type
== bp_overlay_event
)
4041 b
->enable_state
= bp_disabled
;
4042 check_duplicates (b
);
4043 overlay_events_enabled
= 0;
4048 create_thread_event_breakpoint (CORE_ADDR address
)
4050 struct breakpoint
*b
;
4052 b
= create_internal_breakpoint (address
, bp_thread_event
);
4054 b
->enable_state
= bp_enabled
;
4055 /* addr_string has to be used or breakpoint_re_set will delete me. */
4056 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->address
));
4062 remove_thread_event_breakpoints (void)
4064 struct breakpoint
*b
, *temp
;
4066 ALL_BREAKPOINTS_SAFE (b
, temp
)
4067 if (b
->type
== bp_thread_event
)
4068 delete_breakpoint (b
);
4073 remove_solib_event_breakpoints (void)
4075 struct breakpoint
*b
, *temp
;
4077 ALL_BREAKPOINTS_SAFE (b
, temp
)
4078 if (b
->type
== bp_shlib_event
)
4079 delete_breakpoint (b
);
4083 create_solib_event_breakpoint (CORE_ADDR address
)
4085 struct breakpoint
*b
;
4087 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4091 /* Disable any breakpoints that are on code in shared libraries. Only
4092 apply to enabled breakpoints, disabled ones can just stay disabled. */
4095 disable_breakpoints_in_shlibs (int silent
)
4097 struct breakpoint
*b
;
4098 int disabled_shlib_breaks
= 0;
4100 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4103 #if defined (PC_SOLIB)
4104 if (((b
->type
== bp_breakpoint
) ||
4105 (b
->type
== bp_hardware_breakpoint
)) &&
4106 b
->enable_state
== bp_enabled
&&
4108 PC_SOLIB (b
->address
))
4110 b
->enable_state
= bp_shlib_disabled
;
4113 if (!disabled_shlib_breaks
)
4115 target_terminal_ours_for_output ();
4116 warning ("Temporarily disabling shared library breakpoints:");
4118 disabled_shlib_breaks
= 1;
4119 warning ("breakpoint #%d ", b
->number
);
4126 /* Try to reenable any breakpoints in shared libraries. */
4128 re_enable_breakpoints_in_shlibs (void)
4130 struct breakpoint
*b
;
4133 if (b
->enable_state
== bp_shlib_disabled
)
4137 /* Do not reenable the breakpoint if the shared library
4138 is still not mapped in. */
4139 if (target_read_memory (b
->address
, buf
, 1) == 0)
4140 b
->enable_state
= bp_enabled
;
4147 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4148 char *cond_string
, enum bptype bp_kind
)
4150 struct breakpoint
*b
;
4151 struct symtabs_and_lines sals
;
4152 struct cleanup
*old_chain
;
4153 struct cleanup
*canonical_strings_chain
= NULL
;
4154 char *addr_start
= hookname
;
4155 char *addr_end
= NULL
;
4156 char **canonical
= (char **) NULL
;
4157 int thread
= -1; /* All threads. */
4159 /* Set a breakpoint on the specified hook. */
4160 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4161 addr_end
= hookname
;
4163 if (sals
.nelts
== 0)
4165 warning ("Unable to set a breakpoint on dynamic linker callback.");
4166 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4167 warning ("GDB will be unable to track shl_load/shl_unload calls");
4170 if (sals
.nelts
!= 1)
4172 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4173 warning ("GDB will be unable to track shl_load/shl_unload calls");
4177 /* Make sure that all storage allocated in decode_line_1 gets freed
4178 in case the following errors out. */
4179 old_chain
= make_cleanup (xfree
, sals
.sals
);
4180 if (canonical
!= (char **) NULL
)
4182 make_cleanup (xfree
, canonical
);
4183 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4184 if (canonical
[0] != NULL
)
4185 make_cleanup (xfree
, canonical
[0]);
4188 resolve_sal_pc (&sals
.sals
[0]);
4190 /* Remove the canonical strings from the cleanup, they are needed below. */
4191 if (canonical
!= (char **) NULL
)
4192 discard_cleanups (canonical_strings_chain
);
4194 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4195 set_breakpoint_count (breakpoint_count
+ 1);
4196 b
->number
= breakpoint_count
;
4198 b
->cond_string
= (cond_string
== NULL
) ?
4199 NULL
: savestring (cond_string
, strlen (cond_string
));
4202 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4203 b
->addr_string
= canonical
[0];
4204 else if (addr_start
)
4205 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4207 b
->enable_state
= bp_enabled
;
4208 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4210 if (dll_pathname
== NULL
)
4211 b
->dll_pathname
= NULL
;
4214 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4215 strcpy (b
->dll_pathname
, dll_pathname
);
4219 do_cleanups (old_chain
);
4223 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4224 char *dll_pathname
, char *cond_string
)
4226 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4227 cond_string
, bp_catch_load
);
4231 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4232 char *dll_pathname
, char *cond_string
)
4234 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4235 cond_string
, bp_catch_unload
);
4239 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4240 enum bptype bp_kind
)
4242 struct symtab_and_line sal
;
4243 struct breakpoint
*b
;
4244 int thread
= -1; /* All threads. */
4251 b
= set_raw_breakpoint (sal
, bp_kind
);
4252 set_breakpoint_count (breakpoint_count
+ 1);
4253 b
->number
= breakpoint_count
;
4255 b
->cond_string
= (cond_string
== NULL
) ?
4256 NULL
: savestring (cond_string
, strlen (cond_string
));
4258 b
->addr_string
= NULL
;
4259 b
->enable_state
= bp_enabled
;
4260 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4261 b
->forked_inferior_pid
= 0;
4267 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4269 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4273 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4275 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4279 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4281 struct symtab_and_line sal
;
4282 struct breakpoint
*b
;
4283 int thread
= -1; /* All threads. */
4290 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4291 set_breakpoint_count (breakpoint_count
+ 1);
4292 b
->number
= breakpoint_count
;
4294 b
->cond_string
= (cond_string
== NULL
) ?
4295 NULL
: savestring (cond_string
, strlen (cond_string
));
4297 b
->addr_string
= NULL
;
4298 b
->enable_state
= bp_enabled
;
4299 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4305 hw_breakpoint_used_count (void)
4307 struct breakpoint
*b
;
4312 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4320 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4322 struct breakpoint
*b
;
4325 *other_type_used
= 0;
4328 if (b
->enable_state
== bp_enabled
)
4330 if (b
->type
== type
)
4332 else if ((b
->type
== bp_hardware_watchpoint
||
4333 b
->type
== bp_read_watchpoint
||
4334 b
->type
== bp_access_watchpoint
)
4335 && b
->enable_state
== bp_enabled
)
4336 *other_type_used
= 1;
4342 /* Call this after hitting the longjmp() breakpoint. Use this to set
4343 a new breakpoint at the target of the jmp_buf.
4345 FIXME - This ought to be done by setting a temporary breakpoint
4346 that gets deleted automatically... */
4349 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4351 struct breakpoint
*b
;
4354 if (b
->type
== bp_longjmp_resume
)
4357 b
->enable_state
= bp_enabled
;
4358 b
->frame_id
= frame_id
;
4359 check_duplicates (b
);
4365 disable_watchpoints_before_interactive_call_start (void)
4367 struct breakpoint
*b
;
4371 if (((b
->type
== bp_watchpoint
)
4372 || (b
->type
== bp_hardware_watchpoint
)
4373 || (b
->type
== bp_read_watchpoint
)
4374 || (b
->type
== bp_access_watchpoint
)
4375 || ep_is_exception_catchpoint (b
))
4376 && (b
->enable_state
== bp_enabled
))
4378 b
->enable_state
= bp_call_disabled
;
4379 check_duplicates (b
);
4385 enable_watchpoints_after_interactive_call_stop (void)
4387 struct breakpoint
*b
;
4391 if (((b
->type
== bp_watchpoint
)
4392 || (b
->type
== bp_hardware_watchpoint
)
4393 || (b
->type
== bp_read_watchpoint
)
4394 || (b
->type
== bp_access_watchpoint
)
4395 || ep_is_exception_catchpoint (b
))
4396 && (b
->enable_state
== bp_call_disabled
))
4398 b
->enable_state
= bp_enabled
;
4399 check_duplicates (b
);
4405 /* Set a breakpoint that will evaporate an end of command
4406 at address specified by SAL.
4407 Restrict it to frame FRAME if FRAME is nonzero. */
4410 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4413 struct breakpoint
*b
;
4414 b
= set_raw_breakpoint (sal
, type
);
4415 b
->enable_state
= bp_enabled
;
4416 b
->disposition
= disp_donttouch
;
4417 b
->frame_id
= frame_id
;
4419 /* If we're debugging a multi-threaded program, then we
4420 want momentary breakpoints to be active in only a
4421 single thread of control. */
4422 if (in_thread_list (inferior_ptid
))
4423 b
->thread
= pid_to_thread_id (inferior_ptid
);
4429 /* Tell the user we have just set a breakpoint B. */
4432 mention (struct breakpoint
*b
)
4435 struct cleanup
*old_chain
, *ui_out_chain
;
4436 struct ui_stream
*stb
;
4438 stb
= ui_out_stream_new (uiout
);
4439 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4441 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4442 watchpoint) other than breakpoint creation. It should be possible to
4443 clean this up and at the same time replace the random calls to
4444 breakpoint_changed with this hook, as has already been done for
4445 delete_breakpoint_hook and so on. */
4446 if (create_breakpoint_hook
)
4447 create_breakpoint_hook (b
);
4448 breakpoint_create_event (b
->number
);
4450 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4451 b
->ops
->print_mention (b
);
4456 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4459 ui_out_text (uiout
, "Watchpoint ");
4460 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4461 ui_out_field_int (uiout
, "number", b
->number
);
4462 ui_out_text (uiout
, ": ");
4463 print_expression (b
->exp
, stb
->stream
);
4464 ui_out_field_stream (uiout
, "exp", stb
);
4465 do_cleanups (ui_out_chain
);
4467 case bp_hardware_watchpoint
:
4468 ui_out_text (uiout
, "Hardware watchpoint ");
4469 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4470 ui_out_field_int (uiout
, "number", b
->number
);
4471 ui_out_text (uiout
, ": ");
4472 print_expression (b
->exp
, stb
->stream
);
4473 ui_out_field_stream (uiout
, "exp", stb
);
4474 do_cleanups (ui_out_chain
);
4476 case bp_read_watchpoint
:
4477 ui_out_text (uiout
, "Hardware read watchpoint ");
4478 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4479 ui_out_field_int (uiout
, "number", b
->number
);
4480 ui_out_text (uiout
, ": ");
4481 print_expression (b
->exp
, stb
->stream
);
4482 ui_out_field_stream (uiout
, "exp", stb
);
4483 do_cleanups (ui_out_chain
);
4485 case bp_access_watchpoint
:
4486 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4487 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4488 ui_out_field_int (uiout
, "number", b
->number
);
4489 ui_out_text (uiout
, ": ");
4490 print_expression (b
->exp
, stb
->stream
);
4491 ui_out_field_stream (uiout
, "exp", stb
);
4492 do_cleanups (ui_out_chain
);
4495 if (ui_out_is_mi_like_p (uiout
))
4500 printf_filtered ("Breakpoint %d", b
->number
);
4503 case bp_hardware_breakpoint
:
4504 if (ui_out_is_mi_like_p (uiout
))
4509 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4513 case bp_catch_unload
:
4514 printf_filtered ("Catchpoint %d (%s %s)",
4516 (b
->type
== bp_catch_load
) ? "load" : "unload",
4517 (b
->dll_pathname
!= NULL
) ?
4518 b
->dll_pathname
: "<any library>");
4521 case bp_catch_vfork
:
4522 printf_filtered ("Catchpoint %d (%s)",
4524 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4527 printf_filtered ("Catchpoint %d (exec)",
4530 case bp_catch_catch
:
4531 case bp_catch_throw
:
4532 printf_filtered ("Catchpoint %d (%s)",
4534 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4540 case bp_longjmp_resume
:
4541 case bp_step_resume
:
4542 case bp_through_sigtramp
:
4544 case bp_watchpoint_scope
:
4545 case bp_shlib_event
:
4546 case bp_thread_event
:
4547 case bp_overlay_event
:
4553 if (addressprint
|| b
->source_file
== NULL
)
4555 printf_filtered (" at ");
4556 print_address_numeric (b
->address
, 1, gdb_stdout
);
4559 printf_filtered (": file %s, line %d.",
4560 b
->source_file
, b
->line_number
);
4562 do_cleanups (old_chain
);
4563 if (ui_out_is_mi_like_p (uiout
))
4565 printf_filtered ("\n");
4569 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4570 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4571 COND[i] and COND_STRING[i] values.
4573 NOTE: If the function succeeds, the caller is expected to cleanup
4574 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4575 array contents). If the function fails (error() is called), the
4576 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4577 COND and SALS arrays and each of those arrays contents. */
4580 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4581 struct expression
**cond
, char **cond_string
,
4582 enum bptype type
, enum bpdisp disposition
,
4583 int thread
, int ignore_count
, int from_tty
)
4585 if (type
== bp_hardware_breakpoint
)
4587 int i
= hw_breakpoint_used_count ();
4588 int target_resources_ok
=
4589 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4591 if (target_resources_ok
== 0)
4592 error ("No hardware breakpoint support in the target.");
4593 else if (target_resources_ok
< 0)
4594 error ("Hardware breakpoints used exceeds limit.");
4597 /* Now set all the breakpoints. */
4600 for (i
= 0; i
< sals
.nelts
; i
++)
4602 struct breakpoint
*b
;
4603 struct symtab_and_line sal
= sals
.sals
[i
];
4606 describe_other_breakpoints (sal
.pc
, sal
.section
);
4608 b
= set_raw_breakpoint (sal
, type
);
4609 set_breakpoint_count (breakpoint_count
+ 1);
4610 b
->number
= breakpoint_count
;
4614 b
->addr_string
= addr_string
[i
];
4616 /* addr_string has to be used or breakpoint_re_set will delete
4618 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->address
));
4619 b
->cond_string
= cond_string
[i
];
4620 b
->ignore_count
= ignore_count
;
4621 b
->enable_state
= bp_enabled
;
4622 b
->disposition
= disposition
;
4628 /* Parse ARG which is assumed to be a SAL specification possibly
4629 followed by conditionals. On return, SALS contains an array of SAL
4630 addresses found. ADDR_STRING contains a vector of (canonical)
4631 address strings. ARG points to the end of the SAL. */
4634 parse_breakpoint_sals (char **address
,
4635 struct symtabs_and_lines
*sals
,
4636 char ***addr_string
)
4638 char *addr_start
= *address
;
4639 *addr_string
= NULL
;
4640 /* If no arg given, or if first arg is 'if ', use the default
4642 if ((*address
) == NULL
4643 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4645 if (default_breakpoint_valid
)
4647 struct symtab_and_line sal
;
4648 init_sal (&sal
); /* initialize to zeroes */
4649 sals
->sals
= (struct symtab_and_line
*)
4650 xmalloc (sizeof (struct symtab_and_line
));
4651 sal
.pc
= default_breakpoint_address
;
4652 sal
.line
= default_breakpoint_line
;
4653 sal
.symtab
= default_breakpoint_symtab
;
4654 sal
.section
= find_pc_overlay (sal
.pc
);
4655 sals
->sals
[0] = sal
;
4659 error ("No default breakpoint address now.");
4663 /* Force almost all breakpoints to be in terms of the
4664 current_source_symtab (which is decode_line_1's default). This
4665 should produce the results we want almost all of the time while
4666 leaving default_breakpoint_* alone.
4667 ObjC: However, don't match an Objective-C method name which
4668 may have a '+' or '-' succeeded by a '[' */
4670 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
4672 if (default_breakpoint_valid
4674 || ((strchr ("+-", (*address
)[0]) != NULL
)
4675 && ((*address
)[1] != '['))))
4676 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4677 default_breakpoint_line
, addr_string
);
4679 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4681 /* For any SAL that didn't have a canonical string, fill one in. */
4682 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4683 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4684 if (addr_start
!= (*address
))
4687 for (i
= 0; i
< sals
->nelts
; i
++)
4689 /* Add the string if not present. */
4690 if ((*addr_string
)[i
] == NULL
)
4691 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4697 /* Convert each SAL into a real PC. Verify that the PC can be
4698 inserted as a breakpoint. If it can't throw an error. */
4701 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4705 for (i
= 0; i
< sals
->nelts
; i
++)
4707 resolve_sal_pc (&sals
->sals
[i
]);
4709 /* It's possible for the PC to be nonzero, but still an illegal
4710 value on some targets.
4712 For example, on HP-UX if you start gdb, and before running the
4713 inferior you try to set a breakpoint on a shared library function
4714 "foo" where the inferior doesn't call "foo" directly but does
4715 pass its address to another function call, then we do find a
4716 minimal symbol for the "foo", but it's address is invalid.
4717 (Appears to be an index into a table that the loader sets up
4718 when the inferior is run.)
4720 Give the target a chance to bless sals.sals[i].pc before we
4721 try to make a breakpoint for it. */
4722 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4724 if (address
== NULL
)
4725 error ("Cannot break without a running program.");
4727 error ("Cannot break on %s without a running program.",
4733 /* Set a breakpoint according to ARG (function, linenum or *address)
4734 flag: first bit : 0 non-temporary, 1 temporary.
4735 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4738 break_command_1 (char *arg
, int flag
, int from_tty
)
4740 int tempflag
, hardwareflag
;
4741 struct symtabs_and_lines sals
;
4742 struct expression
**cond
= 0;
4743 /* Pointers in arg to the start, and one past the end, of the
4745 char **cond_string
= (char **) NULL
;
4746 char *addr_start
= arg
;
4748 struct cleanup
*old_chain
;
4749 struct cleanup
*breakpoint_chain
= NULL
;
4752 int ignore_count
= 0;
4754 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4755 tempflag
= flag
& BP_TEMPFLAG
;
4760 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4765 /* Create a chain of things that always need to be cleaned up. */
4766 old_chain
= make_cleanup (null_cleanup
, 0);
4768 /* Make sure that all storage allocated to SALS gets freed. */
4769 make_cleanup (xfree
, sals
.sals
);
4771 /* Cleanup the addr_string array but not its contents. */
4772 make_cleanup (xfree
, addr_string
);
4774 /* Allocate space for all the cond expressions. */
4775 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4776 make_cleanup (xfree
, cond
);
4778 /* Allocate space for all the cond strings. */
4779 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4780 make_cleanup (xfree
, cond_string
);
4782 /* ----------------------------- SNIP -----------------------------
4783 Anything added to the cleanup chain beyond this point is assumed
4784 to be part of a breakpoint. If the breakpoint create succeeds
4785 then the memory is not reclaimed. */
4786 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4788 /* Mark the contents of the addr_string for cleanup. These go on
4789 the breakpoint_chain and only occure if the breakpoint create
4791 for (i
= 0; i
< sals
.nelts
; i
++)
4793 if (addr_string
[i
] != NULL
)
4794 make_cleanup (xfree
, addr_string
[i
]);
4797 /* Resolve all line numbers to PC's and verify that the addresses
4798 are ok for the target. */
4799 breakpoint_sals_to_pc (&sals
, addr_start
);
4801 /* Verify that condition can be parsed, before setting any
4802 breakpoints. Allocate a separate condition expression for each
4804 thread
= -1; /* No specific thread yet */
4805 for (i
= 0; i
< sals
.nelts
; i
++)
4812 char *cond_start
= NULL
;
4813 char *cond_end
= NULL
;
4814 while (*tok
== ' ' || *tok
== '\t')
4819 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4822 toklen
= end_tok
- tok
;
4824 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4826 tok
= cond_start
= end_tok
+ 1;
4827 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4828 make_cleanup (xfree
, cond
[i
]);
4830 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4831 make_cleanup (xfree
, cond_string
[i
]);
4833 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4839 thread
= strtol (tok
, &tok
, 0);
4841 error ("Junk after thread keyword.");
4842 if (!valid_thread_id (thread
))
4843 error ("Unknown thread %d\n", thread
);
4846 error ("Junk at end of arguments.");
4850 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4851 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4852 tempflag
? disp_del
: disp_donttouch
,
4853 thread
, ignore_count
, from_tty
);
4857 warning ("Multiple breakpoints were set.");
4858 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4860 /* That's it. Discard the cleanups for data inserted into the
4862 discard_cleanups (breakpoint_chain
);
4863 /* But cleanup everything else. */
4864 do_cleanups (old_chain
);
4867 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4868 linenum or *address) with COND and IGNORE_COUNT. */
4870 struct captured_breakpoint_args
4881 do_captured_breakpoint (void *data
)
4883 struct captured_breakpoint_args
*args
= data
;
4884 struct symtabs_and_lines sals
;
4885 struct expression
**cond
;
4886 struct cleanup
*old_chain
;
4887 struct cleanup
*breakpoint_chain
= NULL
;
4894 /* Parse the source and lines spec. Delay check that the expression
4895 didn't contain trailing garbage until after cleanups are in
4899 address_end
= args
->address
;
4901 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4906 /* Create a chain of things at always need to be cleaned up. */
4907 old_chain
= make_cleanup (null_cleanup
, 0);
4909 /* Always have a addr_string array, even if it is empty. */
4910 make_cleanup (xfree
, addr_string
);
4912 /* Make sure that all storage allocated to SALS gets freed. */
4913 make_cleanup (xfree
, sals
.sals
);
4915 /* Allocate space for all the cond expressions. */
4916 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4917 make_cleanup (xfree
, cond
);
4919 /* Allocate space for all the cond strings. */
4920 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4921 make_cleanup (xfree
, cond_string
);
4923 /* ----------------------------- SNIP -----------------------------
4924 Anything added to the cleanup chain beyond this point is assumed
4925 to be part of a breakpoint. If the breakpoint create goes
4926 through then that memory is not cleaned up. */
4927 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4929 /* Mark the contents of the addr_string for cleanup. These go on
4930 the breakpoint_chain and only occure if the breakpoint create
4932 for (i
= 0; i
< sals
.nelts
; i
++)
4934 if (addr_string
[i
] != NULL
)
4935 make_cleanup (xfree
, addr_string
[i
]);
4938 /* Wait until now before checking for garbage at the end of the
4939 address. That way cleanups can take care of freeing any
4941 if (*address_end
!= '\0')
4942 error ("Garbage %s following breakpoint address", address_end
);
4944 /* Resolve all line numbers to PC's. */
4945 breakpoint_sals_to_pc (&sals
, args
->address
);
4947 /* Verify that conditions can be parsed, before setting any
4949 for (i
= 0; i
< sals
.nelts
; i
++)
4951 if (args
->condition
!= NULL
)
4953 char *tok
= args
->condition
;
4954 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4956 error ("Garbage %s follows condition", tok
);
4957 make_cleanup (xfree
, cond
[i
]);
4958 cond_string
[i
] = xstrdup (args
->condition
);
4962 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4963 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4964 args
->tempflag
? disp_del
: disp_donttouch
,
4965 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4967 /* That's it. Discard the cleanups for data inserted into the
4969 discard_cleanups (breakpoint_chain
);
4970 /* But cleanup everything else. */
4971 do_cleanups (old_chain
);
4976 gdb_breakpoint (char *address
, char *condition
,
4977 int hardwareflag
, int tempflag
,
4978 int thread
, int ignore_count
)
4980 struct captured_breakpoint_args args
;
4981 args
.address
= address
;
4982 args
.condition
= condition
;
4983 args
.hardwareflag
= hardwareflag
;
4984 args
.tempflag
= tempflag
;
4985 args
.thread
= thread
;
4986 args
.ignore_count
= ignore_count
;
4987 return catch_errors (do_captured_breakpoint
, &args
,
4988 NULL
, RETURN_MASK_ALL
);
4993 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4995 struct frame_info
*frame
;
4996 CORE_ADDR low
, high
, selected_pc
= 0;
4997 char *extra_args
= NULL
;
4999 int extra_args_len
= 0, if_arg
= 0;
5002 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5005 if (default_breakpoint_valid
)
5007 if (deprecated_selected_frame
)
5009 selected_pc
= get_frame_pc (deprecated_selected_frame
);
5014 error ("No selected frame.");
5017 error ("No default breakpoint address now.");
5021 extra_args
= strchr (arg
, ' ');
5025 extra_args_len
= strlen (extra_args
);
5026 level_arg
= (char *) xmalloc (extra_args
- arg
);
5027 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5028 level_arg
[extra_args
- arg
- 1] = '\0';
5032 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5033 strcpy (level_arg
, arg
);
5036 frame
= parse_frame_specification (level_arg
);
5038 selected_pc
= get_frame_pc (frame
);
5045 extra_args_len
= strlen (arg
);
5050 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5054 addr_string
= xstrprintf ("*0x%s %s", paddr_nz (high
), extra_args
);
5056 addr_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5057 break_command_1 (addr_string
, flag
, from_tty
);
5058 xfree (addr_string
);
5061 error ("No function contains the specified address");
5064 error ("Unable to set breakpoint at procedure exit");
5069 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5071 char *addr_string
, *break_string
, *beg_addr_string
;
5072 CORE_ADDR low
, high
;
5073 struct symtabs_and_lines sals
;
5074 struct symtab_and_line sal
;
5075 struct cleanup
*old_chain
;
5076 char *extra_args
= NULL
;
5077 int extra_args_len
= 0;
5081 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5083 if (default_breakpoint_valid
)
5085 if (deprecated_selected_frame
)
5087 addr_string
= xstrprintf ("*0x%s",
5088 paddr_nz (get_frame_pc (deprecated_selected_frame
)));
5093 error ("No selected frame.");
5096 error ("No default breakpoint address now.");
5100 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5101 strcpy (addr_string
, arg
);
5107 extra_args_len
= strlen (arg
);
5111 /* get the stuff after the function name or address */
5112 extra_args
= strchr (arg
, ' ');
5116 extra_args_len
= strlen (extra_args
);
5123 beg_addr_string
= addr_string
;
5124 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5127 xfree (beg_addr_string
);
5128 old_chain
= make_cleanup (xfree
, sals
.sals
);
5129 for (i
= 0; (i
< sals
.nelts
); i
++)
5132 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5136 break_string
= xstrprintf ("*0x%s %s", paddr_nz (high
),
5139 break_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5140 break_command_1 (break_string
, flag
, from_tty
);
5141 xfree (break_string
);
5144 error ("No function contains the specified address");
5148 warning ("Multiple breakpoints were set.\n");
5149 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5151 do_cleanups (old_chain
);
5155 /* Helper function for break_command_1 and disassemble_command. */
5158 resolve_sal_pc (struct symtab_and_line
*sal
)
5162 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5164 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5165 error ("No line %d in file \"%s\".",
5166 sal
->line
, sal
->symtab
->filename
);
5170 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5172 struct blockvector
*bv
;
5177 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5180 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5181 sym
= block_function (b
);
5184 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5185 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5189 /* It really is worthwhile to have the section, so we'll just
5190 have to look harder. This case can be executed if we have
5191 line numbers but no functions (as can happen in assembly
5194 struct minimal_symbol
*msym
;
5196 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5198 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5205 break_command (char *arg
, int from_tty
)
5207 break_command_1 (arg
, 0, from_tty
);
5211 break_at_finish_command (char *arg
, int from_tty
)
5213 break_at_finish_command_1 (arg
, 0, from_tty
);
5217 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5219 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5223 tbreak_command (char *arg
, int from_tty
)
5225 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5229 tbreak_at_finish_command (char *arg
, int from_tty
)
5231 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5235 hbreak_command (char *arg
, int from_tty
)
5237 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5241 thbreak_command (char *arg
, int from_tty
)
5243 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5247 stop_command (char *arg
, int from_tty
)
5249 printf_filtered ("Specify the type of breakpoint to set.\n\
5250 Usage: stop in <function | address>\n\
5255 stopin_command (char *arg
, int from_tty
)
5259 if (arg
== (char *) NULL
)
5261 else if (*arg
!= '*')
5266 /* look for a ':'. If this is a line number specification, then
5267 say it is bad, otherwise, it should be an address or
5268 function/method name */
5269 while (*argptr
&& !hasColon
)
5271 hasColon
= (*argptr
== ':');
5276 badInput
= (*argptr
!= ':'); /* Not a class::method */
5278 badInput
= isdigit (*arg
); /* a simple line number */
5282 printf_filtered ("Usage: stop in <function | address>\n");
5284 break_command_1 (arg
, 0, from_tty
);
5288 stopat_command (char *arg
, int from_tty
)
5292 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5299 /* look for a ':'. If there is a '::' then get out, otherwise
5300 it is probably a line number. */
5301 while (*argptr
&& !hasColon
)
5303 hasColon
= (*argptr
== ':');
5308 badInput
= (*argptr
== ':'); /* we have class::method */
5310 badInput
= !isdigit (*arg
); /* not a line number */
5314 printf_filtered ("Usage: stop at <line>\n");
5316 break_command_1 (arg
, 0, from_tty
);
5319 /* accessflag: hw_write: watch write,
5320 hw_read: watch read,
5321 hw_access: watch access (read or write) */
5323 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5325 struct breakpoint
*b
;
5326 struct symtab_and_line sal
;
5327 struct expression
*exp
;
5328 struct block
*exp_valid_block
;
5329 struct value
*val
, *mark
;
5330 struct frame_info
*frame
;
5331 struct frame_info
*prev_frame
= NULL
;
5332 char *exp_start
= NULL
;
5333 char *exp_end
= NULL
;
5334 char *tok
, *end_tok
;
5336 char *cond_start
= NULL
;
5337 char *cond_end
= NULL
;
5338 struct expression
*cond
= NULL
;
5339 int i
, other_type_used
, target_resources_ok
= 0;
5340 enum bptype bp_type
;
5343 init_sal (&sal
); /* initialize to zeroes */
5345 /* Parse arguments. */
5346 innermost_block
= NULL
;
5348 exp
= parse_exp_1 (&arg
, 0, 0);
5350 exp_valid_block
= innermost_block
;
5351 mark
= value_mark ();
5352 val
= evaluate_expression (exp
);
5353 release_value (val
);
5354 if (VALUE_LAZY (val
))
5355 value_fetch_lazy (val
);
5358 while (*tok
== ' ' || *tok
== '\t')
5362 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5365 toklen
= end_tok
- tok
;
5366 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5368 tok
= cond_start
= end_tok
+ 1;
5369 cond
= parse_exp_1 (&tok
, 0, 0);
5373 error ("Junk at end of command.");
5375 if (accessflag
== hw_read
)
5376 bp_type
= bp_read_watchpoint
;
5377 else if (accessflag
== hw_access
)
5378 bp_type
= bp_access_watchpoint
;
5380 bp_type
= bp_hardware_watchpoint
;
5382 mem_cnt
= can_use_hardware_watchpoint (val
);
5383 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5384 error ("Expression cannot be implemented with read/access watchpoint.");
5387 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5388 target_resources_ok
=
5389 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5391 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5392 error ("Target does not support this type of hardware watchpoint.");
5394 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5395 error ("Target can only support one kind of HW watchpoint at a time.");
5398 #if defined(HPUXHPPA)
5399 /* On HP-UX if you set a h/w
5400 watchpoint before the "run" command, the inferior dies with a e.g.,
5401 SIGILL once you start it. I initially believed this was due to a
5402 bad interaction between page protection traps and the initial
5403 startup sequence by the dynamic linker.
5405 However, I tried avoiding that by having HP-UX's implementation of
5406 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5407 yet, which forced slow watches before a "run" or "attach", and it
5408 still fails somewhere in the startup code.
5410 Until I figure out what's happening, I'm disallowing watches altogether
5411 before the "run" or "attach" command. We'll tell the user they must
5412 set watches after getting the program started. */
5413 if (!target_has_execution
)
5415 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5418 #endif /* HPUXHPPA */
5420 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5421 watchpoint could not be set. */
5422 if (!mem_cnt
|| target_resources_ok
<= 0)
5423 bp_type
= bp_watchpoint
;
5425 /* Now set up the breakpoint. */
5426 b
= set_raw_breakpoint (sal
, bp_type
);
5427 set_breakpoint_count (breakpoint_count
+ 1);
5428 b
->number
= breakpoint_count
;
5429 b
->disposition
= disp_donttouch
;
5431 b
->exp_valid_block
= exp_valid_block
;
5432 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5436 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5440 frame
= block_innermost_frame (exp_valid_block
);
5443 prev_frame
= get_prev_frame (frame
);
5444 b
->watchpoint_frame
= get_frame_id (frame
);
5448 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5451 /* If the expression is "local", then set up a "watchpoint scope"
5452 breakpoint at the point where we've left the scope of the watchpoint
5454 if (innermost_block
)
5458 struct breakpoint
*scope_breakpoint
;
5459 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5460 bp_watchpoint_scope
);
5462 scope_breakpoint
->enable_state
= bp_enabled
;
5464 /* Automatically delete the breakpoint when it hits. */
5465 scope_breakpoint
->disposition
= disp_del
;
5467 /* Only break in the proper frame (help with recursion). */
5468 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5470 /* Set the address at which we will stop. */
5471 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5473 /* The scope breakpoint is related to the watchpoint. We
5474 will need to act on them together. */
5475 b
->related_breakpoint
= scope_breakpoint
;
5478 value_free_to_mark (mark
);
5482 /* Return count of locations need to be watched and can be handled
5483 in hardware. If the watchpoint can not be handled
5484 in hardware return zero. */
5486 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5487 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5488 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5491 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5492 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5493 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5497 can_use_hardware_watchpoint (struct value
*v
)
5499 int found_memory_cnt
= 0;
5500 struct value
*head
= v
;
5502 /* Did the user specifically forbid us to use hardware watchpoints? */
5503 if (!can_use_hw_watchpoints
)
5506 /* Make sure that the value of the expression depends only upon
5507 memory contents, and values computed from them within GDB. If we
5508 find any register references or function calls, we can't use a
5509 hardware watchpoint.
5511 The idea here is that evaluating an expression generates a series
5512 of values, one holding the value of every subexpression. (The
5513 expression a*b+c has five subexpressions: a, b, a*b, c, and
5514 a*b+c.) GDB's values hold almost enough information to establish
5515 the criteria given above --- they identify memory lvalues,
5516 register lvalues, computed values, etcetera. So we can evaluate
5517 the expression, and then scan the chain of values that leaves
5518 behind to decide whether we can detect any possible change to the
5519 expression's final value using only hardware watchpoints.
5521 However, I don't think that the values returned by inferior
5522 function calls are special in any way. So this function may not
5523 notice that an expression involving an inferior function call
5524 can't be watched with hardware watchpoints. FIXME. */
5525 for (; v
; v
= v
->next
)
5527 if (VALUE_LVAL (v
) == lval_memory
)
5530 /* A lazy memory lvalue is one that GDB never needed to fetch;
5531 we either just used its address (e.g., `a' in `a.b') or
5532 we never needed it at all (e.g., `a' in `a,b'). */
5536 /* Ahh, memory we actually used! Check if we can cover
5537 it with hardware watchpoints. */
5538 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5540 /* We only watch structs and arrays if user asked for it
5541 explicitly, never if they just happen to appear in a
5542 middle of some value chain. */
5544 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5545 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5547 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5548 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5550 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5557 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5558 return 0; /* ??? What does this represent? */
5559 else if (v
->lval
== lval_register
)
5560 return 0; /* cannot watch a register with a HW watchpoint */
5563 /* The expression itself looks suitable for using a hardware
5564 watchpoint, but give the target machine a chance to reject it. */
5565 return found_memory_cnt
;
5569 watch_command_wrapper (char *arg
, int from_tty
)
5571 watch_command (arg
, from_tty
);
5575 watch_command (char *arg
, int from_tty
)
5577 watch_command_1 (arg
, hw_write
, from_tty
);
5581 rwatch_command_wrapper (char *arg
, int from_tty
)
5583 rwatch_command (arg
, from_tty
);
5587 rwatch_command (char *arg
, int from_tty
)
5589 watch_command_1 (arg
, hw_read
, from_tty
);
5593 awatch_command_wrapper (char *arg
, int from_tty
)
5595 awatch_command (arg
, from_tty
);
5599 awatch_command (char *arg
, int from_tty
)
5601 watch_command_1 (arg
, hw_access
, from_tty
);
5605 /* Helper routines for the until_command routine in infcmd.c. Here
5606 because it uses the mechanisms of breakpoints. */
5608 /* This function is called by fetch_inferior_event via the
5609 cmd_continuation pointer, to complete the until command. It takes
5610 care of cleaning up the temporary breakpoints set up by the until
5613 until_break_command_continuation (struct continuation_arg
*arg
)
5615 struct cleanup
*cleanups
;
5617 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5618 do_exec_cleanups (cleanups
);
5622 until_break_command (char *arg
, int from_tty
, int anywhere
)
5624 struct symtabs_and_lines sals
;
5625 struct symtab_and_line sal
;
5626 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5627 struct breakpoint
*breakpoint
;
5628 struct cleanup
*old_chain
;
5629 struct continuation_arg
*arg1
;
5632 clear_proceed_status ();
5634 /* Set a breakpoint where the user wants it and at return from
5637 if (default_breakpoint_valid
)
5638 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5639 default_breakpoint_line
, (char ***) NULL
);
5641 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5642 0, (char ***) NULL
);
5644 if (sals
.nelts
!= 1)
5645 error ("Couldn't get information on specified line.");
5648 xfree (sals
.sals
); /* malloc'd, so freed */
5651 error ("Junk at end of arguments.");
5653 resolve_sal_pc (&sal
);
5656 /* If the user told us to continue until a specified location,
5657 we don't specify a frame at which we need to stop. */
5658 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5660 /* Otherwise, specify the current frame, because we want to stop only
5661 at the very same frame. */
5662 breakpoint
= set_momentary_breakpoint (sal
,
5663 get_frame_id (deprecated_selected_frame
),
5666 if (!event_loop_p
|| !target_can_async_p ())
5667 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5669 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5671 /* If we are running asynchronously, and the target supports async
5672 execution, we are not waiting for the target to stop, in the call
5673 tp proceed, below. This means that we cannot delete the
5674 brekpoints until the target has actually stopped. The only place
5675 where we get a chance to do that is in fetch_inferior_event, so
5676 we must set things up for that. */
5678 if (event_loop_p
&& target_can_async_p ())
5680 /* In this case the arg for the continuation is just the point
5681 in the exec_cleanups chain from where to start doing
5682 cleanups, because all the continuation does is the cleanups in
5683 the exec_cleanup_chain. */
5685 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5687 arg1
->data
.pointer
= old_chain
;
5689 add_continuation (until_break_command_continuation
, arg1
);
5692 /* Keep within the current frame, or in frames called by the current
5696 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
5697 sal
.pc
= get_frame_pc (prev_frame
);
5698 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
5700 if (!event_loop_p
|| !target_can_async_p ())
5701 make_cleanup_delete_breakpoint (breakpoint
);
5703 make_exec_cleanup_delete_breakpoint (breakpoint
);
5706 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5707 /* Do the cleanups now, anly if we are not running asynchronously,
5708 of if we are, but the target is still synchronous. */
5709 if (!event_loop_p
|| !target_can_async_p ())
5710 do_cleanups (old_chain
);
5714 /* These aren't used; I don't konw what they were for. */
5715 /* Set a breakpoint at the catch clause for NAME. */
5717 catch_breakpoint (char *name
)
5722 disable_catch_breakpoint (void)
5727 delete_catch_breakpoint (void)
5732 enable_catch_breakpoint (void)
5738 ep_skip_leading_whitespace (char **s
)
5740 if ((s
== NULL
) || (*s
== NULL
))
5742 while (isspace (**s
))
5746 /* This function examines a string, and attempts to find a token
5747 that might be an event name in the leading characters. If a
5748 possible match is found, a pointer to the last character of
5749 the token is returned. Else, NULL is returned. */
5752 ep_find_event_name_end (char *arg
)
5755 char *event_name_end
= NULL
;
5757 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5761 /* We break out of the loop when we find a token delimiter.
5762 Basically, we're looking for alphanumerics and underscores;
5763 anything else delimites the token. */
5766 if (!isalnum (*s
) && (*s
!= '_'))
5772 return event_name_end
;
5776 /* This function attempts to parse an optional "if <cond>" clause
5777 from the arg string. If one is not found, it returns NULL.
5779 Else, it returns a pointer to the condition string. (It does not
5780 attempt to evaluate the string against a particular block.) And,
5781 it updates arg to point to the first character following the parsed
5782 if clause in the arg string. */
5785 ep_parse_optional_if_clause (char **arg
)
5789 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5792 /* Skip the "if" keyword. */
5795 /* Skip any extra leading whitespace, and record the start of the
5796 condition string. */
5797 ep_skip_leading_whitespace (arg
);
5800 /* Assume that the condition occupies the remainder of the arg string. */
5801 (*arg
) += strlen (cond_string
);
5806 /* This function attempts to parse an optional filename from the arg
5807 string. If one is not found, it returns NULL.
5809 Else, it returns a pointer to the parsed filename. (This function
5810 makes no attempt to verify that a file of that name exists, or is
5811 accessible.) And, it updates arg to point to the first character
5812 following the parsed filename in the arg string.
5814 Note that clients needing to preserve the returned filename for
5815 future access should copy it to their own buffers. */
5817 ep_parse_optional_filename (char **arg
)
5819 static char filename
[1024];
5824 if ((*arg_p
== '\0') || isspace (*arg_p
))
5842 /* Commands to deal with catching events, such as signals, exceptions,
5843 process start/exit, etc. */
5847 catch_fork
, catch_vfork
5851 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5852 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5853 char *arg
, int tempflag
, int from_tty
);
5856 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5859 char *cond_string
= NULL
;
5861 ep_skip_leading_whitespace (&arg
);
5863 /* The allowed syntax is:
5865 catch [v]fork if <cond>
5867 First, check if there's an if clause. */
5868 cond_string
= ep_parse_optional_if_clause (&arg
);
5870 if ((*arg
!= '\0') && !isspace (*arg
))
5871 error ("Junk at end of arguments.");
5873 /* If this target supports it, create a fork or vfork catchpoint
5874 and enable reporting of such events. */
5878 create_fork_event_catchpoint (tempflag
, cond_string
);
5881 create_vfork_event_catchpoint (tempflag
, cond_string
);
5884 error ("unsupported or unknown fork kind; cannot catch it");
5890 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5892 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5894 char *cond_string
= NULL
;
5896 ep_skip_leading_whitespace (&arg
);
5898 /* The allowed syntax is:
5900 catch exec if <cond>
5902 First, check if there's an if clause. */
5903 cond_string
= ep_parse_optional_if_clause (&arg
);
5905 if ((*arg
!= '\0') && !isspace (*arg
))
5906 error ("Junk at end of arguments.");
5908 /* If this target supports it, create an exec catchpoint
5909 and enable reporting of such events. */
5910 create_exec_event_catchpoint (tempflag
, cond_string
);
5914 #if defined(SOLIB_ADD)
5916 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
5918 char *dll_pathname
= NULL
;
5919 char *cond_string
= NULL
;
5921 ep_skip_leading_whitespace (&arg
);
5923 /* The allowed syntax is:
5925 catch load if <cond>
5926 catch load <filename>
5927 catch load <filename> if <cond>
5929 The user is not allowed to specify the <filename> after an
5932 We'll ignore the pathological case of a file named "if".
5934 First, check if there's an if clause. If so, then there
5935 cannot be a filename. */
5936 cond_string
= ep_parse_optional_if_clause (&arg
);
5938 /* If there was an if clause, then there cannot be a filename.
5939 Else, there might be a filename and an if clause. */
5940 if (cond_string
== NULL
)
5942 dll_pathname
= ep_parse_optional_filename (&arg
);
5943 ep_skip_leading_whitespace (&arg
);
5944 cond_string
= ep_parse_optional_if_clause (&arg
);
5947 if ((*arg
!= '\0') && !isspace (*arg
))
5948 error ("Junk at end of arguments.");
5950 /* Create a load breakpoint that only triggers when a load of
5951 the specified dll (or any dll, if no pathname was specified)
5953 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5954 dll_pathname
, cond_string
);
5958 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
5960 char *dll_pathname
= NULL
;
5961 char *cond_string
= NULL
;
5963 ep_skip_leading_whitespace (&arg
);
5965 /* The allowed syntax is:
5967 catch unload if <cond>
5968 catch unload <filename>
5969 catch unload <filename> if <cond>
5971 The user is not allowed to specify the <filename> after an
5974 We'll ignore the pathological case of a file named "if".
5976 First, check if there's an if clause. If so, then there
5977 cannot be a filename. */
5978 cond_string
= ep_parse_optional_if_clause (&arg
);
5980 /* If there was an if clause, then there cannot be a filename.
5981 Else, there might be a filename and an if clause. */
5982 if (cond_string
== NULL
)
5984 dll_pathname
= ep_parse_optional_filename (&arg
);
5985 ep_skip_leading_whitespace (&arg
);
5986 cond_string
= ep_parse_optional_if_clause (&arg
);
5989 if ((*arg
!= '\0') && !isspace (*arg
))
5990 error ("Junk at end of arguments.");
5992 /* Create an unload breakpoint that only triggers when an unload of
5993 the specified dll (or any dll, if no pathname was specified)
5995 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5996 dll_pathname
, cond_string
);
5998 #endif /* SOLIB_ADD */
6000 /* Commands to deal with catching exceptions. */
6002 /* Set a breakpoint at the specified callback routine for an
6003 exception event callback */
6006 create_exception_catchpoint (int tempflag
, char *cond_string
,
6007 enum exception_event_kind ex_event
,
6008 struct symtab_and_line
*sal
)
6010 struct breakpoint
*b
;
6011 int thread
= -1; /* All threads. */
6014 if (!sal
) /* no exception support? */
6019 case EX_EVENT_THROW
:
6020 bptype
= bp_catch_throw
;
6022 case EX_EVENT_CATCH
:
6023 bptype
= bp_catch_catch
;
6025 default: /* error condition */
6026 error ("Internal error -- invalid catchpoint kind");
6029 b
= set_raw_breakpoint (*sal
, bptype
);
6030 set_breakpoint_count (breakpoint_count
+ 1);
6031 b
->number
= breakpoint_count
;
6033 b
->cond_string
= (cond_string
== NULL
) ?
6034 NULL
: savestring (cond_string
, strlen (cond_string
));
6036 b
->addr_string
= NULL
;
6037 b
->enable_state
= bp_enabled
;
6038 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6042 static enum print_stop_action
6043 print_exception_catchpoint (struct breakpoint
*b
)
6045 annotate_catchpoint (b
->number
);
6047 if (strstr (b
->addr_string
, "throw") != NULL
)
6048 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6051 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6054 return PRINT_SRC_AND_LOC
;
6058 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6063 ui_out_field_core_addr (uiout
, "addr", b
->address
);
6066 *last_addr
= b
->address
;
6067 if (strstr (b
->addr_string
, "throw") != NULL
)
6068 ui_out_field_string (uiout
, "what", "exception throw");
6070 ui_out_field_string (uiout
, "what", "exception catch");
6074 print_mention_exception_catchpoint (struct breakpoint
*b
)
6076 if (strstr (b
->addr_string
, "throw") != NULL
)
6077 printf_filtered ("Catchpoint %d (throw)", b
->number
);
6079 printf_filtered ("Catchpoint %d (catch)", b
->number
);
6082 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6083 print_exception_catchpoint
,
6084 print_one_exception_catchpoint
,
6085 print_mention_exception_catchpoint
6089 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6090 enum exception_event_kind ex_event
, int from_tty
)
6092 char *trigger_func_name
, *nameptr
;
6093 struct symtabs_and_lines sals
;
6094 struct breakpoint
*b
;
6096 if (ex_event
== EX_EVENT_CATCH
)
6097 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6099 trigger_func_name
= xstrdup ("__cxa_throw");
6101 nameptr
= trigger_func_name
;
6102 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
);
6103 if (sals
.nelts
== 0)
6105 xfree (trigger_func_name
);
6109 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6110 set_breakpoint_count (breakpoint_count
+ 1);
6111 b
->number
= breakpoint_count
;
6113 b
->cond_string
= (cond_string
== NULL
) ?
6114 NULL
: savestring (cond_string
, strlen (cond_string
));
6116 b
->addr_string
= trigger_func_name
;
6117 b
->enable_state
= bp_enabled
;
6118 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6119 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6126 /* Deal with "catch catch" and "catch throw" commands */
6129 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6130 int tempflag
, int from_tty
)
6132 char *cond_string
= NULL
;
6133 struct symtab_and_line
*sal
= NULL
;
6135 ep_skip_leading_whitespace (&arg
);
6137 cond_string
= ep_parse_optional_if_clause (&arg
);
6139 if ((*arg
!= '\0') && !isspace (*arg
))
6140 error ("Junk at end of arguments.");
6142 if ((ex_event
!= EX_EVENT_THROW
) &&
6143 (ex_event
!= EX_EVENT_CATCH
))
6144 error ("Unsupported or unknown exception event; cannot catch it");
6146 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6149 /* See if we can find a callback routine */
6150 sal
= target_enable_exception_callback (ex_event
, 1);
6154 /* We have callbacks from the runtime system for exceptions.
6155 Set a breakpoint on the sal found, if no errors */
6156 if (sal
!= (struct symtab_and_line
*) -1)
6157 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6159 return; /* something went wrong with setting up callbacks */
6162 warning ("Unsupported with this platform/compiler combination.");
6165 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6166 inside a catch_errors */
6169 cover_target_enable_exception_callback (void *arg
)
6171 args_for_catchpoint_enable
*args
= arg
;
6172 struct symtab_and_line
*sal
;
6173 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6176 else if (sal
== (struct symtab_and_line
*) -1)
6179 return 1; /*is valid */
6183 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6186 /* The first argument may be an event name, such as "start" or "load".
6187 If so, then handle it as such. If it doesn't match an event name,
6188 then attempt to interpret it as an exception name. (This latter is
6189 the v4.16-and-earlier GDB meaning of the "catch" command.)
6191 First, try to find the bounds of what might be an event name. */
6192 char *arg1_start
= arg
;
6196 if (arg1_start
== NULL
)
6198 /* Old behaviour was to use pre-v-4.16 syntax */
6199 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6201 /* Now, this is not allowed */
6202 error ("Catch requires an event name.");
6205 arg1_end
= ep_find_event_name_end (arg1_start
);
6206 if (arg1_end
== NULL
)
6207 error ("catch requires an event");
6208 arg1_length
= arg1_end
+ 1 - arg1_start
;
6210 /* Try to match what we found against known event names. */
6211 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6213 error ("Catch of signal not yet implemented");
6215 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6217 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6218 tempflag
, from_tty
);
6220 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6222 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6223 tempflag
, from_tty
);
6225 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6227 error ("Catch of thread_start not yet implemented");
6229 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6231 error ("Catch of thread_exit not yet implemented");
6233 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6235 error ("Catch of thread_join not yet implemented");
6237 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6239 error ("Catch of start not yet implemented");
6241 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6243 error ("Catch of exit not yet implemented");
6245 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6247 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6248 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6250 error ("Catch of fork not yet implemented");
6253 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6255 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6256 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6258 error ("Catch of vfork not yet implemented");
6261 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6263 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6264 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6266 error ("Catch of exec not yet implemented");
6269 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6271 #if defined(SOLIB_ADD)
6272 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6274 error ("Catch of load not implemented");
6277 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6279 #if defined(SOLIB_ADD)
6280 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6282 error ("Catch of load not implemented");
6285 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6287 error ("Catch of stop not yet implemented");
6290 /* This doesn't appear to be an event name */
6294 /* Pre-v.4.16 behaviour was to treat the argument
6295 as the name of an exception */
6296 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6297 /* Now this is not allowed */
6298 error ("Unknown event kind specified for catch");
6303 /* Used by the gui, could be made a worker for other things. */
6306 set_breakpoint_sal (struct symtab_and_line sal
)
6308 struct breakpoint
*b
;
6309 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6310 set_breakpoint_count (breakpoint_count
+ 1);
6311 b
->number
= breakpoint_count
;
6318 /* These aren't used; I don't know what they were for. */
6319 /* Disable breakpoints on all catch clauses described in ARGS. */
6321 disable_catch (char *args
)
6323 /* Map the disable command to catch clauses described in ARGS. */
6326 /* Enable breakpoints on all catch clauses described in ARGS. */
6328 enable_catch (char *args
)
6330 /* Map the disable command to catch clauses described in ARGS. */
6333 /* Delete breakpoints on all catch clauses in the active scope. */
6335 delete_catch (char *args
)
6337 /* Map the delete command to catch clauses described in ARGS. */
6342 catch_command (char *arg
, int from_tty
)
6344 catch_command_1 (arg
, 0, from_tty
);
6349 tcatch_command (char *arg
, int from_tty
)
6351 catch_command_1 (arg
, 1, from_tty
);
6354 /* Delete breakpoints by address or line. */
6357 clear_command (char *arg
, int from_tty
)
6359 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6361 struct symtabs_and_lines sals
;
6362 struct symtab_and_line sal
;
6367 sals
= decode_line_spec (arg
, 1);
6372 sals
.sals
= (struct symtab_and_line
*)
6373 xmalloc (sizeof (struct symtab_and_line
));
6374 make_cleanup (xfree
, sals
.sals
);
6375 init_sal (&sal
); /* initialize to zeroes */
6376 sal
.line
= default_breakpoint_line
;
6377 sal
.symtab
= default_breakpoint_symtab
;
6378 sal
.pc
= default_breakpoint_address
;
6379 if (sal
.symtab
== 0)
6380 error ("No source file specified.");
6388 /* For each line spec given, delete bps which correspond
6389 to it. Do it in two passes, solely to preserve the current
6390 behavior that from_tty is forced true if we delete more than
6394 for (i
= 0; i
< sals
.nelts
; i
++)
6396 /* If exact pc given, clear bpts at that pc.
6397 If line given (pc == 0), clear all bpts on specified line.
6398 If defaulting, clear all bpts on default line
6401 defaulting sal.pc != 0 tests to do
6406 1 0 <can't happen> */
6411 /* Find all matching breakpoints, remove them from the
6412 breakpoint chain, and add them to the 'found' chain. */
6413 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6415 /* Are we going to delete b? */
6416 if (b
->type
!= bp_none
6417 && b
->type
!= bp_watchpoint
6418 && b
->type
!= bp_hardware_watchpoint
6419 && b
->type
!= bp_read_watchpoint
6420 && b
->type
!= bp_access_watchpoint
6421 /* Not if b is a watchpoint of any sort... */
6422 && (((sal
.pc
&& (b
->address
== sal
.pc
))
6423 && (!section_is_overlay (b
->section
)
6424 || b
->section
== sal
.section
))
6425 /* Yes, if sal.pc matches b (modulo overlays). */
6426 || ((default_match
|| (0 == sal
.pc
))
6427 && b
->source_file
!= NULL
6428 && sal
.symtab
!= NULL
6429 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6430 && b
->line_number
== sal
.line
)))
6431 /* Yes, if sal source file and line matches b. */
6433 /* Remove it from breakpoint_chain... */
6434 if (b
== breakpoint_chain
)
6436 /* b is at the head of the list */
6437 breakpoint_chain
= b
->next
;
6441 prev
->next
= b
->next
;
6443 /* And add it to 'found' chain. */
6449 /* Keep b, and keep a pointer to it. */
6454 /* Now go thru the 'found' chain and delete them. */
6458 error ("No breakpoint at %s.", arg
);
6460 error ("No breakpoint at this line.");
6464 from_tty
= 1; /* Always report if deleted more than one */
6466 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6467 breakpoints_changed ();
6471 printf_unfiltered ("%d ", found
->number
);
6473 delete_breakpoint (found
);
6477 putchar_unfiltered ('\n');
6480 /* Delete breakpoint in BS if they are `delete' breakpoints and
6481 all breakpoints that are marked for deletion, whether hit or not.
6482 This is called after any breakpoint is hit, or after errors. */
6485 breakpoint_auto_delete (bpstat bs
)
6487 struct breakpoint
*b
, *temp
;
6489 for (; bs
; bs
= bs
->next
)
6490 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6492 delete_breakpoint (bs
->breakpoint_at
);
6494 ALL_BREAKPOINTS_SAFE (b
, temp
)
6496 if (b
->disposition
== disp_del_at_next_stop
)
6497 delete_breakpoint (b
);
6501 /* Delete a breakpoint and clean up all traces of it in the data
6505 delete_breakpoint (struct breakpoint
*bpt
)
6507 struct breakpoint
*b
;
6511 error ("Internal error (attempted to delete a NULL breakpoint)");
6514 /* Has this bp already been deleted? This can happen because multiple
6515 lists can hold pointers to bp's. bpstat lists are especial culprits.
6517 One example of this happening is a watchpoint's scope bp. When the
6518 scope bp triggers, we notice that the watchpoint is out of scope, and
6519 delete it. We also delete its scope bp. But the scope bp is marked
6520 "auto-deleting", and is already on a bpstat. That bpstat is then
6521 checked for auto-deleting bp's, which are deleted.
6523 A real solution to this problem might involve reference counts in bp's,
6524 and/or giving them pointers back to their referencing bpstat's, and
6525 teaching delete_breakpoint to only free a bp's storage when no more
6526 references were extent. A cheaper bandaid was chosen. */
6527 if (bpt
->type
== bp_none
)
6530 if (delete_breakpoint_hook
)
6531 delete_breakpoint_hook (bpt
);
6532 breakpoint_delete_event (bpt
->number
);
6535 remove_breakpoint (bpt
, mark_inserted
);
6537 if (breakpoint_chain
== bpt
)
6538 breakpoint_chain
= bpt
->next
;
6540 /* If we have callback-style exception catchpoints, don't go through
6541 the adjustments to the C++ runtime library etc. if the inferior
6542 isn't actually running. target_enable_exception_callback for a
6543 null target ops vector gives an undesirable error message, so we
6544 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6545 exceptions are supported in this way, it's OK for now. FIXME */
6546 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6548 /* Format possible error msg */
6549 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6551 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6552 args_for_catchpoint_enable args
;
6553 args
.kind
= bpt
->type
== bp_catch_catch
?
6554 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6556 catch_errors (cover_target_enable_exception_callback
, &args
,
6557 message
, RETURN_MASK_ALL
);
6558 do_cleanups (cleanups
);
6565 b
->next
= bpt
->next
;
6569 check_duplicates (bpt
);
6570 /* If this breakpoint was inserted, and there is another breakpoint
6571 at the same address, we need to insert the other breakpoint. */
6573 && bpt
->type
!= bp_hardware_watchpoint
6574 && bpt
->type
!= bp_read_watchpoint
6575 && bpt
->type
!= bp_access_watchpoint
6576 && bpt
->type
!= bp_catch_fork
6577 && bpt
->type
!= bp_catch_vfork
6578 && bpt
->type
!= bp_catch_exec
)
6581 if (b
->address
== bpt
->address
6582 && b
->section
== bpt
->section
6584 && b
->enable_state
!= bp_disabled
6585 && b
->enable_state
!= bp_shlib_disabled
6586 && b
->enable_state
!= bp_call_disabled
)
6590 /* We should never reach this point if there is a permanent
6591 breakpoint at the same address as the one being deleted.
6592 If there is a permanent breakpoint somewhere, it should
6593 always be the only one inserted. */
6594 if (b
->enable_state
== bp_permanent
)
6595 internal_error (__FILE__
, __LINE__
,
6596 "another breakpoint was inserted on top of "
6597 "a permanent breakpoint");
6599 if (b
->type
== bp_hardware_breakpoint
)
6600 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6602 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6604 /* If there was an error in the insert, print a message, then stop execution. */
6607 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6608 make_cleanup_ui_file_delete (tmp_error_stream
);
6611 if (b
->type
== bp_hardware_breakpoint
)
6613 fprintf_unfiltered (tmp_error_stream
,
6614 "Cannot insert hardware breakpoint %d.\n"
6615 "You may have requested too many hardware breakpoints.\n",
6620 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6621 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6622 print_address_numeric (b
->address
, 1, tmp_error_stream
);
6623 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6624 safe_strerror (val
));
6627 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6628 target_terminal_ours_for_output ();
6629 error_stream(tmp_error_stream
);
6636 free_command_lines (&bpt
->commands
);
6639 if (bpt
->cond_string
!= NULL
)
6640 xfree (bpt
->cond_string
);
6641 if (bpt
->addr_string
!= NULL
)
6642 xfree (bpt
->addr_string
);
6643 if (bpt
->exp
!= NULL
)
6645 if (bpt
->exp_string
!= NULL
)
6646 xfree (bpt
->exp_string
);
6647 if (bpt
->val
!= NULL
)
6648 value_free (bpt
->val
);
6649 if (bpt
->source_file
!= NULL
)
6650 xfree (bpt
->source_file
);
6651 if (bpt
->dll_pathname
!= NULL
)
6652 xfree (bpt
->dll_pathname
);
6653 if (bpt
->triggered_dll_pathname
!= NULL
)
6654 xfree (bpt
->triggered_dll_pathname
);
6655 if (bpt
->exec_pathname
!= NULL
)
6656 xfree (bpt
->exec_pathname
);
6658 /* Be sure no bpstat's are pointing at it after it's been freed. */
6659 /* FIXME, how can we find all bpstat's?
6660 We just check stop_bpstat for now. */
6661 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6662 if (bs
->breakpoint_at
== bpt
)
6664 bs
->breakpoint_at
= NULL
;
6666 /* bs->commands will be freed later. */
6668 /* On the chance that someone will soon try again to delete this same
6669 bp, we mark it as deleted before freeing its storage. */
6670 bpt
->type
= bp_none
;
6676 do_delete_breakpoint_cleanup (void *b
)
6678 delete_breakpoint (b
);
6682 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6684 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6688 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6690 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6694 delete_command (char *arg
, int from_tty
)
6696 struct breakpoint
*b
, *temp
;
6702 int breaks_to_delete
= 0;
6704 /* Delete all breakpoints if no argument.
6705 Do not delete internal or call-dummy breakpoints, these
6706 have to be deleted with an explicit breakpoint number argument. */
6709 if (b
->type
!= bp_call_dummy
&&
6710 b
->type
!= bp_shlib_event
&&
6711 b
->type
!= bp_thread_event
&&
6712 b
->type
!= bp_overlay_event
&&
6714 breaks_to_delete
= 1;
6717 /* Ask user only if there are some breakpoints to delete. */
6719 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6721 ALL_BREAKPOINTS_SAFE (b
, temp
)
6723 if (b
->type
!= bp_call_dummy
&&
6724 b
->type
!= bp_shlib_event
&&
6725 b
->type
!= bp_thread_event
&&
6726 b
->type
!= bp_overlay_event
&&
6728 delete_breakpoint (b
);
6733 map_breakpoint_numbers (arg
, delete_breakpoint
);
6736 /* Reset a breakpoint given it's struct breakpoint * BINT.
6737 The value we return ends up being the return value from catch_errors.
6738 Unused in this case. */
6741 breakpoint_re_set_one (void *bint
)
6743 /* get past catch_errs */
6744 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6747 struct symtabs_and_lines sals
;
6749 enum enable_state save_enable
;
6754 warning ("attempted to reset apparently deleted breakpoint #%d?",
6758 case bp_hardware_breakpoint
:
6760 case bp_catch_unload
:
6761 if (b
->addr_string
== NULL
)
6763 /* Anything without a string can't be re-set. */
6764 delete_breakpoint (b
);
6767 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6769 ``And a hack it is, although Apple's Darwin version of GDB
6770 contains an almost identical hack to implement a "future
6771 break" command. It seems to work in many real world cases,
6772 but it is easy to come up with a test case where the patch
6773 doesn't help at all.''
6775 ``It seems that the way GDB implements breakpoints - in -
6776 shared - libraries was designed for a.out shared library
6777 systems (SunOS 4) where shared libraries were loaded at a
6778 fixed address in memory. Since ELF shared libraries can (and
6779 will) be loaded at any address in memory, things break.
6780 Fixing this is not trivial. Therefore, I'm not sure whether
6781 we should add this hack to the branch only. I cannot
6782 guarantee that things will be fixed on the trunk in the near
6785 In case we have a problem, disable this breakpoint. We'll
6786 restore its status if we succeed. Don't disable a
6787 shlib_disabled breakpoint though. There's a fair chance we
6788 can't re-set it if the shared library it's in hasn't been
6790 save_enable
= b
->enable_state
;
6791 if (b
->enable_state
!= bp_shlib_disabled
)
6792 b
->enable_state
= bp_disabled
;
6794 set_language (b
->language
);
6795 input_radix
= b
->input_radix
;
6797 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6798 for (i
= 0; i
< sals
.nelts
; i
++)
6800 resolve_sal_pc (&sals
.sals
[i
]);
6802 /* Reparse conditions, they might contain references to the
6804 if (b
->cond_string
!= NULL
)
6809 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6812 /* We need to re-set the breakpoint if the address changes... */
6813 if (b
->address
!= sals
.sals
[i
].pc
6814 /* ...or new and old breakpoints both have source files, and
6815 the source file name or the line number changes... */
6816 || (b
->source_file
!= NULL
6817 && sals
.sals
[i
].symtab
!= NULL
6818 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6819 || b
->line_number
!= sals
.sals
[i
].line
)
6821 /* ...or we switch between having a source file and not having
6823 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6826 if (b
->source_file
!= NULL
)
6827 xfree (b
->source_file
);
6828 if (sals
.sals
[i
].symtab
== NULL
)
6829 b
->source_file
= NULL
;
6832 savestring (sals
.sals
[i
].symtab
->filename
,
6833 strlen (sals
.sals
[i
].symtab
->filename
));
6834 b
->line_number
= sals
.sals
[i
].line
;
6835 b
->address
= sals
.sals
[i
].pc
;
6837 /* Used to check for duplicates here, but that can
6838 cause trouble, as it doesn't check for disabled
6843 /* Might be better to do this just once per breakpoint_re_set,
6844 rather than once for every breakpoint. */
6845 breakpoints_changed ();
6847 b
->section
= sals
.sals
[i
].section
;
6848 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6851 /* Now that this is re-enabled, check_duplicates
6853 check_duplicates (b
);
6860 case bp_hardware_watchpoint
:
6861 case bp_read_watchpoint
:
6862 case bp_access_watchpoint
:
6863 innermost_block
= NULL
;
6864 /* The issue arises of what context to evaluate this in. The
6865 same one as when it was set, but what does that mean when
6866 symbols have been re-read? We could save the filename and
6867 functionname, but if the context is more local than that, the
6868 best we could do would be something like how many levels deep
6869 and which index at that particular level, but that's going to
6870 be less stable than filenames or function names. */
6872 /* So for now, just use a global context. */
6875 b
->exp
= parse_expression (b
->exp_string
);
6876 b
->exp_valid_block
= innermost_block
;
6877 mark
= value_mark ();
6879 value_free (b
->val
);
6880 b
->val
= evaluate_expression (b
->exp
);
6881 release_value (b
->val
);
6882 if (VALUE_LAZY (b
->val
) && b
->enable_state
== bp_enabled
)
6883 value_fetch_lazy (b
->val
);
6885 if (b
->cond_string
!= NULL
)
6890 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
6892 if (b
->enable_state
== bp_enabled
)
6894 value_free_to_mark (mark
);
6896 case bp_catch_catch
:
6897 case bp_catch_throw
:
6899 /* We needn't really do anything to reset these, since the mask
6900 that requests them is unaffected by e.g., new libraries being
6903 case bp_catch_vfork
:
6908 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
6910 /* Delete longjmp and overlay event breakpoints; they will be
6911 reset later by breakpoint_re_set. */
6913 case bp_longjmp_resume
:
6914 case bp_overlay_event
:
6915 delete_breakpoint (b
);
6918 /* This breakpoint is special, it's set up when the inferior
6919 starts and we really don't want to touch it. */
6920 case bp_shlib_event
:
6922 /* Like bp_shlib_event, this breakpoint type is special.
6923 Once it is set up, we do not want to touch it. */
6924 case bp_thread_event
:
6926 /* Keep temporary breakpoints, which can be encountered when we step
6927 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6928 Otherwise these should have been blown away via the cleanup chain
6929 or by breakpoint_init_inferior when we rerun the executable. */
6932 case bp_watchpoint_scope
:
6934 case bp_step_resume
:
6941 /* Re-set all breakpoints after symbols have been re-loaded. */
6943 breakpoint_re_set (void)
6945 struct breakpoint
*b
, *temp
;
6946 enum language save_language
;
6947 int save_input_radix
;
6949 save_language
= current_language
->la_language
;
6950 save_input_radix
= input_radix
;
6951 ALL_BREAKPOINTS_SAFE (b
, temp
)
6953 /* Format possible error msg */
6954 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
6956 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6957 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
6958 do_cleanups (cleanups
);
6960 set_language (save_language
);
6961 input_radix
= save_input_radix
;
6963 if (GET_LONGJMP_TARGET_P ())
6965 create_longjmp_breakpoint ("longjmp");
6966 create_longjmp_breakpoint ("_longjmp");
6967 create_longjmp_breakpoint ("siglongjmp");
6968 create_longjmp_breakpoint ("_siglongjmp");
6969 create_longjmp_breakpoint (NULL
);
6972 create_overlay_event_breakpoint ("_ovly_debug_event");
6975 /* Reset the thread number of this breakpoint:
6977 - If the breakpoint is for all threads, leave it as-is.
6978 - Else, reset it to the current thread for inferior_ptid. */
6980 breakpoint_re_set_thread (struct breakpoint
*b
)
6982 if (b
->thread
!= -1)
6984 if (in_thread_list (inferior_ptid
))
6985 b
->thread
= pid_to_thread_id (inferior_ptid
);
6989 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6990 If from_tty is nonzero, it prints a message to that effect,
6991 which ends with a period (no newline). */
6994 set_ignore_count (int bptnum
, int count
, int from_tty
)
6996 struct breakpoint
*b
;
7002 if (b
->number
== bptnum
)
7004 b
->ignore_count
= count
;
7008 printf_filtered ("Will stop next time breakpoint %d is reached.",
7010 else if (count
== 1)
7011 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7014 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7017 breakpoints_changed ();
7018 breakpoint_modify_event (b
->number
);
7022 error ("No breakpoint number %d.", bptnum
);
7025 /* Clear the ignore counts of all breakpoints. */
7027 breakpoint_clear_ignore_counts (void)
7029 struct breakpoint
*b
;
7032 b
->ignore_count
= 0;
7035 /* Command to set ignore-count of breakpoint N to COUNT. */
7038 ignore_command (char *args
, int from_tty
)
7044 error_no_arg ("a breakpoint number");
7046 num
= get_number (&p
);
7048 error ("bad breakpoint number: '%s'", args
);
7050 error ("Second argument (specified ignore-count) is missing.");
7052 set_ignore_count (num
,
7053 longest_to_int (value_as_long (parse_and_eval (p
))),
7056 printf_filtered ("\n");
7059 /* Call FUNCTION on each of the breakpoints
7060 whose numbers are given in ARGS. */
7063 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7068 struct breakpoint
*b
, *tmp
;
7072 error_no_arg ("one or more breakpoint numbers");
7079 num
= get_number_or_range (&p1
);
7082 warning ("bad breakpoint number at or near '%s'", p
);
7086 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7087 if (b
->number
== num
)
7089 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7092 if (related_breakpoint
)
7093 function (related_breakpoint
);
7097 printf_unfiltered ("No breakpoint number %d.\n", num
);
7103 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7104 If from_tty is nonzero, it prints a message to that effect,
7105 which ends with a period (no newline). */
7108 disable_breakpoint (struct breakpoint
*bpt
)
7110 /* Never disable a watchpoint scope breakpoint; we want to
7111 hit them when we leave scope so we can delete both the
7112 watchpoint and its scope breakpoint at that time. */
7113 if (bpt
->type
== bp_watchpoint_scope
)
7116 /* You can't disable permanent breakpoints. */
7117 if (bpt
->enable_state
== bp_permanent
)
7120 bpt
->enable_state
= bp_disabled
;
7122 check_duplicates (bpt
);
7124 if (modify_breakpoint_hook
)
7125 modify_breakpoint_hook (bpt
);
7126 breakpoint_modify_event (bpt
->number
);
7130 disable_command (char *args
, int from_tty
)
7132 struct breakpoint
*bpt
;
7134 ALL_BREAKPOINTS (bpt
)
7138 warning ("attempted to disable apparently deleted breakpoint #%d?",
7143 case bp_catch_unload
:
7145 case bp_catch_vfork
:
7147 case bp_catch_catch
:
7148 case bp_catch_throw
:
7149 case bp_hardware_breakpoint
:
7151 case bp_hardware_watchpoint
:
7152 case bp_read_watchpoint
:
7153 case bp_access_watchpoint
:
7154 disable_breakpoint (bpt
);
7159 map_breakpoint_numbers (args
, disable_breakpoint
);
7163 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7165 struct frame_info
*save_selected_frame
= NULL
;
7166 int save_selected_frame_level
= -1;
7167 int target_resources_ok
, other_type_used
;
7170 if (bpt
->type
== bp_hardware_breakpoint
)
7173 i
= hw_breakpoint_used_count ();
7174 target_resources_ok
=
7175 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7177 if (target_resources_ok
== 0)
7178 error ("No hardware breakpoint support in the target.");
7179 else if (target_resources_ok
< 0)
7180 error ("Hardware breakpoints used exceeds limit.");
7183 if (bpt
->enable_state
!= bp_permanent
)
7184 bpt
->enable_state
= bp_enabled
;
7185 bpt
->disposition
= disposition
;
7186 check_duplicates (bpt
);
7187 breakpoints_changed ();
7189 if (bpt
->type
== bp_watchpoint
||
7190 bpt
->type
== bp_hardware_watchpoint
||
7191 bpt
->type
== bp_read_watchpoint
||
7192 bpt
->type
== bp_access_watchpoint
)
7194 if (bpt
->exp_valid_block
!= NULL
)
7196 struct frame_info
*fr
=
7197 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7201 Cannot enable watchpoint %d because the block in which its expression\n\
7202 is valid is not currently in scope.\n", bpt
->number
);
7203 bpt
->enable_state
= bp_disabled
;
7207 save_selected_frame
= deprecated_selected_frame
;
7208 save_selected_frame_level
= frame_relative_level (deprecated_selected_frame
);
7212 value_free (bpt
->val
);
7213 mark
= value_mark ();
7214 bpt
->val
= evaluate_expression (bpt
->exp
);
7215 release_value (bpt
->val
);
7216 if (VALUE_LAZY (bpt
->val
))
7217 value_fetch_lazy (bpt
->val
);
7219 if (bpt
->type
== bp_hardware_watchpoint
||
7220 bpt
->type
== bp_read_watchpoint
||
7221 bpt
->type
== bp_access_watchpoint
)
7223 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7224 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7226 /* Hack around 'unused var' error for some targets here */
7228 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7229 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7230 /* we can consider of type is bp_hardware_watchpoint, convert to
7231 bp_watchpoint in the following condition */
7232 if (target_resources_ok
< 0)
7235 Cannot enable watchpoint %d because target watch resources\n\
7236 have been allocated for other watchpoints.\n", bpt
->number
);
7237 bpt
->enable_state
= bp_disabled
;
7238 value_free_to_mark (mark
);
7243 if (save_selected_frame_level
>= 0)
7244 select_frame (save_selected_frame
);
7245 value_free_to_mark (mark
);
7247 if (modify_breakpoint_hook
)
7248 modify_breakpoint_hook (bpt
);
7249 breakpoint_modify_event (bpt
->number
);
7253 enable_breakpoint (struct breakpoint
*bpt
)
7255 do_enable_breakpoint (bpt
, bpt
->disposition
);
7258 /* The enable command enables the specified breakpoints (or all defined
7259 breakpoints) so they once again become (or continue to be) effective
7260 in stopping the inferior. */
7263 enable_command (char *args
, int from_tty
)
7265 struct breakpoint
*bpt
;
7267 ALL_BREAKPOINTS (bpt
)
7271 warning ("attempted to enable apparently deleted breakpoint #%d?",
7276 case bp_catch_unload
:
7278 case bp_catch_vfork
:
7280 case bp_catch_catch
:
7281 case bp_catch_throw
:
7282 case bp_hardware_breakpoint
:
7284 case bp_hardware_watchpoint
:
7285 case bp_read_watchpoint
:
7286 case bp_access_watchpoint
:
7287 enable_breakpoint (bpt
);
7292 map_breakpoint_numbers (args
, enable_breakpoint
);
7296 enable_once_breakpoint (struct breakpoint
*bpt
)
7298 do_enable_breakpoint (bpt
, disp_disable
);
7302 enable_once_command (char *args
, int from_tty
)
7304 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7308 enable_delete_breakpoint (struct breakpoint
*bpt
)
7310 do_enable_breakpoint (bpt
, disp_del
);
7314 enable_delete_command (char *args
, int from_tty
)
7316 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7319 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7321 struct symtabs_and_lines
7322 decode_line_spec_1 (char *string
, int funfirstline
)
7324 struct symtabs_and_lines sals
;
7326 error ("Empty line specification.");
7327 if (default_breakpoint_valid
)
7328 sals
= decode_line_1 (&string
, funfirstline
,
7329 default_breakpoint_symtab
,
7330 default_breakpoint_line
,
7333 sals
= decode_line_1 (&string
, funfirstline
,
7334 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7336 error ("Junk at end of line specification: %s", string
);
7341 _initialize_breakpoint (void)
7343 struct cmd_list_element
*c
;
7345 breakpoint_chain
= 0;
7346 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7347 before a breakpoint is set. */
7348 breakpoint_count
= 0;
7350 add_com ("ignore", class_breakpoint
, ignore_command
,
7351 "Set ignore-count of breakpoint number N to COUNT.\n\
7352 Usage is `ignore N COUNT'.");
7354 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7356 add_com ("commands", class_breakpoint
, commands_command
,
7357 "Set commands to be executed when a breakpoint is hit.\n\
7358 Give breakpoint number as argument after \"commands\".\n\
7359 With no argument, the targeted breakpoint is the last one set.\n\
7360 The commands themselves follow starting on the next line.\n\
7361 Type a line containing \"end\" to indicate the end of them.\n\
7362 Give \"silent\" as the first line to make the breakpoint silent;\n\
7363 then no output is printed when it is hit, except what the commands print.");
7365 add_com ("condition", class_breakpoint
, condition_command
,
7366 "Specify breakpoint number N to break only if COND is true.\n\
7367 Usage is `condition N COND', where N is an integer and COND is an\n\
7368 expression to be evaluated whenever breakpoint N is reached.");
7370 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7371 "Set a temporary breakpoint. Args like \"break\" command.\n\
7372 Like \"break\" except the breakpoint is only temporary,\n\
7373 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7374 by using \"enable delete\" on the breakpoint number.");
7375 set_cmd_completer (c
, location_completer
);
7377 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7378 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7379 Like \"break\" except the breakpoint requires hardware support,\n\
7380 some target hardware may not have this support.");
7381 set_cmd_completer (c
, location_completer
);
7383 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7384 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7385 Like \"hbreak\" except the breakpoint is only temporary,\n\
7386 so it will be deleted when hit.");
7387 set_cmd_completer (c
, location_completer
);
7389 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7390 "Enable some breakpoints.\n\
7391 Give breakpoint numbers (separated by spaces) as arguments.\n\
7392 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7393 This is used to cancel the effect of the \"disable\" command.\n\
7394 With a subcommand you can enable temporarily.",
7395 &enablelist
, "enable ", 1, &cmdlist
);
7397 add_com ("ab", class_breakpoint
, enable_command
,
7398 "Enable some breakpoints.\n\
7399 Give breakpoint numbers (separated by spaces) as arguments.\n\
7400 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7401 This is used to cancel the effect of the \"disable\" command.\n\
7402 With a subcommand you can enable temporarily.");
7404 add_com_alias ("en", "enable", class_breakpoint
, 1);
7406 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7407 "Enable some breakpoints.\n\
7408 Give breakpoint numbers (separated by spaces) as arguments.\n\
7409 This is used to cancel the effect of the \"disable\" command.\n\
7410 May be abbreviated to simply \"enable\".\n",
7411 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7413 add_cmd ("once", no_class
, enable_once_command
,
7414 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7415 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
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 ("delete", no_class
, enable_delete_command
,
7424 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7425 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7428 add_cmd ("once", no_class
, enable_once_command
,
7429 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7430 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7433 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7434 "Disable some breakpoints.\n\
7435 Arguments are breakpoint numbers with spaces in between.\n\
7436 To disable all breakpoints, give no argument.\n\
7437 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7438 &disablelist
, "disable ", 1, &cmdlist
);
7439 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7440 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7442 add_com ("sb", class_breakpoint
, disable_command
,
7443 "Disable some breakpoints.\n\
7444 Arguments are breakpoint numbers with spaces in between.\n\
7445 To disable all breakpoints, give no argument.\n\
7446 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7448 add_cmd ("breakpoints", class_alias
, disable_command
,
7449 "Disable some breakpoints.\n\
7450 Arguments are breakpoint numbers with spaces in between.\n\
7451 To disable all breakpoints, give no argument.\n\
7452 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7453 This command may be abbreviated \"disable\".",
7456 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7457 "Delete some breakpoints or auto-display expressions.\n\
7458 Arguments are breakpoint numbers with spaces in between.\n\
7459 To delete all breakpoints, give no argument.\n\
7461 Also a prefix command for deletion of other GDB objects.\n\
7462 The \"unset\" command is also an alias for \"delete\".",
7463 &deletelist
, "delete ", 1, &cmdlist
);
7464 add_com_alias ("d", "delete", class_breakpoint
, 1);
7466 add_com ("db", class_breakpoint
, delete_command
,
7467 "Delete some breakpoints.\n\
7468 Arguments are breakpoint numbers with spaces in between.\n\
7469 To delete all breakpoints, give no argument.\n");
7471 add_cmd ("breakpoints", class_alias
, delete_command
,
7472 "Delete some breakpoints or auto-display expressions.\n\
7473 Arguments are breakpoint numbers with spaces in between.\n\
7474 To delete all breakpoints, give no argument.\n\
7475 This command may be abbreviated \"delete\".",
7478 add_com ("clear", class_breakpoint
, clear_command
,
7479 concat ("Clear breakpoint at specified line or function.\n\
7480 Argument may be line number, function name, or \"*\" and an address.\n\
7481 If line number is specified, all breakpoints in that line are cleared.\n\
7482 If function is specified, breakpoints at beginning of function are cleared.\n\
7483 If an address is specified, breakpoints at that address are cleared.\n\n",
7484 "With no argument, clears all breakpoints in the line that the selected frame\n\
7487 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7489 c
= add_com ("break", class_breakpoint
, break_command
,
7490 concat ("Set breakpoint at specified line or function.\n\
7491 Argument may be line number, function name, or \"*\" and an address.\n\
7492 If line number is specified, break at start of code for that line.\n\
7493 If function is specified, break at start of code for that function.\n\
7494 If an address is specified, break at that exact address.\n",
7495 "With no arg, uses current execution address of selected stack frame.\n\
7496 This is useful for breaking on return to a stack frame.\n\
7498 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7500 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7501 set_cmd_completer (c
, location_completer
);
7503 add_com_alias ("b", "break", class_run
, 1);
7504 add_com_alias ("br", "break", class_run
, 1);
7505 add_com_alias ("bre", "break", class_run
, 1);
7506 add_com_alias ("brea", "break", class_run
, 1);
7510 add_com_alias ("ba", "break", class_breakpoint
, 1);
7511 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7516 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7517 "Break in function/address or break at a line in the current file.",
7518 &stoplist
, "stop ", 1, &cmdlist
);
7519 add_cmd ("in", class_breakpoint
, stopin_command
,
7520 "Break in function or address.\n", &stoplist
);
7521 add_cmd ("at", class_breakpoint
, stopat_command
,
7522 "Break at a line in the current file.\n", &stoplist
);
7523 add_com ("status", class_info
, breakpoints_info
,
7524 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7525 The \"Type\" column indicates one of:\n\
7526 \tbreakpoint - normal breakpoint\n\
7527 \twatchpoint - watchpoint\n\
7528 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7529 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7530 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7531 address and file/line number respectively.\n\n",
7532 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7533 are set to the address of the last breakpoint listed.\n\n\
7534 Convenience variable \"$bpnum\" contains the number of the last\n\
7535 breakpoint set.", NULL
));
7538 add_info ("breakpoints", breakpoints_info
,
7539 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7540 The \"Type\" column indicates one of:\n\
7541 \tbreakpoint - normal breakpoint\n\
7542 \twatchpoint - watchpoint\n\
7543 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7544 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7545 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7546 address and file/line number respectively.\n\n",
7547 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7548 are set to the address of the last breakpoint listed.\n\n\
7549 Convenience variable \"$bpnum\" contains the number of the last\n\
7550 breakpoint set.", NULL
));
7553 add_com ("lb", class_breakpoint
, breakpoints_info
,
7554 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7555 The \"Type\" column indicates one of:\n\
7556 \tbreakpoint - normal breakpoint\n\
7557 \twatchpoint - watchpoint\n\
7558 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7559 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7560 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7561 address and file/line number respectively.\n\n",
7562 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7563 are set to the address of the last breakpoint listed.\n\n\
7564 Convenience variable \"$bpnum\" contains the number of the last\n\
7565 breakpoint set.", NULL
));
7567 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7568 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7569 The \"Type\" column indicates one of:\n\
7570 \tbreakpoint - normal breakpoint\n\
7571 \twatchpoint - watchpoint\n\
7572 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7573 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7574 \tuntil - internal breakpoint used by the \"until\" command\n\
7575 \tfinish - internal breakpoint used by the \"finish\" command\n",
7576 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7577 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7578 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7579 address and file/line number respectively.\n\n",
7580 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7581 are set to the address of the last breakpoint listed.\n\n\
7582 Convenience variable \"$bpnum\" contains the number of the last\n\
7583 breakpoint set.", NULL
),
7584 &maintenanceinfolist
);
7586 add_com ("catch", class_breakpoint
, catch_command
,
7587 "Set catchpoints to catch events.\n\
7588 Raised signals may be caught:\n\
7589 \tcatch signal - all signals\n\
7590 \tcatch signal <signame> - a particular signal\n\
7591 Raised exceptions may be caught:\n\
7592 \tcatch throw - all exceptions, when thrown\n\
7593 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7594 \tcatch catch - all exceptions, when caught\n\
7595 \tcatch catch <exceptname> - a particular exception, when caught\n\
7596 Thread or process events may be caught:\n\
7597 \tcatch thread_start - any threads, just after creation\n\
7598 \tcatch thread_exit - any threads, just before expiration\n\
7599 \tcatch thread_join - any threads, just after joins\n\
7600 Process events may be caught:\n\
7601 \tcatch start - any processes, just after creation\n\
7602 \tcatch exit - any processes, just before expiration\n\
7603 \tcatch fork - calls to fork()\n\
7604 \tcatch vfork - calls to vfork()\n\
7605 \tcatch exec - calls to exec()\n\
7606 Dynamically-linked library events may be caught:\n\
7607 \tcatch load - loads of any library\n\
7608 \tcatch load <libname> - loads of a particular library\n\
7609 \tcatch unload - unloads of any library\n\
7610 \tcatch unload <libname> - unloads of a particular library\n\
7611 The act of your program's execution stopping may also be caught:\n\
7613 C++ exceptions may be caught:\n\
7614 \tcatch throw - all exceptions, when thrown\n\
7615 \tcatch catch - all exceptions, when caught\n\
7617 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7618 after a fork or vfork is caught.\n\n\
7619 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7621 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7622 "Set temporary catchpoints to catch events.\n\
7623 Args like \"catch\" command.\n\
7624 Like \"catch\" except the catchpoint is only temporary,\n\
7625 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7626 by using \"enable delete\" on the catchpoint number.");
7628 c
= add_com ("watch", class_breakpoint
, watch_command
,
7629 "Set a watchpoint for an expression.\n\
7630 A watchpoint stops execution of your program whenever the value of\n\
7631 an expression changes.");
7632 set_cmd_completer (c
, location_completer
);
7634 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7635 "Set a read watchpoint for an expression.\n\
7636 A watchpoint stops execution of your program whenever the value of\n\
7637 an expression is read.");
7638 set_cmd_completer (c
, location_completer
);
7640 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7641 "Set a watchpoint for an expression.\n\
7642 A watchpoint stops execution of your program whenever the value of\n\
7643 an expression is either read or written.");
7644 set_cmd_completer (c
, location_completer
);
7646 add_info ("watchpoints", breakpoints_info
,
7647 "Synonym for ``info breakpoints''.");
7650 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7651 (char *) &can_use_hw_watchpoints
,
7652 "Set debugger's willingness to use watchpoint hardware.\n\
7653 If zero, gdb will not use hardware for new watchpoints, even if\n\
7654 such is available. (However, any hardware watchpoints that were\n\
7655 created before setting this to nonzero, will continue to use watchpoint\n\
7658 add_show_from_set (c
, &showlist
);
7660 can_use_hw_watchpoints
= 1;