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 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"
45 #include "completer.h"
49 #include "gdb-events.h"
51 /* Prototypes for local functions. */
53 static void until_break_command_continuation (struct continuation_arg
*arg
);
55 static void catch_command_1 (char *, int, int);
57 static void enable_delete_command (char *, int);
59 static void enable_delete_breakpoint (struct breakpoint
*);
61 static void enable_once_command (char *, int);
63 static void enable_once_breakpoint (struct breakpoint
*);
65 static void disable_command (char *, int);
67 static void enable_command (char *, int);
69 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint
*));
71 static void ignore_command (char *, int);
73 static int breakpoint_re_set_one (PTR
);
75 static void clear_command (char *, int);
77 static void catch_command (char *, int);
79 static void handle_gnu_4_16_catch_command (char *, int, int);
81 static struct symtabs_and_lines
get_catch_sals (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 (PTR
);
110 static void cleanup_executing_breakpoints (PTR
);
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 (PTR
);
142 static int cover_target_enable_exception_callback (PTR
);
144 static void maintenance_info_breakpoints (char *, int);
146 static void create_longjmp_breakpoint (char *);
148 static void create_overlay_event_breakpoint (char *);
150 static int hw_breakpoint_used_count (void);
152 static int hw_watchpoint_used_count (enum bptype
, int *);
154 static void hbreak_command (char *, int);
156 static void thbreak_command (char *, int);
158 static void watch_command_1 (char *, int, int);
160 static void rwatch_command (char *, int);
162 static void awatch_command (char *, int);
164 static void do_enable_breakpoint (struct breakpoint
*, enum bpdisp
);
166 static void solib_load_unload_1 (char *hookname
,
169 char *cond_string
, enum bptype bp_kind
);
171 static void create_fork_vfork_event_catchpoint (int tempflag
,
173 enum bptype bp_kind
);
175 static void break_at_finish_at_depth_command_1 (char *arg
,
176 int flag
, int from_tty
);
178 static void break_at_finish_command_1 (char *arg
, int flag
, int from_tty
);
180 static void stop_command (char *arg
, int from_tty
);
182 static void stopin_command (char *arg
, int from_tty
);
184 static void stopat_command (char *arg
, int from_tty
);
186 static char *ep_find_event_name_end (char *arg
);
188 static char *ep_parse_optional_if_clause (char **arg
);
190 static char *ep_parse_optional_filename (char **arg
);
192 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
);
196 static void create_exception_catchpoint (int tempflag
, char *cond_string
,
197 enum exception_event_kind ex_event
,
198 struct symtab_and_line
*sal
);
200 static void catch_exception_command_1 (enum exception_event_kind ex_event
,
201 char *arg
, int tempflag
, int from_tty
);
203 static void tcatch_command (char *arg
, int from_tty
);
205 static void ep_skip_leading_whitespace (char **s
);
207 /* Prototypes for exported functions. */
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints
;
213 void _initialize_breakpoint (void);
215 extern int addressprint
; /* Print machine addresses? */
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands
;
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled
;
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
234 /* True if SHIFT_INST_REGS defined, false otherwise. */
236 int must_shift_inst_regs
=
237 #if defined(SHIFT_INST_REGS)
244 /* True if breakpoint hit counts should be displayed in breakpoint info. */
246 int show_breakpoint_hit_counts
= 1;
248 /* Chain of all breakpoints defined. */
250 struct breakpoint
*breakpoint_chain
;
252 /* Number of last breakpoint made. */
254 int breakpoint_count
;
256 /* Pointer to current exception event record */
257 static struct exception_event_record
*current_exception_event
;
259 /* Indicator of whether exception catchpoints should be nuked
260 between runs of a program */
261 int exception_catchpoints_are_fragile
= 0;
263 /* Indicator of when exception catchpoints set-up should be
264 reinitialized -- e.g. when program is re-run */
265 int exception_support_initialized
= 0;
267 /* This function returns a pointer to the string representation of the
268 pathname of the dynamically-linked library that has just been
271 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
272 or undefined results are guaranteed.
274 This string's contents are only valid immediately after the
275 inferior has stopped in the dynamic linker hook, and becomes
276 invalid as soon as the inferior is continued. Clients should make
277 a copy of this string if they wish to continue the inferior and
278 then access the string. */
280 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
281 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
284 /* This function returns a pointer to the string representation of the
285 pathname of the dynamically-linked library that has just been
288 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
289 TRUE, or undefined results are guaranteed.
291 This string's contents are only valid immediately after the
292 inferior has stopped in the dynamic linker hook, and becomes
293 invalid as soon as the inferior is continued. Clients should make
294 a copy of this string if they wish to continue the inferior and
295 then access the string. */
297 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
298 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
301 /* This function is called by the "catch load" command. It allows the
302 debugger to be notified by the dynamic linker when a specified
303 library file (or any library file, if filename is NULL) is loaded. */
305 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
306 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
307 error ("catch of library loads not yet implemented on this platform")
310 /* This function is called by the "catch unload" command. It allows
311 the debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is
315 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
316 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library unloads not yet implemented on this platform")
320 /* Set breakpoint count to NUM. */
323 set_breakpoint_count (int num
)
325 breakpoint_count
= num
;
326 set_internalvar (lookup_internalvar ("bpnum"),
327 value_from_longest (builtin_type_int
, (LONGEST
) num
));
330 /* Used in run_command to zero the hit count when a new run starts. */
333 clear_breakpoint_hit_counts (void)
335 struct breakpoint
*b
;
341 /* Default address, symtab and line to put a breakpoint at
342 for "break" command with no arg.
343 if default_breakpoint_valid is zero, the other three are
344 not valid, and "break" with no arg is an error.
346 This set by print_stack_frame, which calls set_default_breakpoint. */
348 int default_breakpoint_valid
;
349 CORE_ADDR default_breakpoint_address
;
350 struct symtab
*default_breakpoint_symtab
;
351 int default_breakpoint_line
;
353 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
354 Advance *PP after the string and any trailing whitespace.
356 Currently the string can either be a number or "$" followed by the name
357 of a convenience variable. Making it an expression wouldn't work well
358 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
360 TRAILER is a character which can be found after the number; most
361 commonly this is `-'. If you don't want a trailer, use \0. */
363 get_number_trailer (char **pp
, int trailer
)
365 int retval
= 0; /* default */
369 /* Empty line means refer to the last breakpoint. */
370 return breakpoint_count
;
373 /* Make a copy of the name, so we can null-terminate it
374 to pass to lookup_internalvar(). */
379 while (isalnum (*p
) || *p
== '_')
381 varname
= (char *) alloca (p
- start
+ 1);
382 strncpy (varname
, start
, p
- start
);
383 varname
[p
- start
] = '\0';
384 val
= value_of_internalvar (lookup_internalvar (varname
));
385 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
)
386 retval
= (int) value_as_long (val
);
389 printf_filtered ("Convenience variable must have integer value.\n");
397 while (*p
>= '0' && *p
<= '9')
400 /* There is no number here. (e.g. "cond a == b"). */
402 /* Skip non-numeric token */
403 while (*p
&& !isspace((int) *p
))
405 /* Return zero, which caller must interpret as error. */
411 if (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
413 /* Trailing junk: return 0 and let caller print error msg. */
414 while (!(isspace (*p
) || *p
== '\0' || *p
== trailer
))
425 /* Like get_number_trailer, but don't allow a trailer. */
427 get_number (char **pp
)
429 return get_number_trailer (pp
, '\0');
432 /* Parse a number or a range.
433 * A number will be of the form handled by get_number.
434 * A range will be of the form <number1> - <number2>, and
435 * will represent all the integers between number1 and number2,
438 * While processing a range, this fuction is called iteratively;
439 * At each call it will return the next value in the range.
441 * At the beginning of parsing a range, the char pointer PP will
442 * be advanced past <number1> and left pointing at the '-' token.
443 * Subsequent calls will not advance the pointer until the range
444 * is completed. The call that completes the range will advance
445 * pointer PP past <number2>.
449 get_number_or_range (char **pp
)
451 static int last_retval
, end_value
;
452 static char *end_ptr
;
453 static int in_range
= 0;
457 /* Default case: pp is pointing either to a solo number,
458 or to the first number of a range. */
459 last_retval
= get_number_trailer (pp
, '-');
464 /* This is the start of a range (<number1> - <number2>).
465 Skip the '-', parse and remember the second number,
466 and also remember the end of the final token. */
470 while (isspace ((int) *end_ptr
))
471 end_ptr
++; /* skip white space */
472 end_value
= get_number (temp
);
473 if (end_value
< last_retval
)
475 error ("inverted range");
477 else if (end_value
== last_retval
)
479 /* degenerate range (number1 == number2). Advance the
480 token pointer so that the range will be treated as a
489 error ("negative value");
492 /* pp points to the '-' that betokens a range. All
493 number-parsing has already been done. Return the next
494 integer value (one greater than the saved previous value).
495 Do not advance the token pointer 'pp' until the end of range
498 if (++last_retval
== end_value
)
500 /* End of range reached; advance token pointer. */
510 /* condition N EXP -- set break condition of breakpoint N to EXP. */
513 condition_command (char *arg
, int from_tty
)
515 register struct breakpoint
*b
;
520 error_no_arg ("breakpoint number");
523 bnum
= get_number (&p
);
525 error ("Bad breakpoint argument: '%s'", arg
);
528 if (b
->number
== bnum
)
535 if (b
->cond_string
!= NULL
)
536 xfree (b
->cond_string
);
541 b
->cond_string
= NULL
;
543 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
548 /* I don't know if it matters whether this is the string the user
549 typed in or the decompiled expression. */
550 b
->cond_string
= savestring (arg
, strlen (arg
));
551 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
553 error ("Junk at end of expression");
555 breakpoints_changed ();
556 breakpoint_modify_event (b
->number
);
560 error ("No breakpoint number %d.", bnum
);
565 commands_command (char *arg
, int from_tty
)
567 register struct breakpoint
*b
;
570 struct command_line
*l
;
572 /* If we allowed this, we would have problems with when to
573 free the storage, if we change the commands currently
576 if (executing_breakpoint_commands
)
577 error ("Can't use the \"commands\" command among a breakpoint's commands.");
580 bnum
= get_number (&p
);
583 error ("Unexpected extra arguments following breakpoint number.");
586 if (b
->number
== bnum
)
590 "Type commands for when breakpoint %d is hit, one per line.",
592 l
= read_command_lines (tmpbuf
, from_tty
);
593 free_command_lines (&b
->commands
);
595 breakpoints_changed ();
596 breakpoint_modify_event (b
->number
);
599 error ("No breakpoint number %d.", bnum
);
602 /* Like target_read_memory() but if breakpoints are inserted, return
603 the shadow contents instead of the breakpoints themselves.
605 Read "memory data" from whatever target or inferior we have.
606 Returns zero if successful, errno value if not. EIO is used
607 for address out of bounds. If breakpoints are inserted, returns
608 shadow contents, not the breakpoints themselves. From breakpoint.c. */
611 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
614 struct breakpoint
*b
;
615 CORE_ADDR bp_addr
= 0;
618 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
619 /* No breakpoints on this machine. */
620 return target_read_memory (memaddr
, myaddr
, len
);
624 if (b
->type
== bp_none
)
625 warning ("reading through apparently deleted breakpoint #%d?",
628 /* memory breakpoint? */
629 if (b
->type
== bp_watchpoint
630 || b
->type
== bp_hardware_watchpoint
631 || b
->type
== bp_read_watchpoint
632 || b
->type
== bp_access_watchpoint
)
637 /* Addresses and length of the part of the breakpoint that
639 /* XXXX The m68k, sh and h8300 have different local and remote
640 breakpoint values. BREAKPOINT_FROM_PC still manages to
641 correctly determine the breakpoints memory address and size
642 for these targets. */
643 bp_addr
= b
->address
;
645 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
650 if (bp_addr
+ bp_size
<= memaddr
)
651 /* The breakpoint is entirely before the chunk of memory we
654 if (bp_addr
>= memaddr
+ len
)
655 /* The breakpoint is entirely after the chunk of memory we are
658 /* Copy the breakpoint from the shadow contents, and recurse for
659 the things before and after. */
661 /* Offset within shadow_contents. */
664 if (bp_addr
< memaddr
)
666 /* Only copy the second part of the breakpoint. */
667 bp_size
-= memaddr
- bp_addr
;
668 bptoffset
= memaddr
- bp_addr
;
672 if (bp_addr
+ bp_size
> memaddr
+ len
)
674 /* Only copy the first part of the breakpoint. */
675 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
678 memcpy (myaddr
+ bp_addr
- memaddr
,
679 b
->shadow_contents
+ bptoffset
, bp_size
);
681 if (bp_addr
> memaddr
)
683 /* Copy the section of memory before the breakpoint. */
684 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
689 if (bp_addr
+ bp_size
< memaddr
+ len
)
691 /* Copy the section of memory after the breakpoint. */
692 status
= read_memory_nobpt (bp_addr
+ bp_size
,
693 myaddr
+ bp_addr
+ bp_size
- memaddr
,
694 memaddr
+ len
- (bp_addr
+ bp_size
));
701 /* Nothing overlaps. Just call read_memory_noerr. */
702 return target_read_memory (memaddr
, myaddr
, len
);
706 /* insert_breakpoints is used when starting or continuing the program.
707 remove_breakpoints is used when the program stops.
708 Both return zero if successful,
709 or an `errno' value if could not write the inferior. */
712 insert_breakpoints (void)
714 register struct breakpoint
*b
, *temp
;
715 int return_val
= 0; /* return success code. */
717 int disabled_breaks
= 0;
718 int hw_breakpoint_error
= 0;
719 int process_warning
= 0;
721 static char message1
[] = "Error inserting catchpoint %d:\n";
722 static char message
[sizeof (message1
) + 30];
724 #ifdef ONE_PROCESS_WRITETEXT
728 struct ui_file
*tmp_error_stream
= mem_fileopen ();
729 make_cleanup_ui_file_delete (tmp_error_stream
);
731 /* Explicitly mark the warning -- this will only be printed if
732 there was an error. */
733 fprintf_unfiltered (tmp_error_stream
, "Warning:\n");
735 ALL_BREAKPOINTS_SAFE (b
, temp
)
737 if (b
->enable_state
== bp_permanent
)
738 /* Permanent breakpoints cannot be inserted or removed. */
740 else if (b
->type
!= bp_watchpoint
741 && b
->type
!= bp_hardware_watchpoint
742 && b
->type
!= bp_read_watchpoint
743 && b
->type
!= bp_access_watchpoint
744 && b
->type
!= bp_catch_fork
745 && b
->type
!= bp_catch_vfork
746 && b
->type
!= bp_catch_exec
747 && b
->type
!= bp_catch_throw
748 && b
->type
!= bp_catch_catch
749 && b
->enable_state
!= bp_disabled
750 && b
->enable_state
!= bp_shlib_disabled
751 && b
->enable_state
!= bp_call_disabled
755 /* "Normal" instruction breakpoint: either the standard
756 trap-instruction bp (bp_breakpoint), or a
757 bp_hardware_breakpoint. */
759 /* First check to see if we have to handle an overlay. */
760 if (overlay_debugging
== ovly_off
761 || b
->section
== NULL
762 || !(section_is_overlay (b
->section
)))
764 /* No overlay handling: just set the breakpoint. */
766 if (b
->type
== bp_hardware_breakpoint
)
767 val
= target_insert_hw_breakpoint (b
->address
,
770 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
774 /* This breakpoint is in an overlay section.
775 Shall we set a breakpoint at the LMA? */
776 if (!overlay_events_enabled
)
778 /* Yes -- overlay event support is not active,
779 so we must try to set a breakpoint at the LMA.
780 This will not work for a hardware breakpoint. */
781 if (b
->type
== bp_hardware_breakpoint
)
782 warning ("hardware breakpoint %d not supported in overlay!\n",
786 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
788 /* Set a software (trap) breakpoint at the LMA. */
789 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
791 fprintf_unfiltered (tmp_error_stream
,
792 "Overlay breakpoint %d failed: in ROM?",
796 /* Shall we set a breakpoint at the VMA? */
797 if (section_is_mapped (b
->section
))
799 /* Yes. This overlay section is mapped into memory. */
800 if (b
->type
== bp_hardware_breakpoint
)
801 val
= target_insert_hw_breakpoint (b
->address
,
804 val
= target_insert_breakpoint (b
->address
,
809 /* No. This breakpoint will not be inserted.
810 No error, but do not mark the bp as 'inserted'. */
817 /* Can't set the breakpoint. */
818 #if defined (DISABLE_UNSETTABLE_BREAK)
819 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
821 /* See also: disable_breakpoints_in_shlibs. */
823 b
->enable_state
= bp_shlib_disabled
;
824 if (!disabled_breaks
)
826 fprintf_unfiltered (tmp_error_stream
,
827 "Cannot insert breakpoint %d.\n", b
->number
);
828 fprintf_unfiltered (tmp_error_stream
,
829 "Temporarily disabling shared library breakpoints:\n");
832 fprintf_unfiltered (tmp_error_stream
, "breakpoint #%d\n", b
->number
);
838 if (b
->type
== bp_hardware_breakpoint
)
840 hw_breakpoint_error
= 1;
841 fprintf_unfiltered (tmp_error_stream
,
842 "Cannot insert hardware breakpoint %d.\n",
847 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
848 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
849 print_address_numeric (b
->address
, 1, tmp_error_stream
);
850 fprintf_filtered (tmp_error_stream
, ": %s.\n",
851 safe_strerror (val
));
860 return_val
= val
; /* remember failure */
862 else if (ep_is_exception_catchpoint (b
)
863 && b
->enable_state
!= bp_disabled
864 && b
->enable_state
!= bp_shlib_disabled
865 && b
->enable_state
!= bp_call_disabled
870 /* If we get here, we must have a callback mechanism for exception
871 events -- with g++ style embedded label support, we insert
872 ordinary breakpoints and not catchpoints. */
873 /* Format possible error message */
874 sprintf (message
, message1
, b
->number
);
876 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
879 /* Couldn't set breakpoint for some reason */
880 fprintf_unfiltered (tmp_error_stream
,
881 "Cannot insert catchpoint %d; disabling it.\n",
883 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
884 print_address_numeric (b
->address
, 1, tmp_error_stream
);
885 fprintf_filtered (tmp_error_stream
, ": %s.\n",
886 safe_strerror (val
));
887 b
->enable_state
= bp_disabled
;
891 /* Bp set, now make sure callbacks are enabled */
893 args_for_catchpoint_enable args
;
894 args
.kind
= b
->type
== bp_catch_catch
?
895 EX_EVENT_CATCH
: EX_EVENT_THROW
;
897 val
= catch_errors (cover_target_enable_exception_callback
,
899 message
, RETURN_MASK_ALL
);
900 if (val
!= 0 && val
!= -1)
904 /* Check if something went wrong; val == 0 can be ignored */
907 /* something went wrong */
908 fprintf_unfiltered (tmp_error_stream
,
909 "Cannot insert catchpoint %d; disabling it.\n",
911 b
->enable_state
= bp_disabled
;
916 return_val
= val
; /* remember failure */
919 else if ((b
->type
== bp_hardware_watchpoint
||
920 b
->type
== bp_read_watchpoint
||
921 b
->type
== bp_access_watchpoint
)
922 && b
->enable_state
== bp_enabled
923 && b
->disposition
!= disp_del_at_next_stop
927 struct frame_info
*saved_frame
;
928 int saved_level
, within_current_scope
;
929 struct value
*mark
= value_mark ();
932 /* Save the current frame and level so we can restore it after
933 evaluating the watchpoint expression on its own frame. */
934 saved_frame
= selected_frame
;
935 saved_level
= frame_relative_level (selected_frame
);
937 /* Determine if the watchpoint is within scope. */
938 if (b
->exp_valid_block
== NULL
)
939 within_current_scope
= 1;
942 struct frame_info
*fi
;
943 fi
= frame_find_by_id (b
->watchpoint_frame
);
944 within_current_scope
= (fi
!= NULL
);
945 if (within_current_scope
)
949 if (within_current_scope
)
951 /* Evaluate the expression and cut the chain of values
952 produced off from the value chain.
954 Make sure the value returned isn't lazy; we use
955 laziness to determine what memory GDB actually needed
956 in order to compute the value of the expression. */
957 v
= evaluate_expression (b
->exp
);
959 value_release_to_mark (mark
);
964 /* Look at each value on the value chain. */
965 for (; v
; v
= v
->next
)
967 /* If it's a memory location, and GDB actually needed
968 its contents to evaluate the expression, then we
970 if (VALUE_LVAL (v
) == lval_memory
973 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
975 /* We only watch structs and arrays if user asked
976 for it explicitly, never if they just happen to
977 appear in the middle of some value chain. */
978 if (v
== b
->val_chain
979 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
980 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
985 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
986 len
= TYPE_LENGTH (VALUE_TYPE (v
));
988 if (b
->type
== bp_read_watchpoint
)
990 else if (b
->type
== bp_access_watchpoint
)
993 val
= target_insert_watchpoint (addr
, len
, type
);
996 /* Don't exit the loop, try to insert
997 every value on the value chain. That's
998 because we will be removing all the
999 watches below, and removing a
1000 watchpoint we didn't insert could have
1008 /* Failure to insert a watchpoint on any memory value in the
1009 value chain brings us here. */
1012 process_warning
= 1;
1013 remove_breakpoint (b
, mark_uninserted
);
1014 hw_breakpoint_error
= 1;
1015 fprintf_unfiltered (tmp_error_stream
,
1016 "Cannot insert hardware watchpoint %d.\n", b
->number
);
1022 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
1023 printf_filtered ("because the program has left the block \n");
1024 printf_filtered ("in which its expression is valid.\n");
1025 if (b
->related_breakpoint
)
1026 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1027 b
->disposition
= disp_del_at_next_stop
;
1030 /* Restore the frame and level. */
1031 if ((saved_frame
!= selected_frame
) ||
1032 (saved_level
!= frame_relative_level (selected_frame
)))
1033 select_frame (saved_frame
);
1036 return_val
= val
; /* remember failure */
1038 else if ((b
->type
== bp_catch_fork
1039 || b
->type
== bp_catch_vfork
1040 || b
->type
== bp_catch_exec
)
1041 && b
->enable_state
== bp_enabled
1049 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
1051 case bp_catch_vfork
:
1052 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
1055 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
1058 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1063 fprintf_unfiltered (tmp_error_stream
, "Cannot insert catchpoint %d.", b
->number
);
1069 return_val
= val
; /* remember failure */
1075 /* If a hardware breakpoint or watchpoint was inserted, add a
1076 message about possibly exhausted resources. */
1077 if (hw_breakpoint_error
)
1079 fprintf_unfiltered (tmp_error_stream
, "Could not insert hardware breakpoints:\n"
1080 "You may have requested too many hardware breakpoints/watchpoints.\n");
1083 if (process_warning
)
1084 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
1086 target_terminal_ours_for_output ();
1087 error_stream (tmp_error_stream
);
1093 remove_breakpoints (void)
1095 register struct breakpoint
*b
;
1102 val
= remove_breakpoint (b
, mark_uninserted
);
1111 remove_hw_watchpoints (void)
1113 register struct breakpoint
*b
;
1119 && (b
->type
== bp_hardware_watchpoint
1120 || b
->type
== bp_read_watchpoint
1121 || b
->type
== bp_access_watchpoint
))
1123 val
= remove_breakpoint (b
, mark_uninserted
);
1132 reattach_breakpoints (int pid
)
1134 register struct breakpoint
*b
;
1136 struct cleanup
*old_chain
= save_inferior_ptid ();
1138 /* Set inferior_ptid; remove_breakpoint uses this global. */
1139 inferior_ptid
= pid_to_ptid (pid
);
1144 remove_breakpoint (b
, mark_inserted
);
1145 if (b
->type
== bp_hardware_breakpoint
)
1146 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1148 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1151 do_cleanups (old_chain
);
1156 do_cleanups (old_chain
);
1161 update_breakpoints_after_exec (void)
1163 struct breakpoint
*b
;
1164 struct breakpoint
*temp
;
1166 /* Doing this first prevents the badness of having delete_breakpoint()
1167 write a breakpoint's current "shadow contents" to lift the bp. That
1168 shadow is NOT valid after an exec()! */
1169 mark_breakpoints_out ();
1171 ALL_BREAKPOINTS_SAFE (b
, temp
)
1173 /* Solib breakpoints must be explicitly reset after an exec(). */
1174 if (b
->type
== bp_shlib_event
)
1176 delete_breakpoint (b
);
1180 /* Thread event breakpoints must be set anew after an exec(),
1181 as must overlay event breakpoints. */
1182 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1184 delete_breakpoint (b
);
1188 /* Step-resume breakpoints are meaningless after an exec(). */
1189 if (b
->type
== bp_step_resume
)
1191 delete_breakpoint (b
);
1195 /* Ditto the sigtramp handler breakpoints. */
1196 if (b
->type
== bp_through_sigtramp
)
1198 delete_breakpoint (b
);
1202 /* Ditto the exception-handling catchpoints. */
1203 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1205 delete_breakpoint (b
);
1209 /* Don't delete an exec catchpoint, because else the inferior
1210 won't stop when it ought!
1212 Similarly, we probably ought to keep vfork catchpoints, 'cause
1213 on this target, we may not be able to stop when the vfork is
1214 seen, but only when the subsequent exec is seen. (And because
1215 deleting fork catchpoints here but not vfork catchpoints will
1216 seem mysterious to users, keep those too.)
1218 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1219 target address field, if any, is sufficient to have it be reset
1220 automagically. Certainly on HP-UX that's true.
1222 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1223 valid code address on some platforms (like the mn10200 and
1224 mn10300 simulators). We shouldn't assign any special
1225 interpretation to a breakpoint with a zero address. And in
1226 fact, GDB doesn't --- I can't see what that comment above is
1227 talking about. As far as I can tell, setting the address of a
1228 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1229 is meaningless, since those are implemented with HP-UX kernel
1230 hackery, not by storing breakpoint instructions somewhere. */
1231 if ((b
->type
== bp_catch_exec
) ||
1232 (b
->type
== bp_catch_vfork
) ||
1233 (b
->type
== bp_catch_fork
))
1235 b
->address
= (CORE_ADDR
) NULL
;
1239 /* bp_finish is a special case. The only way we ought to be able
1240 to see one of these when an exec() has happened, is if the user
1241 caught a vfork, and then said "finish". Ordinarily a finish just
1242 carries them to the call-site of the current callee, by setting
1243 a temporary bp there and resuming. But in this case, the finish
1244 will carry them entirely through the vfork & exec.
1246 We don't want to allow a bp_finish to remain inserted now. But
1247 we can't safely delete it, 'cause finish_command has a handle to
1248 the bp on a bpstat, and will later want to delete it. There's a
1249 chance (and I've seen it happen) that if we delete the bp_finish
1250 here, that its storage will get reused by the time finish_command
1251 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1252 We really must allow finish_command to delete a bp_finish.
1254 In the absense of a general solution for the "how do we know
1255 it's safe to delete something others may have handles to?"
1256 problem, what we'll do here is just uninsert the bp_finish, and
1257 let finish_command delete it.
1259 (We know the bp_finish is "doomed" in the sense that it's
1260 momentary, and will be deleted as soon as finish_command sees
1261 the inferior stopped. So it doesn't matter that the bp's
1262 address is probably bogus in the new a.out, unlike e.g., the
1263 solib breakpoints.) */
1265 if (b
->type
== bp_finish
)
1270 /* Without a symbolic address, we have little hope of the
1271 pre-exec() address meaning the same thing in the post-exec()
1273 if (b
->addr_string
== NULL
)
1275 delete_breakpoint (b
);
1279 /* If this breakpoint has survived the above battery of checks, then
1280 it must have a symbolic address. Be sure that it gets reevaluated
1281 to a target address, rather than reusing the old evaluation.
1283 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1284 for bp_catch_exec and friends, I'm pretty sure this is entirely
1285 unnecessary. A call to breakpoint_re_set_one always recomputes
1286 the breakpoint's address from scratch, or deletes it if it can't.
1287 So I think this assignment could be deleted without effect. */
1288 b
->address
= (CORE_ADDR
) NULL
;
1290 /* FIXME what about longjmp breakpoints? Re-create them here? */
1291 create_overlay_event_breakpoint ("_ovly_debug_event");
1295 detach_breakpoints (int pid
)
1297 register struct breakpoint
*b
;
1299 struct cleanup
*old_chain
= save_inferior_ptid ();
1301 if (pid
== PIDGET (inferior_ptid
))
1302 error ("Cannot detach breakpoints of inferior_ptid");
1304 /* Set inferior_ptid; remove_breakpoint uses this global. */
1305 inferior_ptid
= pid_to_ptid (pid
);
1310 val
= remove_breakpoint (b
, mark_inserted
);
1313 do_cleanups (old_chain
);
1318 do_cleanups (old_chain
);
1323 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1327 if (b
->enable_state
== bp_permanent
)
1328 /* Permanent breakpoints cannot be inserted or removed. */
1331 if (b
->type
== bp_none
)
1332 warning ("attempted to remove apparently deleted breakpoint #%d?",
1335 if (b
->type
!= bp_watchpoint
1336 && b
->type
!= bp_hardware_watchpoint
1337 && b
->type
!= bp_read_watchpoint
1338 && b
->type
!= bp_access_watchpoint
1339 && b
->type
!= bp_catch_fork
1340 && b
->type
!= bp_catch_vfork
1341 && b
->type
!= bp_catch_exec
1342 && b
->type
!= bp_catch_catch
1343 && b
->type
!= bp_catch_throw
)
1345 /* "Normal" instruction breakpoint: either the standard
1346 trap-instruction bp (bp_breakpoint), or a
1347 bp_hardware_breakpoint. */
1349 /* First check to see if we have to handle an overlay. */
1350 if (overlay_debugging
== ovly_off
1351 || b
->section
== NULL
1352 || !(section_is_overlay (b
->section
)))
1354 /* No overlay handling: just remove the breakpoint. */
1356 if (b
->type
== bp_hardware_breakpoint
)
1357 val
= target_remove_hw_breakpoint (b
->address
,
1358 b
->shadow_contents
);
1360 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1364 /* This breakpoint is in an overlay section.
1365 Did we set a breakpoint at the LMA? */
1366 if (!overlay_events_enabled
)
1368 /* Yes -- overlay event support is not active, so we
1369 should have set a breakpoint at the LMA. Remove it.
1371 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1373 /* Ignore any failures: if the LMA is in ROM, we will
1374 have already warned when we failed to insert it. */
1375 if (b
->type
!= bp_hardware_breakpoint
)
1376 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1378 target_remove_breakpoint (addr
, b
->shadow_contents
);
1380 /* Did we set a breakpoint at the VMA?
1381 If so, we will have marked the breakpoint 'inserted'. */
1384 /* Yes -- remove it. Previously we did not bother to
1385 remove the breakpoint if the section had been
1386 unmapped, but let's not rely on that being safe. We
1387 don't know what the overlay manager might do. */
1388 if (b
->type
== bp_hardware_breakpoint
)
1389 val
= target_remove_hw_breakpoint (b
->address
,
1390 b
->shadow_contents
);
1392 val
= target_remove_breakpoint (b
->address
,
1393 b
->shadow_contents
);
1397 /* No -- not inserted, so no need to remove. No error. */
1403 b
->inserted
= (is
== mark_inserted
);
1405 else if ((b
->type
== bp_hardware_watchpoint
||
1406 b
->type
== bp_read_watchpoint
||
1407 b
->type
== bp_access_watchpoint
)
1408 && b
->enable_state
== bp_enabled
1414 b
->inserted
= (is
== mark_inserted
);
1415 /* Walk down the saved value chain. */
1416 for (v
= b
->val_chain
; v
; v
= v
->next
)
1418 /* For each memory reference remove the watchpoint
1420 if (VALUE_LVAL (v
) == lval_memory
1421 && ! VALUE_LAZY (v
))
1423 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1425 if (v
== b
->val_chain
1426 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1427 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1432 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1433 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1435 if (b
->type
== bp_read_watchpoint
)
1437 else if (b
->type
== bp_access_watchpoint
)
1440 val
= target_remove_watchpoint (addr
, len
, type
);
1447 /* Failure to remove any of the hardware watchpoints comes here. */
1448 if ((is
== mark_uninserted
) && (b
->inserted
))
1449 warning ("Could not remove hardware watchpoint %d.",
1452 /* Free the saved value chain. We will construct a new one
1453 the next time the watchpoint is inserted. */
1454 for (v
= b
->val_chain
; v
; v
= n
)
1459 b
->val_chain
= NULL
;
1461 else if ((b
->type
== bp_catch_fork
||
1462 b
->type
== bp_catch_vfork
||
1463 b
->type
== bp_catch_exec
)
1464 && b
->enable_state
== bp_enabled
1471 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1473 case bp_catch_vfork
:
1474 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1477 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1480 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1485 b
->inserted
= (is
== mark_inserted
);
1487 else if ((b
->type
== bp_catch_catch
||
1488 b
->type
== bp_catch_throw
)
1489 && b
->enable_state
== bp_enabled
1493 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1496 b
->inserted
= (is
== mark_inserted
);
1498 else if (ep_is_exception_catchpoint (b
)
1499 && b
->inserted
/* sometimes previous insert doesn't happen */
1500 && b
->enable_state
== bp_enabled
1504 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1508 b
->inserted
= (is
== mark_inserted
);
1514 /* Clear the "inserted" flag in all breakpoints. */
1517 mark_breakpoints_out (void)
1519 register struct breakpoint
*b
;
1525 /* Clear the "inserted" flag in all breakpoints and delete any
1526 breakpoints which should go away between runs of the program.
1528 Plus other such housekeeping that has to be done for breakpoints
1531 Note: this function gets called at the end of a run (by
1532 generic_mourn_inferior) and when a run begins (by
1533 init_wait_for_inferior). */
1538 breakpoint_init_inferior (enum inf_context context
)
1540 register struct breakpoint
*b
, *temp
;
1541 static int warning_needed
= 0;
1543 ALL_BREAKPOINTS_SAFE (b
, temp
)
1550 case bp_watchpoint_scope
:
1552 /* If the call dummy breakpoint is at the entry point it will
1553 cause problems when the inferior is rerun, so we better
1556 Also get rid of scope breakpoints. */
1557 delete_breakpoint (b
);
1561 case bp_hardware_watchpoint
:
1562 case bp_read_watchpoint
:
1563 case bp_access_watchpoint
:
1565 /* Likewise for watchpoints on local expressions. */
1566 if (b
->exp_valid_block
!= NULL
)
1567 delete_breakpoint (b
);
1570 /* Likewise for exception catchpoints in dynamic-linked
1571 executables where required */
1572 if (ep_is_exception_catchpoint (b
) &&
1573 exception_catchpoints_are_fragile
)
1576 delete_breakpoint (b
);
1582 if (exception_catchpoints_are_fragile
)
1583 exception_support_initialized
= 0;
1585 /* Don't issue the warning unless it's really needed... */
1586 if (warning_needed
&& (context
!= inf_exited
))
1588 warning ("Exception catchpoints from last run were deleted.");
1589 warning ("You must reinsert them explicitly.");
1594 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1595 exists at PC. It returns ordinary_breakpoint_here if it's an
1596 ordinary breakpoint, or permanent_breakpoint_here if it's a
1597 permanent breakpoint.
1598 - When continuing from a location with an ordinary breakpoint, we
1599 actually single step once before calling insert_breakpoints.
1600 - When continuing from a localion with a permanent breakpoint, we
1601 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1602 the target, to advance the PC past the breakpoint. */
1604 enum breakpoint_here
1605 breakpoint_here_p (CORE_ADDR pc
)
1607 register struct breakpoint
*b
;
1608 int any_breakpoint_here
= 0;
1611 if ((b
->enable_state
== bp_enabled
1612 || b
->enable_state
== bp_permanent
)
1613 && b
->address
== pc
) /* bp is enabled and matches pc */
1615 if (overlay_debugging
1616 && section_is_overlay (b
->section
)
1617 && !section_is_mapped (b
->section
))
1618 continue; /* unmapped overlay -- can't be a match */
1619 else if (b
->enable_state
== bp_permanent
)
1620 return permanent_breakpoint_here
;
1622 any_breakpoint_here
= 1;
1625 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1629 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1630 but it only returns true if there is actually a breakpoint inserted
1634 breakpoint_inserted_here_p (CORE_ADDR pc
)
1636 register struct breakpoint
*b
;
1640 && b
->address
== pc
) /* bp is inserted and matches pc */
1642 if (overlay_debugging
1643 && section_is_overlay (b
->section
)
1644 && !section_is_mapped (b
->section
))
1645 continue; /* unmapped overlay -- can't be a match */
1653 /* Return nonzero if FRAME is a dummy frame. We can't use
1654 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1655 much time, at least using get_saved_register on the 68k. This
1656 means that for this function to work right a port must use the
1657 bp_call_dummy breakpoint. */
1660 frame_in_dummy (struct frame_info
*frame
)
1662 struct breakpoint
*b
;
1667 if (USE_GENERIC_DUMMY_FRAMES
)
1668 return generic_pc_in_call_dummy (frame
->pc
, frame
->frame
, frame
->frame
);
1672 if (b
->type
== bp_call_dummy
1673 && b
->frame
== frame
->frame
1674 /* We need to check the PC as well as the frame on the sparc,
1675 for signals.exp in the testsuite. */
1678 - SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * REGISTER_SIZE
))
1679 && frame
->pc
<= b
->address
)
1685 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1686 PC is valid for process/thread PID. */
1689 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1691 struct breakpoint
*b
;
1694 thread
= pid_to_thread_id (ptid
);
1697 if (b
->enable_state
!= bp_disabled
1698 && b
->enable_state
!= bp_shlib_disabled
1699 && b
->enable_state
!= bp_call_disabled
1701 && (b
->thread
== -1 || b
->thread
== thread
))
1703 if (overlay_debugging
1704 && section_is_overlay (b
->section
)
1705 && !section_is_mapped (b
->section
))
1706 continue; /* unmapped overlay -- can't be a match */
1715 /* bpstat stuff. External routines' interfaces are documented
1719 ep_is_catchpoint (struct breakpoint
*ep
)
1722 (ep
->type
== bp_catch_load
)
1723 || (ep
->type
== bp_catch_unload
)
1724 || (ep
->type
== bp_catch_fork
)
1725 || (ep
->type
== bp_catch_vfork
)
1726 || (ep
->type
== bp_catch_exec
)
1727 || (ep
->type
== bp_catch_catch
)
1728 || (ep
->type
== bp_catch_throw
);
1730 /* ??rehrauer: Add more kinds here, as are implemented... */
1734 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1737 (ep
->type
== bp_catch_load
)
1738 || (ep
->type
== bp_catch_unload
);
1742 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1745 (ep
->type
== bp_catch_catch
)
1746 || (ep
->type
== bp_catch_throw
);
1749 /* Clear a bpstat so that it says we are not at any breakpoint.
1750 Also free any storage that is part of a bpstat. */
1753 bpstat_clear (bpstat
*bsp
)
1764 if (p
->old_val
!= NULL
)
1765 value_free (p
->old_val
);
1772 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1773 is part of the bpstat is copied as well. */
1776 bpstat_copy (bpstat bs
)
1780 bpstat retval
= NULL
;
1785 for (; bs
!= NULL
; bs
= bs
->next
)
1787 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1788 memcpy (tmp
, bs
, sizeof (*tmp
));
1790 /* This is the first thing in the chain. */
1800 /* Find the bpstat associated with this breakpoint */
1803 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1808 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1810 if (bsp
->breakpoint_at
== breakpoint
)
1816 /* Find a step_resume breakpoint associated with this bpstat.
1817 (If there are multiple step_resume bp's on the list, this function
1818 will arbitrarily pick one.)
1820 It is an error to use this function if BPSTAT doesn't contain a
1821 step_resume breakpoint.
1823 See wait_for_inferior's use of this function. */
1825 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1830 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1832 current_thread
= pid_to_thread_id (inferior_ptid
);
1834 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1836 if ((bsp
->breakpoint_at
!= NULL
) &&
1837 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1838 (bsp
->breakpoint_at
->thread
== current_thread
||
1839 bsp
->breakpoint_at
->thread
== -1))
1840 return bsp
->breakpoint_at
;
1843 error ("Internal error (no step_resume breakpoint found)");
1847 /* Return the breakpoint number of the first breakpoint we are stopped
1848 at. *BSP upon return is a bpstat which points to the remaining
1849 breakpoints stopped at (but which is not guaranteed to be good for
1850 anything but further calls to bpstat_num).
1851 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1854 bpstat_num (bpstat
*bsp
)
1856 struct breakpoint
*b
;
1859 return 0; /* No more breakpoint values */
1862 b
= (*bsp
)->breakpoint_at
;
1863 *bsp
= (*bsp
)->next
;
1865 return -1; /* breakpoint that's been deleted since */
1867 return b
->number
; /* We have its number */
1871 /* Modify BS so that the actions will not be performed. */
1874 bpstat_clear_actions (bpstat bs
)
1876 for (; bs
!= NULL
; bs
= bs
->next
)
1878 bs
->commands
= NULL
;
1879 if (bs
->old_val
!= NULL
)
1881 value_free (bs
->old_val
);
1887 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1890 cleanup_executing_breakpoints (PTR ignore
)
1892 executing_breakpoint_commands
= 0;
1895 /* Execute all the commands associated with all the breakpoints at this
1896 location. Any of these commands could cause the process to proceed
1897 beyond this point, etc. We look out for such changes by checking
1898 the global "breakpoint_proceeded" after each command. */
1901 bpstat_do_actions (bpstat
*bsp
)
1904 struct cleanup
*old_chain
;
1905 struct command_line
*cmd
;
1907 /* Avoid endless recursion if a `source' command is contained
1909 if (executing_breakpoint_commands
)
1912 executing_breakpoint_commands
= 1;
1913 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1916 /* Note that (as of this writing), our callers all appear to
1917 be passing us the address of global stop_bpstat. And, if
1918 our calls to execute_control_command cause the inferior to
1919 proceed, that global (and hence, *bsp) will change.
1921 We must be careful to not touch *bsp unless the inferior
1922 has not proceeded. */
1924 /* This pointer will iterate over the list of bpstat's. */
1927 breakpoint_proceeded
= 0;
1928 for (; bs
!= NULL
; bs
= bs
->next
)
1933 execute_control_command (cmd
);
1935 if (breakpoint_proceeded
)
1940 if (breakpoint_proceeded
)
1941 /* The inferior is proceeded by the command; bomb out now.
1942 The bpstat chain has been blown away by wait_for_inferior.
1943 But since execution has stopped again, there is a new bpstat
1944 to look at, so start over. */
1947 bs
->commands
= NULL
;
1950 executing_breakpoint_commands
= 0;
1951 discard_cleanups (old_chain
);
1954 /* This is the normal print function for a bpstat. In the future,
1955 much of this logic could (should?) be moved to bpstat_stop_status,
1956 by having it set different print_it values.
1958 Current scheme: When we stop, bpstat_print() is called. It loops
1959 through the bpstat list of things causing this stop, calling the
1960 print_bp_stop_message function on each one. The behavior of the
1961 print_bp_stop_message function depends on the print_it field of
1962 bpstat. If such field so indicates, call this function here.
1964 Return values from this routine (ultimately used by bpstat_print()
1965 and normal_stop() to decide what to do):
1966 PRINT_NOTHING: Means we already printed all we needed to print,
1967 don't print anything else.
1968 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1969 that something to be followed by a location.
1970 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1971 that something to be followed by a location.
1972 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1975 static enum print_stop_action
1976 print_it_typical (bpstat bs
)
1978 struct cleanup
*old_chain
;
1979 struct ui_stream
*stb
;
1980 stb
= ui_out_stream_new (uiout
);
1981 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1982 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1983 which has since been deleted. */
1984 if (bs
->breakpoint_at
== NULL
)
1985 return PRINT_UNKNOWN
;
1987 switch (bs
->breakpoint_at
->type
)
1990 case bp_hardware_breakpoint
:
1991 annotate_breakpoint (bs
->breakpoint_at
->number
);
1992 ui_out_text (uiout
, "\nBreakpoint ");
1993 if (ui_out_is_mi_like_p (uiout
))
1994 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
1995 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
1996 ui_out_text (uiout
, ", ");
1997 return PRINT_SRC_AND_LOC
;
2000 case bp_shlib_event
:
2001 /* Did we stop because the user set the stop_on_solib_events
2002 variable? (If so, we report this as a generic, "Stopped due
2003 to shlib event" message.) */
2004 printf_filtered ("Stopped due to shared library event\n");
2005 return PRINT_NOTHING
;
2008 case bp_thread_event
:
2009 /* Not sure how we will get here.
2010 GDB should not stop for these breakpoints. */
2011 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2012 return PRINT_NOTHING
;
2015 case bp_overlay_event
:
2016 /* By analogy with the thread event, GDB should not stop for these. */
2017 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2018 return PRINT_NOTHING
;
2022 annotate_catchpoint (bs
->breakpoint_at
->number
);
2023 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2024 printf_filtered ("loaded");
2025 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2026 return PRINT_SRC_AND_LOC
;
2029 case bp_catch_unload
:
2030 annotate_catchpoint (bs
->breakpoint_at
->number
);
2031 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2032 printf_filtered ("unloaded");
2033 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
2034 return PRINT_SRC_AND_LOC
;
2038 annotate_catchpoint (bs
->breakpoint_at
->number
);
2039 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2040 printf_filtered ("forked");
2041 printf_filtered (" process %d), ",
2042 bs
->breakpoint_at
->forked_inferior_pid
);
2043 return PRINT_SRC_AND_LOC
;
2046 case bp_catch_vfork
:
2047 annotate_catchpoint (bs
->breakpoint_at
->number
);
2048 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2049 printf_filtered ("vforked");
2050 printf_filtered (" process %d), ",
2051 bs
->breakpoint_at
->forked_inferior_pid
);
2052 return PRINT_SRC_AND_LOC
;
2056 annotate_catchpoint (bs
->breakpoint_at
->number
);
2057 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2058 bs
->breakpoint_at
->number
,
2059 bs
->breakpoint_at
->exec_pathname
);
2060 return PRINT_SRC_AND_LOC
;
2063 case bp_catch_catch
:
2064 if (current_exception_event
&&
2065 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2067 annotate_catchpoint (bs
->breakpoint_at
->number
);
2068 printf_filtered ("\nCatchpoint %d (exception caught), ",
2069 bs
->breakpoint_at
->number
);
2070 printf_filtered ("throw location ");
2071 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2072 printf_filtered ("%s:%d",
2073 CURRENT_EXCEPTION_THROW_FILE
,
2074 CURRENT_EXCEPTION_THROW_LINE
);
2076 printf_filtered ("unknown");
2078 printf_filtered (", catch location ");
2079 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2080 printf_filtered ("%s:%d",
2081 CURRENT_EXCEPTION_CATCH_FILE
,
2082 CURRENT_EXCEPTION_CATCH_LINE
);
2084 printf_filtered ("unknown");
2086 printf_filtered ("\n");
2087 /* don't bother to print location frame info */
2088 return PRINT_SRC_ONLY
;
2092 /* really throw, some other bpstat will handle it */
2093 return PRINT_UNKNOWN
;
2097 case bp_catch_throw
:
2098 if (current_exception_event
&&
2099 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2101 annotate_catchpoint (bs
->breakpoint_at
->number
);
2102 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2103 bs
->breakpoint_at
->number
);
2104 printf_filtered ("throw location ");
2105 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2106 printf_filtered ("%s:%d",
2107 CURRENT_EXCEPTION_THROW_FILE
,
2108 CURRENT_EXCEPTION_THROW_LINE
);
2110 printf_filtered ("unknown");
2112 printf_filtered (", catch location ");
2113 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2114 printf_filtered ("%s:%d",
2115 CURRENT_EXCEPTION_CATCH_FILE
,
2116 CURRENT_EXCEPTION_CATCH_LINE
);
2118 printf_filtered ("unknown");
2120 printf_filtered ("\n");
2121 /* don't bother to print location frame info */
2122 return PRINT_SRC_ONLY
;
2126 /* really catch, some other bpstat will handle it */
2127 return PRINT_UNKNOWN
;
2132 case bp_hardware_watchpoint
:
2133 if (bs
->old_val
!= NULL
)
2135 annotate_watchpoint (bs
->breakpoint_at
->number
);
2136 if (ui_out_is_mi_like_p (uiout
))
2137 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2138 mention (bs
->breakpoint_at
);
2139 ui_out_tuple_begin (uiout
, "value");
2140 ui_out_text (uiout
, "\nOld value = ");
2141 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2142 ui_out_field_stream (uiout
, "old", stb
);
2143 ui_out_text (uiout
, "\nNew value = ");
2144 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2145 ui_out_field_stream (uiout
, "new", stb
);
2146 ui_out_tuple_end (uiout
);
2147 ui_out_text (uiout
, "\n");
2148 value_free (bs
->old_val
);
2151 /* More than one watchpoint may have been triggered. */
2152 return PRINT_UNKNOWN
;
2155 case bp_read_watchpoint
:
2156 if (ui_out_is_mi_like_p (uiout
))
2157 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2158 mention (bs
->breakpoint_at
);
2159 ui_out_tuple_begin (uiout
, "value");
2160 ui_out_text (uiout
, "\nValue = ");
2161 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2162 ui_out_field_stream (uiout
, "value", stb
);
2163 ui_out_tuple_end (uiout
);
2164 ui_out_text (uiout
, "\n");
2165 return PRINT_UNKNOWN
;
2168 case bp_access_watchpoint
:
2169 if (bs
->old_val
!= NULL
)
2171 annotate_watchpoint (bs
->breakpoint_at
->number
);
2172 if (ui_out_is_mi_like_p (uiout
))
2173 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2174 mention (bs
->breakpoint_at
);
2175 ui_out_tuple_begin (uiout
, "value");
2176 ui_out_text (uiout
, "\nOld value = ");
2177 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2178 ui_out_field_stream (uiout
, "old", stb
);
2179 value_free (bs
->old_val
);
2181 ui_out_text (uiout
, "\nNew value = ");
2185 mention (bs
->breakpoint_at
);
2186 if (ui_out_is_mi_like_p (uiout
))
2187 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2188 ui_out_tuple_begin (uiout
, "value");
2189 ui_out_text (uiout
, "\nValue = ");
2191 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2192 ui_out_field_stream (uiout
, "new", stb
);
2193 ui_out_tuple_end (uiout
);
2194 ui_out_text (uiout
, "\n");
2195 return PRINT_UNKNOWN
;
2198 /* Fall through, we don't deal with these types of breakpoints
2202 if (ui_out_is_mi_like_p (uiout
))
2203 ui_out_field_string (uiout
, "reason", "function-finished");
2204 return PRINT_UNKNOWN
;
2208 if (ui_out_is_mi_like_p (uiout
))
2209 ui_out_field_string (uiout
, "reason", "location-reached");
2210 return PRINT_UNKNOWN
;
2215 case bp_longjmp_resume
:
2216 case bp_step_resume
:
2217 case bp_through_sigtramp
:
2218 case bp_watchpoint_scope
:
2221 return PRINT_UNKNOWN
;
2225 /* Generic routine for printing messages indicating why we
2226 stopped. The behavior of this function depends on the value
2227 'print_it' in the bpstat structure. Under some circumstances we
2228 may decide not to print anything here and delegate the task to
2231 static enum print_stop_action
2232 print_bp_stop_message (bpstat bs
)
2234 switch (bs
->print_it
)
2237 /* Nothing should be printed for this bpstat entry. */
2238 return PRINT_UNKNOWN
;
2242 /* We still want to print the frame, but we already printed the
2243 relevant messages. */
2244 return PRINT_SRC_AND_LOC
;
2247 case print_it_normal
:
2248 /* Normal case, we handle everything in print_it_typical. */
2249 return print_it_typical (bs
);
2252 internal_error (__FILE__
, __LINE__
,
2253 "print_bp_stop_message: unrecognized enum value");
2258 /* Print a message indicating what happened. This is called from
2259 normal_stop(). The input to this routine is the head of the bpstat
2260 list - a list of the eventpoints that caused this stop. This
2261 routine calls the generic print routine for printing a message
2262 about reasons for stopping. This will print (for example) the
2263 "Breakpoint n," part of the output. The return value of this
2266 PRINT_UNKNOWN: Means we printed nothing
2267 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2268 code to print the location. An example is
2269 "Breakpoint 1, " which should be followed by
2271 PRINT_SRC_ONLY: Means we printed something, but there is no need
2272 to also print the location part of the message.
2273 An example is the catch/throw messages, which
2274 don't require a location appended to the end.
2275 PRINT_NOTHING: We have done some printing and we don't need any
2276 further info to be printed.*/
2278 enum print_stop_action
2279 bpstat_print (bpstat bs
)
2283 /* Maybe another breakpoint in the chain caused us to stop.
2284 (Currently all watchpoints go on the bpstat whether hit or not.
2285 That probably could (should) be changed, provided care is taken
2286 with respect to bpstat_explains_signal). */
2287 for (; bs
; bs
= bs
->next
)
2289 val
= print_bp_stop_message (bs
);
2290 if (val
== PRINT_SRC_ONLY
2291 || val
== PRINT_SRC_AND_LOC
2292 || val
== PRINT_NOTHING
)
2296 /* We reached the end of the chain, or we got a null BS to start
2297 with and nothing was printed. */
2298 return PRINT_UNKNOWN
;
2301 /* Evaluate the expression EXP and return 1 if value is zero.
2302 This is used inside a catch_errors to evaluate the breakpoint condition.
2303 The argument is a "struct expression *" that has been cast to char * to
2304 make it pass through catch_errors. */
2307 breakpoint_cond_eval (PTR exp
)
2309 struct value
*mark
= value_mark ();
2310 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2311 value_free_to_mark (mark
);
2315 /* Allocate a new bpstat and chain it to the current one. */
2318 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2322 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2324 bs
->breakpoint_at
= b
;
2325 /* If the condition is false, etc., don't do the commands. */
2326 bs
->commands
= NULL
;
2328 bs
->print_it
= print_it_normal
;
2332 /* Possible return values for watchpoint_check (this can't be an enum
2333 because of check_errors). */
2334 /* The watchpoint has been deleted. */
2335 #define WP_DELETED 1
2336 /* The value has changed. */
2337 #define WP_VALUE_CHANGED 2
2338 /* The value has not changed. */
2339 #define WP_VALUE_NOT_CHANGED 3
2341 #define BP_TEMPFLAG 1
2342 #define BP_HARDWAREFLAG 2
2344 /* Check watchpoint condition. */
2347 watchpoint_check (PTR p
)
2349 bpstat bs
= (bpstat
) p
;
2350 struct breakpoint
*b
;
2351 struct frame_info
*fr
;
2352 int within_current_scope
;
2354 b
= bs
->breakpoint_at
;
2356 if (b
->exp_valid_block
== NULL
)
2357 within_current_scope
= 1;
2360 /* There is no current frame at this moment. If we're going to have
2361 any chance of handling watchpoints on local variables, we'll need
2362 the frame chain (so we can determine if we're in scope). */
2363 reinit_frame_cache ();
2364 fr
= frame_find_by_id (b
->watchpoint_frame
);
2365 within_current_scope
= (fr
!= NULL
);
2366 /* in_function_epilogue_p() returns a non-zero value if we're still
2367 in the function but the stack frame has already been invalidated.
2368 Since we can't rely on the values of local variables after the
2369 stack has been destroyed, we are treating the watchpoint in that
2370 state as `not changed' without further checking. */
2371 if (within_current_scope
&& fr
== get_current_frame ()
2372 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2373 return WP_VALUE_NOT_CHANGED
;
2374 if (within_current_scope
)
2375 /* If we end up stopping, the current frame will get selected
2376 in normal_stop. So this call to select_frame won't affect
2381 if (within_current_scope
)
2383 /* We use value_{,free_to_}mark because it could be a
2384 *long* time before we return to the command level and
2385 call free_all_values. We can't call free_all_values because
2386 we might be in the middle of evaluating a function call. */
2388 struct value
*mark
= value_mark ();
2389 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2390 if (!value_equal (b
->val
, new_val
))
2392 release_value (new_val
);
2393 value_free_to_mark (mark
);
2394 bs
->old_val
= b
->val
;
2396 /* We will stop here */
2397 return WP_VALUE_CHANGED
;
2401 /* Nothing changed, don't do anything. */
2402 value_free_to_mark (mark
);
2403 /* We won't stop here */
2404 return WP_VALUE_NOT_CHANGED
;
2409 /* This seems like the only logical thing to do because
2410 if we temporarily ignored the watchpoint, then when
2411 we reenter the block in which it is valid it contains
2412 garbage (in the case of a function, it may have two
2413 garbage values, one before and one after the prologue).
2414 So we can't even detect the first assignment to it and
2415 watch after that (since the garbage may or may not equal
2416 the first value assigned). */
2417 /* We print all the stop information in print_it_typical(), but
2418 in this case, by the time we call print_it_typical() this bp
2419 will be deleted already. So we have no choice but print the
2420 information here. */
2421 if (ui_out_is_mi_like_p (uiout
))
2422 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2423 ui_out_text (uiout
, "\nWatchpoint ");
2424 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2425 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2426 which its expression is valid.\n");
2428 if (b
->related_breakpoint
)
2429 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2430 b
->disposition
= disp_del_at_next_stop
;
2436 /* Get a bpstat associated with having just stopped at address *PC
2437 and frame address CORE_ADDRESS. Update *PC to point at the
2438 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2439 if this is known to not be a real breakpoint (it could still be a
2440 watchpoint, though). */
2442 /* Determine whether we stopped at a breakpoint, etc, or whether we
2443 don't understand this stop. Result is a chain of bpstat's such that:
2445 if we don't understand the stop, the result is a null pointer.
2447 if we understand why we stopped, the result is not null.
2449 Each element of the chain refers to a particular breakpoint or
2450 watchpoint at which we have stopped. (We may have stopped for
2451 several reasons concurrently.)
2453 Each element of the chain has valid next, breakpoint_at,
2454 commands, FIXME??? fields. */
2457 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_sw_breakpoint
)
2459 register struct breakpoint
*b
, *temp
;
2461 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2462 int real_breakpoint
= 0;
2463 /* Root of the chain of bpstat's */
2464 struct bpstats root_bs
[1];
2465 /* Pointer to the last thing in the chain currently. */
2466 bpstat bs
= root_bs
;
2467 static char message1
[] =
2468 "Error evaluating expression for watchpoint %d\n";
2469 char message
[sizeof (message1
) + 30 /* slop */ ];
2471 /* Get the address where the breakpoint would have been. The
2472 "not_a_sw_breakpoint" argument is meant to distinguish between a
2473 breakpoint trap event and a trace/singlestep trap event. For a
2474 trace/singlestep trap event, we would not want to subtract
2475 DECR_PC_AFTER_BREAK from the PC. */
2477 bp_addr
= *pc
- (not_a_sw_breakpoint
? 0 : DECR_PC_AFTER_BREAK
);
2479 ALL_BREAKPOINTS_SAFE (b
, temp
)
2481 if (b
->enable_state
== bp_disabled
2482 || b
->enable_state
== bp_shlib_disabled
2483 || b
->enable_state
== bp_call_disabled
)
2486 if (b
->type
!= bp_watchpoint
2487 && b
->type
!= bp_hardware_watchpoint
2488 && b
->type
!= bp_read_watchpoint
2489 && b
->type
!= bp_access_watchpoint
2490 && b
->type
!= bp_hardware_breakpoint
2491 && b
->type
!= bp_catch_fork
2492 && b
->type
!= bp_catch_vfork
2493 && b
->type
!= bp_catch_exec
2494 && b
->type
!= bp_catch_catch
2495 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2497 if (b
->address
!= bp_addr
) /* address doesn't match */
2499 if (overlay_debugging
/* unmapped overlay section */
2500 && section_is_overlay (b
->section
)
2501 && !section_is_mapped (b
->section
))
2505 if (b
->type
== bp_hardware_breakpoint
)
2507 if (b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2509 if (overlay_debugging
/* unmapped overlay section */
2510 && section_is_overlay (b
->section
)
2511 && !section_is_mapped (b
->section
))
2515 /* Is this a catchpoint of a load or unload? If so, did we
2516 get a load or unload of the specified library? If not,
2518 if ((b
->type
== bp_catch_load
)
2519 #if defined(SOLIB_HAVE_LOAD_EVENT)
2520 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2521 || ((b
->dll_pathname
!= NULL
)
2522 && (strcmp (b
->dll_pathname
,
2523 SOLIB_LOADED_LIBRARY_PATHNAME (
2524 PIDGET (inferior_ptid
)))
2530 if ((b
->type
== bp_catch_unload
)
2531 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2532 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2533 || ((b
->dll_pathname
!= NULL
)
2534 && (strcmp (b
->dll_pathname
,
2535 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2536 PIDGET (inferior_ptid
)))
2542 if ((b
->type
== bp_catch_fork
)
2543 && !target_has_forked (PIDGET (inferior_ptid
),
2544 &b
->forked_inferior_pid
))
2547 if ((b
->type
== bp_catch_vfork
)
2548 && !target_has_vforked (PIDGET (inferior_ptid
),
2549 &b
->forked_inferior_pid
))
2552 if ((b
->type
== bp_catch_exec
)
2553 && !target_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2556 if (ep_is_exception_catchpoint (b
) &&
2557 !(current_exception_event
= target_get_current_exception_event ()))
2560 /* Come here if it's a watchpoint, or if the break address matches */
2562 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2564 /* Watchpoints may change this, if not found to have triggered. */
2568 sprintf (message
, message1
, b
->number
);
2569 if (b
->type
== bp_watchpoint
||
2570 b
->type
== bp_hardware_watchpoint
)
2572 switch (catch_errors (watchpoint_check
, bs
, message
,
2576 /* We've already printed what needs to be printed. */
2577 /* Actually this is superfluous, because by the time we
2578 call print_it_typical() the wp will be already deleted,
2579 and the function will return immediately. */
2580 bs
->print_it
= print_it_done
;
2583 case WP_VALUE_CHANGED
:
2587 case WP_VALUE_NOT_CHANGED
:
2589 bs
->print_it
= print_it_noop
;
2596 /* Error from catch_errors. */
2597 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2598 if (b
->related_breakpoint
)
2599 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2600 b
->disposition
= disp_del_at_next_stop
;
2601 /* We've already printed what needs to be printed. */
2602 bs
->print_it
= print_it_done
;
2608 else if (b
->type
== bp_read_watchpoint
||
2609 b
->type
== bp_access_watchpoint
)
2615 addr
= target_stopped_data_address ();
2618 for (v
= b
->val_chain
; v
; v
= v
->next
)
2620 if (VALUE_LVAL (v
) == lval_memory
2621 && ! VALUE_LAZY (v
))
2623 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2625 if (v
== b
->val_chain
2626 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2627 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2631 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2632 /* Exact match not required. Within range is
2634 if (addr
>= vaddr
&&
2635 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2641 switch (catch_errors (watchpoint_check
, bs
, message
,
2645 /* We've already printed what needs to be printed. */
2646 bs
->print_it
= print_it_done
;
2649 case WP_VALUE_CHANGED
:
2650 if (b
->type
== bp_read_watchpoint
)
2652 /* Don't stop: read watchpoints shouldn't fire if
2653 the value has changed. This is for targets which
2654 cannot set read-only watchpoints. */
2655 bs
->print_it
= print_it_noop
;
2661 case WP_VALUE_NOT_CHANGED
:
2668 /* Error from catch_errors. */
2669 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2670 if (b
->related_breakpoint
)
2671 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2672 b
->disposition
= disp_del_at_next_stop
;
2673 /* We've already printed what needs to be printed. */
2674 bs
->print_it
= print_it_done
;
2677 else /* found == 0 */
2679 /* This is a case where some watchpoint(s) triggered,
2680 but not at the address of this watchpoint (FOUND
2681 was left zero). So don't print anything for this
2683 bs
->print_it
= print_it_noop
;
2690 /* By definition, an encountered breakpoint is a triggered
2694 real_breakpoint
= 1;
2698 b
->frame
!= (get_current_frame ())->frame
)
2702 int value_is_zero
= 0;
2706 /* Need to select the frame, with all that implies
2707 so that the conditions will have the right context. */
2708 select_frame (get_current_frame ());
2710 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2711 "Error in testing breakpoint condition:\n",
2713 /* FIXME-someday, should give breakpoint # */
2716 if (b
->cond
&& value_is_zero
)
2719 /* Don't consider this a hit. */
2722 else if (b
->ignore_count
> 0)
2725 annotate_ignore_count_change ();
2730 /* We will stop here */
2731 if (b
->disposition
== disp_disable
)
2732 b
->enable_state
= bp_disabled
;
2733 bs
->commands
= b
->commands
;
2737 (STREQ ("silent", bs
->commands
->line
) ||
2738 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2740 bs
->commands
= bs
->commands
->next
;
2745 /* Print nothing for this entry if we dont stop or if we dont print. */
2746 if (bs
->stop
== 0 || bs
->print
== 0)
2747 bs
->print_it
= print_it_noop
;
2750 bs
->next
= NULL
; /* Terminate the chain */
2751 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2753 if (real_breakpoint
&& bs
)
2755 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2757 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2759 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2765 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2768 #if defined (SHIFT_INST_REGS)
2770 #else /* No SHIFT_INST_REGS. */
2772 #endif /* No SHIFT_INST_REGS. */
2777 /* The value of a hardware watchpoint hasn't changed, but the
2778 intermediate memory locations we are watching may have. */
2779 if (bs
&& !bs
->stop
&&
2780 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2781 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2782 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2784 remove_breakpoints ();
2785 insert_breakpoints ();
2790 /* Tell what to do about this bpstat. */
2792 bpstat_what (bpstat bs
)
2794 /* Classify each bpstat as one of the following. */
2797 /* This bpstat element has no effect on the main_action. */
2800 /* There was a watchpoint, stop but don't print. */
2803 /* There was a watchpoint, stop and print. */
2806 /* There was a breakpoint but we're not stopping. */
2809 /* There was a breakpoint, stop but don't print. */
2812 /* There was a breakpoint, stop and print. */
2815 /* We hit the longjmp breakpoint. */
2818 /* We hit the longjmp_resume breakpoint. */
2821 /* We hit the step_resume breakpoint. */
2824 /* We hit the through_sigtramp breakpoint. */
2827 /* We hit the shared library event breakpoint. */
2830 /* We caught a shared library event. */
2833 /* This is just used to count how many enums there are. */
2837 /* Here is the table which drives this routine. So that we can
2838 format it pretty, we define some abbreviations for the
2839 enum bpstat_what codes. */
2840 #define kc BPSTAT_WHAT_KEEP_CHECKING
2841 #define ss BPSTAT_WHAT_STOP_SILENT
2842 #define sn BPSTAT_WHAT_STOP_NOISY
2843 #define sgl BPSTAT_WHAT_SINGLE
2844 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2845 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2846 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2847 #define sr BPSTAT_WHAT_STEP_RESUME
2848 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2849 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2850 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2852 /* "Can't happen." Might want to print an error message.
2853 abort() is not out of the question, but chances are GDB is just
2854 a bit confused, not unusable. */
2855 #define err BPSTAT_WHAT_STOP_NOISY
2857 /* Given an old action and a class, come up with a new action. */
2858 /* One interesting property of this table is that wp_silent is the same
2859 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2860 after stopping, the check for whether to step over a breakpoint
2861 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2862 reference to how we stopped. We retain separate wp_silent and
2863 bp_silent codes in case we want to change that someday.
2865 Another possibly interesting property of this table is that
2866 there's a partial ordering, priority-like, of the actions. Once
2867 you've decided that some action is appropriate, you'll never go
2868 back and decide something of a lower priority is better. The
2871 kc < clr sgl shl shlr slr sn sr ss ts
2872 sgl < clrs shl shlr slr sn sr ss ts
2873 slr < err shl shlr sn sr ss ts
2874 clr < clrs err shl shlr sn sr ss ts
2875 clrs < err shl shlr sn sr ss ts
2876 ss < shl shlr sn sr ts
2883 What I think this means is that we don't need a damned table
2884 here. If you just put the rows and columns in the right order,
2885 it'd look awfully regular. We could simply walk the bpstat list
2886 and choose the highest priority action we find, with a little
2887 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2888 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2889 is messy anyway). */
2891 /* step_resume entries: a step resume breakpoint overrides another
2892 breakpoint of signal handling (see comment in wait_for_inferior
2893 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2894 /* We handle the through_sigtramp_breakpoint the same way; having both
2895 one of those and a step_resume_breakpoint is probably very rare (?). */
2897 static const enum bpstat_what_main_action
2898 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2901 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2904 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2906 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2908 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2910 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2912 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2914 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2916 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2918 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2920 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2922 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2924 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2926 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2941 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
2942 struct bpstat_what retval
;
2944 retval
.call_dummy
= 0;
2945 for (; bs
!= NULL
; bs
= bs
->next
)
2947 enum class bs_class
= no_effect
;
2948 if (bs
->breakpoint_at
== NULL
)
2949 /* I suspect this can happen if it was a momentary breakpoint
2950 which has since been deleted. */
2952 switch (bs
->breakpoint_at
->type
)
2958 case bp_hardware_breakpoint
:
2964 bs_class
= bp_noisy
;
2966 bs_class
= bp_silent
;
2969 bs_class
= bp_nostop
;
2972 case bp_hardware_watchpoint
:
2973 case bp_read_watchpoint
:
2974 case bp_access_watchpoint
:
2978 bs_class
= wp_noisy
;
2980 bs_class
= wp_silent
;
2983 /* There was a watchpoint, but we're not stopping.
2984 This requires no further action. */
2985 bs_class
= no_effect
;
2988 bs_class
= long_jump
;
2990 case bp_longjmp_resume
:
2991 bs_class
= long_resume
;
2993 case bp_step_resume
:
2996 bs_class
= step_resume
;
2999 /* It is for the wrong frame. */
3000 bs_class
= bp_nostop
;
3002 case bp_through_sigtramp
:
3003 bs_class
= through_sig
;
3005 case bp_watchpoint_scope
:
3006 bs_class
= bp_nostop
;
3008 case bp_shlib_event
:
3009 bs_class
= shlib_event
;
3011 case bp_thread_event
:
3012 case bp_overlay_event
:
3013 bs_class
= bp_nostop
;
3016 case bp_catch_unload
:
3017 /* Only if this catchpoint triggered should we cause the
3018 step-out-of-dld behaviour. Otherwise, we ignore this
3021 bs_class
= catch_shlib_event
;
3023 bs_class
= no_effect
;
3026 case bp_catch_vfork
:
3031 bs_class
= bp_noisy
;
3033 bs_class
= bp_silent
;
3036 /* There was a catchpoint, but we're not stopping.
3037 This requires no further action. */
3038 bs_class
= no_effect
;
3040 case bp_catch_catch
:
3041 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3042 bs_class
= bp_nostop
;
3044 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3046 case bp_catch_throw
:
3047 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3048 bs_class
= bp_nostop
;
3050 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3053 /* Make sure the action is stop (silent or noisy),
3054 so infrun.c pops the dummy frame. */
3055 bs_class
= bp_silent
;
3056 retval
.call_dummy
= 1;
3059 current_action
= table
[(int) bs_class
][(int) current_action
];
3061 retval
.main_action
= current_action
;
3065 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3066 without hardware support). This isn't related to a specific bpstat,
3067 just to things like whether watchpoints are set. */
3070 bpstat_should_step (void)
3072 struct breakpoint
*b
;
3074 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3079 /* Nonzero if there are enabled hardware watchpoints. */
3081 bpstat_have_active_hw_watchpoints (void)
3083 struct breakpoint
*b
;
3085 if ((b
->enable_state
== bp_enabled
) &&
3087 ((b
->type
== bp_hardware_watchpoint
) ||
3088 (b
->type
== bp_read_watchpoint
) ||
3089 (b
->type
== bp_access_watchpoint
)))
3095 /* Given a bpstat that records zero or more triggered eventpoints, this
3096 function returns another bpstat which contains only the catchpoints
3097 on that first list, if any. */
3099 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3101 struct bpstats root_bs
[1];
3102 bpstat bs
= root_bs
;
3103 struct breakpoint
*ep
;
3106 bpstat_clear (cp_list
);
3107 root_bs
->next
= NULL
;
3109 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3111 /* Is this eventpoint a catchpoint? If not, ignore it. */
3112 ep
= ep_list
->breakpoint_at
;
3115 if ((ep
->type
!= bp_catch_load
) &&
3116 (ep
->type
!= bp_catch_unload
) &&
3117 (ep
->type
!= bp_catch_catch
) &&
3118 (ep
->type
!= bp_catch_throw
))
3119 /* pai: (temp) ADD fork/vfork here!! */
3122 /* Yes; add it to the list. */
3123 bs
= bpstat_alloc (ep
, bs
);
3128 #if defined(SOLIB_ADD)
3129 /* Also, for each triggered catchpoint, tag it with the name of
3130 the library that caused this trigger. (We copy the name now,
3131 because it's only guaranteed to be available NOW, when the
3132 catchpoint triggers. Clients who may wish to know the name
3133 later must get it from the catchpoint itself.) */
3134 if (ep
->triggered_dll_pathname
!= NULL
)
3135 xfree (ep
->triggered_dll_pathname
);
3136 if (ep
->type
== bp_catch_load
)
3137 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3138 PIDGET (inferior_ptid
));
3140 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3141 PIDGET (inferior_ptid
));
3143 dll_pathname
= NULL
;
3147 ep
->triggered_dll_pathname
= (char *)
3148 xmalloc (strlen (dll_pathname
) + 1);
3149 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3152 ep
->triggered_dll_pathname
= NULL
;
3158 /* Print B to gdb_stdout. */
3160 print_one_breakpoint (struct breakpoint
*b
,
3161 CORE_ADDR
*last_addr
)
3163 register struct command_line
*l
;
3164 register struct symbol
*sym
;
3165 struct ep_type_description
3170 static struct ep_type_description bptypes
[] =
3172 {bp_none
, "?deleted?"},
3173 {bp_breakpoint
, "breakpoint"},
3174 {bp_hardware_breakpoint
, "hw breakpoint"},
3175 {bp_until
, "until"},
3176 {bp_finish
, "finish"},
3177 {bp_watchpoint
, "watchpoint"},
3178 {bp_hardware_watchpoint
, "hw watchpoint"},
3179 {bp_read_watchpoint
, "read watchpoint"},
3180 {bp_access_watchpoint
, "acc watchpoint"},
3181 {bp_longjmp
, "longjmp"},
3182 {bp_longjmp_resume
, "longjmp resume"},
3183 {bp_step_resume
, "step resume"},
3184 {bp_through_sigtramp
, "sigtramp"},
3185 {bp_watchpoint_scope
, "watchpoint scope"},
3186 {bp_call_dummy
, "call dummy"},
3187 {bp_shlib_event
, "shlib events"},
3188 {bp_thread_event
, "thread events"},
3189 {bp_overlay_event
, "overlay events"},
3190 {bp_catch_load
, "catch load"},
3191 {bp_catch_unload
, "catch unload"},
3192 {bp_catch_fork
, "catch fork"},
3193 {bp_catch_vfork
, "catch vfork"},
3194 {bp_catch_exec
, "catch exec"},
3195 {bp_catch_catch
, "catch catch"},
3196 {bp_catch_throw
, "catch throw"}
3199 static char *bpdisps
[] =
3200 {"del", "dstp", "dis", "keep"};
3201 static char bpenables
[] = "nynny";
3202 char wrap_indent
[80];
3203 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3204 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3207 ui_out_tuple_begin (uiout
, "bkpt");
3211 ui_out_field_int (uiout
, "number", b
->number
);
3215 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3216 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3217 internal_error (__FILE__
, __LINE__
,
3218 "bptypes table does not describe type #%d.",
3220 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3224 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3228 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3229 ui_out_spaces (uiout
, 2);
3232 strcpy (wrap_indent
, " ");
3235 if (TARGET_ADDR_BIT
<= 32)
3236 strcat (wrap_indent
, " ");
3238 strcat (wrap_indent
, " ");
3243 internal_error (__FILE__
, __LINE__
,
3244 "print_one_breakpoint: bp_none encountered\n");
3248 case bp_hardware_watchpoint
:
3249 case bp_read_watchpoint
:
3250 case bp_access_watchpoint
:
3251 /* Field 4, the address, is omitted (which makes the columns
3252 not line up too nicely with the headers, but the effect
3253 is relatively readable). */
3255 ui_out_field_skip (uiout
, "addr");
3257 print_expression (b
->exp
, stb
->stream
);
3258 ui_out_field_stream (uiout
, "what", stb
);
3262 case bp_catch_unload
:
3263 /* Field 4, the address, is omitted (which makes the columns
3264 not line up too nicely with the headers, but the effect
3265 is relatively readable). */
3267 ui_out_field_skip (uiout
, "addr");
3269 if (b
->dll_pathname
== NULL
)
3271 ui_out_field_string (uiout
, "what", "<any library>");
3272 ui_out_spaces (uiout
, 1);
3276 ui_out_text (uiout
, "library \"");
3277 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3278 ui_out_text (uiout
, "\" ");
3283 case bp_catch_vfork
:
3284 /* Field 4, the address, is omitted (which makes the columns
3285 not line up too nicely with the headers, but the effect
3286 is relatively readable). */
3288 ui_out_field_skip (uiout
, "addr");
3290 if (b
->forked_inferior_pid
!= 0)
3292 ui_out_text (uiout
, "process ");
3293 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3294 ui_out_spaces (uiout
, 1);
3298 /* Field 4, the address, is omitted (which makes the columns
3299 not line up too nicely with the headers, but the effect
3300 is relatively readable). */
3302 ui_out_field_skip (uiout
, "addr");
3304 if (b
->exec_pathname
!= NULL
)
3306 ui_out_text (uiout
, "program \"");
3307 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3308 ui_out_text (uiout
, "\" ");
3312 case bp_catch_catch
:
3313 /* Field 4, the address, is omitted (which makes the columns
3314 not line up too nicely with the headers, but the effect
3315 is relatively readable). */
3317 ui_out_field_skip (uiout
, "addr");
3319 ui_out_field_string (uiout
, "what", "exception catch");
3320 ui_out_spaces (uiout
, 1);
3323 case bp_catch_throw
:
3324 /* Field 4, the address, is omitted (which makes the columns
3325 not line up too nicely with the headers, but the effect
3326 is relatively readable). */
3328 ui_out_field_skip (uiout
, "addr");
3330 ui_out_field_string (uiout
, "what", "exception throw");
3331 ui_out_spaces (uiout
, 1);
3335 case bp_hardware_breakpoint
:
3339 case bp_longjmp_resume
:
3340 case bp_step_resume
:
3341 case bp_through_sigtramp
:
3342 case bp_watchpoint_scope
:
3344 case bp_shlib_event
:
3345 case bp_thread_event
:
3346 case bp_overlay_event
:
3350 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3353 *last_addr
= b
->address
;
3356 sym
= find_pc_sect_function (b
->address
, b
->section
);
3359 ui_out_text (uiout
, "in ");
3360 ui_out_field_string (uiout
, "func",
3361 SYMBOL_SOURCE_NAME (sym
));
3362 ui_out_wrap_hint (uiout
, wrap_indent
);
3363 ui_out_text (uiout
, " at ");
3365 ui_out_field_string (uiout
, "file", b
->source_file
);
3366 ui_out_text (uiout
, ":");
3367 ui_out_field_int (uiout
, "line", b
->line_number
);
3371 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3372 ui_out_field_stream (uiout
, "at", stb
);
3377 if (b
->thread
!= -1)
3379 /* FIXME: This seems to be redundant and lost here; see the
3380 "stop only in" line a little further down. */
3381 ui_out_text (uiout
, " thread ");
3382 ui_out_field_int (uiout
, "thread", b
->thread
);
3385 ui_out_text (uiout
, "\n");
3390 ui_out_text (uiout
, "\tstop only in stack frame at ");
3391 ui_out_field_core_addr (uiout
, "frame", b
->frame
);
3392 ui_out_text (uiout
, "\n");
3398 ui_out_text (uiout
, "\tstop only if ");
3399 print_expression (b
->cond
, stb
->stream
);
3400 ui_out_field_stream (uiout
, "cond", stb
);
3401 ui_out_text (uiout
, "\n");
3404 if (b
->thread
!= -1)
3406 /* FIXME should make an annotation for this */
3407 ui_out_text (uiout
, "\tstop only in thread ");
3408 ui_out_field_int (uiout
, "thread", b
->thread
);
3409 ui_out_text (uiout
, "\n");
3412 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3414 /* FIXME should make an annotation for this */
3415 if (ep_is_catchpoint (b
))
3416 ui_out_text (uiout
, "\tcatchpoint");
3418 ui_out_text (uiout
, "\tbreakpoint");
3419 ui_out_text (uiout
, " already hit ");
3420 ui_out_field_int (uiout
, "times", b
->hit_count
);
3421 if (b
->hit_count
== 1)
3422 ui_out_text (uiout
, " time\n");
3424 ui_out_text (uiout
, " times\n");
3427 /* Output the count also if it is zero, but only if this is
3428 mi. FIXME: Should have a better test for this. */
3429 if (ui_out_is_mi_like_p (uiout
))
3430 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3431 ui_out_field_int (uiout
, "times", b
->hit_count
);
3433 if (b
->ignore_count
)
3436 ui_out_text (uiout
, "\tignore next ");
3437 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3438 ui_out_text (uiout
, " hits\n");
3441 if ((l
= b
->commands
))
3444 ui_out_tuple_begin (uiout
, "script");
3445 print_command_lines (uiout
, l
, 4);
3446 ui_out_tuple_end (uiout
);
3448 ui_out_tuple_end (uiout
);
3449 do_cleanups (old_chain
);
3452 struct captured_breakpoint_query_args
3458 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3460 struct captured_breakpoint_query_args
*args
= data
;
3461 register struct breakpoint
*b
;
3462 CORE_ADDR dummy_addr
= 0;
3465 if (args
->bnum
== b
->number
)
3467 print_one_breakpoint (b
, &dummy_addr
);
3475 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3477 struct captured_breakpoint_query_args args
;
3479 /* For the moment we don't trust print_one_breakpoint() to not throw
3481 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3482 NULL
, RETURN_MASK_ALL
);
3485 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3486 catchpoints, et.al.). */
3489 user_settable_breakpoint (const struct breakpoint
*b
)
3491 return (b
->type
== bp_breakpoint
3492 || b
->type
== bp_catch_load
3493 || b
->type
== bp_catch_unload
3494 || b
->type
== bp_catch_fork
3495 || b
->type
== bp_catch_vfork
3496 || b
->type
== bp_catch_exec
3497 || b
->type
== bp_catch_catch
3498 || b
->type
== bp_catch_throw
3499 || b
->type
== bp_hardware_breakpoint
3500 || b
->type
== bp_watchpoint
3501 || b
->type
== bp_read_watchpoint
3502 || b
->type
== bp_access_watchpoint
3503 || b
->type
== bp_hardware_watchpoint
);
3506 /* Print information on user settable breakpoint (watchpoint, etc)
3507 number BNUM. If BNUM is -1 print all user settable breakpoints.
3508 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3511 breakpoint_1 (int bnum
, int allflag
)
3513 register struct breakpoint
*b
;
3514 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3515 int nr_printable_breakpoints
;
3517 /* Compute the number of rows in the table. */
3518 nr_printable_breakpoints
= 0;
3521 || bnum
== b
->number
)
3523 if (allflag
|| user_settable_breakpoint (b
))
3524 nr_printable_breakpoints
++;
3528 ui_out_table_begin (uiout
, 6, nr_printable_breakpoints
, "BreakpointTable");
3530 ui_out_table_begin (uiout
, 5, nr_printable_breakpoints
, "BreakpointTable");
3532 if (nr_printable_breakpoints
> 0)
3533 annotate_breakpoints_headers ();
3534 if (nr_printable_breakpoints
> 0)
3536 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3537 if (nr_printable_breakpoints
> 0)
3539 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3540 if (nr_printable_breakpoints
> 0)
3542 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3543 if (nr_printable_breakpoints
> 0)
3545 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3548 if (nr_printable_breakpoints
> 0)
3550 if (TARGET_ADDR_BIT
<= 32)
3551 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3553 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3555 if (nr_printable_breakpoints
> 0)
3557 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3558 ui_out_table_body (uiout
);
3559 if (nr_printable_breakpoints
> 0)
3560 annotate_breakpoints_table ();
3564 || bnum
== b
->number
)
3566 /* We only print out user settable breakpoints unless the
3568 if (allflag
|| user_settable_breakpoint (b
))
3569 print_one_breakpoint (b
, &last_addr
);
3572 ui_out_table_end (uiout
);
3574 if (nr_printable_breakpoints
== 0)
3577 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3579 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3584 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3585 that a comparison of an unsigned with -1 is always false. */
3586 if (last_addr
!= (CORE_ADDR
) -1)
3587 set_next_address (last_addr
);
3590 /* FIXME? Should this be moved up so that it is only called when
3591 there have been breakpoints? */
3592 annotate_breakpoints_table_end ();
3597 breakpoints_info (char *bnum_exp
, int from_tty
)
3602 bnum
= parse_and_eval_long (bnum_exp
);
3604 breakpoint_1 (bnum
, 0);
3609 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3614 bnum
= parse_and_eval_long (bnum_exp
);
3616 breakpoint_1 (bnum
, 1);
3619 /* Print a message describing any breakpoints set at PC. */
3622 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3624 register int others
= 0;
3625 register struct breakpoint
*b
;
3628 if (b
->address
== pc
) /* address match / overlay match */
3629 if (!overlay_debugging
|| b
->section
== section
)
3633 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3635 if (b
->address
== pc
) /* address match / overlay match */
3636 if (!overlay_debugging
|| b
->section
== section
)
3639 printf_filtered ("%d%s%s ",
3641 ((b
->enable_state
== bp_disabled
||
3642 b
->enable_state
== bp_shlib_disabled
||
3643 b
->enable_state
== bp_call_disabled
)
3645 : b
->enable_state
== bp_permanent
3649 : ((others
== 1) ? " and" : ""));
3651 printf_filtered ("also set at pc ");
3652 print_address_numeric (pc
, 1, gdb_stdout
);
3653 printf_filtered (".\n");
3657 /* Set the default place to put a breakpoint
3658 for the `break' command with no arguments. */
3661 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3664 default_breakpoint_valid
= valid
;
3665 default_breakpoint_address
= addr
;
3666 default_breakpoint_symtab
= symtab
;
3667 default_breakpoint_line
= line
;
3670 /* Return true iff it is meaningful to use the address member of
3671 BPT. For some breakpoint types, the address member is irrelevant
3672 and it makes no sense to attempt to compare it to other addresses
3673 (or use it for any other purpose either).
3675 More specifically, each of the following breakpoint types will always
3676 have a zero valued address and we don't want check_duplicates() to mark
3677 breakpoints of any of these types to be a duplicate of an actual
3678 breakpoint at address zero:
3681 bp_hardware_watchpoint
3683 bp_access_watchpoint
3690 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3692 enum bptype type
= bpt
->type
;
3694 return (type
!= bp_watchpoint
3695 && type
!= bp_hardware_watchpoint
3696 && type
!= bp_read_watchpoint
3697 && type
!= bp_access_watchpoint
3698 && type
!= bp_catch_exec
3699 && type
!= bp_longjmp_resume
3700 && type
!= bp_catch_fork
3701 && type
!= bp_catch_vfork
);
3704 /* Rescan breakpoints at the same address and section as BPT,
3705 marking the first one as "first" and any others as "duplicates".
3706 This is so that the bpt instruction is only inserted once.
3707 If we have a permanent breakpoint at the same place as BPT, make
3708 that one the official one, and the rest as duplicates. */
3711 check_duplicates (struct breakpoint
*bpt
)
3713 register struct breakpoint
*b
;
3714 register int count
= 0;
3715 struct breakpoint
*perm_bp
= 0;
3716 CORE_ADDR address
= bpt
->address
;
3717 asection
*section
= bpt
->section
;
3719 if (! breakpoint_address_is_meaningful (bpt
))
3723 if (b
->enable_state
!= bp_disabled
3724 && b
->enable_state
!= bp_shlib_disabled
3725 && b
->enable_state
!= bp_call_disabled
3726 && b
->address
== address
/* address / overlay match */
3727 && (!overlay_debugging
|| b
->section
== section
)
3728 && breakpoint_address_is_meaningful (b
))
3730 /* Have we found a permanent breakpoint? */
3731 if (b
->enable_state
== bp_permanent
)
3738 b
->duplicate
= count
> 1;
3741 /* If we found a permanent breakpoint at this address, go over the
3742 list again and declare all the other breakpoints there to be the
3746 perm_bp
->duplicate
= 0;
3748 /* Permanent breakpoint should always be inserted. */
3749 if (! perm_bp
->inserted
)
3750 internal_error (__FILE__
, __LINE__
,
3751 "allegedly permanent breakpoint is not "
3752 "actually inserted");
3758 internal_error (__FILE__
, __LINE__
,
3759 "another breakpoint was inserted on top of "
3760 "a permanent breakpoint");
3762 if (b
->enable_state
!= bp_disabled
3763 && b
->enable_state
!= bp_shlib_disabled
3764 && b
->enable_state
!= bp_call_disabled
3765 && b
->address
== address
/* address / overlay match */
3766 && (!overlay_debugging
|| b
->section
== section
)
3767 && breakpoint_address_is_meaningful (b
))
3773 /* set_raw_breakpoint() is a low level routine for allocating and
3774 partially initializing a breakpoint of type BPTYPE. The newly
3775 created breakpoint's address, section, source file name, and line
3776 number are provided by SAL. The newly created and partially
3777 initialized breakpoint is added to the breakpoint chain and
3778 is also returned as the value of this function.
3780 It is expected that the caller will complete the initialization of
3781 the newly created breakpoint struct as well as output any status
3782 information regarding the creation of a new breakpoint. In
3783 particular, set_raw_breakpoint() does NOT set the breakpoint
3784 number! Care should be taken to not allow an error() to occur
3785 prior to completing the initialization of the breakpoint. If this
3786 should happen, a bogus breakpoint will be left on the chain. */
3789 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3791 register struct breakpoint
*b
, *b1
;
3793 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3794 memset (b
, 0, sizeof (*b
));
3795 b
->address
= sal
.pc
;
3796 if (sal
.symtab
== NULL
)
3797 b
->source_file
= NULL
;
3799 b
->source_file
= savestring (sal
.symtab
->filename
,
3800 strlen (sal
.symtab
->filename
));
3801 b
->section
= sal
.section
;
3803 b
->language
= current_language
->la_language
;
3804 b
->input_radix
= input_radix
;
3806 b
->line_number
= sal
.line
;
3807 b
->enable_state
= bp_enabled
;
3810 b
->ignore_count
= 0;
3813 b
->dll_pathname
= NULL
;
3814 b
->triggered_dll_pathname
= NULL
;
3815 b
->forked_inferior_pid
= 0;
3816 b
->exec_pathname
= NULL
;
3818 /* Add this breakpoint to the end of the chain
3819 so that a list of breakpoints will come out in order
3820 of increasing numbers. */
3822 b1
= breakpoint_chain
;
3824 breakpoint_chain
= b
;
3832 check_duplicates (b
);
3833 breakpoints_changed ();
3839 /* Note that the breakpoint object B describes a permanent breakpoint
3840 instruction, hard-wired into the inferior's code. */
3842 make_breakpoint_permanent (struct breakpoint
*b
)
3844 b
->enable_state
= bp_permanent
;
3846 /* By definition, permanent breakpoints are already present in the code. */
3850 static struct breakpoint
*
3851 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3853 static int internal_breakpoint_number
= -1;
3854 struct symtab_and_line sal
;
3855 struct breakpoint
*b
;
3857 INIT_SAL (&sal
); /* initialize to zeroes */
3860 sal
.section
= find_pc_overlay (sal
.pc
);
3862 b
= set_raw_breakpoint (sal
, type
);
3863 b
->number
= internal_breakpoint_number
--;
3864 b
->disposition
= disp_donttouch
;
3871 create_longjmp_breakpoint (char *func_name
)
3873 struct breakpoint
*b
;
3874 struct minimal_symbol
*m
;
3876 if (func_name
== NULL
)
3877 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3880 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3883 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3886 b
->enable_state
= bp_disabled
;
3889 b
->addr_string
= xstrdup (func_name
);
3892 /* Call this routine when stepping and nexting to enable a breakpoint
3893 if we do a longjmp(). When we hit that breakpoint, call
3894 set_longjmp_resume_breakpoint() to figure out where we are going. */
3897 enable_longjmp_breakpoint (void)
3899 register struct breakpoint
*b
;
3902 if (b
->type
== bp_longjmp
)
3904 b
->enable_state
= bp_enabled
;
3905 check_duplicates (b
);
3910 disable_longjmp_breakpoint (void)
3912 register struct breakpoint
*b
;
3915 if (b
->type
== bp_longjmp
3916 || b
->type
== bp_longjmp_resume
)
3918 b
->enable_state
= bp_disabled
;
3919 check_duplicates (b
);
3924 create_overlay_event_breakpoint (char *func_name
)
3926 struct breakpoint
*b
;
3927 struct minimal_symbol
*m
;
3929 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3932 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
3934 b
->addr_string
= xstrdup (func_name
);
3936 if (overlay_debugging
== ovly_auto
)
3938 b
->enable_state
= bp_enabled
;
3939 overlay_events_enabled
= 1;
3943 b
->enable_state
= bp_disabled
;
3944 overlay_events_enabled
= 0;
3949 enable_overlay_breakpoints (void)
3951 register struct breakpoint
*b
;
3954 if (b
->type
== bp_overlay_event
)
3956 b
->enable_state
= bp_enabled
;
3957 check_duplicates (b
);
3958 overlay_events_enabled
= 1;
3963 disable_overlay_breakpoints (void)
3965 register struct breakpoint
*b
;
3968 if (b
->type
== bp_overlay_event
)
3970 b
->enable_state
= bp_disabled
;
3971 check_duplicates (b
);
3972 overlay_events_enabled
= 0;
3977 create_thread_event_breakpoint (CORE_ADDR address
)
3979 struct breakpoint
*b
;
3980 char addr_string
[80]; /* Surely an addr can't be longer than that. */
3982 b
= create_internal_breakpoint (address
, bp_thread_event
);
3984 b
->enable_state
= bp_enabled
;
3985 /* addr_string has to be used or breakpoint_re_set will delete me. */
3986 sprintf (addr_string
, "*0x%s", paddr (b
->address
));
3987 b
->addr_string
= xstrdup (addr_string
);
3993 remove_thread_event_breakpoints (void)
3995 struct breakpoint
*b
, *temp
;
3997 ALL_BREAKPOINTS_SAFE (b
, temp
)
3998 if (b
->type
== bp_thread_event
)
3999 delete_breakpoint (b
);
4004 remove_solib_event_breakpoints (void)
4006 register struct breakpoint
*b
, *temp
;
4008 ALL_BREAKPOINTS_SAFE (b
, temp
)
4009 if (b
->type
== bp_shlib_event
)
4010 delete_breakpoint (b
);
4014 create_solib_event_breakpoint (CORE_ADDR address
)
4016 struct breakpoint
*b
;
4018 b
= create_internal_breakpoint (address
, bp_shlib_event
);
4022 /* Disable any breakpoints that are on code in shared libraries. Only
4023 apply to enabled breakpoints, disabled ones can just stay disabled. */
4026 disable_breakpoints_in_shlibs (int silent
)
4028 struct breakpoint
*b
;
4029 int disabled_shlib_breaks
= 0;
4031 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4034 #if defined (PC_SOLIB)
4035 if (((b
->type
== bp_breakpoint
) ||
4036 (b
->type
== bp_hardware_breakpoint
)) &&
4037 b
->enable_state
== bp_enabled
&&
4039 PC_SOLIB (b
->address
))
4041 b
->enable_state
= bp_shlib_disabled
;
4044 if (!disabled_shlib_breaks
)
4046 target_terminal_ours_for_output ();
4047 warning ("Temporarily disabling shared library breakpoints:");
4049 disabled_shlib_breaks
= 1;
4050 warning ("breakpoint #%d ", b
->number
);
4057 /* Try to reenable any breakpoints in shared libraries. */
4059 re_enable_breakpoints_in_shlibs (void)
4061 struct breakpoint
*b
;
4064 if (b
->enable_state
== bp_shlib_disabled
)
4068 /* Do not reenable the breakpoint if the shared library
4069 is still not mapped in. */
4070 if (target_read_memory (b
->address
, buf
, 1) == 0)
4071 b
->enable_state
= bp_enabled
;
4078 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4079 char *cond_string
, enum bptype bp_kind
)
4081 struct breakpoint
*b
;
4082 struct symtabs_and_lines sals
;
4083 struct cleanup
*old_chain
;
4084 struct cleanup
*canonical_strings_chain
= NULL
;
4085 char *addr_start
= hookname
;
4086 char *addr_end
= NULL
;
4087 char **canonical
= (char **) NULL
;
4088 int thread
= -1; /* All threads. */
4090 /* Set a breakpoint on the specified hook. */
4091 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4092 addr_end
= hookname
;
4094 if (sals
.nelts
== 0)
4096 warning ("Unable to set a breakpoint on dynamic linker callback.");
4097 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4098 warning ("GDB will be unable to track shl_load/shl_unload calls");
4101 if (sals
.nelts
!= 1)
4103 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4104 warning ("GDB will be unable to track shl_load/shl_unload calls");
4108 /* Make sure that all storage allocated in decode_line_1 gets freed
4109 in case the following errors out. */
4110 old_chain
= make_cleanup (xfree
, sals
.sals
);
4111 if (canonical
!= (char **) NULL
)
4113 make_cleanup (xfree
, canonical
);
4114 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4115 if (canonical
[0] != NULL
)
4116 make_cleanup (xfree
, canonical
[0]);
4119 resolve_sal_pc (&sals
.sals
[0]);
4121 /* Remove the canonical strings from the cleanup, they are needed below. */
4122 if (canonical
!= (char **) NULL
)
4123 discard_cleanups (canonical_strings_chain
);
4125 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4126 set_breakpoint_count (breakpoint_count
+ 1);
4127 b
->number
= breakpoint_count
;
4129 b
->cond_string
= (cond_string
== NULL
) ?
4130 NULL
: savestring (cond_string
, strlen (cond_string
));
4133 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4134 b
->addr_string
= canonical
[0];
4135 else if (addr_start
)
4136 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4138 b
->enable_state
= bp_enabled
;
4139 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4141 if (dll_pathname
== NULL
)
4142 b
->dll_pathname
= NULL
;
4145 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4146 strcpy (b
->dll_pathname
, dll_pathname
);
4150 do_cleanups (old_chain
);
4154 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4155 char *dll_pathname
, char *cond_string
)
4157 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4158 cond_string
, bp_catch_load
);
4162 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4163 char *dll_pathname
, char *cond_string
)
4165 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4166 cond_string
, bp_catch_unload
);
4170 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4171 enum bptype bp_kind
)
4173 struct symtab_and_line sal
;
4174 struct breakpoint
*b
;
4175 int thread
= -1; /* All threads. */
4182 b
= set_raw_breakpoint (sal
, bp_kind
);
4183 set_breakpoint_count (breakpoint_count
+ 1);
4184 b
->number
= breakpoint_count
;
4186 b
->cond_string
= (cond_string
== NULL
) ?
4187 NULL
: savestring (cond_string
, strlen (cond_string
));
4189 b
->addr_string
= NULL
;
4190 b
->enable_state
= bp_enabled
;
4191 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4192 b
->forked_inferior_pid
= 0;
4198 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4200 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4204 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4206 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4210 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4212 struct symtab_and_line sal
;
4213 struct breakpoint
*b
;
4214 int thread
= -1; /* All threads. */
4221 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4222 set_breakpoint_count (breakpoint_count
+ 1);
4223 b
->number
= breakpoint_count
;
4225 b
->cond_string
= (cond_string
== NULL
) ?
4226 NULL
: savestring (cond_string
, strlen (cond_string
));
4228 b
->addr_string
= NULL
;
4229 b
->enable_state
= bp_enabled
;
4230 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4236 hw_breakpoint_used_count (void)
4238 register struct breakpoint
*b
;
4243 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4251 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4253 register struct breakpoint
*b
;
4256 *other_type_used
= 0;
4259 if (b
->enable_state
== bp_enabled
)
4261 if (b
->type
== type
)
4263 else if ((b
->type
== bp_hardware_watchpoint
||
4264 b
->type
== bp_read_watchpoint
||
4265 b
->type
== bp_access_watchpoint
)
4266 && b
->enable_state
== bp_enabled
)
4267 *other_type_used
= 1;
4273 /* Call this after hitting the longjmp() breakpoint. Use this to set
4274 a new breakpoint at the target of the jmp_buf.
4276 FIXME - This ought to be done by setting a temporary breakpoint
4277 that gets deleted automatically... */
4280 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_info
*frame
)
4282 register struct breakpoint
*b
;
4285 if (b
->type
== bp_longjmp_resume
)
4288 b
->enable_state
= bp_enabled
;
4290 b
->frame
= frame
->frame
;
4293 check_duplicates (b
);
4299 disable_watchpoints_before_interactive_call_start (void)
4301 struct breakpoint
*b
;
4305 if (((b
->type
== bp_watchpoint
)
4306 || (b
->type
== bp_hardware_watchpoint
)
4307 || (b
->type
== bp_read_watchpoint
)
4308 || (b
->type
== bp_access_watchpoint
)
4309 || ep_is_exception_catchpoint (b
))
4310 && (b
->enable_state
== bp_enabled
))
4312 b
->enable_state
= bp_call_disabled
;
4313 check_duplicates (b
);
4319 enable_watchpoints_after_interactive_call_stop (void)
4321 struct breakpoint
*b
;
4325 if (((b
->type
== bp_watchpoint
)
4326 || (b
->type
== bp_hardware_watchpoint
)
4327 || (b
->type
== bp_read_watchpoint
)
4328 || (b
->type
== bp_access_watchpoint
)
4329 || ep_is_exception_catchpoint (b
))
4330 && (b
->enable_state
== bp_call_disabled
))
4332 b
->enable_state
= bp_enabled
;
4333 check_duplicates (b
);
4339 /* Set a breakpoint that will evaporate an end of command
4340 at address specified by SAL.
4341 Restrict it to frame FRAME if FRAME is nonzero. */
4344 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_info
*frame
,
4347 register struct breakpoint
*b
;
4348 b
= set_raw_breakpoint (sal
, type
);
4349 b
->enable_state
= bp_enabled
;
4350 b
->disposition
= disp_donttouch
;
4351 b
->frame
= (frame
? frame
->frame
: 0);
4353 /* If we're debugging a multi-threaded program, then we
4354 want momentary breakpoints to be active in only a
4355 single thread of control. */
4356 if (in_thread_list (inferior_ptid
))
4357 b
->thread
= pid_to_thread_id (inferior_ptid
);
4363 /* Tell the user we have just set a breakpoint B. */
4366 mention (struct breakpoint
*b
)
4369 struct cleanup
*old_chain
;
4370 struct ui_stream
*stb
;
4372 stb
= ui_out_stream_new (uiout
);
4373 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4375 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4376 watchpoint) other than breakpoint creation. It should be possible to
4377 clean this up and at the same time replace the random calls to
4378 breakpoint_changed with this hook, as has already been done for
4379 delete_breakpoint_hook and so on. */
4380 if (create_breakpoint_hook
)
4381 create_breakpoint_hook (b
);
4382 breakpoint_create_event (b
->number
);
4387 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4390 ui_out_text (uiout
, "Watchpoint ");
4391 ui_out_tuple_begin (uiout
, "wpt");
4392 ui_out_field_int (uiout
, "number", b
->number
);
4393 ui_out_text (uiout
, ": ");
4394 print_expression (b
->exp
, stb
->stream
);
4395 ui_out_field_stream (uiout
, "exp", stb
);
4396 ui_out_tuple_end (uiout
);
4398 case bp_hardware_watchpoint
:
4399 ui_out_text (uiout
, "Hardware watchpoint ");
4400 ui_out_tuple_begin (uiout
, "wpt");
4401 ui_out_field_int (uiout
, "number", b
->number
);
4402 ui_out_text (uiout
, ": ");
4403 print_expression (b
->exp
, stb
->stream
);
4404 ui_out_field_stream (uiout
, "exp", stb
);
4405 ui_out_tuple_end (uiout
);
4407 case bp_read_watchpoint
:
4408 ui_out_text (uiout
, "Hardware read watchpoint ");
4409 ui_out_tuple_begin (uiout
, "hw-rwpt");
4410 ui_out_field_int (uiout
, "number", b
->number
);
4411 ui_out_text (uiout
, ": ");
4412 print_expression (b
->exp
, stb
->stream
);
4413 ui_out_field_stream (uiout
, "exp", stb
);
4414 ui_out_tuple_end (uiout
);
4416 case bp_access_watchpoint
:
4417 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4418 ui_out_tuple_begin (uiout
, "hw-awpt");
4419 ui_out_field_int (uiout
, "number", b
->number
);
4420 ui_out_text (uiout
, ": ");
4421 print_expression (b
->exp
, stb
->stream
);
4422 ui_out_field_stream (uiout
, "exp", stb
);
4423 ui_out_tuple_end (uiout
);
4426 if (ui_out_is_mi_like_p (uiout
))
4431 printf_filtered ("Breakpoint %d", b
->number
);
4434 case bp_hardware_breakpoint
:
4435 if (ui_out_is_mi_like_p (uiout
))
4440 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4444 case bp_catch_unload
:
4445 printf_filtered ("Catchpoint %d (%s %s)",
4447 (b
->type
== bp_catch_load
) ? "load" : "unload",
4448 (b
->dll_pathname
!= NULL
) ?
4449 b
->dll_pathname
: "<any library>");
4452 case bp_catch_vfork
:
4453 printf_filtered ("Catchpoint %d (%s)",
4455 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4458 printf_filtered ("Catchpoint %d (exec)",
4461 case bp_catch_catch
:
4462 case bp_catch_throw
:
4463 printf_filtered ("Catchpoint %d (%s)",
4465 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4471 case bp_longjmp_resume
:
4472 case bp_step_resume
:
4473 case bp_through_sigtramp
:
4475 case bp_watchpoint_scope
:
4476 case bp_shlib_event
:
4477 case bp_thread_event
:
4478 case bp_overlay_event
:
4483 if (addressprint
|| b
->source_file
== NULL
)
4485 printf_filtered (" at ");
4486 print_address_numeric (b
->address
, 1, gdb_stdout
);
4489 printf_filtered (": file %s, line %d.",
4490 b
->source_file
, b
->line_number
);
4492 do_cleanups (old_chain
);
4493 if (ui_out_is_mi_like_p (uiout
))
4495 printf_filtered ("\n");
4499 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4500 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4501 COND[i] and COND_STRING[i] values.
4503 NOTE: If the function succeeds, the caller is expected to cleanup
4504 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4505 array contents). If the function fails (error() is called), the
4506 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4507 COND and SALS arrays and each of those arrays contents. */
4510 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4511 struct expression
**cond
, char **cond_string
,
4512 enum bptype type
, enum bpdisp disposition
,
4513 int thread
, int ignore_count
, int from_tty
)
4515 if (type
== bp_hardware_breakpoint
)
4517 int i
= hw_breakpoint_used_count ();
4518 int target_resources_ok
=
4519 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4521 if (target_resources_ok
== 0)
4522 error ("No hardware breakpoint support in the target.");
4523 else if (target_resources_ok
< 0)
4524 error ("Hardware breakpoints used exceeds limit.");
4527 /* Now set all the breakpoints. */
4530 for (i
= 0; i
< sals
.nelts
; i
++)
4532 struct breakpoint
*b
;
4533 struct symtab_and_line sal
= sals
.sals
[i
];
4536 describe_other_breakpoints (sal
.pc
, sal
.section
);
4538 b
= set_raw_breakpoint (sal
, type
);
4539 set_breakpoint_count (breakpoint_count
+ 1);
4540 b
->number
= breakpoint_count
;
4543 b
->addr_string
= addr_string
[i
];
4544 b
->cond_string
= cond_string
[i
];
4545 b
->ignore_count
= ignore_count
;
4546 b
->enable_state
= bp_enabled
;
4547 b
->disposition
= disposition
;
4553 /* Parse ARG which is assumed to be a SAL specification possibly
4554 followed by conditionals. On return, SALS contains an array of SAL
4555 addresses found. ADDR_STRING contains a vector of (canonical)
4556 address strings. ARG points to the end of the SAL. */
4559 parse_breakpoint_sals (char **address
,
4560 struct symtabs_and_lines
*sals
,
4561 char ***addr_string
)
4563 char *addr_start
= *address
;
4564 *addr_string
= NULL
;
4565 /* If no arg given, or if first arg is 'if ', use the default
4567 if ((*address
) == NULL
4568 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4570 if (default_breakpoint_valid
)
4572 struct symtab_and_line sal
;
4573 INIT_SAL (&sal
); /* initialize to zeroes */
4574 sals
->sals
= (struct symtab_and_line
*)
4575 xmalloc (sizeof (struct symtab_and_line
));
4576 sal
.pc
= default_breakpoint_address
;
4577 sal
.line
= default_breakpoint_line
;
4578 sal
.symtab
= default_breakpoint_symtab
;
4579 sal
.section
= find_pc_overlay (sal
.pc
);
4580 sals
->sals
[0] = sal
;
4584 error ("No default breakpoint address now.");
4588 /* Force almost all breakpoints to be in terms of the
4589 current_source_symtab (which is decode_line_1's default). This
4590 should produce the results we want almost all of the time while
4591 leaving default_breakpoint_* alone. */
4592 if (default_breakpoint_valid
4593 && (!current_source_symtab
4594 || (strchr ("+-", (*address
)[0]) != NULL
)))
4595 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4596 default_breakpoint_line
, addr_string
);
4598 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4600 /* For any SAL that didn't have a canonical string, fill one in. */
4601 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4602 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4603 if (addr_start
!= (*address
))
4606 for (i
= 0; i
< sals
->nelts
; i
++)
4608 /* Add the string if not present. */
4609 if ((*addr_string
)[i
] == NULL
)
4610 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4616 /* Convert each SAL into a real PC. Verify that the PC can be
4617 inserted as a breakpoint. If it can't throw an error. */
4620 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4624 for (i
= 0; i
< sals
->nelts
; i
++)
4626 resolve_sal_pc (&sals
->sals
[i
]);
4628 /* It's possible for the PC to be nonzero, but still an illegal
4629 value on some targets.
4631 For example, on HP-UX if you start gdb, and before running the
4632 inferior you try to set a breakpoint on a shared library function
4633 "foo" where the inferior doesn't call "foo" directly but does
4634 pass its address to another function call, then we do find a
4635 minimal symbol for the "foo", but it's address is invalid.
4636 (Appears to be an index into a table that the loader sets up
4637 when the inferior is run.)
4639 Give the target a chance to bless sals.sals[i].pc before we
4640 try to make a breakpoint for it. */
4641 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4643 if (address
== NULL
)
4644 error ("Cannot break without a running program.");
4646 error ("Cannot break on %s without a running program.",
4652 /* Set a breakpoint according to ARG (function, linenum or *address)
4653 flag: first bit : 0 non-temporary, 1 temporary.
4654 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4657 break_command_1 (char *arg
, int flag
, int from_tty
)
4659 int tempflag
, hardwareflag
;
4660 struct symtabs_and_lines sals
;
4661 register struct expression
**cond
= 0;
4662 /* Pointers in arg to the start, and one past the end, of the
4664 char **cond_string
= (char **) NULL
;
4665 char *addr_start
= arg
;
4667 struct cleanup
*old_chain
;
4668 struct cleanup
*breakpoint_chain
= NULL
;
4671 int ignore_count
= 0;
4673 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4674 tempflag
= flag
& BP_TEMPFLAG
;
4679 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4684 /* Create a chain of things that always need to be cleaned up. */
4685 old_chain
= make_cleanup (null_cleanup
, 0);
4687 /* Make sure that all storage allocated to SALS gets freed. */
4688 make_cleanup (xfree
, sals
.sals
);
4690 /* Cleanup the addr_string array but not its contents. */
4691 make_cleanup (xfree
, addr_string
);
4693 /* Allocate space for all the cond expressions. */
4694 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4695 make_cleanup (xfree
, cond
);
4697 /* Allocate space for all the cond strings. */
4698 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4699 make_cleanup (xfree
, cond_string
);
4701 /* ----------------------------- SNIP -----------------------------
4702 Anything added to the cleanup chain beyond this point is assumed
4703 to be part of a breakpoint. If the breakpoint create succeeds
4704 then the memory is not reclaimed. */
4705 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4707 /* Mark the contents of the addr_string for cleanup. These go on
4708 the breakpoint_chain and only occure if the breakpoint create
4710 for (i
= 0; i
< sals
.nelts
; i
++)
4712 if (addr_string
[i
] != NULL
)
4713 make_cleanup (xfree
, addr_string
[i
]);
4716 /* Resolve all line numbers to PC's and verify that the addresses
4717 are ok for the target. */
4718 breakpoint_sals_to_pc (&sals
, addr_start
);
4720 /* Verify that condition can be parsed, before setting any
4721 breakpoints. Allocate a separate condition expression for each
4723 thread
= -1; /* No specific thread yet */
4724 for (i
= 0; i
< sals
.nelts
; i
++)
4731 char *cond_start
= NULL
;
4732 char *cond_end
= NULL
;
4733 while (*tok
== ' ' || *tok
== '\t')
4738 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4741 toklen
= end_tok
- tok
;
4743 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4745 tok
= cond_start
= end_tok
+ 1;
4746 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4747 make_cleanup (xfree
, cond
[i
]);
4749 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4750 make_cleanup (xfree
, cond_string
[i
]);
4752 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4758 thread
= strtol (tok
, &tok
, 0);
4760 error ("Junk after thread keyword.");
4761 if (!valid_thread_id (thread
))
4762 error ("Unknown thread %d\n", thread
);
4765 error ("Junk at end of arguments.");
4769 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4770 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4771 tempflag
? disp_del
: disp_donttouch
,
4772 thread
, ignore_count
, from_tty
);
4776 warning ("Multiple breakpoints were set.");
4777 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4779 /* That's it. Discard the cleanups for data inserted into the
4781 discard_cleanups (breakpoint_chain
);
4782 /* But cleanup everything else. */
4783 do_cleanups (old_chain
);
4786 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4787 linenum or *address) with COND and IGNORE_COUNT. */
4789 struct captured_breakpoint_args
4800 do_captured_breakpoint (void *data
)
4802 struct captured_breakpoint_args
*args
= data
;
4803 struct symtabs_and_lines sals
;
4804 register struct expression
**cond
;
4805 struct cleanup
*old_chain
;
4806 struct cleanup
*breakpoint_chain
= NULL
;
4813 /* Parse the source and lines spec. Delay check that the expression
4814 didn't contain trailing garbage until after cleanups are in
4818 address_end
= args
->address
;
4820 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4825 /* Create a chain of things at always need to be cleaned up. */
4826 old_chain
= make_cleanup (null_cleanup
, 0);
4828 /* Always have a addr_string array, even if it is empty. */
4829 make_cleanup (xfree
, addr_string
);
4831 /* Make sure that all storage allocated to SALS gets freed. */
4832 make_cleanup (xfree
, sals
.sals
);
4834 /* Allocate space for all the cond expressions. */
4835 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4836 make_cleanup (xfree
, cond
);
4838 /* Allocate space for all the cond strings. */
4839 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4840 make_cleanup (xfree
, cond_string
);
4842 /* ----------------------------- SNIP -----------------------------
4843 Anything added to the cleanup chain beyond this point is assumed
4844 to be part of a breakpoint. If the breakpoint create goes
4845 through then that memory is not cleaned up. */
4846 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4848 /* Mark the contents of the addr_string for cleanup. These go on
4849 the breakpoint_chain and only occure if the breakpoint create
4851 for (i
= 0; i
< sals
.nelts
; i
++)
4853 if (addr_string
[i
] != NULL
)
4854 make_cleanup (xfree
, addr_string
[i
]);
4857 /* Wait until now before checking for garbage at the end of the
4858 address. That way cleanups can take care of freeing any
4860 if (*address_end
!= '\0')
4861 error ("Garbage %s following breakpoint address", address_end
);
4863 /* Resolve all line numbers to PC's. */
4864 breakpoint_sals_to_pc (&sals
, args
->address
);
4866 /* Verify that conditions can be parsed, before setting any
4868 for (i
= 0; i
< sals
.nelts
; i
++)
4870 if (args
->condition
!= NULL
)
4872 char *tok
= args
->condition
;
4873 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4875 error ("Garbage %s follows condition", tok
);
4876 make_cleanup (xfree
, cond
[i
]);
4877 cond_string
[i
] = xstrdup (args
->condition
);
4881 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4882 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4883 args
->tempflag
? disp_del
: disp_donttouch
,
4884 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4886 /* That's it. Discard the cleanups for data inserted into the
4888 discard_cleanups (breakpoint_chain
);
4889 /* But cleanup everything else. */
4890 do_cleanups (old_chain
);
4895 gdb_breakpoint (char *address
, char *condition
,
4896 int hardwareflag
, int tempflag
,
4897 int thread
, int ignore_count
)
4899 struct captured_breakpoint_args args
;
4900 args
.address
= address
;
4901 args
.condition
= condition
;
4902 args
.hardwareflag
= hardwareflag
;
4903 args
.tempflag
= tempflag
;
4904 args
.thread
= thread
;
4905 args
.ignore_count
= ignore_count
;
4906 return catch_errors (do_captured_breakpoint
, &args
,
4907 NULL
, RETURN_MASK_ALL
);
4912 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4914 struct frame_info
*frame
;
4915 CORE_ADDR low
, high
, selected_pc
= 0;
4916 char *extra_args
= NULL
;
4919 int extra_args_len
= 0, if_arg
= 0;
4922 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4925 if (default_breakpoint_valid
)
4929 selected_pc
= selected_frame
->pc
;
4934 error ("No selected frame.");
4937 error ("No default breakpoint address now.");
4941 extra_args
= strchr (arg
, ' ');
4945 extra_args_len
= strlen (extra_args
);
4946 level_arg
= (char *) xmalloc (extra_args
- arg
);
4947 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
4948 level_arg
[extra_args
- arg
- 1] = '\0';
4952 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
4953 strcpy (level_arg
, arg
);
4956 frame
= parse_frame_specification (level_arg
);
4958 selected_pc
= frame
->pc
;
4965 extra_args_len
= strlen (arg
);
4970 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
4972 addr_string
= (char *) xmalloc (26 + extra_args_len
);
4974 sprintf (addr_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
4976 sprintf (addr_string
, "*0x%s", paddr_nz (high
));
4977 break_command_1 (addr_string
, flag
, from_tty
);
4978 xfree (addr_string
);
4981 error ("No function contains the specified address");
4984 error ("Unable to set breakpoint at procedure exit");
4989 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
4991 char *addr_string
, *break_string
, *beg_addr_string
;
4992 CORE_ADDR low
, high
;
4993 struct symtabs_and_lines sals
;
4994 struct symtab_and_line sal
;
4995 struct cleanup
*old_chain
;
4996 char *extra_args
= NULL
;
4997 int extra_args_len
= 0;
5001 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
5003 if (default_breakpoint_valid
)
5007 addr_string
= (char *) xmalloc (15);
5008 sprintf (addr_string
, "*0x%s", paddr_nz (selected_frame
->pc
));
5013 error ("No selected frame.");
5016 error ("No default breakpoint address now.");
5020 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
5021 strcpy (addr_string
, arg
);
5027 extra_args_len
= strlen (arg
);
5031 /* get the stuff after the function name or address */
5032 extra_args
= strchr (arg
, ' ');
5036 extra_args_len
= strlen (extra_args
);
5043 beg_addr_string
= addr_string
;
5044 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5047 xfree (beg_addr_string
);
5048 old_chain
= make_cleanup (xfree
, sals
.sals
);
5049 for (i
= 0; (i
< sals
.nelts
); i
++)
5052 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5054 break_string
= (char *) xmalloc (extra_args_len
+ 26);
5056 sprintf (break_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5058 sprintf (break_string
, "*0x%s", paddr_nz (high
));
5059 break_command_1 (break_string
, flag
, from_tty
);
5060 xfree (break_string
);
5063 error ("No function contains the specified address");
5067 warning ("Multiple breakpoints were set.\n");
5068 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5070 do_cleanups (old_chain
);
5074 /* Helper function for break_command_1 and disassemble_command. */
5077 resolve_sal_pc (struct symtab_and_line
*sal
)
5081 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5083 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5084 error ("No line %d in file \"%s\".",
5085 sal
->line
, sal
->symtab
->filename
);
5089 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5091 struct blockvector
*bv
;
5096 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5099 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5100 sym
= block_function (b
);
5103 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5104 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5108 /* It really is worthwhile to have the section, so we'll just
5109 have to look harder. This case can be executed if we have
5110 line numbers but no functions (as can happen in assembly
5113 struct minimal_symbol
*msym
;
5115 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5117 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5124 break_command (char *arg
, int from_tty
)
5126 break_command_1 (arg
, 0, from_tty
);
5130 break_at_finish_command (char *arg
, int from_tty
)
5132 break_at_finish_command_1 (arg
, 0, from_tty
);
5136 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5138 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5142 tbreak_command (char *arg
, int from_tty
)
5144 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5148 tbreak_at_finish_command (char *arg
, int from_tty
)
5150 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5154 hbreak_command (char *arg
, int from_tty
)
5156 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5160 thbreak_command (char *arg
, int from_tty
)
5162 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5166 stop_command (char *arg
, int from_tty
)
5168 printf_filtered ("Specify the type of breakpoint to set.\n\
5169 Usage: stop in <function | address>\n\
5174 stopin_command (char *arg
, int from_tty
)
5178 if (arg
== (char *) NULL
)
5180 else if (*arg
!= '*')
5185 /* look for a ':'. If this is a line number specification, then
5186 say it is bad, otherwise, it should be an address or
5187 function/method name */
5188 while (*argptr
&& !hasColon
)
5190 hasColon
= (*argptr
== ':');
5195 badInput
= (*argptr
!= ':'); /* Not a class::method */
5197 badInput
= isdigit (*arg
); /* a simple line number */
5201 printf_filtered ("Usage: stop in <function | address>\n");
5203 break_command_1 (arg
, 0, from_tty
);
5207 stopat_command (char *arg
, int from_tty
)
5211 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5218 /* look for a ':'. If there is a '::' then get out, otherwise
5219 it is probably a line number. */
5220 while (*argptr
&& !hasColon
)
5222 hasColon
= (*argptr
== ':');
5227 badInput
= (*argptr
== ':'); /* we have class::method */
5229 badInput
= !isdigit (*arg
); /* not a line number */
5233 printf_filtered ("Usage: stop at <line>\n");
5235 break_command_1 (arg
, 0, from_tty
);
5239 /* accessflag: hw_write: watch write,
5240 hw_read: watch read,
5241 hw_access: watch access (read or write) */
5243 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5245 struct breakpoint
*b
;
5246 struct symtab_and_line sal
;
5247 struct expression
*exp
;
5248 struct block
*exp_valid_block
;
5249 struct value
*val
, *mark
;
5250 struct frame_info
*frame
;
5251 struct frame_info
*prev_frame
= NULL
;
5252 char *exp_start
= NULL
;
5253 char *exp_end
= NULL
;
5254 char *tok
, *end_tok
;
5256 char *cond_start
= NULL
;
5257 char *cond_end
= NULL
;
5258 struct expression
*cond
= NULL
;
5259 int i
, other_type_used
, target_resources_ok
= 0;
5260 enum bptype bp_type
;
5263 INIT_SAL (&sal
); /* initialize to zeroes */
5265 /* Parse arguments. */
5266 innermost_block
= NULL
;
5268 exp
= parse_exp_1 (&arg
, 0, 0);
5270 exp_valid_block
= innermost_block
;
5271 mark
= value_mark ();
5272 val
= evaluate_expression (exp
);
5273 release_value (val
);
5274 if (VALUE_LAZY (val
))
5275 value_fetch_lazy (val
);
5278 while (*tok
== ' ' || *tok
== '\t')
5282 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5285 toklen
= end_tok
- tok
;
5286 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5288 tok
= cond_start
= end_tok
+ 1;
5289 cond
= parse_exp_1 (&tok
, 0, 0);
5293 error ("Junk at end of command.");
5295 if (accessflag
== hw_read
)
5296 bp_type
= bp_read_watchpoint
;
5297 else if (accessflag
== hw_access
)
5298 bp_type
= bp_access_watchpoint
;
5300 bp_type
= bp_hardware_watchpoint
;
5302 mem_cnt
= can_use_hardware_watchpoint (val
);
5303 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5304 error ("Expression cannot be implemented with read/access watchpoint.");
5307 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5308 target_resources_ok
=
5309 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5311 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5312 error ("Target does not support this type of hardware watchpoint.");
5314 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5315 error ("Target can only support one kind of HW watchpoint at a time.");
5318 #if defined(HPUXHPPA)
5319 /* On HP-UX if you set a h/w
5320 watchpoint before the "run" command, the inferior dies with a e.g.,
5321 SIGILL once you start it. I initially believed this was due to a
5322 bad interaction between page protection traps and the initial
5323 startup sequence by the dynamic linker.
5325 However, I tried avoiding that by having HP-UX's implementation of
5326 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5327 yet, which forced slow watches before a "run" or "attach", and it
5328 still fails somewhere in the startup code.
5330 Until I figure out what's happening, I'm disallowing watches altogether
5331 before the "run" or "attach" command. We'll tell the user they must
5332 set watches after getting the program started. */
5333 if (!target_has_execution
)
5335 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5338 #endif /* HPUXHPPA */
5340 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5341 watchpoint could not be set. */
5342 if (!mem_cnt
|| target_resources_ok
<= 0)
5343 bp_type
= bp_watchpoint
;
5345 /* Now set up the breakpoint. */
5346 b
= set_raw_breakpoint (sal
, bp_type
);
5347 set_breakpoint_count (breakpoint_count
+ 1);
5348 b
->number
= breakpoint_count
;
5349 b
->disposition
= disp_donttouch
;
5351 b
->exp_valid_block
= exp_valid_block
;
5352 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5356 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5360 frame
= block_innermost_frame (exp_valid_block
);
5363 prev_frame
= get_prev_frame (frame
);
5364 get_frame_id (frame
, &b
->watchpoint_frame
);
5368 memset (&b
->watchpoint_frame
, 0, sizeof (b
->watchpoint_frame
));
5371 /* If the expression is "local", then set up a "watchpoint scope"
5372 breakpoint at the point where we've left the scope of the watchpoint
5374 if (innermost_block
)
5378 struct breakpoint
*scope_breakpoint
;
5379 scope_breakpoint
= create_internal_breakpoint (get_frame_pc (prev_frame
),
5380 bp_watchpoint_scope
);
5382 scope_breakpoint
->enable_state
= bp_enabled
;
5384 /* Automatically delete the breakpoint when it hits. */
5385 scope_breakpoint
->disposition
= disp_del
;
5387 /* Only break in the proper frame (help with recursion). */
5388 scope_breakpoint
->frame
= prev_frame
->frame
;
5390 /* Set the address at which we will stop. */
5391 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5393 /* The scope breakpoint is related to the watchpoint. We
5394 will need to act on them together. */
5395 b
->related_breakpoint
= scope_breakpoint
;
5398 value_free_to_mark (mark
);
5402 /* Return count of locations need to be watched and can be handled
5403 in hardware. If the watchpoint can not be handled
5404 in hardware return zero. */
5406 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5407 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5408 ((BYTE_SIZE) <= (REGISTER_SIZE))
5411 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5412 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5413 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5417 can_use_hardware_watchpoint (struct value
*v
)
5419 int found_memory_cnt
= 0;
5420 struct value
*head
= v
;
5422 /* Did the user specifically forbid us to use hardware watchpoints? */
5423 if (!can_use_hw_watchpoints
)
5426 /* Make sure that the value of the expression depends only upon
5427 memory contents, and values computed from them within GDB. If we
5428 find any register references or function calls, we can't use a
5429 hardware watchpoint.
5431 The idea here is that evaluating an expression generates a series
5432 of values, one holding the value of every subexpression. (The
5433 expression a*b+c has five subexpressions: a, b, a*b, c, and
5434 a*b+c.) GDB's values hold almost enough information to establish
5435 the criteria given above --- they identify memory lvalues,
5436 register lvalues, computed values, etcetera. So we can evaluate
5437 the expression, and then scan the chain of values that leaves
5438 behind to decide whether we can detect any possible change to the
5439 expression's final value using only hardware watchpoints.
5441 However, I don't think that the values returned by inferior
5442 function calls are special in any way. So this function may not
5443 notice that an expression involving an inferior function call
5444 can't be watched with hardware watchpoints. FIXME. */
5445 for (; v
; v
= v
->next
)
5447 if (VALUE_LVAL (v
) == lval_memory
)
5450 /* A lazy memory lvalue is one that GDB never needed to fetch;
5451 we either just used its address (e.g., `a' in `a.b') or
5452 we never needed it at all (e.g., `a' in `a,b'). */
5456 /* Ahh, memory we actually used! Check if we can cover
5457 it with hardware watchpoints. */
5458 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5460 /* We only watch structs and arrays if user asked for it
5461 explicitly, never if they just happen to appear in a
5462 middle of some value chain. */
5464 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5465 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5467 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5468 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5470 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5477 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5478 return 0; /* ??? What does this represent? */
5479 else if (v
->lval
== lval_register
)
5480 return 0; /* cannot watch a register with a HW watchpoint */
5483 /* The expression itself looks suitable for using a hardware
5484 watchpoint, but give the target machine a chance to reject it. */
5485 return found_memory_cnt
;
5489 watch_command_wrapper (char *arg
, int from_tty
)
5491 watch_command (arg
, from_tty
);
5495 watch_command (char *arg
, int from_tty
)
5497 watch_command_1 (arg
, hw_write
, from_tty
);
5501 rwatch_command_wrapper (char *arg
, int from_tty
)
5503 rwatch_command (arg
, from_tty
);
5507 rwatch_command (char *arg
, int from_tty
)
5509 watch_command_1 (arg
, hw_read
, from_tty
);
5513 awatch_command_wrapper (char *arg
, int from_tty
)
5515 awatch_command (arg
, from_tty
);
5519 awatch_command (char *arg
, int from_tty
)
5521 watch_command_1 (arg
, hw_access
, from_tty
);
5525 /* Helper routines for the until_command routine in infcmd.c. Here
5526 because it uses the mechanisms of breakpoints. */
5528 /* This function is called by fetch_inferior_event via the
5529 cmd_continuation pointer, to complete the until command. It takes
5530 care of cleaning up the temporary breakpoints set up by the until
5533 until_break_command_continuation (struct continuation_arg
*arg
)
5535 struct cleanup
*cleanups
;
5537 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5538 do_exec_cleanups (cleanups
);
5543 until_break_command (char *arg
, int from_tty
)
5545 struct symtabs_and_lines sals
;
5546 struct symtab_and_line sal
;
5547 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
5548 struct breakpoint
*breakpoint
;
5549 struct cleanup
*old_chain
;
5550 struct continuation_arg
*arg1
;
5553 clear_proceed_status ();
5555 /* Set a breakpoint where the user wants it and at return from
5558 if (default_breakpoint_valid
)
5559 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5560 default_breakpoint_line
, (char ***) NULL
);
5562 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5563 0, (char ***) NULL
);
5565 if (sals
.nelts
!= 1)
5566 error ("Couldn't get information on specified line.");
5569 xfree (sals
.sals
); /* malloc'd, so freed */
5572 error ("Junk at end of arguments.");
5574 resolve_sal_pc (&sal
);
5576 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
5578 if (!event_loop_p
|| !target_can_async_p ())
5579 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5581 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5583 /* If we are running asynchronously, and the target supports async
5584 execution, we are not waiting for the target to stop, in the call
5585 tp proceed, below. This means that we cannot delete the
5586 brekpoints until the target has actually stopped. The only place
5587 where we get a chance to do that is in fetch_inferior_event, so
5588 we must set things up for that. */
5590 if (event_loop_p
&& target_can_async_p ())
5592 /* In this case the arg for the continuation is just the point
5593 in the exec_cleanups chain from where to start doing
5594 cleanups, because all the continuation does is the cleanups in
5595 the exec_cleanup_chain. */
5597 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5599 arg1
->data
.pointer
= old_chain
;
5601 add_continuation (until_break_command_continuation
, arg1
);
5604 /* Keep within the current frame */
5608 sal
= find_pc_line (prev_frame
->pc
, 0);
5609 sal
.pc
= prev_frame
->pc
;
5610 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
5611 if (!event_loop_p
|| !target_can_async_p ())
5612 make_cleanup_delete_breakpoint (breakpoint
);
5614 make_exec_cleanup_delete_breakpoint (breakpoint
);
5617 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5618 /* Do the cleanups now, anly if we are not running asynchronously,
5619 of if we are, but the target is still synchronous. */
5620 if (!event_loop_p
|| !target_can_async_p ())
5621 do_cleanups (old_chain
);
5625 /* These aren't used; I don't konw what they were for. */
5626 /* Set a breakpoint at the catch clause for NAME. */
5628 catch_breakpoint (char *name
)
5633 disable_catch_breakpoint (void)
5638 delete_catch_breakpoint (void)
5643 enable_catch_breakpoint (void)
5650 struct sal_chain
*next
;
5651 struct symtab_and_line sal
;
5655 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5656 had been commented out in the v.4.16 sources, and stays
5657 disabled there now because "catch NAME" syntax isn't allowed.
5659 /* This isn't used; I don't know what it was for. */
5660 /* For each catch clause identified in ARGS, run FUNCTION
5661 with that clause as an argument. */
5662 static struct symtabs_and_lines
5663 map_catch_names (char *args
, int (*function
) ())
5665 register char *p
= args
;
5667 struct symtabs_and_lines sals
;
5669 struct sal_chain
*sal_chain
= 0;
5673 error_no_arg ("one or more catch names");
5681 /* Don't swallow conditional part. */
5682 if (p1
[0] == 'i' && p1
[1] == 'f'
5683 && (p1
[2] == ' ' || p1
[2] == '\t'))
5689 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
5693 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
5694 error ("Arguments must be catch names.");
5700 struct sal_chain
*next
= (struct sal_chain
*)
5701 alloca (sizeof (struct sal_chain
));
5702 next
->next
= sal_chain
;
5703 next
->sal
= get_catch_sal (p
);
5708 printf_unfiltered ("No catch clause for exception %s.\n", p
);
5713 while (*p
== ' ' || *p
== '\t')
5719 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5721 static struct symtabs_and_lines
5722 get_catch_sals (int this_level_only
)
5724 register struct blockvector
*bl
;
5725 register struct block
*block
;
5726 int index
, have_default
= 0;
5728 struct symtabs_and_lines sals
;
5729 struct sal_chain
*sal_chain
= 0;
5730 char *blocks_searched
;
5732 /* Not sure whether an error message is always the correct response,
5733 but it's better than a core dump. */
5734 if (selected_frame
== NULL
)
5735 error ("No selected frame.");
5736 block
= get_frame_block (selected_frame
, 0);
5737 pc
= selected_frame
->pc
;
5743 error ("No symbol table info available.\n");
5745 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
5746 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5747 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5751 CORE_ADDR end
= BLOCK_END (block
) - 4;
5754 if (bl
!= blockvector_for_pc (end
, &index
))
5755 error ("blockvector blotch");
5756 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
5757 error ("blockvector botch");
5758 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
5761 /* Don't print out blocks that have gone by. */
5762 while (index
< last_index
5763 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
5766 while (index
< last_index
5767 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
5769 if (blocks_searched
[index
] == 0)
5771 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
5773 register struct symbol
*sym
;
5775 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
5777 if (STREQ (SYMBOL_NAME (sym
), "default"))
5783 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
5785 struct sal_chain
*next
= (struct sal_chain
*)
5786 alloca (sizeof (struct sal_chain
));
5787 next
->next
= sal_chain
;
5788 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
),
5793 blocks_searched
[index
] = 1;
5799 if (sal_chain
&& this_level_only
)
5802 /* After handling the function's top-level block, stop.
5803 Don't continue to its superblock, the block of
5804 per-file symbols. */
5805 if (BLOCK_FUNCTION (block
))
5807 block
= BLOCK_SUPERBLOCK (block
);
5812 struct sal_chain
*tmp_chain
;
5814 /* Count the number of entries. */
5815 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
5816 tmp_chain
= tmp_chain
->next
)
5820 sals
.sals
= (struct symtab_and_line
*)
5821 xmalloc (index
* sizeof (struct symtab_and_line
));
5822 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
5823 sals
.sals
[index
] = sal_chain
->sal
;
5830 ep_skip_leading_whitespace (char **s
)
5832 if ((s
== NULL
) || (*s
== NULL
))
5834 while (isspace (**s
))
5838 /* This function examines a string, and attempts to find a token
5839 that might be an event name in the leading characters. If a
5840 possible match is found, a pointer to the last character of
5841 the token is returned. Else, NULL is returned. */
5844 ep_find_event_name_end (char *arg
)
5847 char *event_name_end
= NULL
;
5849 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5853 /* We break out of the loop when we find a token delimiter.
5854 Basically, we're looking for alphanumerics and underscores;
5855 anything else delimites the token. */
5858 if (!isalnum (*s
) && (*s
!= '_'))
5864 return event_name_end
;
5868 /* This function attempts to parse an optional "if <cond>" clause
5869 from the arg string. If one is not found, it returns NULL.
5871 Else, it returns a pointer to the condition string. (It does not
5872 attempt to evaluate the string against a particular block.) And,
5873 it updates arg to point to the first character following the parsed
5874 if clause in the arg string. */
5877 ep_parse_optional_if_clause (char **arg
)
5881 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5884 /* Skip the "if" keyword. */
5887 /* Skip any extra leading whitespace, and record the start of the
5888 condition string. */
5889 ep_skip_leading_whitespace (arg
);
5892 /* Assume that the condition occupies the remainder of the arg string. */
5893 (*arg
) += strlen (cond_string
);
5898 /* This function attempts to parse an optional filename from the arg
5899 string. If one is not found, it returns NULL.
5901 Else, it returns a pointer to the parsed filename. (This function
5902 makes no attempt to verify that a file of that name exists, or is
5903 accessible.) And, it updates arg to point to the first character
5904 following the parsed filename in the arg string.
5906 Note that clients needing to preserve the returned filename for
5907 future access should copy it to their own buffers. */
5909 ep_parse_optional_filename (char **arg
)
5911 static char filename
[1024];
5916 if ((*arg_p
== '\0') || isspace (*arg_p
))
5934 /* Commands to deal with catching events, such as signals, exceptions,
5935 process start/exit, etc. */
5939 catch_fork
, catch_vfork
5943 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5944 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5945 char *arg
, int tempflag
, int from_tty
);
5948 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5951 char *cond_string
= NULL
;
5953 ep_skip_leading_whitespace (&arg
);
5955 /* The allowed syntax is:
5957 catch [v]fork if <cond>
5959 First, check if there's an if clause. */
5960 cond_string
= ep_parse_optional_if_clause (&arg
);
5962 if ((*arg
!= '\0') && !isspace (*arg
))
5963 error ("Junk at end of arguments.");
5965 /* If this target supports it, create a fork or vfork catchpoint
5966 and enable reporting of such events. */
5970 create_fork_event_catchpoint (tempflag
, cond_string
);
5973 create_vfork_event_catchpoint (tempflag
, cond_string
);
5976 error ("unsupported or unknown fork kind; cannot catch it");
5982 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5984 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5986 char *cond_string
= NULL
;
5988 ep_skip_leading_whitespace (&arg
);
5990 /* The allowed syntax is:
5992 catch exec if <cond>
5994 First, check if there's an if clause. */
5995 cond_string
= ep_parse_optional_if_clause (&arg
);
5997 if ((*arg
!= '\0') && !isspace (*arg
))
5998 error ("Junk at end of arguments.");
6000 /* If this target supports it, create an exec catchpoint
6001 and enable reporting of such events. */
6002 create_exec_event_catchpoint (tempflag
, cond_string
);
6006 #if defined(SOLIB_ADD)
6008 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
6010 char *dll_pathname
= NULL
;
6011 char *cond_string
= NULL
;
6013 ep_skip_leading_whitespace (&arg
);
6015 /* The allowed syntax is:
6017 catch load if <cond>
6018 catch load <filename>
6019 catch load <filename> if <cond>
6021 The user is not allowed to specify the <filename> after an
6024 We'll ignore the pathological case of a file named "if".
6026 First, check if there's an if clause. If so, then there
6027 cannot be a filename. */
6028 cond_string
= ep_parse_optional_if_clause (&arg
);
6030 /* If there was an if clause, then there cannot be a filename.
6031 Else, there might be a filename and an if clause. */
6032 if (cond_string
== NULL
)
6034 dll_pathname
= ep_parse_optional_filename (&arg
);
6035 ep_skip_leading_whitespace (&arg
);
6036 cond_string
= ep_parse_optional_if_clause (&arg
);
6039 if ((*arg
!= '\0') && !isspace (*arg
))
6040 error ("Junk at end of arguments.");
6042 /* Create a load breakpoint that only triggers when a load of
6043 the specified dll (or any dll, if no pathname was specified)
6045 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6046 dll_pathname
, cond_string
);
6050 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6052 char *dll_pathname
= NULL
;
6053 char *cond_string
= NULL
;
6055 ep_skip_leading_whitespace (&arg
);
6057 /* The allowed syntax is:
6059 catch unload if <cond>
6060 catch unload <filename>
6061 catch unload <filename> if <cond>
6063 The user is not allowed to specify the <filename> after an
6066 We'll ignore the pathological case of a file named "if".
6068 First, check if there's an if clause. If so, then there
6069 cannot be a filename. */
6070 cond_string
= ep_parse_optional_if_clause (&arg
);
6072 /* If there was an if clause, then there cannot be a filename.
6073 Else, there might be a filename and an if clause. */
6074 if (cond_string
== NULL
)
6076 dll_pathname
= ep_parse_optional_filename (&arg
);
6077 ep_skip_leading_whitespace (&arg
);
6078 cond_string
= ep_parse_optional_if_clause (&arg
);
6081 if ((*arg
!= '\0') && !isspace (*arg
))
6082 error ("Junk at end of arguments.");
6084 /* Create an unload breakpoint that only triggers when an unload of
6085 the specified dll (or any dll, if no pathname was specified)
6087 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6088 dll_pathname
, cond_string
);
6090 #endif /* SOLIB_ADD */
6092 /* Commands to deal with catching exceptions. */
6094 /* Set a breakpoint at the specified callback routine for an
6095 exception event callback */
6098 create_exception_catchpoint (int tempflag
, char *cond_string
,
6099 enum exception_event_kind ex_event
,
6100 struct symtab_and_line
*sal
)
6102 struct breakpoint
*b
;
6103 int thread
= -1; /* All threads. */
6106 if (!sal
) /* no exception support? */
6111 case EX_EVENT_THROW
:
6112 bptype
= bp_catch_throw
;
6114 case EX_EVENT_CATCH
:
6115 bptype
= bp_catch_catch
;
6117 default: /* error condition */
6118 error ("Internal error -- invalid catchpoint kind");
6121 b
= set_raw_breakpoint (*sal
, bptype
);
6122 set_breakpoint_count (breakpoint_count
+ 1);
6123 b
->number
= breakpoint_count
;
6125 b
->cond_string
= (cond_string
== NULL
) ?
6126 NULL
: savestring (cond_string
, strlen (cond_string
));
6128 b
->addr_string
= NULL
;
6129 b
->enable_state
= bp_enabled
;
6130 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6134 /* Deal with "catch catch" and "catch throw" commands */
6137 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6138 int tempflag
, int from_tty
)
6140 char *cond_string
= NULL
;
6141 struct symtab_and_line
*sal
= NULL
;
6143 ep_skip_leading_whitespace (&arg
);
6145 cond_string
= ep_parse_optional_if_clause (&arg
);
6147 if ((*arg
!= '\0') && !isspace (*arg
))
6148 error ("Junk at end of arguments.");
6150 if ((ex_event
!= EX_EVENT_THROW
) &&
6151 (ex_event
!= EX_EVENT_CATCH
))
6152 error ("Unsupported or unknown exception event; cannot catch it");
6154 /* See if we can find a callback routine */
6155 sal
= target_enable_exception_callback (ex_event
, 1);
6159 /* We have callbacks from the runtime system for exceptions.
6160 Set a breakpoint on the sal found, if no errors */
6161 if (sal
!= (struct symtab_and_line
*) -1)
6162 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6164 return; /* something went wrong with setting up callbacks */
6168 /* No callbacks from runtime system for exceptions.
6169 Try GNU C++ exception breakpoints using labels in debug info. */
6170 if (ex_event
== EX_EVENT_CATCH
)
6172 handle_gnu_4_16_catch_command (arg
, tempflag
, from_tty
);
6174 else if (ex_event
== EX_EVENT_THROW
)
6176 /* Set a breakpoint on __raise_exception () */
6178 warning ("Unsupported with this platform/compiler combination.");
6179 warning ("Perhaps you can achieve the effect you want by setting");
6180 warning ("a breakpoint on __raise_exception().");
6185 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6186 inside a catch_errors */
6189 cover_target_enable_exception_callback (PTR arg
)
6191 args_for_catchpoint_enable
*args
= arg
;
6192 struct symtab_and_line
*sal
;
6193 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6196 else if (sal
== (struct symtab_and_line
*) -1)
6199 return 1; /*is valid */
6204 /* This is the original v.4.16 and earlier version of the
6205 catch_command_1() function. Now that other flavours of "catch"
6206 have been introduced, and since exception handling can be handled
6207 in other ways (through target ops) also, this is used only for the
6208 GNU C++ exception handling system.
6209 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6210 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6211 there was no code in GDB 4.16 for "catch throw".
6213 Called from catch_exception_command_1 () */
6217 handle_gnu_4_16_catch_command (char *arg
, int tempflag
, int from_tty
)
6219 /* First, translate ARG into something we can deal with in terms
6222 struct symtabs_and_lines sals
;
6223 struct symtab_and_line sal
;
6224 register struct expression
*cond
= 0;
6225 register struct breakpoint
*b
;
6229 INIT_SAL (&sal
); /* initialize to zeroes */
6231 /* If no arg given, or if first arg is 'if ', all active catch clauses
6232 are breakpointed. */
6234 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
6235 && (arg
[2] == ' ' || arg
[2] == '\t')))
6237 /* Grab all active catch clauses. */
6238 sals
= get_catch_sals (0);
6242 /* Grab selected catch clauses. */
6243 error ("catch NAME not implemented");
6246 /* Not sure why this code has been disabled. I'm leaving
6247 it disabled. We can never come here now anyway
6248 since we don't allow the "catch NAME" syntax.
6251 /* This isn't used; I don't know what it was for. */
6252 sals
= map_catch_names (arg
, catch_breakpoint
);
6260 for (i
= 0; i
< sals
.nelts
; i
++)
6262 resolve_sal_pc (&sals
.sals
[i
]);
6266 if (arg
[0] == 'i' && arg
[1] == 'f'
6267 && (arg
[2] == ' ' || arg
[2] == '\t'))
6268 cond
= parse_exp_1 ((arg
+= 2, &arg
),
6269 block_for_pc (sals
.sals
[i
].pc
), 0);
6271 error ("Junk at end of arguments.");
6276 for (i
= 0; i
< sals
.nelts
; i
++)
6281 describe_other_breakpoints (sal
.pc
, sal
.section
);
6283 /* Important -- this is an ordinary breakpoint. For platforms
6284 with callback support for exceptions,
6285 create_exception_catchpoint() will create special bp types
6286 (bp_catch_catch and bp_catch_throw), and there is code in
6287 insert_breakpoints() and elsewhere that depends on that. */
6288 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6289 set_breakpoint_count (breakpoint_count
+ 1);
6290 b
->number
= breakpoint_count
;
6293 b
->enable_state
= bp_enabled
;
6294 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6301 warning ("Multiple breakpoints were set.");
6302 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6308 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6311 /* The first argument may be an event name, such as "start" or "load".
6312 If so, then handle it as such. If it doesn't match an event name,
6313 then attempt to interpret it as an exception name. (This latter is
6314 the v4.16-and-earlier GDB meaning of the "catch" command.)
6316 First, try to find the bounds of what might be an event name. */
6317 char *arg1_start
= arg
;
6321 if (arg1_start
== NULL
)
6323 /* Old behaviour was to use pre-v-4.16 syntax */
6324 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6326 /* Now, this is not allowed */
6327 error ("Catch requires an event name.");
6330 arg1_end
= ep_find_event_name_end (arg1_start
);
6331 if (arg1_end
== NULL
)
6332 error ("catch requires an event");
6333 arg1_length
= arg1_end
+ 1 - arg1_start
;
6335 /* Try to match what we found against known event names. */
6336 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6338 error ("Catch of signal not yet implemented");
6340 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6342 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6343 tempflag
, from_tty
);
6345 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6347 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6348 tempflag
, from_tty
);
6350 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6352 error ("Catch of thread_start not yet implemented");
6354 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6356 error ("Catch of thread_exit not yet implemented");
6358 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6360 error ("Catch of thread_join not yet implemented");
6362 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6364 error ("Catch of start not yet implemented");
6366 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6368 error ("Catch of exit not yet implemented");
6370 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6372 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6373 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6375 error ("Catch of fork not yet implemented");
6378 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6380 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6381 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6383 error ("Catch of vfork not yet implemented");
6386 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6388 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6389 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6391 error ("Catch of exec not yet implemented");
6394 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6396 #if defined(SOLIB_ADD)
6397 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6399 error ("Catch of load not implemented");
6402 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6404 #if defined(SOLIB_ADD)
6405 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6407 error ("Catch of load not implemented");
6410 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6412 error ("Catch of stop not yet implemented");
6415 /* This doesn't appear to be an event name */
6419 /* Pre-v.4.16 behaviour was to treat the argument
6420 as the name of an exception */
6421 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6422 /* Now this is not allowed */
6423 error ("Unknown event kind specified for catch");
6428 /* Used by the gui, could be made a worker for other things. */
6431 set_breakpoint_sal (struct symtab_and_line sal
)
6433 struct breakpoint
*b
;
6434 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6435 set_breakpoint_count (breakpoint_count
+ 1);
6436 b
->number
= breakpoint_count
;
6443 /* These aren't used; I don't know what they were for. */
6444 /* Disable breakpoints on all catch clauses described in ARGS. */
6446 disable_catch (char *args
)
6448 /* Map the disable command to catch clauses described in ARGS. */
6451 /* Enable breakpoints on all catch clauses described in ARGS. */
6453 enable_catch (char *args
)
6455 /* Map the disable command to catch clauses described in ARGS. */
6458 /* Delete breakpoints on all catch clauses in the active scope. */
6460 delete_catch (char *args
)
6462 /* Map the delete command to catch clauses described in ARGS. */
6467 catch_command (char *arg
, int from_tty
)
6469 catch_command_1 (arg
, 0, from_tty
);
6474 tcatch_command (char *arg
, int from_tty
)
6476 catch_command_1 (arg
, 1, from_tty
);
6479 /* Delete breakpoints by address or line. */
6482 clear_command (char *arg
, int from_tty
)
6484 struct breakpoint
*b
, *tmp
, *prev
, *found
;
6486 struct symtabs_and_lines sals
;
6487 struct symtab_and_line sal
;
6492 sals
= decode_line_spec (arg
, 1);
6497 sals
.sals
= (struct symtab_and_line
*)
6498 xmalloc (sizeof (struct symtab_and_line
));
6499 make_cleanup (xfree
, sals
.sals
);
6500 INIT_SAL (&sal
); /* initialize to zeroes */
6501 sal
.line
= default_breakpoint_line
;
6502 sal
.symtab
= default_breakpoint_symtab
;
6503 sal
.pc
= default_breakpoint_address
;
6504 if (sal
.symtab
== 0)
6505 error ("No source file specified.");
6513 /* For each line spec given, delete bps which correspond
6514 to it. Do it in two passes, solely to preserve the current
6515 behavior that from_tty is forced true if we delete more than
6519 for (i
= 0; i
< sals
.nelts
; i
++)
6521 /* If exact pc given, clear bpts at that pc.
6522 If line given (pc == 0), clear all bpts on specified line.
6523 If defaulting, clear all bpts on default line
6526 defaulting sal.pc != 0 tests to do
6531 1 0 <can't happen> */
6536 /* Find all matching breakpoints, remove them from the
6537 breakpoint chain, and add them to the 'found' chain. */
6538 ALL_BREAKPOINTS_SAFE (b
, tmp
)
6540 /* Are we going to delete b? */
6541 if (b
->type
!= bp_none
6542 && b
->type
!= bp_watchpoint
6543 && b
->type
!= bp_hardware_watchpoint
6544 && b
->type
!= bp_read_watchpoint
6545 && b
->type
!= bp_access_watchpoint
6546 /* Not if b is a watchpoint of any sort... */
6547 && (((sal
.pc
&& (b
->address
== sal
.pc
))
6548 && (!section_is_overlay (b
->section
)
6549 || b
->section
== sal
.section
))
6550 /* Yes, if sal.pc matches b (modulo overlays). */
6551 || ((default_match
|| (0 == sal
.pc
))
6552 && b
->source_file
!= NULL
6553 && sal
.symtab
!= NULL
6554 && STREQ (b
->source_file
, sal
.symtab
->filename
)
6555 && b
->line_number
== sal
.line
)))
6556 /* Yes, if sal source file and line matches b. */
6558 /* Remove it from breakpoint_chain... */
6559 if (b
== breakpoint_chain
)
6561 /* b is at the head of the list */
6562 breakpoint_chain
= b
->next
;
6566 prev
->next
= b
->next
;
6568 /* And add it to 'found' chain. */
6574 /* Keep b, and keep a pointer to it. */
6579 /* Now go thru the 'found' chain and delete them. */
6583 error ("No breakpoint at %s.", arg
);
6585 error ("No breakpoint at this line.");
6589 from_tty
= 1; /* Always report if deleted more than one */
6591 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6592 breakpoints_changed ();
6596 printf_unfiltered ("%d ", found
->number
);
6598 delete_breakpoint (found
);
6602 putchar_unfiltered ('\n');
6605 /* Delete breakpoint in BS if they are `delete' breakpoints and
6606 all breakpoints that are marked for deletion, whether hit or not.
6607 This is called after any breakpoint is hit, or after errors. */
6610 breakpoint_auto_delete (bpstat bs
)
6612 struct breakpoint
*b
, *temp
;
6614 for (; bs
; bs
= bs
->next
)
6615 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6617 delete_breakpoint (bs
->breakpoint_at
);
6619 ALL_BREAKPOINTS_SAFE (b
, temp
)
6621 if (b
->disposition
== disp_del_at_next_stop
)
6622 delete_breakpoint (b
);
6626 /* Delete a breakpoint and clean up all traces of it in the data
6630 delete_breakpoint (struct breakpoint
*bpt
)
6632 register struct breakpoint
*b
;
6636 error ("Internal error (attempted to delete a NULL breakpoint)");
6639 /* Has this bp already been deleted? This can happen because multiple
6640 lists can hold pointers to bp's. bpstat lists are especial culprits.
6642 One example of this happening is a watchpoint's scope bp. When the
6643 scope bp triggers, we notice that the watchpoint is out of scope, and
6644 delete it. We also delete its scope bp. But the scope bp is marked
6645 "auto-deleting", and is already on a bpstat. That bpstat is then
6646 checked for auto-deleting bp's, which are deleted.
6648 A real solution to this problem might involve reference counts in bp's,
6649 and/or giving them pointers back to their referencing bpstat's, and
6650 teaching delete_breakpoint to only free a bp's storage when no more
6651 references were extent. A cheaper bandaid was chosen. */
6652 if (bpt
->type
== bp_none
)
6655 if (delete_breakpoint_hook
)
6656 delete_breakpoint_hook (bpt
);
6657 breakpoint_delete_event (bpt
->number
);
6660 remove_breakpoint (bpt
, mark_inserted
);
6662 if (breakpoint_chain
== bpt
)
6663 breakpoint_chain
= bpt
->next
;
6665 /* If we have callback-style exception catchpoints, don't go through
6666 the adjustments to the C++ runtime library etc. if the inferior
6667 isn't actually running. target_enable_exception_callback for a
6668 null target ops vector gives an undesirable error message, so we
6669 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6670 exceptions are supported in this way, it's OK for now. FIXME */
6671 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6673 static char message1
[] = "Error in deleting catchpoint %d:\n";
6674 static char message
[sizeof (message1
) + 30];
6675 args_for_catchpoint_enable args
;
6677 /* Format possible error msg */
6678 sprintf (message
, message1
, bpt
->number
);
6679 args
.kind
= bpt
->type
== bp_catch_catch
?
6680 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6682 catch_errors (cover_target_enable_exception_callback
, &args
,
6683 message
, RETURN_MASK_ALL
);
6690 b
->next
= bpt
->next
;
6694 check_duplicates (bpt
);
6695 /* If this breakpoint was inserted, and there is another breakpoint
6696 at the same address, we need to insert the other breakpoint. */
6698 && bpt
->type
!= bp_hardware_watchpoint
6699 && bpt
->type
!= bp_read_watchpoint
6700 && bpt
->type
!= bp_access_watchpoint
6701 && bpt
->type
!= bp_catch_fork
6702 && bpt
->type
!= bp_catch_vfork
6703 && bpt
->type
!= bp_catch_exec
)
6706 if (b
->address
== bpt
->address
6707 && b
->section
== bpt
->section
6709 && b
->enable_state
!= bp_disabled
6710 && b
->enable_state
!= bp_shlib_disabled
6711 && b
->enable_state
!= bp_call_disabled
)
6715 /* We should never reach this point if there is a permanent
6716 breakpoint at the same address as the one being deleted.
6717 If there is a permanent breakpoint somewhere, it should
6718 always be the only one inserted. */
6719 if (b
->enable_state
== bp_permanent
)
6720 internal_error (__FILE__
, __LINE__
,
6721 "another breakpoint was inserted on top of "
6722 "a permanent breakpoint");
6724 if (b
->type
== bp_hardware_breakpoint
)
6725 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6727 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6729 /* If there was an error in the insert, print a message, then stop execution. */
6732 struct ui_file
*tmp_error_stream
= mem_fileopen ();
6733 make_cleanup_ui_file_delete (tmp_error_stream
);
6736 if (b
->type
== bp_hardware_breakpoint
)
6738 fprintf_unfiltered (tmp_error_stream
,
6739 "Cannot insert hardware breakpoint %d.\n"
6740 "You may have requested too many hardware breakpoints.\n",
6745 fprintf_unfiltered (tmp_error_stream
, "Cannot insert breakpoint %d.\n", b
->number
);
6746 fprintf_filtered (tmp_error_stream
, "Error accessing memory address ");
6747 print_address_numeric (b
->address
, 1, tmp_error_stream
);
6748 fprintf_filtered (tmp_error_stream
, ": %s.\n",
6749 safe_strerror (val
));
6752 fprintf_unfiltered (tmp_error_stream
,"The same program may be running in another process.");
6753 target_terminal_ours_for_output ();
6754 error_stream(tmp_error_stream
);
6761 free_command_lines (&bpt
->commands
);
6764 if (bpt
->cond_string
!= NULL
)
6765 xfree (bpt
->cond_string
);
6766 if (bpt
->addr_string
!= NULL
)
6767 xfree (bpt
->addr_string
);
6768 if (bpt
->exp
!= NULL
)
6770 if (bpt
->exp_string
!= NULL
)
6771 xfree (bpt
->exp_string
);
6772 if (bpt
->val
!= NULL
)
6773 value_free (bpt
->val
);
6774 if (bpt
->source_file
!= NULL
)
6775 xfree (bpt
->source_file
);
6776 if (bpt
->dll_pathname
!= NULL
)
6777 xfree (bpt
->dll_pathname
);
6778 if (bpt
->triggered_dll_pathname
!= NULL
)
6779 xfree (bpt
->triggered_dll_pathname
);
6780 if (bpt
->exec_pathname
!= NULL
)
6781 xfree (bpt
->exec_pathname
);
6783 /* Be sure no bpstat's are pointing at it after it's been freed. */
6784 /* FIXME, how can we find all bpstat's?
6785 We just check stop_bpstat for now. */
6786 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6787 if (bs
->breakpoint_at
== bpt
)
6789 bs
->breakpoint_at
= NULL
;
6791 /* we'd call bpstat_clear_actions, but that free's stuff and due
6792 to the multiple pointers pointing to one item with no
6793 reference counts found anywhere through out the bpstat's (how
6794 do you spell fragile?), we don't want to free things twice --
6795 better a memory leak than a corrupt malloc pool! */
6796 bs
->commands
= NULL
;
6799 /* On the chance that someone will soon try again to delete this same
6800 bp, we mark it as deleted before freeing its storage. */
6801 bpt
->type
= bp_none
;
6807 do_delete_breakpoint_cleanup (void *b
)
6809 delete_breakpoint (b
);
6813 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6815 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6819 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6821 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6825 delete_command (char *arg
, int from_tty
)
6827 struct breakpoint
*b
, *temp
;
6833 int breaks_to_delete
= 0;
6835 /* Delete all breakpoints if no argument.
6836 Do not delete internal or call-dummy breakpoints, these
6837 have to be deleted with an explicit breakpoint number argument. */
6840 if (b
->type
!= bp_call_dummy
&&
6841 b
->type
!= bp_shlib_event
&&
6842 b
->type
!= bp_thread_event
&&
6843 b
->type
!= bp_overlay_event
&&
6845 breaks_to_delete
= 1;
6848 /* Ask user only if there are some breakpoints to delete. */
6850 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6852 ALL_BREAKPOINTS_SAFE (b
, temp
)
6854 if (b
->type
!= bp_call_dummy
&&
6855 b
->type
!= bp_shlib_event
&&
6856 b
->type
!= bp_thread_event
&&
6857 b
->type
!= bp_overlay_event
&&
6859 delete_breakpoint (b
);
6864 map_breakpoint_numbers (arg
, delete_breakpoint
);
6867 /* Reset a breakpoint given it's struct breakpoint * BINT.
6868 The value we return ends up being the return value from catch_errors.
6869 Unused in this case. */
6872 breakpoint_re_set_one (PTR bint
)
6874 /* get past catch_errs */
6875 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6878 struct symtabs_and_lines sals
;
6880 enum enable_state save_enable
;
6885 warning ("attempted to reset apparently deleted breakpoint #%d?",
6889 case bp_hardware_breakpoint
:
6891 case bp_catch_unload
:
6892 if (b
->addr_string
== NULL
)
6894 /* Anything without a string can't be re-set. */
6895 delete_breakpoint (b
);
6898 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6900 ``And a hack it is, although Apple's Darwin version of GDB
6901 contains an almost identical hack to implement a "future
6902 break" command. It seems to work in many real world cases,
6903 but it is easy to come up with a test case where the patch
6904 doesn't help at all.''
6906 ``It seems that the way GDB implements breakpoints - in -
6907 shared - libraries was designed for a.out shared library
6908 systems (SunOS 4) where shared libraries were loaded at a
6909 fixed address in memory. Since ELF shared libraries can (and
6910 will) be loaded at any address in memory, things break.
6911 Fixing this is not trivial. Therefore, I'm not sure whether
6912 we should add this hack to the branch only. I cannot
6913 guarantee that things will be fixed on the trunk in the near
6916 In case we have a problem, disable this breakpoint. We'll
6917 restore its status if we succeed. Don't disable a
6918 shlib_disabled breakpoint though. There's a fair chance we
6919 can't re-set it if the shared library it's in hasn't been
6921 save_enable
= b
->enable_state
;
6922 if (b
->enable_state
!= bp_shlib_disabled
)
6923 b
->enable_state
= bp_disabled
;
6925 set_language (b
->language
);
6926 input_radix
= b
->input_radix
;
6928 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6929 for (i
= 0; i
< sals
.nelts
; i
++)
6931 resolve_sal_pc (&sals
.sals
[i
]);
6933 /* Reparse conditions, they might contain references to the
6935 if (b
->cond_string
!= NULL
)
6940 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6943 /* We need to re-set the breakpoint if the address changes... */
6944 if (b
->address
!= sals
.sals
[i
].pc
6945 /* ...or new and old breakpoints both have source files, and
6946 the source file name or the line number changes... */
6947 || (b
->source_file
!= NULL
6948 && sals
.sals
[i
].symtab
!= NULL
6949 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6950 || b
->line_number
!= sals
.sals
[i
].line
)
6952 /* ...or we switch between having a source file and not having
6954 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6957 if (b
->source_file
!= NULL
)
6958 xfree (b
->source_file
);
6959 if (sals
.sals
[i
].symtab
== NULL
)
6960 b
->source_file
= NULL
;
6963 savestring (sals
.sals
[i
].symtab
->filename
,
6964 strlen (sals
.sals
[i
].symtab
->filename
));
6965 b
->line_number
= sals
.sals
[i
].line
;
6966 b
->address
= sals
.sals
[i
].pc
;
6968 /* Used to check for duplicates here, but that can
6969 cause trouble, as it doesn't check for disabled
6974 /* Might be better to do this just once per breakpoint_re_set,
6975 rather than once for every breakpoint. */
6976 breakpoints_changed ();
6978 b
->section
= sals
.sals
[i
].section
;
6979 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6982 /* Now that this is re-enabled, check_duplicates
6984 check_duplicates (b
);
6991 case bp_hardware_watchpoint
:
6992 case bp_read_watchpoint
:
6993 case bp_access_watchpoint
:
6994 innermost_block
= NULL
;
6995 /* The issue arises of what context to evaluate this in. The
6996 same one as when it was set, but what does that mean when
6997 symbols have been re-read? We could save the filename and
6998 functionname, but if the context is more local than that, the
6999 best we could do would be something like how many levels deep
7000 and which index at that particular level, but that's going to
7001 be less stable than filenames or function names. */
7003 /* So for now, just use a global context. */
7006 b
->exp
= parse_expression (b
->exp_string
);
7007 b
->exp_valid_block
= innermost_block
;
7008 mark
= value_mark ();
7010 value_free (b
->val
);
7011 b
->val
= evaluate_expression (b
->exp
);
7012 release_value (b
->val
);
7013 if (VALUE_LAZY (b
->val
))
7014 value_fetch_lazy (b
->val
);
7016 if (b
->cond_string
!= NULL
)
7021 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
7023 if (b
->enable_state
== bp_enabled
)
7025 value_free_to_mark (mark
);
7027 case bp_catch_catch
:
7028 case bp_catch_throw
:
7030 /* We needn't really do anything to reset these, since the mask
7031 that requests them is unaffected by e.g., new libraries being
7034 case bp_catch_vfork
:
7039 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
7041 /* Delete longjmp and overlay event breakpoints; they will be
7042 reset later by breakpoint_re_set. */
7044 case bp_longjmp_resume
:
7045 case bp_overlay_event
:
7046 delete_breakpoint (b
);
7049 /* This breakpoint is special, it's set up when the inferior
7050 starts and we really don't want to touch it. */
7051 case bp_shlib_event
:
7053 /* Like bp_shlib_event, this breakpoint type is special.
7054 Once it is set up, we do not want to touch it. */
7055 case bp_thread_event
:
7057 /* Keep temporary breakpoints, which can be encountered when we step
7058 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7059 Otherwise these should have been blown away via the cleanup chain
7060 or by breakpoint_init_inferior when we rerun the executable. */
7063 case bp_watchpoint_scope
:
7065 case bp_step_resume
:
7072 /* Re-set all breakpoints after symbols have been re-loaded. */
7074 breakpoint_re_set (void)
7076 struct breakpoint
*b
, *temp
;
7077 enum language save_language
;
7078 int save_input_radix
;
7079 static char message1
[] = "Error in re-setting breakpoint %d:\n";
7080 char message
[sizeof (message1
) + 30 /* slop */ ];
7082 save_language
= current_language
->la_language
;
7083 save_input_radix
= input_radix
;
7084 ALL_BREAKPOINTS_SAFE (b
, temp
)
7086 /* Format possible error msg */
7087 sprintf (message
, message1
, b
->number
);
7088 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7090 set_language (save_language
);
7091 input_radix
= save_input_radix
;
7093 if (GET_LONGJMP_TARGET_P ())
7095 create_longjmp_breakpoint ("longjmp");
7096 create_longjmp_breakpoint ("_longjmp");
7097 create_longjmp_breakpoint ("siglongjmp");
7098 create_longjmp_breakpoint ("_siglongjmp");
7099 create_longjmp_breakpoint (NULL
);
7102 create_overlay_event_breakpoint ("_ovly_debug_event");
7105 /* Reset the thread number of this breakpoint:
7107 - If the breakpoint is for all threads, leave it as-is.
7108 - Else, reset it to the current thread for inferior_ptid. */
7110 breakpoint_re_set_thread (struct breakpoint
*b
)
7112 if (b
->thread
!= -1)
7114 if (in_thread_list (inferior_ptid
))
7115 b
->thread
= pid_to_thread_id (inferior_ptid
);
7119 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7120 If from_tty is nonzero, it prints a message to that effect,
7121 which ends with a period (no newline). */
7124 set_ignore_count (int bptnum
, int count
, int from_tty
)
7126 register struct breakpoint
*b
;
7132 if (b
->number
== bptnum
)
7134 b
->ignore_count
= count
;
7138 printf_filtered ("Will stop next time breakpoint %d is reached.",
7140 else if (count
== 1)
7141 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7144 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7147 breakpoints_changed ();
7148 breakpoint_modify_event (b
->number
);
7152 error ("No breakpoint number %d.", bptnum
);
7155 /* Clear the ignore counts of all breakpoints. */
7157 breakpoint_clear_ignore_counts (void)
7159 struct breakpoint
*b
;
7162 b
->ignore_count
= 0;
7165 /* Command to set ignore-count of breakpoint N to COUNT. */
7168 ignore_command (char *args
, int from_tty
)
7174 error_no_arg ("a breakpoint number");
7176 num
= get_number (&p
);
7178 error ("bad breakpoint number: '%s'", args
);
7180 error ("Second argument (specified ignore-count) is missing.");
7182 set_ignore_count (num
,
7183 longest_to_int (value_as_long (parse_and_eval (p
))),
7186 printf_filtered ("\n");
7189 /* Call FUNCTION on each of the breakpoints
7190 whose numbers are given in ARGS. */
7193 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7195 register char *p
= args
;
7198 register struct breakpoint
*b
, *tmp
;
7202 error_no_arg ("one or more breakpoint numbers");
7209 num
= get_number_or_range (&p1
);
7212 warning ("bad breakpoint number at or near '%s'", p
);
7216 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7217 if (b
->number
== num
)
7219 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7222 if (related_breakpoint
)
7223 function (related_breakpoint
);
7227 printf_unfiltered ("No breakpoint number %d.\n", num
);
7233 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7234 If from_tty is nonzero, it prints a message to that effect,
7235 which ends with a period (no newline). */
7238 disable_breakpoint (struct breakpoint
*bpt
)
7240 /* Never disable a watchpoint scope breakpoint; we want to
7241 hit them when we leave scope so we can delete both the
7242 watchpoint and its scope breakpoint at that time. */
7243 if (bpt
->type
== bp_watchpoint_scope
)
7246 /* You can't disable permanent breakpoints. */
7247 if (bpt
->enable_state
== bp_permanent
)
7250 bpt
->enable_state
= bp_disabled
;
7252 check_duplicates (bpt
);
7254 if (modify_breakpoint_hook
)
7255 modify_breakpoint_hook (bpt
);
7256 breakpoint_modify_event (bpt
->number
);
7261 disable_command (char *args
, int from_tty
)
7263 register struct breakpoint
*bpt
;
7265 ALL_BREAKPOINTS (bpt
)
7269 warning ("attempted to disable apparently deleted breakpoint #%d?",
7274 case bp_catch_unload
:
7276 case bp_catch_vfork
:
7278 case bp_catch_catch
:
7279 case bp_catch_throw
:
7280 case bp_hardware_breakpoint
:
7282 case bp_hardware_watchpoint
:
7283 case bp_read_watchpoint
:
7284 case bp_access_watchpoint
:
7285 disable_breakpoint (bpt
);
7290 map_breakpoint_numbers (args
, disable_breakpoint
);
7294 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7296 struct frame_info
*save_selected_frame
= NULL
;
7297 int save_selected_frame_level
= -1;
7298 int target_resources_ok
, other_type_used
;
7301 if (bpt
->type
== bp_hardware_breakpoint
)
7304 i
= hw_breakpoint_used_count ();
7305 target_resources_ok
=
7306 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7308 if (target_resources_ok
== 0)
7309 error ("No hardware breakpoint support in the target.");
7310 else if (target_resources_ok
< 0)
7311 error ("Hardware breakpoints used exceeds limit.");
7314 if (bpt
->enable_state
!= bp_permanent
)
7315 bpt
->enable_state
= bp_enabled
;
7316 bpt
->disposition
= disposition
;
7317 check_duplicates (bpt
);
7318 breakpoints_changed ();
7320 if (bpt
->type
== bp_watchpoint
||
7321 bpt
->type
== bp_hardware_watchpoint
||
7322 bpt
->type
== bp_read_watchpoint
||
7323 bpt
->type
== bp_access_watchpoint
)
7325 if (bpt
->exp_valid_block
!= NULL
)
7327 struct frame_info
*fr
=
7328 fr
= frame_find_by_id (bpt
->watchpoint_frame
);
7332 Cannot enable watchpoint %d because the block in which its expression\n\
7333 is valid is not currently in scope.\n", bpt
->number
);
7334 bpt
->enable_state
= bp_disabled
;
7338 save_selected_frame
= selected_frame
;
7339 save_selected_frame_level
= frame_relative_level (selected_frame
);
7343 value_free (bpt
->val
);
7344 mark
= value_mark ();
7345 bpt
->val
= evaluate_expression (bpt
->exp
);
7346 release_value (bpt
->val
);
7347 if (VALUE_LAZY (bpt
->val
))
7348 value_fetch_lazy (bpt
->val
);
7350 if (bpt
->type
== bp_hardware_watchpoint
||
7351 bpt
->type
== bp_read_watchpoint
||
7352 bpt
->type
== bp_access_watchpoint
)
7354 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7355 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7357 /* Hack around 'unused var' error for some targets here */
7359 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7360 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7361 /* we can consider of type is bp_hardware_watchpoint, convert to
7362 bp_watchpoint in the following condition */
7363 if (target_resources_ok
< 0)
7366 Cannot enable watchpoint %d because target watch resources\n\
7367 have been allocated for other watchpoints.\n", bpt
->number
);
7368 bpt
->enable_state
= bp_disabled
;
7369 value_free_to_mark (mark
);
7374 if (save_selected_frame_level
>= 0)
7375 select_frame (save_selected_frame
);
7376 value_free_to_mark (mark
);
7378 if (modify_breakpoint_hook
)
7379 modify_breakpoint_hook (bpt
);
7380 breakpoint_modify_event (bpt
->number
);
7384 enable_breakpoint (struct breakpoint
*bpt
)
7386 do_enable_breakpoint (bpt
, bpt
->disposition
);
7389 /* The enable command enables the specified breakpoints (or all defined
7390 breakpoints) so they once again become (or continue to be) effective
7391 in stopping the inferior. */
7395 enable_command (char *args
, int from_tty
)
7397 register struct breakpoint
*bpt
;
7399 ALL_BREAKPOINTS (bpt
)
7403 warning ("attempted to enable apparently deleted breakpoint #%d?",
7408 case bp_catch_unload
:
7410 case bp_catch_vfork
:
7412 case bp_catch_catch
:
7413 case bp_catch_throw
:
7414 case bp_hardware_breakpoint
:
7416 case bp_hardware_watchpoint
:
7417 case bp_read_watchpoint
:
7418 case bp_access_watchpoint
:
7419 enable_breakpoint (bpt
);
7424 map_breakpoint_numbers (args
, enable_breakpoint
);
7428 enable_once_breakpoint (struct breakpoint
*bpt
)
7430 do_enable_breakpoint (bpt
, disp_disable
);
7435 enable_once_command (char *args
, int from_tty
)
7437 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7441 enable_delete_breakpoint (struct breakpoint
*bpt
)
7443 do_enable_breakpoint (bpt
, disp_del
);
7448 enable_delete_command (char *args
, int from_tty
)
7450 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7453 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7455 struct symtabs_and_lines
7456 decode_line_spec_1 (char *string
, int funfirstline
)
7458 struct symtabs_and_lines sals
;
7460 error ("Empty line specification.");
7461 if (default_breakpoint_valid
)
7462 sals
= decode_line_1 (&string
, funfirstline
,
7463 default_breakpoint_symtab
,
7464 default_breakpoint_line
,
7467 sals
= decode_line_1 (&string
, funfirstline
,
7468 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7470 error ("Junk at end of line specification: %s", string
);
7475 _initialize_breakpoint (void)
7477 struct cmd_list_element
*c
;
7479 breakpoint_chain
= 0;
7480 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7481 before a breakpoint is set. */
7482 breakpoint_count
= 0;
7484 add_com ("ignore", class_breakpoint
, ignore_command
,
7485 "Set ignore-count of breakpoint number N to COUNT.\n\
7486 Usage is `ignore N COUNT'.");
7488 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7490 add_com ("commands", class_breakpoint
, commands_command
,
7491 "Set commands to be executed when a breakpoint is hit.\n\
7492 Give breakpoint number as argument after \"commands\".\n\
7493 With no argument, the targeted breakpoint is the last one set.\n\
7494 The commands themselves follow starting on the next line.\n\
7495 Type a line containing \"end\" to indicate the end of them.\n\
7496 Give \"silent\" as the first line to make the breakpoint silent;\n\
7497 then no output is printed when it is hit, except what the commands print.");
7499 add_com ("condition", class_breakpoint
, condition_command
,
7500 "Specify breakpoint number N to break only if COND is true.\n\
7501 Usage is `condition N COND', where N is an integer and COND is an\n\
7502 expression to be evaluated whenever breakpoint N is reached.");
7504 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7505 "Set a temporary breakpoint. Args like \"break\" command.\n\
7506 Like \"break\" except the breakpoint is only temporary,\n\
7507 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7508 by using \"enable delete\" on the breakpoint number.");
7509 set_cmd_completer (c
, location_completer
);
7511 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7512 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7513 Like \"break\" except the breakpoint requires hardware support,\n\
7514 some target hardware may not have this support.");
7515 set_cmd_completer (c
, location_completer
);
7517 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7518 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7519 Like \"hbreak\" except the breakpoint is only temporary,\n\
7520 so it will be deleted when hit.");
7521 set_cmd_completer (c
, location_completer
);
7523 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7524 "Enable some breakpoints.\n\
7525 Give breakpoint numbers (separated by spaces) as arguments.\n\
7526 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7527 This is used to cancel the effect of the \"disable\" command.\n\
7528 With a subcommand you can enable temporarily.",
7529 &enablelist
, "enable ", 1, &cmdlist
);
7531 add_com ("ab", class_breakpoint
, enable_command
,
7532 "Enable some breakpoints.\n\
7533 Give breakpoint numbers (separated by spaces) as arguments.\n\
7534 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7535 This is used to cancel the effect of the \"disable\" command.\n\
7536 With a subcommand you can enable temporarily.");
7538 add_com_alias ("en", "enable", class_breakpoint
, 1);
7540 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7541 "Enable some breakpoints.\n\
7542 Give breakpoint numbers (separated by spaces) as arguments.\n\
7543 This is used to cancel the effect of the \"disable\" command.\n\
7544 May be abbreviated to simply \"enable\".\n",
7545 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7547 add_cmd ("once", no_class
, enable_once_command
,
7548 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7549 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7552 add_cmd ("delete", no_class
, enable_delete_command
,
7553 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7554 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7557 add_cmd ("delete", no_class
, enable_delete_command
,
7558 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7559 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7562 add_cmd ("once", no_class
, enable_once_command
,
7563 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7564 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7567 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7568 "Disable some breakpoints.\n\
7569 Arguments are breakpoint numbers with spaces in between.\n\
7570 To disable all breakpoints, give no argument.\n\
7571 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7572 &disablelist
, "disable ", 1, &cmdlist
);
7573 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7574 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7576 add_com ("sb", class_breakpoint
, disable_command
,
7577 "Disable some breakpoints.\n\
7578 Arguments are breakpoint numbers with spaces in between.\n\
7579 To disable all breakpoints, give no argument.\n\
7580 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7582 add_cmd ("breakpoints", class_alias
, disable_command
,
7583 "Disable some breakpoints.\n\
7584 Arguments are breakpoint numbers with spaces in between.\n\
7585 To disable all breakpoints, give no argument.\n\
7586 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7587 This command may be abbreviated \"disable\".",
7590 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7591 "Delete some breakpoints or auto-display expressions.\n\
7592 Arguments are breakpoint numbers with spaces in between.\n\
7593 To delete all breakpoints, give no argument.\n\
7595 Also a prefix command for deletion of other GDB objects.\n\
7596 The \"unset\" command is also an alias for \"delete\".",
7597 &deletelist
, "delete ", 1, &cmdlist
);
7598 add_com_alias ("d", "delete", class_breakpoint
, 1);
7600 add_com ("db", class_breakpoint
, delete_command
,
7601 "Delete some breakpoints.\n\
7602 Arguments are breakpoint numbers with spaces in between.\n\
7603 To delete all breakpoints, give no argument.\n");
7605 add_cmd ("breakpoints", class_alias
, delete_command
,
7606 "Delete some breakpoints or auto-display expressions.\n\
7607 Arguments are breakpoint numbers with spaces in between.\n\
7608 To delete all breakpoints, give no argument.\n\
7609 This command may be abbreviated \"delete\".",
7612 add_com ("clear", class_breakpoint
, clear_command
,
7613 concat ("Clear breakpoint at specified line or function.\n\
7614 Argument may be line number, function name, or \"*\" and an address.\n\
7615 If line number is specified, all breakpoints in that line are cleared.\n\
7616 If function is specified, breakpoints at beginning of function are cleared.\n\
7617 If an address is specified, breakpoints at that address are cleared.\n\n",
7618 "With no argument, clears all breakpoints in the line that the selected frame\n\
7621 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7623 c
= add_com ("break", class_breakpoint
, break_command
,
7624 concat ("Set breakpoint at specified line or function.\n\
7625 Argument may be line number, function name, or \"*\" and an address.\n\
7626 If line number is specified, break at start of code for that line.\n\
7627 If function is specified, break at start of code for that function.\n\
7628 If an address is specified, break at that exact address.\n",
7629 "With no arg, uses current execution address of selected stack frame.\n\
7630 This is useful for breaking on return to a stack frame.\n\
7632 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7634 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7635 set_cmd_completer (c
, location_completer
);
7637 add_com_alias ("b", "break", class_run
, 1);
7638 add_com_alias ("br", "break", class_run
, 1);
7639 add_com_alias ("bre", "break", class_run
, 1);
7640 add_com_alias ("brea", "break", class_run
, 1);
7644 add_com_alias ("ba", "break", class_breakpoint
, 1);
7645 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7650 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7651 "Break in function/address or break at a line in the current file.",
7652 &stoplist
, "stop ", 1, &cmdlist
);
7653 add_cmd ("in", class_breakpoint
, stopin_command
,
7654 "Break in function or address.\n", &stoplist
);
7655 add_cmd ("at", class_breakpoint
, stopat_command
,
7656 "Break at a line in the current file.\n", &stoplist
);
7657 add_com ("status", class_info
, breakpoints_info
,
7658 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7659 The \"Type\" column indicates one of:\n\
7660 \tbreakpoint - normal breakpoint\n\
7661 \twatchpoint - watchpoint\n\
7662 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7663 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7664 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7665 address and file/line number respectively.\n\n",
7666 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7667 are set to the address of the last breakpoint listed.\n\n\
7668 Convenience variable \"$bpnum\" contains the number of the last\n\
7669 breakpoint set.", NULL
));
7672 add_info ("breakpoints", breakpoints_info
,
7673 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7674 The \"Type\" column indicates one of:\n\
7675 \tbreakpoint - normal breakpoint\n\
7676 \twatchpoint - watchpoint\n\
7677 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7678 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7679 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7680 address and file/line number respectively.\n\n",
7681 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7682 are set to the address of the last breakpoint listed.\n\n\
7683 Convenience variable \"$bpnum\" contains the number of the last\n\
7684 breakpoint set.", NULL
));
7687 add_com ("lb", class_breakpoint
, breakpoints_info
,
7688 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7689 The \"Type\" column indicates one of:\n\
7690 \tbreakpoint - normal breakpoint\n\
7691 \twatchpoint - watchpoint\n\
7692 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7693 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7694 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7695 address and file/line number respectively.\n\n",
7696 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7697 are set to the address of the last breakpoint listed.\n\n\
7698 Convenience variable \"$bpnum\" contains the number of the last\n\
7699 breakpoint set.", NULL
));
7701 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7702 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7703 The \"Type\" column indicates one of:\n\
7704 \tbreakpoint - normal breakpoint\n\
7705 \twatchpoint - watchpoint\n\
7706 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7707 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7708 \tuntil - internal breakpoint used by the \"until\" command\n\
7709 \tfinish - internal breakpoint used by the \"finish\" command\n",
7710 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7711 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7712 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7713 address and file/line number respectively.\n\n",
7714 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7715 are set to the address of the last breakpoint listed.\n\n\
7716 Convenience variable \"$bpnum\" contains the number of the last\n\
7717 breakpoint set.", NULL
),
7718 &maintenanceinfolist
);
7720 add_com ("catch", class_breakpoint
, catch_command
,
7721 "Set catchpoints to catch events.\n\
7722 Raised signals may be caught:\n\
7723 \tcatch signal - all signals\n\
7724 \tcatch signal <signame> - a particular signal\n\
7725 Raised exceptions may be caught:\n\
7726 \tcatch throw - all exceptions, when thrown\n\
7727 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7728 \tcatch catch - all exceptions, when caught\n\
7729 \tcatch catch <exceptname> - a particular exception, when caught\n\
7730 Thread or process events may be caught:\n\
7731 \tcatch thread_start - any threads, just after creation\n\
7732 \tcatch thread_exit - any threads, just before expiration\n\
7733 \tcatch thread_join - any threads, just after joins\n\
7734 Process events may be caught:\n\
7735 \tcatch start - any processes, just after creation\n\
7736 \tcatch exit - any processes, just before expiration\n\
7737 \tcatch fork - calls to fork()\n\
7738 \tcatch vfork - calls to vfork()\n\
7739 \tcatch exec - calls to exec()\n\
7740 Dynamically-linked library events may be caught:\n\
7741 \tcatch load - loads of any library\n\
7742 \tcatch load <libname> - loads of a particular library\n\
7743 \tcatch unload - unloads of any library\n\
7744 \tcatch unload <libname> - unloads of a particular library\n\
7745 The act of your program's execution stopping may also be caught:\n\
7747 C++ exceptions may be caught:\n\
7748 \tcatch throw - all exceptions, when thrown\n\
7749 \tcatch catch - all exceptions, when caught\n\
7751 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7752 after a fork or vfork is caught.\n\n\
7753 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7755 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7756 "Set temporary catchpoints to catch events.\n\
7757 Args like \"catch\" command.\n\
7758 Like \"catch\" except the catchpoint is only temporary,\n\
7759 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7760 by using \"enable delete\" on the catchpoint number.");
7762 c
= add_com ("watch", class_breakpoint
, watch_command
,
7763 "Set a watchpoint for an expression.\n\
7764 A watchpoint stops execution of your program whenever the value of\n\
7765 an expression changes.");
7766 set_cmd_completer (c
, location_completer
);
7768 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7769 "Set a read watchpoint for an expression.\n\
7770 A watchpoint stops execution of your program whenever the value of\n\
7771 an expression is read.");
7772 set_cmd_completer (c
, location_completer
);
7774 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7775 "Set a watchpoint for an expression.\n\
7776 A watchpoint stops execution of your program whenever the value of\n\
7777 an expression is either read or written.");
7778 set_cmd_completer (c
, location_completer
);
7780 add_info ("watchpoints", breakpoints_info
,
7781 "Synonym for ``info breakpoints''.");
7784 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7785 (char *) &can_use_hw_watchpoints
,
7786 "Set debugger's willingness to use watchpoint hardware.\n\
7787 If zero, gdb will not use hardware for new watchpoints, even if\n\
7788 such is available. (However, any hardware watchpoints that were\n\
7789 created before setting this to nonzero, will continue to use watchpoint\n\
7792 add_show_from_set (c
, &showlist
);
7794 can_use_hw_watchpoints
= 1;