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 ();
559 error ("No breakpoint number %d.", bnum
);
564 commands_command (char *arg
, int from_tty
)
566 register struct breakpoint
*b
;
569 struct command_line
*l
;
571 /* If we allowed this, we would have problems with when to
572 free the storage, if we change the commands currently
575 if (executing_breakpoint_commands
)
576 error ("Can't use the \"commands\" command among a breakpoint's commands.");
579 bnum
= get_number (&p
);
582 error ("Unexpected extra arguments following breakpoint number.");
585 if (b
->number
== bnum
)
589 "Type commands for when breakpoint %d is hit, one per line.",
591 l
= read_command_lines (tmpbuf
, from_tty
);
592 free_command_lines (&b
->commands
);
594 breakpoints_changed ();
597 error ("No breakpoint number %d.", bnum
);
600 /* Like target_read_memory() but if breakpoints are inserted, return
601 the shadow contents instead of the breakpoints themselves.
603 Read "memory data" from whatever target or inferior we have.
604 Returns zero if successful, errno value if not. EIO is used
605 for address out of bounds. If breakpoints are inserted, returns
606 shadow contents, not the breakpoints themselves. From breakpoint.c. */
609 read_memory_nobpt (CORE_ADDR memaddr
, char *myaddr
, unsigned len
)
612 struct breakpoint
*b
;
613 CORE_ADDR bp_addr
= 0;
616 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
617 /* No breakpoints on this machine. */
618 return target_read_memory (memaddr
, myaddr
, len
);
622 if (b
->type
== bp_none
)
623 warning ("reading through apparently deleted breakpoint #%d?",
626 /* memory breakpoint? */
627 if (b
->type
== bp_watchpoint
628 || b
->type
== bp_hardware_watchpoint
629 || b
->type
== bp_read_watchpoint
630 || b
->type
== bp_access_watchpoint
)
635 /* Addresses and length of the part of the breakpoint that
637 /* XXXX The m68k, sh and h8300 have different local and remote
638 breakpoint values. BREAKPOINT_FROM_PC still manages to
639 correctly determine the breakpoints memory address and size
640 for these targets. */
641 bp_addr
= b
->address
;
643 if (BREAKPOINT_FROM_PC (&bp_addr
, &bp_size
) == NULL
)
648 if (bp_addr
+ bp_size
<= memaddr
)
649 /* The breakpoint is entirely before the chunk of memory we
652 if (bp_addr
>= memaddr
+ len
)
653 /* The breakpoint is entirely after the chunk of memory we are
656 /* Copy the breakpoint from the shadow contents, and recurse for
657 the things before and after. */
659 /* Offset within shadow_contents. */
662 if (bp_addr
< memaddr
)
664 /* Only copy the second part of the breakpoint. */
665 bp_size
-= memaddr
- bp_addr
;
666 bptoffset
= memaddr
- bp_addr
;
670 if (bp_addr
+ bp_size
> memaddr
+ len
)
672 /* Only copy the first part of the breakpoint. */
673 bp_size
-= (bp_addr
+ bp_size
) - (memaddr
+ len
);
676 memcpy (myaddr
+ bp_addr
- memaddr
,
677 b
->shadow_contents
+ bptoffset
, bp_size
);
679 if (bp_addr
> memaddr
)
681 /* Copy the section of memory before the breakpoint. */
682 status
= read_memory_nobpt (memaddr
, myaddr
, bp_addr
- memaddr
);
687 if (bp_addr
+ bp_size
< memaddr
+ len
)
689 /* Copy the section of memory after the breakpoint. */
690 status
= read_memory_nobpt (bp_addr
+ bp_size
,
691 myaddr
+ bp_addr
+ bp_size
- memaddr
,
692 memaddr
+ len
- (bp_addr
+ bp_size
));
699 /* Nothing overlaps. Just call read_memory_noerr. */
700 return target_read_memory (memaddr
, myaddr
, len
);
704 /* insert_breakpoints is used when starting or continuing the program.
705 remove_breakpoints is used when the program stops.
706 Both return zero if successful,
707 or an `errno' value if could not write the inferior. */
710 insert_breakpoints (void)
712 register struct breakpoint
*b
, *temp
;
713 int return_val
= 0; /* return success code. */
715 int disabled_breaks
= 0;
717 static char message1
[] = "Error inserting catchpoint %d:\n";
718 static char message
[sizeof (message1
) + 30];
721 ALL_BREAKPOINTS_SAFE (b
, temp
)
723 if (b
->enable_state
== bp_permanent
)
724 /* Permanent breakpoints cannot be inserted or removed. */
726 else if (b
->type
!= bp_watchpoint
727 && b
->type
!= bp_hardware_watchpoint
728 && b
->type
!= bp_read_watchpoint
729 && b
->type
!= bp_access_watchpoint
730 && b
->type
!= bp_catch_fork
731 && b
->type
!= bp_catch_vfork
732 && b
->type
!= bp_catch_exec
733 && b
->type
!= bp_catch_throw
734 && b
->type
!= bp_catch_catch
735 && b
->enable_state
!= bp_disabled
736 && b
->enable_state
!= bp_shlib_disabled
737 && b
->enable_state
!= bp_call_disabled
741 /* "Normal" instruction breakpoint: either the standard
742 trap-instruction bp (bp_breakpoint), or a
743 bp_hardware_breakpoint. */
745 /* First check to see if we have to handle an overlay. */
746 if (overlay_debugging
== ovly_off
747 || b
->section
== NULL
748 || !(section_is_overlay (b
->section
)))
750 /* No overlay handling: just set the breakpoint. */
752 if (b
->type
== bp_hardware_breakpoint
)
753 val
= target_insert_hw_breakpoint (b
->address
,
756 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
760 /* This breakpoint is in an overlay section.
761 Shall we set a breakpoint at the LMA? */
762 if (!overlay_events_enabled
)
764 /* Yes -- overlay event support is not active,
765 so we must try to set a breakpoint at the LMA.
766 This will not work for a hardware breakpoint. */
767 if (b
->type
== bp_hardware_breakpoint
)
768 warning ("hardware breakpoint %d not supported in overlay!\n",
772 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
774 /* Set a software (trap) breakpoint at the LMA. */
775 val
= target_insert_breakpoint (addr
, b
->shadow_contents
);
777 warning ("overlay breakpoint %d failed: in ROM?",
781 /* Shall we set a breakpoint at the VMA? */
782 if (section_is_mapped (b
->section
))
784 /* Yes. This overlay section is mapped into memory. */
785 if (b
->type
== bp_hardware_breakpoint
)
786 val
= target_insert_hw_breakpoint (b
->address
,
789 val
= target_insert_breakpoint (b
->address
,
794 /* No. This breakpoint will not be inserted.
795 No error, but do not mark the bp as 'inserted'. */
802 /* Can't set the breakpoint. */
803 #if defined (DISABLE_UNSETTABLE_BREAK)
804 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
806 /* See also: disable_breakpoints_in_shlibs. */
808 b
->enable_state
= bp_shlib_disabled
;
809 if (!disabled_breaks
)
811 target_terminal_ours_for_output ();
812 warning ("Cannot insert breakpoint %d:", b
->number
);
813 warning ("Temporarily disabling shared library breakpoints:");
816 warning ("breakpoint #%d ", b
->number
);
821 target_terminal_ours_for_output ();
822 warning ("Cannot insert breakpoint %d:", b
->number
);
823 #ifdef ONE_PROCESS_WRITETEXT
824 warning ("The same program may be running in another process.");
826 memory_error (val
, b
->address
); /* which bombs us out */
833 return_val
= val
; /* remember failure */
835 else if (ep_is_exception_catchpoint (b
)
836 && b
->enable_state
!= bp_disabled
837 && b
->enable_state
!= bp_shlib_disabled
838 && b
->enable_state
!= bp_call_disabled
843 /* If we get here, we must have a callback mechanism for exception
844 events -- with g++ style embedded label support, we insert
845 ordinary breakpoints and not catchpoints. */
846 /* Format possible error message */
847 sprintf (message
, message1
, b
->number
);
849 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
852 /* Couldn't set breakpoint for some reason */
853 target_terminal_ours_for_output ();
854 warning ("Cannot insert catchpoint %d; disabling it.",
856 b
->enable_state
= bp_disabled
;
860 /* Bp set, now make sure callbacks are enabled */
862 args_for_catchpoint_enable args
;
863 args
.kind
= b
->type
== bp_catch_catch
?
864 EX_EVENT_CATCH
: EX_EVENT_THROW
;
866 val
= catch_errors (cover_target_enable_exception_callback
,
868 message
, RETURN_MASK_ALL
);
869 if (val
!= 0 && val
!= -1)
873 /* Check if something went wrong; val == 0 can be ignored */
876 /* something went wrong */
877 target_terminal_ours_for_output ();
878 warning ("Cannot insert catchpoint %d; disabling it.",
880 b
->enable_state
= bp_disabled
;
885 return_val
= val
; /* remember failure */
888 else if ((b
->type
== bp_hardware_watchpoint
||
889 b
->type
== bp_read_watchpoint
||
890 b
->type
== bp_access_watchpoint
)
891 && b
->enable_state
== bp_enabled
892 && b
->disposition
!= disp_del_at_next_stop
896 struct frame_info
*saved_frame
;
897 int saved_level
, within_current_scope
;
898 struct value
*mark
= value_mark ();
901 /* Save the current frame and level so we can restore it after
902 evaluating the watchpoint expression on its own frame. */
903 saved_frame
= selected_frame
;
904 saved_level
= selected_frame_level
;
906 /* Determine if the watchpoint is within scope. */
907 if (b
->exp_valid_block
== NULL
)
908 within_current_scope
= 1;
911 struct frame_info
*fi
;
913 /* There might be no current frame at this moment if we are
914 resuming from a step over a breakpoint.
915 Set up current frame before trying to find the watchpoint
917 get_current_frame ();
918 fi
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
919 within_current_scope
= (fi
!= NULL
);
920 if (within_current_scope
)
921 select_frame (fi
, -1);
924 if (within_current_scope
)
926 /* Evaluate the expression and cut the chain of values
927 produced off from the value chain.
929 Make sure the value returned isn't lazy; we use
930 laziness to determine what memory GDB actually needed
931 in order to compute the value of the expression. */
932 v
= evaluate_expression (b
->exp
);
934 value_release_to_mark (mark
);
939 /* Look at each value on the value chain. */
940 for (; v
; v
= v
->next
)
942 /* If it's a memory location, and GDB actually needed
943 its contents to evaluate the expression, then we
945 if (VALUE_LVAL (v
) == lval_memory
948 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
950 /* We only watch structs and arrays if user asked
951 for it explicitly, never if they just happen to
952 appear in the middle of some value chain. */
953 if (v
== b
->val_chain
954 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
955 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
960 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
961 len
= TYPE_LENGTH (VALUE_TYPE (v
));
963 if (b
->type
== bp_read_watchpoint
)
965 else if (b
->type
== bp_access_watchpoint
)
968 val
= target_insert_watchpoint (addr
, len
, type
);
971 /* Don't exit the loop, try to insert
972 every value on the value chain. That's
973 because we will be removing all the
974 watches below, and removing a
975 watchpoint we didn't insert could have
983 /* Failure to insert a watchpoint on any memory value in the
984 value chain brings us here. */
987 remove_breakpoint (b
, mark_uninserted
);
988 warning ("Could not insert hardware watchpoint %d.",
995 printf_filtered ("Hardware watchpoint %d deleted ", b
->number
);
996 printf_filtered ("because the program has left the block \n");
997 printf_filtered ("in which its expression is valid.\n");
998 if (b
->related_breakpoint
)
999 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
1000 b
->disposition
= disp_del_at_next_stop
;
1003 /* Restore the frame and level. */
1004 if ((saved_frame
!= selected_frame
) ||
1005 (saved_level
!= selected_frame_level
))
1006 select_frame (saved_frame
, saved_level
);
1009 return_val
= val
; /* remember failure */
1011 else if ((b
->type
== bp_catch_fork
1012 || b
->type
== bp_catch_vfork
1013 || b
->type
== bp_catch_exec
)
1014 && b
->enable_state
== bp_enabled
1022 val
= target_insert_fork_catchpoint (PIDGET (inferior_ptid
));
1024 case bp_catch_vfork
:
1025 val
= target_insert_vfork_catchpoint (PIDGET (inferior_ptid
));
1028 val
= target_insert_exec_catchpoint (PIDGET (inferior_ptid
));
1031 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1036 target_terminal_ours_for_output ();
1037 warning ("Cannot insert catchpoint %d.", b
->number
);
1043 return_val
= val
; /* remember failure */
1052 remove_breakpoints (void)
1054 register struct breakpoint
*b
;
1061 val
= remove_breakpoint (b
, mark_uninserted
);
1070 remove_hw_watchpoints (void)
1072 register struct breakpoint
*b
;
1078 && (b
->type
== bp_hardware_watchpoint
1079 || b
->type
== bp_read_watchpoint
1080 || b
->type
== bp_access_watchpoint
))
1082 val
= remove_breakpoint (b
, mark_uninserted
);
1091 reattach_breakpoints (int pid
)
1093 register struct breakpoint
*b
;
1095 struct cleanup
*old_chain
= save_inferior_ptid ();
1097 /* Set inferior_ptid; remove_breakpoint uses this global. */
1098 inferior_ptid
= pid_to_ptid (pid
);
1103 remove_breakpoint (b
, mark_inserted
);
1104 if (b
->type
== bp_hardware_breakpoint
)
1105 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
1107 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
1110 do_cleanups (old_chain
);
1115 do_cleanups (old_chain
);
1120 update_breakpoints_after_exec (void)
1122 struct breakpoint
*b
;
1123 struct breakpoint
*temp
;
1125 /* Doing this first prevents the badness of having delete_breakpoint()
1126 write a breakpoint's current "shadow contents" to lift the bp. That
1127 shadow is NOT valid after an exec()! */
1128 mark_breakpoints_out ();
1130 ALL_BREAKPOINTS_SAFE (b
, temp
)
1132 /* Solib breakpoints must be explicitly reset after an exec(). */
1133 if (b
->type
== bp_shlib_event
)
1135 delete_breakpoint (b
);
1139 /* Thread event breakpoints must be set anew after an exec(),
1140 as must overlay event breakpoints. */
1141 if (b
->type
== bp_thread_event
|| b
->type
== bp_overlay_event
)
1143 delete_breakpoint (b
);
1147 /* Step-resume breakpoints are meaningless after an exec(). */
1148 if (b
->type
== bp_step_resume
)
1150 delete_breakpoint (b
);
1154 /* Ditto the sigtramp handler breakpoints. */
1155 if (b
->type
== bp_through_sigtramp
)
1157 delete_breakpoint (b
);
1161 /* Ditto the exception-handling catchpoints. */
1162 if ((b
->type
== bp_catch_catch
) || (b
->type
== bp_catch_throw
))
1164 delete_breakpoint (b
);
1168 /* Don't delete an exec catchpoint, because else the inferior
1169 won't stop when it ought!
1171 Similarly, we probably ought to keep vfork catchpoints, 'cause
1172 on this target, we may not be able to stop when the vfork is
1173 seen, but only when the subsequent exec is seen. (And because
1174 deleting fork catchpoints here but not vfork catchpoints will
1175 seem mysterious to users, keep those too.)
1177 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1178 target address field, if any, is sufficient to have it be reset
1179 automagically. Certainly on HP-UX that's true.
1181 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1182 valid code address on some platforms (like the mn10200 and
1183 mn10300 simulators). We shouldn't assign any special
1184 interpretation to a breakpoint with a zero address. And in
1185 fact, GDB doesn't --- I can't see what that comment above is
1186 talking about. As far as I can tell, setting the address of a
1187 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1188 is meaningless, since those are implemented with HP-UX kernel
1189 hackery, not by storing breakpoint instructions somewhere. */
1190 if ((b
->type
== bp_catch_exec
) ||
1191 (b
->type
== bp_catch_vfork
) ||
1192 (b
->type
== bp_catch_fork
))
1194 b
->address
= (CORE_ADDR
) NULL
;
1198 /* bp_finish is a special case. The only way we ought to be able
1199 to see one of these when an exec() has happened, is if the user
1200 caught a vfork, and then said "finish". Ordinarily a finish just
1201 carries them to the call-site of the current callee, by setting
1202 a temporary bp there and resuming. But in this case, the finish
1203 will carry them entirely through the vfork & exec.
1205 We don't want to allow a bp_finish to remain inserted now. But
1206 we can't safely delete it, 'cause finish_command has a handle to
1207 the bp on a bpstat, and will later want to delete it. There's a
1208 chance (and I've seen it happen) that if we delete the bp_finish
1209 here, that its storage will get reused by the time finish_command
1210 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1211 We really must allow finish_command to delete a bp_finish.
1213 In the absense of a general solution for the "how do we know
1214 it's safe to delete something others may have handles to?"
1215 problem, what we'll do here is just uninsert the bp_finish, and
1216 let finish_command delete it.
1218 (We know the bp_finish is "doomed" in the sense that it's
1219 momentary, and will be deleted as soon as finish_command sees
1220 the inferior stopped. So it doesn't matter that the bp's
1221 address is probably bogus in the new a.out, unlike e.g., the
1222 solib breakpoints.) */
1224 if (b
->type
== bp_finish
)
1229 /* Without a symbolic address, we have little hope of the
1230 pre-exec() address meaning the same thing in the post-exec()
1232 if (b
->addr_string
== NULL
)
1234 delete_breakpoint (b
);
1238 /* If this breakpoint has survived the above battery of checks, then
1239 it must have a symbolic address. Be sure that it gets reevaluated
1240 to a target address, rather than reusing the old evaluation.
1242 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1243 for bp_catch_exec and friends, I'm pretty sure this is entirely
1244 unnecessary. A call to breakpoint_re_set_one always recomputes
1245 the breakpoint's address from scratch, or deletes it if it can't.
1246 So I think this assignment could be deleted without effect. */
1247 b
->address
= (CORE_ADDR
) NULL
;
1249 /* FIXME what about longjmp breakpoints? Re-create them here? */
1250 create_overlay_event_breakpoint ("_ovly_debug_event");
1254 detach_breakpoints (int pid
)
1256 register struct breakpoint
*b
;
1258 struct cleanup
*old_chain
= save_inferior_ptid ();
1260 if (pid
== PIDGET (inferior_ptid
))
1261 error ("Cannot detach breakpoints of inferior_ptid");
1263 /* Set inferior_ptid; remove_breakpoint uses this global. */
1264 inferior_ptid
= pid_to_ptid (pid
);
1269 val
= remove_breakpoint (b
, mark_inserted
);
1272 do_cleanups (old_chain
);
1277 do_cleanups (old_chain
);
1282 remove_breakpoint (struct breakpoint
*b
, insertion_state_t is
)
1286 if (b
->enable_state
== bp_permanent
)
1287 /* Permanent breakpoints cannot be inserted or removed. */
1290 if (b
->type
== bp_none
)
1291 warning ("attempted to remove apparently deleted breakpoint #%d?",
1294 if (b
->type
!= bp_watchpoint
1295 && b
->type
!= bp_hardware_watchpoint
1296 && b
->type
!= bp_read_watchpoint
1297 && b
->type
!= bp_access_watchpoint
1298 && b
->type
!= bp_catch_fork
1299 && b
->type
!= bp_catch_vfork
1300 && b
->type
!= bp_catch_exec
1301 && b
->type
!= bp_catch_catch
1302 && b
->type
!= bp_catch_throw
)
1304 /* "Normal" instruction breakpoint: either the standard
1305 trap-instruction bp (bp_breakpoint), or a
1306 bp_hardware_breakpoint. */
1308 /* First check to see if we have to handle an overlay. */
1309 if (overlay_debugging
== ovly_off
1310 || b
->section
== NULL
1311 || !(section_is_overlay (b
->section
)))
1313 /* No overlay handling: just remove the breakpoint. */
1315 if (b
->type
== bp_hardware_breakpoint
)
1316 val
= target_remove_hw_breakpoint (b
->address
,
1317 b
->shadow_contents
);
1319 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1323 /* This breakpoint is in an overlay section.
1324 Did we set a breakpoint at the LMA? */
1325 if (!overlay_events_enabled
)
1327 /* Yes -- overlay event support is not active, so we
1328 should have set a breakpoint at the LMA. Remove it.
1330 CORE_ADDR addr
= overlay_unmapped_address (b
->address
,
1332 /* Ignore any failures: if the LMA is in ROM, we will
1333 have already warned when we failed to insert it. */
1334 if (b
->type
!= bp_hardware_breakpoint
)
1335 target_remove_hw_breakpoint (addr
, b
->shadow_contents
);
1337 target_remove_breakpoint (addr
, b
->shadow_contents
);
1339 /* Did we set a breakpoint at the VMA?
1340 If so, we will have marked the breakpoint 'inserted'. */
1343 /* Yes -- remove it. Previously we did not bother to
1344 remove the breakpoint if the section had been
1345 unmapped, but let's not rely on that being safe. We
1346 don't know what the overlay manager might do. */
1347 if (b
->type
== bp_hardware_breakpoint
)
1348 val
= target_remove_hw_breakpoint (b
->address
,
1349 b
->shadow_contents
);
1351 val
= target_remove_breakpoint (b
->address
,
1352 b
->shadow_contents
);
1356 /* No -- not inserted, so no need to remove. No error. */
1362 b
->inserted
= (is
== mark_inserted
);
1364 else if ((b
->type
== bp_hardware_watchpoint
||
1365 b
->type
== bp_read_watchpoint
||
1366 b
->type
== bp_access_watchpoint
)
1367 && b
->enable_state
== bp_enabled
1373 b
->inserted
= (is
== mark_inserted
);
1374 /* Walk down the saved value chain. */
1375 for (v
= b
->val_chain
; v
; v
= v
->next
)
1377 /* For each memory reference remove the watchpoint
1379 if (VALUE_LVAL (v
) == lval_memory
1380 && ! VALUE_LAZY (v
))
1382 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
1384 if (v
== b
->val_chain
1385 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
1386 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
1391 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1392 len
= TYPE_LENGTH (VALUE_TYPE (v
));
1394 if (b
->type
== bp_read_watchpoint
)
1396 else if (b
->type
== bp_access_watchpoint
)
1399 val
= target_remove_watchpoint (addr
, len
, type
);
1406 /* Failure to remove any of the hardware watchpoints comes here. */
1407 if ((is
== mark_uninserted
) && (b
->inserted
))
1408 warning ("Could not remove hardware watchpoint %d.",
1411 /* Free the saved value chain. We will construct a new one
1412 the next time the watchpoint is inserted. */
1413 for (v
= b
->val_chain
; v
; v
= n
)
1418 b
->val_chain
= NULL
;
1420 else if ((b
->type
== bp_catch_fork
||
1421 b
->type
== bp_catch_vfork
||
1422 b
->type
== bp_catch_exec
)
1423 && b
->enable_state
== bp_enabled
1430 val
= target_remove_fork_catchpoint (PIDGET (inferior_ptid
));
1432 case bp_catch_vfork
:
1433 val
= target_remove_vfork_catchpoint (PIDGET (inferior_ptid
));
1436 val
= target_remove_exec_catchpoint (PIDGET (inferior_ptid
));
1439 warning ("Internal error, %s line %d.", __FILE__
, __LINE__
);
1444 b
->inserted
= (is
== mark_inserted
);
1446 else if ((b
->type
== bp_catch_catch
||
1447 b
->type
== bp_catch_throw
)
1448 && b
->enable_state
== bp_enabled
1452 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1455 b
->inserted
= (is
== mark_inserted
);
1457 else if (ep_is_exception_catchpoint (b
)
1458 && b
->inserted
/* sometimes previous insert doesn't happen */
1459 && b
->enable_state
== bp_enabled
1463 val
= target_remove_breakpoint (b
->address
, b
->shadow_contents
);
1467 b
->inserted
= (is
== mark_inserted
);
1473 /* Clear the "inserted" flag in all breakpoints. */
1476 mark_breakpoints_out (void)
1478 register struct breakpoint
*b
;
1484 /* Clear the "inserted" flag in all breakpoints and delete any
1485 breakpoints which should go away between runs of the program.
1487 Plus other such housekeeping that has to be done for breakpoints
1490 Note: this function gets called at the end of a run (by
1491 generic_mourn_inferior) and when a run begins (by
1492 init_wait_for_inferior). */
1497 breakpoint_init_inferior (enum inf_context context
)
1499 register struct breakpoint
*b
, *temp
;
1500 static int warning_needed
= 0;
1502 ALL_BREAKPOINTS_SAFE (b
, temp
)
1509 case bp_watchpoint_scope
:
1511 /* If the call dummy breakpoint is at the entry point it will
1512 cause problems when the inferior is rerun, so we better
1515 Also get rid of scope breakpoints. */
1516 delete_breakpoint (b
);
1520 case bp_hardware_watchpoint
:
1521 case bp_read_watchpoint
:
1522 case bp_access_watchpoint
:
1524 /* Likewise for watchpoints on local expressions. */
1525 if (b
->exp_valid_block
!= NULL
)
1526 delete_breakpoint (b
);
1529 /* Likewise for exception catchpoints in dynamic-linked
1530 executables where required */
1531 if (ep_is_exception_catchpoint (b
) &&
1532 exception_catchpoints_are_fragile
)
1535 delete_breakpoint (b
);
1541 if (exception_catchpoints_are_fragile
)
1542 exception_support_initialized
= 0;
1544 /* Don't issue the warning unless it's really needed... */
1545 if (warning_needed
&& (context
!= inf_exited
))
1547 warning ("Exception catchpoints from last run were deleted.");
1548 warning ("You must reinsert them explicitly.");
1553 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1554 exists at PC. It returns ordinary_breakpoint_here if it's an
1555 ordinary breakpoint, or permanent_breakpoint_here if it's a
1556 permanent breakpoint.
1557 - When continuing from a location with an ordinary breakpoint, we
1558 actually single step once before calling insert_breakpoints.
1559 - When continuing from a localion with a permanent breakpoint, we
1560 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1561 the target, to advance the PC past the breakpoint. */
1563 enum breakpoint_here
1564 breakpoint_here_p (CORE_ADDR pc
)
1566 register struct breakpoint
*b
;
1567 int any_breakpoint_here
= 0;
1570 if ((b
->enable_state
== bp_enabled
1571 || b
->enable_state
== bp_permanent
)
1572 && b
->address
== pc
) /* bp is enabled and matches pc */
1574 if (overlay_debugging
1575 && section_is_overlay (b
->section
)
1576 && !section_is_mapped (b
->section
))
1577 continue; /* unmapped overlay -- can't be a match */
1578 else if (b
->enable_state
== bp_permanent
)
1579 return permanent_breakpoint_here
;
1581 any_breakpoint_here
= 1;
1584 return any_breakpoint_here
? ordinary_breakpoint_here
: 0;
1588 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1589 but it only returns true if there is actually a breakpoint inserted
1593 breakpoint_inserted_here_p (CORE_ADDR pc
)
1595 register struct breakpoint
*b
;
1599 && b
->address
== pc
) /* bp is inserted and matches pc */
1601 if (overlay_debugging
1602 && section_is_overlay (b
->section
)
1603 && !section_is_mapped (b
->section
))
1604 continue; /* unmapped overlay -- can't be a match */
1612 /* Return nonzero if FRAME is a dummy frame. We can't use
1613 PC_IN_CALL_DUMMY because figuring out the saved SP would take too
1614 much time, at least using get_saved_register on the 68k. This
1615 means that for this function to work right a port must use the
1616 bp_call_dummy breakpoint. */
1619 frame_in_dummy (struct frame_info
*frame
)
1621 struct breakpoint
*b
;
1626 if (USE_GENERIC_DUMMY_FRAMES
)
1627 return generic_pc_in_call_dummy (frame
->pc
, frame
->frame
, frame
->frame
);
1631 if (b
->type
== bp_call_dummy
1632 && b
->frame
== frame
->frame
1633 /* We need to check the PC as well as the frame on the sparc,
1634 for signals.exp in the testsuite. */
1637 - SIZEOF_CALL_DUMMY_WORDS
/ sizeof (LONGEST
) * REGISTER_SIZE
))
1638 && frame
->pc
<= b
->address
)
1644 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1645 PC is valid for process/thread PID. */
1648 breakpoint_thread_match (CORE_ADDR pc
, ptid_t ptid
)
1650 struct breakpoint
*b
;
1653 thread
= pid_to_thread_id (ptid
);
1656 if (b
->enable_state
!= bp_disabled
1657 && b
->enable_state
!= bp_shlib_disabled
1658 && b
->enable_state
!= bp_call_disabled
1660 && (b
->thread
== -1 || b
->thread
== thread
))
1662 if (overlay_debugging
1663 && section_is_overlay (b
->section
)
1664 && !section_is_mapped (b
->section
))
1665 continue; /* unmapped overlay -- can't be a match */
1674 /* bpstat stuff. External routines' interfaces are documented
1678 ep_is_catchpoint (struct breakpoint
*ep
)
1681 (ep
->type
== bp_catch_load
)
1682 || (ep
->type
== bp_catch_unload
)
1683 || (ep
->type
== bp_catch_fork
)
1684 || (ep
->type
== bp_catch_vfork
)
1685 || (ep
->type
== bp_catch_exec
)
1686 || (ep
->type
== bp_catch_catch
)
1687 || (ep
->type
== bp_catch_throw
);
1689 /* ??rehrauer: Add more kinds here, as are implemented... */
1693 ep_is_shlib_catchpoint (struct breakpoint
*ep
)
1696 (ep
->type
== bp_catch_load
)
1697 || (ep
->type
== bp_catch_unload
);
1701 ep_is_exception_catchpoint (struct breakpoint
*ep
)
1704 (ep
->type
== bp_catch_catch
)
1705 || (ep
->type
== bp_catch_throw
);
1708 /* Clear a bpstat so that it says we are not at any breakpoint.
1709 Also free any storage that is part of a bpstat. */
1712 bpstat_clear (bpstat
*bsp
)
1723 if (p
->old_val
!= NULL
)
1724 value_free (p
->old_val
);
1731 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1732 is part of the bpstat is copied as well. */
1735 bpstat_copy (bpstat bs
)
1739 bpstat retval
= NULL
;
1744 for (; bs
!= NULL
; bs
= bs
->next
)
1746 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
1747 memcpy (tmp
, bs
, sizeof (*tmp
));
1749 /* This is the first thing in the chain. */
1759 /* Find the bpstat associated with this breakpoint */
1762 bpstat_find_breakpoint (bpstat bsp
, struct breakpoint
*breakpoint
)
1767 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1769 if (bsp
->breakpoint_at
== breakpoint
)
1775 /* Find a step_resume breakpoint associated with this bpstat.
1776 (If there are multiple step_resume bp's on the list, this function
1777 will arbitrarily pick one.)
1779 It is an error to use this function if BPSTAT doesn't contain a
1780 step_resume breakpoint.
1782 See wait_for_inferior's use of this function. */
1784 bpstat_find_step_resume_breakpoint (bpstat bsp
)
1789 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1791 current_thread
= pid_to_thread_id (inferior_ptid
);
1793 for (; bsp
!= NULL
; bsp
= bsp
->next
)
1795 if ((bsp
->breakpoint_at
!= NULL
) &&
1796 (bsp
->breakpoint_at
->type
== bp_step_resume
) &&
1797 (bsp
->breakpoint_at
->thread
== current_thread
||
1798 bsp
->breakpoint_at
->thread
== -1))
1799 return bsp
->breakpoint_at
;
1802 error ("Internal error (no step_resume breakpoint found)");
1806 /* Return the breakpoint number of the first breakpoint we are stopped
1807 at. *BSP upon return is a bpstat which points to the remaining
1808 breakpoints stopped at (but which is not guaranteed to be good for
1809 anything but further calls to bpstat_num).
1810 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1813 bpstat_num (bpstat
*bsp
)
1815 struct breakpoint
*b
;
1818 return 0; /* No more breakpoint values */
1821 b
= (*bsp
)->breakpoint_at
;
1822 *bsp
= (*bsp
)->next
;
1824 return -1; /* breakpoint that's been deleted since */
1826 return b
->number
; /* We have its number */
1830 /* Modify BS so that the actions will not be performed. */
1833 bpstat_clear_actions (bpstat bs
)
1835 for (; bs
!= NULL
; bs
= bs
->next
)
1837 bs
->commands
= NULL
;
1838 if (bs
->old_val
!= NULL
)
1840 value_free (bs
->old_val
);
1846 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1849 cleanup_executing_breakpoints (PTR ignore
)
1851 executing_breakpoint_commands
= 0;
1854 /* Execute all the commands associated with all the breakpoints at this
1855 location. Any of these commands could cause the process to proceed
1856 beyond this point, etc. We look out for such changes by checking
1857 the global "breakpoint_proceeded" after each command. */
1860 bpstat_do_actions (bpstat
*bsp
)
1863 struct cleanup
*old_chain
;
1864 struct command_line
*cmd
;
1866 /* Avoid endless recursion if a `source' command is contained
1868 if (executing_breakpoint_commands
)
1871 executing_breakpoint_commands
= 1;
1872 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
1875 /* Note that (as of this writing), our callers all appear to
1876 be passing us the address of global stop_bpstat. And, if
1877 our calls to execute_control_command cause the inferior to
1878 proceed, that global (and hence, *bsp) will change.
1880 We must be careful to not touch *bsp unless the inferior
1881 has not proceeded. */
1883 /* This pointer will iterate over the list of bpstat's. */
1886 breakpoint_proceeded
= 0;
1887 for (; bs
!= NULL
; bs
= bs
->next
)
1892 execute_control_command (cmd
);
1894 if (breakpoint_proceeded
)
1899 if (breakpoint_proceeded
)
1900 /* The inferior is proceeded by the command; bomb out now.
1901 The bpstat chain has been blown away by wait_for_inferior.
1902 But since execution has stopped again, there is a new bpstat
1903 to look at, so start over. */
1906 bs
->commands
= NULL
;
1909 executing_breakpoint_commands
= 0;
1910 discard_cleanups (old_chain
);
1913 /* This is the normal print function for a bpstat. In the future,
1914 much of this logic could (should?) be moved to bpstat_stop_status,
1915 by having it set different print_it values.
1917 Current scheme: When we stop, bpstat_print() is called. It loops
1918 through the bpstat list of things causing this stop, calling the
1919 print_bp_stop_message function on each one. The behavior of the
1920 print_bp_stop_message function depends on the print_it field of
1921 bpstat. If such field so indicates, call this function here.
1923 Return values from this routine (ultimately used by bpstat_print()
1924 and normal_stop() to decide what to do):
1925 PRINT_NOTHING: Means we already printed all we needed to print,
1926 don't print anything else.
1927 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
1928 that something to be followed by a location.
1929 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
1930 that something to be followed by a location.
1931 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
1934 static enum print_stop_action
1935 print_it_typical (bpstat bs
)
1937 struct cleanup
*old_chain
;
1938 struct ui_stream
*stb
;
1939 stb
= ui_out_stream_new (uiout
);
1940 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
1941 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
1942 which has since been deleted. */
1943 if (bs
->breakpoint_at
== NULL
)
1944 return PRINT_UNKNOWN
;
1946 switch (bs
->breakpoint_at
->type
)
1949 case bp_hardware_breakpoint
:
1950 annotate_breakpoint (bs
->breakpoint_at
->number
);
1951 ui_out_text (uiout
, "\nBreakpoint ");
1952 if (ui_out_is_mi_like_p (uiout
))
1953 ui_out_field_string (uiout
, "reason", "breakpoint-hit");
1954 ui_out_field_int (uiout
, "bkptno", bs
->breakpoint_at
->number
);
1955 ui_out_text (uiout
, ", ");
1956 return PRINT_SRC_AND_LOC
;
1959 case bp_shlib_event
:
1960 /* Did we stop because the user set the stop_on_solib_events
1961 variable? (If so, we report this as a generic, "Stopped due
1962 to shlib event" message.) */
1963 printf_filtered ("Stopped due to shared library event\n");
1964 return PRINT_NOTHING
;
1967 case bp_thread_event
:
1968 /* Not sure how we will get here.
1969 GDB should not stop for these breakpoints. */
1970 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
1971 return PRINT_NOTHING
;
1974 case bp_overlay_event
:
1975 /* By analogy with the thread event, GDB should not stop for these. */
1976 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
1977 return PRINT_NOTHING
;
1981 annotate_catchpoint (bs
->breakpoint_at
->number
);
1982 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1983 printf_filtered ("loaded");
1984 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1985 return PRINT_SRC_AND_LOC
;
1988 case bp_catch_unload
:
1989 annotate_catchpoint (bs
->breakpoint_at
->number
);
1990 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1991 printf_filtered ("unloaded");
1992 printf_filtered (" %s), ", bs
->breakpoint_at
->triggered_dll_pathname
);
1993 return PRINT_SRC_AND_LOC
;
1997 annotate_catchpoint (bs
->breakpoint_at
->number
);
1998 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
1999 printf_filtered ("forked");
2000 printf_filtered (" process %d), ",
2001 bs
->breakpoint_at
->forked_inferior_pid
);
2002 return PRINT_SRC_AND_LOC
;
2005 case bp_catch_vfork
:
2006 annotate_catchpoint (bs
->breakpoint_at
->number
);
2007 printf_filtered ("\nCatchpoint %d (", bs
->breakpoint_at
->number
);
2008 printf_filtered ("vforked");
2009 printf_filtered (" process %d), ",
2010 bs
->breakpoint_at
->forked_inferior_pid
);
2011 return PRINT_SRC_AND_LOC
;
2015 annotate_catchpoint (bs
->breakpoint_at
->number
);
2016 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2017 bs
->breakpoint_at
->number
,
2018 bs
->breakpoint_at
->exec_pathname
);
2019 return PRINT_SRC_AND_LOC
;
2022 case bp_catch_catch
:
2023 if (current_exception_event
&&
2024 (CURRENT_EXCEPTION_KIND
== EX_EVENT_CATCH
))
2026 annotate_catchpoint (bs
->breakpoint_at
->number
);
2027 printf_filtered ("\nCatchpoint %d (exception caught), ",
2028 bs
->breakpoint_at
->number
);
2029 printf_filtered ("throw location ");
2030 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2031 printf_filtered ("%s:%d",
2032 CURRENT_EXCEPTION_THROW_FILE
,
2033 CURRENT_EXCEPTION_THROW_LINE
);
2035 printf_filtered ("unknown");
2037 printf_filtered (", catch location ");
2038 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2039 printf_filtered ("%s:%d",
2040 CURRENT_EXCEPTION_CATCH_FILE
,
2041 CURRENT_EXCEPTION_CATCH_LINE
);
2043 printf_filtered ("unknown");
2045 printf_filtered ("\n");
2046 /* don't bother to print location frame info */
2047 return PRINT_SRC_ONLY
;
2051 /* really throw, some other bpstat will handle it */
2052 return PRINT_UNKNOWN
;
2056 case bp_catch_throw
:
2057 if (current_exception_event
&&
2058 (CURRENT_EXCEPTION_KIND
== EX_EVENT_THROW
))
2060 annotate_catchpoint (bs
->breakpoint_at
->number
);
2061 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2062 bs
->breakpoint_at
->number
);
2063 printf_filtered ("throw location ");
2064 if (CURRENT_EXCEPTION_THROW_PC
&& CURRENT_EXCEPTION_THROW_LINE
)
2065 printf_filtered ("%s:%d",
2066 CURRENT_EXCEPTION_THROW_FILE
,
2067 CURRENT_EXCEPTION_THROW_LINE
);
2069 printf_filtered ("unknown");
2071 printf_filtered (", catch location ");
2072 if (CURRENT_EXCEPTION_CATCH_PC
&& CURRENT_EXCEPTION_CATCH_LINE
)
2073 printf_filtered ("%s:%d",
2074 CURRENT_EXCEPTION_CATCH_FILE
,
2075 CURRENT_EXCEPTION_CATCH_LINE
);
2077 printf_filtered ("unknown");
2079 printf_filtered ("\n");
2080 /* don't bother to print location frame info */
2081 return PRINT_SRC_ONLY
;
2085 /* really catch, some other bpstat will handle it */
2086 return PRINT_UNKNOWN
;
2091 case bp_hardware_watchpoint
:
2092 if (bs
->old_val
!= NULL
)
2094 annotate_watchpoint (bs
->breakpoint_at
->number
);
2095 if (ui_out_is_mi_like_p (uiout
))
2096 ui_out_field_string (uiout
, "reason", "watchpoint-trigger");
2097 mention (bs
->breakpoint_at
);
2098 ui_out_tuple_begin (uiout
, "value");
2099 ui_out_text (uiout
, "\nOld value = ");
2100 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2101 ui_out_field_stream (uiout
, "old", stb
);
2102 ui_out_text (uiout
, "\nNew value = ");
2103 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2104 ui_out_field_stream (uiout
, "new", stb
);
2105 ui_out_tuple_end (uiout
);
2106 ui_out_text (uiout
, "\n");
2107 value_free (bs
->old_val
);
2110 /* More than one watchpoint may have been triggered. */
2111 return PRINT_UNKNOWN
;
2114 case bp_read_watchpoint
:
2115 if (ui_out_is_mi_like_p (uiout
))
2116 ui_out_field_string (uiout
, "reason", "read-watchpoint-trigger");
2117 mention (bs
->breakpoint_at
);
2118 ui_out_tuple_begin (uiout
, "value");
2119 ui_out_text (uiout
, "\nValue = ");
2120 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0, Val_pretty_default
);
2121 ui_out_field_stream (uiout
, "value", stb
);
2122 ui_out_tuple_end (uiout
);
2123 ui_out_text (uiout
, "\n");
2124 return PRINT_UNKNOWN
;
2127 case bp_access_watchpoint
:
2128 if (bs
->old_val
!= NULL
)
2130 annotate_watchpoint (bs
->breakpoint_at
->number
);
2131 if (ui_out_is_mi_like_p (uiout
))
2132 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2133 mention (bs
->breakpoint_at
);
2134 ui_out_tuple_begin (uiout
, "value");
2135 ui_out_text (uiout
, "\nOld value = ");
2136 value_print (bs
->old_val
, stb
->stream
, 0, Val_pretty_default
);
2137 ui_out_field_stream (uiout
, "old", stb
);
2138 value_free (bs
->old_val
);
2140 ui_out_text (uiout
, "\nNew value = ");
2144 mention (bs
->breakpoint_at
);
2145 if (ui_out_is_mi_like_p (uiout
))
2146 ui_out_field_string (uiout
, "reason", "access-watchpoint-trigger");
2147 ui_out_tuple_begin (uiout
, "value");
2148 ui_out_text (uiout
, "\nValue = ");
2150 value_print (bs
->breakpoint_at
->val
, stb
->stream
, 0,Val_pretty_default
);
2151 ui_out_field_stream (uiout
, "new", stb
);
2152 ui_out_tuple_end (uiout
);
2153 ui_out_text (uiout
, "\n");
2154 return PRINT_UNKNOWN
;
2157 /* Fall through, we don't deal with these types of breakpoints
2161 if (ui_out_is_mi_like_p (uiout
))
2162 ui_out_field_string (uiout
, "reason", "function-finished");
2163 return PRINT_UNKNOWN
;
2167 if (ui_out_is_mi_like_p (uiout
))
2168 ui_out_field_string (uiout
, "reason", "location-reached");
2169 return PRINT_UNKNOWN
;
2174 case bp_longjmp_resume
:
2175 case bp_step_resume
:
2176 case bp_through_sigtramp
:
2177 case bp_watchpoint_scope
:
2180 return PRINT_UNKNOWN
;
2184 /* Generic routine for printing messages indicating why we
2185 stopped. The behavior of this function depends on the value
2186 'print_it' in the bpstat structure. Under some circumstances we
2187 may decide not to print anything here and delegate the task to
2190 static enum print_stop_action
2191 print_bp_stop_message (bpstat bs
)
2193 switch (bs
->print_it
)
2196 /* Nothing should be printed for this bpstat entry. */
2197 return PRINT_UNKNOWN
;
2201 /* We still want to print the frame, but we already printed the
2202 relevant messages. */
2203 return PRINT_SRC_AND_LOC
;
2206 case print_it_normal
:
2207 /* Normal case, we handle everything in print_it_typical. */
2208 return print_it_typical (bs
);
2211 internal_error (__FILE__
, __LINE__
,
2212 "print_bp_stop_message: unrecognized enum value");
2217 /* Print a message indicating what happened. This is called from
2218 normal_stop(). The input to this routine is the head of the bpstat
2219 list - a list of the eventpoints that caused this stop. This
2220 routine calls the generic print routine for printing a message
2221 about reasons for stopping. This will print (for example) the
2222 "Breakpoint n," part of the output. The return value of this
2225 PRINT_UNKNOWN: Means we printed nothing
2226 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2227 code to print the location. An example is
2228 "Breakpoint 1, " which should be followed by
2230 PRINT_SRC_ONLY: Means we printed something, but there is no need
2231 to also print the location part of the message.
2232 An example is the catch/throw messages, which
2233 don't require a location appended to the end.
2234 PRINT_NOTHING: We have done some printing and we don't need any
2235 further info to be printed.*/
2237 enum print_stop_action
2238 bpstat_print (bpstat bs
)
2242 /* Maybe another breakpoint in the chain caused us to stop.
2243 (Currently all watchpoints go on the bpstat whether hit or not.
2244 That probably could (should) be changed, provided care is taken
2245 with respect to bpstat_explains_signal). */
2246 for (; bs
; bs
= bs
->next
)
2248 val
= print_bp_stop_message (bs
);
2249 if (val
== PRINT_SRC_ONLY
2250 || val
== PRINT_SRC_AND_LOC
2251 || val
== PRINT_NOTHING
)
2255 /* We reached the end of the chain, or we got a null BS to start
2256 with and nothing was printed. */
2257 return PRINT_UNKNOWN
;
2260 /* Evaluate the expression EXP and return 1 if value is zero.
2261 This is used inside a catch_errors to evaluate the breakpoint condition.
2262 The argument is a "struct expression *" that has been cast to char * to
2263 make it pass through catch_errors. */
2266 breakpoint_cond_eval (PTR exp
)
2268 struct value
*mark
= value_mark ();
2269 int i
= !value_true (evaluate_expression ((struct expression
*) exp
));
2270 value_free_to_mark (mark
);
2274 /* Allocate a new bpstat and chain it to the current one. */
2277 bpstat_alloc (struct breakpoint
*b
, bpstat cbs
/* Current "bs" value */ )
2281 bs
= (bpstat
) xmalloc (sizeof (*bs
));
2283 bs
->breakpoint_at
= b
;
2284 /* If the condition is false, etc., don't do the commands. */
2285 bs
->commands
= NULL
;
2287 bs
->print_it
= print_it_normal
;
2291 /* Possible return values for watchpoint_check (this can't be an enum
2292 because of check_errors). */
2293 /* The watchpoint has been deleted. */
2294 #define WP_DELETED 1
2295 /* The value has changed. */
2296 #define WP_VALUE_CHANGED 2
2297 /* The value has not changed. */
2298 #define WP_VALUE_NOT_CHANGED 3
2300 #define BP_TEMPFLAG 1
2301 #define BP_HARDWAREFLAG 2
2303 /* Check watchpoint condition. */
2306 watchpoint_check (PTR p
)
2308 bpstat bs
= (bpstat
) p
;
2309 struct breakpoint
*b
;
2310 struct frame_info
*fr
;
2311 int within_current_scope
;
2313 b
= bs
->breakpoint_at
;
2315 if (b
->exp_valid_block
== NULL
)
2316 within_current_scope
= 1;
2319 /* There is no current frame at this moment. If we're going to have
2320 any chance of handling watchpoints on local variables, we'll need
2321 the frame chain (so we can determine if we're in scope). */
2322 reinit_frame_cache ();
2323 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
2324 within_current_scope
= (fr
!= NULL
);
2325 /* in_function_epilogue_p() returns a non-zero value if we're still
2326 in the function but the stack frame has already been invalidated.
2327 Since we can't rely on the values of local variables after the
2328 stack has been destroyed, we are treating the watchpoint in that
2329 state as `not changed' without further checking. */
2330 if (within_current_scope
&& fr
== get_current_frame ()
2331 && gdbarch_in_function_epilogue_p (current_gdbarch
, read_pc ()))
2332 return WP_VALUE_NOT_CHANGED
;
2333 if (within_current_scope
)
2334 /* If we end up stopping, the current frame will get selected
2335 in normal_stop. So this call to select_frame won't affect
2337 select_frame (fr
, -1);
2340 if (within_current_scope
)
2342 /* We use value_{,free_to_}mark because it could be a
2343 *long* time before we return to the command level and
2344 call free_all_values. We can't call free_all_values because
2345 we might be in the middle of evaluating a function call. */
2347 struct value
*mark
= value_mark ();
2348 struct value
*new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
2349 if (!value_equal (b
->val
, new_val
))
2351 release_value (new_val
);
2352 value_free_to_mark (mark
);
2353 bs
->old_val
= b
->val
;
2355 /* We will stop here */
2356 return WP_VALUE_CHANGED
;
2360 /* Nothing changed, don't do anything. */
2361 value_free_to_mark (mark
);
2362 /* We won't stop here */
2363 return WP_VALUE_NOT_CHANGED
;
2368 /* This seems like the only logical thing to do because
2369 if we temporarily ignored the watchpoint, then when
2370 we reenter the block in which it is valid it contains
2371 garbage (in the case of a function, it may have two
2372 garbage values, one before and one after the prologue).
2373 So we can't even detect the first assignment to it and
2374 watch after that (since the garbage may or may not equal
2375 the first value assigned). */
2376 /* We print all the stop information in print_it_typical(), but
2377 in this case, by the time we call print_it_typical() this bp
2378 will be deleted already. So we have no choice but print the
2379 information here. */
2380 if (ui_out_is_mi_like_p (uiout
))
2381 ui_out_field_string (uiout
, "reason", "watchpoint-scope");
2382 ui_out_text (uiout
, "\nWatchpoint ");
2383 ui_out_field_int (uiout
, "wpnum", bs
->breakpoint_at
->number
);
2384 ui_out_text (uiout
, " deleted because the program has left the block in\n\
2385 which its expression is valid.\n");
2387 if (b
->related_breakpoint
)
2388 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2389 b
->disposition
= disp_del_at_next_stop
;
2395 /* Get a bpstat associated with having just stopped at address *PC
2396 and frame address CORE_ADDRESS. Update *PC to point at the
2397 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
2398 if this is known to not be a real breakpoint (it could still be a
2399 watchpoint, though). */
2401 /* Determine whether we stopped at a breakpoint, etc, or whether we
2402 don't understand this stop. Result is a chain of bpstat's such that:
2404 if we don't understand the stop, the result is a null pointer.
2406 if we understand why we stopped, the result is not null.
2408 Each element of the chain refers to a particular breakpoint or
2409 watchpoint at which we have stopped. (We may have stopped for
2410 several reasons concurrently.)
2412 Each element of the chain has valid next, breakpoint_at,
2413 commands, FIXME??? fields. */
2416 bpstat_stop_status (CORE_ADDR
*pc
, int not_a_breakpoint
)
2418 register struct breakpoint
*b
, *temp
;
2420 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2421 int real_breakpoint
= 0;
2422 /* Root of the chain of bpstat's */
2423 struct bpstats root_bs
[1];
2424 /* Pointer to the last thing in the chain currently. */
2425 bpstat bs
= root_bs
;
2426 static char message1
[] =
2427 "Error evaluating expression for watchpoint %d\n";
2428 char message
[sizeof (message1
) + 30 /* slop */ ];
2430 /* Get the address where the breakpoint would have been.
2431 The "not_a_breakpoint" argument is meant to distinguish
2432 between a breakpoint trap event and a trace/singlestep
2433 trap event. For a trace/singlestep trap event, we would
2434 not want to subtract DECR_PC_AFTER_BREAK from the PC. */
2436 bp_addr
= *pc
- (not_a_breakpoint
&& !SOFTWARE_SINGLE_STEP_P () ?
2437 0 : DECR_PC_AFTER_BREAK
);
2439 ALL_BREAKPOINTS_SAFE (b
, temp
)
2441 if (b
->enable_state
== bp_disabled
2442 || b
->enable_state
== bp_shlib_disabled
2443 || b
->enable_state
== bp_call_disabled
)
2446 if (b
->type
!= bp_watchpoint
2447 && b
->type
!= bp_hardware_watchpoint
2448 && b
->type
!= bp_read_watchpoint
2449 && b
->type
!= bp_access_watchpoint
2450 && b
->type
!= bp_hardware_breakpoint
2451 && b
->type
!= bp_catch_fork
2452 && b
->type
!= bp_catch_vfork
2453 && b
->type
!= bp_catch_exec
2454 && b
->type
!= bp_catch_catch
2455 && b
->type
!= bp_catch_throw
) /* a non-watchpoint bp */
2457 if (b
->address
!= bp_addr
) /* address doesn't match */
2459 if (overlay_debugging
/* unmapped overlay section */
2460 && section_is_overlay (b
->section
)
2461 && !section_is_mapped (b
->section
))
2465 if (b
->type
== bp_hardware_breakpoint
)
2467 if (b
->address
!= (*pc
- DECR_PC_AFTER_HW_BREAK
))
2469 if (overlay_debugging
/* unmapped overlay section */
2470 && section_is_overlay (b
->section
)
2471 && !section_is_mapped (b
->section
))
2475 /* Is this a catchpoint of a load or unload? If so, did we
2476 get a load or unload of the specified library? If not,
2478 if ((b
->type
== bp_catch_load
)
2479 #if defined(SOLIB_HAVE_LOAD_EVENT)
2480 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid
))
2481 || ((b
->dll_pathname
!= NULL
)
2482 && (strcmp (b
->dll_pathname
,
2483 SOLIB_LOADED_LIBRARY_PATHNAME (
2484 PIDGET (inferior_ptid
)))
2490 if ((b
->type
== bp_catch_unload
)
2491 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2492 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid
))
2493 || ((b
->dll_pathname
!= NULL
)
2494 && (strcmp (b
->dll_pathname
,
2495 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2496 PIDGET (inferior_ptid
)))
2502 if ((b
->type
== bp_catch_fork
)
2503 && !target_has_forked (PIDGET (inferior_ptid
),
2504 &b
->forked_inferior_pid
))
2507 if ((b
->type
== bp_catch_vfork
)
2508 && !target_has_vforked (PIDGET (inferior_ptid
),
2509 &b
->forked_inferior_pid
))
2512 if ((b
->type
== bp_catch_exec
)
2513 && !target_has_execd (PIDGET (inferior_ptid
), &b
->exec_pathname
))
2516 if (ep_is_exception_catchpoint (b
) &&
2517 !(current_exception_event
= target_get_current_exception_event ()))
2520 /* Come here if it's a watchpoint, or if the break address matches */
2522 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
2524 /* Watchpoints may change this, if not found to have triggered. */
2528 sprintf (message
, message1
, b
->number
);
2529 if (b
->type
== bp_watchpoint
||
2530 b
->type
== bp_hardware_watchpoint
)
2532 switch (catch_errors (watchpoint_check
, bs
, message
,
2536 /* We've already printed what needs to be printed. */
2537 /* Actually this is superfluous, because by the time we
2538 call print_it_typical() the wp will be already deleted,
2539 and the function will return immediately. */
2540 bs
->print_it
= print_it_done
;
2543 case WP_VALUE_CHANGED
:
2547 case WP_VALUE_NOT_CHANGED
:
2549 bs
->print_it
= print_it_noop
;
2556 /* Error from catch_errors. */
2557 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2558 if (b
->related_breakpoint
)
2559 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2560 b
->disposition
= disp_del_at_next_stop
;
2561 /* We've already printed what needs to be printed. */
2562 bs
->print_it
= print_it_done
;
2568 else if (b
->type
== bp_read_watchpoint
||
2569 b
->type
== bp_access_watchpoint
)
2575 addr
= target_stopped_data_address ();
2578 for (v
= b
->val_chain
; v
; v
= v
->next
)
2580 if (VALUE_LVAL (v
) == lval_memory
2581 && ! VALUE_LAZY (v
))
2583 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
2585 if (v
== b
->val_chain
2586 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
2587 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
2591 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
2592 /* Exact match not required. Within range is
2594 if (addr
>= vaddr
&&
2595 addr
< vaddr
+ TYPE_LENGTH (VALUE_TYPE (v
)))
2601 switch (catch_errors (watchpoint_check
, bs
, message
,
2605 /* We've already printed what needs to be printed. */
2606 bs
->print_it
= print_it_done
;
2609 case WP_VALUE_CHANGED
:
2610 if (b
->type
== bp_read_watchpoint
)
2612 /* Don't stop: read watchpoints shouldn't fire if
2613 the value has changed. This is for targets which
2614 cannot set read-only watchpoints. */
2615 bs
->print_it
= print_it_noop
;
2621 case WP_VALUE_NOT_CHANGED
:
2628 /* Error from catch_errors. */
2629 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
2630 if (b
->related_breakpoint
)
2631 b
->related_breakpoint
->disposition
= disp_del_at_next_stop
;
2632 b
->disposition
= disp_del_at_next_stop
;
2633 /* We've already printed what needs to be printed. */
2634 bs
->print_it
= print_it_done
;
2637 else /* found == 0 */
2639 /* This is a case where some watchpoint(s) triggered,
2640 but not at the address of this watchpoint (FOUND
2641 was left zero). So don't print anything for this
2643 bs
->print_it
= print_it_noop
;
2650 /* By definition, an encountered breakpoint is a triggered
2654 real_breakpoint
= 1;
2658 b
->frame
!= (get_current_frame ())->frame
)
2662 int value_is_zero
= 0;
2666 /* Need to select the frame, with all that implies
2667 so that the conditions will have the right context. */
2668 select_frame (get_current_frame (), 0);
2670 = catch_errors (breakpoint_cond_eval
, (b
->cond
),
2671 "Error in testing breakpoint condition:\n",
2673 /* FIXME-someday, should give breakpoint # */
2676 if (b
->cond
&& value_is_zero
)
2679 /* Don't consider this a hit. */
2682 else if (b
->ignore_count
> 0)
2685 annotate_ignore_count_change ();
2690 /* We will stop here */
2691 if (b
->disposition
== disp_disable
)
2692 b
->enable_state
= bp_disabled
;
2693 bs
->commands
= b
->commands
;
2697 (STREQ ("silent", bs
->commands
->line
) ||
2698 (xdb_commands
&& STREQ ("Q", bs
->commands
->line
))))
2700 bs
->commands
= bs
->commands
->next
;
2705 /* Print nothing for this entry if we dont stop or if we dont print. */
2706 if (bs
->stop
== 0 || bs
->print
== 0)
2707 bs
->print_it
= print_it_noop
;
2710 bs
->next
= NULL
; /* Terminate the chain */
2711 bs
= root_bs
->next
; /* Re-grab the head of the chain */
2713 if (real_breakpoint
&& bs
)
2715 if (bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
2717 if (DECR_PC_AFTER_HW_BREAK
!= 0)
2719 *pc
= *pc
- DECR_PC_AFTER_HW_BREAK
;
2725 if (DECR_PC_AFTER_BREAK
!= 0 || must_shift_inst_regs
)
2728 #if defined (SHIFT_INST_REGS)
2730 #else /* No SHIFT_INST_REGS. */
2732 #endif /* No SHIFT_INST_REGS. */
2737 /* The value of a hardware watchpoint hasn't changed, but the
2738 intermediate memory locations we are watching may have. */
2739 if (bs
&& !bs
->stop
&&
2740 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
2741 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
2742 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
2744 remove_breakpoints ();
2745 insert_breakpoints ();
2750 /* Tell what to do about this bpstat. */
2752 bpstat_what (bpstat bs
)
2754 /* Classify each bpstat as one of the following. */
2757 /* This bpstat element has no effect on the main_action. */
2760 /* There was a watchpoint, stop but don't print. */
2763 /* There was a watchpoint, stop and print. */
2766 /* There was a breakpoint but we're not stopping. */
2769 /* There was a breakpoint, stop but don't print. */
2772 /* There was a breakpoint, stop and print. */
2775 /* We hit the longjmp breakpoint. */
2778 /* We hit the longjmp_resume breakpoint. */
2781 /* We hit the step_resume breakpoint. */
2784 /* We hit the through_sigtramp breakpoint. */
2787 /* We hit the shared library event breakpoint. */
2790 /* We caught a shared library event. */
2793 /* This is just used to count how many enums there are. */
2797 /* Here is the table which drives this routine. So that we can
2798 format it pretty, we define some abbreviations for the
2799 enum bpstat_what codes. */
2800 #define kc BPSTAT_WHAT_KEEP_CHECKING
2801 #define ss BPSTAT_WHAT_STOP_SILENT
2802 #define sn BPSTAT_WHAT_STOP_NOISY
2803 #define sgl BPSTAT_WHAT_SINGLE
2804 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2805 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2806 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2807 #define sr BPSTAT_WHAT_STEP_RESUME
2808 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2809 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2810 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2812 /* "Can't happen." Might want to print an error message.
2813 abort() is not out of the question, but chances are GDB is just
2814 a bit confused, not unusable. */
2815 #define err BPSTAT_WHAT_STOP_NOISY
2817 /* Given an old action and a class, come up with a new action. */
2818 /* One interesting property of this table is that wp_silent is the same
2819 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2820 after stopping, the check for whether to step over a breakpoint
2821 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2822 reference to how we stopped. We retain separate wp_silent and
2823 bp_silent codes in case we want to change that someday.
2825 Another possibly interesting property of this table is that
2826 there's a partial ordering, priority-like, of the actions. Once
2827 you've decided that some action is appropriate, you'll never go
2828 back and decide something of a lower priority is better. The
2831 kc < clr sgl shl shlr slr sn sr ss ts
2832 sgl < clrs shl shlr slr sn sr ss ts
2833 slr < err shl shlr sn sr ss ts
2834 clr < clrs err shl shlr sn sr ss ts
2835 clrs < err shl shlr sn sr ss ts
2836 ss < shl shlr sn sr ts
2843 What I think this means is that we don't need a damned table
2844 here. If you just put the rows and columns in the right order,
2845 it'd look awfully regular. We could simply walk the bpstat list
2846 and choose the highest priority action we find, with a little
2847 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2848 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2849 is messy anyway). */
2851 /* step_resume entries: a step resume breakpoint overrides another
2852 breakpoint of signal handling (see comment in wait_for_inferior
2853 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
2854 /* We handle the through_sigtramp_breakpoint the same way; having both
2855 one of those and a step_resume_breakpoint is probably very rare (?). */
2857 static const enum bpstat_what_main_action
2858 table
[(int) class_last
][(int) BPSTAT_WHAT_LAST
] =
2861 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2864 {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
, shlr
},
2866 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2868 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2870 {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
, shlr
},
2872 {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
, shlr
},
2874 {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
, shlr
},
2876 {slr
, ss
, sn
, slr
, slr
, err
, err
, sr
, ts
, shl
, shlr
},
2878 {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
, shlr
},
2880 {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
, shlr
},
2882 {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
, shlr
},
2884 {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
, shlr
},
2886 {shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, shlr
, ts
, shlr
, shlr
}
2901 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
2902 struct bpstat_what retval
;
2904 retval
.call_dummy
= 0;
2905 for (; bs
!= NULL
; bs
= bs
->next
)
2907 enum class bs_class
= no_effect
;
2908 if (bs
->breakpoint_at
== NULL
)
2909 /* I suspect this can happen if it was a momentary breakpoint
2910 which has since been deleted. */
2912 switch (bs
->breakpoint_at
->type
)
2918 case bp_hardware_breakpoint
:
2924 bs_class
= bp_noisy
;
2926 bs_class
= bp_silent
;
2929 bs_class
= bp_nostop
;
2932 case bp_hardware_watchpoint
:
2933 case bp_read_watchpoint
:
2934 case bp_access_watchpoint
:
2938 bs_class
= wp_noisy
;
2940 bs_class
= wp_silent
;
2943 /* There was a watchpoint, but we're not stopping.
2944 This requires no further action. */
2945 bs_class
= no_effect
;
2948 bs_class
= long_jump
;
2950 case bp_longjmp_resume
:
2951 bs_class
= long_resume
;
2953 case bp_step_resume
:
2956 bs_class
= step_resume
;
2959 /* It is for the wrong frame. */
2960 bs_class
= bp_nostop
;
2962 case bp_through_sigtramp
:
2963 bs_class
= through_sig
;
2965 case bp_watchpoint_scope
:
2966 bs_class
= bp_nostop
;
2968 case bp_shlib_event
:
2969 bs_class
= shlib_event
;
2971 case bp_thread_event
:
2972 case bp_overlay_event
:
2973 bs_class
= bp_nostop
;
2976 case bp_catch_unload
:
2977 /* Only if this catchpoint triggered should we cause the
2978 step-out-of-dld behaviour. Otherwise, we ignore this
2981 bs_class
= catch_shlib_event
;
2983 bs_class
= no_effect
;
2986 case bp_catch_vfork
:
2991 bs_class
= bp_noisy
;
2993 bs_class
= bp_silent
;
2996 /* There was a catchpoint, but we're not stopping.
2997 This requires no further action. */
2998 bs_class
= no_effect
;
3000 case bp_catch_catch
:
3001 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_CATCH
)
3002 bs_class
= bp_nostop
;
3004 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3006 case bp_catch_throw
:
3007 if (!bs
->stop
|| CURRENT_EXCEPTION_KIND
!= EX_EVENT_THROW
)
3008 bs_class
= bp_nostop
;
3010 bs_class
= bs
->print
? bp_noisy
: bp_silent
;
3013 /* Make sure the action is stop (silent or noisy),
3014 so infrun.c pops the dummy frame. */
3015 bs_class
= bp_silent
;
3016 retval
.call_dummy
= 1;
3019 current_action
= table
[(int) bs_class
][(int) current_action
];
3021 retval
.main_action
= current_action
;
3025 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3026 without hardware support). This isn't related to a specific bpstat,
3027 just to things like whether watchpoints are set. */
3030 bpstat_should_step (void)
3032 struct breakpoint
*b
;
3034 if (b
->enable_state
== bp_enabled
&& b
->type
== bp_watchpoint
)
3039 /* Nonzero if there are enabled hardware watchpoints. */
3041 bpstat_have_active_hw_watchpoints (void)
3043 struct breakpoint
*b
;
3045 if ((b
->enable_state
== bp_enabled
) &&
3047 ((b
->type
== bp_hardware_watchpoint
) ||
3048 (b
->type
== bp_read_watchpoint
) ||
3049 (b
->type
== bp_access_watchpoint
)))
3055 /* Given a bpstat that records zero or more triggered eventpoints, this
3056 function returns another bpstat which contains only the catchpoints
3057 on that first list, if any. */
3059 bpstat_get_triggered_catchpoints (bpstat ep_list
, bpstat
*cp_list
)
3061 struct bpstats root_bs
[1];
3062 bpstat bs
= root_bs
;
3063 struct breakpoint
*ep
;
3066 bpstat_clear (cp_list
);
3067 root_bs
->next
= NULL
;
3069 for (; ep_list
!= NULL
; ep_list
= ep_list
->next
)
3071 /* Is this eventpoint a catchpoint? If not, ignore it. */
3072 ep
= ep_list
->breakpoint_at
;
3075 if ((ep
->type
!= bp_catch_load
) &&
3076 (ep
->type
!= bp_catch_unload
) &&
3077 (ep
->type
!= bp_catch_catch
) &&
3078 (ep
->type
!= bp_catch_throw
))
3079 /* pai: (temp) ADD fork/vfork here!! */
3082 /* Yes; add it to the list. */
3083 bs
= bpstat_alloc (ep
, bs
);
3088 #if defined(SOLIB_ADD)
3089 /* Also, for each triggered catchpoint, tag it with the name of
3090 the library that caused this trigger. (We copy the name now,
3091 because it's only guaranteed to be available NOW, when the
3092 catchpoint triggers. Clients who may wish to know the name
3093 later must get it from the catchpoint itself.) */
3094 if (ep
->triggered_dll_pathname
!= NULL
)
3095 xfree (ep
->triggered_dll_pathname
);
3096 if (ep
->type
== bp_catch_load
)
3097 dll_pathname
= SOLIB_LOADED_LIBRARY_PATHNAME (
3098 PIDGET (inferior_ptid
));
3100 dll_pathname
= SOLIB_UNLOADED_LIBRARY_PATHNAME (
3101 PIDGET (inferior_ptid
));
3103 dll_pathname
= NULL
;
3107 ep
->triggered_dll_pathname
= (char *)
3108 xmalloc (strlen (dll_pathname
) + 1);
3109 strcpy (ep
->triggered_dll_pathname
, dll_pathname
);
3112 ep
->triggered_dll_pathname
= NULL
;
3118 /* Print B to gdb_stdout. */
3120 print_one_breakpoint (struct breakpoint
*b
,
3121 CORE_ADDR
*last_addr
)
3123 register struct command_line
*l
;
3124 register struct symbol
*sym
;
3125 struct ep_type_description
3130 static struct ep_type_description bptypes
[] =
3132 {bp_none
, "?deleted?"},
3133 {bp_breakpoint
, "breakpoint"},
3134 {bp_hardware_breakpoint
, "hw breakpoint"},
3135 {bp_until
, "until"},
3136 {bp_finish
, "finish"},
3137 {bp_watchpoint
, "watchpoint"},
3138 {bp_hardware_watchpoint
, "hw watchpoint"},
3139 {bp_read_watchpoint
, "read watchpoint"},
3140 {bp_access_watchpoint
, "acc watchpoint"},
3141 {bp_longjmp
, "longjmp"},
3142 {bp_longjmp_resume
, "longjmp resume"},
3143 {bp_step_resume
, "step resume"},
3144 {bp_through_sigtramp
, "sigtramp"},
3145 {bp_watchpoint_scope
, "watchpoint scope"},
3146 {bp_call_dummy
, "call dummy"},
3147 {bp_shlib_event
, "shlib events"},
3148 {bp_thread_event
, "thread events"},
3149 {bp_overlay_event
, "overlay events"},
3150 {bp_catch_load
, "catch load"},
3151 {bp_catch_unload
, "catch unload"},
3152 {bp_catch_fork
, "catch fork"},
3153 {bp_catch_vfork
, "catch vfork"},
3154 {bp_catch_exec
, "catch exec"},
3155 {bp_catch_catch
, "catch catch"},
3156 {bp_catch_throw
, "catch throw"}
3159 static char *bpdisps
[] =
3160 {"del", "dstp", "dis", "keep"};
3161 static char bpenables
[] = "nynny";
3162 char wrap_indent
[80];
3163 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
3164 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
3167 ui_out_tuple_begin (uiout
, "bkpt");
3171 ui_out_field_int (uiout
, "number", b
->number
);
3175 if (((int) b
->type
> (sizeof (bptypes
) / sizeof (bptypes
[0])))
3176 || ((int) b
->type
!= bptypes
[(int) b
->type
].type
))
3177 internal_error (__FILE__
, __LINE__
,
3178 "bptypes table does not describe type #%d.",
3180 ui_out_field_string (uiout
, "type", bptypes
[(int) b
->type
].description
);
3184 ui_out_field_string (uiout
, "disp", bpdisps
[(int) b
->disposition
]);
3188 ui_out_field_fmt (uiout
, "enabled", "%c", bpenables
[(int) b
->enable_state
]);
3189 ui_out_spaces (uiout
, 2);
3192 strcpy (wrap_indent
, " ");
3195 if (TARGET_ADDR_BIT
<= 32)
3196 strcat (wrap_indent
, " ");
3198 strcat (wrap_indent
, " ");
3203 internal_error (__FILE__
, __LINE__
,
3204 "print_one_breakpoint: bp_none encountered\n");
3208 case bp_hardware_watchpoint
:
3209 case bp_read_watchpoint
:
3210 case bp_access_watchpoint
:
3211 /* Field 4, the address, is omitted (which makes the columns
3212 not line up too nicely with the headers, but the effect
3213 is relatively readable). */
3215 ui_out_field_skip (uiout
, "addr");
3217 print_expression (b
->exp
, stb
->stream
);
3218 ui_out_field_stream (uiout
, "what", stb
);
3222 case bp_catch_unload
:
3223 /* Field 4, the address, is omitted (which makes the columns
3224 not line up too nicely with the headers, but the effect
3225 is relatively readable). */
3227 ui_out_field_skip (uiout
, "addr");
3229 if (b
->dll_pathname
== NULL
)
3231 ui_out_field_string (uiout
, "what", "<any library>");
3232 ui_out_spaces (uiout
, 1);
3236 ui_out_text (uiout
, "library \"");
3237 ui_out_field_string (uiout
, "what", b
->dll_pathname
);
3238 ui_out_text (uiout
, "\" ");
3243 case bp_catch_vfork
:
3244 /* Field 4, the address, is omitted (which makes the columns
3245 not line up too nicely with the headers, but the effect
3246 is relatively readable). */
3248 ui_out_field_skip (uiout
, "addr");
3250 if (b
->forked_inferior_pid
!= 0)
3252 ui_out_text (uiout
, "process ");
3253 ui_out_field_int (uiout
, "what", b
->forked_inferior_pid
);
3254 ui_out_spaces (uiout
, 1);
3258 /* Field 4, the address, is omitted (which makes the columns
3259 not line up too nicely with the headers, but the effect
3260 is relatively readable). */
3262 ui_out_field_skip (uiout
, "addr");
3264 if (b
->exec_pathname
!= NULL
)
3266 ui_out_text (uiout
, "program \"");
3267 ui_out_field_string (uiout
, "what", b
->exec_pathname
);
3268 ui_out_text (uiout
, "\" ");
3272 case bp_catch_catch
:
3273 /* Field 4, the address, is omitted (which makes the columns
3274 not line up too nicely with the headers, but the effect
3275 is relatively readable). */
3277 ui_out_field_skip (uiout
, "addr");
3279 ui_out_field_string (uiout
, "what", "exception catch");
3280 ui_out_spaces (uiout
, 1);
3283 case bp_catch_throw
:
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 ui_out_field_string (uiout
, "what", "exception throw");
3291 ui_out_spaces (uiout
, 1);
3295 case bp_hardware_breakpoint
:
3299 case bp_longjmp_resume
:
3300 case bp_step_resume
:
3301 case bp_through_sigtramp
:
3302 case bp_watchpoint_scope
:
3304 case bp_shlib_event
:
3305 case bp_thread_event
:
3306 case bp_overlay_event
:
3310 ui_out_field_core_addr (uiout
, "addr", b
->address
);
3313 *last_addr
= b
->address
;
3316 sym
= find_pc_sect_function (b
->address
, b
->section
);
3319 ui_out_text (uiout
, "in ");
3320 ui_out_field_string (uiout
, "func",
3321 SYMBOL_SOURCE_NAME (sym
));
3322 ui_out_wrap_hint (uiout
, wrap_indent
);
3323 ui_out_text (uiout
, " at ");
3325 ui_out_field_string (uiout
, "file", b
->source_file
);
3326 ui_out_text (uiout
, ":");
3327 ui_out_field_int (uiout
, "line", b
->line_number
);
3331 print_address_symbolic (b
->address
, stb
->stream
, demangle
, "");
3332 ui_out_field_stream (uiout
, "at", stb
);
3337 if (b
->thread
!= -1)
3339 /* FIXME: This seems to be redundant and lost here; see the
3340 "stop only in" line a little further down. */
3341 ui_out_text (uiout
, " thread ");
3342 ui_out_field_int (uiout
, "thread", b
->thread
);
3345 ui_out_text (uiout
, "\n");
3350 ui_out_text (uiout
, "\tstop only in stack frame at ");
3351 ui_out_field_core_addr (uiout
, "frame", b
->frame
);
3352 ui_out_text (uiout
, "\n");
3358 ui_out_text (uiout
, "\tstop only if ");
3359 print_expression (b
->cond
, stb
->stream
);
3360 ui_out_field_stream (uiout
, "cond", stb
);
3361 ui_out_text (uiout
, "\n");
3364 if (b
->thread
!= -1)
3366 /* FIXME should make an annotation for this */
3367 ui_out_text (uiout
, "\tstop only in thread ");
3368 ui_out_field_int (uiout
, "thread", b
->thread
);
3369 ui_out_text (uiout
, "\n");
3372 if (show_breakpoint_hit_counts
&& b
->hit_count
)
3374 /* FIXME should make an annotation for this */
3375 if (ep_is_catchpoint (b
))
3376 ui_out_text (uiout
, "\tcatchpoint");
3378 ui_out_text (uiout
, "\tbreakpoint");
3379 ui_out_text (uiout
, " already hit ");
3380 ui_out_field_int (uiout
, "times", b
->hit_count
);
3381 if (b
->hit_count
== 1)
3382 ui_out_text (uiout
, " time\n");
3384 ui_out_text (uiout
, " times\n");
3387 /* Output the count also if it is zero, but only if this is
3388 mi. FIXME: Should have a better test for this. */
3389 if (ui_out_is_mi_like_p (uiout
))
3390 if (show_breakpoint_hit_counts
&& b
->hit_count
== 0)
3391 ui_out_field_int (uiout
, "times", b
->hit_count
);
3393 if (b
->ignore_count
)
3396 ui_out_text (uiout
, "\tignore next ");
3397 ui_out_field_int (uiout
, "ignore", b
->ignore_count
);
3398 ui_out_text (uiout
, " hits\n");
3401 if ((l
= b
->commands
))
3404 ui_out_tuple_begin (uiout
, "script");
3405 print_command_lines (uiout
, l
, 4);
3406 ui_out_tuple_end (uiout
);
3408 ui_out_tuple_end (uiout
);
3409 do_cleanups (old_chain
);
3412 struct captured_breakpoint_query_args
3418 do_captured_breakpoint_query (struct ui_out
*uiout
, void *data
)
3420 struct captured_breakpoint_query_args
*args
= data
;
3421 register struct breakpoint
*b
;
3422 CORE_ADDR dummy_addr
= 0;
3425 if (args
->bnum
== b
->number
)
3427 print_one_breakpoint (b
, &dummy_addr
);
3435 gdb_breakpoint_query (struct ui_out
*uiout
, int bnum
)
3437 struct captured_breakpoint_query_args args
;
3439 /* For the moment we don't trust print_one_breakpoint() to not throw
3441 return catch_exceptions (uiout
, do_captured_breakpoint_query
, &args
,
3442 NULL
, RETURN_MASK_ALL
);
3445 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3446 catchpoints, et.al.). */
3449 user_settable_breakpoint (const struct breakpoint
*b
)
3451 return (b
->type
== bp_breakpoint
3452 || b
->type
== bp_catch_load
3453 || b
->type
== bp_catch_unload
3454 || b
->type
== bp_catch_fork
3455 || b
->type
== bp_catch_vfork
3456 || b
->type
== bp_catch_exec
3457 || b
->type
== bp_catch_catch
3458 || b
->type
== bp_catch_throw
3459 || b
->type
== bp_hardware_breakpoint
3460 || b
->type
== bp_watchpoint
3461 || b
->type
== bp_read_watchpoint
3462 || b
->type
== bp_access_watchpoint
3463 || b
->type
== bp_hardware_watchpoint
);
3466 /* Print information on user settable breakpoint (watchpoint, etc)
3467 number BNUM. If BNUM is -1 print all user settable breakpoints.
3468 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3471 breakpoint_1 (int bnum
, int allflag
)
3473 register struct breakpoint
*b
;
3474 CORE_ADDR last_addr
= (CORE_ADDR
) -1;
3475 int nr_printable_breakpoints
;
3477 /* Compute the number of rows in the table. */
3478 nr_printable_breakpoints
= 0;
3481 || bnum
== b
->number
)
3483 if (allflag
|| user_settable_breakpoint (b
))
3484 nr_printable_breakpoints
++;
3488 ui_out_table_begin (uiout
, 6, nr_printable_breakpoints
, "BreakpointTable");
3490 ui_out_table_begin (uiout
, 5, nr_printable_breakpoints
, "BreakpointTable");
3492 if (nr_printable_breakpoints
> 0)
3493 annotate_breakpoints_headers ();
3494 if (nr_printable_breakpoints
> 0)
3496 ui_out_table_header (uiout
, 3, ui_left
, "number", "Num"); /* 1 */
3497 if (nr_printable_breakpoints
> 0)
3499 ui_out_table_header (uiout
, 14, ui_left
, "type", "Type"); /* 2 */
3500 if (nr_printable_breakpoints
> 0)
3502 ui_out_table_header (uiout
, 4, ui_left
, "disp", "Disp"); /* 3 */
3503 if (nr_printable_breakpoints
> 0)
3505 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb"); /* 4 */
3508 if (nr_printable_breakpoints
> 0)
3510 if (TARGET_ADDR_BIT
<= 32)
3511 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");/* 5 */
3513 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");/* 5 */
3515 if (nr_printable_breakpoints
> 0)
3517 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What"); /* 6 */
3518 ui_out_table_body (uiout
);
3519 if (nr_printable_breakpoints
> 0)
3520 annotate_breakpoints_table ();
3524 || bnum
== b
->number
)
3526 /* We only print out user settable breakpoints unless the
3528 if (allflag
|| user_settable_breakpoint (b
))
3529 print_one_breakpoint (b
, &last_addr
);
3532 ui_out_table_end (uiout
);
3534 if (nr_printable_breakpoints
== 0)
3537 ui_out_message (uiout
, 0, "No breakpoints or watchpoints.\n");
3539 ui_out_message (uiout
, 0, "No breakpoint or watchpoint number %d.\n",
3544 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3545 that a comparison of an unsigned with -1 is always false. */
3546 if (last_addr
!= (CORE_ADDR
) -1)
3547 set_next_address (last_addr
);
3550 /* FIXME? Should this be moved up so that it is only called when
3551 there have been breakpoints? */
3552 annotate_breakpoints_table_end ();
3557 breakpoints_info (char *bnum_exp
, int from_tty
)
3562 bnum
= parse_and_eval_long (bnum_exp
);
3564 breakpoint_1 (bnum
, 0);
3569 maintenance_info_breakpoints (char *bnum_exp
, int from_tty
)
3574 bnum
= parse_and_eval_long (bnum_exp
);
3576 breakpoint_1 (bnum
, 1);
3579 /* Print a message describing any breakpoints set at PC. */
3582 describe_other_breakpoints (CORE_ADDR pc
, asection
*section
)
3584 register int others
= 0;
3585 register struct breakpoint
*b
;
3588 if (b
->address
== pc
) /* address match / overlay match */
3589 if (!overlay_debugging
|| b
->section
== section
)
3593 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
3595 if (b
->address
== pc
) /* address match / overlay match */
3596 if (!overlay_debugging
|| b
->section
== section
)
3599 printf_filtered ("%d%s%s ",
3601 ((b
->enable_state
== bp_disabled
||
3602 b
->enable_state
== bp_shlib_disabled
||
3603 b
->enable_state
== bp_call_disabled
)
3605 : b
->enable_state
== bp_permanent
3609 : ((others
== 1) ? " and" : ""));
3611 printf_filtered ("also set at pc ");
3612 print_address_numeric (pc
, 1, gdb_stdout
);
3613 printf_filtered (".\n");
3617 /* Set the default place to put a breakpoint
3618 for the `break' command with no arguments. */
3621 set_default_breakpoint (int valid
, CORE_ADDR addr
, struct symtab
*symtab
,
3624 default_breakpoint_valid
= valid
;
3625 default_breakpoint_address
= addr
;
3626 default_breakpoint_symtab
= symtab
;
3627 default_breakpoint_line
= line
;
3630 /* Return true iff it is meaningful to use the address member of
3631 BPT. For some breakpoint types, the address member is irrelevant
3632 and it makes no sense to attempt to compare it to other addresses
3633 (or use it for any other purpose either).
3635 More specifically, each of the following breakpoint types will always
3636 have a zero valued address and we don't want check_duplicates() to mark
3637 breakpoints of any of these types to be a duplicate of an actual
3638 breakpoint at address zero:
3641 bp_hardware_watchpoint
3643 bp_access_watchpoint
3650 breakpoint_address_is_meaningful (struct breakpoint
*bpt
)
3652 enum bptype type
= bpt
->type
;
3654 return (type
!= bp_watchpoint
3655 && type
!= bp_hardware_watchpoint
3656 && type
!= bp_read_watchpoint
3657 && type
!= bp_access_watchpoint
3658 && type
!= bp_catch_exec
3659 && type
!= bp_longjmp_resume
3660 && type
!= bp_catch_fork
3661 && type
!= bp_catch_vfork
);
3664 /* Rescan breakpoints at the same address and section as BPT,
3665 marking the first one as "first" and any others as "duplicates".
3666 This is so that the bpt instruction is only inserted once.
3667 If we have a permanent breakpoint at the same place as BPT, make
3668 that one the official one, and the rest as duplicates. */
3671 check_duplicates (struct breakpoint
*bpt
)
3673 register struct breakpoint
*b
;
3674 register int count
= 0;
3675 struct breakpoint
*perm_bp
= 0;
3676 CORE_ADDR address
= bpt
->address
;
3677 asection
*section
= bpt
->section
;
3679 if (! breakpoint_address_is_meaningful (bpt
))
3683 if (b
->enable_state
!= bp_disabled
3684 && b
->enable_state
!= bp_shlib_disabled
3685 && b
->enable_state
!= bp_call_disabled
3686 && b
->address
== address
/* address / overlay match */
3687 && (!overlay_debugging
|| b
->section
== section
)
3688 && breakpoint_address_is_meaningful (b
))
3690 /* Have we found a permanent breakpoint? */
3691 if (b
->enable_state
== bp_permanent
)
3698 b
->duplicate
= count
> 1;
3701 /* If we found a permanent breakpoint at this address, go over the
3702 list again and declare all the other breakpoints there to be the
3706 perm_bp
->duplicate
= 0;
3708 /* Permanent breakpoint should always be inserted. */
3709 if (! perm_bp
->inserted
)
3710 internal_error (__FILE__
, __LINE__
,
3711 "allegedly permanent breakpoint is not "
3712 "actually inserted");
3718 internal_error (__FILE__
, __LINE__
,
3719 "another breakpoint was inserted on top of "
3720 "a permanent breakpoint");
3722 if (b
->enable_state
!= bp_disabled
3723 && b
->enable_state
!= bp_shlib_disabled
3724 && b
->enable_state
!= bp_call_disabled
3725 && b
->address
== address
/* address / overlay match */
3726 && (!overlay_debugging
|| b
->section
== section
)
3727 && breakpoint_address_is_meaningful (b
))
3733 /* set_raw_breakpoint() is a low level routine for allocating and
3734 partially initializing a breakpoint of type BPTYPE. The newly
3735 created breakpoint's address, section, source file name, and line
3736 number are provided by SAL. The newly created and partially
3737 initialized breakpoint is added to the breakpoint chain and
3738 is also returned as the value of this function.
3740 It is expected that the caller will complete the initialization of
3741 the newly created breakpoint struct as well as output any status
3742 information regarding the creation of a new breakpoint. In
3743 particular, set_raw_breakpoint() does NOT set the breakpoint
3744 number! Care should be taken to not allow an error() to occur
3745 prior to completing the initialization of the breakpoint. If this
3746 should happen, a bogus breakpoint will be left on the chain. */
3749 set_raw_breakpoint (struct symtab_and_line sal
, enum bptype bptype
)
3751 register struct breakpoint
*b
, *b1
;
3753 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
3754 memset (b
, 0, sizeof (*b
));
3755 b
->address
= sal
.pc
;
3756 if (sal
.symtab
== NULL
)
3757 b
->source_file
= NULL
;
3759 b
->source_file
= savestring (sal
.symtab
->filename
,
3760 strlen (sal
.symtab
->filename
));
3761 b
->section
= sal
.section
;
3763 b
->language
= current_language
->la_language
;
3764 b
->input_radix
= input_radix
;
3766 b
->line_number
= sal
.line
;
3767 b
->enable_state
= bp_enabled
;
3770 b
->ignore_count
= 0;
3773 b
->dll_pathname
= NULL
;
3774 b
->triggered_dll_pathname
= NULL
;
3775 b
->forked_inferior_pid
= 0;
3776 b
->exec_pathname
= NULL
;
3778 /* Add this breakpoint to the end of the chain
3779 so that a list of breakpoints will come out in order
3780 of increasing numbers. */
3782 b1
= breakpoint_chain
;
3784 breakpoint_chain
= b
;
3792 check_duplicates (b
);
3793 breakpoints_changed ();
3799 /* Note that the breakpoint object B describes a permanent breakpoint
3800 instruction, hard-wired into the inferior's code. */
3802 make_breakpoint_permanent (struct breakpoint
*b
)
3804 b
->enable_state
= bp_permanent
;
3806 /* By definition, permanent breakpoints are already present in the code. */
3810 static struct breakpoint
*
3811 create_internal_breakpoint (CORE_ADDR address
, enum bptype type
)
3813 static int internal_breakpoint_number
= -1;
3814 struct symtab_and_line sal
;
3815 struct breakpoint
*b
;
3817 INIT_SAL (&sal
); /* initialize to zeroes */
3820 sal
.section
= find_pc_overlay (sal
.pc
);
3822 b
= set_raw_breakpoint (sal
, type
);
3823 b
->number
= internal_breakpoint_number
--;
3824 b
->disposition
= disp_donttouch
;
3831 create_longjmp_breakpoint (char *func_name
)
3833 struct breakpoint
*b
;
3834 struct minimal_symbol
*m
;
3836 if (func_name
== NULL
)
3837 b
= create_internal_breakpoint (0, bp_longjmp_resume
);
3840 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3843 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
), bp_longjmp
);
3846 b
->enable_state
= bp_disabled
;
3849 b
->addr_string
= xstrdup (func_name
);
3852 /* Call this routine when stepping and nexting to enable a breakpoint
3853 if we do a longjmp(). When we hit that breakpoint, call
3854 set_longjmp_resume_breakpoint() to figure out where we are going. */
3857 enable_longjmp_breakpoint (void)
3859 register struct breakpoint
*b
;
3862 if (b
->type
== bp_longjmp
)
3864 b
->enable_state
= bp_enabled
;
3865 check_duplicates (b
);
3870 disable_longjmp_breakpoint (void)
3872 register struct breakpoint
*b
;
3875 if (b
->type
== bp_longjmp
3876 || b
->type
== bp_longjmp_resume
)
3878 b
->enable_state
= bp_disabled
;
3879 check_duplicates (b
);
3884 create_overlay_event_breakpoint (char *func_name
)
3886 struct breakpoint
*b
;
3887 struct minimal_symbol
*m
;
3889 if ((m
= lookup_minimal_symbol_text (func_name
, NULL
, NULL
)) == NULL
)
3892 b
= create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m
),
3894 b
->addr_string
= xstrdup (func_name
);
3896 if (overlay_debugging
== ovly_auto
)
3898 b
->enable_state
= bp_enabled
;
3899 overlay_events_enabled
= 1;
3903 b
->enable_state
= bp_disabled
;
3904 overlay_events_enabled
= 0;
3909 enable_overlay_breakpoints (void)
3911 register struct breakpoint
*b
;
3914 if (b
->type
== bp_overlay_event
)
3916 b
->enable_state
= bp_enabled
;
3917 check_duplicates (b
);
3918 overlay_events_enabled
= 1;
3923 disable_overlay_breakpoints (void)
3925 register struct breakpoint
*b
;
3928 if (b
->type
== bp_overlay_event
)
3930 b
->enable_state
= bp_disabled
;
3931 check_duplicates (b
);
3932 overlay_events_enabled
= 0;
3937 create_thread_event_breakpoint (CORE_ADDR address
)
3939 struct breakpoint
*b
;
3940 char addr_string
[80]; /* Surely an addr can't be longer than that. */
3942 b
= create_internal_breakpoint (address
, bp_thread_event
);
3944 b
->enable_state
= bp_enabled
;
3945 /* addr_string has to be used or breakpoint_re_set will delete me. */
3946 sprintf (addr_string
, "*0x%s", paddr (b
->address
));
3947 b
->addr_string
= xstrdup (addr_string
);
3953 remove_thread_event_breakpoints (void)
3955 struct breakpoint
*b
, *temp
;
3957 ALL_BREAKPOINTS_SAFE (b
, temp
)
3958 if (b
->type
== bp_thread_event
)
3959 delete_breakpoint (b
);
3964 remove_solib_event_breakpoints (void)
3966 register struct breakpoint
*b
, *temp
;
3968 ALL_BREAKPOINTS_SAFE (b
, temp
)
3969 if (b
->type
== bp_shlib_event
)
3970 delete_breakpoint (b
);
3974 create_solib_event_breakpoint (CORE_ADDR address
)
3976 struct breakpoint
*b
;
3978 b
= create_internal_breakpoint (address
, bp_shlib_event
);
3982 /* Disable any breakpoints that are on code in shared libraries. Only
3983 apply to enabled breakpoints, disabled ones can just stay disabled. */
3986 disable_breakpoints_in_shlibs (int silent
)
3988 struct breakpoint
*b
;
3989 int disabled_shlib_breaks
= 0;
3991 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
3994 #if defined (PC_SOLIB)
3995 if (((b
->type
== bp_breakpoint
) ||
3996 (b
->type
== bp_hardware_breakpoint
)) &&
3997 b
->enable_state
== bp_enabled
&&
3999 PC_SOLIB (b
->address
))
4001 b
->enable_state
= bp_shlib_disabled
;
4004 if (!disabled_shlib_breaks
)
4006 target_terminal_ours_for_output ();
4007 warning ("Temporarily disabling shared library breakpoints:");
4009 disabled_shlib_breaks
= 1;
4010 warning ("breakpoint #%d ", b
->number
);
4017 /* Try to reenable any breakpoints in shared libraries. */
4019 re_enable_breakpoints_in_shlibs (void)
4021 struct breakpoint
*b
;
4024 if (b
->enable_state
== bp_shlib_disabled
)
4028 /* Do not reenable the breakpoint if the shared library
4029 is still not mapped in. */
4030 if (target_read_memory (b
->address
, buf
, 1) == 0)
4031 b
->enable_state
= bp_enabled
;
4038 solib_load_unload_1 (char *hookname
, int tempflag
, char *dll_pathname
,
4039 char *cond_string
, enum bptype bp_kind
)
4041 struct breakpoint
*b
;
4042 struct symtabs_and_lines sals
;
4043 struct cleanup
*old_chain
;
4044 struct cleanup
*canonical_strings_chain
= NULL
;
4045 char *addr_start
= hookname
;
4046 char *addr_end
= NULL
;
4047 char **canonical
= (char **) NULL
;
4048 int thread
= -1; /* All threads. */
4050 /* Set a breakpoint on the specified hook. */
4051 sals
= decode_line_1 (&hookname
, 1, (struct symtab
*) NULL
, 0, &canonical
);
4052 addr_end
= hookname
;
4054 if (sals
.nelts
== 0)
4056 warning ("Unable to set a breakpoint on dynamic linker callback.");
4057 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4058 warning ("GDB will be unable to track shl_load/shl_unload calls");
4061 if (sals
.nelts
!= 1)
4063 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4064 warning ("GDB will be unable to track shl_load/shl_unload calls");
4068 /* Make sure that all storage allocated in decode_line_1 gets freed
4069 in case the following errors out. */
4070 old_chain
= make_cleanup (xfree
, sals
.sals
);
4071 if (canonical
!= (char **) NULL
)
4073 make_cleanup (xfree
, canonical
);
4074 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
4075 if (canonical
[0] != NULL
)
4076 make_cleanup (xfree
, canonical
[0]);
4079 resolve_sal_pc (&sals
.sals
[0]);
4081 /* Remove the canonical strings from the cleanup, they are needed below. */
4082 if (canonical
!= (char **) NULL
)
4083 discard_cleanups (canonical_strings_chain
);
4085 b
= set_raw_breakpoint (sals
.sals
[0], bp_kind
);
4086 set_breakpoint_count (breakpoint_count
+ 1);
4087 b
->number
= breakpoint_count
;
4089 b
->cond_string
= (cond_string
== NULL
) ?
4090 NULL
: savestring (cond_string
, strlen (cond_string
));
4093 if (canonical
!= (char **) NULL
&& canonical
[0] != NULL
)
4094 b
->addr_string
= canonical
[0];
4095 else if (addr_start
)
4096 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
4098 b
->enable_state
= bp_enabled
;
4099 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4101 if (dll_pathname
== NULL
)
4102 b
->dll_pathname
= NULL
;
4105 b
->dll_pathname
= (char *) xmalloc (strlen (dll_pathname
) + 1);
4106 strcpy (b
->dll_pathname
, dll_pathname
);
4110 do_cleanups (old_chain
);
4114 create_solib_load_event_breakpoint (char *hookname
, int tempflag
,
4115 char *dll_pathname
, char *cond_string
)
4117 solib_load_unload_1 (hookname
, tempflag
, dll_pathname
,
4118 cond_string
, bp_catch_load
);
4122 create_solib_unload_event_breakpoint (char *hookname
, int tempflag
,
4123 char *dll_pathname
, char *cond_string
)
4125 solib_load_unload_1 (hookname
,tempflag
, dll_pathname
,
4126 cond_string
, bp_catch_unload
);
4130 create_fork_vfork_event_catchpoint (int tempflag
, char *cond_string
,
4131 enum bptype bp_kind
)
4133 struct symtab_and_line sal
;
4134 struct breakpoint
*b
;
4135 int thread
= -1; /* All threads. */
4142 b
= set_raw_breakpoint (sal
, bp_kind
);
4143 set_breakpoint_count (breakpoint_count
+ 1);
4144 b
->number
= breakpoint_count
;
4146 b
->cond_string
= (cond_string
== NULL
) ?
4147 NULL
: savestring (cond_string
, strlen (cond_string
));
4149 b
->addr_string
= NULL
;
4150 b
->enable_state
= bp_enabled
;
4151 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4152 b
->forked_inferior_pid
= 0;
4158 create_fork_event_catchpoint (int tempflag
, char *cond_string
)
4160 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_fork
);
4164 create_vfork_event_catchpoint (int tempflag
, char *cond_string
)
4166 create_fork_vfork_event_catchpoint (tempflag
, cond_string
, bp_catch_vfork
);
4170 create_exec_event_catchpoint (int tempflag
, char *cond_string
)
4172 struct symtab_and_line sal
;
4173 struct breakpoint
*b
;
4174 int thread
= -1; /* All threads. */
4181 b
= set_raw_breakpoint (sal
, bp_catch_exec
);
4182 set_breakpoint_count (breakpoint_count
+ 1);
4183 b
->number
= breakpoint_count
;
4185 b
->cond_string
= (cond_string
== NULL
) ?
4186 NULL
: savestring (cond_string
, strlen (cond_string
));
4188 b
->addr_string
= NULL
;
4189 b
->enable_state
= bp_enabled
;
4190 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
4196 hw_breakpoint_used_count (void)
4198 register struct breakpoint
*b
;
4203 if (b
->type
== bp_hardware_breakpoint
&& b
->enable_state
== bp_enabled
)
4211 hw_watchpoint_used_count (enum bptype type
, int *other_type_used
)
4213 register struct breakpoint
*b
;
4216 *other_type_used
= 0;
4219 if (b
->enable_state
== bp_enabled
)
4221 if (b
->type
== type
)
4223 else if ((b
->type
== bp_hardware_watchpoint
||
4224 b
->type
== bp_read_watchpoint
||
4225 b
->type
== bp_access_watchpoint
)
4226 && b
->enable_state
== bp_enabled
)
4227 *other_type_used
= 1;
4233 /* Call this after hitting the longjmp() breakpoint. Use this to set
4234 a new breakpoint at the target of the jmp_buf.
4236 FIXME - This ought to be done by setting a temporary breakpoint
4237 that gets deleted automatically... */
4240 set_longjmp_resume_breakpoint (CORE_ADDR pc
, struct frame_info
*frame
)
4242 register struct breakpoint
*b
;
4245 if (b
->type
== bp_longjmp_resume
)
4248 b
->enable_state
= bp_enabled
;
4250 b
->frame
= frame
->frame
;
4253 check_duplicates (b
);
4259 disable_watchpoints_before_interactive_call_start (void)
4261 struct breakpoint
*b
;
4265 if (((b
->type
== bp_watchpoint
)
4266 || (b
->type
== bp_hardware_watchpoint
)
4267 || (b
->type
== bp_read_watchpoint
)
4268 || (b
->type
== bp_access_watchpoint
)
4269 || ep_is_exception_catchpoint (b
))
4270 && (b
->enable_state
== bp_enabled
))
4272 b
->enable_state
= bp_call_disabled
;
4273 check_duplicates (b
);
4279 enable_watchpoints_after_interactive_call_stop (void)
4281 struct breakpoint
*b
;
4285 if (((b
->type
== bp_watchpoint
)
4286 || (b
->type
== bp_hardware_watchpoint
)
4287 || (b
->type
== bp_read_watchpoint
)
4288 || (b
->type
== bp_access_watchpoint
)
4289 || ep_is_exception_catchpoint (b
))
4290 && (b
->enable_state
== bp_call_disabled
))
4292 b
->enable_state
= bp_enabled
;
4293 check_duplicates (b
);
4299 /* Set a breakpoint that will evaporate an end of command
4300 at address specified by SAL.
4301 Restrict it to frame FRAME if FRAME is nonzero. */
4304 set_momentary_breakpoint (struct symtab_and_line sal
, struct frame_info
*frame
,
4307 register struct breakpoint
*b
;
4308 b
= set_raw_breakpoint (sal
, type
);
4309 b
->enable_state
= bp_enabled
;
4310 b
->disposition
= disp_donttouch
;
4311 b
->frame
= (frame
? frame
->frame
: 0);
4313 /* If we're debugging a multi-threaded program, then we
4314 want momentary breakpoints to be active in only a
4315 single thread of control. */
4316 if (in_thread_list (inferior_ptid
))
4317 b
->thread
= pid_to_thread_id (inferior_ptid
);
4323 /* Tell the user we have just set a breakpoint B. */
4326 mention (struct breakpoint
*b
)
4329 struct cleanup
*old_chain
;
4330 struct ui_stream
*stb
;
4332 stb
= ui_out_stream_new (uiout
);
4333 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4335 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4336 watchpoint) other than breakpoint creation. It should be possible to
4337 clean this up and at the same time replace the random calls to
4338 breakpoint_changed with this hook, as has already been done for
4339 delete_breakpoint_hook and so on. */
4340 if (create_breakpoint_hook
)
4341 create_breakpoint_hook (b
);
4342 breakpoint_create_event (b
->number
);
4347 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b
->number
);
4350 ui_out_text (uiout
, "Watchpoint ");
4351 ui_out_tuple_begin (uiout
, "wpt");
4352 ui_out_field_int (uiout
, "number", b
->number
);
4353 ui_out_text (uiout
, ": ");
4354 print_expression (b
->exp
, stb
->stream
);
4355 ui_out_field_stream (uiout
, "exp", stb
);
4356 ui_out_tuple_end (uiout
);
4358 case bp_hardware_watchpoint
:
4359 ui_out_text (uiout
, "Hardware watchpoint ");
4360 ui_out_tuple_begin (uiout
, "wpt");
4361 ui_out_field_int (uiout
, "number", b
->number
);
4362 ui_out_text (uiout
, ": ");
4363 print_expression (b
->exp
, stb
->stream
);
4364 ui_out_field_stream (uiout
, "exp", stb
);
4365 ui_out_tuple_end (uiout
);
4367 case bp_read_watchpoint
:
4368 ui_out_text (uiout
, "Hardware read watchpoint ");
4369 ui_out_tuple_begin (uiout
, "hw-rwpt");
4370 ui_out_field_int (uiout
, "number", b
->number
);
4371 ui_out_text (uiout
, ": ");
4372 print_expression (b
->exp
, stb
->stream
);
4373 ui_out_field_stream (uiout
, "exp", stb
);
4374 ui_out_tuple_end (uiout
);
4376 case bp_access_watchpoint
:
4377 ui_out_text (uiout
, "Hardware access (read/write) watchpoint ");
4378 ui_out_tuple_begin (uiout
, "hw-awpt");
4379 ui_out_field_int (uiout
, "number", b
->number
);
4380 ui_out_text (uiout
, ": ");
4381 print_expression (b
->exp
, stb
->stream
);
4382 ui_out_field_stream (uiout
, "exp", stb
);
4383 ui_out_tuple_end (uiout
);
4386 if (ui_out_is_mi_like_p (uiout
))
4391 printf_filtered ("Breakpoint %d", b
->number
);
4394 case bp_hardware_breakpoint
:
4395 if (ui_out_is_mi_like_p (uiout
))
4400 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
4404 case bp_catch_unload
:
4405 printf_filtered ("Catchpoint %d (%s %s)",
4407 (b
->type
== bp_catch_load
) ? "load" : "unload",
4408 (b
->dll_pathname
!= NULL
) ?
4409 b
->dll_pathname
: "<any library>");
4412 case bp_catch_vfork
:
4413 printf_filtered ("Catchpoint %d (%s)",
4415 (b
->type
== bp_catch_fork
) ? "fork" : "vfork");
4418 printf_filtered ("Catchpoint %d (exec)",
4421 case bp_catch_catch
:
4422 case bp_catch_throw
:
4423 printf_filtered ("Catchpoint %d (%s)",
4425 (b
->type
== bp_catch_catch
) ? "catch" : "throw");
4431 case bp_longjmp_resume
:
4432 case bp_step_resume
:
4433 case bp_through_sigtramp
:
4435 case bp_watchpoint_scope
:
4436 case bp_shlib_event
:
4437 case bp_thread_event
:
4438 case bp_overlay_event
:
4443 if (addressprint
|| b
->source_file
== NULL
)
4445 printf_filtered (" at ");
4446 print_address_numeric (b
->address
, 1, gdb_stdout
);
4449 printf_filtered (": file %s, line %d.",
4450 b
->source_file
, b
->line_number
);
4452 do_cleanups (old_chain
);
4453 if (ui_out_is_mi_like_p (uiout
))
4455 printf_filtered ("\n");
4459 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4460 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4461 COND[i] and COND_STRING[i] values.
4463 NOTE: If the function succeeds, the caller is expected to cleanup
4464 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4465 array contents). If the function fails (error() is called), the
4466 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4467 COND and SALS arrays and each of those arrays contents. */
4470 create_breakpoints (struct symtabs_and_lines sals
, char **addr_string
,
4471 struct expression
**cond
, char **cond_string
,
4472 enum bptype type
, enum bpdisp disposition
,
4473 int thread
, int ignore_count
, int from_tty
)
4475 if (type
== bp_hardware_breakpoint
)
4477 int i
= hw_breakpoint_used_count ();
4478 int target_resources_ok
=
4479 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
4481 if (target_resources_ok
== 0)
4482 error ("No hardware breakpoint support in the target.");
4483 else if (target_resources_ok
< 0)
4484 error ("Hardware breakpoints used exceeds limit.");
4487 /* Now set all the breakpoints. */
4490 for (i
= 0; i
< sals
.nelts
; i
++)
4492 struct breakpoint
*b
;
4493 struct symtab_and_line sal
= sals
.sals
[i
];
4496 describe_other_breakpoints (sal
.pc
, sal
.section
);
4498 b
= set_raw_breakpoint (sal
, type
);
4499 set_breakpoint_count (breakpoint_count
+ 1);
4500 b
->number
= breakpoint_count
;
4503 b
->addr_string
= addr_string
[i
];
4504 b
->cond_string
= cond_string
[i
];
4505 b
->ignore_count
= ignore_count
;
4506 b
->enable_state
= bp_enabled
;
4507 b
->disposition
= disposition
;
4513 /* Parse ARG which is assumed to be a SAL specification possibly
4514 followed by conditionals. On return, SALS contains an array of SAL
4515 addresses found. ADDR_STRING contains a vector of (canonical)
4516 address strings. ARG points to the end of the SAL. */
4519 parse_breakpoint_sals (char **address
,
4520 struct symtabs_and_lines
*sals
,
4521 char ***addr_string
)
4523 char *addr_start
= *address
;
4524 *addr_string
= NULL
;
4525 /* If no arg given, or if first arg is 'if ', use the default
4527 if ((*address
) == NULL
4528 || (strncmp ((*address
), "if", 2) == 0 && isspace ((*address
)[2])))
4530 if (default_breakpoint_valid
)
4532 struct symtab_and_line sal
;
4533 INIT_SAL (&sal
); /* initialize to zeroes */
4534 sals
->sals
= (struct symtab_and_line
*)
4535 xmalloc (sizeof (struct symtab_and_line
));
4536 sal
.pc
= default_breakpoint_address
;
4537 sal
.line
= default_breakpoint_line
;
4538 sal
.symtab
= default_breakpoint_symtab
;
4539 sal
.section
= find_pc_overlay (sal
.pc
);
4540 sals
->sals
[0] = sal
;
4544 error ("No default breakpoint address now.");
4548 /* Force almost all breakpoints to be in terms of the
4549 current_source_symtab (which is decode_line_1's default). This
4550 should produce the results we want almost all of the time while
4551 leaving default_breakpoint_* alone. */
4552 if (default_breakpoint_valid
4553 && (!current_source_symtab
4554 || (strchr ("+-", (*address
)[0]) != NULL
)))
4555 *sals
= decode_line_1 (address
, 1, default_breakpoint_symtab
,
4556 default_breakpoint_line
, addr_string
);
4558 *sals
= decode_line_1 (address
, 1, (struct symtab
*) NULL
, 0, addr_string
);
4560 /* For any SAL that didn't have a canonical string, fill one in. */
4561 if (sals
->nelts
> 0 && *addr_string
== NULL
)
4562 *addr_string
= xcalloc (sals
->nelts
, sizeof (char **));
4563 if (addr_start
!= (*address
))
4566 for (i
= 0; i
< sals
->nelts
; i
++)
4568 /* Add the string if not present. */
4569 if ((*addr_string
)[i
] == NULL
)
4570 (*addr_string
)[i
] = savestring (addr_start
, (*address
) - addr_start
);
4576 /* Convert each SAL into a real PC. Verify that the PC can be
4577 inserted as a breakpoint. If it can't throw an error. */
4580 breakpoint_sals_to_pc (struct symtabs_and_lines
*sals
,
4584 for (i
= 0; i
< sals
->nelts
; i
++)
4586 resolve_sal_pc (&sals
->sals
[i
]);
4588 /* It's possible for the PC to be nonzero, but still an illegal
4589 value on some targets.
4591 For example, on HP-UX if you start gdb, and before running the
4592 inferior you try to set a breakpoint on a shared library function
4593 "foo" where the inferior doesn't call "foo" directly but does
4594 pass its address to another function call, then we do find a
4595 minimal symbol for the "foo", but it's address is invalid.
4596 (Appears to be an index into a table that the loader sets up
4597 when the inferior is run.)
4599 Give the target a chance to bless sals.sals[i].pc before we
4600 try to make a breakpoint for it. */
4601 if (PC_REQUIRES_RUN_BEFORE_USE (sals
->sals
[i
].pc
))
4603 if (address
== NULL
)
4604 error ("Cannot break without a running program.");
4606 error ("Cannot break on %s without a running program.",
4612 /* Set a breakpoint according to ARG (function, linenum or *address)
4613 flag: first bit : 0 non-temporary, 1 temporary.
4614 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4617 break_command_1 (char *arg
, int flag
, int from_tty
)
4619 int tempflag
, hardwareflag
;
4620 struct symtabs_and_lines sals
;
4621 register struct expression
**cond
= 0;
4622 /* Pointers in arg to the start, and one past the end, of the
4624 char **cond_string
= (char **) NULL
;
4625 char *addr_start
= arg
;
4627 struct cleanup
*old_chain
;
4628 struct cleanup
*breakpoint_chain
= NULL
;
4631 int ignore_count
= 0;
4633 hardwareflag
= flag
& BP_HARDWAREFLAG
;
4634 tempflag
= flag
& BP_TEMPFLAG
;
4639 parse_breakpoint_sals (&arg
, &sals
, &addr_string
);
4644 /* Create a chain of things that always need to be cleaned up. */
4645 old_chain
= make_cleanup (null_cleanup
, 0);
4647 /* Make sure that all storage allocated to SALS gets freed. */
4648 make_cleanup (xfree
, sals
.sals
);
4650 /* Cleanup the addr_string array but not its contents. */
4651 make_cleanup (xfree
, addr_string
);
4653 /* Allocate space for all the cond expressions. */
4654 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4655 make_cleanup (xfree
, cond
);
4657 /* Allocate space for all the cond strings. */
4658 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4659 make_cleanup (xfree
, cond_string
);
4661 /* ----------------------------- SNIP -----------------------------
4662 Anything added to the cleanup chain beyond this point is assumed
4663 to be part of a breakpoint. If the breakpoint create succeeds
4664 then the memory is not reclaimed. */
4665 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4667 /* Mark the contents of the addr_string for cleanup. These go on
4668 the breakpoint_chain and only occure if the breakpoint create
4670 for (i
= 0; i
< sals
.nelts
; i
++)
4672 if (addr_string
[i
] != NULL
)
4673 make_cleanup (xfree
, addr_string
[i
]);
4676 /* Resolve all line numbers to PC's and verify that the addresses
4677 are ok for the target. */
4678 breakpoint_sals_to_pc (&sals
, addr_start
);
4680 /* Verify that condition can be parsed, before setting any
4681 breakpoints. Allocate a separate condition expression for each
4683 thread
= -1; /* No specific thread yet */
4684 for (i
= 0; i
< sals
.nelts
; i
++)
4691 char *cond_start
= NULL
;
4692 char *cond_end
= NULL
;
4693 while (*tok
== ' ' || *tok
== '\t')
4698 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
4701 toklen
= end_tok
- tok
;
4703 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
4705 tok
= cond_start
= end_tok
+ 1;
4706 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4707 make_cleanup (xfree
, cond
[i
]);
4709 cond_string
[i
] = savestring (cond_start
, cond_end
- cond_start
);
4710 make_cleanup (xfree
, cond_string
[i
]);
4712 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
4718 thread
= strtol (tok
, &tok
, 0);
4720 error ("Junk after thread keyword.");
4721 if (!valid_thread_id (thread
))
4722 error ("Unknown thread %d\n", thread
);
4725 error ("Junk at end of arguments.");
4729 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4730 hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4731 tempflag
? disp_del
: disp_donttouch
,
4732 thread
, ignore_count
, from_tty
);
4736 warning ("Multiple breakpoints were set.");
4737 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4739 /* That's it. Discard the cleanups for data inserted into the
4741 discard_cleanups (breakpoint_chain
);
4742 /* But cleanup everything else. */
4743 do_cleanups (old_chain
);
4746 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4747 linenum or *address) with COND and IGNORE_COUNT. */
4749 struct captured_breakpoint_args
4760 do_captured_breakpoint (void *data
)
4762 struct captured_breakpoint_args
*args
= data
;
4763 struct symtabs_and_lines sals
;
4764 register struct expression
**cond
;
4765 struct cleanup
*old_chain
;
4766 struct cleanup
*breakpoint_chain
= NULL
;
4773 /* Parse the source and lines spec. Delay check that the expression
4774 didn't contain trailing garbage until after cleanups are in
4778 address_end
= args
->address
;
4780 parse_breakpoint_sals (&address_end
, &sals
, &addr_string
);
4785 /* Create a chain of things at always need to be cleaned up. */
4786 old_chain
= make_cleanup (null_cleanup
, 0);
4788 /* Always have a addr_string array, even if it is empty. */
4789 make_cleanup (xfree
, addr_string
);
4791 /* Make sure that all storage allocated to SALS gets freed. */
4792 make_cleanup (xfree
, sals
.sals
);
4794 /* Allocate space for all the cond expressions. */
4795 cond
= xcalloc (sals
.nelts
, sizeof (struct expression
*));
4796 make_cleanup (xfree
, cond
);
4798 /* Allocate space for all the cond strings. */
4799 cond_string
= xcalloc (sals
.nelts
, sizeof (char **));
4800 make_cleanup (xfree
, cond_string
);
4802 /* ----------------------------- SNIP -----------------------------
4803 Anything added to the cleanup chain beyond this point is assumed
4804 to be part of a breakpoint. If the breakpoint create goes
4805 through then that memory is not cleaned up. */
4806 breakpoint_chain
= make_cleanup (null_cleanup
, 0);
4808 /* Mark the contents of the addr_string for cleanup. These go on
4809 the breakpoint_chain and only occure if the breakpoint create
4811 for (i
= 0; i
< sals
.nelts
; i
++)
4813 if (addr_string
[i
] != NULL
)
4814 make_cleanup (xfree
, addr_string
[i
]);
4817 /* Wait until now before checking for garbage at the end of the
4818 address. That way cleanups can take care of freeing any
4820 if (*address_end
!= '\0')
4821 error ("Garbage %s following breakpoint address", address_end
);
4823 /* Resolve all line numbers to PC's. */
4824 breakpoint_sals_to_pc (&sals
, args
->address
);
4826 /* Verify that conditions can be parsed, before setting any
4828 for (i
= 0; i
< sals
.nelts
; i
++)
4830 if (args
->condition
!= NULL
)
4832 char *tok
= args
->condition
;
4833 cond
[i
] = parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
4835 error ("Garbage %s follows condition", tok
);
4836 make_cleanup (xfree
, cond
[i
]);
4837 cond_string
[i
] = xstrdup (args
->condition
);
4841 create_breakpoints (sals
, addr_string
, cond
, cond_string
,
4842 args
->hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
,
4843 args
->tempflag
? disp_del
: disp_donttouch
,
4844 args
->thread
, args
->ignore_count
, 0/*from-tty*/);
4846 /* That's it. Discard the cleanups for data inserted into the
4848 discard_cleanups (breakpoint_chain
);
4849 /* But cleanup everything else. */
4850 do_cleanups (old_chain
);
4855 gdb_breakpoint (char *address
, char *condition
,
4856 int hardwareflag
, int tempflag
,
4857 int thread
, int ignore_count
)
4859 struct captured_breakpoint_args args
;
4860 args
.address
= address
;
4861 args
.condition
= condition
;
4862 args
.hardwareflag
= hardwareflag
;
4863 args
.tempflag
= tempflag
;
4864 args
.thread
= thread
;
4865 args
.ignore_count
= ignore_count
;
4866 return catch_errors (do_captured_breakpoint
, &args
,
4867 NULL
, RETURN_MASK_ALL
);
4872 break_at_finish_at_depth_command_1 (char *arg
, int flag
, int from_tty
)
4874 struct frame_info
*frame
;
4875 CORE_ADDR low
, high
, selected_pc
= 0;
4876 char *extra_args
= NULL
;
4879 int extra_args_len
= 0, if_arg
= 0;
4882 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4885 if (default_breakpoint_valid
)
4889 selected_pc
= selected_frame
->pc
;
4894 error ("No selected frame.");
4897 error ("No default breakpoint address now.");
4901 extra_args
= strchr (arg
, ' ');
4905 extra_args_len
= strlen (extra_args
);
4906 level_arg
= (char *) xmalloc (extra_args
- arg
);
4907 strncpy (level_arg
, arg
, extra_args
- arg
- 1);
4908 level_arg
[extra_args
- arg
- 1] = '\0';
4912 level_arg
= (char *) xmalloc (strlen (arg
) + 1);
4913 strcpy (level_arg
, arg
);
4916 frame
= parse_frame_specification (level_arg
);
4918 selected_pc
= frame
->pc
;
4925 extra_args_len
= strlen (arg
);
4930 if (find_pc_partial_function (selected_pc
, (char **) NULL
, &low
, &high
))
4932 addr_string
= (char *) xmalloc (26 + extra_args_len
);
4934 sprintf (addr_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
4936 sprintf (addr_string
, "*0x%s", paddr_nz (high
));
4937 break_command_1 (addr_string
, flag
, from_tty
);
4938 xfree (addr_string
);
4941 error ("No function contains the specified address");
4944 error ("Unable to set breakpoint at procedure exit");
4949 break_at_finish_command_1 (char *arg
, int flag
, int from_tty
)
4951 char *addr_string
, *break_string
, *beg_addr_string
;
4952 CORE_ADDR low
, high
;
4953 struct symtabs_and_lines sals
;
4954 struct symtab_and_line sal
;
4955 struct cleanup
*old_chain
;
4956 char *extra_args
= NULL
;
4957 int extra_args_len
= 0;
4961 (arg
[0] == 'i' && arg
[1] == 'f' && (arg
[2] == ' ' || arg
[2] == '\t')))
4963 if (default_breakpoint_valid
)
4967 addr_string
= (char *) xmalloc (15);
4968 sprintf (addr_string
, "*0x%s", paddr_nz (selected_frame
->pc
));
4973 error ("No selected frame.");
4976 error ("No default breakpoint address now.");
4980 addr_string
= (char *) xmalloc (strlen (arg
) + 1);
4981 strcpy (addr_string
, arg
);
4987 extra_args_len
= strlen (arg
);
4991 /* get the stuff after the function name or address */
4992 extra_args
= strchr (arg
, ' ');
4996 extra_args_len
= strlen (extra_args
);
5003 beg_addr_string
= addr_string
;
5004 sals
= decode_line_1 (&addr_string
, 1, (struct symtab
*) NULL
, 0,
5007 xfree (beg_addr_string
);
5008 old_chain
= make_cleanup (xfree
, sals
.sals
);
5009 for (i
= 0; (i
< sals
.nelts
); i
++)
5012 if (find_pc_partial_function (sal
.pc
, (char **) NULL
, &low
, &high
))
5014 break_string
= (char *) xmalloc (extra_args_len
+ 26);
5016 sprintf (break_string
, "*0x%s %s", paddr_nz (high
), extra_args
);
5018 sprintf (break_string
, "*0x%s", paddr_nz (high
));
5019 break_command_1 (break_string
, flag
, from_tty
);
5020 xfree (break_string
);
5023 error ("No function contains the specified address");
5027 warning ("Multiple breakpoints were set.\n");
5028 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5030 do_cleanups (old_chain
);
5034 /* Helper function for break_command_1 and disassemble_command. */
5037 resolve_sal_pc (struct symtab_and_line
*sal
)
5041 if (sal
->pc
== 0 && sal
->symtab
!= NULL
)
5043 if (!find_line_pc (sal
->symtab
, sal
->line
, &pc
))
5044 error ("No line %d in file \"%s\".",
5045 sal
->line
, sal
->symtab
->filename
);
5049 if (sal
->section
== 0 && sal
->symtab
!= NULL
)
5051 struct blockvector
*bv
;
5056 bv
= blockvector_for_pc_sect (sal
->pc
, 0, &index
, sal
->symtab
);
5059 b
= BLOCKVECTOR_BLOCK (bv
, index
);
5060 sym
= block_function (b
);
5063 fixup_symbol_section (sym
, sal
->symtab
->objfile
);
5064 sal
->section
= SYMBOL_BFD_SECTION (sym
);
5068 /* It really is worthwhile to have the section, so we'll just
5069 have to look harder. This case can be executed if we have
5070 line numbers but no functions (as can happen in assembly
5073 struct minimal_symbol
*msym
;
5075 msym
= lookup_minimal_symbol_by_pc (sal
->pc
);
5077 sal
->section
= SYMBOL_BFD_SECTION (msym
);
5084 break_command (char *arg
, int from_tty
)
5086 break_command_1 (arg
, 0, from_tty
);
5090 break_at_finish_command (char *arg
, int from_tty
)
5092 break_at_finish_command_1 (arg
, 0, from_tty
);
5096 break_at_finish_at_depth_command (char *arg
, int from_tty
)
5098 break_at_finish_at_depth_command_1 (arg
, 0, from_tty
);
5102 tbreak_command (char *arg
, int from_tty
)
5104 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5108 tbreak_at_finish_command (char *arg
, int from_tty
)
5110 break_at_finish_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
5114 hbreak_command (char *arg
, int from_tty
)
5116 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
5120 thbreak_command (char *arg
, int from_tty
)
5122 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
5126 stop_command (char *arg
, int from_tty
)
5128 printf_filtered ("Specify the type of breakpoint to set.\n\
5129 Usage: stop in <function | address>\n\
5134 stopin_command (char *arg
, int from_tty
)
5138 if (arg
== (char *) NULL
)
5140 else if (*arg
!= '*')
5145 /* look for a ':'. If this is a line number specification, then
5146 say it is bad, otherwise, it should be an address or
5147 function/method name */
5148 while (*argptr
&& !hasColon
)
5150 hasColon
= (*argptr
== ':');
5155 badInput
= (*argptr
!= ':'); /* Not a class::method */
5157 badInput
= isdigit (*arg
); /* a simple line number */
5161 printf_filtered ("Usage: stop in <function | address>\n");
5163 break_command_1 (arg
, 0, from_tty
);
5167 stopat_command (char *arg
, int from_tty
)
5171 if (arg
== (char *) NULL
|| *arg
== '*') /* no line number */
5178 /* look for a ':'. If there is a '::' then get out, otherwise
5179 it is probably a line number. */
5180 while (*argptr
&& !hasColon
)
5182 hasColon
= (*argptr
== ':');
5187 badInput
= (*argptr
== ':'); /* we have class::method */
5189 badInput
= !isdigit (*arg
); /* not a line number */
5193 printf_filtered ("Usage: stop at <line>\n");
5195 break_command_1 (arg
, 0, from_tty
);
5199 /* accessflag: hw_write: watch write,
5200 hw_read: watch read,
5201 hw_access: watch access (read or write) */
5203 watch_command_1 (char *arg
, int accessflag
, int from_tty
)
5205 struct breakpoint
*b
;
5206 struct symtab_and_line sal
;
5207 struct expression
*exp
;
5208 struct block
*exp_valid_block
;
5209 struct value
*val
, *mark
;
5210 struct frame_info
*frame
;
5211 struct frame_info
*prev_frame
= NULL
;
5212 char *exp_start
= NULL
;
5213 char *exp_end
= NULL
;
5214 char *tok
, *end_tok
;
5216 char *cond_start
= NULL
;
5217 char *cond_end
= NULL
;
5218 struct expression
*cond
= NULL
;
5219 int i
, other_type_used
, target_resources_ok
= 0;
5220 enum bptype bp_type
;
5223 INIT_SAL (&sal
); /* initialize to zeroes */
5225 /* Parse arguments. */
5226 innermost_block
= NULL
;
5228 exp
= parse_exp_1 (&arg
, 0, 0);
5230 exp_valid_block
= innermost_block
;
5231 mark
= value_mark ();
5232 val
= evaluate_expression (exp
);
5233 release_value (val
);
5234 if (VALUE_LAZY (val
))
5235 value_fetch_lazy (val
);
5238 while (*tok
== ' ' || *tok
== '\t')
5242 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
5245 toklen
= end_tok
- tok
;
5246 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
5248 tok
= cond_start
= end_tok
+ 1;
5249 cond
= parse_exp_1 (&tok
, 0, 0);
5253 error ("Junk at end of command.");
5255 if (accessflag
== hw_read
)
5256 bp_type
= bp_read_watchpoint
;
5257 else if (accessflag
== hw_access
)
5258 bp_type
= bp_access_watchpoint
;
5260 bp_type
= bp_hardware_watchpoint
;
5262 mem_cnt
= can_use_hardware_watchpoint (val
);
5263 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
5264 error ("Expression cannot be implemented with read/access watchpoint.");
5267 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
5268 target_resources_ok
=
5269 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type
, i
+ mem_cnt
,
5271 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
5272 error ("Target does not support this type of hardware watchpoint.");
5274 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
5275 error ("Target can only support one kind of HW watchpoint at a time.");
5278 #if defined(HPUXHPPA)
5279 /* On HP-UX if you set a h/w
5280 watchpoint before the "run" command, the inferior dies with a e.g.,
5281 SIGILL once you start it. I initially believed this was due to a
5282 bad interaction between page protection traps and the initial
5283 startup sequence by the dynamic linker.
5285 However, I tried avoiding that by having HP-UX's implementation of
5286 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5287 yet, which forced slow watches before a "run" or "attach", and it
5288 still fails somewhere in the startup code.
5290 Until I figure out what's happening, I'm disallowing watches altogether
5291 before the "run" or "attach" command. We'll tell the user they must
5292 set watches after getting the program started. */
5293 if (!target_has_execution
)
5295 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5298 #endif /* HPUXHPPA */
5300 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5301 watchpoint could not be set. */
5302 if (!mem_cnt
|| target_resources_ok
<= 0)
5303 bp_type
= bp_watchpoint
;
5305 /* Now set up the breakpoint. */
5306 b
= set_raw_breakpoint (sal
, bp_type
);
5307 set_breakpoint_count (breakpoint_count
+ 1);
5308 b
->number
= breakpoint_count
;
5309 b
->disposition
= disp_donttouch
;
5311 b
->exp_valid_block
= exp_valid_block
;
5312 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
5316 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
5320 frame
= block_innermost_frame (exp_valid_block
);
5323 prev_frame
= get_prev_frame (frame
);
5324 b
->watchpoint_frame
= frame
->frame
;
5327 b
->watchpoint_frame
= (CORE_ADDR
) 0;
5329 /* If the expression is "local", then set up a "watchpoint scope"
5330 breakpoint at the point where we've left the scope of the watchpoint
5332 if (innermost_block
)
5336 struct breakpoint
*scope_breakpoint
;
5337 struct symtab_and_line scope_sal
;
5339 INIT_SAL (&scope_sal
); /* initialize to zeroes */
5340 scope_sal
.pc
= get_frame_pc (prev_frame
);
5341 scope_sal
.section
= find_pc_overlay (scope_sal
.pc
);
5343 scope_breakpoint
= set_raw_breakpoint (scope_sal
,
5344 bp_watchpoint_scope
);
5345 set_breakpoint_count (breakpoint_count
+ 1);
5346 scope_breakpoint
->number
= breakpoint_count
;
5348 scope_breakpoint
->enable_state
= bp_enabled
;
5350 /* Automatically delete the breakpoint when it hits. */
5351 scope_breakpoint
->disposition
= disp_del
;
5353 /* Only break in the proper frame (help with recursion). */
5354 scope_breakpoint
->frame
= prev_frame
->frame
;
5356 /* Set the address at which we will stop. */
5357 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
5359 /* The scope breakpoint is related to the watchpoint. We
5360 will need to act on them together. */
5361 b
->related_breakpoint
= scope_breakpoint
;
5364 value_free_to_mark (mark
);
5368 /* Return count of locations need to be watched and can be handled
5369 in hardware. If the watchpoint can not be handled
5370 in hardware return zero. */
5372 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5373 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5374 ((BYTE_SIZE) <= (REGISTER_SIZE))
5377 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5378 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5379 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5383 can_use_hardware_watchpoint (struct value
*v
)
5385 int found_memory_cnt
= 0;
5386 struct value
*head
= v
;
5388 /* Did the user specifically forbid us to use hardware watchpoints? */
5389 if (!can_use_hw_watchpoints
)
5392 /* Make sure that the value of the expression depends only upon
5393 memory contents, and values computed from them within GDB. If we
5394 find any register references or function calls, we can't use a
5395 hardware watchpoint.
5397 The idea here is that evaluating an expression generates a series
5398 of values, one holding the value of every subexpression. (The
5399 expression a*b+c has five subexpressions: a, b, a*b, c, and
5400 a*b+c.) GDB's values hold almost enough information to establish
5401 the criteria given above --- they identify memory lvalues,
5402 register lvalues, computed values, etcetera. So we can evaluate
5403 the expression, and then scan the chain of values that leaves
5404 behind to decide whether we can detect any possible change to the
5405 expression's final value using only hardware watchpoints.
5407 However, I don't think that the values returned by inferior
5408 function calls are special in any way. So this function may not
5409 notice that an expression involving an inferior function call
5410 can't be watched with hardware watchpoints. FIXME. */
5411 for (; v
; v
= v
->next
)
5413 if (VALUE_LVAL (v
) == lval_memory
)
5416 /* A lazy memory lvalue is one that GDB never needed to fetch;
5417 we either just used its address (e.g., `a' in `a.b') or
5418 we never needed it at all (e.g., `a' in `a,b'). */
5422 /* Ahh, memory we actually used! Check if we can cover
5423 it with hardware watchpoints. */
5424 struct type
*vtype
= check_typedef (VALUE_TYPE (v
));
5426 /* We only watch structs and arrays if user asked for it
5427 explicitly, never if they just happen to appear in a
5428 middle of some value chain. */
5430 || (TYPE_CODE (vtype
) != TYPE_CODE_STRUCT
5431 && TYPE_CODE (vtype
) != TYPE_CODE_ARRAY
))
5433 CORE_ADDR vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
5434 int len
= TYPE_LENGTH (VALUE_TYPE (v
));
5436 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr
, len
))
5443 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
5444 return 0; /* ??? What does this represent? */
5445 else if (v
->lval
== lval_register
)
5446 return 0; /* cannot watch a register with a HW watchpoint */
5449 /* The expression itself looks suitable for using a hardware
5450 watchpoint, but give the target machine a chance to reject it. */
5451 return found_memory_cnt
;
5455 watch_command_wrapper (char *arg
, int from_tty
)
5457 watch_command (arg
, from_tty
);
5461 watch_command (char *arg
, int from_tty
)
5463 watch_command_1 (arg
, hw_write
, from_tty
);
5467 rwatch_command_wrapper (char *arg
, int from_tty
)
5469 rwatch_command (arg
, from_tty
);
5473 rwatch_command (char *arg
, int from_tty
)
5475 watch_command_1 (arg
, hw_read
, from_tty
);
5479 awatch_command_wrapper (char *arg
, int from_tty
)
5481 awatch_command (arg
, from_tty
);
5485 awatch_command (char *arg
, int from_tty
)
5487 watch_command_1 (arg
, hw_access
, from_tty
);
5491 /* Helper routines for the until_command routine in infcmd.c. Here
5492 because it uses the mechanisms of breakpoints. */
5494 /* This function is called by fetch_inferior_event via the
5495 cmd_continuation pointer, to complete the until command. It takes
5496 care of cleaning up the temporary breakpoints set up by the until
5499 until_break_command_continuation (struct continuation_arg
*arg
)
5501 struct cleanup
*cleanups
;
5503 cleanups
= (struct cleanup
*) arg
->data
.pointer
;
5504 do_exec_cleanups (cleanups
);
5509 until_break_command (char *arg
, int from_tty
)
5511 struct symtabs_and_lines sals
;
5512 struct symtab_and_line sal
;
5513 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
5514 struct breakpoint
*breakpoint
;
5515 struct cleanup
*old_chain
;
5516 struct continuation_arg
*arg1
;
5519 clear_proceed_status ();
5521 /* Set a breakpoint where the user wants it and at return from
5524 if (default_breakpoint_valid
)
5525 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
5526 default_breakpoint_line
, (char ***) NULL
);
5528 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
5529 0, (char ***) NULL
);
5531 if (sals
.nelts
!= 1)
5532 error ("Couldn't get information on specified line.");
5535 xfree (sals
.sals
); /* malloc'd, so freed */
5538 error ("Junk at end of arguments.");
5540 resolve_sal_pc (&sal
);
5542 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
5544 if (!event_loop_p
|| !target_can_async_p ())
5545 old_chain
= make_cleanup_delete_breakpoint (breakpoint
);
5547 old_chain
= make_exec_cleanup_delete_breakpoint (breakpoint
);
5549 /* If we are running asynchronously, and the target supports async
5550 execution, we are not waiting for the target to stop, in the call
5551 tp proceed, below. This means that we cannot delete the
5552 brekpoints until the target has actually stopped. The only place
5553 where we get a chance to do that is in fetch_inferior_event, so
5554 we must set things up for that. */
5556 if (event_loop_p
&& target_can_async_p ())
5558 /* In this case the arg for the continuation is just the point
5559 in the exec_cleanups chain from where to start doing
5560 cleanups, because all the continuation does is the cleanups in
5561 the exec_cleanup_chain. */
5563 (struct continuation_arg
*) xmalloc (sizeof (struct continuation_arg
));
5565 arg1
->data
.pointer
= old_chain
;
5567 add_continuation (until_break_command_continuation
, arg1
);
5570 /* Keep within the current frame */
5574 sal
= find_pc_line (prev_frame
->pc
, 0);
5575 sal
.pc
= prev_frame
->pc
;
5576 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
5577 if (!event_loop_p
|| !target_can_async_p ())
5578 make_cleanup_delete_breakpoint (breakpoint
);
5580 make_exec_cleanup_delete_breakpoint (breakpoint
);
5583 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
5584 /* Do the cleanups now, anly if we are not running asynchronously,
5585 of if we are, but the target is still synchronous. */
5586 if (!event_loop_p
|| !target_can_async_p ())
5587 do_cleanups (old_chain
);
5591 /* These aren't used; I don't konw what they were for. */
5592 /* Set a breakpoint at the catch clause for NAME. */
5594 catch_breakpoint (char *name
)
5599 disable_catch_breakpoint (void)
5604 delete_catch_breakpoint (void)
5609 enable_catch_breakpoint (void)
5616 struct sal_chain
*next
;
5617 struct symtab_and_line sal
;
5621 /* Not really used -- invocation in handle_gnu_4_16_catch_command
5622 had been commented out in the v.4.16 sources, and stays
5623 disabled there now because "catch NAME" syntax isn't allowed.
5625 /* This isn't used; I don't know what it was for. */
5626 /* For each catch clause identified in ARGS, run FUNCTION
5627 with that clause as an argument. */
5628 static struct symtabs_and_lines
5629 map_catch_names (char *args
, int (*function
) ())
5631 register char *p
= args
;
5633 struct symtabs_and_lines sals
;
5635 struct sal_chain
*sal_chain
= 0;
5639 error_no_arg ("one or more catch names");
5647 /* Don't swallow conditional part. */
5648 if (p1
[0] == 'i' && p1
[1] == 'f'
5649 && (p1
[2] == ' ' || p1
[2] == '\t'))
5655 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
5659 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
5660 error ("Arguments must be catch names.");
5666 struct sal_chain
*next
= (struct sal_chain
*)
5667 alloca (sizeof (struct sal_chain
));
5668 next
->next
= sal_chain
;
5669 next
->sal
= get_catch_sal (p
);
5674 printf_unfiltered ("No catch clause for exception %s.\n", p
);
5679 while (*p
== ' ' || *p
== '\t')
5685 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
5687 static struct symtabs_and_lines
5688 get_catch_sals (int this_level_only
)
5690 register struct blockvector
*bl
;
5691 register struct block
*block
;
5692 int index
, have_default
= 0;
5694 struct symtabs_and_lines sals
;
5695 struct sal_chain
*sal_chain
= 0;
5696 char *blocks_searched
;
5698 /* Not sure whether an error message is always the correct response,
5699 but it's better than a core dump. */
5700 if (selected_frame
== NULL
)
5701 error ("No selected frame.");
5702 block
= get_frame_block (selected_frame
, 0);
5703 pc
= selected_frame
->pc
;
5709 error ("No symbol table info available.\n");
5711 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
5712 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5713 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
5717 CORE_ADDR end
= BLOCK_END (block
) - 4;
5720 if (bl
!= blockvector_for_pc (end
, &index
))
5721 error ("blockvector blotch");
5722 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
5723 error ("blockvector botch");
5724 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
5727 /* Don't print out blocks that have gone by. */
5728 while (index
< last_index
5729 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
5732 while (index
< last_index
5733 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
5735 if (blocks_searched
[index
] == 0)
5737 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
5739 register struct symbol
*sym
;
5741 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
5743 if (STREQ (SYMBOL_NAME (sym
), "default"))
5749 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
5751 struct sal_chain
*next
= (struct sal_chain
*)
5752 alloca (sizeof (struct sal_chain
));
5753 next
->next
= sal_chain
;
5754 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
),
5759 blocks_searched
[index
] = 1;
5765 if (sal_chain
&& this_level_only
)
5768 /* After handling the function's top-level block, stop.
5769 Don't continue to its superblock, the block of
5770 per-file symbols. */
5771 if (BLOCK_FUNCTION (block
))
5773 block
= BLOCK_SUPERBLOCK (block
);
5778 struct sal_chain
*tmp_chain
;
5780 /* Count the number of entries. */
5781 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
5782 tmp_chain
= tmp_chain
->next
)
5786 sals
.sals
= (struct symtab_and_line
*)
5787 xmalloc (index
* sizeof (struct symtab_and_line
));
5788 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
5789 sals
.sals
[index
] = sal_chain
->sal
;
5796 ep_skip_leading_whitespace (char **s
)
5798 if ((s
== NULL
) || (*s
== NULL
))
5800 while (isspace (**s
))
5804 /* This function examines a string, and attempts to find a token
5805 that might be an event name in the leading characters. If a
5806 possible match is found, a pointer to the last character of
5807 the token is returned. Else, NULL is returned. */
5810 ep_find_event_name_end (char *arg
)
5813 char *event_name_end
= NULL
;
5815 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5819 /* We break out of the loop when we find a token delimiter.
5820 Basically, we're looking for alphanumerics and underscores;
5821 anything else delimites the token. */
5824 if (!isalnum (*s
) && (*s
!= '_'))
5830 return event_name_end
;
5834 /* This function attempts to parse an optional "if <cond>" clause
5835 from the arg string. If one is not found, it returns NULL.
5837 Else, it returns a pointer to the condition string. (It does not
5838 attempt to evaluate the string against a particular block.) And,
5839 it updates arg to point to the first character following the parsed
5840 if clause in the arg string. */
5843 ep_parse_optional_if_clause (char **arg
)
5847 if (((*arg
)[0] != 'i') || ((*arg
)[1] != 'f') || !isspace ((*arg
)[2]))
5850 /* Skip the "if" keyword. */
5853 /* Skip any extra leading whitespace, and record the start of the
5854 condition string. */
5855 ep_skip_leading_whitespace (arg
);
5858 /* Assume that the condition occupies the remainder of the arg string. */
5859 (*arg
) += strlen (cond_string
);
5864 /* This function attempts to parse an optional filename from the arg
5865 string. If one is not found, it returns NULL.
5867 Else, it returns a pointer to the parsed filename. (This function
5868 makes no attempt to verify that a file of that name exists, or is
5869 accessible.) And, it updates arg to point to the first character
5870 following the parsed filename in the arg string.
5872 Note that clients needing to preserve the returned filename for
5873 future access should copy it to their own buffers. */
5875 ep_parse_optional_filename (char **arg
)
5877 static char filename
[1024];
5882 if ((*arg_p
== '\0') || isspace (*arg_p
))
5900 /* Commands to deal with catching events, such as signals, exceptions,
5901 process start/exit, etc. */
5905 catch_fork
, catch_vfork
5909 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5910 static void catch_fork_command_1 (catch_fork_kind fork_kind
,
5911 char *arg
, int tempflag
, int from_tty
);
5914 catch_fork_command_1 (catch_fork_kind fork_kind
, char *arg
, int tempflag
,
5917 char *cond_string
= NULL
;
5919 ep_skip_leading_whitespace (&arg
);
5921 /* The allowed syntax is:
5923 catch [v]fork if <cond>
5925 First, check if there's an if clause. */
5926 cond_string
= ep_parse_optional_if_clause (&arg
);
5928 if ((*arg
!= '\0') && !isspace (*arg
))
5929 error ("Junk at end of arguments.");
5931 /* If this target supports it, create a fork or vfork catchpoint
5932 and enable reporting of such events. */
5936 create_fork_event_catchpoint (tempflag
, cond_string
);
5939 create_vfork_event_catchpoint (tempflag
, cond_string
);
5942 error ("unsupported or unknown fork kind; cannot catch it");
5948 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5950 catch_exec_command_1 (char *arg
, int tempflag
, int from_tty
)
5952 char *cond_string
= NULL
;
5954 ep_skip_leading_whitespace (&arg
);
5956 /* The allowed syntax is:
5958 catch exec if <cond>
5960 First, check if there's an if clause. */
5961 cond_string
= ep_parse_optional_if_clause (&arg
);
5963 if ((*arg
!= '\0') && !isspace (*arg
))
5964 error ("Junk at end of arguments.");
5966 /* If this target supports it, create an exec catchpoint
5967 and enable reporting of such events. */
5968 create_exec_event_catchpoint (tempflag
, cond_string
);
5972 #if defined(SOLIB_ADD)
5974 catch_load_command_1 (char *arg
, int tempflag
, int from_tty
)
5976 char *dll_pathname
= NULL
;
5977 char *cond_string
= NULL
;
5979 ep_skip_leading_whitespace (&arg
);
5981 /* The allowed syntax is:
5983 catch load if <cond>
5984 catch load <filename>
5985 catch load <filename> if <cond>
5987 The user is not allowed to specify the <filename> after an
5990 We'll ignore the pathological case of a file named "if".
5992 First, check if there's an if clause. If so, then there
5993 cannot be a filename. */
5994 cond_string
= ep_parse_optional_if_clause (&arg
);
5996 /* If there was an if clause, then there cannot be a filename.
5997 Else, there might be a filename and an if clause. */
5998 if (cond_string
== NULL
)
6000 dll_pathname
= ep_parse_optional_filename (&arg
);
6001 ep_skip_leading_whitespace (&arg
);
6002 cond_string
= ep_parse_optional_if_clause (&arg
);
6005 if ((*arg
!= '\0') && !isspace (*arg
))
6006 error ("Junk at end of arguments.");
6008 /* Create a load breakpoint that only triggers when a load of
6009 the specified dll (or any dll, if no pathname was specified)
6011 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6012 dll_pathname
, cond_string
);
6016 catch_unload_command_1 (char *arg
, int tempflag
, int from_tty
)
6018 char *dll_pathname
= NULL
;
6019 char *cond_string
= NULL
;
6021 ep_skip_leading_whitespace (&arg
);
6023 /* The allowed syntax is:
6025 catch unload if <cond>
6026 catch unload <filename>
6027 catch unload <filename> if <cond>
6029 The user is not allowed to specify the <filename> after an
6032 We'll ignore the pathological case of a file named "if".
6034 First, check if there's an if clause. If so, then there
6035 cannot be a filename. */
6036 cond_string
= ep_parse_optional_if_clause (&arg
);
6038 /* If there was an if clause, then there cannot be a filename.
6039 Else, there might be a filename and an if clause. */
6040 if (cond_string
== NULL
)
6042 dll_pathname
= ep_parse_optional_filename (&arg
);
6043 ep_skip_leading_whitespace (&arg
);
6044 cond_string
= ep_parse_optional_if_clause (&arg
);
6047 if ((*arg
!= '\0') && !isspace (*arg
))
6048 error ("Junk at end of arguments.");
6050 /* Create an unload breakpoint that only triggers when an unload of
6051 the specified dll (or any dll, if no pathname was specified)
6053 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid
), tempflag
,
6054 dll_pathname
, cond_string
);
6056 #endif /* SOLIB_ADD */
6058 /* Commands to deal with catching exceptions. */
6060 /* Set a breakpoint at the specified callback routine for an
6061 exception event callback */
6064 create_exception_catchpoint (int tempflag
, char *cond_string
,
6065 enum exception_event_kind ex_event
,
6066 struct symtab_and_line
*sal
)
6068 struct breakpoint
*b
;
6069 int thread
= -1; /* All threads. */
6072 if (!sal
) /* no exception support? */
6077 case EX_EVENT_THROW
:
6078 bptype
= bp_catch_throw
;
6080 case EX_EVENT_CATCH
:
6081 bptype
= bp_catch_catch
;
6083 default: /* error condition */
6084 error ("Internal error -- invalid catchpoint kind");
6087 b
= set_raw_breakpoint (*sal
, bptype
);
6088 set_breakpoint_count (breakpoint_count
+ 1);
6089 b
->number
= breakpoint_count
;
6091 b
->cond_string
= (cond_string
== NULL
) ?
6092 NULL
: savestring (cond_string
, strlen (cond_string
));
6094 b
->addr_string
= NULL
;
6095 b
->enable_state
= bp_enabled
;
6096 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6100 /* Deal with "catch catch" and "catch throw" commands */
6103 catch_exception_command_1 (enum exception_event_kind ex_event
, char *arg
,
6104 int tempflag
, int from_tty
)
6106 char *cond_string
= NULL
;
6107 struct symtab_and_line
*sal
= NULL
;
6109 ep_skip_leading_whitespace (&arg
);
6111 cond_string
= ep_parse_optional_if_clause (&arg
);
6113 if ((*arg
!= '\0') && !isspace (*arg
))
6114 error ("Junk at end of arguments.");
6116 if ((ex_event
!= EX_EVENT_THROW
) &&
6117 (ex_event
!= EX_EVENT_CATCH
))
6118 error ("Unsupported or unknown exception event; cannot catch it");
6120 /* See if we can find a callback routine */
6121 sal
= target_enable_exception_callback (ex_event
, 1);
6125 /* We have callbacks from the runtime system for exceptions.
6126 Set a breakpoint on the sal found, if no errors */
6127 if (sal
!= (struct symtab_and_line
*) -1)
6128 create_exception_catchpoint (tempflag
, cond_string
, ex_event
, sal
);
6130 return; /* something went wrong with setting up callbacks */
6134 /* No callbacks from runtime system for exceptions.
6135 Try GNU C++ exception breakpoints using labels in debug info. */
6136 if (ex_event
== EX_EVENT_CATCH
)
6138 handle_gnu_4_16_catch_command (arg
, tempflag
, from_tty
);
6140 else if (ex_event
== EX_EVENT_THROW
)
6142 /* Set a breakpoint on __raise_exception () */
6144 warning ("Unsupported with this platform/compiler combination.");
6145 warning ("Perhaps you can achieve the effect you want by setting");
6146 warning ("a breakpoint on __raise_exception().");
6151 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6152 inside a catch_errors */
6155 cover_target_enable_exception_callback (PTR arg
)
6157 args_for_catchpoint_enable
*args
= arg
;
6158 struct symtab_and_line
*sal
;
6159 sal
= target_enable_exception_callback (args
->kind
, args
->enable_p
);
6162 else if (sal
== (struct symtab_and_line
*) -1)
6165 return 1; /*is valid */
6170 /* This is the original v.4.16 and earlier version of the
6171 catch_command_1() function. Now that other flavours of "catch"
6172 have been introduced, and since exception handling can be handled
6173 in other ways (through target ops) also, this is used only for the
6174 GNU C++ exception handling system.
6175 Note: Only the "catch" flavour of GDB 4.16 is handled here. The
6176 "catch NAME" is now no longer allowed in catch_command_1(). Also,
6177 there was no code in GDB 4.16 for "catch throw".
6179 Called from catch_exception_command_1 () */
6183 handle_gnu_4_16_catch_command (char *arg
, int tempflag
, int from_tty
)
6185 /* First, translate ARG into something we can deal with in terms
6188 struct symtabs_and_lines sals
;
6189 struct symtab_and_line sal
;
6190 register struct expression
*cond
= 0;
6191 register struct breakpoint
*b
;
6195 INIT_SAL (&sal
); /* initialize to zeroes */
6197 /* If no arg given, or if first arg is 'if ', all active catch clauses
6198 are breakpointed. */
6200 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
6201 && (arg
[2] == ' ' || arg
[2] == '\t')))
6203 /* Grab all active catch clauses. */
6204 sals
= get_catch_sals (0);
6208 /* Grab selected catch clauses. */
6209 error ("catch NAME not implemented");
6212 /* Not sure why this code has been disabled. I'm leaving
6213 it disabled. We can never come here now anyway
6214 since we don't allow the "catch NAME" syntax.
6217 /* This isn't used; I don't know what it was for. */
6218 sals
= map_catch_names (arg
, catch_breakpoint
);
6226 for (i
= 0; i
< sals
.nelts
; i
++)
6228 resolve_sal_pc (&sals
.sals
[i
]);
6232 if (arg
[0] == 'i' && arg
[1] == 'f'
6233 && (arg
[2] == ' ' || arg
[2] == '\t'))
6234 cond
= parse_exp_1 ((arg
+= 2, &arg
),
6235 block_for_pc (sals
.sals
[i
].pc
), 0);
6237 error ("Junk at end of arguments.");
6242 for (i
= 0; i
< sals
.nelts
; i
++)
6247 describe_other_breakpoints (sal
.pc
, sal
.section
);
6249 /* Important -- this is an ordinary breakpoint. For platforms
6250 with callback support for exceptions,
6251 create_exception_catchpoint() will create special bp types
6252 (bp_catch_catch and bp_catch_throw), and there is code in
6253 insert_breakpoints() and elsewhere that depends on that. */
6254 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6255 set_breakpoint_count (breakpoint_count
+ 1);
6256 b
->number
= breakpoint_count
;
6259 b
->enable_state
= bp_enabled
;
6260 b
->disposition
= tempflag
? disp_del
: disp_donttouch
;
6267 warning ("Multiple breakpoints were set.");
6268 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
6274 catch_command_1 (char *arg
, int tempflag
, int from_tty
)
6277 /* The first argument may be an event name, such as "start" or "load".
6278 If so, then handle it as such. If it doesn't match an event name,
6279 then attempt to interpret it as an exception name. (This latter is
6280 the v4.16-and-earlier GDB meaning of the "catch" command.)
6282 First, try to find the bounds of what might be an event name. */
6283 char *arg1_start
= arg
;
6287 if (arg1_start
== NULL
)
6289 /* Old behaviour was to use pre-v-4.16 syntax */
6290 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6292 /* Now, this is not allowed */
6293 error ("Catch requires an event name.");
6296 arg1_end
= ep_find_event_name_end (arg1_start
);
6297 if (arg1_end
== NULL
)
6298 error ("catch requires an event");
6299 arg1_length
= arg1_end
+ 1 - arg1_start
;
6301 /* Try to match what we found against known event names. */
6302 if (strncmp (arg1_start
, "signal", arg1_length
) == 0)
6304 error ("Catch of signal not yet implemented");
6306 else if (strncmp (arg1_start
, "catch", arg1_length
) == 0)
6308 catch_exception_command_1 (EX_EVENT_CATCH
, arg1_end
+ 1,
6309 tempflag
, from_tty
);
6311 else if (strncmp (arg1_start
, "throw", arg1_length
) == 0)
6313 catch_exception_command_1 (EX_EVENT_THROW
, arg1_end
+ 1,
6314 tempflag
, from_tty
);
6316 else if (strncmp (arg1_start
, "thread_start", arg1_length
) == 0)
6318 error ("Catch of thread_start not yet implemented");
6320 else if (strncmp (arg1_start
, "thread_exit", arg1_length
) == 0)
6322 error ("Catch of thread_exit not yet implemented");
6324 else if (strncmp (arg1_start
, "thread_join", arg1_length
) == 0)
6326 error ("Catch of thread_join not yet implemented");
6328 else if (strncmp (arg1_start
, "start", arg1_length
) == 0)
6330 error ("Catch of start not yet implemented");
6332 else if (strncmp (arg1_start
, "exit", arg1_length
) == 0)
6334 error ("Catch of exit not yet implemented");
6336 else if (strncmp (arg1_start
, "fork", arg1_length
) == 0)
6338 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6339 catch_fork_command_1 (catch_fork
, arg1_end
+ 1, tempflag
, from_tty
);
6341 error ("Catch of fork not yet implemented");
6344 else if (strncmp (arg1_start
, "vfork", arg1_length
) == 0)
6346 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6347 catch_fork_command_1 (catch_vfork
, arg1_end
+ 1, tempflag
, from_tty
);
6349 error ("Catch of vfork not yet implemented");
6352 else if (strncmp (arg1_start
, "exec", arg1_length
) == 0)
6354 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6355 catch_exec_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6357 error ("Catch of exec not yet implemented");
6360 else if (strncmp (arg1_start
, "load", arg1_length
) == 0)
6362 #if defined(SOLIB_ADD)
6363 catch_load_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6365 error ("Catch of load not implemented");
6368 else if (strncmp (arg1_start
, "unload", arg1_length
) == 0)
6370 #if defined(SOLIB_ADD)
6371 catch_unload_command_1 (arg1_end
+ 1, tempflag
, from_tty
);
6373 error ("Catch of load not implemented");
6376 else if (strncmp (arg1_start
, "stop", arg1_length
) == 0)
6378 error ("Catch of stop not yet implemented");
6381 /* This doesn't appear to be an event name */
6385 /* Pre-v.4.16 behaviour was to treat the argument
6386 as the name of an exception */
6387 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6388 /* Now this is not allowed */
6389 error ("Unknown event kind specified for catch");
6394 /* Used by the gui, could be made a worker for other things. */
6397 set_breakpoint_sal (struct symtab_and_line sal
)
6399 struct breakpoint
*b
;
6400 b
= set_raw_breakpoint (sal
, bp_breakpoint
);
6401 set_breakpoint_count (breakpoint_count
+ 1);
6402 b
->number
= breakpoint_count
;
6409 /* These aren't used; I don't know what they were for. */
6410 /* Disable breakpoints on all catch clauses described in ARGS. */
6412 disable_catch (char *args
)
6414 /* Map the disable command to catch clauses described in ARGS. */
6417 /* Enable breakpoints on all catch clauses described in ARGS. */
6419 enable_catch (char *args
)
6421 /* Map the disable command to catch clauses described in ARGS. */
6424 /* Delete breakpoints on all catch clauses in the active scope. */
6426 delete_catch (char *args
)
6428 /* Map the delete command to catch clauses described in ARGS. */
6433 catch_command (char *arg
, int from_tty
)
6435 catch_command_1 (arg
, 0, from_tty
);
6440 tcatch_command (char *arg
, int from_tty
)
6442 catch_command_1 (arg
, 1, from_tty
);
6447 clear_command (char *arg
, int from_tty
)
6449 register struct breakpoint
*b
, *b1
;
6451 struct symtabs_and_lines sals
;
6452 struct symtab_and_line sal
;
6453 register struct breakpoint
*found
;
6458 sals
= decode_line_spec (arg
, 1);
6463 sals
.sals
= (struct symtab_and_line
*)
6464 xmalloc (sizeof (struct symtab_and_line
));
6465 INIT_SAL (&sal
); /* initialize to zeroes */
6466 sal
.line
= default_breakpoint_line
;
6467 sal
.symtab
= default_breakpoint_symtab
;
6468 sal
.pc
= default_breakpoint_address
;
6469 if (sal
.symtab
== 0)
6470 error ("No source file specified.");
6478 /* For each line spec given, delete bps which correspond
6479 to it. We do this in two loops: the first loop looks at
6480 the initial bp(s) in the chain which should be deleted,
6481 the second goes down the rest of the chain looking ahead
6482 one so it can take those bps off the chain without messing
6486 for (i
= 0; i
< sals
.nelts
; i
++)
6488 /* If exact pc given, clear bpts at that pc.
6489 If line given (pc == 0), clear all bpts on specified line.
6490 If defaulting, clear all bpts on default line
6493 defaulting sal.pc != 0 tests to do
6498 1 0 <can't happen> */
6501 found
= (struct breakpoint
*) 0;
6504 while (breakpoint_chain
6505 /* Why don't we check here that this is not
6506 a watchpoint, etc., as we do below?
6507 I can't make it fail, but don't know
6508 what's stopping the failure: a watchpoint
6509 of the same address as "sal.pc" should
6510 wind up being deleted. */
6512 && (((sal
.pc
&& (breakpoint_chain
->address
== sal
.pc
))
6513 && (!overlay_debugging
6514 || breakpoint_chain
->section
== sal
.section
))
6515 || ((default_match
|| (0 == sal
.pc
))
6516 && breakpoint_chain
->source_file
!= NULL
6517 && sal
.symtab
!= NULL
6518 && STREQ (breakpoint_chain
->source_file
, sal
.symtab
->filename
)
6519 && breakpoint_chain
->line_number
== sal
.line
)))
6522 b1
= breakpoint_chain
;
6523 breakpoint_chain
= b1
->next
;
6530 && b
->next
->type
!= bp_none
6531 && b
->next
->type
!= bp_watchpoint
6532 && b
->next
->type
!= bp_hardware_watchpoint
6533 && b
->next
->type
!= bp_read_watchpoint
6534 && b
->next
->type
!= bp_access_watchpoint
6535 && (((sal
.pc
&& (b
->next
->address
== sal
.pc
))
6536 && (!overlay_debugging
|| b
->next
->section
== sal
.section
))
6537 || ((default_match
|| (0 == sal
.pc
))
6538 && b
->next
->source_file
!= NULL
6539 && sal
.symtab
!= NULL
6540 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
6541 && b
->next
->line_number
== sal
.line
)))
6554 error ("No breakpoint at %s.", arg
);
6556 error ("No breakpoint at this line.");
6560 from_tty
= 1; /* Always report if deleted more than one */
6562 printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
6563 breakpoints_changed ();
6567 printf_unfiltered ("%d ", found
->number
);
6569 delete_breakpoint (found
);
6573 putchar_unfiltered ('\n');
6578 /* Delete breakpoint in BS if they are `delete' breakpoints and
6579 all breakpoints that are marked for deletion, whether hit or not.
6580 This is called after any breakpoint is hit, or after errors. */
6583 breakpoint_auto_delete (bpstat bs
)
6585 struct breakpoint
*b
, *temp
;
6587 for (; bs
; bs
= bs
->next
)
6588 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== disp_del
6590 delete_breakpoint (bs
->breakpoint_at
);
6592 ALL_BREAKPOINTS_SAFE (b
, temp
)
6594 if (b
->disposition
== disp_del_at_next_stop
)
6595 delete_breakpoint (b
);
6599 /* Delete a breakpoint and clean up all traces of it in the data
6603 delete_breakpoint (struct breakpoint
*bpt
)
6605 register struct breakpoint
*b
;
6609 error ("Internal error (attempted to delete a NULL breakpoint)");
6612 /* Has this bp already been deleted? This can happen because multiple
6613 lists can hold pointers to bp's. bpstat lists are especial culprits.
6615 One example of this happening is a watchpoint's scope bp. When the
6616 scope bp triggers, we notice that the watchpoint is out of scope, and
6617 delete it. We also delete its scope bp. But the scope bp is marked
6618 "auto-deleting", and is already on a bpstat. That bpstat is then
6619 checked for auto-deleting bp's, which are deleted.
6621 A real solution to this problem might involve reference counts in bp's,
6622 and/or giving them pointers back to their referencing bpstat's, and
6623 teaching delete_breakpoint to only free a bp's storage when no more
6624 references were extent. A cheaper bandaid was chosen. */
6625 if (bpt
->type
== bp_none
)
6628 if (delete_breakpoint_hook
)
6629 delete_breakpoint_hook (bpt
);
6630 breakpoint_delete_event (bpt
->number
);
6633 remove_breakpoint (bpt
, mark_inserted
);
6635 if (breakpoint_chain
== bpt
)
6636 breakpoint_chain
= bpt
->next
;
6638 /* If we have callback-style exception catchpoints, don't go through
6639 the adjustments to the C++ runtime library etc. if the inferior
6640 isn't actually running. target_enable_exception_callback for a
6641 null target ops vector gives an undesirable error message, so we
6642 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6643 exceptions are supported in this way, it's OK for now. FIXME */
6644 if (ep_is_exception_catchpoint (bpt
) && target_has_execution
)
6646 static char message1
[] = "Error in deleting catchpoint %d:\n";
6647 static char message
[sizeof (message1
) + 30];
6648 args_for_catchpoint_enable args
;
6650 /* Format possible error msg */
6651 sprintf (message
, message1
, bpt
->number
);
6652 args
.kind
= bpt
->type
== bp_catch_catch
?
6653 EX_EVENT_CATCH
: EX_EVENT_THROW
;
6655 catch_errors (cover_target_enable_exception_callback
, &args
,
6656 message
, RETURN_MASK_ALL
);
6663 b
->next
= bpt
->next
;
6667 check_duplicates (bpt
);
6668 /* If this breakpoint was inserted, and there is another breakpoint
6669 at the same address, we need to insert the other breakpoint. */
6671 && bpt
->type
!= bp_hardware_watchpoint
6672 && bpt
->type
!= bp_read_watchpoint
6673 && bpt
->type
!= bp_access_watchpoint
6674 && bpt
->type
!= bp_catch_fork
6675 && bpt
->type
!= bp_catch_vfork
6676 && bpt
->type
!= bp_catch_exec
)
6679 if (b
->address
== bpt
->address
6680 && b
->section
== bpt
->section
6682 && b
->enable_state
!= bp_disabled
6683 && b
->enable_state
!= bp_shlib_disabled
6684 && b
->enable_state
!= bp_call_disabled
)
6688 /* We should never reach this point if there is a permanent
6689 breakpoint at the same address as the one being deleted.
6690 If there is a permanent breakpoint somewhere, it should
6691 always be the only one inserted. */
6692 if (b
->enable_state
== bp_permanent
)
6693 internal_error (__FILE__
, __LINE__
,
6694 "another breakpoint was inserted on top of "
6695 "a permanent breakpoint");
6697 if (b
->type
== bp_hardware_breakpoint
)
6698 val
= target_insert_hw_breakpoint (b
->address
, b
->shadow_contents
);
6700 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
6704 target_terminal_ours_for_output ();
6705 warning ("Cannot insert breakpoint %d:", b
->number
);
6706 memory_error (val
, b
->address
); /* which bombs us out */
6713 free_command_lines (&bpt
->commands
);
6716 if (bpt
->cond_string
!= NULL
)
6717 xfree (bpt
->cond_string
);
6718 if (bpt
->addr_string
!= NULL
)
6719 xfree (bpt
->addr_string
);
6720 if (bpt
->exp
!= NULL
)
6722 if (bpt
->exp_string
!= NULL
)
6723 xfree (bpt
->exp_string
);
6724 if (bpt
->val
!= NULL
)
6725 value_free (bpt
->val
);
6726 if (bpt
->source_file
!= NULL
)
6727 xfree (bpt
->source_file
);
6728 if (bpt
->dll_pathname
!= NULL
)
6729 xfree (bpt
->dll_pathname
);
6730 if (bpt
->triggered_dll_pathname
!= NULL
)
6731 xfree (bpt
->triggered_dll_pathname
);
6732 if (bpt
->exec_pathname
!= NULL
)
6733 xfree (bpt
->exec_pathname
);
6735 /* Be sure no bpstat's are pointing at it after it's been freed. */
6736 /* FIXME, how can we find all bpstat's?
6737 We just check stop_bpstat for now. */
6738 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
6739 if (bs
->breakpoint_at
== bpt
)
6741 bs
->breakpoint_at
= NULL
;
6743 /* we'd call bpstat_clear_actions, but that free's stuff and due
6744 to the multiple pointers pointing to one item with no
6745 reference counts found anywhere through out the bpstat's (how
6746 do you spell fragile?), we don't want to free things twice --
6747 better a memory leak than a corrupt malloc pool! */
6748 bs
->commands
= NULL
;
6751 /* On the chance that someone will soon try again to delete this same
6752 bp, we mark it as deleted before freeing its storage. */
6753 bpt
->type
= bp_none
;
6759 do_delete_breakpoint_cleanup (void *b
)
6761 delete_breakpoint (b
);
6765 make_cleanup_delete_breakpoint (struct breakpoint
*b
)
6767 return make_cleanup (do_delete_breakpoint_cleanup
, b
);
6771 make_exec_cleanup_delete_breakpoint (struct breakpoint
*b
)
6773 return make_exec_cleanup (do_delete_breakpoint_cleanup
, b
);
6777 delete_command (char *arg
, int from_tty
)
6779 struct breakpoint
*b
, *temp
;
6783 int breaks_to_delete
= 0;
6785 /* Delete all breakpoints if no argument.
6786 Do not delete internal or call-dummy breakpoints, these
6787 have to be deleted with an explicit breakpoint number argument. */
6790 if (b
->type
!= bp_call_dummy
&&
6791 b
->type
!= bp_shlib_event
&&
6792 b
->type
!= bp_thread_event
&&
6793 b
->type
!= bp_overlay_event
&&
6795 breaks_to_delete
= 1;
6798 /* Ask user only if there are some breakpoints to delete. */
6800 || (breaks_to_delete
&& query ("Delete all breakpoints? ")))
6802 ALL_BREAKPOINTS_SAFE (b
, temp
)
6804 if (b
->type
!= bp_call_dummy
&&
6805 b
->type
!= bp_shlib_event
&&
6806 b
->type
!= bp_thread_event
&&
6807 b
->type
!= bp_overlay_event
&&
6809 delete_breakpoint (b
);
6814 map_breakpoint_numbers (arg
, delete_breakpoint
);
6817 /* Reset a breakpoint given it's struct breakpoint * BINT.
6818 The value we return ends up being the return value from catch_errors.
6819 Unused in this case. */
6822 breakpoint_re_set_one (PTR bint
)
6824 /* get past catch_errs */
6825 struct breakpoint
*b
= (struct breakpoint
*) bint
;
6828 struct symtabs_and_lines sals
;
6830 enum enable_state save_enable
;
6835 warning ("attempted to reset apparently deleted breakpoint #%d?",
6839 case bp_hardware_breakpoint
:
6841 case bp_catch_unload
:
6842 if (b
->addr_string
== NULL
)
6844 /* Anything without a string can't be re-set. */
6845 delete_breakpoint (b
);
6848 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6850 ``And a hack it is, although Apple's Darwin version of GDB
6851 contains an almost identical hack to implement a "future
6852 break" command. It seems to work in many real world cases,
6853 but it is easy to come up with a test case where the patch
6854 doesn't help at all.''
6856 ``It seems that the way GDB implements breakpoints - in -
6857 shared - libraries was designed for a.out shared library
6858 systems (SunOS 4) where shared libraries were loaded at a
6859 fixed address in memory. Since ELF shared libraries can (and
6860 will) be loaded at any address in memory, things break.
6861 Fixing this is not trivial. Therefore, I'm not sure whether
6862 we should add this hack to the branch only. I cannot
6863 guarantee that things will be fixed on the trunk in the near
6866 In case we have a problem, disable this breakpoint. We'll
6867 restore its status if we succeed. Don't disable a
6868 shlib_disabled breakpoint though. There's a fair chance we
6869 can't re-set it if the shared library it's in hasn't been
6871 save_enable
= b
->enable_state
;
6872 if (b
->enable_state
!= bp_shlib_disabled
)
6873 b
->enable_state
= bp_disabled
;
6875 set_language (b
->language
);
6876 input_radix
= b
->input_radix
;
6878 sals
= decode_line_1 (&s
, 1, (struct symtab
*) NULL
, 0, (char ***) NULL
);
6879 for (i
= 0; i
< sals
.nelts
; i
++)
6881 resolve_sal_pc (&sals
.sals
[i
]);
6883 /* Reparse conditions, they might contain references to the
6885 if (b
->cond_string
!= NULL
)
6890 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
6893 /* We need to re-set the breakpoint if the address changes... */
6894 if (b
->address
!= sals
.sals
[i
].pc
6895 /* ...or new and old breakpoints both have source files, and
6896 the source file name or the line number changes... */
6897 || (b
->source_file
!= NULL
6898 && sals
.sals
[i
].symtab
!= NULL
6899 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
6900 || b
->line_number
!= sals
.sals
[i
].line
)
6902 /* ...or we switch between having a source file and not having
6904 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
6907 if (b
->source_file
!= NULL
)
6908 xfree (b
->source_file
);
6909 if (sals
.sals
[i
].symtab
== NULL
)
6910 b
->source_file
= NULL
;
6913 savestring (sals
.sals
[i
].symtab
->filename
,
6914 strlen (sals
.sals
[i
].symtab
->filename
));
6915 b
->line_number
= sals
.sals
[i
].line
;
6916 b
->address
= sals
.sals
[i
].pc
;
6918 /* Used to check for duplicates here, but that can
6919 cause trouble, as it doesn't check for disabled
6924 /* Might be better to do this just once per breakpoint_re_set,
6925 rather than once for every breakpoint. */
6926 breakpoints_changed ();
6928 b
->section
= sals
.sals
[i
].section
;
6929 b
->enable_state
= save_enable
; /* Restore it, this worked. */
6932 /* Now that this is re-enabled, check_duplicates
6934 check_duplicates (b
);
6941 case bp_hardware_watchpoint
:
6942 case bp_read_watchpoint
:
6943 case bp_access_watchpoint
:
6944 innermost_block
= NULL
;
6945 /* The issue arises of what context to evaluate this in. The
6946 same one as when it was set, but what does that mean when
6947 symbols have been re-read? We could save the filename and
6948 functionname, but if the context is more local than that, the
6949 best we could do would be something like how many levels deep
6950 and which index at that particular level, but that's going to
6951 be less stable than filenames or function names. */
6953 /* So for now, just use a global context. */
6956 b
->exp
= parse_expression (b
->exp_string
);
6957 b
->exp_valid_block
= innermost_block
;
6958 mark
= value_mark ();
6960 value_free (b
->val
);
6961 b
->val
= evaluate_expression (b
->exp
);
6962 release_value (b
->val
);
6963 if (VALUE_LAZY (b
->val
))
6964 value_fetch_lazy (b
->val
);
6966 if (b
->cond_string
!= NULL
)
6971 b
->cond
= parse_exp_1 (&s
, (struct block
*) 0, 0);
6973 if (b
->enable_state
== bp_enabled
)
6975 value_free_to_mark (mark
);
6977 case bp_catch_catch
:
6978 case bp_catch_throw
:
6980 /* We needn't really do anything to reset these, since the mask
6981 that requests them is unaffected by e.g., new libraries being
6984 case bp_catch_vfork
:
6989 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
6991 /* Delete longjmp and overlay event breakpoints; they will be
6992 reset later by breakpoint_re_set. */
6994 case bp_longjmp_resume
:
6995 case bp_overlay_event
:
6996 delete_breakpoint (b
);
6999 /* This breakpoint is special, it's set up when the inferior
7000 starts and we really don't want to touch it. */
7001 case bp_shlib_event
:
7003 /* Like bp_shlib_event, this breakpoint type is special.
7004 Once it is set up, we do not want to touch it. */
7005 case bp_thread_event
:
7007 /* Keep temporary breakpoints, which can be encountered when we step
7008 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
7009 Otherwise these should have been blown away via the cleanup chain
7010 or by breakpoint_init_inferior when we rerun the executable. */
7013 case bp_watchpoint_scope
:
7015 case bp_step_resume
:
7022 /* Re-set all breakpoints after symbols have been re-loaded. */
7024 breakpoint_re_set (void)
7026 struct breakpoint
*b
, *temp
;
7027 enum language save_language
;
7028 int save_input_radix
;
7029 static char message1
[] = "Error in re-setting breakpoint %d:\n";
7030 char message
[sizeof (message1
) + 30 /* slop */ ];
7032 save_language
= current_language
->la_language
;
7033 save_input_radix
= input_radix
;
7034 ALL_BREAKPOINTS_SAFE (b
, temp
)
7036 /* Format possible error msg */
7037 sprintf (message
, message1
, b
->number
);
7038 catch_errors (breakpoint_re_set_one
, b
, message
, RETURN_MASK_ALL
);
7040 set_language (save_language
);
7041 input_radix
= save_input_radix
;
7043 if (GET_LONGJMP_TARGET_P ())
7045 create_longjmp_breakpoint ("longjmp");
7046 create_longjmp_breakpoint ("_longjmp");
7047 create_longjmp_breakpoint ("siglongjmp");
7048 create_longjmp_breakpoint ("_siglongjmp");
7049 create_longjmp_breakpoint (NULL
);
7052 create_overlay_event_breakpoint ("_ovly_debug_event");
7055 /* Reset the thread number of this breakpoint:
7057 - If the breakpoint is for all threads, leave it as-is.
7058 - Else, reset it to the current thread for inferior_ptid. */
7060 breakpoint_re_set_thread (struct breakpoint
*b
)
7062 if (b
->thread
!= -1)
7064 if (in_thread_list (inferior_ptid
))
7065 b
->thread
= pid_to_thread_id (inferior_ptid
);
7069 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7070 If from_tty is nonzero, it prints a message to that effect,
7071 which ends with a period (no newline). */
7074 set_ignore_count (int bptnum
, int count
, int from_tty
)
7076 register struct breakpoint
*b
;
7082 if (b
->number
== bptnum
)
7084 b
->ignore_count
= count
;
7087 else if (count
== 0)
7088 printf_filtered ("Will stop next time breakpoint %d is reached.",
7090 else if (count
== 1)
7091 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7094 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7096 breakpoints_changed ();
7100 error ("No breakpoint number %d.", bptnum
);
7103 /* Clear the ignore counts of all breakpoints. */
7105 breakpoint_clear_ignore_counts (void)
7107 struct breakpoint
*b
;
7110 b
->ignore_count
= 0;
7113 /* Command to set ignore-count of breakpoint N to COUNT. */
7116 ignore_command (char *args
, int from_tty
)
7122 error_no_arg ("a breakpoint number");
7124 num
= get_number (&p
);
7126 error ("bad breakpoint number: '%s'", args
);
7128 error ("Second argument (specified ignore-count) is missing.");
7130 set_ignore_count (num
,
7131 longest_to_int (value_as_long (parse_and_eval (p
))),
7133 printf_filtered ("\n");
7134 breakpoints_changed ();
7137 /* Call FUNCTION on each of the breakpoints
7138 whose numbers are given in ARGS. */
7141 map_breakpoint_numbers (char *args
, void (*function
) (struct breakpoint
*))
7143 register char *p
= args
;
7146 register struct breakpoint
*b
, *tmp
;
7150 error_no_arg ("one or more breakpoint numbers");
7157 num
= get_number_or_range (&p1
);
7160 warning ("bad breakpoint number at or near '%s'", p
);
7164 ALL_BREAKPOINTS_SAFE (b
, tmp
)
7165 if (b
->number
== num
)
7167 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
7170 if (related_breakpoint
)
7171 function (related_breakpoint
);
7175 printf_unfiltered ("No breakpoint number %d.\n", num
);
7181 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7182 If from_tty is nonzero, it prints a message to that effect,
7183 which ends with a period (no newline). */
7186 disable_breakpoint (struct breakpoint
*bpt
)
7188 /* Never disable a watchpoint scope breakpoint; we want to
7189 hit them when we leave scope so we can delete both the
7190 watchpoint and its scope breakpoint at that time. */
7191 if (bpt
->type
== bp_watchpoint_scope
)
7194 /* You can't disable permanent breakpoints. */
7195 if (bpt
->enable_state
== bp_permanent
)
7198 bpt
->enable_state
= bp_disabled
;
7200 check_duplicates (bpt
);
7202 if (modify_breakpoint_hook
)
7203 modify_breakpoint_hook (bpt
);
7204 breakpoint_modify_event (bpt
->number
);
7209 disable_command (char *args
, int from_tty
)
7211 register struct breakpoint
*bpt
;
7213 ALL_BREAKPOINTS (bpt
)
7217 warning ("attempted to disable apparently deleted breakpoint #%d?",
7222 case bp_catch_unload
:
7224 case bp_catch_vfork
:
7226 case bp_catch_catch
:
7227 case bp_catch_throw
:
7228 case bp_hardware_breakpoint
:
7230 case bp_hardware_watchpoint
:
7231 case bp_read_watchpoint
:
7232 case bp_access_watchpoint
:
7233 disable_breakpoint (bpt
);
7238 map_breakpoint_numbers (args
, disable_breakpoint
);
7242 do_enable_breakpoint (struct breakpoint
*bpt
, enum bpdisp disposition
)
7244 struct frame_info
*save_selected_frame
= NULL
;
7245 int save_selected_frame_level
= -1;
7246 int target_resources_ok
, other_type_used
;
7249 if (bpt
->type
== bp_hardware_breakpoint
)
7252 i
= hw_breakpoint_used_count ();
7253 target_resources_ok
=
7254 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint
,
7256 if (target_resources_ok
== 0)
7257 error ("No hardware breakpoint support in the target.");
7258 else if (target_resources_ok
< 0)
7259 error ("Hardware breakpoints used exceeds limit.");
7262 if (bpt
->enable_state
!= bp_permanent
)
7263 bpt
->enable_state
= bp_enabled
;
7264 bpt
->disposition
= disposition
;
7265 check_duplicates (bpt
);
7266 breakpoints_changed ();
7268 if (bpt
->type
== bp_watchpoint
||
7269 bpt
->type
== bp_hardware_watchpoint
||
7270 bpt
->type
== bp_read_watchpoint
||
7271 bpt
->type
== bp_access_watchpoint
)
7273 if (bpt
->exp_valid_block
!= NULL
)
7275 struct frame_info
*fr
=
7277 /* Ensure that we have the current frame. Else, this
7278 next query may pessimistically be answered as, "No,
7279 not within current scope". */
7280 get_current_frame ();
7281 fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
7285 Cannot enable watchpoint %d because the block in which its expression\n\
7286 is valid is not currently in scope.\n", bpt
->number
);
7287 bpt
->enable_state
= bp_disabled
;
7291 save_selected_frame
= selected_frame
;
7292 save_selected_frame_level
= selected_frame_level
;
7293 select_frame (fr
, -1);
7296 value_free (bpt
->val
);
7297 mark
= value_mark ();
7298 bpt
->val
= evaluate_expression (bpt
->exp
);
7299 release_value (bpt
->val
);
7300 if (VALUE_LAZY (bpt
->val
))
7301 value_fetch_lazy (bpt
->val
);
7303 if (bpt
->type
== bp_hardware_watchpoint
||
7304 bpt
->type
== bp_read_watchpoint
||
7305 bpt
->type
== bp_access_watchpoint
)
7307 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
7308 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
7310 /* Hack around 'unused var' error for some targets here */
7312 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7313 bpt
->type
, i
+ mem_cnt
, other_type_used
);
7314 /* we can consider of type is bp_hardware_watchpoint, convert to
7315 bp_watchpoint in the following condition */
7316 if (target_resources_ok
< 0)
7319 Cannot enable watchpoint %d because target watch resources\n\
7320 have been allocated for other watchpoints.\n", bpt
->number
);
7321 bpt
->enable_state
= bp_disabled
;
7322 value_free_to_mark (mark
);
7327 if (save_selected_frame_level
>= 0)
7328 select_frame (save_selected_frame
, save_selected_frame_level
);
7329 value_free_to_mark (mark
);
7331 if (modify_breakpoint_hook
)
7332 modify_breakpoint_hook (bpt
);
7333 breakpoint_modify_event (bpt
->number
);
7337 enable_breakpoint (struct breakpoint
*bpt
)
7339 do_enable_breakpoint (bpt
, bpt
->disposition
);
7342 /* The enable command enables the specified breakpoints (or all defined
7343 breakpoints) so they once again become (or continue to be) effective
7344 in stopping the inferior. */
7348 enable_command (char *args
, int from_tty
)
7350 register struct breakpoint
*bpt
;
7352 ALL_BREAKPOINTS (bpt
)
7356 warning ("attempted to enable apparently deleted breakpoint #%d?",
7361 case bp_catch_unload
:
7363 case bp_catch_vfork
:
7365 case bp_catch_catch
:
7366 case bp_catch_throw
:
7367 case bp_hardware_breakpoint
:
7369 case bp_hardware_watchpoint
:
7370 case bp_read_watchpoint
:
7371 case bp_access_watchpoint
:
7372 enable_breakpoint (bpt
);
7377 map_breakpoint_numbers (args
, enable_breakpoint
);
7381 enable_once_breakpoint (struct breakpoint
*bpt
)
7383 do_enable_breakpoint (bpt
, disp_disable
);
7388 enable_once_command (char *args
, int from_tty
)
7390 map_breakpoint_numbers (args
, enable_once_breakpoint
);
7394 enable_delete_breakpoint (struct breakpoint
*bpt
)
7396 do_enable_breakpoint (bpt
, disp_del
);
7401 enable_delete_command (char *args
, int from_tty
)
7403 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
7406 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7408 struct symtabs_and_lines
7409 decode_line_spec_1 (char *string
, int funfirstline
)
7411 struct symtabs_and_lines sals
;
7413 error ("Empty line specification.");
7414 if (default_breakpoint_valid
)
7415 sals
= decode_line_1 (&string
, funfirstline
,
7416 default_breakpoint_symtab
,
7417 default_breakpoint_line
,
7420 sals
= decode_line_1 (&string
, funfirstline
,
7421 (struct symtab
*) NULL
, 0, (char ***) NULL
);
7423 error ("Junk at end of line specification: %s", string
);
7428 _initialize_breakpoint (void)
7430 struct cmd_list_element
*c
;
7432 breakpoint_chain
= 0;
7433 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7434 before a breakpoint is set. */
7435 breakpoint_count
= 0;
7437 add_com ("ignore", class_breakpoint
, ignore_command
,
7438 "Set ignore-count of breakpoint number N to COUNT.\n\
7439 Usage is `ignore N COUNT'.");
7441 add_com_alias ("bc", "ignore", class_breakpoint
, 1);
7443 add_com ("commands", class_breakpoint
, commands_command
,
7444 "Set commands to be executed when a breakpoint is hit.\n\
7445 Give breakpoint number as argument after \"commands\".\n\
7446 With no argument, the targeted breakpoint is the last one set.\n\
7447 The commands themselves follow starting on the next line.\n\
7448 Type a line containing \"end\" to indicate the end of them.\n\
7449 Give \"silent\" as the first line to make the breakpoint silent;\n\
7450 then no output is printed when it is hit, except what the commands print.");
7452 add_com ("condition", class_breakpoint
, condition_command
,
7453 "Specify breakpoint number N to break only if COND is true.\n\
7454 Usage is `condition N COND', where N is an integer and COND is an\n\
7455 expression to be evaluated whenever breakpoint N is reached.");
7457 c
= add_com ("tbreak", class_breakpoint
, tbreak_command
,
7458 "Set a temporary breakpoint. Args like \"break\" command.\n\
7459 Like \"break\" except the breakpoint is only temporary,\n\
7460 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7461 by using \"enable delete\" on the breakpoint number.");
7462 set_cmd_completer (c
, location_completer
);
7464 c
= add_com ("hbreak", class_breakpoint
, hbreak_command
,
7465 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7466 Like \"break\" except the breakpoint requires hardware support,\n\
7467 some target hardware may not have this support.");
7468 set_cmd_completer (c
, location_completer
);
7470 c
= add_com ("thbreak", class_breakpoint
, thbreak_command
,
7471 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7472 Like \"hbreak\" except the breakpoint is only temporary,\n\
7473 so it will be deleted when hit.");
7474 set_cmd_completer (c
, location_completer
);
7476 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
7477 "Enable some breakpoints.\n\
7478 Give breakpoint numbers (separated by spaces) as arguments.\n\
7479 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7480 This is used to cancel the effect of the \"disable\" command.\n\
7481 With a subcommand you can enable temporarily.",
7482 &enablelist
, "enable ", 1, &cmdlist
);
7484 add_com ("ab", class_breakpoint
, enable_command
,
7485 "Enable some breakpoints.\n\
7486 Give breakpoint numbers (separated by spaces) as arguments.\n\
7487 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7488 This is used to cancel the effect of the \"disable\" command.\n\
7489 With a subcommand you can enable temporarily.");
7491 add_com_alias ("en", "enable", class_breakpoint
, 1);
7493 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
7494 "Enable some breakpoints.\n\
7495 Give breakpoint numbers (separated by spaces) as arguments.\n\
7496 This is used to cancel the effect of the \"disable\" command.\n\
7497 May be abbreviated to simply \"enable\".\n",
7498 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
7500 add_cmd ("once", no_class
, enable_once_command
,
7501 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7502 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7505 add_cmd ("delete", no_class
, enable_delete_command
,
7506 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7507 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7510 add_cmd ("delete", no_class
, enable_delete_command
,
7511 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7512 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7515 add_cmd ("once", no_class
, enable_once_command
,
7516 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7517 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7520 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
7521 "Disable some breakpoints.\n\
7522 Arguments are breakpoint numbers with spaces in between.\n\
7523 To disable all breakpoints, give no argument.\n\
7524 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7525 &disablelist
, "disable ", 1, &cmdlist
);
7526 add_com_alias ("dis", "disable", class_breakpoint
, 1);
7527 add_com_alias ("disa", "disable", class_breakpoint
, 1);
7529 add_com ("sb", class_breakpoint
, disable_command
,
7530 "Disable some breakpoints.\n\
7531 Arguments are breakpoint numbers with spaces in between.\n\
7532 To disable all breakpoints, give no argument.\n\
7533 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7535 add_cmd ("breakpoints", class_alias
, disable_command
,
7536 "Disable some breakpoints.\n\
7537 Arguments are breakpoint numbers with spaces in between.\n\
7538 To disable all breakpoints, give no argument.\n\
7539 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7540 This command may be abbreviated \"disable\".",
7543 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
7544 "Delete some breakpoints or auto-display expressions.\n\
7545 Arguments are breakpoint numbers with spaces in between.\n\
7546 To delete all breakpoints, give no argument.\n\
7548 Also a prefix command for deletion of other GDB objects.\n\
7549 The \"unset\" command is also an alias for \"delete\".",
7550 &deletelist
, "delete ", 1, &cmdlist
);
7551 add_com_alias ("d", "delete", class_breakpoint
, 1);
7553 add_com ("db", class_breakpoint
, delete_command
,
7554 "Delete some breakpoints.\n\
7555 Arguments are breakpoint numbers with spaces in between.\n\
7556 To delete all breakpoints, give no argument.\n");
7558 add_cmd ("breakpoints", class_alias
, delete_command
,
7559 "Delete some breakpoints or auto-display expressions.\n\
7560 Arguments are breakpoint numbers with spaces in between.\n\
7561 To delete all breakpoints, give no argument.\n\
7562 This command may be abbreviated \"delete\".",
7565 add_com ("clear", class_breakpoint
, clear_command
,
7566 concat ("Clear breakpoint at specified line or function.\n\
7567 Argument may be line number, function name, or \"*\" and an address.\n\
7568 If line number is specified, all breakpoints in that line are cleared.\n\
7569 If function is specified, breakpoints at beginning of function are cleared.\n\
7570 If an address is specified, breakpoints at that address are cleared.\n\n",
7571 "With no argument, clears all breakpoints in the line that the selected frame\n\
7574 See also the \"delete\" command which clears breakpoints by number.", NULL
));
7576 c
= add_com ("break", class_breakpoint
, break_command
,
7577 concat ("Set breakpoint at specified line or function.\n\
7578 Argument may be line number, function name, or \"*\" and an address.\n\
7579 If line number is specified, break at start of code for that line.\n\
7580 If function is specified, break at start of code for that function.\n\
7581 If an address is specified, break at that exact address.\n",
7582 "With no arg, uses current execution address of selected stack frame.\n\
7583 This is useful for breaking on return to a stack frame.\n\
7585 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7587 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
7588 set_cmd_completer (c
, location_completer
);
7590 add_com_alias ("b", "break", class_run
, 1);
7591 add_com_alias ("br", "break", class_run
, 1);
7592 add_com_alias ("bre", "break", class_run
, 1);
7593 add_com_alias ("brea", "break", class_run
, 1);
7597 add_com_alias ("ba", "break", class_breakpoint
, 1);
7598 add_com_alias ("bu", "ubreak", class_breakpoint
, 1);
7603 add_abbrev_prefix_cmd ("stop", class_breakpoint
, stop_command
,
7604 "Break in function/address or break at a line in the current file.",
7605 &stoplist
, "stop ", 1, &cmdlist
);
7606 add_cmd ("in", class_breakpoint
, stopin_command
,
7607 "Break in function or address.\n", &stoplist
);
7608 add_cmd ("at", class_breakpoint
, stopat_command
,
7609 "Break at a line in the current file.\n", &stoplist
);
7610 add_com ("status", class_info
, breakpoints_info
,
7611 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7612 The \"Type\" column indicates one of:\n\
7613 \tbreakpoint - normal breakpoint\n\
7614 \twatchpoint - watchpoint\n\
7615 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7616 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7617 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7618 address and file/line number respectively.\n\n",
7619 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7620 are set to the address of the last breakpoint listed.\n\n\
7621 Convenience variable \"$bpnum\" contains the number of the last\n\
7622 breakpoint set.", NULL
));
7625 add_info ("breakpoints", breakpoints_info
,
7626 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7627 The \"Type\" column indicates one of:\n\
7628 \tbreakpoint - normal breakpoint\n\
7629 \twatchpoint - watchpoint\n\
7630 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7631 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7632 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7633 address and file/line number respectively.\n\n",
7634 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7635 are set to the address of the last breakpoint listed.\n\n\
7636 Convenience variable \"$bpnum\" contains the number of the last\n\
7637 breakpoint set.", NULL
));
7640 add_com ("lb", class_breakpoint
, breakpoints_info
,
7641 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7642 The \"Type\" column indicates one of:\n\
7643 \tbreakpoint - normal breakpoint\n\
7644 \twatchpoint - watchpoint\n\
7645 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7646 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7647 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7648 address and file/line number respectively.\n\n",
7649 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7650 are set to the address of the last breakpoint listed.\n\n\
7651 Convenience variable \"$bpnum\" contains the number of the last\n\
7652 breakpoint set.", NULL
));
7654 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
7655 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7656 The \"Type\" column indicates one of:\n\
7657 \tbreakpoint - normal breakpoint\n\
7658 \twatchpoint - watchpoint\n\
7659 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7660 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7661 \tuntil - internal breakpoint used by the \"until\" command\n\
7662 \tfinish - internal breakpoint used by the \"finish\" command\n",
7663 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7664 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7665 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7666 address and file/line number respectively.\n\n",
7667 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7668 are set to the address of the last breakpoint listed.\n\n\
7669 Convenience variable \"$bpnum\" contains the number of the last\n\
7670 breakpoint set.", NULL
),
7671 &maintenanceinfolist
);
7673 add_com ("catch", class_breakpoint
, catch_command
,
7674 "Set catchpoints to catch events.\n\
7675 Raised signals may be caught:\n\
7676 \tcatch signal - all signals\n\
7677 \tcatch signal <signame> - a particular signal\n\
7678 Raised exceptions may be caught:\n\
7679 \tcatch throw - all exceptions, when thrown\n\
7680 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7681 \tcatch catch - all exceptions, when caught\n\
7682 \tcatch catch <exceptname> - a particular exception, when caught\n\
7683 Thread or process events may be caught:\n\
7684 \tcatch thread_start - any threads, just after creation\n\
7685 \tcatch thread_exit - any threads, just before expiration\n\
7686 \tcatch thread_join - any threads, just after joins\n\
7687 Process events may be caught:\n\
7688 \tcatch start - any processes, just after creation\n\
7689 \tcatch exit - any processes, just before expiration\n\
7690 \tcatch fork - calls to fork()\n\
7691 \tcatch vfork - calls to vfork()\n\
7692 \tcatch exec - calls to exec()\n\
7693 Dynamically-linked library events may be caught:\n\
7694 \tcatch load - loads of any library\n\
7695 \tcatch load <libname> - loads of a particular library\n\
7696 \tcatch unload - unloads of any library\n\
7697 \tcatch unload <libname> - unloads of a particular library\n\
7698 The act of your program's execution stopping may also be caught:\n\
7700 C++ exceptions may be caught:\n\
7701 \tcatch throw - all exceptions, when thrown\n\
7702 \tcatch catch - all exceptions, when caught\n\
7704 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7705 after a fork or vfork is caught.\n\n\
7706 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7708 add_com ("tcatch", class_breakpoint
, tcatch_command
,
7709 "Set temporary catchpoints to catch events.\n\
7710 Args like \"catch\" command.\n\
7711 Like \"catch\" except the catchpoint is only temporary,\n\
7712 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7713 by using \"enable delete\" on the catchpoint number.");
7715 c
= add_com ("watch", class_breakpoint
, watch_command
,
7716 "Set a watchpoint for an expression.\n\
7717 A watchpoint stops execution of your program whenever the value of\n\
7718 an expression changes.");
7719 set_cmd_completer (c
, location_completer
);
7721 c
= add_com ("rwatch", class_breakpoint
, rwatch_command
,
7722 "Set a read watchpoint for an expression.\n\
7723 A watchpoint stops execution of your program whenever the value of\n\
7724 an expression is read.");
7725 set_cmd_completer (c
, location_completer
);
7727 c
= add_com ("awatch", class_breakpoint
, awatch_command
,
7728 "Set a watchpoint for an expression.\n\
7729 A watchpoint stops execution of your program whenever the value of\n\
7730 an expression is either read or written.");
7731 set_cmd_completer (c
, location_completer
);
7733 add_info ("watchpoints", breakpoints_info
,
7734 "Synonym for ``info breakpoints''.");
7737 c
= add_set_cmd ("can-use-hw-watchpoints", class_support
, var_zinteger
,
7738 (char *) &can_use_hw_watchpoints
,
7739 "Set debugger's willingness to use watchpoint hardware.\n\
7740 If zero, gdb will not use hardware for new watchpoints, even if\n\
7741 such is available. (However, any hardware watchpoints that were\n\
7742 created before setting this to nonzero, will continue to use watchpoint\n\
7745 add_show_from_set (c
, &showlist
);
7747 can_use_hw_watchpoints
= 1;