1 /* Everything about breakpoints, for GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "breakpoint.h"
30 #include "expression.h"
36 #include "gdbthread.h"
39 #include "gdb_string.h"
46 #include "completer.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
53 #include "gdb-events.h"
55 /* Prototypes for local functions. */
57 static void until_break_command_continuation (struct continuation_arg
*arg
);
59 static void catch_command_1 (char *, int, int);
61 static void enable_delete_command (char *, int);
63 static void enable_delete_breakpoint (struct breakpoint
*);
65 static void enable_once_command (char *, int);
67 static void enable_once_breakpoint (struct breakpoint
*);
69 static void disable_command (char *, int);
71 static void enable_command (char *, int);
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
75 static void ignore_command (char *, int);
77 static int breakpoint_re_set_one (void *);
79 static void clear_command (char *, int);
81 static void catch_command (char *, int);
83 static void watch_command (char *, int);
85 static int can_use_hardware_watchpoint (struct value
*);
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
90 extern void tbreak_at_finish_command (char *, int);
92 static void break_command_1 (char *, int, int);
94 static void mention (struct breakpoint
*);
96 struct breakpoint
*set_raw_breakpoint (struct symtab_and_line
, enum bptype
);
98 static void check_duplicates (struct breakpoint
*);
100 static void describe_other_breakpoints (CORE_ADDR
, asection
*);
102 static void breakpoints_info (char *, int);
104 static void breakpoint_1 (int, int);
106 static bpstat
bpstat_alloc (struct breakpoint
*, bpstat
);
108 static int breakpoint_cond_eval (void *);
110 static void cleanup_executing_breakpoints (void *);
112 static void commands_command (char *, int);
114 static void condition_command (char *, int);
116 static int get_number_trailer (char **, int);
118 void set_breakpoint_count (int);
127 static int remove_breakpoint (struct breakpoint
*, insertion_state_t
);
129 static enum print_stop_action
print_it_typical (bpstat
);
131 static enum print_stop_action
print_bp_stop_message (bpstat bs
);
135 enum exception_event_kind kind
;
138 args_for_catchpoint_enable
;
140 static int watchpoint_check (void *);
142 static int cover_target_enable_exception_callback (void *);
144 static void maintenance_info_breakpoints (char *, int);
146 static void create_longjmp_breakpoint (char *);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype
, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
166 static void solib_load_unload_1 (char *hookname
,
169 char *cond_string
, enum bptype bp_kind
);
171 static void create_fork_vfork_event_catchpoint (int tempflag
,
173 enum bptype bp_kind
);
175 static void break_at_finish_at_depth_command_1 (char *arg
,
176 int flag
, int from_tty
);
178 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
180 static void stop_command (char *arg
, int from_tty
);
182 static void stopin_command (char *arg
, int from_tty
);
184 static void stopat_command (char *arg
, int from_tty
);
186 static char *ep_find_event_name_end (char *arg
);
188 static char *ep_parse_optional_if_clause (char **arg
);
190 static char *ep_parse_optional_filename (char **arg
);
192 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
196 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
197 enum exception_event_kind ex_event
,
198 struct symtab_and_line
*sal
);
200 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
201 char *arg
, int tempflag
, int from_tty
);
203 static void tcatch_command (char *arg
, int from_tty
);
205 static void ep_skip_leading_whitespace (char **s
);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints
;
213 void _initialize_breakpoint (void);
215 extern int addressprint
; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands
;
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled
;
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
234 /* True if SHIFT_INST_REGS defined, false otherwise. */
236 int must_shift_inst_regs
=
237 #if defined(SHIFT_INST_REGS)
244 /* True if breakpoint hit counts should be displayed in breakpoint info. */
246 int show_breakpoint_hit_counts
= 1;
248 /* Chain of all breakpoints defined. */
250 struct breakpoint
*breakpoint_chain
;
252 /* Number of last breakpoint made. */
254 int breakpoint_count
;
256 /* Pointer to current exception event record */
257 static struct exception_event_record
*current_exception_event
;
259 /* Indicator of whether exception catchpoints should be nuked
260 between runs of a program */
261 int exception_catchpoints_are_fragile
= 0;
263 /* Indicator of when exception catchpoints set-up should be
264 reinitialized -- e.g. when program is re-run */
265 int exception_support_initialized
= 0;
267 /* This function returns a pointer to the string representation of the
268 pathname of the dynamically-linked library that has just been
271 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
272 or undefined results are guaranteed.
274 This string's contents are only valid immediately after the
275 inferior has stopped in the dynamic linker hook, and becomes
276 invalid as soon as the inferior is continued. Clients should make
277 a copy of this string if they wish to continue the inferior and
278 then access the string. */
280 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
281 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
284 /* This function returns a pointer to the string representation of the
285 pathname of the dynamically-linked library that has just been
288 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
289 TRUE, or undefined results are guaranteed.
291 This string's contents are only valid immediately after the
292 inferior has stopped in the dynamic linker hook, and becomes
293 invalid as soon as the inferior is continued. Clients should make
294 a copy of this string if they wish to continue the inferior and
295 then access the string. */
297 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
298 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
301 /* This function is called by the "catch load" command. It allows the
302 debugger to be notified by the dynamic linker when a specified
303 library file (or any library file, if filename is NULL) is loaded. */
305 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
306 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
307 error ("catch of library loads not yet implemented on this platform")
310 /* This function is called by the "catch unload" command. It allows
311 the debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is
315 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
316 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library unloads not yet implemented on this platform")
320 /* Set breakpoint count to NUM. */
323 set_breakpoint_count (int num
)
325 breakpoint_count
= num
;
326 set_internalvar (lookup_internalvar ("bpnum"),
327 value_from_longest (builtin_type_int
, (LONGEST
) num
));
330 /* Used in run_command to zero the hit count when a new run starts. */
333 clear_breakpoint_hit_counts (void)
335 struct breakpoint
*b
;
341 /* Default address, symtab and line to put a breakpoint at
342 for "break" command with no arg.
343 if default_breakpoint_valid is zero, the other three are
344 not valid, and "break" with no arg is an error.
346 This set by print_stack_frame, which calls set_default_breakpoint. */
348 int default_breakpoint_valid
;
349 CORE_ADDR default_breakpoint_address
;
350 struct symtab
*default_breakpoint_symtab
;
351 int default_breakpoint_line
;
353 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
354 Advance *PP after the string and any trailing whitespace.
356 Currently the string can either be a number or "$" followed by the name
357 of a convenience variable. Making it an expression wouldn't work well
358 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
360 TRAILER is a character which can be found after the number; most
361 commonly this is `-'. If you don't want a trailer, use \0. */
363 get_number_trailer (char **pp
, int trailer
)
365 int retval
= 0; /* default */
369 /* Empty line means refer to the last breakpoint. */
370 return breakpoint_count
;
373 /* Make a copy of the name, so we can null-terminate it
374 to pass to lookup_internalvar(). */
379 while (isalnum (*p
) || *p
== '_')
381 varname
= (char *) alloca (p
- start
+ 1);
382 strncpy (varname
, start
, p
- start
);
383 varname
[p
- start
] = '\0';
384 val
= value_of_internalvar (lookup_internalvar (varname
));
385 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
386 retval
= (int) value_as_long (val
);
389 printf_filtered ("Convenience variable must have integer value.\n");
397 while (*p
>= '0' && *p
<= '9')
400 /* There is no number here. (e.g. "cond a == b"). */
402 /* Skip non-numeric token */
403 while (*p
&& !isspace((int) *p
))
405 /* Return zero, which caller must interpret as error. */
411 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
413 /* Trailing junk: return 0 and let caller print error msg. */
414 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
425 /* Like get_number_trailer, but don't allow a trailer. */
427 get_number (char **pp
)
429 return get_number_trailer (pp
, '\0');
432 /* Parse a number or a range.
433 * A number will be of the form handled by get_number.
434 * A range will be of the form <number1> - <number2>, and
435 * will represent all the integers between number1 and number2,
438 * While processing a range, this fuction is called iteratively;
439 * At each call it will return the next value in the range.
441 * At the beginning of parsing a range, the char pointer PP will
442 * be advanced past <number1> and left pointing at the '-' token.
443 * Subsequent calls will not advance the pointer until the range
444 * is completed. The call that completes the range will advance
445 * pointer PP past <number2>.
449 get_number_or_range (char **pp
)
451 static int last_retval
, end_value
;
452 static char *end_ptr
;
453 static int in_range
= 0;
457 /* Default case: pp is pointing either to a solo number,
458 or to the first number of a range. */
459 last_retval
= get_number_trailer (pp
, '-');
464 /* This is the start of a range (<number1> - <number2>).
465 Skip the '-', parse and remember the second number,
466 and also remember the end of the final token. */
470 while (isspace ((int) *end_ptr
))
471 end_ptr
++; /* skip white space */
472 end_value
= get_number (temp
);
473 if (end_value
< last_retval
)
475 error ("inverted range");
477 else if (end_value
== last_retval
)
479 /* degenerate range (number1 == number2). Advance the
480 token pointer so that the range will be treated as a
489 error ("negative value");
492 /* pp points to the '-' that betokens a range. All
493 number-parsing has already been done. Return the next
494 integer value (one greater than the saved previous value).
495 Do not advance the token pointer 'pp' until the end of range
498 if (++last_retval
== end_value
)
500 /* End of range reached; advance token pointer. */
510 /* condition N EXP -- set break condition of breakpoint N to EXP. */
513 condition_command (char *arg
, int from_tty
)
515 register struct breakpoint
*b
;
520 error_no_arg ("breakpoint number");
523 bnum
= get_number (&p
);
525 error ("Bad breakpoint argument: '%s'", arg
);
528 if (b
->number
== bnum
)
535 if (b
->cond_string
!= NULL
)
536 xfree (b
->cond_string
);
541 b
->cond_string
= NULL
;
543 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
548 /* I don't know if it matters whether this is the string the user
549 typed in or the decompiled expression. */
550 b
->cond_string
= savestring (arg
, strlen (arg
));
551 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
553 error ("Junk at end of expression");
555 breakpoints_changed ();
556 breakpoint_modify_event (b
->number
);
560 error ("No breakpoint number %d.", bnum
);
565 commands_command (char *arg
, int from_tty
)
567 register struct breakpoint
*b
;
570 struct command_line
*l
;
572 /* If we allowed this, we would have problems with when to
573 free the storage, if we change the commands currently
576 if (executing_breakpoint_commands
)
577 error ("Can't use the \"commands\" command among a breakpoint's commands.");
580 bnum
= get_number (&p
);
583 error ("Unexpected extra arguments following breakpoint number.");
586 if (b
->number
== bnum
)
588 char *tmpbuf
= xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
590 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
591 l
= read_command_lines (tmpbuf
, from_tty
);
592 do_cleanups (cleanups
);
593 free_command_lines (&b
->commands
);
595 breakpoints_changed ();
596 breakpoint_modify_event (b
->number
);
599 error ("No breakpoint number %d.", bnum
);
602 /* Like target_read_memory() but if breakpoints are inserted, return
603 the shadow contents instead of the breakpoints themselves.
605 Read "memory data" from whatever target or inferior we have.
606 Returns zero if successful, errno value if not. EIO is used
607 for address out of bounds. If breakpoints are inserted, returns
608 shadow contents, not the breakpoints themselves. From breakpoint.c. */
611 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
614 struct breakpoint
*b
;
615 CORE_ADDR bp_addr
= 0;
618 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
619 /* No breakpoints on this machine. */
620 return target_read_memory (memaddr
, myaddr
, len
);
624 if (b
->type
== bp_none
)
625 warning ("reading through apparently deleted breakpoint #%d?",
628 /* memory breakpoint? */
629 if (b
->type
== bp_watchpoint
630 || b
->type
== bp_hardware_watchpoint
631 || b
->type
== bp_read_watchpoint
632 || b
->type
== bp_access_watchpoint
)
637 /* Addresses and length of the part of the breakpoint that
639 /* XXXX The m68k, sh and h8300 have different local and remote
640 breakpoint values. BREAKPOINT_FROM_PC still manages to
641 correctly determine the breakpoints memory address and size
642 for these targets. */
643 bp_addr
= b
->address
;
645 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
650 if (bp_addr
+ bp_size
<= memaddr
)
651 /* The breakpoint is entirely before the chunk of memory we
654 if (bp_addr
>= memaddr
+ len
)
655 /* The breakpoint is entirely after the chunk of memory we are
658 /* Copy the breakpoint from the shadow contents, and recurse for
659 the things before and after. */
661 /* Offset within shadow_contents. */
664 if (bp_addr
< memaddr
)
666 /* Only copy the second part of the breakpoint. */
667 bp_size
-= memaddr
- bp_addr
;
668 bptoffset
= memaddr
- bp_addr
;
672 if (bp_addr
+ bp_size
> memaddr
+ len
)
674 /* Only copy the first part of the breakpoint. */
675 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
678 memcpy (myaddr
+ bp_addr
- memaddr
,
679 b
->shadow_contents
+ bptoffset
, bp_size
);
681 if (bp_addr
> memaddr
)
683 /* Copy the section of memory before the breakpoint. */
684 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
689 if (bp_addr
+ bp_size
< memaddr
+ len
)
691 /* Copy the section of memory after the breakpoint. */
692 status
= read_memory_nobpt (bp_addr
+ bp_size
,
693 myaddr
+ bp_addr
+ bp_size
- memaddr
,
694 memaddr
+ len
- (bp_addr
+ bp_size
));
701 /* Nothing overlaps. Just call read_memory_noerr. */
702 return target_read_memory (memaddr
, myaddr
, len
);
706 /* A wrapper function for inserting catchpoints. */
708 insert_catchpoint (struct ui_out
*uo
, void *args
)
710 struct breakpoint
*b
= (struct breakpoint
*) args
;
716 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
719 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
722 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
725 internal_error (__FILE__
, __LINE__
, "unknown breakpoint type");
730 throw_exception (RETURN_ERROR
);
735 /* insert_breakpoints is used when starting or continuing the program.
736 remove_breakpoints is used when the program stops.
737 Both return zero if successful,
738 or an `errno' value if could not write the inferior. */
741 insert_breakpoints (void)
743 register struct breakpoint
*b
, *temp
;
744 int return_val
= 0; /* return success code. */
746 int disabled_breaks
= 0;
747 int hw_breakpoint_error
= 0;
748 #ifdef ONE_PROCESS_WRITETEXT
749 int process_warning
= 0;
752 struct ui_file
*tmp_error_stream
= mem_fileopen ();
753 make_cleanup_ui_file_delete (tmp_error_stream
);
755 /* Explicitly mark the warning -- this will only be printed if
756 there was an error. */
757 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
759 ALL_BREAKPOINTS_SAFE (b
, temp
)
761 /* Permanent breakpoints cannot be inserted or removed. Disabled
762 breakpoints should not be inserted. */
763 if (b
->enable_state
!= bp_enabled
)
766 if ((b
->type
== bp_watchpoint
767 || b
->type
== bp_hardware_watchpoint
768 || b
->type
== bp_read_watchpoint
769 || b
->type
== bp_access_watchpoint
) && (!b
->val
))
772 val
= evaluate_expression (b
->exp
);
774 if (VALUE_LAZY (val
))
775 value_fetch_lazy (val
);
778 if (b
->type
!= bp_watchpoint
779 && b
->type
!= bp_hardware_watchpoint
780 && b
->type
!= bp_read_watchpoint
781 && b
->type
!= bp_access_watchpoint
782 && b
->type
!= bp_catch_fork
783 && b
->type
!= bp_catch_vfork
784 && b
->type
!= bp_catch_exec
785 && b
->type
!= bp_catch_throw
786 && b
->type
!= bp_catch_catch
790 /* "Normal" instruction breakpoint: either the standard
791 trap-instruction bp (bp_breakpoint), or a
792 bp_hardware_breakpoint. */
794 /* First check to see if we have to handle an overlay. */
795 if (overlay_debugging
== ovly_off
796 || b
->section
== NULL
797 || !(section_is_overlay (b
->section
)))
799 /* No overlay handling: just set the breakpoint. */
801 if (b
->type
== bp_hardware_breakpoint
)
802 val
= target_insert_hw_breakpoint (b
->address
,
805 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
809 /* This breakpoint is in an overlay section.
810 Shall we set a breakpoint at the LMA? */
811 if (!overlay_events_enabled
)
813 /* Yes -- overlay event support is not active,
814 so we must try to set a breakpoint at the LMA.
815 This will not work for a hardware breakpoint. */
816 if (b
->type
== bp_hardware_breakpoint
)
817 warning ("hardware breakpoint %d not supported in overlay!\n",
821 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
823 /* Set a software (trap) breakpoint at the LMA. */
824 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
826 fprintf_unfiltered (tmp_error_stream
,
827 "Overlay breakpoint %d failed: in ROM?",
831 /* Shall we set a breakpoint at the VMA? */
832 if (section_is_mapped (b
->section
))
834 /* Yes. This overlay section is mapped into memory. */
835 if (b
->type
== bp_hardware_breakpoint
)
836 val
= target_insert_hw_breakpoint (b
->address
,
839 val
= target_insert_breakpoint (b
->address
,
844 /* No. This breakpoint will not be inserted.
845 No error, but do not mark the bp as 'inserted'. */
852 /* Can't set the breakpoint. */
853 #if defined (DISABLE_UNSETTABLE_BREAK)
854 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
856 /* See also: disable_breakpoints_in_shlibs. */
858 b
->enable_state
= bp_shlib_disabled
;
859 if (!disabled_breaks
)
861 fprintf_unfiltered (tmp_error_stream
,
862 "Cannot insert breakpoint %d.\n",
864 fprintf_unfiltered (tmp_error_stream
,
865 "Temporarily disabling shared library breakpoints:\n");
868 fprintf_unfiltered (tmp_error_stream
,
869 "breakpoint #%d\n", b
->number
);
874 #ifdef ONE_PROCESS_WRITETEXT
877 if (b
->type
== bp_hardware_breakpoint
)
879 hw_breakpoint_error
= 1;
880 fprintf_unfiltered (tmp_error_stream
,
881 "Cannot insert hardware breakpoint %d.\n",
886 fprintf_unfiltered (tmp_error_stream
,
887 "Cannot insert breakpoint %d.\n",
889 fprintf_filtered (tmp_error_stream
,
890 "Error accessing memory address ");
891 print_address_numeric (b
->address
, 1, tmp_error_stream
);
892 fprintf_filtered (tmp_error_stream
, ": %s.\n",
893 safe_strerror (val
));
902 return_val
= val
; /* remember failure */
904 else if (ep_is_exception_catchpoint (b
)
909 /* If we get here, we must have a callback mechanism for exception
910 events -- with g++ style embedded label support, we insert
911 ordinary breakpoints and not catchpoints. */
912 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
915 /* Couldn't set breakpoint for some reason */
916 fprintf_unfiltered (tmp_error_stream
,
917 "Cannot insert catchpoint %d; disabling it.\n",
919 fprintf_filtered (tmp_error_stream
,
920 "Error accessing memory address ");
921 print_address_numeric (b
->address
, 1, tmp_error_stream
);
922 fprintf_filtered (tmp_error_stream
, ": %s.\n",
923 safe_strerror (val
));
924 b
->enable_state
= bp_disabled
;
928 /* Bp set, now make sure callbacks are enabled */
929 /* Format possible error msg */
930 char *message
= xstrprintf ("Error inserting catchpoint %d:\n",
932 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
934 args_for_catchpoint_enable args
;
935 args
.kind
= b
->type
== bp_catch_catch
?
936 EX_EVENT_CATCH
: EX_EVENT_THROW
;
938 val
= catch_errors (cover_target_enable_exception_callback
,
939 &args
, message
, RETURN_MASK_ALL
);
940 do_cleanups (cleanups
);
941 if (val
!= 0 && val
!= -1)
945 /* Check if something went wrong; val == 0 can be ignored */
948 /* something went wrong */
949 fprintf_unfiltered (tmp_error_stream
,
950 "Cannot insert catchpoint %d; disabling it.\n",
952 b
->enable_state
= bp_disabled
;
957 return_val
= val
; /* remember failure */
960 else if ((b
->type
== bp_hardware_watchpoint
||
961 b
->type
== bp_read_watchpoint
||
962 b
->type
== bp_access_watchpoint
)
963 && b
->disposition
!= disp_del_at_next_stop
967 struct frame_info
*saved_frame
;
968 int saved_level
, within_current_scope
;
969 struct value
*mark
= value_mark ();
972 /* Save the current frame and level so we can restore it after
973 evaluating the watchpoint expression on its own frame. */
974 saved_frame
= deprecated_selected_frame
;
975 saved_level
= frame_relative_level (deprecated_selected_frame
);
977 /* Determine if the watchpoint is within scope. */
978 if (b
->exp_valid_block
== NULL
)
979 within_current_scope
= 1;
982 struct frame_info
*fi
;
983 fi
= frame_find_by_id (b
->watchpoint_frame
);
984 within_current_scope
= (fi
!= NULL
);
985 if (within_current_scope
)
989 if (within_current_scope
)
991 /* Evaluate the expression and cut the chain of values
992 produced off from the value chain.
994 Make sure the value returned isn't lazy; we use
995 laziness to determine what memory GDB actually needed
996 in order to compute the value of the expression. */
997 v
= evaluate_expression (b
->exp
);
999 value_release_to_mark (mark
);
1004 /* Look at each value on the value chain. */
1005 for (; v
; v
= v
->next
)
1007 /* If it's a memory location, and GDB actually needed
1008 its contents to evaluate the expression, then we
1010 if (VALUE_LVAL (v
) == lval_memory
1011 && ! VALUE_LAZY (v
))
1013 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1015 /* We only watch structs and arrays if user asked
1016 for it explicitly, never if they just happen to
1017 appear in the middle of some value chain. */
1018 if (v
== b
->val_chain
1019 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1020 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1025 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1026 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1028 if (b
->type
== bp_read_watchpoint
)
1030 else if (b
->type
== bp_access_watchpoint
)
1033 val
= target_insert_watchpoint (addr
, len
, type
);
1036 /* Don't exit the loop, try to insert
1037 every value on the value chain. That's
1038 because we will be removing all the
1039 watches below, and removing a
1040 watchpoint we didn't insert could have
1048 /* Failure to insert a watchpoint on any memory value in the
1049 value chain brings us here. */
1052 remove_breakpoint (b
, mark_uninserted
);
1053 hw_breakpoint_error
= 1;
1054 fprintf_unfiltered (tmp_error_stream
,
1055 "Could not insert hardware watchpoint %d.\n",
1062 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
1063 printf_filtered ("because the program has left the block \n");
1064 printf_filtered ("in which its expression is valid.\n");
1065 if (b
->related_breakpoint
)
1066 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1067 b
->disposition
= disp_del_at_next_stop
;
1070 /* Restore the frame and level. */
1071 if ((saved_frame
!= deprecated_selected_frame
) ||
1072 (saved_level
!= frame_relative_level (deprecated_selected_frame
)))
1073 select_frame (saved_frame
);
1076 return_val
= val
; /* remember failure */
1078 else if ((b
->type
== bp_catch_fork
1079 || b
->type
== bp_catch_vfork
1080 || b
->type
== bp_catch_exec
)
1084 char *prefix
= xstrprintf ("warning: inserting catchpoint %d: ",
1086 struct cleanup
*cleanups
= make_cleanup (xfree
, prefix
);
1087 val
= catch_exceptions (uiout
, insert_catchpoint
, b
, prefix
,
1089 do_cleanups (cleanups
);
1091 b
->enable_state
= bp_disabled
;
1099 /* If a hardware breakpoint or watchpoint was inserted, add a
1100 message about possibly exhausted resources. */
1101 if (hw_breakpoint_error
)
1103 fprintf_unfiltered (tmp_error_stream
,
1104 "Could not insert hardware breakpoints:\n\
1105 You may have requested too many hardware breakpoints/watchpoints.\n");
1107 #ifdef ONE_PROCESS_WRITETEXT
1108 if (process_warning
)
1109 fprintf_unfiltered (tmp_error_stream
,
1110 "The same program may be running in another process.");
1112 target_terminal_ours_for_output ();
1113 error_stream (tmp_error_stream
);
1119 remove_breakpoints (void)
1121 register struct breakpoint
*b
;
1128 val
= remove_breakpoint (b
, mark_uninserted
);
1137 remove_hw_watchpoints (void)
1139 register struct breakpoint
*b
;
1145 && (b
->type
== bp_hardware_watchpoint
1146 || b
->type
== bp_read_watchpoint
1147 || b
->type
== bp_access_watchpoint
))
1149 val
= remove_breakpoint (b
, mark_uninserted
);
1158 reattach_breakpoints (int pid
)
1160 register struct breakpoint
*b
;
1162 struct cleanup
*old_chain
= save_inferior_ptid ();
1164 /* Set inferior_ptid; remove_breakpoint uses this global. */
1165 inferior_ptid
= pid_to_ptid (pid
);
1170 remove_breakpoint (b
, mark_inserted
);
1171 if (b
->type
== bp_hardware_breakpoint
)
1172 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1174 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1177 do_cleanups (old_chain
);
1182 do_cleanups (old_chain
);
1187 update_breakpoints_after_exec (void)
1189 struct breakpoint
*b
;
1190 struct breakpoint
*temp
;
1192 /* Doing this first prevents the badness of having delete_breakpoint()
1193 write a breakpoint's current "shadow contents" to lift the bp. That
1194 shadow is NOT valid after an exec()! */
1195 mark_breakpoints_out ();
1197 ALL_BREAKPOINTS_SAFE (b
, temp
)
1199 /* Solib breakpoints must be explicitly reset after an exec(). */
1200 if (b
->type
== bp_shlib_event
)
1202 delete_breakpoint (b
);
1206 /* Thread event breakpoints must be set anew after an exec(),
1207 as must overlay event breakpoints. */
1208 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1210 delete_breakpoint (b
);
1214 /* Step-resume breakpoints are meaningless after an exec(). */
1215 if (b
->type
== bp_step_resume
)
1217 delete_breakpoint (b
);
1221 /* Ditto the sigtramp handler breakpoints. */
1222 if (b
->type
== bp_through_sigtramp
)
1224 delete_breakpoint (b
);
1228 /* Ditto the exception-handling catchpoints. */
1229 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1231 delete_breakpoint (b
);
1235 /* Don't delete an exec catchpoint, because else the inferior
1236 won't stop when it ought!
1238 Similarly, we probably ought to keep vfork catchpoints, 'cause
1239 on this target, we may not be able to stop when the vfork is
1240 seen, but only when the subsequent exec is seen. (And because
1241 deleting fork catchpoints here but not vfork catchpoints will
1242 seem mysterious to users, keep those too.)
1244 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1245 target address field, if any, is sufficient to have it be reset
1246 automagically. Certainly on HP-UX that's true.
1248 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1249 valid code address on some platforms (like the OBSOLETE mn10200
1250 and mn10300 simulators). We shouldn't assign any special
1251 interpretation to a breakpoint with a zero address. And in
1252 fact, GDB doesn't --- I can't see what that comment above is
1253 talking about. As far as I can tell, setting the address of a
1254 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1255 is meaningless, since those are implemented with HP-UX kernel
1256 hackery, not by storing breakpoint instructions somewhere. */
1257 if ((b
->type
== bp_catch_exec
) ||
1258 (b
->type
== bp_catch_vfork
) ||
1259 (b
->type
== bp_catch_fork
))
1261 b
->address
= (CORE_ADDR
) NULL
;
1265 /* bp_finish is a special case. The only way we ought to be able
1266 to see one of these when an exec() has happened, is if the user
1267 caught a vfork, and then said "finish". Ordinarily a finish just
1268 carries them to the call-site of the current callee, by setting
1269 a temporary bp there and resuming. But in this case, the finish
1270 will carry them entirely through the vfork & exec.
1272 We don't want to allow a bp_finish to remain inserted now. But
1273 we can't safely delete it, 'cause finish_command has a handle to
1274 the bp on a bpstat, and will later want to delete it. There's a
1275 chance (and I've seen it happen) that if we delete the bp_finish
1276 here, that its storage will get reused by the time finish_command
1277 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1278 We really must allow finish_command to delete a bp_finish.
1280 In the absense of a general solution for the "how do we know
1281 it's safe to delete something others may have handles to?"
1282 problem, what we'll do here is just uninsert the bp_finish, and
1283 let finish_command delete it.
1285 (We know the bp_finish is "doomed" in the sense that it's
1286 momentary, and will be deleted as soon as finish_command sees
1287 the inferior stopped. So it doesn't matter that the bp's
1288 address is probably bogus in the new a.out, unlike e.g., the
1289 solib breakpoints.) */
1291 if (b
->type
== bp_finish
)
1296 /* Without a symbolic address, we have little hope of the
1297 pre-exec() address meaning the same thing in the post-exec()
1299 if (b
->addr_string
== NULL
)
1301 delete_breakpoint (b
);
1305 /* If this breakpoint has survived the above battery of checks, then
1306 it must have a symbolic address. Be sure that it gets reevaluated
1307 to a target address, rather than reusing the old evaluation.
1309 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1310 for bp_catch_exec and friends, I'm pretty sure this is entirely
1311 unnecessary. A call to breakpoint_re_set_one always recomputes
1312 the breakpoint's address from scratch, or deletes it if it can't.
1313 So I think this assignment could be deleted without effect. */
1314 b
->address
= (CORE_ADDR
) NULL
;
1316 /* FIXME what about longjmp breakpoints? Re-create them here? */
1317 create_overlay_event_breakpoint ("_ovly_debug_event");
1321 detach_breakpoints (int pid
)
1323 register struct breakpoint
*b
;
1325 struct cleanup
*old_chain
= save_inferior_ptid ();
1327 if (pid
== PIDGET (inferior_ptid
))
1328 error ("Cannot detach breakpoints of inferior_ptid");
1330 /* Set inferior_ptid; remove_breakpoint uses this global. */
1331 inferior_ptid
= pid_to_ptid (pid
);
1336 val
= remove_breakpoint (b
, mark_inserted
);
1339 do_cleanups (old_chain
);
1344 do_cleanups (old_chain
);
1349 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1353 if (b
->enable_state
== bp_permanent
)
1354 /* Permanent breakpoints cannot be inserted or removed. */
1357 if (b
->type
== bp_none
)
1358 warning ("attempted to remove apparently deleted breakpoint #%d?",
1361 if (b
->type
!= bp_watchpoint
1362 && b
->type
!= bp_hardware_watchpoint
1363 && b
->type
!= bp_read_watchpoint
1364 && b
->type
!= bp_access_watchpoint
1365 && b
->type
!= bp_catch_fork
1366 && b
->type
!= bp_catch_vfork
1367 && b
->type
!= bp_catch_exec
1368 && b
->type
!= bp_catch_catch
1369 && b
->type
!= bp_catch_throw
)
1371 /* "Normal" instruction breakpoint: either the standard
1372 trap-instruction bp (bp_breakpoint), or a
1373 bp_hardware_breakpoint. */
1375 /* First check to see if we have to handle an overlay. */
1376 if (overlay_debugging
== ovly_off
1377 || b
->section
== NULL
1378 || !(section_is_overlay (b
->section
)))
1380 /* No overlay handling: just remove the breakpoint. */
1382 if (b
->type
== bp_hardware_breakpoint
)
1383 val
= target_remove_hw_breakpoint (b
->address
,
1384 b
->shadow_contents
);
1386 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1390 /* This breakpoint is in an overlay section.
1391 Did we set a breakpoint at the LMA? */
1392 if (!overlay_events_enabled
)
1394 /* Yes -- overlay event support is not active, so we
1395 should have set a breakpoint at the LMA. Remove it.
1397 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1399 /* Ignore any failures: if the LMA is in ROM, we will
1400 have already warned when we failed to insert it. */
1401 if (b
->type
!= bp_hardware_breakpoint
)
1402 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1404 target_remove_breakpoint (addr
, b
->shadow_contents
);
1406 /* Did we set a breakpoint at the VMA?
1407 If so, we will have marked the breakpoint 'inserted'. */
1410 /* Yes -- remove it. Previously we did not bother to
1411 remove the breakpoint if the section had been
1412 unmapped, but let's not rely on that being safe. We
1413 don't know what the overlay manager might do. */
1414 if (b
->type
== bp_hardware_breakpoint
)
1415 val
= target_remove_hw_breakpoint (b
->address
,
1416 b
->shadow_contents
);
1418 val
= target_remove_breakpoint (b
->address
,
1419 b
->shadow_contents
);
1423 /* No -- not inserted, so no need to remove. No error. */
1429 b
->inserted
= (is
== mark_inserted
);
1431 else if ((b
->type
== bp_hardware_watchpoint
||
1432 b
->type
== bp_read_watchpoint
||
1433 b
->type
== bp_access_watchpoint
)
1434 && b
->enable_state
== bp_enabled
1440 b
->inserted
= (is
== mark_inserted
);
1441 /* Walk down the saved value chain. */
1442 for (v
= b
->val_chain
; v
; v
= v
->next
)
1444 /* For each memory reference remove the watchpoint
1446 if (VALUE_LVAL (v
) == lval_memory
1447 && ! VALUE_LAZY (v
))
1449 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1451 if (v
== b
->val_chain
1452 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1453 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1458 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1459 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1461 if (b
->type
== bp_read_watchpoint
)
1463 else if (b
->type
== bp_access_watchpoint
)
1466 val
= target_remove_watchpoint (addr
, len
, type
);
1473 /* Failure to remove any of the hardware watchpoints comes here. */
1474 if ((is
== mark_uninserted
) && (b
->inserted
))
1475 warning ("Could not remove hardware watchpoint %d.",
1478 /* Free the saved value chain. We will construct a new one
1479 the next time the watchpoint is inserted. */
1480 for (v
= b
->val_chain
; v
; v
= n
)
1485 b
->val_chain
= NULL
;
1487 else if ((b
->type
== bp_catch_fork
||
1488 b
->type
== bp_catch_vfork
||
1489 b
->type
== bp_catch_exec
)
1490 && b
->enable_state
== bp_enabled
1497 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1499 case bp_catch_vfork
:
1500 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1503 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1506 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1511 b
->inserted
= (is
== mark_inserted
);
1513 else if ((b
->type
== bp_catch_catch
||
1514 b
->type
== bp_catch_throw
)
1515 && b
->enable_state
== bp_enabled
1519 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1522 b
->inserted
= (is
== mark_inserted
);
1524 else if (ep_is_exception_catchpoint (b
)
1525 && b
->inserted
/* sometimes previous insert doesn't happen */
1526 && b
->enable_state
== bp_enabled
1530 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1534 b
->inserted
= (is
== mark_inserted
);
1540 /* Clear the "inserted" flag in all breakpoints. */
1543 mark_breakpoints_out (void)
1545 register struct breakpoint
*b
;
1551 /* Clear the "inserted" flag in all breakpoints and delete any
1552 breakpoints which should go away between runs of the program.
1554 Plus other such housekeeping that has to be done for breakpoints
1557 Note: this function gets called at the end of a run (by
1558 generic_mourn_inferior) and when a run begins (by
1559 init_wait_for_inferior). */
1564 breakpoint_init_inferior (enum inf_context context
)
1566 register struct breakpoint
*b
, *temp
;
1567 static int warning_needed
= 0;
1569 ALL_BREAKPOINTS_SAFE (b
, temp
)
1576 case bp_watchpoint_scope
:
1578 /* If the call dummy breakpoint is at the entry point it will
1579 cause problems when the inferior is rerun, so we better
1582 Also get rid of scope breakpoints. */
1583 delete_breakpoint (b
);
1587 case bp_hardware_watchpoint
:
1588 case bp_read_watchpoint
:
1589 case bp_access_watchpoint
:
1591 /* Likewise for watchpoints on local expressions. */
1592 if (b
->exp_valid_block
!= NULL
)
1593 delete_breakpoint (b
);
1594 if (context
== inf_starting
)
1596 /* Reset val field to force reread of starting value
1597 in insert_breakpoints. */
1599 value_free (b
->val
);
1604 /* Likewise for exception catchpoints in dynamic-linked
1605 executables where required */
1606 if (ep_is_exception_catchpoint (b
) &&
1607 exception_catchpoints_are_fragile
)
1610 delete_breakpoint (b
);
1616 if (exception_catchpoints_are_fragile
)
1617 exception_support_initialized
= 0;
1619 /* Don't issue the warning unless it's really needed... */
1620 if (warning_needed
&& (context
!= inf_exited
))
1622 warning ("Exception catchpoints from last run were deleted.");
1623 warning ("You must reinsert them explicitly.");
1628 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1629 exists at PC. It returns ordinary_breakpoint_here if it's an
1630 ordinary breakpoint, or permanent_breakpoint_here if it's a
1631 permanent breakpoint.
1632 - When continuing from a location with an ordinary breakpoint, we
1633 actually single step once before calling insert_breakpoints.
1634 - When continuing from a localion with a permanent breakpoint, we
1635 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1636 the target, to advance the PC past the breakpoint. */
1638 enum breakpoint_here
1639 breakpoint_here_p (CORE_ADDR pc
)
1641 register struct breakpoint
*b
;
1642 int any_breakpoint_here
= 0;
1645 if ((b
->enable_state
== bp_enabled
1646 || b
->enable_state
== bp_permanent
)
1647 && b
->address
== pc
) /* bp is enabled and matches pc */
1649 if (overlay_debugging
1650 && section_is_overlay (b
->section
)
1651 && !section_is_mapped (b
->section
))
1652 continue; /* unmapped overlay -- can't be a match */
1653 else if (b
->enable_state
== bp_permanent
)
1654 return permanent_breakpoint_here
;
1656 any_breakpoint_here
= 1;
1659 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1663 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1664 but it only returns true if there is actually a breakpoint inserted
1668 breakpoint_inserted_here_p (CORE_ADDR pc
)
1670 register struct breakpoint
*b
;
1674 && b
->address
== pc
) /* bp is inserted and matches pc */
1676 if (overlay_debugging
1677 && section_is_overlay (b
->section
)
1678 && !section_is_mapped (b
->section
))
1679 continue; /* unmapped overlay -- can't be a match */
1687 /* Return nonzero if FRAME is a dummy frame. We can't use
1688 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1689 take too much time, at least using frame_register() on the 68k.
1690 This means that for this function to work right a port must use the
1691 bp_call_dummy breakpoint. */
1694 deprecated_frame_in_dummy (struct frame_info
*frame
)
1696 struct breakpoint
*b
;
1698 /* This function is used by two files: get_frame_type(), after first
1699 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1700 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1701 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES
);
1705 if (b
->type
== bp_call_dummy
1706 && frame_id_eq (b
->frame_id
, get_frame_id (frame
))
1707 /* We need to check the PC as well as the frame on the sparc,
1708 for signals.exp in the testsuite. */
1709 && (get_frame_pc (frame
)
1711 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * DEPRECATED_REGISTER_SIZE
))
1712 && get_frame_pc (frame
) <= b
->address
)
1718 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1719 PC is valid for process/thread PID. */
1722 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1724 struct breakpoint
*b
;
1727 thread
= pid_to_thread_id (ptid
);
1730 if (b
->enable_state
!= bp_disabled
1731 && b
->enable_state
!= bp_shlib_disabled
1732 && b
->enable_state
!= bp_call_disabled
1734 && (b
->thread
== -1 || b
->thread
== thread
))
1736 if (overlay_debugging
1737 && section_is_overlay (b
->section
)
1738 && !section_is_mapped (b
->section
))
1739 continue; /* unmapped overlay -- can't be a match */
1748 /* bpstat stuff. External routines' interfaces are documented
1752 ep_is_catchpoint (struct breakpoint
*ep
)
1755 (ep
->type
== bp_catch_load
)
1756 || (ep
->type
== bp_catch_unload
)
1757 || (ep
->type
== bp_catch_fork
)
1758 || (ep
->type
== bp_catch_vfork
)
1759 || (ep
->type
== bp_catch_exec
)
1760 || (ep
->type
== bp_catch_catch
)
1761 || (ep
->type
== bp_catch_throw
);
1763 /* ??rehrauer: Add more kinds here, as are implemented... */
1767 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1770 (ep
->type
== bp_catch_load
)
1771 || (ep
->type
== bp_catch_unload
);
1775 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1778 (ep
->type
== bp_catch_catch
)
1779 || (ep
->type
== bp_catch_throw
);
1782 /* Clear a bpstat so that it says we are not at any breakpoint.
1783 Also free any storage that is part of a bpstat. */
1786 bpstat_clear (bpstat
*bsp
)
1797 if (p
->old_val
!= NULL
)
1798 value_free (p
->old_val
);
1799 free_command_lines (&p
->commands
);
1806 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1807 is part of the bpstat is copied as well. */
1810 bpstat_copy (bpstat bs
)
1814 bpstat retval
= NULL
;
1819 for (; bs
!= NULL
; bs
= bs
->next
)
1821 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1822 memcpy (tmp
, bs
, sizeof (*tmp
));
1823 if (bs
->commands
!= NULL
)
1824 tmp
->commands
= copy_command_lines (bs
->commands
);
1825 if (bs
->old_val
!= NULL
)
1826 tmp
->old_val
= value_copy (bs
->old_val
);
1829 /* This is the first thing in the chain. */
1839 /* Find the bpstat associated with this breakpoint */
1842 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1847 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1849 if (bsp
->breakpoint_at
== breakpoint
)
1855 /* Find a step_resume breakpoint associated with this bpstat.
1856 (If there are multiple step_resume bp's on the list, this function
1857 will arbitrarily pick one.)
1859 It is an error to use this function if BPSTAT doesn't contain a
1860 step_resume breakpoint.
1862 See wait_for_inferior's use of this function. */
1864 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1869 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1871 current_thread
= pid_to_thread_id (inferior_ptid
);
1873 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1875 if ((bsp
->breakpoint_at
!= NULL
) &&
1876 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1877 (bsp
->breakpoint_at
->thread
== current_thread
||
1878 bsp
->breakpoint_at
->thread
== -1))
1879 return bsp
->breakpoint_at
;
1882 error ("Internal error (no step_resume breakpoint found)");
1886 /* Return the breakpoint number of the first breakpoint we are stopped
1887 at. *BSP upon return is a bpstat which points to the remaining
1888 breakpoints stopped at (but which is not guaranteed to be good for
1889 anything but further calls to bpstat_num).
1890 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1893 bpstat_num (bpstat
*bsp
)
1895 struct breakpoint
*b
;
1898 return 0; /* No more breakpoint values */
1901 b
= (*bsp
)->breakpoint_at
;
1902 *bsp
= (*bsp
)->next
;
1904 return -1; /* breakpoint that's been deleted since */
1906 return b
->number
; /* We have its number */
1910 /* Modify BS so that the actions will not be performed. */
1913 bpstat_clear_actions (bpstat bs
)
1915 for (; bs
!= NULL
; bs
= bs
->next
)
1917 free_command_lines (&bs
->commands
);
1918 if (bs
->old_val
!= NULL
)
1920 value_free (bs
->old_val
);
1926 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1929 cleanup_executing_breakpoints (void *ignore
)
1931 executing_breakpoint_commands
= 0;
1934 /* Execute all the commands associated with all the breakpoints at this
1935 location. Any of these commands could cause the process to proceed
1936 beyond this point, etc. We look out for such changes by checking
1937 the global "breakpoint_proceeded" after each command. */
1940 bpstat_do_actions (bpstat
*bsp
)
1943 struct cleanup
*old_chain
;
1944 struct command_line
*cmd
;
1946 /* Avoid endless recursion if a `source' command is contained
1948 if (executing_breakpoint_commands
)
1951 executing_breakpoint_commands
= 1;
1952 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1955 /* Note that (as of this writing), our callers all appear to
1956 be passing us the address of global stop_bpstat. And, if
1957 our calls to execute_control_command cause the inferior to
1958 proceed, that global (and hence, *bsp) will change.
1960 We must be careful to not touch *bsp unless the inferior
1961 has not proceeded. */
1963 /* This pointer will iterate over the list of bpstat's. */
1966 breakpoint_proceeded
= 0;
1967 for (; bs
!= NULL
; bs
= bs
->next
)
1972 execute_control_command (cmd
);
1974 if (breakpoint_proceeded
)
1979 if (breakpoint_proceeded
)
1980 /* The inferior is proceeded by the command; bomb out now.
1981 The bpstat chain has been blown away by wait_for_inferior.
1982 But since execution has stopped again, there is a new bpstat
1983 to look at, so start over. */
1986 free_command_lines (&bs
->commands
);
1988 do_cleanups (old_chain
);
1991 /* This is the normal print function for a bpstat. In the future,
1992 much of this logic could (should?) be moved to bpstat_stop_status,
1993 by having it set different print_it values.
1995 Current scheme: When we stop, bpstat_print() is called. It loops
1996 through the bpstat list of things causing this stop, calling the
1997 print_bp_stop_message function on each one. The behavior of the
1998 print_bp_stop_message function depends on the print_it field of
1999 bpstat. If such field so indicates, call this function here.
2001 Return values from this routine (ultimately used by bpstat_print()
2002 and normal_stop() to decide what to do):
2003 PRINT_NOTHING: Means we already printed all we needed to print,
2004 don't print anything else.
2005 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2006 that something to be followed by a location.
2007 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2008 that something to be followed by a location.
2009 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2012 static enum print_stop_action
2013 print_it_typical (bpstat bs
)
2015 struct cleanup
*old_chain
, *ui_out_chain
;
2016 struct ui_stream
*stb
;
2017 stb
= ui_out_stream_new (uiout
);
2018 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
2019 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2020 which has since been deleted. */
2021 if (bs
->breakpoint_at
== NULL
)
2022 return PRINT_UNKNOWN
;
2024 switch (bs
->breakpoint_at
->type
)
2027 case bp_hardware_breakpoint
:
2028 annotate_breakpoint (bs
->breakpoint_at
->number
);
2029 ui_out_text (uiout
, "\nBreakpoint ");
2030 if (ui_out_is_mi_like_p (uiout
))
2031 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
2032 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
2033 ui_out_text (uiout
, ", ");
2034 return PRINT_SRC_AND_LOC
;
2037 case bp_shlib_event
:
2038 /* Did we stop because the user set the stop_on_solib_events
2039 variable? (If so, we report this as a generic, "Stopped due
2040 to shlib event" message.) */
2041 printf_filtered ("Stopped due to shared library event\n");
2042 return PRINT_NOTHING
;
2045 case bp_thread_event
:
2046 /* Not sure how we will get here.
2047 GDB should not stop for these breakpoints. */
2048 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2049 return PRINT_NOTHING
;
2052 case bp_overlay_event
:
2053 /* By analogy with the thread event, GDB should not stop for these. */
2054 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2055 return PRINT_NOTHING
;
2059 annotate_catchpoint (bs
->breakpoint_at
->number
);
2060 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2061 printf_filtered ("loaded");
2062 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2063 return PRINT_SRC_AND_LOC
;
2066 case bp_catch_unload
:
2067 annotate_catchpoint (bs
->breakpoint_at
->number
);
2068 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2069 printf_filtered ("unloaded");
2070 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2071 return PRINT_SRC_AND_LOC
;
2075 annotate_catchpoint (bs
->breakpoint_at
->number
);
2076 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2077 printf_filtered ("forked");
2078 printf_filtered (" process %d), ",
2079 bs
->breakpoint_at
->forked_inferior_pid
);
2080 return PRINT_SRC_AND_LOC
;
2083 case bp_catch_vfork
:
2084 annotate_catchpoint (bs
->breakpoint_at
->number
);
2085 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2086 printf_filtered ("vforked");
2087 printf_filtered (" process %d), ",
2088 bs
->breakpoint_at
->forked_inferior_pid
);
2089 return PRINT_SRC_AND_LOC
;
2093 annotate_catchpoint (bs
->breakpoint_at
->number
);
2094 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2095 bs
->breakpoint_at
->number
,
2096 bs
->breakpoint_at
->exec_pathname
);
2097 return PRINT_SRC_AND_LOC
;
2100 case bp_catch_catch
:
2101 if (current_exception_event
&&
2102 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2104 annotate_catchpoint (bs
->breakpoint_at
->number
);
2105 printf_filtered ("\nCatchpoint %d (exception caught), ",
2106 bs
->breakpoint_at
->number
);
2107 printf_filtered ("throw location ");
2108 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2109 printf_filtered ("%s:%d",
2110 CURRENT_EXCEPTION_THROW_FILE
,
2111 CURRENT_EXCEPTION_THROW_LINE
);
2113 printf_filtered ("unknown");
2115 printf_filtered (", catch location ");
2116 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2117 printf_filtered ("%s:%d",
2118 CURRENT_EXCEPTION_CATCH_FILE
,
2119 CURRENT_EXCEPTION_CATCH_LINE
);
2121 printf_filtered ("unknown");
2123 printf_filtered ("\n");
2124 /* don't bother to print location frame info */
2125 return PRINT_SRC_ONLY
;
2129 /* really throw, some other bpstat will handle it */
2130 return PRINT_UNKNOWN
;
2134 case bp_catch_throw
:
2135 if (current_exception_event
&&
2136 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2138 annotate_catchpoint (bs
->breakpoint_at
->number
);
2139 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2140 bs
->breakpoint_at
->number
);
2141 printf_filtered ("throw location ");
2142 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2143 printf_filtered ("%s:%d",
2144 CURRENT_EXCEPTION_THROW_FILE
,
2145 CURRENT_EXCEPTION_THROW_LINE
);
2147 printf_filtered ("unknown");
2149 printf_filtered (", catch location ");
2150 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2151 printf_filtered ("%s:%d",
2152 CURRENT_EXCEPTION_CATCH_FILE
,
2153 CURRENT_EXCEPTION_CATCH_LINE
);
2155 printf_filtered ("unknown");
2157 printf_filtered ("\n");
2158 /* don't bother to print location frame info */
2159 return PRINT_SRC_ONLY
;
2163 /* really catch, some other bpstat will handle it */
2164 return PRINT_UNKNOWN
;
2169 case bp_hardware_watchpoint
:
2170 if (bs
->old_val
!= NULL
)
2172 annotate_watchpoint (bs
->breakpoint_at
->number
);
2173 if (ui_out_is_mi_like_p (uiout
))
2174 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2175 mention (bs
->breakpoint_at
);
2176 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2177 ui_out_text (uiout
, "\nOld value = ");
2178 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2179 ui_out_field_stream (uiout
, "old", stb
);
2180 ui_out_text (uiout
, "\nNew value = ");
2181 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2182 ui_out_field_stream (uiout
, "new", stb
);
2183 do_cleanups (ui_out_chain
);
2184 ui_out_text (uiout
, "\n");
2185 value_free (bs
->old_val
);
2188 /* More than one watchpoint may have been triggered. */
2189 return PRINT_UNKNOWN
;
2192 case bp_read_watchpoint
:
2193 if (ui_out_is_mi_like_p (uiout
))
2194 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2195 mention (bs
->breakpoint_at
);
2196 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2197 ui_out_text (uiout
, "\nValue = ");
2198 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2199 ui_out_field_stream (uiout
, "value", stb
);
2200 do_cleanups (ui_out_chain
);
2201 ui_out_text (uiout
, "\n");
2202 return PRINT_UNKNOWN
;
2205 case bp_access_watchpoint
:
2206 if (bs
->old_val
!= NULL
)
2208 annotate_watchpoint (bs
->breakpoint_at
->number
);
2209 if (ui_out_is_mi_like_p (uiout
))
2210 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2211 mention (bs
->breakpoint_at
);
2212 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2213 ui_out_text (uiout
, "\nOld value = ");
2214 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2215 ui_out_field_stream (uiout
, "old", stb
);
2216 value_free (bs
->old_val
);
2218 ui_out_text (uiout
, "\nNew value = ");
2222 mention (bs
->breakpoint_at
);
2223 if (ui_out_is_mi_like_p (uiout
))
2224 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2225 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "value");
2226 ui_out_text (uiout
, "\nValue = ");
2228 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2229 ui_out_field_stream (uiout
, "new", stb
);
2230 do_cleanups (ui_out_chain
);
2231 ui_out_text (uiout
, "\n");
2232 return PRINT_UNKNOWN
;
2235 /* Fall through, we don't deal with these types of breakpoints
2239 if (ui_out_is_mi_like_p (uiout
))
2240 ui_out_field_string (uiout
, "reason", "function-finished");
2241 return PRINT_UNKNOWN
;
2245 if (ui_out_is_mi_like_p (uiout
))
2246 ui_out_field_string (uiout
, "reason", "location-reached");
2247 return PRINT_UNKNOWN
;
2252 case bp_longjmp_resume
:
2253 case bp_step_resume
:
2254 case bp_through_sigtramp
:
2255 case bp_watchpoint_scope
:
2258 return PRINT_UNKNOWN
;
2262 /* Generic routine for printing messages indicating why we
2263 stopped. The behavior of this function depends on the value
2264 'print_it' in the bpstat structure. Under some circumstances we
2265 may decide not to print anything here and delegate the task to
2268 static enum print_stop_action
2269 print_bp_stop_message (bpstat bs
)
2271 switch (bs
->print_it
)
2274 /* Nothing should be printed for this bpstat entry. */
2275 return PRINT_UNKNOWN
;
2279 /* We still want to print the frame, but we already printed the
2280 relevant messages. */
2281 return PRINT_SRC_AND_LOC
;
2284 case print_it_normal
:
2285 /* Normal case. Call the breakpoint's print_it method, or
2286 print_it_typical. */
2287 if (bs
->breakpoint_at
!= NULL
&& bs
->breakpoint_at
->ops
!= NULL
2288 && bs
->breakpoint_at
->ops
->print_it
!= NULL
)
2289 return bs
->breakpoint_at
->ops
->print_it (bs
->breakpoint_at
);
2291 return print_it_typical (bs
);
2295 internal_error (__FILE__
, __LINE__
,
2296 "print_bp_stop_message: unrecognized enum value");
2301 /* Print a message indicating what happened. This is called from
2302 normal_stop(). The input to this routine is the head of the bpstat
2303 list - a list of the eventpoints that caused this stop. This
2304 routine calls the generic print routine for printing a message
2305 about reasons for stopping. This will print (for example) the
2306 "Breakpoint n," part of the output. The return value of this
2309 PRINT_UNKNOWN: Means we printed nothing
2310 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2311 code to print the location. An example is
2312 "Breakpoint 1, " which should be followed by
2314 PRINT_SRC_ONLY: Means we printed something, but there is no need
2315 to also print the location part of the message.
2316 An example is the catch/throw messages, which
2317 don't require a location appended to the end.
2318 PRINT_NOTHING: We have done some printing and we don't need any
2319 further info to be printed.*/
2321 enum print_stop_action
2322 bpstat_print (bpstat bs
)
2326 /* Maybe another breakpoint in the chain caused us to stop.
2327 (Currently all watchpoints go on the bpstat whether hit or not.
2328 That probably could (should) be changed, provided care is taken
2329 with respect to bpstat_explains_signal). */
2330 for (; bs
; bs
= bs
->next
)
2332 val
= print_bp_stop_message (bs
);
2333 if (val
== PRINT_SRC_ONLY
2334 || val
== PRINT_SRC_AND_LOC
2335 || val
== PRINT_NOTHING
)
2339 /* We reached the end of the chain, or we got a null BS to start
2340 with and nothing was printed. */
2341 return PRINT_UNKNOWN
;
2344 /* Evaluate the expression EXP and return 1 if value is zero.
2345 This is used inside a catch_errors to evaluate the breakpoint condition.
2346 The argument is a "struct expression *" that has been cast to char * to
2347 make it pass through catch_errors. */
2350 breakpoint_cond_eval (void *exp
)
2352 struct value
*mark
= value_mark ();
2353 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2354 value_free_to_mark (mark
);
2358 /* Allocate a new bpstat and chain it to the current one. */
2361 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2365 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2367 bs
->breakpoint_at
= b
;
2368 /* If the condition is false, etc., don't do the commands. */
2369 bs
->commands
= NULL
;
2371 bs
->print_it
= print_it_normal
;
2375 /* Possible return values for watchpoint_check (this can't be an enum
2376 because of check_errors). */
2377 /* The watchpoint has been deleted. */
2378 #define WP_DELETED 1
2379 /* The value has changed. */
2380 #define WP_VALUE_CHANGED 2
2381 /* The value has not changed. */
2382 #define WP_VALUE_NOT_CHANGED 3
2384 #define BP_TEMPFLAG 1
2385 #define BP_HARDWAREFLAG 2
2387 /* Check watchpoint condition. */
2390 watchpoint_check (void *p
)
2392 bpstat bs
= (bpstat
) p
;
2393 struct breakpoint
*b
;
2394 struct frame_info
*fr
;
2395 int within_current_scope
;
2397 struct frame_id current_frame_id
;
2400 b
= bs
->breakpoint_at
;
2402 if (b
->exp_valid_block
== NULL
)
2403 within_current_scope
= 1;
2406 /* There is no current frame at this moment. If we're going to have
2407 any chance of handling watchpoints on local variables, we'll need
2408 the frame chain (so we can determine if we're in scope). */
2409 reinit_frame_cache ();
2410 fr
= frame_find_by_id (b
->watchpoint_frame
);
2411 within_current_scope
= (fr
!= NULL
);
2412 /* in_function_epilogue_p() returns a non-zero value if we're still
2413 in the function but the stack frame has already been invalidated.
2414 Since we can't rely on the values of local variables after the
2415 stack has been destroyed, we are treating the watchpoint in that
2416 state as `not changed' without further checking.
2418 vinschen/2003-09-04: The former implementation left out the case
2419 that the watchpoint frame couldn't be found by frame_find_by_id()
2420 because the current PC is currently in an epilogue. Calling
2421 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2422 if ((!within_current_scope
|| fr
== get_current_frame ())
2423 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2424 return WP_VALUE_NOT_CHANGED
;
2425 if (fr
&& within_current_scope
)
2426 /* If we end up stopping, the current frame will get selected
2427 in normal_stop. So this call to select_frame won't affect
2432 if (within_current_scope
)
2434 /* We use value_{,free_to_}mark because it could be a
2435 *long* time before we return to the command level and
2436 call free_all_values. We can't call free_all_values because
2437 we might be in the middle of evaluating a function call. */
2439 struct value
*mark
= value_mark ();
2440 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2441 if (!value_equal (b
->val
, new_val
))
2443 release_value (new_val
);
2444 value_free_to_mark (mark
);
2445 bs
->old_val
= b
->val
;
2447 /* We will stop here */
2448 return WP_VALUE_CHANGED
;
2452 /* Nothing changed, don't do anything. */
2453 value_free_to_mark (mark
);
2454 /* We won't stop here */
2455 return WP_VALUE_NOT_CHANGED
;
2460 /* This seems like the only logical thing to do because
2461 if we temporarily ignored the watchpoint, then when
2462 we reenter the block in which it is valid it contains
2463 garbage (in the case of a function, it may have two
2464 garbage values, one before and one after the prologue).
2465 So we can't even detect the first assignment to it and
2466 watch after that (since the garbage may or may not equal
2467 the first value assigned). */
2468 /* We print all the stop information in print_it_typical(), but
2469 in this case, by the time we call print_it_typical() this bp
2470 will be deleted already. So we have no choice but print the
2471 information here. */
2472 if (ui_out_is_mi_like_p (uiout
))
2473 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2474 ui_out_text (uiout
, "\nWatchpoint ");
2475 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2476 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2477 which its expression is valid.\n");
2479 if (b
->related_breakpoint
)
2480 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2481 b
->disposition
= disp_del_at_next_stop
;
2487 /* Get a bpstat associated with having just stopped at address *PC
2488 and frame address CORE_ADDRESS. Update *PC to point at the
2489 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2490 if this is known to not be a real breakpoint (it could still be a
2491 watchpoint, though). */
2493 /* Determine whether we stopped at a breakpoint, etc, or whether we
2494 don't understand this stop. Result is a chain of bpstat's such that:
2496 if we don't understand the stop, the result is a null pointer.
2498 if we understand why we stopped, the result is not null.
2500 Each element of the chain refers to a particular breakpoint or
2501 watchpoint at which we have stopped. (We may have stopped for
2502 several reasons concurrently.)
2504 Each element of the chain has valid next, breakpoint_at,
2505 commands, FIXME??? fields. */
2508 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_sw_breakpoint
)
2510 register struct breakpoint
*b
, *temp
;
2512 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2513 int real_breakpoint
= 0;
2514 /* Root of the chain of bpstat's */
2515 struct bpstats root_bs
[1];
2516 /* Pointer to the last thing in the chain currently. */
2517 bpstat bs
= root_bs
;
2519 /* Get the address where the breakpoint would have been. The
2520 "not_a_sw_breakpoint" argument is meant to distinguish between a
2521 breakpoint trap event and a trace/singlestep trap event. For a
2522 trace/singlestep trap event, we would not want to subtract
2523 DECR_PC_AFTER_BREAK from the PC. */
2525 bp_addr
= *pc
- (not_a_sw_breakpoint
? 0 : DECR_PC_AFTER_BREAK
);
2527 ALL_BREAKPOINTS_SAFE (b
, temp
)
2529 if (b
->enable_state
== bp_disabled
2530 || b
->enable_state
== bp_shlib_disabled
2531 || b
->enable_state
== bp_call_disabled
)
2534 if (b
->type
!= bp_watchpoint
2535 && b
->type
!= bp_hardware_watchpoint
2536 && b
->type
!= bp_read_watchpoint
2537 && b
->type
!= bp_access_watchpoint
2538 && b
->type
!= bp_hardware_breakpoint
2539 && b
->type
!= bp_catch_fork
2540 && b
->type
!= bp_catch_vfork
2541 && b
->type
!= bp_catch_exec
2542 && b
->type
!= bp_catch_catch
2543 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2545 if (b
->address
!= bp_addr
) /* address doesn't match */
2547 if (overlay_debugging
/* unmapped overlay section */
2548 && section_is_overlay (b
->section
)
2549 && !section_is_mapped (b
->section
))
2553 if (b
->type
== bp_hardware_breakpoint
)
2555 if (b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2557 if (overlay_debugging
/* unmapped overlay section */
2558 && section_is_overlay (b
->section
)
2559 && !section_is_mapped (b
->section
))
2563 /* Is this a catchpoint of a load or unload? If so, did we
2564 get a load or unload of the specified library? If not,
2566 if ((b
->type
== bp_catch_load
)
2567 #if defined(SOLIB_HAVE_LOAD_EVENT)
2568 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2569 || ((b
->dll_pathname
!= NULL
)
2570 && (strcmp (b
->dll_pathname
,
2571 SOLIB_LOADED_LIBRARY_PATHNAME (
2572 PIDGET (inferior_ptid
)))
2578 if ((b
->type
== bp_catch_unload
)
2579 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2580 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2581 || ((b
->dll_pathname
!= NULL
)
2582 && (strcmp (b
->dll_pathname
,
2583 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2584 PIDGET (inferior_ptid
)))
2590 if ((b
->type
== bp_catch_fork
)
2591 && !inferior_has_forked (PIDGET (inferior_ptid
),
2592 &b
->forked_inferior_pid
))
2595 if ((b
->type
== bp_catch_vfork
)
2596 && !inferior_has_vforked (PIDGET (inferior_ptid
),
2597 &b
->forked_inferior_pid
))
2600 if ((b
->type
== bp_catch_exec
)
2601 && !inferior_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2604 if (ep_is_exception_catchpoint (b
) &&
2605 !(current_exception_event
= target_get_current_exception_event ()))
2608 /* Come here if it's a watchpoint, or if the break address matches */
2610 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2612 /* Watchpoints may change this, if not found to have triggered. */
2616 if (b
->type
== bp_watchpoint
||
2617 b
->type
== bp_hardware_watchpoint
)
2619 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2621 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2622 int e
= catch_errors (watchpoint_check
, bs
, message
,
2624 do_cleanups (cleanups
);
2628 /* We've already printed what needs to be printed. */
2629 /* Actually this is superfluous, because by the time we
2630 call print_it_typical() the wp will be already deleted,
2631 and the function will return immediately. */
2632 bs
->print_it
= print_it_done
;
2635 case WP_VALUE_CHANGED
:
2639 case WP_VALUE_NOT_CHANGED
:
2641 bs
->print_it
= print_it_noop
;
2648 /* Error from catch_errors. */
2649 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2650 if (b
->related_breakpoint
)
2651 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2652 b
->disposition
= disp_del_at_next_stop
;
2653 /* We've already printed what needs to be printed. */
2654 bs
->print_it
= print_it_done
;
2660 else if (b
->type
== bp_read_watchpoint
||
2661 b
->type
== bp_access_watchpoint
)
2667 addr
= target_stopped_data_address ();
2670 for (v
= b
->val_chain
; v
; v
= v
->next
)
2672 if (VALUE_LVAL (v
) == lval_memory
2673 && ! VALUE_LAZY (v
))
2675 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2677 if (v
== b
->val_chain
2678 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2679 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2683 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2684 /* Exact match not required. Within range is
2686 if (addr
>= vaddr
&&
2687 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2694 char *message
= xstrprintf ("Error evaluating expression for watchpoint %d\n",
2696 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
2697 int e
= catch_errors (watchpoint_check
, bs
, message
,
2699 do_cleanups (cleanups
);
2703 /* We've already printed what needs to be printed. */
2704 bs
->print_it
= print_it_done
;
2707 case WP_VALUE_CHANGED
:
2708 if (b
->type
== bp_read_watchpoint
)
2710 /* Don't stop: read watchpoints shouldn't fire if
2711 the value has changed. This is for targets
2712 which cannot set read-only watchpoints. */
2713 bs
->print_it
= print_it_noop
;
2719 case WP_VALUE_NOT_CHANGED
:
2726 /* Error from catch_errors. */
2727 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2728 if (b
->related_breakpoint
)
2729 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2730 b
->disposition
= disp_del_at_next_stop
;
2731 /* We've already printed what needs to be printed. */
2732 bs
->print_it
= print_it_done
;
2736 else /* found == 0 */
2738 /* This is a case where some watchpoint(s) triggered,
2739 but not at the address of this watchpoint (FOUND
2740 was left zero). So don't print anything for this
2742 bs
->print_it
= print_it_noop
;
2749 /* By definition, an encountered breakpoint is a triggered
2753 real_breakpoint
= 1;
2756 if (frame_id_p (b
->frame_id
)
2757 && !frame_id_eq (b
->frame_id
, get_frame_id (get_current_frame ())))
2761 int value_is_zero
= 0;
2765 /* Need to select the frame, with all that implies
2766 so that the conditions will have the right context. */
2767 select_frame (get_current_frame ());
2769 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2770 "Error in testing breakpoint condition:\n",
2772 /* FIXME-someday, should give breakpoint # */
2775 if (b
->cond
&& value_is_zero
)
2778 /* Don't consider this a hit. */
2781 else if (b
->ignore_count
> 0)
2784 annotate_ignore_count_change ();
2789 /* We will stop here */
2790 if (b
->disposition
== disp_disable
)
2791 b
->enable_state
= bp_disabled
;
2794 bs
->commands
= b
->commands
;
2796 (STREQ ("silent", bs
->commands
->line
) ||
2797 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2799 bs
->commands
= bs
->commands
->next
;
2802 bs
->commands
= copy_command_lines (bs
->commands
);
2805 /* Print nothing for this entry if we dont stop or if we dont print. */
2806 if (bs
->stop
== 0 || bs
->print
== 0)
2807 bs
->print_it
= print_it_noop
;
2810 bs
->next
= NULL
; /* Terminate the chain */
2811 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2813 if (real_breakpoint
&& bs
)
2815 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2817 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2819 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2825 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2828 #if defined (SHIFT_INST_REGS)
2830 #else /* No SHIFT_INST_REGS. */
2832 #endif /* No SHIFT_INST_REGS. */
2837 /* The value of a hardware watchpoint hasn't changed, but the
2838 intermediate memory locations we are watching may have. */
2839 if (bs
&& !bs
->stop
&&
2840 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2841 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2842 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2844 remove_breakpoints ();
2845 insert_breakpoints ();
2850 /* Tell what to do about this bpstat. */
2852 bpstat_what (bpstat bs
)
2854 /* Classify each bpstat as one of the following. */
2857 /* This bpstat element has no effect on the main_action. */
2860 /* There was a watchpoint, stop but don't print. */
2863 /* There was a watchpoint, stop and print. */
2866 /* There was a breakpoint but we're not stopping. */
2869 /* There was a breakpoint, stop but don't print. */
2872 /* There was a breakpoint, stop and print. */
2875 /* We hit the longjmp breakpoint. */
2878 /* We hit the longjmp_resume breakpoint. */
2881 /* We hit the step_resume breakpoint. */
2884 /* We hit the through_sigtramp breakpoint. */
2887 /* We hit the shared library event breakpoint. */
2890 /* We caught a shared library event. */
2893 /* This is just used to count how many enums there are. */
2897 /* Here is the table which drives this routine. So that we can
2898 format it pretty, we define some abbreviations for the
2899 enum bpstat_what codes. */
2900 #define kc BPSTAT_WHAT_KEEP_CHECKING
2901 #define ss BPSTAT_WHAT_STOP_SILENT
2902 #define sn BPSTAT_WHAT_STOP_NOISY
2903 #define sgl BPSTAT_WHAT_SINGLE
2904 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2905 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2906 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2907 #define sr BPSTAT_WHAT_STEP_RESUME
2908 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2909 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2910 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2912 /* "Can't happen." Might want to print an error message.
2913 abort() is not out of the question, but chances are GDB is just
2914 a bit confused, not unusable. */
2915 #define err BPSTAT_WHAT_STOP_NOISY
2917 /* Given an old action and a class, come up with a new action. */
2918 /* One interesting property of this table is that wp_silent is the same
2919 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2920 after stopping, the check for whether to step over a breakpoint
2921 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2922 reference to how we stopped. We retain separate wp_silent and
2923 bp_silent codes in case we want to change that someday.
2925 Another possibly interesting property of this table is that
2926 there's a partial ordering, priority-like, of the actions. Once
2927 you've decided that some action is appropriate, you'll never go
2928 back and decide something of a lower priority is better. The
2931 kc < clr sgl shl shlr slr sn sr ss ts
2932 sgl < clrs shl shlr slr sn sr ss ts
2933 slr < err shl shlr sn sr ss ts
2934 clr < clrs err shl shlr sn sr ss ts
2935 clrs < err shl shlr sn sr ss ts
2936 ss < shl shlr sn sr ts
2943 What I think this means is that we don't need a damned table
2944 here. If you just put the rows and columns in the right order,
2945 it'd look awfully regular. We could simply walk the bpstat list
2946 and choose the highest priority action we find, with a little
2947 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2948 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2949 is messy anyway). */
2951 /* step_resume entries: a step resume breakpoint overrides another
2952 breakpoint of signal handling (see comment in wait_for_inferior
2953 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2954 /* We handle the through_sigtramp_breakpoint the same way; having both
2955 one of those and a step_resume_breakpoint is probably very rare (?). */
2957 static const enum bpstat_what_main_action
2958 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2961 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2964 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2966 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2968 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2970 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2972 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2974 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2976 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2978 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2980 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2982 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2984 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2986 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
3001 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
3002 struct bpstat_what retval
;
3004 retval
.call_dummy
= 0;
3005 for (; bs
!= NULL
; bs
= bs
->next
)
3007 enum class bs_class
= no_effect
;
3008 if (bs
->breakpoint_at
== NULL
)
3009 /* I suspect this can happen if it was a momentary breakpoint
3010 which has since been deleted. */
3012 switch (bs
->breakpoint_at
->type
)
3018 case bp_hardware_breakpoint
:
3024 bs_class
= bp_noisy
;
3026 bs_class
= bp_silent
;
3029 bs_class
= bp_nostop
;
3032 case bp_hardware_watchpoint
:
3033 case bp_read_watchpoint
:
3034 case bp_access_watchpoint
:
3038 bs_class
= wp_noisy
;
3040 bs_class
= wp_silent
;
3043 /* There was a watchpoint, but we're not stopping.
3044 This requires no further action. */
3045 bs_class
= no_effect
;
3048 bs_class
= long_jump
;
3050 case bp_longjmp_resume
:
3051 bs_class
= long_resume
;
3053 case bp_step_resume
:
3056 bs_class
= step_resume
;
3059 /* It is for the wrong frame. */
3060 bs_class
= bp_nostop
;
3062 case bp_through_sigtramp
:
3063 bs_class
= through_sig
;
3065 case bp_watchpoint_scope
:
3066 bs_class
= bp_nostop
;
3068 case bp_shlib_event
:
3069 bs_class
= shlib_event
;
3071 case bp_thread_event
:
3072 case bp_overlay_event
:
3073 bs_class
= bp_nostop
;
3076 case bp_catch_unload
:
3077 /* Only if this catchpoint triggered should we cause the
3078 step-out-of-dld behaviour. Otherwise, we ignore this
3081 bs_class
= catch_shlib_event
;
3083 bs_class
= no_effect
;
3086 case bp_catch_vfork
:
3091 bs_class
= bp_noisy
;
3093 bs_class
= bp_silent
;
3096 /* There was a catchpoint, but we're not stopping.
3097 This requires no further action. */
3098 bs_class
= no_effect
;
3100 case bp_catch_catch
:
3101 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3102 bs_class
= bp_nostop
;
3104 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3106 case bp_catch_throw
:
3107 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3108 bs_class
= bp_nostop
;
3110 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3113 /* Make sure the action is stop (silent or noisy),
3114 so infrun.c pops the dummy frame. */
3115 bs_class
= bp_silent
;
3116 retval
.call_dummy
= 1;
3119 current_action
= table
[(int) bs_class
][(int) current_action
];
3121 retval
.main_action
= current_action
;
3125 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3126 without hardware support). This isn't related to a specific bpstat,
3127 just to things like whether watchpoints are set. */
3130 bpstat_should_step (void)
3132 struct breakpoint
*b
;
3134 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3139 /* Nonzero if there are enabled hardware watchpoints. */
3141 bpstat_have_active_hw_watchpoints (void)
3143 struct breakpoint
*b
;
3145 if ((b
->enable_state
== bp_enabled
) &&
3147 ((b
->type
== bp_hardware_watchpoint
) ||
3148 (b
->type
== bp_read_watchpoint
) ||
3149 (b
->type
== bp_access_watchpoint
)))
3155 /* Given a bpstat that records zero or more triggered eventpoints, this
3156 function returns another bpstat which contains only the catchpoints
3157 on that first list, if any. */
3159 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3161 struct bpstats root_bs
[1];
3162 bpstat bs
= root_bs
;
3163 struct breakpoint
*ep
;
3166 bpstat_clear (cp_list
);
3167 root_bs
->next
= NULL
;
3169 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3171 /* Is this eventpoint a catchpoint? If not, ignore it. */
3172 ep
= ep_list
->breakpoint_at
;
3175 if ((ep
->type
!= bp_catch_load
) &&
3176 (ep
->type
!= bp_catch_unload
) &&
3177 (ep
->type
!= bp_catch_catch
) &&
3178 (ep
->type
!= bp_catch_throw
))
3179 /* pai: (temp) ADD fork/vfork here!! */
3182 /* Yes; add it to the list. */
3183 bs
= bpstat_alloc (ep
, bs
);
3188 #if defined(SOLIB_ADD)
3189 /* Also, for each triggered catchpoint, tag it with the name of
3190 the library that caused this trigger. (We copy the name now,
3191 because it's only guaranteed to be available NOW, when the
3192 catchpoint triggers. Clients who may wish to know the name
3193 later must get it from the catchpoint itself.) */
3194 if (ep
->triggered_dll_pathname
!= NULL
)
3195 xfree (ep
->triggered_dll_pathname
);
3196 if (ep
->type
== bp_catch_load
)
3197 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3198 PIDGET (inferior_ptid
));
3200 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3201 PIDGET (inferior_ptid
));
3203 dll_pathname
= NULL
;
3207 ep
->triggered_dll_pathname
= (char *)
3208 xmalloc (strlen (dll_pathname
) + 1);
3209 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3212 ep
->triggered_dll_pathname
= NULL
;
3218 /* Print B to gdb_stdout. */
3220 print_one_breakpoint (struct breakpoint
*b
,
3221 CORE_ADDR
*last_addr
)
3223 register struct command_line
*l
;
3224 register struct symbol
*sym
;
3225 struct ep_type_description
3230 static struct ep_type_description bptypes
[] =
3232 {bp_none
, "?deleted?"},
3233 {bp_breakpoint
, "breakpoint"},
3234 {bp_hardware_breakpoint
, "hw breakpoint"},
3235 {bp_until
, "until"},
3236 {bp_finish
, "finish"},
3237 {bp_watchpoint
, "watchpoint"},
3238 {bp_hardware_watchpoint
, "hw watchpoint"},
3239 {bp_read_watchpoint
, "read watchpoint"},
3240 {bp_access_watchpoint
, "acc watchpoint"},
3241 {bp_longjmp
, "longjmp"},
3242 {bp_longjmp_resume
, "longjmp resume"},
3243 {bp_step_resume
, "step resume"},
3244 {bp_through_sigtramp
, "sigtramp"},
3245 {bp_watchpoint_scope
, "watchpoint scope"},
3246 {bp_call_dummy
, "call dummy"},
3247 {bp_shlib_event
, "shlib events"},
3248 {bp_thread_event
, "thread events"},
3249 {bp_overlay_event
, "overlay events"},
3250 {bp_catch_load
, "catch load"},
3251 {bp_catch_unload
, "catch unload"},
3252 {bp_catch_fork
, "catch fork"},
3253 {bp_catch_vfork
, "catch vfork"},
3254 {bp_catch_exec
, "catch exec"},
3255 {bp_catch_catch
, "catch catch"},
3256 {bp_catch_throw
, "catch throw"}
3259 static char *bpdisps
[] =
3260 {"del", "dstp", "dis", "keep"};
3261 static char bpenables
[] = "nynny";
3262 char wrap_indent
[80];
3263 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3264 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3265 struct cleanup
*bkpt_chain
;
3268 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "bkpt");
3272 ui_out_field_int (uiout
, "number", b
->number
);
3276 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3277 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3278 internal_error (__FILE__
, __LINE__
,
3279 "bptypes table does not describe type #%d.",
3281 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3285 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3289 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3290 ui_out_spaces (uiout
, 2);
3293 strcpy (wrap_indent
, " ");
3296 if (TARGET_ADDR_BIT
<= 32)
3297 strcat (wrap_indent
, " ");
3299 strcat (wrap_indent
, " ");
3302 if (b
->ops
!= NULL
&& b
->ops
->print_one
!= NULL
)
3303 b
->ops
->print_one (b
, last_addr
);
3308 internal_error (__FILE__
, __LINE__
,
3309 "print_one_breakpoint: bp_none encountered\n");
3313 case bp_hardware_watchpoint
:
3314 case bp_read_watchpoint
:
3315 case bp_access_watchpoint
:
3316 /* Field 4, the address, is omitted (which makes the columns
3317 not line up too nicely with the headers, but the effect
3318 is relatively readable). */
3320 ui_out_field_skip (uiout
, "addr");
3322 print_expression (b
->exp
, stb
->stream
);
3323 ui_out_field_stream (uiout
, "what", stb
);
3327 case bp_catch_unload
:
3328 /* Field 4, the address, is omitted (which makes the columns
3329 not line up too nicely with the headers, but the effect
3330 is relatively readable). */
3332 ui_out_field_skip (uiout
, "addr");
3334 if (b
->dll_pathname
== NULL
)
3336 ui_out_field_string (uiout
, "what", "<any library>");
3337 ui_out_spaces (uiout
, 1);
3341 ui_out_text (uiout
, "library \"");
3342 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3343 ui_out_text (uiout
, "\" ");
3348 case bp_catch_vfork
:
3349 /* Field 4, the address, is omitted (which makes the columns
3350 not line up too nicely with the headers, but the effect
3351 is relatively readable). */
3353 ui_out_field_skip (uiout
, "addr");
3355 if (b
->forked_inferior_pid
!= 0)
3357 ui_out_text (uiout
, "process ");
3358 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3359 ui_out_spaces (uiout
, 1);
3363 /* Field 4, the address, is omitted (which makes the columns
3364 not line up too nicely with the headers, but the effect
3365 is relatively readable). */
3367 ui_out_field_skip (uiout
, "addr");
3369 if (b
->exec_pathname
!= NULL
)
3371 ui_out_text (uiout
, "program \"");
3372 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3373 ui_out_text (uiout
, "\" ");
3377 case bp_catch_catch
:
3378 /* Field 4, the address, is omitted (which makes the columns
3379 not line up too nicely with the headers, but the effect
3380 is relatively readable). */
3382 ui_out_field_skip (uiout
, "addr");
3384 ui_out_field_string (uiout
, "what", "exception catch");
3385 ui_out_spaces (uiout
, 1);
3388 case bp_catch_throw
:
3389 /* Field 4, the address, is omitted (which makes the columns
3390 not line up too nicely with the headers, but the effect
3391 is relatively readable). */
3393 ui_out_field_skip (uiout
, "addr");
3395 ui_out_field_string (uiout
, "what", "exception throw");
3396 ui_out_spaces (uiout
, 1);
3400 case bp_hardware_breakpoint
:
3404 case bp_longjmp_resume
:
3405 case bp_step_resume
:
3406 case bp_through_sigtramp
:
3407 case bp_watchpoint_scope
:
3409 case bp_shlib_event
:
3410 case bp_thread_event
:
3411 case bp_overlay_event
:
3415 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3418 *last_addr
= b
->address
;
3421 sym
= find_pc_sect_function (b
->address
, b
->section
);
3424 ui_out_text (uiout
, "in ");
3425 ui_out_field_string (uiout
, "func",
3426 SYMBOL_PRINT_NAME (sym
));
3427 ui_out_wrap_hint (uiout
, wrap_indent
);
3428 ui_out_text (uiout
, " at ");
3430 ui_out_field_string (uiout
, "file", b
->source_file
);
3431 ui_out_text (uiout
, ":");
3432 ui_out_field_int (uiout
, "line", b
->line_number
);
3436 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3437 ui_out_field_stream (uiout
, "at", stb
);
3442 if (b
->thread
!= -1)
3444 /* FIXME: This seems to be redundant and lost here; see the
3445 "stop only in" line a little further down. */
3446 ui_out_text (uiout
, " thread ");
3447 ui_out_field_int (uiout
, "thread", b
->thread
);
3450 ui_out_text (uiout
, "\n");
3452 if (frame_id_p (b
->frame_id
))
3455 ui_out_text (uiout
, "\tstop only in stack frame at ");
3456 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3458 ui_out_field_core_addr (uiout
, "frame", b
->frame_id
.stack_addr
);
3459 ui_out_text (uiout
, "\n");
3465 ui_out_text (uiout
, "\tstop only if ");
3466 print_expression (b
->cond
, stb
->stream
);
3467 ui_out_field_stream (uiout
, "cond", stb
);
3468 ui_out_text (uiout
, "\n");
3471 if (b
->thread
!= -1)
3473 /* FIXME should make an annotation for this */
3474 ui_out_text (uiout
, "\tstop only in thread ");
3475 ui_out_field_int (uiout
, "thread", b
->thread
);
3476 ui_out_text (uiout
, "\n");
3479 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3481 /* FIXME should make an annotation for this */
3482 if (ep_is_catchpoint (b
))
3483 ui_out_text (uiout
, "\tcatchpoint");
3485 ui_out_text (uiout
, "\tbreakpoint");
3486 ui_out_text (uiout
, " already hit ");
3487 ui_out_field_int (uiout
, "times", b
->hit_count
);
3488 if (b
->hit_count
== 1)
3489 ui_out_text (uiout
, " time\n");
3491 ui_out_text (uiout
, " times\n");
3494 /* Output the count also if it is zero, but only if this is
3495 mi. FIXME: Should have a better test for this. */
3496 if (ui_out_is_mi_like_p (uiout
))
3497 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3498 ui_out_field_int (uiout
, "times", b
->hit_count
);
3500 if (b
->ignore_count
)
3503 ui_out_text (uiout
, "\tignore next ");
3504 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3505 ui_out_text (uiout
, " hits\n");
3508 if ((l
= b
->commands
))
3510 struct cleanup
*script_chain
;
3513 script_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "script");
3514 print_command_lines (uiout
, l
, 4);
3515 do_cleanups (script_chain
);
3517 do_cleanups (bkpt_chain
);
3518 do_cleanups (old_chain
);
3521 struct captured_breakpoint_query_args
3527 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3529 struct captured_breakpoint_query_args
*args
= data
;
3530 register struct breakpoint
*b
;
3531 CORE_ADDR dummy_addr
= 0;
3534 if (args
->bnum
== b
->number
)
3536 print_one_breakpoint (b
, &dummy_addr
);
3544 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3546 struct captured_breakpoint_query_args args
;
3548 /* For the moment we don't trust print_one_breakpoint() to not throw
3550 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3551 NULL
, RETURN_MASK_ALL
);
3554 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3555 catchpoints, et.al.). */
3558 user_settable_breakpoint (const struct breakpoint
*b
)
3560 return (b
->type
== bp_breakpoint
3561 || b
->type
== bp_catch_load
3562 || b
->type
== bp_catch_unload
3563 || b
->type
== bp_catch_fork
3564 || b
->type
== bp_catch_vfork
3565 || b
->type
== bp_catch_exec
3566 || b
->type
== bp_catch_catch
3567 || b
->type
== bp_catch_throw
3568 || b
->type
== bp_hardware_breakpoint
3569 || b
->type
== bp_watchpoint
3570 || b
->type
== bp_read_watchpoint
3571 || b
->type
== bp_access_watchpoint
3572 || b
->type
== bp_hardware_watchpoint
);
3575 /* Print information on user settable breakpoint (watchpoint, etc)
3576 number BNUM. If BNUM is -1 print all user settable breakpoints.
3577 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3580 breakpoint_1 (int bnum
, int allflag
)
3582 register struct breakpoint
*b
;
3583 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3584 int nr_printable_breakpoints
;
3585 struct cleanup
*bkpttbl_chain
;
3587 /* Compute the number of rows in the table. */
3588 nr_printable_breakpoints
= 0;
3591 || bnum
== b
->number
)
3593 if (allflag
|| user_settable_breakpoint (b
))
3594 nr_printable_breakpoints
++;
3599 = make_cleanup_ui_out_table_begin_end (uiout
, 6, nr_printable_breakpoints
,
3603 = make_cleanup_ui_out_table_begin_end (uiout
, 5, nr_printable_breakpoints
,
3606 if (nr_printable_breakpoints
> 0)
3607 annotate_breakpoints_headers ();
3608 if (nr_printable_breakpoints
> 0)
3610 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3611 if (nr_printable_breakpoints
> 0)
3613 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3614 if (nr_printable_breakpoints
> 0)
3616 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3617 if (nr_printable_breakpoints
> 0)
3619 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3622 if (nr_printable_breakpoints
> 0)
3624 if (TARGET_ADDR_BIT
<= 32)
3625 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3627 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3629 if (nr_printable_breakpoints
> 0)
3631 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3632 ui_out_table_body (uiout
);
3633 if (nr_printable_breakpoints
> 0)
3634 annotate_breakpoints_table ();
3638 || bnum
== b
->number
)
3640 /* We only print out user settable breakpoints unless the
3642 if (allflag
|| user_settable_breakpoint (b
))
3643 print_one_breakpoint (b
, &last_addr
);
3646 do_cleanups (bkpttbl_chain
);
3648 if (nr_printable_breakpoints
== 0)
3651 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3653 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3658 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3659 that a comparison of an unsigned with -1 is always false. */
3660 if (last_addr
!= (CORE_ADDR
) -1)
3661 set_next_address (last_addr
);
3664 /* FIXME? Should this be moved up so that it is only called when
3665 there have been breakpoints? */
3666 annotate_breakpoints_table_end ();
3671 breakpoints_info (char *bnum_exp
, int from_tty
)
3676 bnum
= parse_and_eval_long (bnum_exp
);
3678 breakpoint_1 (bnum
, 0);
3683 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3688 bnum
= parse_and_eval_long (bnum_exp
);
3690 breakpoint_1 (bnum
, 1);
3693 /* Print a message describing any breakpoints set at PC. */
3696 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3698 register int others
= 0;
3699 register struct breakpoint
*b
;
3702 if (b
->address
== pc
) /* address match / overlay match */
3703 if (!overlay_debugging
|| b
->section
== section
)
3707 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3709 if (b
->address
== pc
) /* address match / overlay match */
3710 if (!overlay_debugging
|| b
->section
== section
)
3713 printf_filtered ("%d%s%s ",
3715 ((b
->enable_state
== bp_disabled
||
3716 b
->enable_state
== bp_shlib_disabled
||
3717 b
->enable_state
== bp_call_disabled
)
3719 : b
->enable_state
== bp_permanent
3723 : ((others
== 1) ? " and" : ""));
3725 printf_filtered ("also set at pc ");
3726 print_address_numeric (pc
, 1, gdb_stdout
);
3727 printf_filtered (".\n");
3731 /* Set the default place to put a breakpoint
3732 for the `break' command with no arguments. */
3735 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3738 default_breakpoint_valid
= valid
;
3739 default_breakpoint_address
= addr
;
3740 default_breakpoint_symtab
= symtab
;
3741 default_breakpoint_line
= line
;
3744 /* Return true iff it is meaningful to use the address member of
3745 BPT. For some breakpoint types, the address member is irrelevant
3746 and it makes no sense to attempt to compare it to other addresses
3747 (or use it for any other purpose either).
3749 More specifically, each of the following breakpoint types will always
3750 have a zero valued address and we don't want check_duplicates() to mark
3751 breakpoints of any of these types to be a duplicate of an actual
3752 breakpoint at address zero:
3755 bp_hardware_watchpoint
3757 bp_access_watchpoint
3764 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3766 enum bptype type
= bpt
->type
;
3768 return (type
!= bp_watchpoint
3769 && type
!= bp_hardware_watchpoint
3770 && type
!= bp_read_watchpoint
3771 && type
!= bp_access_watchpoint
3772 && type
!= bp_catch_exec
3773 && type
!= bp_longjmp_resume
3774 && type
!= bp_catch_fork
3775 && type
!= bp_catch_vfork
);
3778 /* Rescan breakpoints at the same address and section as BPT,
3779 marking the first one as "first" and any others as "duplicates".
3780 This is so that the bpt instruction is only inserted once.
3781 If we have a permanent breakpoint at the same place as BPT, make
3782 that one the official one, and the rest as duplicates. */
3785 check_duplicates (struct breakpoint
*bpt
)
3787 register struct breakpoint
*b
;
3788 register int count
= 0;
3789 struct breakpoint
*perm_bp
= 0;
3790 CORE_ADDR address
= bpt
->address
;
3791 asection
*section
= bpt
->section
;
3793 if (! breakpoint_address_is_meaningful (bpt
))
3797 if (b
->enable_state
!= bp_disabled
3798 && b
->enable_state
!= bp_shlib_disabled
3799 && b
->enable_state
!= bp_call_disabled
3800 && b
->address
== address
/* address / overlay match */
3801 && (!overlay_debugging
|| b
->section
== section
)
3802 && breakpoint_address_is_meaningful (b
))
3804 /* Have we found a permanent breakpoint? */
3805 if (b
->enable_state
== bp_permanent
)
3812 b
->duplicate
= count
> 1;
3815 /* If we found a permanent breakpoint at this address, go over the
3816 list again and declare all the other breakpoints there to be the
3820 perm_bp
->duplicate
= 0;
3822 /* Permanent breakpoint should always be inserted. */
3823 if (! perm_bp
->inserted
)
3824 internal_error (__FILE__
, __LINE__
,
3825 "allegedly permanent breakpoint is not "
3826 "actually inserted");
3832 internal_error (__FILE__
, __LINE__
,
3833 "another breakpoint was inserted on top of "
3834 "a permanent breakpoint");
3836 if (b
->enable_state
!= bp_disabled
3837 && b
->enable_state
!= bp_shlib_disabled
3838 && b
->enable_state
!= bp_call_disabled
3839 && b
->address
== address
/* address / overlay match */
3840 && (!overlay_debugging
|| b
->section
== section
)
3841 && breakpoint_address_is_meaningful (b
))
3847 /* set_raw_breakpoint() is a low level routine for allocating and
3848 partially initializing a breakpoint of type BPTYPE. The newly
3849 created breakpoint's address, section, source file name, and line
3850 number are provided by SAL. The newly created and partially
3851 initialized breakpoint is added to the breakpoint chain and
3852 is also returned as the value of this function.
3854 It is expected that the caller will complete the initialization of
3855 the newly created breakpoint struct as well as output any status
3856 information regarding the creation of a new breakpoint. In
3857 particular, set_raw_breakpoint() does NOT set the breakpoint
3858 number! Care should be taken to not allow an error() to occur
3859 prior to completing the initialization of the breakpoint. If this
3860 should happen, a bogus breakpoint will be left on the chain. */
3863 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3865 register struct breakpoint
*b
, *b1
;
3867 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3868 memset (b
, 0, sizeof (*b
));
3869 b
->address
= sal
.pc
;
3870 if (sal
.symtab
== NULL
)
3871 b
->source_file
= NULL
;
3873 b
->source_file
= savestring (sal
.symtab
->filename
,
3874 strlen (sal
.symtab
->filename
));
3875 b
->section
= sal
.section
;
3877 b
->language
= current_language
->la_language
;
3878 b
->input_radix
= input_radix
;
3880 b
->line_number
= sal
.line
;
3881 b
->enable_state
= bp_enabled
;
3884 b
->ignore_count
= 0;
3886 b
->frame_id
= null_frame_id
;
3887 b
->dll_pathname
= NULL
;
3888 b
->triggered_dll_pathname
= NULL
;
3889 b
->forked_inferior_pid
= 0;
3890 b
->exec_pathname
= NULL
;
3893 /* Add this breakpoint to the end of the chain
3894 so that a list of breakpoints will come out in order
3895 of increasing numbers. */
3897 b1
= breakpoint_chain
;
3899 breakpoint_chain
= b
;
3907 check_duplicates (b
);
3908 breakpoints_changed ();
3914 /* Note that the breakpoint object B describes a permanent breakpoint
3915 instruction, hard-wired into the inferior's code. */
3917 make_breakpoint_permanent (struct breakpoint
*b
)
3919 b
->enable_state
= bp_permanent
;
3921 /* By definition, permanent breakpoints are already present in the code. */
3925 static struct breakpoint
*
3926 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3928 static int internal_breakpoint_number
= -1;
3929 struct symtab_and_line sal
;
3930 struct breakpoint
*b
;
3932 init_sal (&sal
); /* initialize to zeroes */
3935 sal
.section
= find_pc_overlay (sal
.pc
);
3937 b
= set_raw_breakpoint (sal
, type
);
3938 b
->number
= internal_breakpoint_number
--;
3939 b
->disposition
= disp_donttouch
;
3946 create_longjmp_breakpoint (char *func_name
)
3948 struct breakpoint
*b
;
3949 struct minimal_symbol
*m
;
3951 if (func_name
== NULL
)
3952 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3955 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3958 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3961 b
->enable_state
= bp_disabled
;
3964 b
->addr_string
= xstrdup (func_name
);
3967 /* Call this routine when stepping and nexting to enable a breakpoint
3968 if we do a longjmp(). When we hit that breakpoint, call
3969 set_longjmp_resume_breakpoint() to figure out where we are going. */
3972 enable_longjmp_breakpoint (void)
3974 register struct breakpoint
*b
;
3977 if (b
->type
== bp_longjmp
)
3979 b
->enable_state
= bp_enabled
;
3980 check_duplicates (b
);
3985 disable_longjmp_breakpoint (void)
3987 register struct breakpoint
*b
;
3990 if (b
->type
== bp_longjmp
3991 || b
->type
== bp_longjmp_resume
)
3993 b
->enable_state
= bp_disabled
;
3994 check_duplicates (b
);
3999 create_overlay_event_breakpoint (char *func_name
)
4001 struct breakpoint
*b
;
4002 struct minimal_symbol
*m
;
4004 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
4007 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
4009 b
->addr_string
= xstrdup (func_name
);
4011 if (overlay_debugging
== ovly_auto
)
4013 b
->enable_state
= bp_enabled
;
4014 overlay_events_enabled
= 1;
4018 b
->enable_state
= bp_disabled
;
4019 overlay_events_enabled
= 0;
4024 enable_overlay_breakpoints (void)
4026 register struct breakpoint
*b
;
4029 if (b
->type
== bp_overlay_event
)
4031 b
->enable_state
= bp_enabled
;
4032 check_duplicates (b
);
4033 overlay_events_enabled
= 1;
4038 disable_overlay_breakpoints (void)
4040 register struct breakpoint
*b
;
4043 if (b
->type
== bp_overlay_event
)
4045 b
->enable_state
= bp_disabled
;
4046 check_duplicates (b
);
4047 overlay_events_enabled
= 0;
4052 create_thread_event_breakpoint (CORE_ADDR address
)
4054 struct breakpoint
*b
;
4056 b
= create_internal_breakpoint (address
, bp_thread_event
);
4058 b
->enable_state
= bp_enabled
;
4059 /* addr_string has to be used or breakpoint_re_set will delete me. */
4060 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->address
));
4066 remove_thread_event_breakpoints (void)
4068 struct breakpoint
*b
, *temp
;
4070 ALL_BREAKPOINTS_SAFE (b
, temp
)
4071 if (b
->type
== bp_thread_event
)
4072 delete_breakpoint (b
);
4077 remove_solib_event_breakpoints (void)
4079 register struct breakpoint
*b
, *temp
;
4081 ALL_BREAKPOINTS_SAFE (b
, temp
)
4082 if (b
->type
== bp_shlib_event
)
4083 delete_breakpoint (b
);
4087 create_solib_event_breakpoint (CORE_ADDR address
)
4089 struct breakpoint
*b
;
4091 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4095 /* Disable any breakpoints that are on code in shared libraries. Only
4096 apply to enabled breakpoints, disabled ones can just stay disabled. */
4099 disable_breakpoints_in_shlibs (int silent
)
4101 struct breakpoint
*b
;
4102 int disabled_shlib_breaks
= 0;
4104 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4107 #if defined (PC_SOLIB)
4108 if (((b
->type
== bp_breakpoint
) ||
4109 (b
->type
== bp_hardware_breakpoint
)) &&
4110 b
->enable_state
== bp_enabled
&&
4112 PC_SOLIB (b
->address
))
4114 b
->enable_state
= bp_shlib_disabled
;
4117 if (!disabled_shlib_breaks
)
4119 target_terminal_ours_for_output ();
4120 warning ("Temporarily disabling shared library breakpoints:");
4122 disabled_shlib_breaks
= 1;
4123 warning ("breakpoint #%d ", b
->number
);
4130 /* Try to reenable any breakpoints in shared libraries. */
4132 re_enable_breakpoints_in_shlibs (void)
4134 struct breakpoint
*b
;
4137 if (b
->enable_state
== bp_shlib_disabled
)
4141 /* Do not reenable the breakpoint if the shared library
4142 is still not mapped in. */
4143 if (target_read_memory (b
->address
, buf
, 1) == 0)
4144 b
->enable_state
= bp_enabled
;
4151 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4152 char *cond_string
, enum bptype bp_kind
)
4154 struct breakpoint
*b
;
4155 struct symtabs_and_lines sals
;
4156 struct cleanup
*old_chain
;
4157 struct cleanup
*canonical_strings_chain
= NULL
;
4158 char *addr_start
= hookname
;
4159 char *addr_end
= NULL
;
4160 char **canonical
= (char **) NULL
;
4161 int thread
= -1; /* All threads. */
4163 /* Set a breakpoint on the specified hook. */
4164 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4165 addr_end
= hookname
;
4167 if (sals
.nelts
== 0)
4169 warning ("Unable to set a breakpoint on dynamic linker callback.");
4170 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4171 warning ("GDB will be unable to track shl_load/shl_unload calls");
4174 if (sals
.nelts
!= 1)
4176 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4177 warning ("GDB will be unable to track shl_load/shl_unload calls");
4181 /* Make sure that all storage allocated in decode_line_1 gets freed
4182 in case the following errors out. */
4183 old_chain
= make_cleanup (xfree
, sals
.sals
);
4184 if (canonical
!= (char **) NULL
)
4186 make_cleanup (xfree
, canonical
);
4187 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4188 if (canonical
[0] != NULL
)
4189 make_cleanup (xfree
, canonical
[0]);
4192 resolve_sal_pc (&sals
.sals
[0]);
4194 /* Remove the canonical strings from the cleanup, they are needed below. */
4195 if (canonical
!= (char **) NULL
)
4196 discard_cleanups (canonical_strings_chain
);
4198 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4199 set_breakpoint_count (breakpoint_count
+ 1);
4200 b
->number
= breakpoint_count
;
4202 b
->cond_string
= (cond_string
== NULL
) ?
4203 NULL
: savestring (cond_string
, strlen (cond_string
));
4206 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4207 b
->addr_string
= canonical
[0];
4208 else if (addr_start
)
4209 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4211 b
->enable_state
= bp_enabled
;
4212 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4214 if (dll_pathname
== NULL
)
4215 b
->dll_pathname
= NULL
;
4218 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4219 strcpy (b
->dll_pathname
, dll_pathname
);
4223 do_cleanups (old_chain
);
4227 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4228 char *dll_pathname
, char *cond_string
)
4230 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4231 cond_string
, bp_catch_load
);
4235 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4236 char *dll_pathname
, char *cond_string
)
4238 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4239 cond_string
, bp_catch_unload
);
4243 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4244 enum bptype bp_kind
)
4246 struct symtab_and_line sal
;
4247 struct breakpoint
*b
;
4248 int thread
= -1; /* All threads. */
4255 b
= set_raw_breakpoint (sal
, bp_kind
);
4256 set_breakpoint_count (breakpoint_count
+ 1);
4257 b
->number
= breakpoint_count
;
4259 b
->cond_string
= (cond_string
== NULL
) ?
4260 NULL
: savestring (cond_string
, strlen (cond_string
));
4262 b
->addr_string
= NULL
;
4263 b
->enable_state
= bp_enabled
;
4264 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4265 b
->forked_inferior_pid
= 0;
4271 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4273 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4277 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4279 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4283 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4285 struct symtab_and_line sal
;
4286 struct breakpoint
*b
;
4287 int thread
= -1; /* All threads. */
4294 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4295 set_breakpoint_count (breakpoint_count
+ 1);
4296 b
->number
= breakpoint_count
;
4298 b
->cond_string
= (cond_string
== NULL
) ?
4299 NULL
: savestring (cond_string
, strlen (cond_string
));
4301 b
->addr_string
= NULL
;
4302 b
->enable_state
= bp_enabled
;
4303 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4309 hw_breakpoint_used_count (void)
4311 register struct breakpoint
*b
;
4316 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4324 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4326 register struct breakpoint
*b
;
4329 *other_type_used
= 0;
4332 if (b
->enable_state
== bp_enabled
)
4334 if (b
->type
== type
)
4336 else if ((b
->type
== bp_hardware_watchpoint
||
4337 b
->type
== bp_read_watchpoint
||
4338 b
->type
== bp_access_watchpoint
)
4339 && b
->enable_state
== bp_enabled
)
4340 *other_type_used
= 1;
4346 /* Call this after hitting the longjmp() breakpoint. Use this to set
4347 a new breakpoint at the target of the jmp_buf.
4349 FIXME - This ought to be done by setting a temporary breakpoint
4350 that gets deleted automatically... */
4353 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_id frame_id
)
4355 register struct breakpoint
*b
;
4358 if (b
->type
== bp_longjmp_resume
)
4361 b
->enable_state
= bp_enabled
;
4362 b
->frame_id
= frame_id
;
4363 check_duplicates (b
);
4369 disable_watchpoints_before_interactive_call_start (void)
4371 struct breakpoint
*b
;
4375 if (((b
->type
== bp_watchpoint
)
4376 || (b
->type
== bp_hardware_watchpoint
)
4377 || (b
->type
== bp_read_watchpoint
)
4378 || (b
->type
== bp_access_watchpoint
)
4379 || ep_is_exception_catchpoint (b
))
4380 && (b
->enable_state
== bp_enabled
))
4382 b
->enable_state
= bp_call_disabled
;
4383 check_duplicates (b
);
4389 enable_watchpoints_after_interactive_call_stop (void)
4391 struct breakpoint
*b
;
4395 if (((b
->type
== bp_watchpoint
)
4396 || (b
->type
== bp_hardware_watchpoint
)
4397 || (b
->type
== bp_read_watchpoint
)
4398 || (b
->type
== bp_access_watchpoint
)
4399 || ep_is_exception_catchpoint (b
))
4400 && (b
->enable_state
== bp_call_disabled
))
4402 b
->enable_state
= bp_enabled
;
4403 check_duplicates (b
);
4409 /* Set a breakpoint that will evaporate an end of command
4410 at address specified by SAL.
4411 Restrict it to frame FRAME if FRAME is nonzero. */
4414 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_id frame_id
,
4417 register struct breakpoint
*b
;
4418 b
= set_raw_breakpoint (sal
, type
);
4419 b
->enable_state
= bp_enabled
;
4420 b
->disposition
= disp_donttouch
;
4421 b
->frame_id
= frame_id
;
4423 /* If we're debugging a multi-threaded program, then we
4424 want momentary breakpoints to be active in only a
4425 single thread of control. */
4426 if (in_thread_list (inferior_ptid
))
4427 b
->thread
= pid_to_thread_id (inferior_ptid
);
4433 /* Tell the user we have just set a breakpoint B. */
4436 mention (struct breakpoint
*b
)
4439 struct cleanup
*old_chain
, *ui_out_chain
;
4440 struct ui_stream
*stb
;
4442 stb
= ui_out_stream_new (uiout
);
4443 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4445 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4446 watchpoint) other than breakpoint creation. It should be possible to
4447 clean this up and at the same time replace the random calls to
4448 breakpoint_changed with this hook, as has already been done for
4449 delete_breakpoint_hook and so on. */
4450 if (create_breakpoint_hook
)
4451 create_breakpoint_hook (b
);
4452 breakpoint_create_event (b
->number
);
4454 if (b
->ops
!= NULL
&& b
->ops
->print_mention
!= NULL
)
4455 b
->ops
->print_mention (b
);
4460 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4463 ui_out_text (uiout
, "Watchpoint ");
4464 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4465 ui_out_field_int (uiout
, "number", b
->number
);
4466 ui_out_text (uiout
, ": ");
4467 print_expression (b
->exp
, stb
->stream
);
4468 ui_out_field_stream (uiout
, "exp", stb
);
4469 do_cleanups (ui_out_chain
);
4471 case bp_hardware_watchpoint
:
4472 ui_out_text (uiout
, "Hardware watchpoint ");
4473 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "wpt");
4474 ui_out_field_int (uiout
, "number", b
->number
);
4475 ui_out_text (uiout
, ": ");
4476 print_expression (b
->exp
, stb
->stream
);
4477 ui_out_field_stream (uiout
, "exp", stb
);
4478 do_cleanups (ui_out_chain
);
4480 case bp_read_watchpoint
:
4481 ui_out_text (uiout
, "Hardware read watchpoint ");
4482 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-rwpt");
4483 ui_out_field_int (uiout
, "number", b
->number
);
4484 ui_out_text (uiout
, ": ");
4485 print_expression (b
->exp
, stb
->stream
);
4486 ui_out_field_stream (uiout
, "exp", stb
);
4487 do_cleanups (ui_out_chain
);
4489 case bp_access_watchpoint
:
4490 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4491 ui_out_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "hw-awpt");
4492 ui_out_field_int (uiout
, "number", b
->number
);
4493 ui_out_text (uiout
, ": ");
4494 print_expression (b
->exp
, stb
->stream
);
4495 ui_out_field_stream (uiout
, "exp", stb
);
4496 do_cleanups (ui_out_chain
);
4499 if (ui_out_is_mi_like_p (uiout
))
4504 printf_filtered ("Breakpoint %d", b
->number
);
4507 case bp_hardware_breakpoint
:
4508 if (ui_out_is_mi_like_p (uiout
))
4513 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4517 case bp_catch_unload
:
4518 printf_filtered ("Catchpoint %d (%s %s)",
4520 (b
->type
== bp_catch_load
) ? "load" : "unload",
4521 (b
->dll_pathname
!= NULL
) ?
4522 b
->dll_pathname
: "<any library>");
4525 case bp_catch_vfork
:
4526 printf_filtered ("Catchpoint %d (%s)",
4528 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4531 printf_filtered ("Catchpoint %d (exec)",
4534 case bp_catch_catch
:
4535 case bp_catch_throw
:
4536 printf_filtered ("Catchpoint %d (%s)",
4538 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4544 case bp_longjmp_resume
:
4545 case bp_step_resume
:
4546 case bp_through_sigtramp
:
4548 case bp_watchpoint_scope
:
4549 case bp_shlib_event
:
4550 case bp_thread_event
:
4551 case bp_overlay_event
:
4557 if (addressprint
|| b
->source_file
== NULL
)
4559 printf_filtered (" at ");
4560 print_address_numeric (b
->address
, 1, gdb_stdout
);
4563 printf_filtered (": file %s, line %d.",
4564 b
->source_file
, b
->line_number
);
4566 do_cleanups (old_chain
);
4567 if (ui_out_is_mi_like_p (uiout
))
4569 printf_filtered ("\n");
4573 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4574 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4575 COND[i] and COND_STRING[i] values.
4577 NOTE: If the function succeeds, the caller is expected to cleanup
4578 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4579 array contents). If the function fails (error() is called), the
4580 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4581 COND and SALS arrays and each of those arrays contents. */
4584 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4585 struct expression
**cond
, char **cond_string
,
4586 enum bptype type
, enum bpdisp disposition
,
4587 int thread
, int ignore_count
, int from_tty
)
4589 if (type
== bp_hardware_breakpoint
)
4591 int i
= hw_breakpoint_used_count ();
4592 int target_resources_ok
=
4593 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4595 if (target_resources_ok
== 0)
4596 error ("No hardware breakpoint support in the target.");
4597 else if (target_resources_ok
< 0)
4598 error ("Hardware breakpoints used exceeds limit.");
4601 /* Now set all the breakpoints. */
4604 for (i
= 0; i
< sals
.nelts
; i
++)
4606 struct breakpoint
*b
;
4607 struct symtab_and_line sal
= sals
.sals
[i
];
4610 describe_other_breakpoints (sal
.pc
, sal
.section
);
4612 b
= set_raw_breakpoint (sal
, type
);
4613 set_breakpoint_count (breakpoint_count
+ 1);
4614 b
->number
= breakpoint_count
;
4618 b
->addr_string
= addr_string
[i
];
4620 /* addr_string has to be used or breakpoint_re_set will delete
4622 xasprintf (&b
->addr_string
, "*0x%s", paddr (b
->address
));
4623 b
->cond_string
= cond_string
[i
];
4624 b
->ignore_count
= ignore_count
;
4625 b
->enable_state
= bp_enabled
;
4626 b
->disposition
= disposition
;
4632 /* Parse ARG which is assumed to be a SAL specification possibly
4633 followed by conditionals. On return, SALS contains an array of SAL
4634 addresses found. ADDR_STRING contains a vector of (canonical)
4635 address strings. ARG points to the end of the SAL. */
4638 parse_breakpoint_sals (char **address
,
4639 struct symtabs_and_lines
*sals
,
4640 char ***addr_string
)
4642 char *addr_start
= *address
;
4643 *addr_string
= NULL
;
4644 /* If no arg given, or if first arg is 'if ', use the default
4646 if ((*address
) == NULL
4647 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4649 if (default_breakpoint_valid
)
4651 struct symtab_and_line sal
;
4652 init_sal (&sal
); /* initialize to zeroes */
4653 sals
->sals
= (struct symtab_and_line
*)
4654 xmalloc (sizeof (struct symtab_and_line
));
4655 sal
.pc
= default_breakpoint_address
;
4656 sal
.line
= default_breakpoint_line
;
4657 sal
.symtab
= default_breakpoint_symtab
;
4658 sal
.section
= find_pc_overlay (sal
.pc
);
4659 sals
->sals
[0] = sal
;
4663 error ("No default breakpoint address now.");
4667 /* Force almost all breakpoints to be in terms of the
4668 current_source_symtab (which is decode_line_1's default). This
4669 should produce the results we want almost all of the time while
4670 leaving default_breakpoint_* alone.
4671 ObjC: However, don't match an Objective-C method name which
4672 may have a '+' or '-' succeeded by a '[' */
4674 struct symtab_and_line cursal
= get_current_source_symtab_and_line ();
4676 if (default_breakpoint_valid
4678 || ((strchr ("+-", (*address
)[0]) != NULL
)
4679 && ((*address
)[1] != '['))))
4680 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4681 default_breakpoint_line
, addr_string
);
4683 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4685 /* For any SAL that didn't have a canonical string, fill one in. */
4686 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4687 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4688 if (addr_start
!= (*address
))
4691 for (i
= 0; i
< sals
->nelts
; i
++)
4693 /* Add the string if not present. */
4694 if ((*addr_string
)[i
] == NULL
)
4695 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4701 /* Convert each SAL into a real PC. Verify that the PC can be
4702 inserted as a breakpoint. If it can't throw an error. */
4705 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4709 for (i
= 0; i
< sals
->nelts
; i
++)
4711 resolve_sal_pc (&sals
->sals
[i
]);
4713 /* It's possible for the PC to be nonzero, but still an illegal
4714 value on some targets.
4716 For example, on HP-UX if you start gdb, and before running the
4717 inferior you try to set a breakpoint on a shared library function
4718 "foo" where the inferior doesn't call "foo" directly but does
4719 pass its address to another function call, then we do find a
4720 minimal symbol for the "foo", but it's address is invalid.
4721 (Appears to be an index into a table that the loader sets up
4722 when the inferior is run.)
4724 Give the target a chance to bless sals.sals[i].pc before we
4725 try to make a breakpoint for it. */
4726 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4728 if (address
== NULL
)
4729 error ("Cannot break without a running program.");
4731 error ("Cannot break on %s without a running program.",
4737 /* Set a breakpoint according to ARG (function, linenum or *address)
4738 flag: first bit : 0 non-temporary, 1 temporary.
4739 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4742 break_command_1 (char *arg
, int flag
, int from_tty
)
4744 int tempflag
, hardwareflag
;
4745 struct symtabs_and_lines sals
;
4746 register struct expression
**cond
= 0;
4747 /* Pointers in arg to the start, and one past the end, of the
4749 char **cond_string
= (char **) NULL
;
4750 char *addr_start
= arg
;
4752 struct cleanup
*old_chain
;
4753 struct cleanup
*breakpoint_chain
= NULL
;
4756 int ignore_count
= 0;
4758 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4759 tempflag
= flag
& BP_TEMPFLAG
;
4764 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4769 /* Create a chain of things that always need to be cleaned up. */
4770 old_chain
= make_cleanup (null_cleanup
, 0);
4772 /* Make sure that all storage allocated to SALS gets freed. */
4773 make_cleanup (xfree
, sals
.sals
);
4775 /* Cleanup the addr_string array but not its contents. */
4776 make_cleanup (xfree
, addr_string
);
4778 /* Allocate space for all the cond expressions. */
4779 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4780 make_cleanup (xfree
, cond
);
4782 /* Allocate space for all the cond strings. */
4783 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4784 make_cleanup (xfree
, cond_string
);
4786 /* ----------------------------- SNIP -----------------------------
4787 Anything added to the cleanup chain beyond this point is assumed
4788 to be part of a breakpoint. If the breakpoint create succeeds
4789 then the memory is not reclaimed. */
4790 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4792 /* Mark the contents of the addr_string for cleanup. These go on
4793 the breakpoint_chain and only occure if the breakpoint create
4795 for (i
= 0; i
< sals
.nelts
; i
++)
4797 if (addr_string
[i
] != NULL
)
4798 make_cleanup (xfree
, addr_string
[i
]);
4801 /* Resolve all line numbers to PC's and verify that the addresses
4802 are ok for the target. */
4803 breakpoint_sals_to_pc (&sals
, addr_start
);
4805 /* Verify that condition can be parsed, before setting any
4806 breakpoints. Allocate a separate condition expression for each
4808 thread
= -1; /* No specific thread yet */
4809 for (i
= 0; i
< sals
.nelts
; i
++)
4816 char *cond_start
= NULL
;
4817 char *cond_end
= NULL
;
4818 while (*tok
== ' ' || *tok
== '\t')
4823 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4826 toklen
= end_tok
- tok
;
4828 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4830 tok
= cond_start
= end_tok
+ 1;
4831 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4832 make_cleanup (xfree
, cond
[i
]);
4834 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4835 make_cleanup (xfree
, cond_string
[i
]);
4837 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4843 thread
= strtol (tok
, &tok
, 0);
4845 error ("Junk after thread keyword.");
4846 if (!valid_thread_id (thread
))
4847 error ("Unknown thread %d\n", thread
);
4850 error ("Junk at end of arguments.");
4854 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4855 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4856 tempflag
? disp_del
: disp_donttouch
,
4857 thread
, ignore_count
, from_tty
);
4861 warning ("Multiple breakpoints were set.");
4862 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4864 /* That's it. Discard the cleanups for data inserted into the
4866 discard_cleanups (breakpoint_chain
);
4867 /* But cleanup everything else. */
4868 do_cleanups (old_chain
);
4871 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4872 linenum or *address) with COND and IGNORE_COUNT. */
4874 struct captured_breakpoint_args
4885 do_captured_breakpoint (void *data
)
4887 struct captured_breakpoint_args
*args
= data
;
4888 struct symtabs_and_lines sals
;
4889 register struct expression
**cond
;
4890 struct cleanup
*old_chain
;
4891 struct cleanup
*breakpoint_chain
= NULL
;
4898 /* Parse the source and lines spec. Delay check that the expression
4899 didn't contain trailing garbage until after cleanups are in
4903 address_end
= args
->address
;
4905 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4910 /* Create a chain of things at always need to be cleaned up. */
4911 old_chain
= make_cleanup (null_cleanup
, 0);
4913 /* Always have a addr_string array, even if it is empty. */
4914 make_cleanup (xfree
, addr_string
);
4916 /* Make sure that all storage allocated to SALS gets freed. */
4917 make_cleanup (xfree
, sals
.sals
);
4919 /* Allocate space for all the cond expressions. */
4920 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4921 make_cleanup (xfree
, cond
);
4923 /* Allocate space for all the cond strings. */
4924 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4925 make_cleanup (xfree
, cond_string
);
4927 /* ----------------------------- SNIP -----------------------------
4928 Anything added to the cleanup chain beyond this point is assumed
4929 to be part of a breakpoint. If the breakpoint create goes
4930 through then that memory is not cleaned up. */
4931 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4933 /* Mark the contents of the addr_string for cleanup. These go on
4934 the breakpoint_chain and only occure if the breakpoint create
4936 for (i
= 0; i
< sals
.nelts
; i
++)
4938 if (addr_string
[i
] != NULL
)
4939 make_cleanup (xfree
, addr_string
[i
]);
4942 /* Wait until now before checking for garbage at the end of the
4943 address. That way cleanups can take care of freeing any
4945 if (*address_end
!= '\0')
4946 error ("Garbage %s following breakpoint address", address_end
);
4948 /* Resolve all line numbers to PC's. */
4949 breakpoint_sals_to_pc (&sals
, args
->address
);
4951 /* Verify that conditions can be parsed, before setting any
4953 for (i
= 0; i
< sals
.nelts
; i
++)
4955 if (args
->condition
!= NULL
)
4957 char *tok
= args
->condition
;
4958 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4960 error ("Garbage %s follows condition", tok
);
4961 make_cleanup (xfree
, cond
[i
]);
4962 cond_string
[i
] = xstrdup (args
->condition
);
4966 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4967 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4968 args
->tempflag
? disp_del
: disp_donttouch
,
4969 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4971 /* That's it. Discard the cleanups for data inserted into the
4973 discard_cleanups (breakpoint_chain
);
4974 /* But cleanup everything else. */
4975 do_cleanups (old_chain
);
4980 gdb_breakpoint (char *address
, char *condition
,
4981 int hardwareflag
, int tempflag
,
4982 int thread
, int ignore_count
)
4984 struct captured_breakpoint_args args
;
4985 args
.address
= address
;
4986 args
.condition
= condition
;
4987 args
.hardwareflag
= hardwareflag
;
4988 args
.tempflag
= tempflag
;
4989 args
.thread
= thread
;
4990 args
.ignore_count
= ignore_count
;
4991 return catch_errors (do_captured_breakpoint
, &args
,
4992 NULL
, RETURN_MASK_ALL
);
4997 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4999 struct frame_info
*frame
;
5000 CORE_ADDR low
, high
, selected_pc
= 0;
5001 char *extra_args
= NULL
;
5003 int extra_args_len
= 0, if_arg
= 0;
5006 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5009 if (default_breakpoint_valid
)
5011 if (deprecated_selected_frame
)
5013 selected_pc
= get_frame_pc (deprecated_selected_frame
);
5018 error ("No selected frame.");
5021 error ("No default breakpoint address now.");
5025 extra_args
= strchr (arg
, ' ');
5029 extra_args_len
= strlen (extra_args
);
5030 level_arg
= (char *) xmalloc (extra_args
- arg
);
5031 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
5032 level_arg
[extra_args
- arg
- 1] = '\0';
5036 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
5037 strcpy (level_arg
, arg
);
5040 frame
= parse_frame_specification (level_arg
);
5042 selected_pc
= get_frame_pc (frame
);
5049 extra_args_len
= strlen (arg
);
5054 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
5058 addr_string
= xstrprintf ("*0x%s %s", paddr_nz (high
), extra_args
);
5060 addr_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5061 break_command_1 (addr_string
, flag
, from_tty
);
5062 xfree (addr_string
);
5065 error ("No function contains the specified address");
5068 error ("Unable to set breakpoint at procedure exit");
5073 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
5075 char *addr_string
, *break_string
, *beg_addr_string
;
5076 CORE_ADDR low
, high
;
5077 struct symtabs_and_lines sals
;
5078 struct symtab_and_line sal
;
5079 struct cleanup
*old_chain
;
5080 char *extra_args
= NULL
;
5081 int extra_args_len
= 0;
5085 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5087 if (default_breakpoint_valid
)
5089 if (deprecated_selected_frame
)
5091 addr_string
= xstrprintf ("*0x%s",
5092 paddr_nz (get_frame_pc (deprecated_selected_frame
)));
5097 error ("No selected frame.");
5100 error ("No default breakpoint address now.");
5104 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5105 strcpy (addr_string
, arg
);
5111 extra_args_len
= strlen (arg
);
5115 /* get the stuff after the function name or address */
5116 extra_args
= strchr (arg
, ' ');
5120 extra_args_len
= strlen (extra_args
);
5127 beg_addr_string
= addr_string
;
5128 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5131 xfree (beg_addr_string
);
5132 old_chain
= make_cleanup (xfree
, sals
.sals
);
5133 for (i
= 0; (i
< sals
.nelts
); i
++)
5136 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5140 break_string
= xstrprintf ("*0x%s %s", paddr_nz (high
),
5143 break_string
= xstrprintf ("*0x%s", paddr_nz (high
));
5144 break_command_1 (break_string
, flag
, from_tty
);
5145 xfree (break_string
);
5148 error ("No function contains the specified address");
5152 warning ("Multiple breakpoints were set.\n");
5153 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5155 do_cleanups (old_chain
);
5159 /* Helper function for break_command_1 and disassemble_command. */
5162 resolve_sal_pc (struct symtab_and_line
*sal
)
5166 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5168 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5169 error ("No line %d in file \"%s\".",
5170 sal
->line
, sal
->symtab
->filename
);
5174 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5176 struct blockvector
*bv
;
5181 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5184 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5185 sym
= block_function (b
);
5188 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5189 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5193 /* It really is worthwhile to have the section, so we'll just
5194 have to look harder. This case can be executed if we have
5195 line numbers but no functions (as can happen in assembly
5198 struct minimal_symbol
*msym
;
5200 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5202 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5209 break_command (char *arg
, int from_tty
)
5211 break_command_1 (arg
, 0, from_tty
);
5215 break_at_finish_command (char *arg
, int from_tty
)
5217 break_at_finish_command_1 (arg
, 0, from_tty
);
5221 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5223 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5227 tbreak_command (char *arg
, int from_tty
)
5229 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5233 tbreak_at_finish_command (char *arg
, int from_tty
)
5235 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5239 hbreak_command (char *arg
, int from_tty
)
5241 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5245 thbreak_command (char *arg
, int from_tty
)
5247 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5251 stop_command (char *arg
, int from_tty
)
5253 printf_filtered ("Specify the type of breakpoint to set.\n\
5254 Usage: stop in <function | address>\n\
5259 stopin_command (char *arg
, int from_tty
)
5263 if (arg
== (char *) NULL
)
5265 else if (*arg
!= '*')
5270 /* look for a ':'. If this is a line number specification, then
5271 say it is bad, otherwise, it should be an address or
5272 function/method name */
5273 while (*argptr
&& !hasColon
)
5275 hasColon
= (*argptr
== ':');
5280 badInput
= (*argptr
!= ':'); /* Not a class::method */
5282 badInput
= isdigit (*arg
); /* a simple line number */
5286 printf_filtered ("Usage: stop in <function | address>\n");
5288 break_command_1 (arg
, 0, from_tty
);
5292 stopat_command (char *arg
, int from_tty
)
5296 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5303 /* look for a ':'. If there is a '::' then get out, otherwise
5304 it is probably a line number. */
5305 while (*argptr
&& !hasColon
)
5307 hasColon
= (*argptr
== ':');
5312 badInput
= (*argptr
== ':'); /* we have class::method */
5314 badInput
= !isdigit (*arg
); /* not a line number */
5318 printf_filtered ("Usage: stop at <line>\n");
5320 break_command_1 (arg
, 0, from_tty
);
5324 /* accessflag: hw_write: watch write,
5325 hw_read: watch read,
5326 hw_access: watch access (read or write) */
5328 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5330 struct breakpoint
*b
;
5331 struct symtab_and_line sal
;
5332 struct expression
*exp
;
5333 struct block
*exp_valid_block
;
5334 struct value
*val
, *mark
;
5335 struct frame_info
*frame
;
5336 struct frame_info
*prev_frame
= NULL
;
5337 char *exp_start
= NULL
;
5338 char *exp_end
= NULL
;
5339 char *tok
, *end_tok
;
5341 char *cond_start
= NULL
;
5342 char *cond_end
= NULL
;
5343 struct expression
*cond
= NULL
;
5344 int i
, other_type_used
, target_resources_ok
= 0;
5345 enum bptype bp_type
;
5348 init_sal (&sal
); /* initialize to zeroes */
5350 /* Parse arguments. */
5351 innermost_block
= NULL
;
5353 exp
= parse_exp_1 (&arg
, 0, 0);
5355 exp_valid_block
= innermost_block
;
5356 mark
= value_mark ();
5357 val
= evaluate_expression (exp
);
5358 release_value (val
);
5359 if (VALUE_LAZY (val
))
5360 value_fetch_lazy (val
);
5363 while (*tok
== ' ' || *tok
== '\t')
5367 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5370 toklen
= end_tok
- tok
;
5371 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5373 tok
= cond_start
= end_tok
+ 1;
5374 cond
= parse_exp_1 (&tok
, 0, 0);
5378 error ("Junk at end of command.");
5380 if (accessflag
== hw_read
)
5381 bp_type
= bp_read_watchpoint
;
5382 else if (accessflag
== hw_access
)
5383 bp_type
= bp_access_watchpoint
;
5385 bp_type
= bp_hardware_watchpoint
;
5387 mem_cnt
= can_use_hardware_watchpoint (val
);
5388 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5389 error ("Expression cannot be implemented with read/access watchpoint.");
5392 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5393 target_resources_ok
=
5394 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5396 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5397 error ("Target does not support this type of hardware watchpoint.");
5399 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5400 error ("Target can only support one kind of HW watchpoint at a time.");
5403 #if defined(HPUXHPPA)
5404 /* On HP-UX if you set a h/w
5405 watchpoint before the "run" command, the inferior dies with a e.g.,
5406 SIGILL once you start it. I initially believed this was due to a
5407 bad interaction between page protection traps and the initial
5408 startup sequence by the dynamic linker.
5410 However, I tried avoiding that by having HP-UX's implementation of
5411 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5412 yet, which forced slow watches before a "run" or "attach", and it
5413 still fails somewhere in the startup code.
5415 Until I figure out what's happening, I'm disallowing watches altogether
5416 before the "run" or "attach" command. We'll tell the user they must
5417 set watches after getting the program started. */
5418 if (!target_has_execution
)
5420 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5423 #endif /* HPUXHPPA */
5425 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5426 watchpoint could not be set. */
5427 if (!mem_cnt
|| target_resources_ok
<= 0)
5428 bp_type
= bp_watchpoint
;
5430 /* Now set up the breakpoint. */
5431 b
= set_raw_breakpoint (sal
, bp_type
);
5432 set_breakpoint_count (breakpoint_count
+ 1);
5433 b
->number
= breakpoint_count
;
5434 b
->disposition
= disp_donttouch
;
5436 b
->exp_valid_block
= exp_valid_block
;
5437 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5441 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5445 frame
= block_innermost_frame (exp_valid_block
);
5448 prev_frame
= get_prev_frame (frame
);
5449 b
->watchpoint_frame
= get_frame_id (frame
);
5453 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5456 /* If the expression is "local", then set up a "watchpoint scope"
5457 breakpoint at the point where we've left the scope of the watchpoint
5459 if (innermost_block
)
5463 struct breakpoint
*scope_breakpoint
;
5464 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5465 bp_watchpoint_scope
);
5467 scope_breakpoint
->enable_state
= bp_enabled
;
5469 /* Automatically delete the breakpoint when it hits. */
5470 scope_breakpoint
->disposition
= disp_del
;
5472 /* Only break in the proper frame (help with recursion). */
5473 scope_breakpoint
->frame_id
= get_frame_id (prev_frame
);
5475 /* Set the address at which we will stop. */
5476 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5478 /* The scope breakpoint is related to the watchpoint. We
5479 will need to act on them together. */
5480 b
->related_breakpoint
= scope_breakpoint
;
5483 value_free_to_mark (mark
);
5487 /* Return count of locations need to be watched and can be handled
5488 in hardware. If the watchpoint can not be handled
5489 in hardware return zero. */
5491 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5492 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5493 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5496 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5497 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5498 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5502 can_use_hardware_watchpoint (struct value
*v
)
5504 int found_memory_cnt
= 0;
5505 struct value
*head
= v
;
5507 /* Did the user specifically forbid us to use hardware watchpoints? */
5508 if (!can_use_hw_watchpoints
)
5511 /* Make sure that the value of the expression depends only upon
5512 memory contents, and values computed from them within GDB. If we
5513 find any register references or function calls, we can't use a
5514 hardware watchpoint.
5516 The idea here is that evaluating an expression generates a series
5517 of values, one holding the value of every subexpression. (The
5518 expression a*b+c has five subexpressions: a, b, a*b, c, and
5519 a*b+c.) GDB's values hold almost enough information to establish
5520 the criteria given above --- they identify memory lvalues,
5521 register lvalues, computed values, etcetera. So we can evaluate
5522 the expression, and then scan the chain of values that leaves
5523 behind to decide whether we can detect any possible change to the
5524 expression's final value using only hardware watchpoints.
5526 However, I don't think that the values returned by inferior
5527 function calls are special in any way. So this function may not
5528 notice that an expression involving an inferior function call
5529 can't be watched with hardware watchpoints. FIXME. */
5530 for (; v
; v
= v
->next
)
5532 if (VALUE_LVAL (v
) == lval_memory
)
5535 /* A lazy memory lvalue is one that GDB never needed to fetch;
5536 we either just used its address (e.g., `a' in `a.b') or
5537 we never needed it at all (e.g., `a' in `a,b'). */
5541 /* Ahh, memory we actually used! Check if we can cover
5542 it with hardware watchpoints. */
5543 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5545 /* We only watch structs and arrays if user asked for it
5546 explicitly, never if they just happen to appear in a
5547 middle of some value chain. */
5549 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5550 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5552 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5553 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5555 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5562 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5563 return 0; /* ??? What does this represent? */
5564 else if (v
->lval
== lval_register
)
5565 return 0; /* cannot watch a register with a HW watchpoint */
5568 /* The expression itself looks suitable for using a hardware
5569 watchpoint, but give the target machine a chance to reject it. */
5570 return found_memory_cnt
;
5574 watch_command_wrapper (char *arg
, int from_tty
)
5576 watch_command (arg
, from_tty
);
5580 watch_command (char *arg
, int from_tty
)
5582 watch_command_1 (arg
, hw_write
, from_tty
);
5586 rwatch_command_wrapper (char *arg
, int from_tty
)
5588 rwatch_command (arg
, from_tty
);
5592 rwatch_command (char *arg
, int from_tty
)
5594 watch_command_1 (arg
, hw_read
, from_tty
);
5598 awatch_command_wrapper (char *arg
, int from_tty
)
5600 awatch_command (arg
, from_tty
);
5604 awatch_command (char *arg
, int from_tty
)
5606 watch_command_1 (arg
, hw_access
, from_tty
);
5610 /* Helper routines for the until_command routine in infcmd.c. Here
5611 because it uses the mechanisms of breakpoints. */
5613 /* This function is called by fetch_inferior_event via the
5614 cmd_continuation pointer, to complete the until command. It takes
5615 care of cleaning up the temporary breakpoints set up by the until
5618 until_break_command_continuation (struct continuation_arg
*arg
)
5620 struct cleanup
*cleanups
;
5622 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5623 do_exec_cleanups (cleanups
);
5628 until_break_command (char *arg
, int from_tty
, int anywhere
)
5630 struct symtabs_and_lines sals
;
5631 struct symtab_and_line sal
;
5632 struct frame_info
*prev_frame
= get_prev_frame (deprecated_selected_frame
);
5633 struct breakpoint
*breakpoint
;
5634 struct cleanup
*old_chain
;
5635 struct continuation_arg
*arg1
;
5638 clear_proceed_status ();
5640 /* Set a breakpoint where the user wants it and at return from
5643 if (default_breakpoint_valid
)
5644 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5645 default_breakpoint_line
, (char ***) NULL
);
5647 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5648 0, (char ***) NULL
);
5650 if (sals
.nelts
!= 1)
5651 error ("Couldn't get information on specified line.");
5654 xfree (sals
.sals
); /* malloc'd, so freed */
5657 error ("Junk at end of arguments.");
5659 resolve_sal_pc (&sal
);
5662 /* If the user told us to continue until a specified location,
5663 we don't specify a frame at which we need to stop. */
5664 breakpoint
= set_momentary_breakpoint (sal
, null_frame_id
, bp_until
);
5666 /* Otherwise, specify the current frame, because we want to stop only
5667 at the very same frame. */
5668 breakpoint
= set_momentary_breakpoint (sal
,
5669 get_frame_id (deprecated_selected_frame
),
5672 if (!event_loop_p
|| !target_can_async_p ())
5673 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5675 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5677 /* If we are running asynchronously, and the target supports async
5678 execution, we are not waiting for the target to stop, in the call
5679 tp proceed, below. This means that we cannot delete the
5680 brekpoints until the target has actually stopped. The only place
5681 where we get a chance to do that is in fetch_inferior_event, so
5682 we must set things up for that. */
5684 if (event_loop_p
&& target_can_async_p ())
5686 /* In this case the arg for the continuation is just the point
5687 in the exec_cleanups chain from where to start doing
5688 cleanups, because all the continuation does is the cleanups in
5689 the exec_cleanup_chain. */
5691 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5693 arg1
->data
.pointer
= old_chain
;
5695 add_continuation (until_break_command_continuation
, arg1
);
5698 /* Keep within the current frame, or in frames called by the current
5702 sal
= find_pc_line (get_frame_pc (prev_frame
), 0);
5703 sal
.pc
= get_frame_pc (prev_frame
);
5704 breakpoint
= set_momentary_breakpoint (sal
, get_frame_id (prev_frame
),
5706 if (!event_loop_p
|| !target_can_async_p ())
5707 make_cleanup_delete_breakpoint (breakpoint
);
5709 make_exec_cleanup_delete_breakpoint (breakpoint
);
5712 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5713 /* Do the cleanups now, anly if we are not running asynchronously,
5714 of if we are, but the target is still synchronous. */
5715 if (!event_loop_p
|| !target_can_async_p ())
5716 do_cleanups (old_chain
);
5720 /* These aren't used; I don't konw what they were for. */
5721 /* Set a breakpoint at the catch clause for NAME. */
5723 catch_breakpoint (char *name
)
5728 disable_catch_breakpoint (void)
5733 delete_catch_breakpoint (void)
5738 enable_catch_breakpoint (void)
5744 ep_skip_leading_whitespace (char **s
)
5746 if ((s
== NULL
) || (*s
== NULL
))
5748 while (isspace (**s
))
5752 /* This function examines a string, and attempts to find a token
5753 that might be an event name in the leading characters. If a
5754 possible match is found, a pointer to the last character of
5755 the token is returned. Else, NULL is returned. */
5758 ep_find_event_name_end (char *arg
)
5761 char *event_name_end
= NULL
;
5763 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5767 /* We break out of the loop when we find a token delimiter.
5768 Basically, we're looking for alphanumerics and underscores;
5769 anything else delimites the token. */
5772 if (!isalnum (*s
) && (*s
!= '_'))
5778 return event_name_end
;
5782 /* This function attempts to parse an optional "if <cond>" clause
5783 from the arg string. If one is not found, it returns NULL.
5785 Else, it returns a pointer to the condition string. (It does not
5786 attempt to evaluate the string against a particular block.) And,
5787 it updates arg to point to the first character following the parsed
5788 if clause in the arg string. */
5791 ep_parse_optional_if_clause (char **arg
)
5795 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5798 /* Skip the "if" keyword. */
5801 /* Skip any extra leading whitespace, and record the start of the
5802 condition string. */
5803 ep_skip_leading_whitespace (arg
);
5806 /* Assume that the condition occupies the remainder of the arg string. */
5807 (*arg
) += strlen (cond_string
);
5812 /* This function attempts to parse an optional filename from the arg
5813 string. If one is not found, it returns NULL.
5815 Else, it returns a pointer to the parsed filename. (This function
5816 makes no attempt to verify that a file of that name exists, or is
5817 accessible.) And, it updates arg to point to the first character
5818 following the parsed filename in the arg string.
5820 Note that clients needing to preserve the returned filename for
5821 future access should copy it to their own buffers. */
5823 ep_parse_optional_filename (char **arg
)
5825 static char filename
[1024];
5830 if ((*arg_p
== '\0') || isspace (*arg_p
))
5848 /* Commands to deal with catching events, such as signals, exceptions,
5849 process start/exit, etc. */
5853 catch_fork
, catch_vfork
5857 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5858 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5859 char *arg
, int tempflag
, int from_tty
);
5862 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5865 char *cond_string
= NULL
;
5867 ep_skip_leading_whitespace (&arg
);
5869 /* The allowed syntax is:
5871 catch [v]fork if <cond>
5873 First, check if there's an if clause. */
5874 cond_string
= ep_parse_optional_if_clause (&arg
);
5876 if ((*arg
!= '\0') && !isspace (*arg
))
5877 error ("Junk at end of arguments.");
5879 /* If this target supports it, create a fork or vfork catchpoint
5880 and enable reporting of such events. */
5884 create_fork_event_catchpoint (tempflag
, cond_string
);
5887 create_vfork_event_catchpoint (tempflag
, cond_string
);
5890 error ("unsupported or unknown fork kind; cannot catch it");
5896 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5898 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5900 char *cond_string
= NULL
;
5902 ep_skip_leading_whitespace (&arg
);
5904 /* The allowed syntax is:
5906 catch exec if <cond>
5908 First, check if there's an if clause. */
5909 cond_string
= ep_parse_optional_if_clause (&arg
);
5911 if ((*arg
!= '\0') && !isspace (*arg
))
5912 error ("Junk at end of arguments.");
5914 /* If this target supports it, create an exec catchpoint
5915 and enable reporting of such events. */
5916 create_exec_event_catchpoint (tempflag
, cond_string
);
5920 #if defined(SOLIB_ADD)
5922 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
5924 char *dll_pathname
= NULL
;
5925 char *cond_string
= NULL
;
5927 ep_skip_leading_whitespace (&arg
);
5929 /* The allowed syntax is:
5931 catch load if <cond>
5932 catch load <filename>
5933 catch load <filename> if <cond>
5935 The user is not allowed to specify the <filename> after an
5938 We'll ignore the pathological case of a file named "if".
5940 First, check if there's an if clause. If so, then there
5941 cannot be a filename. */
5942 cond_string
= ep_parse_optional_if_clause (&arg
);
5944 /* If there was an if clause, then there cannot be a filename.
5945 Else, there might be a filename and an if clause. */
5946 if (cond_string
== NULL
)
5948 dll_pathname
= ep_parse_optional_filename (&arg
);
5949 ep_skip_leading_whitespace (&arg
);
5950 cond_string
= ep_parse_optional_if_clause (&arg
);
5953 if ((*arg
!= '\0') && !isspace (*arg
))
5954 error ("Junk at end of arguments.");
5956 /* Create a load breakpoint that only triggers when a load of
5957 the specified dll (or any dll, if no pathname was specified)
5959 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
5960 dll_pathname
, cond_string
);
5964 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
5966 char *dll_pathname
= NULL
;
5967 char *cond_string
= NULL
;
5969 ep_skip_leading_whitespace (&arg
);
5971 /* The allowed syntax is:
5973 catch unload if <cond>
5974 catch unload <filename>
5975 catch unload <filename> if <cond>
5977 The user is not allowed to specify the <filename> after an
5980 We'll ignore the pathological case of a file named "if".
5982 First, check if there's an if clause. If so, then there
5983 cannot be a filename. */
5984 cond_string
= ep_parse_optional_if_clause (&arg
);
5986 /* If there was an if clause, then there cannot be a filename.
5987 Else, there might be a filename and an if clause. */
5988 if (cond_string
== NULL
)
5990 dll_pathname
= ep_parse_optional_filename (&arg
);
5991 ep_skip_leading_whitespace (&arg
);
5992 cond_string
= ep_parse_optional_if_clause (&arg
);
5995 if ((*arg
!= '\0') && !isspace (*arg
))
5996 error ("Junk at end of arguments.");
5998 /* Create an unload breakpoint that only triggers when an unload of
5999 the specified dll (or any dll, if no pathname was specified)
6001 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6002 dll_pathname
, cond_string
);
6004 #endif /* SOLIB_ADD */
6006 /* Commands to deal with catching exceptions. */
6008 /* Set a breakpoint at the specified callback routine for an
6009 exception event callback */
6012 create_exception_catchpoint (int tempflag
, char *cond_string
,
6013 enum exception_event_kind ex_event
,
6014 struct symtab_and_line
*sal
)
6016 struct breakpoint
*b
;
6017 int thread
= -1; /* All threads. */
6020 if (!sal
) /* no exception support? */
6025 case EX_EVENT_THROW
:
6026 bptype
= bp_catch_throw
;
6028 case EX_EVENT_CATCH
:
6029 bptype
= bp_catch_catch
;
6031 default: /* error condition */
6032 error ("Internal error -- invalid catchpoint kind");
6035 b
= set_raw_breakpoint (*sal
, bptype
);
6036 set_breakpoint_count (breakpoint_count
+ 1);
6037 b
->number
= breakpoint_count
;
6039 b
->cond_string
= (cond_string
== NULL
) ?
6040 NULL
: savestring (cond_string
, strlen (cond_string
));
6042 b
->addr_string
= NULL
;
6043 b
->enable_state
= bp_enabled
;
6044 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6048 static enum print_stop_action
6049 print_exception_catchpoint (struct breakpoint
*b
)
6051 annotate_catchpoint (b
->number
);
6053 if (strstr (b
->addr_string
, "throw") != NULL
)
6054 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6057 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6060 return PRINT_SRC_AND_LOC
;
6064 print_one_exception_catchpoint (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
6069 ui_out_field_core_addr (uiout
, "addr", b
->address
);
6072 *last_addr
= b
->address
;
6073 if (strstr (b
->addr_string
, "throw") != NULL
)
6074 ui_out_field_string (uiout
, "what", "exception throw");
6076 ui_out_field_string (uiout
, "what", "exception catch");
6080 print_mention_exception_catchpoint (struct breakpoint
*b
)
6082 if (strstr (b
->addr_string
, "throw") != NULL
)
6083 printf_filtered ("Catchpoint %d (throw)", b
->number
);
6085 printf_filtered ("Catchpoint %d (catch)", b
->number
);
6088 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops
= {
6089 print_exception_catchpoint
,
6090 print_one_exception_catchpoint
,
6091 print_mention_exception_catchpoint
6095 handle_gnu_v3_exceptions (int tempflag
, char *cond_string
,
6096 enum exception_event_kind ex_event
, int from_tty
)
6098 char *trigger_func_name
, *nameptr
;
6099 struct symtabs_and_lines sals
;
6100 struct breakpoint
*b
;
6102 if (ex_event
== EX_EVENT_CATCH
)
6103 trigger_func_name
= xstrdup ("__cxa_begin_catch");
6105 trigger_func_name
= xstrdup ("__cxa_throw");
6107 nameptr
= trigger_func_name
;
6108 sals
= decode_line_1 (&nameptr
, 1, NULL
, 0, NULL
);
6109 if (sals
.nelts
== 0)
6111 xfree (trigger_func_name
);
6115 b
= set_raw_breakpoint (sals
.sals
[0], bp_breakpoint
);
6116 set_breakpoint_count (breakpoint_count
+ 1);
6117 b
->number
= breakpoint_count
;
6119 b
->cond_string
= (cond_string
== NULL
) ?
6120 NULL
: savestring (cond_string
, strlen (cond_string
));
6122 b
->addr_string
= trigger_func_name
;
6123 b
->enable_state
= bp_enabled
;
6124 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6125 b
->ops
= &gnu_v3_exception_catchpoint_ops
;
6132 /* Deal with "catch catch" and "catch throw" commands */
6135 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6136 int tempflag
, int from_tty
)
6138 char *cond_string
= NULL
;
6139 struct symtab_and_line
*sal
= NULL
;
6141 ep_skip_leading_whitespace (&arg
);
6143 cond_string
= ep_parse_optional_if_clause (&arg
);
6145 if ((*arg
!= '\0') && !isspace (*arg
))
6146 error ("Junk at end of arguments.");
6148 if ((ex_event
!= EX_EVENT_THROW
) &&
6149 (ex_event
!= EX_EVENT_CATCH
))
6150 error ("Unsupported or unknown exception event; cannot catch it");
6152 if (handle_gnu_v3_exceptions (tempflag
, cond_string
, ex_event
, from_tty
))
6155 /* See if we can find a callback routine */
6156 sal
= target_enable_exception_callback (ex_event
, 1);
6160 /* We have callbacks from the runtime system for exceptions.
6161 Set a breakpoint on the sal found, if no errors */
6162 if (sal
!= (struct symtab_and_line
*) -1)
6163 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6165 return; /* something went wrong with setting up callbacks */
6168 warning ("Unsupported with this platform/compiler combination.");
6171 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6172 inside a catch_errors */
6175 cover_target_enable_exception_callback (void *arg
)
6177 args_for_catchpoint_enable
*args
= arg
;
6178 struct symtab_and_line
*sal
;
6179 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6182 else if (sal
== (struct symtab_and_line
*) -1)
6185 return 1; /*is valid */
6189 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6192 /* The first argument may be an event name, such as "start" or "load".
6193 If so, then handle it as such. If it doesn't match an event name,
6194 then attempt to interpret it as an exception name. (This latter is
6195 the v4.16-and-earlier GDB meaning of the "catch" command.)
6197 First, try to find the bounds of what might be an event name. */
6198 char *arg1_start
= arg
;
6202 if (arg1_start
== NULL
)
6204 /* Old behaviour was to use pre-v-4.16 syntax */
6205 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6207 /* Now, this is not allowed */
6208 error ("Catch requires an event name.");
6211 arg1_end
= ep_find_event_name_end (arg1_start
);
6212 if (arg1_end
== NULL
)
6213 error ("catch requires an event");
6214 arg1_length
= arg1_end
+ 1 - arg1_start
;
6216 /* Try to match what we found against known event names. */
6217 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6219 error ("Catch of signal not yet implemented");
6221 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6223 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6224 tempflag
, from_tty
);
6226 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6228 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6229 tempflag
, from_tty
);
6231 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6233 error ("Catch of thread_start not yet implemented");
6235 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6237 error ("Catch of thread_exit not yet implemented");
6239 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6241 error ("Catch of thread_join not yet implemented");
6243 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6245 error ("Catch of start not yet implemented");
6247 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6249 error ("Catch of exit not yet implemented");
6251 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6253 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6254 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6256 error ("Catch of fork not yet implemented");
6259 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6261 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6262 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6264 error ("Catch of vfork not yet implemented");
6267 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6269 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6270 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6272 error ("Catch of exec not yet implemented");
6275 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6277 #if defined(SOLIB_ADD)
6278 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6280 error ("Catch of load not implemented");
6283 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6285 #if defined(SOLIB_ADD)
6286 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6288 error ("Catch of load not implemented");
6291 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6293 error ("Catch of stop not yet implemented");
6296 /* This doesn't appear to be an event name */
6300 /* Pre-v.4.16 behaviour was to treat the argument
6301 as the name of an exception */
6302 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6303 /* Now this is not allowed */
6304 error ("Unknown event kind specified for catch");
6309 /* Used by the gui, could be made a worker for other things. */
6312 set_breakpoint_sal (struct symtab_and_line sal
)
6314 struct breakpoint
*b
;
6315 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6316 set_breakpoint_count (breakpoint_count
+ 1);
6317 b
->number
= breakpoint_count
;
6324 /* These aren't used; I don't know what they were for. */
6325 /* Disable breakpoints on all catch clauses described in ARGS. */
6327 disable_catch (char *args
)
6329 /* Map the disable command to catch clauses described in ARGS. */
6332 /* Enable breakpoints on all catch clauses described in ARGS. */
6334 enable_catch (char *args
)
6336 /* Map the disable command to catch clauses described in ARGS. */
6339 /* Delete breakpoints on all catch clauses in the active scope. */
6341 delete_catch (char *args
)
6343 /* Map the delete command to catch clauses described in ARGS. */
6348 catch_command (char *arg
, int from_tty
)
6350 catch_command_1 (arg
, 0, from_tty
);
6355 tcatch_command (char *arg
, int from_tty
)
6357 catch_command_1 (arg
, 1, from_tty
);
6360 /* Delete breakpoints by address or line. */
6363 clear_command (char *arg
, int from_tty
)
6365 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6367 struct symtabs_and_lines sals
;
6368 struct symtab_and_line sal
;
6373 sals
= decode_line_spec (arg
, 1);
6378 sals
.sals
= (struct symtab_and_line
*)
6379 xmalloc (sizeof (struct symtab_and_line
));
6380 make_cleanup (xfree
, sals
.sals
);
6381 init_sal (&sal
); /* initialize to zeroes */
6382 sal
.line
= default_breakpoint_line
;
6383 sal
.symtab
= default_breakpoint_symtab
;
6384 sal
.pc
= default_breakpoint_address
;
6385 if (sal
.symtab
== 0)
6386 error ("No source file specified.");
6394 /* For each line spec given, delete bps which correspond
6395 to it. Do it in two passes, solely to preserve the current
6396 behavior that from_tty is forced true if we delete more than
6400 for (i
= 0; i
< sals
.nelts
; i
++)
6402 /* If exact pc given, clear bpts at that pc.
6403 If line given (pc == 0), clear all bpts on specified line.
6404 If defaulting, clear all bpts on default line
6407 defaulting sal.pc != 0 tests to do
6412 1 0 <can't happen> */
6417 /* Find all matching breakpoints, remove them from the
6418 breakpoint chain, and add them to the 'found' chain. */
6419 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6421 /* Are we going to delete b? */
6422 if (b
->type
!= bp_none
6423 && b
->type
!= bp_watchpoint
6424 && b
->type
!= bp_hardware_watchpoint
6425 && b
->type
!= bp_read_watchpoint
6426 && b
->type
!= bp_access_watchpoint
6427 /* Not if b is a watchpoint of any sort... */
6428 && (((sal
.pc
&& (b
->address
== sal
.pc
))
6429 && (!section_is_overlay (b
->section
)
6430 || b
->section
== sal
.section
))
6431 /* Yes, if sal.pc matches b (modulo overlays). */
6432 || ((default_match
|| (0 == sal
.pc
))
6433 && b
->source_file
!= NULL
6434 && sal
.symtab
!= NULL
6435 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6436 && b
->line_number
== sal
.line
)))
6437 /* Yes, if sal source file and line matches b. */
6439 /* Remove it from breakpoint_chain... */
6440 if (b
== breakpoint_chain
)
6442 /* b is at the head of the list */
6443 breakpoint_chain
= b
->next
;
6447 prev
->next
= b
->next
;
6449 /* And add it to 'found' chain. */
6455 /* Keep b, and keep a pointer to it. */
6460 /* Now go thru the 'found' chain and delete them. */
6464 error ("No breakpoint at %s.", arg
);
6466 error ("No breakpoint at this line.");
6470 from_tty
= 1; /* Always report if deleted more than one */
6472 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6473 breakpoints_changed ();
6477 printf_unfiltered ("%d ", found
->number
);
6479 delete_breakpoint (found
);
6483 putchar_unfiltered ('\n');
6486 /* Delete breakpoint in BS if they are `delete' breakpoints and
6487 all breakpoints that are marked for deletion, whether hit or not.
6488 This is called after any breakpoint is hit, or after errors. */
6491 breakpoint_auto_delete (bpstat bs
)
6493 struct breakpoint
*b
, *temp
;
6495 for (; bs
; bs
= bs
->next
)
6496 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6498 delete_breakpoint (bs
->breakpoint_at
);
6500 ALL_BREAKPOINTS_SAFE (b
, temp
)
6502 if (b
->disposition
== disp_del_at_next_stop
)
6503 delete_breakpoint (b
);
6507 /* Delete a breakpoint and clean up all traces of it in the data
6511 delete_breakpoint (struct breakpoint
*bpt
)
6513 register struct breakpoint
*b
;
6517 error ("Internal error (attempted to delete a NULL breakpoint)");
6520 /* Has this bp already been deleted? This can happen because multiple
6521 lists can hold pointers to bp's. bpstat lists are especial culprits.
6523 One example of this happening is a watchpoint's scope bp. When the
6524 scope bp triggers, we notice that the watchpoint is out of scope, and
6525 delete it. We also delete its scope bp. But the scope bp is marked
6526 "auto-deleting", and is already on a bpstat. That bpstat is then
6527 checked for auto-deleting bp's, which are deleted.
6529 A real solution to this problem might involve reference counts in bp's,
6530 and/or giving them pointers back to their referencing bpstat's, and
6531 teaching delete_breakpoint to only free a bp's storage when no more
6532 references were extent. A cheaper bandaid was chosen. */
6533 if (bpt
->type
== bp_none
)
6536 if (delete_breakpoint_hook
)
6537 delete_breakpoint_hook (bpt
);
6538 breakpoint_delete_event (bpt
->number
);
6541 remove_breakpoint (bpt
, mark_inserted
);
6543 if (breakpoint_chain
== bpt
)
6544 breakpoint_chain
= bpt
->next
;
6546 /* If we have callback-style exception catchpoints, don't go through
6547 the adjustments to the C++ runtime library etc. if the inferior
6548 isn't actually running. target_enable_exception_callback for a
6549 null target ops vector gives an undesirable error message, so we
6550 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6551 exceptions are supported in this way, it's OK for now. FIXME */
6552 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6554 /* Format possible error msg */
6555 char *message
= xstrprintf ("Error in deleting catchpoint %d:\n",
6557 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6558 args_for_catchpoint_enable args
;
6559 args
.kind
= bpt
->type
== bp_catch_catch
?
6560 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6562 catch_errors (cover_target_enable_exception_callback
, &args
,
6563 message
, RETURN_MASK_ALL
);
6564 do_cleanups (cleanups
);
6571 b
->next
= bpt
->next
;
6575 check_duplicates (bpt
);
6576 /* If this breakpoint was inserted, and there is another breakpoint
6577 at the same address, we need to insert the other breakpoint. */
6579 && bpt
->type
!= bp_hardware_watchpoint
6580 && bpt
->type
!= bp_read_watchpoint
6581 && bpt
->type
!= bp_access_watchpoint
6582 && bpt
->type
!= bp_catch_fork
6583 && bpt
->type
!= bp_catch_vfork
6584 && bpt
->type
!= bp_catch_exec
)
6587 if (b
->address
== bpt
->address
6588 && b
->section
== bpt
->section
6590 && b
->enable_state
!= bp_disabled
6591 && b
->enable_state
!= bp_shlib_disabled
6592 && b
->enable_state
!= bp_call_disabled
)
6596 /* We should never reach this point if there is a permanent
6597 breakpoint at the same address as the one being deleted.
6598 If there is a permanent breakpoint somewhere, it should
6599 always be the only one inserted. */
6600 if (b
->enable_state
== bp_permanent
)
6601 internal_error (__FILE__
, __LINE__
,
6602 "another breakpoint was inserted on top of "
6603 "a permanent breakpoint");
6605 if (b
->type
== bp_hardware_breakpoint
)
6606 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6608 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6610 /* If there was an error in the insert, print a message, then stop execution. */
6613 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6614 make_cleanup_ui_file_delete (tmp_error_stream
);
6617 if (b
->type
== bp_hardware_breakpoint
)
6619 fprintf_unfiltered (tmp_error_stream
,
6620 "Cannot insert hardware breakpoint %d.\n"
6621 "You may have requested too many hardware breakpoints.\n",
6626 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6627 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6628 print_address_numeric (b
->address
, 1, tmp_error_stream
);
6629 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6630 safe_strerror (val
));
6633 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6634 target_terminal_ours_for_output ();
6635 error_stream(tmp_error_stream
);
6642 free_command_lines (&bpt
->commands
);
6645 if (bpt
->cond_string
!= NULL
)
6646 xfree (bpt
->cond_string
);
6647 if (bpt
->addr_string
!= NULL
)
6648 xfree (bpt
->addr_string
);
6649 if (bpt
->exp
!= NULL
)
6651 if (bpt
->exp_string
!= NULL
)
6652 xfree (bpt
->exp_string
);
6653 if (bpt
->val
!= NULL
)
6654 value_free (bpt
->val
);
6655 if (bpt
->source_file
!= NULL
)
6656 xfree (bpt
->source_file
);
6657 if (bpt
->dll_pathname
!= NULL
)
6658 xfree (bpt
->dll_pathname
);
6659 if (bpt
->triggered_dll_pathname
!= NULL
)
6660 xfree (bpt
->triggered_dll_pathname
);
6661 if (bpt
->exec_pathname
!= NULL
)
6662 xfree (bpt
->exec_pathname
);
6664 /* Be sure no bpstat's are pointing at it after it's been freed. */
6665 /* FIXME, how can we find all bpstat's?
6666 We just check stop_bpstat for now. */
6667 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6668 if (bs
->breakpoint_at
== bpt
)
6670 bs
->breakpoint_at
= NULL
;
6672 /* bs->commands will be freed later. */
6674 /* On the chance that someone will soon try again to delete this same
6675 bp, we mark it as deleted before freeing its storage. */
6676 bpt
->type
= bp_none
;
6682 do_delete_breakpoint_cleanup (void *b
)
6684 delete_breakpoint (b
);
6688 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6690 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6694 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6696 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6700 delete_command (char *arg
, int from_tty
)
6702 struct breakpoint
*b
, *temp
;
6708 int breaks_to_delete
= 0;
6710 /* Delete all breakpoints if no argument.
6711 Do not delete internal or call-dummy breakpoints, these
6712 have to be deleted with an explicit breakpoint number argument. */
6715 if (b
->type
!= bp_call_dummy
&&
6716 b
->type
!= bp_shlib_event
&&
6717 b
->type
!= bp_thread_event
&&
6718 b
->type
!= bp_overlay_event
&&
6720 breaks_to_delete
= 1;
6723 /* Ask user only if there are some breakpoints to delete. */
6725 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6727 ALL_BREAKPOINTS_SAFE (b
, temp
)
6729 if (b
->type
!= bp_call_dummy
&&
6730 b
->type
!= bp_shlib_event
&&
6731 b
->type
!= bp_thread_event
&&
6732 b
->type
!= bp_overlay_event
&&
6734 delete_breakpoint (b
);
6739 map_breakpoint_numbers (arg
, delete_breakpoint
);
6742 /* Reset a breakpoint given it's struct breakpoint * BINT.
6743 The value we return ends up being the return value from catch_errors.
6744 Unused in this case. */
6747 breakpoint_re_set_one (void *bint
)
6749 /* get past catch_errs */
6750 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6753 struct symtabs_and_lines sals
;
6755 enum enable_state save_enable
;
6760 warning ("attempted to reset apparently deleted breakpoint #%d?",
6764 case bp_hardware_breakpoint
:
6766 case bp_catch_unload
:
6767 if (b
->addr_string
== NULL
)
6769 /* Anything without a string can't be re-set. */
6770 delete_breakpoint (b
);
6773 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6775 ``And a hack it is, although Apple's Darwin version of GDB
6776 contains an almost identical hack to implement a "future
6777 break" command. It seems to work in many real world cases,
6778 but it is easy to come up with a test case where the patch
6779 doesn't help at all.''
6781 ``It seems that the way GDB implements breakpoints - in -
6782 shared - libraries was designed for a.out shared library
6783 systems (SunOS 4) where shared libraries were loaded at a
6784 fixed address in memory. Since ELF shared libraries can (and
6785 will) be loaded at any address in memory, things break.
6786 Fixing this is not trivial. Therefore, I'm not sure whether
6787 we should add this hack to the branch only. I cannot
6788 guarantee that things will be fixed on the trunk in the near
6791 In case we have a problem, disable this breakpoint. We'll
6792 restore its status if we succeed. Don't disable a
6793 shlib_disabled breakpoint though. There's a fair chance we
6794 can't re-set it if the shared library it's in hasn't been
6796 save_enable
= b
->enable_state
;
6797 if (b
->enable_state
!= bp_shlib_disabled
)
6798 b
->enable_state
= bp_disabled
;
6800 set_language (b
->language
);
6801 input_radix
= b
->input_radix
;
6803 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6804 for (i
= 0; i
< sals
.nelts
; i
++)
6806 resolve_sal_pc (&sals
.sals
[i
]);
6808 /* Reparse conditions, they might contain references to the
6810 if (b
->cond_string
!= NULL
)
6815 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6818 /* We need to re-set the breakpoint if the address changes... */
6819 if (b
->address
!= sals
.sals
[i
].pc
6820 /* ...or new and old breakpoints both have source files, and
6821 the source file name or the line number changes... */
6822 || (b
->source_file
!= NULL
6823 && sals
.sals
[i
].symtab
!= NULL
6824 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6825 || b
->line_number
!= sals
.sals
[i
].line
)
6827 /* ...or we switch between having a source file and not having
6829 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6832 if (b
->source_file
!= NULL
)
6833 xfree (b
->source_file
);
6834 if (sals
.sals
[i
].symtab
== NULL
)
6835 b
->source_file
= NULL
;
6838 savestring (sals
.sals
[i
].symtab
->filename
,
6839 strlen (sals
.sals
[i
].symtab
->filename
));
6840 b
->line_number
= sals
.sals
[i
].line
;
6841 b
->address
= sals
.sals
[i
].pc
;
6843 /* Used to check for duplicates here, but that can
6844 cause trouble, as it doesn't check for disabled
6849 /* Might be better to do this just once per breakpoint_re_set,
6850 rather than once for every breakpoint. */
6851 breakpoints_changed ();
6853 b
->section
= sals
.sals
[i
].section
;
6854 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6857 /* Now that this is re-enabled, check_duplicates
6859 check_duplicates (b
);
6866 case bp_hardware_watchpoint
:
6867 case bp_read_watchpoint
:
6868 case bp_access_watchpoint
:
6869 innermost_block
= NULL
;
6870 /* The issue arises of what context to evaluate this in. The
6871 same one as when it was set, but what does that mean when
6872 symbols have been re-read? We could save the filename and
6873 functionname, but if the context is more local than that, the
6874 best we could do would be something like how many levels deep
6875 and which index at that particular level, but that's going to
6876 be less stable than filenames or function names. */
6878 /* So for now, just use a global context. */
6881 b
->exp
= parse_expression (b
->exp_string
);
6882 b
->exp_valid_block
= innermost_block
;
6883 mark
= value_mark ();
6885 value_free (b
->val
);
6886 b
->val
= evaluate_expression (b
->exp
);
6887 release_value (b
->val
);
6888 if (VALUE_LAZY (b
->val
) && b
->enable_state
== bp_enabled
)
6889 value_fetch_lazy (b
->val
);
6891 if (b
->cond_string
!= NULL
)
6896 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
6898 if (b
->enable_state
== bp_enabled
)
6900 value_free_to_mark (mark
);
6902 case bp_catch_catch
:
6903 case bp_catch_throw
:
6905 /* We needn't really do anything to reset these, since the mask
6906 that requests them is unaffected by e.g., new libraries being
6909 case bp_catch_vfork
:
6914 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
6916 /* Delete longjmp and overlay event breakpoints; they will be
6917 reset later by breakpoint_re_set. */
6919 case bp_longjmp_resume
:
6920 case bp_overlay_event
:
6921 delete_breakpoint (b
);
6924 /* This breakpoint is special, it's set up when the inferior
6925 starts and we really don't want to touch it. */
6926 case bp_shlib_event
:
6928 /* Like bp_shlib_event, this breakpoint type is special.
6929 Once it is set up, we do not want to touch it. */
6930 case bp_thread_event
:
6932 /* Keep temporary breakpoints, which can be encountered when we step
6933 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6934 Otherwise these should have been blown away via the cleanup chain
6935 or by breakpoint_init_inferior when we rerun the executable. */
6938 case bp_watchpoint_scope
:
6940 case bp_step_resume
:
6947 /* Re-set all breakpoints after symbols have been re-loaded. */
6949 breakpoint_re_set (void)
6951 struct breakpoint
*b
, *temp
;
6952 enum language save_language
;
6953 int save_input_radix
;
6955 save_language
= current_language
->la_language
;
6956 save_input_radix
= input_radix
;
6957 ALL_BREAKPOINTS_SAFE (b
, temp
)
6959 /* Format possible error msg */
6960 char *message
= xstrprintf ("Error in re-setting breakpoint %d:\n",
6962 struct cleanup
*cleanups
= make_cleanup (xfree
, message
);
6963 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
6964 do_cleanups (cleanups
);
6966 set_language (save_language
);
6967 input_radix
= save_input_radix
;
6969 if (GET_LONGJMP_TARGET_P ())
6971 create_longjmp_breakpoint ("longjmp");
6972 create_longjmp_breakpoint ("_longjmp");
6973 create_longjmp_breakpoint ("siglongjmp");
6974 create_longjmp_breakpoint ("_siglongjmp");
6975 create_longjmp_breakpoint (NULL
);
6978 create_overlay_event_breakpoint ("_ovly_debug_event");
6981 /* Reset the thread number of this breakpoint:
6983 - If the breakpoint is for all threads, leave it as-is.
6984 - Else, reset it to the current thread for inferior_ptid. */
6986 breakpoint_re_set_thread (struct breakpoint
*b
)
6988 if (b
->thread
!= -1)
6990 if (in_thread_list (inferior_ptid
))
6991 b
->thread
= pid_to_thread_id (inferior_ptid
);
6995 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6996 If from_tty is nonzero, it prints a message to that effect,
6997 which ends with a period (no newline). */
7000 set_ignore_count (int bptnum
, int count
, int from_tty
)
7002 register struct breakpoint
*b
;
7008 if (b
->number
== bptnum
)
7010 b
->ignore_count
= count
;
7014 printf_filtered ("Will stop next time breakpoint %d is reached.",
7016 else if (count
== 1)
7017 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7020 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7023 breakpoints_changed ();
7024 breakpoint_modify_event (b
->number
);
7028 error ("No breakpoint number %d.", bptnum
);
7031 /* Clear the ignore counts of all breakpoints. */
7033 breakpoint_clear_ignore_counts (void)
7035 struct breakpoint
*b
;
7038 b
->ignore_count
= 0;
7041 /* Command to set ignore-count of breakpoint N to COUNT. */
7044 ignore_command (char *args
, int from_tty
)
7050 error_no_arg ("a breakpoint number");
7052 num
= get_number (&p
);
7054 error ("bad breakpoint number: '%s'", args
);
7056 error ("Second argument (specified ignore-count) is missing.");
7058 set_ignore_count (num
,
7059 longest_to_int (value_as_long (parse_and_eval (p
))),
7062 printf_filtered ("\n");
7065 /* Call FUNCTION on each of the breakpoints
7066 whose numbers are given in ARGS. */
7069 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7071 register char *p
= args
;
7074 register struct breakpoint
*b
, *tmp
;
7078 error_no_arg ("one or more breakpoint numbers");
7085 num
= get_number_or_range (&p1
);
7088 warning ("bad breakpoint number at or near '%s'", p
);
7092 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7093 if (b
->number
== num
)
7095 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7098 if (related_breakpoint
)
7099 function (related_breakpoint
);
7103 printf_unfiltered ("No breakpoint number %d.\n", num
);
7109 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7110 If from_tty is nonzero, it prints a message to that effect,
7111 which ends with a period (no newline). */
7114 disable_breakpoint (struct breakpoint
*bpt
)
7116 /* Never disable a watchpoint scope breakpoint; we want to
7117 hit them when we leave scope so we can delete both the
7118 watchpoint and its scope breakpoint at that time. */
7119 if (bpt
->type
== bp_watchpoint_scope
)
7122 /* You can't disable permanent breakpoints. */
7123 if (bpt
->enable_state
== bp_permanent
)
7126 bpt
->enable_state
= bp_disabled
;
7128 check_duplicates (bpt
);
7130 if (modify_breakpoint_hook
)
7131 modify_breakpoint_hook (bpt
);
7132 breakpoint_modify_event (bpt
->number
);
7137 disable_command (char *args
, int from_tty
)
7139 register struct breakpoint
*bpt
;
7141 ALL_BREAKPOINTS (bpt
)
7145 warning ("attempted to disable apparently deleted breakpoint #%d?",
7150 case bp_catch_unload
:
7152 case bp_catch_vfork
:
7154 case bp_catch_catch
:
7155 case bp_catch_throw
:
7156 case bp_hardware_breakpoint
:
7158 case bp_hardware_watchpoint
:
7159 case bp_read_watchpoint
:
7160 case bp_access_watchpoint
:
7161 disable_breakpoint (bpt
);
7166 map_breakpoint_numbers (args
, disable_breakpoint
);
7170 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7172 struct frame_info
*save_selected_frame
= NULL
;
7173 int save_selected_frame_level
= -1;
7174 int target_resources_ok
, other_type_used
;
7177 if (bpt
->type
== bp_hardware_breakpoint
)
7180 i
= hw_breakpoint_used_count ();
7181 target_resources_ok
=
7182 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7184 if (target_resources_ok
== 0)
7185 error ("No hardware breakpoint support in the target.");
7186 else if (target_resources_ok
< 0)
7187 error ("Hardware breakpoints used exceeds limit.");
7190 if (bpt
->enable_state
!= bp_permanent
)
7191 bpt
->enable_state
= bp_enabled
;
7192 bpt
->disposition
= disposition
;
7193 check_duplicates (bpt
);
7194 breakpoints_changed ();
7196 if (bpt
->type
== bp_watchpoint
||
7197 bpt
->type
== bp_hardware_watchpoint
||
7198 bpt
->type
== bp_read_watchpoint
||
7199 bpt
->type
== bp_access_watchpoint
)
7201 if (bpt
->exp_valid_block
!= NULL
)
7203 struct frame_info
*fr
=
7204 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7208 Cannot enable watchpoint %d because the block in which its expression\n\
7209 is valid is not currently in scope.\n", bpt
->number
);
7210 bpt
->enable_state
= bp_disabled
;
7214 save_selected_frame
= deprecated_selected_frame
;
7215 save_selected_frame_level
= frame_relative_level (deprecated_selected_frame
);
7219 value_free (bpt
->val
);
7220 mark
= value_mark ();
7221 bpt
->val
= evaluate_expression (bpt
->exp
);
7222 release_value (bpt
->val
);
7223 if (VALUE_LAZY (bpt
->val
))
7224 value_fetch_lazy (bpt
->val
);
7226 if (bpt
->type
== bp_hardware_watchpoint
||
7227 bpt
->type
== bp_read_watchpoint
||
7228 bpt
->type
== bp_access_watchpoint
)
7230 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7231 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7233 /* Hack around 'unused var' error for some targets here */
7235 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7236 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7237 /* we can consider of type is bp_hardware_watchpoint, convert to
7238 bp_watchpoint in the following condition */
7239 if (target_resources_ok
< 0)
7242 Cannot enable watchpoint %d because target watch resources\n\
7243 have been allocated for other watchpoints.\n", bpt
->number
);
7244 bpt
->enable_state
= bp_disabled
;
7245 value_free_to_mark (mark
);
7250 if (save_selected_frame_level
>= 0)
7251 select_frame (save_selected_frame
);
7252 value_free_to_mark (mark
);
7254 if (modify_breakpoint_hook
)
7255 modify_breakpoint_hook (bpt
);
7256 breakpoint_modify_event (bpt
->number
);
7260 enable_breakpoint (struct breakpoint
*bpt
)
7262 do_enable_breakpoint (bpt
, bpt
->disposition
);
7265 /* The enable command enables the specified breakpoints (or all defined
7266 breakpoints) so they once again become (or continue to be) effective
7267 in stopping the inferior. */
7271 enable_command (char *args
, int from_tty
)
7273 register struct breakpoint
*bpt
;
7275 ALL_BREAKPOINTS (bpt
)
7279 warning ("attempted to enable apparently deleted breakpoint #%d?",
7284 case bp_catch_unload
:
7286 case bp_catch_vfork
:
7288 case bp_catch_catch
:
7289 case bp_catch_throw
:
7290 case bp_hardware_breakpoint
:
7292 case bp_hardware_watchpoint
:
7293 case bp_read_watchpoint
:
7294 case bp_access_watchpoint
:
7295 enable_breakpoint (bpt
);
7300 map_breakpoint_numbers (args
, enable_breakpoint
);
7304 enable_once_breakpoint (struct breakpoint
*bpt
)
7306 do_enable_breakpoint (bpt
, disp_disable
);
7311 enable_once_command (char *args
, int from_tty
)
7313 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7317 enable_delete_breakpoint (struct breakpoint
*bpt
)
7319 do_enable_breakpoint (bpt
, disp_del
);
7324 enable_delete_command (char *args
, int from_tty
)
7326 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7329 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7331 struct symtabs_and_lines
7332 decode_line_spec_1 (char *string
, int funfirstline
)
7334 struct symtabs_and_lines sals
;
7336 error ("Empty line specification.");
7337 if (default_breakpoint_valid
)
7338 sals
= decode_line_1 (&string
, funfirstline
,
7339 default_breakpoint_symtab
,
7340 default_breakpoint_line
,
7343 sals
= decode_line_1 (&string
, funfirstline
,
7344 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7346 error ("Junk at end of line specification: %s", string
);
7351 _initialize_breakpoint (void)
7353 struct cmd_list_element
*c
;
7355 breakpoint_chain
= 0;
7356 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7357 before a breakpoint is set. */
7358 breakpoint_count
= 0;
7360 add_com ("ignore", class_breakpoint
, ignore_command
,
7361 "Set ignore-count of breakpoint number N to COUNT.\n\
7362 Usage is `ignore N COUNT'.");
7364 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7366 add_com ("commands", class_breakpoint
, commands_command
,
7367 "Set commands to be executed when a breakpoint is hit.\n\
7368 Give breakpoint number as argument after \"commands\".\n\
7369 With no argument, the targeted breakpoint is the last one set.\n\
7370 The commands themselves follow starting on the next line.\n\
7371 Type a line containing \"end\" to indicate the end of them.\n\
7372 Give \"silent\" as the first line to make the breakpoint silent;\n\
7373 then no output is printed when it is hit, except what the commands print.");
7375 add_com ("condition", class_breakpoint
, condition_command
,
7376 "Specify breakpoint number N to break only if COND is true.\n\
7377 Usage is `condition N COND', where N is an integer and COND is an\n\
7378 expression to be evaluated whenever breakpoint N is reached.");
7380 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7381 "Set a temporary breakpoint. Args like \"break\" command.\n\
7382 Like \"break\" except the breakpoint is only temporary,\n\
7383 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7384 by using \"enable delete\" on the breakpoint number.");
7385 set_cmd_completer (c
, location_completer
);
7387 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7388 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7389 Like \"break\" except the breakpoint requires hardware support,\n\
7390 some target hardware may not have this support.");
7391 set_cmd_completer (c
, location_completer
);
7393 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7394 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7395 Like \"hbreak\" except the breakpoint is only temporary,\n\
7396 so it will be deleted when hit.");
7397 set_cmd_completer (c
, location_completer
);
7399 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7400 "Enable some breakpoints.\n\
7401 Give breakpoint numbers (separated by spaces) as arguments.\n\
7402 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7403 This is used to cancel the effect of the \"disable\" command.\n\
7404 With a subcommand you can enable temporarily.",
7405 &enablelist
, "enable ", 1, &cmdlist
);
7407 add_com ("ab", class_breakpoint
, enable_command
,
7408 "Enable some breakpoints.\n\
7409 Give breakpoint numbers (separated by spaces) as arguments.\n\
7410 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7411 This is used to cancel the effect of the \"disable\" command.\n\
7412 With a subcommand you can enable temporarily.");
7414 add_com_alias ("en", "enable", class_breakpoint
, 1);
7416 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7417 "Enable some breakpoints.\n\
7418 Give breakpoint numbers (separated by spaces) as arguments.\n\
7419 This is used to cancel the effect of the \"disable\" command.\n\
7420 May be abbreviated to simply \"enable\".\n",
7421 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7423 add_cmd ("once", no_class
, enable_once_command
,
7424 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7425 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7428 add_cmd ("delete", no_class
, enable_delete_command
,
7429 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7430 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7433 add_cmd ("delete", no_class
, enable_delete_command
,
7434 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7435 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7438 add_cmd ("once", no_class
, enable_once_command
,
7439 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7440 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7443 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7444 "Disable some breakpoints.\n\
7445 Arguments are breakpoint numbers with spaces in between.\n\
7446 To disable all breakpoints, give no argument.\n\
7447 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7448 &disablelist
, "disable ", 1, &cmdlist
);
7449 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7450 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7452 add_com ("sb", class_breakpoint
, disable_command
,
7453 "Disable some breakpoints.\n\
7454 Arguments are breakpoint numbers with spaces in between.\n\
7455 To disable all breakpoints, give no argument.\n\
7456 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7458 add_cmd ("breakpoints", class_alias
, disable_command
,
7459 "Disable some breakpoints.\n\
7460 Arguments are breakpoint numbers with spaces in between.\n\
7461 To disable all breakpoints, give no argument.\n\
7462 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7463 This command may be abbreviated \"disable\".",
7466 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7467 "Delete some breakpoints or auto-display expressions.\n\
7468 Arguments are breakpoint numbers with spaces in between.\n\
7469 To delete all breakpoints, give no argument.\n\
7471 Also a prefix command for deletion of other GDB objects.\n\
7472 The \"unset\" command is also an alias for \"delete\".",
7473 &deletelist
, "delete ", 1, &cmdlist
);
7474 add_com_alias ("d", "delete", class_breakpoint
, 1);
7476 add_com ("db", class_breakpoint
, delete_command
,
7477 "Delete some breakpoints.\n\
7478 Arguments are breakpoint numbers with spaces in between.\n\
7479 To delete all breakpoints, give no argument.\n");
7481 add_cmd ("breakpoints", class_alias
, delete_command
,
7482 "Delete some breakpoints or auto-display expressions.\n\
7483 Arguments are breakpoint numbers with spaces in between.\n\
7484 To delete all breakpoints, give no argument.\n\
7485 This command may be abbreviated \"delete\".",
7488 add_com ("clear", class_breakpoint
, clear_command
,
7489 concat ("Clear breakpoint at specified line or function.\n\
7490 Argument may be line number, function name, or \"*\" and an address.\n\
7491 If line number is specified, all breakpoints in that line are cleared.\n\
7492 If function is specified, breakpoints at beginning of function are cleared.\n\
7493 If an address is specified, breakpoints at that address are cleared.\n\n",
7494 "With no argument, clears all breakpoints in the line that the selected frame\n\
7497 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7499 c
= add_com ("break", class_breakpoint
, break_command
,
7500 concat ("Set breakpoint at specified line or function.\n\
7501 Argument may be line number, function name, or \"*\" and an address.\n\
7502 If line number is specified, break at start of code for that line.\n\
7503 If function is specified, break at start of code for that function.\n\
7504 If an address is specified, break at that exact address.\n",
7505 "With no arg, uses current execution address of selected stack frame.\n\
7506 This is useful for breaking on return to a stack frame.\n\
7508 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7510 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7511 set_cmd_completer (c
, location_completer
);
7513 add_com_alias ("b", "break", class_run
, 1);
7514 add_com_alias ("br", "break", class_run
, 1);
7515 add_com_alias ("bre", "break", class_run
, 1);
7516 add_com_alias ("brea", "break", class_run
, 1);
7520 add_com_alias ("ba", "break", class_breakpoint
, 1);
7521 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7526 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7527 "Break in function/address or break at a line in the current file.",
7528 &stoplist
, "stop ", 1, &cmdlist
);
7529 add_cmd ("in", class_breakpoint
, stopin_command
,
7530 "Break in function or address.\n", &stoplist
);
7531 add_cmd ("at", class_breakpoint
, stopat_command
,
7532 "Break at a line in the current file.\n", &stoplist
);
7533 add_com ("status", class_info
, breakpoints_info
,
7534 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7535 The \"Type\" column indicates one of:\n\
7536 \tbreakpoint - normal breakpoint\n\
7537 \twatchpoint - watchpoint\n\
7538 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7539 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7540 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7541 address and file/line number respectively.\n\n",
7542 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7543 are set to the address of the last breakpoint listed.\n\n\
7544 Convenience variable \"$bpnum\" contains the number of the last\n\
7545 breakpoint set.", NULL
));
7548 add_info ("breakpoints", breakpoints_info
,
7549 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7550 The \"Type\" column indicates one of:\n\
7551 \tbreakpoint - normal breakpoint\n\
7552 \twatchpoint - watchpoint\n\
7553 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7554 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7555 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7556 address and file/line number respectively.\n\n",
7557 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7558 are set to the address of the last breakpoint listed.\n\n\
7559 Convenience variable \"$bpnum\" contains the number of the last\n\
7560 breakpoint set.", NULL
));
7563 add_com ("lb", class_breakpoint
, breakpoints_info
,
7564 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7565 The \"Type\" column indicates one of:\n\
7566 \tbreakpoint - normal breakpoint\n\
7567 \twatchpoint - watchpoint\n\
7568 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7569 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7570 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7571 address and file/line number respectively.\n\n",
7572 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7573 are set to the address of the last breakpoint listed.\n\n\
7574 Convenience variable \"$bpnum\" contains the number of the last\n\
7575 breakpoint set.", NULL
));
7577 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7578 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7579 The \"Type\" column indicates one of:\n\
7580 \tbreakpoint - normal breakpoint\n\
7581 \twatchpoint - watchpoint\n\
7582 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7583 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7584 \tuntil - internal breakpoint used by the \"until\" command\n\
7585 \tfinish - internal breakpoint used by the \"finish\" command\n",
7586 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7587 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7588 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7589 address and file/line number respectively.\n\n",
7590 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7591 are set to the address of the last breakpoint listed.\n\n\
7592 Convenience variable \"$bpnum\" contains the number of the last\n\
7593 breakpoint set.", NULL
),
7594 &maintenanceinfolist
);
7596 add_com ("catch", class_breakpoint
, catch_command
,
7597 "Set catchpoints to catch events.\n\
7598 Raised signals may be caught:\n\
7599 \tcatch signal - all signals\n\
7600 \tcatch signal <signame> - a particular signal\n\
7601 Raised exceptions may be caught:\n\
7602 \tcatch throw - all exceptions, when thrown\n\
7603 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7604 \tcatch catch - all exceptions, when caught\n\
7605 \tcatch catch <exceptname> - a particular exception, when caught\n\
7606 Thread or process events may be caught:\n\
7607 \tcatch thread_start - any threads, just after creation\n\
7608 \tcatch thread_exit - any threads, just before expiration\n\
7609 \tcatch thread_join - any threads, just after joins\n\
7610 Process events may be caught:\n\
7611 \tcatch start - any processes, just after creation\n\
7612 \tcatch exit - any processes, just before expiration\n\
7613 \tcatch fork - calls to fork()\n\
7614 \tcatch vfork - calls to vfork()\n\
7615 \tcatch exec - calls to exec()\n\
7616 Dynamically-linked library events may be caught:\n\
7617 \tcatch load - loads of any library\n\
7618 \tcatch load <libname> - loads of a particular library\n\
7619 \tcatch unload - unloads of any library\n\
7620 \tcatch unload <libname> - unloads of a particular library\n\
7621 The act of your program's execution stopping may also be caught:\n\
7623 C++ exceptions may be caught:\n\
7624 \tcatch throw - all exceptions, when thrown\n\
7625 \tcatch catch - all exceptions, when caught\n\
7627 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7628 after a fork or vfork is caught.\n\n\
7629 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7631 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7632 "Set temporary catchpoints to catch events.\n\
7633 Args like \"catch\" command.\n\
7634 Like \"catch\" except the catchpoint is only temporary,\n\
7635 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7636 by using \"enable delete\" on the catchpoint number.");
7638 c
= add_com ("watch", class_breakpoint
, watch_command
,
7639 "Set a watchpoint for an expression.\n\
7640 A watchpoint stops execution of your program whenever the value of\n\
7641 an expression changes.");
7642 set_cmd_completer (c
, location_completer
);
7644 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7645 "Set a read watchpoint for an expression.\n\
7646 A watchpoint stops execution of your program whenever the value of\n\
7647 an expression is read.");
7648 set_cmd_completer (c
, location_completer
);
7650 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7651 "Set a watchpoint for an expression.\n\
7652 A watchpoint stops execution of your program whenever the value of\n\
7653 an expression is either read or written.");
7654 set_cmd_completer (c
, location_completer
);
7656 add_info ("watchpoints", breakpoints_info
,
7657 "Synonym for ``info breakpoints''.");
7660 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7661 (char *) &can_use_hw_watchpoints
,
7662 "Set debugger's willingness to use watchpoint hardware.\n\
7663 If zero, gdb will not use hardware for new watchpoints, even if\n\
7664 such is available. (However, any hardware watchpoints that were\n\
7665 created before setting this to nonzero, will continue to use watchpoint\n\
7668 add_show_from_set (c
, &showlist
);
7670 can_use_hw_watchpoints
= 1;