1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
26 #include "expression.h"
39 /* local function prototypes */
42 catch_command_1
PARAMS ((char *, int, int));
45 enable_delete_command
PARAMS ((char *, int));
48 enable_delete_breakpoint
PARAMS ((struct breakpoint
*));
51 enable_once_command
PARAMS ((char *, int));
54 enable_once_breakpoint
PARAMS ((struct breakpoint
*));
57 disable_command
PARAMS ((char *, int));
60 disable_breakpoint
PARAMS ((struct breakpoint
*));
63 enable_command
PARAMS ((char *, int));
66 enable_breakpoint
PARAMS ((struct breakpoint
*));
69 map_breakpoint_numbers
PARAMS ((char *, void (*)(struct breakpoint
*)));
72 ignore_command
PARAMS ((char *, int));
75 breakpoint_re_set_one
PARAMS ((char *));
78 delete_command
PARAMS ((char *, int));
81 clear_command
PARAMS ((char *, int));
84 catch_command
PARAMS ((char *, int));
86 static struct symtabs_and_lines
87 get_catch_sals
PARAMS ((int));
90 watch_command
PARAMS ((char *, int));
93 can_use_hardware_watchpoint
PARAMS ((struct value
*));
96 tbreak_command
PARAMS ((char *, int));
99 break_command_1
PARAMS ((char *, int, int));
102 mention
PARAMS ((struct breakpoint
*));
104 static struct breakpoint
*
105 set_raw_breakpoint
PARAMS ((struct symtab_and_line
));
108 check_duplicates
PARAMS ((CORE_ADDR
));
111 describe_other_breakpoints
PARAMS ((CORE_ADDR
));
114 breakpoints_info
PARAMS ((char *, int));
117 breakpoint_1
PARAMS ((int, int));
120 bpstat_alloc
PARAMS ((struct breakpoint
*, bpstat
));
123 breakpoint_cond_eval
PARAMS ((char *));
126 cleanup_executing_breakpoints
PARAMS ((int));
129 commands_command
PARAMS ((char *, int));
132 condition_command
PARAMS ((char *, int));
135 get_number
PARAMS ((char **));
138 set_breakpoint_count
PARAMS ((int));
141 remove_breakpoint
PARAMS ((struct breakpoint
*));
143 extern int addressprint
; /* Print machine addresses? */
144 extern int demangle
; /* Print de-mangled symbol names? */
146 /* Are we executing breakpoint commands? */
147 static int executing_breakpoint_commands
;
149 /* Walk the following statement or block through all breakpoints.
150 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
153 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
155 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
156 for (b = breakpoint_chain; \
157 b? (tmp=b->next, 1): 0; \
160 /* By default no support for hardware watchpoints is assumed. */
161 #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT
162 #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) 0
163 #define target_remove_watchpoint(ADDR,LEN,TYPE) -1
164 #define target_insert_watchpoint(ADDR,LEN,TYPE) -1
167 #ifndef target_insert_hw_breakpoint
168 #define target_remove_hw_breakpoint(ADDR,SHADOW) -1
169 #define target_insert_hw_breakpoint(ADDR,SHADOW) -1
172 #ifndef target_stopped_data_address
173 #define target_stopped_data_address() 0
176 /* Chain of all breakpoints defined. */
178 static struct breakpoint
*breakpoint_chain
;
180 /* Number of last breakpoint made. */
182 static int breakpoint_count
;
184 /* Set breakpoint count to NUM. */
186 set_breakpoint_count (num
)
189 breakpoint_count
= num
;
190 set_internalvar (lookup_internalvar ("bpnum"),
191 value_from_longest (builtin_type_int
, (LONGEST
) num
));
194 /* Default address, symtab and line to put a breakpoint at
195 for "break" command with no arg.
196 if default_breakpoint_valid is zero, the other three are
197 not valid, and "break" with no arg is an error.
199 This set by print_stack_frame, which calls set_default_breakpoint. */
201 int default_breakpoint_valid
;
202 CORE_ADDR default_breakpoint_address
;
203 struct symtab
*default_breakpoint_symtab
;
204 int default_breakpoint_line
;
206 /* Flag indicating extra verbosity for xgdb. */
207 extern int xgdb_verbose
;
210 breakpoints_changed ()
212 if (annotation_level
> 1)
214 target_terminal_ours ();
215 printf_unfiltered ("\n\032\032breakpoints-invalid\n");
219 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
220 Advance *PP after the string and any trailing whitespace.
222 Currently the string can either be a number or "$" followed by the name
223 of a convenience variable. Making it an expression wouldn't work well
224 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
233 /* Empty line means refer to the last breakpoint. */
234 return breakpoint_count
;
237 /* Make a copy of the name, so we can null-terminate it
238 to pass to lookup_internalvar(). */
243 while (isalnum (*p
) || *p
== '_')
245 varname
= (char *) alloca (p
- start
+ 1);
246 strncpy (varname
, start
, p
- start
);
247 varname
[p
- start
] = '\0';
248 val
= value_of_internalvar (lookup_internalvar (varname
));
249 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
251 "Convenience variables used to specify breakpoints must have integer values."
253 retval
= (int) value_as_long (val
);
259 while (*p
>= '0' && *p
<= '9')
262 /* There is no number here. (e.g. "cond a == b"). */
263 error_no_arg ("breakpoint number");
266 if (!(isspace (*p
) || *p
== '\0'))
267 error ("breakpoint number expected");
274 /* condition N EXP -- set break condition of breakpoint N to EXP. */
277 condition_command (arg
, from_tty
)
281 register struct breakpoint
*b
;
286 error_no_arg ("breakpoint number");
289 bnum
= get_number (&p
);
292 if (b
->number
== bnum
)
299 if (b
->cond_string
!= NULL
)
300 free ((PTR
)b
->cond_string
);
305 b
->cond_string
= NULL
;
307 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
312 /* I don't know if it matters whether this is the string the user
313 typed in or the decompiled expression. */
314 b
->cond_string
= savestring (arg
, strlen (arg
));
315 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
317 error ("Junk at end of expression");
322 error ("No breakpoint number %d.", bnum
);
327 commands_command (arg
, from_tty
)
331 register struct breakpoint
*b
;
334 struct command_line
*l
;
336 /* If we allowed this, we would have problems with when to
337 free the storage, if we change the commands currently
340 if (executing_breakpoint_commands
)
341 error ("Can't use the \"commands\" command among a breakpoint's commands.");
344 bnum
= get_number (&p
);
346 error ("Unexpected extra arguments following breakpoint number.");
349 if (b
->number
== bnum
)
351 if (from_tty
&& input_from_terminal_p ())
352 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
353 End with a line saying just \"end\".\n", bnum
);
354 l
= read_command_lines ();
355 free_command_lines (&b
->commands
);
357 breakpoints_changed ();
360 error ("No breakpoint number %d.", bnum
);
363 extern int memory_breakpoint_size
; /* from mem-break.c */
365 /* Like target_read_memory() but if breakpoints are inserted, return
366 the shadow contents instead of the breakpoints themselves.
368 Read "memory data" from whatever target or inferior we have.
369 Returns zero if successful, errno value if not. EIO is used
370 for address out of bounds. If breakpoints are inserted, returns
371 shadow contents, not the breakpoints themselves. From breakpoint.c. */
374 read_memory_nobpt (memaddr
, myaddr
, len
)
380 struct breakpoint
*b
;
382 if (memory_breakpoint_size
< 0)
383 /* No breakpoints on this machine. FIXME: This should be
384 dependent on the debugging target. Probably want
385 target_insert_breakpoint to return a size, saying how many
386 bytes of the shadow contents are used, or perhaps have
387 something like target_xfer_shadow. */
388 return target_read_memory (memaddr
, myaddr
, len
);
392 if (b
->type
== bp_watchpoint
393 || b
->type
== bp_hardware_watchpoint
394 || b
->type
== bp_read_watchpoint
395 || b
->type
== bp_access_watchpoint
398 else if (b
->address
+ memory_breakpoint_size
<= memaddr
)
399 /* The breakpoint is entirely before the chunk of memory
402 else if (b
->address
>= memaddr
+ len
)
403 /* The breakpoint is entirely after the chunk of memory we
408 /* Copy the breakpoint from the shadow contents, and recurse
409 for the things before and after. */
411 /* Addresses and length of the part of the breakpoint that
413 CORE_ADDR membpt
= b
->address
;
414 unsigned int bptlen
= memory_breakpoint_size
;
415 /* Offset within shadow_contents. */
418 if (membpt
< memaddr
)
420 /* Only copy the second part of the breakpoint. */
421 bptlen
-= memaddr
- membpt
;
422 bptoffset
= memaddr
- membpt
;
426 if (membpt
+ bptlen
> memaddr
+ len
)
428 /* Only copy the first part of the breakpoint. */
429 bptlen
-= (membpt
+ bptlen
) - (memaddr
+ len
);
432 memcpy (myaddr
+ membpt
- memaddr
,
433 b
->shadow_contents
+ bptoffset
, bptlen
);
435 if (membpt
> memaddr
)
437 /* Copy the section of memory before the breakpoint. */
438 status
= read_memory_nobpt (memaddr
, myaddr
, membpt
- memaddr
);
443 if (membpt
+ bptlen
< memaddr
+ len
)
445 /* Copy the section of memory after the breakpoint. */
446 status
= read_memory_nobpt
448 myaddr
+ membpt
+ bptlen
- memaddr
,
449 memaddr
+ len
- (membpt
+ bptlen
));
456 /* Nothing overlaps. Just call read_memory_noerr. */
457 return target_read_memory (memaddr
, myaddr
, len
);
460 /* insert_breakpoints is used when starting or continuing the program.
461 remove_breakpoints is used when the program stops.
462 Both return zero if successful,
463 or an `errno' value if could not write the inferior. */
466 insert_breakpoints ()
468 register struct breakpoint
*b
;
470 int disabled_breaks
= 0;
473 if (b
->type
!= bp_watchpoint
474 && b
->type
!= bp_hardware_watchpoint
475 && b
->type
!= bp_read_watchpoint
476 && b
->type
!= bp_access_watchpoint
477 && b
->enable
!= disabled
481 if (b
->type
== bp_hardware_breakpoint
)
482 val
= target_insert_hw_breakpoint(b
->address
, b
->shadow_contents
);
484 val
= target_insert_breakpoint(b
->address
, b
->shadow_contents
);
487 /* Can't set the breakpoint. */
488 #if defined (DISABLE_UNSETTABLE_BREAK)
489 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
492 b
->enable
= disabled
;
493 if (!disabled_breaks
)
495 target_terminal_ours_for_output ();
496 fprintf_unfiltered (gdb_stderr
,
497 "Cannot insert breakpoint %d:\n", b
->number
);
498 printf_filtered ("Disabling shared library breakpoints:\n");
501 printf_filtered ("%d ", b
->number
);
506 target_terminal_ours_for_output ();
507 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
508 #ifdef ONE_PROCESS_WRITETEXT
509 fprintf_unfiltered (gdb_stderr
,
510 "The same program may be running in another process.\n");
512 memory_error (val
, b
->address
); /* which bombs us out */
518 else if ((b
->type
== bp_hardware_watchpoint
||
519 b
->type
== bp_read_watchpoint
||
520 b
->type
== bp_access_watchpoint
)
521 && b
->enable
== enabled
526 int saved_level
, within_current_scope
;
527 value_ptr mark
= value_mark ();
530 /* Save the current frame and level so we can restore it after
531 evaluating the watchpoint expression on its own frame. */
532 saved_frame
= selected_frame
;
533 saved_level
= selected_frame_level
;
535 /* Determine if the watchpoint is within scope. */
536 if (b
->exp_valid_block
== NULL
)
537 within_current_scope
= 1;
540 FRAME fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
541 within_current_scope
= (fr
!= NULL
);
542 if (within_current_scope
)
543 select_frame (fr
, -1);
546 if (within_current_scope
)
548 /* Evaluate the expression and cut the chain of values
549 produced off from the value chain. */
550 v
= evaluate_expression (b
->exp
);
551 value_release_to_mark (mark
);
556 /* Look at each value on the value chain. */
557 for ( ; v
; v
=v
->next
)
559 /* If it's a memory location, then we must watch it. */
560 if (v
->lval
== lval_memory
)
564 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
565 len
= TYPE_LENGTH (VALUE_TYPE (v
));
567 if (b
->type
== bp_read_watchpoint
)
569 else if (b
->type
== bp_access_watchpoint
)
572 val
= target_insert_watchpoint (addr
, len
, type
);
581 /* Failure to insert a watchpoint on any memory value in the
582 value chain brings us here. */
584 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
590 Hardware watchpoint %d deleted because the program has left the block in\n\
591 which its expression is valid.\n", b
->number
);
592 if (b
->related_breakpoint
)
593 delete_breakpoint (b
->related_breakpoint
);
594 delete_breakpoint (b
);
597 /* Restore the frame and level. */
598 select_frame (saved_frame
, saved_level
);
601 printf_filtered ("\n");
607 remove_breakpoints ()
609 register struct breakpoint
*b
;
616 val
= remove_breakpoint (b
);
626 remove_breakpoint (b
)
627 struct breakpoint
*b
;
631 if (b
->type
!= bp_watchpoint
632 && b
->type
!= bp_hardware_watchpoint
633 && b
->type
!= bp_read_watchpoint
634 && b
->type
!= bp_access_watchpoint
)
636 if (b
->type
== bp_hardware_breakpoint
)
637 val
= target_remove_hw_breakpoint(b
->address
, b
->shadow_contents
);
639 val
= target_remove_breakpoint(b
->address
, b
->shadow_contents
);
644 else if ((b
->type
== bp_hardware_watchpoint
||
645 b
->type
== bp_read_watchpoint
||
646 b
->type
== bp_access_watchpoint
)
647 && b
->enable
== enabled
653 /* Walk down the saved value chain. */
654 for (v
= b
->val_chain
; v
; v
= v
->next
)
656 /* For each memory reference remove the watchpoint
658 if (v
->lval
== lval_memory
)
662 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
663 len
= TYPE_LENGTH (VALUE_TYPE (v
));
664 val
= target_remove_watchpoint (addr
, len
, b
->type
);
670 /* Failure to remove any of the hardware watchpoints comes here. */
672 error ("Hardware watchpoint %d: Could not remove watchpoint\n",
675 /* Free the saved value chain. We will construct a new one
676 the next time the watchpoint is inserted. */
677 for (v
= b
->val_chain
; v
; v
= n
)
687 /* Clear the "inserted" flag in all breakpoints. */
690 mark_breakpoints_out ()
692 register struct breakpoint
*b
;
698 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
699 which should go away between runs of the program. */
702 breakpoint_init_inferior ()
704 register struct breakpoint
*b
, *temp
;
706 ALL_BREAKPOINTS_SAFE (b
, temp
)
710 /* If the call dummy breakpoint is at the entry point it will
711 cause problems when the inferior is rerun, so we better
713 if (b
->type
== bp_call_dummy
)
714 delete_breakpoint (b
);
716 /* Likewise for scope breakpoints. */
717 if (b
->type
== bp_watchpoint_scope
)
718 delete_breakpoint (b
);
720 /* Likewise for watchpoints on local expressions. */
721 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
||
722 b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
723 && b
->exp_valid_block
!= NULL
)
724 delete_breakpoint (b
);
728 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
729 When continuing from a location with a breakpoint,
730 we actually single step once before calling insert_breakpoints. */
733 breakpoint_here_p (pc
)
736 register struct breakpoint
*b
;
739 if (b
->enable
!= disabled
&& b
->address
== pc
)
745 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
746 because figuring out the saved SP would take too much time, at least using
747 get_saved_register on the 68k. This means that for this function to
748 work right a port must use the bp_call_dummy breakpoint. */
751 frame_in_dummy (frame
)
754 struct breakpoint
*b
;
759 static unsigned LONGEST dummy
[] = CALL_DUMMY
;
761 if (b
->type
== bp_call_dummy
762 && b
->frame
== frame
->frame
764 /* We need to check the PC as well as the frame on the sparc,
765 for signals.exp in the testsuite. */
768 - sizeof (dummy
) / sizeof (LONGEST
) * REGISTER_SIZE
))
769 && frame
->pc
<= b
->address
)
772 #endif /* CALL_DUMMY */
776 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
777 is valid for process/thread PID. */
780 breakpoint_thread_match (pc
, pid
)
784 struct breakpoint
*b
;
787 thread
= pid_to_thread_id (pid
);
790 if (b
->enable
!= disabled
792 && (b
->thread
== -1 || b
->thread
== thread
))
799 /* bpstat stuff. External routines' interfaces are documented
802 /* Clear a bpstat so that it says we are not at any breakpoint.
803 Also free any storage that is part of a bpstat. */
818 if (p
->old_val
!= NULL
)
819 value_free (p
->old_val
);
826 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
827 is part of the bpstat is copied as well. */
835 bpstat retval
= NULL
;
840 for (; bs
!= NULL
; bs
= bs
->next
)
842 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
843 memcpy (tmp
, bs
, sizeof (*tmp
));
845 /* This is the first thing in the chain. */
855 /* Find the bpstat associated with this breakpoint */
858 bpstat_find_breakpoint(bsp
, breakpoint
)
860 struct breakpoint
*breakpoint
;
862 if (bsp
== NULL
) return NULL
;
864 for (;bsp
!= NULL
; bsp
= bsp
->next
) {
865 if (bsp
->breakpoint_at
== breakpoint
) return bsp
;
870 /* Return the breakpoint number of the first breakpoint we are stopped
871 at. *BSP upon return is a bpstat which points to the remaining
872 breakpoints stopped at (but which is not guaranteed to be good for
873 anything but further calls to bpstat_num).
874 Return 0 if passed a bpstat which does not indicate any breakpoints. */
880 struct breakpoint
*b
;
883 return 0; /* No more breakpoint values */
886 b
= (*bsp
)->breakpoint_at
;
889 return -1; /* breakpoint that's been deleted since */
891 return b
->number
; /* We have its number */
895 /* Modify BS so that the actions will not be performed. */
898 bpstat_clear_actions (bs
)
901 for (; bs
!= NULL
; bs
= bs
->next
)
904 if (bs
->old_val
!= NULL
)
906 value_free (bs
->old_val
);
912 /* Stub for cleaning up our state if we error-out of a breakpoint command */
915 cleanup_executing_breakpoints (ignore
)
918 executing_breakpoint_commands
= 0;
921 /* Execute all the commands associated with all the breakpoints at this
922 location. Any of these commands could cause the process to proceed
923 beyond this point, etc. We look out for such changes by checking
924 the global "breakpoint_proceeded" after each command. */
927 bpstat_do_actions (bsp
)
931 struct cleanup
*old_chain
;
933 executing_breakpoint_commands
= 1;
934 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
939 breakpoint_proceeded
= 0;
940 for (; bs
!= NULL
; bs
= bs
->next
)
944 char *line
= bs
->commands
->line
;
945 bs
->commands
= bs
->commands
->next
;
946 execute_command (line
, 0);
947 /* If the inferior is proceeded by the command, bomb out now.
948 The bpstat chain has been blown away by wait_for_inferior.
949 But since execution has stopped again, there is a new bpstat
950 to look at, so start over. */
951 if (breakpoint_proceeded
)
956 executing_breakpoint_commands
= 0;
957 discard_cleanups (old_chain
);
960 /* This is the normal print_it function for a bpstat. In the future,
961 much of this logic could (should?) be moved to bpstat_stop_status,
962 by having it set different print_it functions. */
968 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
969 which has since been deleted. */
970 if (bs
->breakpoint_at
== NULL
971 || (bs
->breakpoint_at
->type
!= bp_breakpoint
972 && bs
->breakpoint_at
->type
!= bp_hardware_breakpoint
973 && bs
->breakpoint_at
->type
!= bp_watchpoint
974 && bs
->breakpoint_at
->type
!= bp_read_watchpoint
975 && bs
->breakpoint_at
->type
!= bp_access_watchpoint
976 && bs
->breakpoint_at
->type
!= bp_hardware_watchpoint
))
979 if (bs
->breakpoint_at
->type
== bp_breakpoint
||
980 bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
982 /* I think the user probably only wants to see one breakpoint
983 number, not all of them. */
984 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
987 else if ((bs
->old_val
!= NULL
) &&
988 (bs
->breakpoint_at
->type
== bp_watchpoint
||
989 bs
->breakpoint_at
->type
== bp_access_watchpoint
||
990 bs
->breakpoint_at
->type
== bp_hardware_watchpoint
))
992 mention (bs
->breakpoint_at
);
993 printf_filtered ("\nOld value = ");
994 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
995 printf_filtered ("\nNew value = ");
996 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
998 printf_filtered ("\n");
999 value_free (bs
->old_val
);
1001 /* More than one watchpoint may have been triggered. */
1004 else if (bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1005 bs
->breakpoint_at
->type
== bp_read_watchpoint
)
1007 mention (bs
->breakpoint_at
);
1008 printf_filtered ("\nValue = ");
1009 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1010 Val_pretty_default
);
1011 printf_filtered ("\n");
1014 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1018 /* Print a message indicating what happened. Returns nonzero to
1019 say that only the source line should be printed after this (zero
1020 return means print the frame as well as the source line). */
1021 /* Currently we always return zero. */
1031 val
= (*bs
->print_it
) (bs
);
1035 /* Maybe another breakpoint in the chain caused us to stop.
1036 (Currently all watchpoints go on the bpstat whether hit or
1037 not. That probably could (should) be changed, provided care is taken
1038 with respect to bpstat_explains_signal). */
1040 return bpstat_print (bs
->next
);
1042 /* We reached the end of the chain without printing anything. */
1046 /* Evaluate the expression EXP and return 1 if value is zero.
1047 This is used inside a catch_errors to evaluate the breakpoint condition.
1048 The argument is a "struct expression *" that has been cast to char * to
1049 make it pass through catch_errors. */
1052 breakpoint_cond_eval (exp
)
1055 value_ptr mark
= value_mark ();
1056 int i
= !value_true (evaluate_expression ((struct expression
*)exp
));
1057 value_free_to_mark (mark
);
1061 /* Allocate a new bpstat and chain it to the current one. */
1064 bpstat_alloc (b
, cbs
)
1065 register struct breakpoint
*b
;
1066 bpstat cbs
; /* Current "bs" value */
1070 bs
= (bpstat
) xmalloc (sizeof (*bs
));
1072 bs
->breakpoint_at
= b
;
1073 /* If the condition is false, etc., don't do the commands. */
1074 bs
->commands
= NULL
;
1076 bs
->print_it
= print_it_normal
;
1082 /* Possible return values for watchpoint_check (this can't be an enum
1083 because of check_errors). */
1084 /* The watchpoint has been deleted. */
1085 #define WP_DELETED 1
1086 /* The value has changed. */
1087 #define WP_VALUE_CHANGED 2
1088 /* The value has not changed. */
1089 #define WP_VALUE_NOT_CHANGED 3
1091 /* Check watchpoint condition. */
1093 watchpoint_check (p
)
1096 bpstat bs
= (bpstat
) p
;
1097 struct breakpoint
*b
;
1098 FRAME saved_frame
, fr
;
1099 int within_current_scope
, saved_level
;
1101 /* Save the current frame and level so we can restore it after
1102 evaluating the watchpoint expression on its own frame. */
1103 saved_frame
= selected_frame
;
1104 saved_level
= selected_frame_level
;
1106 if (bs
->breakpoint_at
->exp_valid_block
== NULL
)
1107 within_current_scope
= 1;
1110 fr
= find_frame_addr_in_frame_chain (bs
->breakpoint_at
->watchpoint_frame
);
1111 within_current_scope
= (fr
!= NULL
);
1112 if (within_current_scope
)
1113 /* If we end up stopping, the current frame will get selected
1114 in normal_stop. So this call to select_frame won't affect
1116 select_frame (fr
, -1);
1119 if (within_current_scope
)
1121 /* We use value_{,free_to_}mark because it could be a
1122 *long* time before we return to the command level and
1123 call free_all_values. We can't call free_all_values because
1124 we might be in the middle of evaluating a function call. */
1126 value_ptr mark
= value_mark ();
1127 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
1128 if (!value_equal (bs
->breakpoint_at
->val
, new_val
))
1130 release_value (new_val
);
1131 value_free_to_mark (mark
);
1132 bs
->old_val
= bs
->breakpoint_at
->val
;
1133 bs
->breakpoint_at
->val
= new_val
;
1134 /* We will stop here */
1135 select_frame (saved_frame
, saved_level
);
1136 return WP_VALUE_CHANGED
;
1140 /* Nothing changed, don't do anything. */
1141 value_free_to_mark (mark
);
1142 /* We won't stop here */
1143 select_frame (saved_frame
, saved_level
);
1144 return WP_VALUE_NOT_CHANGED
;
1149 /* This seems like the only logical thing to do because
1150 if we temporarily ignored the watchpoint, then when
1151 we reenter the block in which it is valid it contains
1152 garbage (in the case of a function, it may have two
1153 garbage values, one before and one after the prologue).
1154 So we can't even detect the first assignment to it and
1155 watch after that (since the garbage may or may not equal
1156 the first value assigned). */
1158 Watchpoint %d deleted because the program has left the block in\n\
1159 which its expression is valid.\n", bs
->breakpoint_at
->number
);
1160 if (bs
->breakpoint_at
->related_breakpoint
)
1161 delete_breakpoint (bs
->breakpoint_at
->related_breakpoint
);
1162 delete_breakpoint (bs
->breakpoint_at
);
1164 select_frame (saved_frame
, saved_level
);
1169 /* This is used when everything which needs to be printed has
1170 already been printed. But we still want to print the frame. */
1178 /* This is used when nothing should be printed for this bpstat entry. */
1187 /* Get a bpstat associated with having just stopped at address *PC
1188 and frame address FRAME_ADDRESS. Update *PC to point at the
1189 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1190 if this is known to not be a real breakpoint (it could still be a
1191 watchpoint, though). */
1193 /* Determine whether we stopped at a breakpoint, etc, or whether we
1194 don't understand this stop. Result is a chain of bpstat's such that:
1196 if we don't understand the stop, the result is a null pointer.
1198 if we understand why we stopped, the result is not null.
1200 Each element of the chain refers to a particular breakpoint or
1201 watchpoint at which we have stopped. (We may have stopped for
1202 several reasons concurrently.)
1204 Each element of the chain has valid next, breakpoint_at,
1205 commands, FIXME??? fields.
1210 bpstat_stop_status (pc
, frame_address
, not_a_breakpoint
)
1212 FRAME_ADDR frame_address
;
1213 int not_a_breakpoint
;
1215 register struct breakpoint
*b
;
1217 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1218 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1219 int real_breakpoint
= 0;
1221 /* Root of the chain of bpstat's */
1222 struct bpstat root_bs
[1];
1223 /* Pointer to the last thing in the chain currently. */
1224 bpstat bs
= root_bs
;
1225 static char message1
[] =
1226 "Error evaluating expression for watchpoint %d\n";
1227 char message
[sizeof (message1
) + 30 /* slop */];
1229 /* Get the address where the breakpoint would have been. */
1230 bp_addr
= *pc
- DECR_PC_AFTER_BREAK
;
1234 if (b
->enable
== disabled
)
1237 if (b
->type
!= bp_watchpoint
1238 && b
->type
!= bp_hardware_watchpoint
1239 && b
->type
!= bp_read_watchpoint
1240 && b
->type
!= bp_access_watchpoint
1241 && b
->type
!= bp_hardware_breakpoint
1242 && b
->address
!= bp_addr
)
1245 #ifndef DECR_PC_AFTER_HW_BREAK
1246 #define DECR_PC_AFTER_HW_BREAK 0
1248 if (b
->type
== bp_hardware_breakpoint
1249 && b
->address
!= (bp_addr
- DECR_PC_AFTER_HW_BREAK
))
1252 if (b
->type
!= bp_watchpoint
1253 && b
->type
!= bp_hardware_watchpoint
1254 && b
->type
!= bp_read_watchpoint
1255 && b
->type
!= bp_access_watchpoint
1256 && not_a_breakpoint
)
1259 /* Come here if it's a watchpoint, or if the break address matches */
1261 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
1266 sprintf (message
, message1
, b
->number
);
1267 if (b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1269 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1273 /* We've already printed what needs to be printed. */
1274 bs
->print_it
= print_it_done
;
1277 case WP_VALUE_CHANGED
:
1280 case WP_VALUE_NOT_CHANGED
:
1282 bs
->print_it
= print_it_noop
;
1289 /* Error from catch_errors. */
1290 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1291 if (b
->related_breakpoint
)
1292 delete_breakpoint (b
->related_breakpoint
);
1293 delete_breakpoint (b
);
1294 /* We've already printed what needs to be printed. */
1295 bs
->print_it
= print_it_done
;
1301 else if (b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
1307 addr
= target_stopped_data_address();
1308 if (addr
== 0) continue;
1309 for (v
= b
->val_chain
; v
; v
= v
->next
)
1311 if (v
->lval
== lval_memory
)
1315 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1321 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1325 /* We've already printed what needs to be printed. */
1326 bs
->print_it
= print_it_done
;
1329 case WP_VALUE_CHANGED
:
1330 case WP_VALUE_NOT_CHANGED
:
1336 /* Error from catch_errors. */
1337 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1338 if (b
->related_breakpoint
)
1339 delete_breakpoint (b
->related_breakpoint
);
1340 delete_breakpoint (b
);
1341 /* We've already printed what needs to be printed. */
1342 bs
->print_it
= print_it_done
;
1346 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1348 real_breakpoint
= 1;
1351 if (b
->frame
&& b
->frame
!= frame_address
)
1355 int value_is_zero
= 0;
1359 /* Need to select the frame, with all that implies
1360 so that the conditions will have the right context. */
1361 select_frame (get_current_frame (), 0);
1363 = catch_errors (breakpoint_cond_eval
, (char *)(b
->cond
),
1364 "Error in testing breakpoint condition:\n",
1366 /* FIXME-someday, should give breakpoint # */
1369 if (b
->cond
&& value_is_zero
)
1373 else if (b
->ignore_count
> 0)
1380 /* We will stop here */
1381 if (b
->disposition
== disable
)
1382 b
->enable
= disabled
;
1383 bs
->commands
= b
->commands
;
1386 if (bs
->commands
&& STREQ ("silent", bs
->commands
->line
))
1388 bs
->commands
= bs
->commands
->next
;
1393 /* Print nothing for this entry if we dont stop or if we dont print. */
1394 if (bs
->stop
== 0 || bs
->print
== 0)
1395 bs
->print_it
= print_it_noop
;
1398 bs
->next
= NULL
; /* Terminate the chain */
1399 bs
= root_bs
->next
; /* Re-grab the head of the chain */
1400 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1403 if (real_breakpoint
)
1406 #if defined (SHIFT_INST_REGS)
1408 #else /* No SHIFT_INST_REGS. */
1410 #endif /* No SHIFT_INST_REGS. */
1413 #endif /* DECR_PC_AFTER_BREAK != 0. */
1415 /* The value of a hardware watchpoint hasn't changed, but the
1416 intermediate memory locations we are watching may have. */
1417 if (bs
&& ! bs
->stop
&&
1418 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
1419 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
1420 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
1422 remove_breakpoints ();
1423 insert_breakpoints ();
1428 /* Tell what to do about this bpstat. */
1433 /* Classify each bpstat as one of the following. */
1435 /* This bpstat element has no effect on the main_action. */
1438 /* There was a watchpoint, stop but don't print. */
1441 /* There was a watchpoint, stop and print. */
1444 /* There was a breakpoint but we're not stopping. */
1447 /* There was a breakpoint, stop but don't print. */
1450 /* There was a breakpoint, stop and print. */
1453 /* We hit the longjmp breakpoint. */
1456 /* We hit the longjmp_resume breakpoint. */
1459 /* We hit the step_resume breakpoint. */
1462 /* We hit the through_sigtramp breakpoint. */
1465 /* This is just used to count how many enums there are. */
1469 /* Here is the table which drives this routine. So that we can
1470 format it pretty, we define some abbreviations for the
1471 enum bpstat_what codes. */
1472 #define keep_c BPSTAT_WHAT_KEEP_CHECKING
1473 #define stop_s BPSTAT_WHAT_STOP_SILENT
1474 #define stop_n BPSTAT_WHAT_STOP_NOISY
1475 #define single BPSTAT_WHAT_SINGLE
1476 #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1477 #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1478 #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1479 #define sr BPSTAT_WHAT_STEP_RESUME
1480 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1482 /* "Can't happen." Might want to print an error message.
1483 abort() is not out of the question, but chances are GDB is just
1484 a bit confused, not unusable. */
1485 #define err BPSTAT_WHAT_STOP_NOISY
1487 /* Given an old action and a class, come up with a new action. */
1488 /* One interesting property of this table is that wp_silent is the same
1489 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1490 after stopping, the check for whether to step over a breakpoint
1491 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1492 reference to how we stopped. We retain separate wp_silent and bp_silent
1493 codes in case we want to change that someday. */
1495 /* step_resume entries: a step resume breakpoint overrides another
1496 breakpoint of signal handling (see comment in wait_for_inferior
1497 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1498 /* We handle the through_sigtramp_breakpoint the same way; having both
1499 one of those and a step_resume_breakpoint is probably very rare (?). */
1501 static const enum bpstat_what_main_action
1502 table
[(int)class_last
][(int)BPSTAT_WHAT_LAST
] =
1505 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts
1507 /*no_effect*/ {keep_c
,stop_s
,stop_n
,single
, setlr
, clrlr
, clrlrs
, sr
, ts
},
1508 /*wp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1509 /*wp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1510 /*bp_nostop*/ {single
,stop_s
,stop_n
,single
, setlr
, clrlrs
, clrlrs
, sr
, ts
},
1511 /*bp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1512 /*bp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1513 /*long_jump*/ {setlr
,stop_s
,stop_n
,setlr
, err
, err
, err
, sr
, ts
},
1514 /*long_resume*/ {clrlr
,stop_s
,stop_n
,clrlrs
, err
, err
, err
, sr
, ts
},
1515 /*step_resume*/ {sr
,sr
,sr
,sr
, sr
, sr
, sr
, sr
, ts
},
1516 /*through_sig*/ {ts
,ts
,ts
,ts
, ts
, ts
, ts
, ts
, ts
}
1528 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
1529 struct bpstat_what retval
;
1531 retval
.call_dummy
= 0;
1532 for (; bs
!= NULL
; bs
= bs
->next
)
1534 enum class bs_class
= no_effect
;
1535 if (bs
->breakpoint_at
== NULL
)
1536 /* I suspect this can happen if it was a momentary breakpoint
1537 which has since been deleted. */
1539 switch (bs
->breakpoint_at
->type
)
1542 case bp_hardware_breakpoint
:
1548 bs_class
= bp_noisy
;
1550 bs_class
= bp_silent
;
1553 bs_class
= bp_nostop
;
1556 case bp_hardware_watchpoint
:
1557 case bp_read_watchpoint
:
1558 case bp_access_watchpoint
:
1562 bs_class
= wp_noisy
;
1564 bs_class
= wp_silent
;
1567 /* There was a watchpoint, but we're not stopping. This requires
1568 no further action. */
1569 bs_class
= no_effect
;
1572 bs_class
= long_jump
;
1574 case bp_longjmp_resume
:
1575 bs_class
= long_resume
;
1577 case bp_step_resume
:
1580 bs_class
= step_resume
;
1583 /* It is for the wrong frame. */
1584 bs_class
= bp_nostop
;
1586 case bp_through_sigtramp
:
1587 bs_class
= through_sig
;
1589 case bp_watchpoint_scope
:
1590 bs_class
= bp_nostop
;
1594 /* Make sure the action is stop (silent or noisy), so infrun.c
1595 pops the dummy frame. */
1596 bs_class
= bp_silent
;
1597 retval
.call_dummy
= 1;
1600 current_action
= table
[(int)bs_class
][(int)current_action
];
1602 retval
.main_action
= current_action
;
1606 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1607 without hardware support). This isn't related to a specific bpstat,
1608 just to things like whether watchpoints are set. */
1611 bpstat_should_step ()
1613 struct breakpoint
*b
;
1615 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
1620 /* Print information on breakpoint number BNUM, or -1 if all.
1621 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1622 is nonzero, process only watchpoints. */
1625 breakpoint_1 (bnum
, allflag
)
1629 register struct breakpoint
*b
;
1630 register struct command_line
*l
;
1631 register struct symbol
*sym
;
1632 CORE_ADDR last_addr
= (CORE_ADDR
)-1;
1633 int found_a_breakpoint
= 0;
1634 static char *bptypes
[] = {"breakpoint", "hw breakpoint",
1635 "until", "finish", "watchpoint",
1636 "hw watchpoint", "read watchpoint",
1637 "acc watchpoint", "longjmp",
1638 "longjmp resume", "step resume",
1639 "watchpoint scope", "call dummy" };
1640 static char *bpdisps
[] = {"del", "dis", "keep"};
1641 static char bpenables
[] = "ny";
1642 char wrap_indent
[80];
1646 || bnum
== b
->number
)
1648 /* We only print out user settable breakpoints unless the allflag is set. */
1650 && b
->type
!= bp_breakpoint
1651 && b
->type
!= bp_hardware_breakpoint
1652 && b
->type
!= bp_watchpoint
1653 && b
->type
!= bp_read_watchpoint
1654 && b
->type
!= bp_access_watchpoint
1655 && b
->type
!= bp_hardware_watchpoint
)
1658 if (!found_a_breakpoint
++)
1660 if (annotation_level
> 1)
1661 printf_filtered ("\n\032\032breakpoints-headers\n");
1663 printf_filtered ("Num Type Disp Enb %sWhat\n",
1664 addressprint
? "Address " : "");
1666 if (annotation_level
> 1)
1667 printf_filtered ("\n\032\032breakpoints-table\n");
1670 if (annotation_level
> 1)
1671 printf_filtered ("\n\032\032field 0\n");
1672 printf_filtered ("%-3d ", b
->number
);
1673 if (annotation_level
> 1)
1674 printf_filtered ("\n\032\032field 1\n");
1675 printf_filtered ("%-14s ", bptypes
[(int)b
->type
]);
1676 if (annotation_level
> 1)
1677 printf_filtered ("\n\032\032field 2\n");
1678 printf_filtered ("%-4s ", bpdisps
[(int)b
->disposition
]);
1679 if (annotation_level
> 1)
1680 printf_filtered ("\n\032\032field 3\n");
1681 printf_filtered ("%-3c ", bpenables
[(int)b
->enable
]);
1683 strcpy (wrap_indent
, " ");
1685 strcat (wrap_indent
, " ");
1689 case bp_hardware_watchpoint
:
1690 case bp_read_watchpoint
:
1691 case bp_access_watchpoint
:
1692 /* Field 4, the address, is omitted (which makes the columns
1693 not line up too nicely with the headers, but the effect
1694 is relatively readable). */
1695 if (annotation_level
> 1)
1696 printf_filtered ("\n\032\032field 5\n");
1697 print_expression (b
->exp
, gdb_stdout
);
1701 case bp_hardware_breakpoint
:
1705 case bp_longjmp_resume
:
1706 case bp_step_resume
:
1707 case bp_through_sigtramp
:
1708 case bp_watchpoint_scope
:
1712 if (annotation_level
> 1)
1713 printf_filtered ("\n\032\032field 4\n");
1714 /* FIXME-32x64: need a print_address_numeric with
1718 local_hex_string_custom
1719 ((unsigned long) b
->address
, "08l"));
1722 if (annotation_level
> 1)
1723 printf_filtered ("\n\032\032field 5\n");
1725 last_addr
= b
->address
;
1728 sym
= find_pc_function (b
->address
);
1731 fputs_filtered ("in ", gdb_stdout
);
1732 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
1733 wrap_here (wrap_indent
);
1734 fputs_filtered (" at ", gdb_stdout
);
1736 fputs_filtered (b
->source_file
, gdb_stdout
);
1737 printf_filtered (":%d", b
->line_number
);
1740 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
1744 printf_filtered ("\n");
1748 if (annotation_level
> 1)
1749 printf_filtered ("\n\032\032field 6\n");
1751 printf_filtered ("\tstop only in stack frame at ");
1752 print_address_numeric (b
->frame
, 1, gdb_stdout
);
1753 printf_filtered ("\n");
1758 if (annotation_level
> 1)
1759 printf_filtered ("\n\032\032field 7\n");
1761 printf_filtered ("\tstop only if ");
1762 print_expression (b
->cond
, gdb_stdout
);
1763 printf_filtered ("\n");
1766 if (b
->ignore_count
)
1768 if (annotation_level
> 1)
1769 printf_filtered ("\n\032\032field 8\n");
1771 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
1774 if ((l
= b
->commands
))
1776 if (annotation_level
> 1)
1777 printf_filtered ("\n\032\032field 9\n");
1781 fputs_filtered ("\t", gdb_stdout
);
1782 fputs_filtered (l
->line
, gdb_stdout
);
1783 fputs_filtered ("\n", gdb_stdout
);
1789 if (!found_a_breakpoint
)
1792 printf_filtered ("No breakpoints or watchpoints.\n");
1794 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
1797 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1798 that a comparison of an unsigned with -1 is always false. */
1799 if (last_addr
!= (CORE_ADDR
)-1)
1800 set_next_address (last_addr
);
1802 if (annotation_level
> 1)
1803 printf_filtered ("\n\032\032breakpoints-table-end\n");
1808 breakpoints_info (bnum_exp
, from_tty
)
1815 bnum
= parse_and_eval_address (bnum_exp
);
1817 breakpoint_1 (bnum
, 0);
1820 #if MAINTENANCE_CMDS
1824 maintenance_info_breakpoints (bnum_exp
, from_tty
)
1831 bnum
= parse_and_eval_address (bnum_exp
);
1833 breakpoint_1 (bnum
, 1);
1838 /* Print a message describing any breakpoints set at PC. */
1841 describe_other_breakpoints (pc
)
1842 register CORE_ADDR pc
;
1844 register int others
= 0;
1845 register struct breakpoint
*b
;
1848 if (b
->address
== pc
)
1852 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
1854 if (b
->address
== pc
)
1860 (b
->enable
== disabled
) ? " (disabled)" : "",
1861 (others
> 1) ? "," : ((others
== 1) ? " and" : ""));
1863 printf_filtered ("also set at pc ");
1864 print_address_numeric (pc
, 1, gdb_stdout
);
1865 printf_filtered (".\n");
1869 /* Set the default place to put a breakpoint
1870 for the `break' command with no arguments. */
1873 set_default_breakpoint (valid
, addr
, symtab
, line
)
1876 struct symtab
*symtab
;
1879 default_breakpoint_valid
= valid
;
1880 default_breakpoint_address
= addr
;
1881 default_breakpoint_symtab
= symtab
;
1882 default_breakpoint_line
= line
;
1885 /* Rescan breakpoints at address ADDRESS,
1886 marking the first one as "first" and any others as "duplicates".
1887 This is so that the bpt instruction is only inserted once. */
1890 check_duplicates (address
)
1893 register struct breakpoint
*b
;
1894 register int count
= 0;
1896 if (address
== 0) /* Watchpoints are uninteresting */
1900 if (b
->enable
!= disabled
&& b
->address
== address
)
1903 b
->duplicate
= count
> 1;
1907 /* Low level routine to set a breakpoint.
1908 Takes as args the three things that every breakpoint must have.
1909 Returns the breakpoint object so caller can set other things.
1910 Does not set the breakpoint number!
1911 Does not print anything.
1913 ==> This routine should not be called if there is a chance of later
1914 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1915 your arguments BEFORE calling this routine! */
1917 static struct breakpoint
*
1918 set_raw_breakpoint (sal
)
1919 struct symtab_and_line sal
;
1921 register struct breakpoint
*b
, *b1
;
1923 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
1924 memset (b
, 0, sizeof (*b
));
1925 b
->address
= sal
.pc
;
1926 if (sal
.symtab
== NULL
)
1927 b
->source_file
= NULL
;
1929 b
->source_file
= savestring (sal
.symtab
->filename
,
1930 strlen (sal
.symtab
->filename
));
1932 b
->line_number
= sal
.line
;
1933 b
->enable
= enabled
;
1936 b
->ignore_count
= 0;
1940 /* Add this breakpoint to the end of the chain
1941 so that a list of breakpoints will come out in order
1942 of increasing numbers. */
1944 b1
= breakpoint_chain
;
1946 breakpoint_chain
= b
;
1954 check_duplicates (sal
.pc
);
1955 breakpoints_changed ();
1961 create_longjmp_breakpoint(func_name
)
1964 struct symtab_and_line sal
;
1965 struct breakpoint
*b
;
1966 static int internal_breakpoint_number
= -1;
1968 if (func_name
!= NULL
)
1970 struct minimal_symbol
*m
;
1972 m
= lookup_minimal_symbol(func_name
, (struct objfile
*)NULL
);
1974 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
1984 b
= set_raw_breakpoint(sal
);
1987 b
->type
= func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
;
1988 b
->disposition
= donttouch
;
1989 b
->enable
= disabled
;
1992 b
->addr_string
= strsave(func_name
);
1993 b
->number
= internal_breakpoint_number
--;
1996 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1997 a longjmp(). When we hit that breakpoint, call
1998 set_longjmp_resume_breakpoint() to figure out where we are going. */
2001 enable_longjmp_breakpoint()
2003 register struct breakpoint
*b
;
2006 if (b
->type
== bp_longjmp
)
2008 b
->enable
= enabled
;
2009 check_duplicates (b
->address
);
2014 disable_longjmp_breakpoint()
2016 register struct breakpoint
*b
;
2019 if ( b
->type
== bp_longjmp
2020 || b
->type
== bp_longjmp_resume
)
2022 b
->enable
= disabled
;
2023 check_duplicates (b
->address
);
2028 hw_breakpoint_used_count()
2030 register struct breakpoint
*b
;
2035 if (b
->type
== bp_hardware_breakpoint
&& b
->enable
== enabled
)
2043 hw_watchpoint_used_count(type
, other_type_used
)
2045 int *other_type_used
;
2047 register struct breakpoint
*b
;
2050 *other_type_used
= 0;
2053 if (b
->enable
== enabled
)
2055 if (b
->type
== type
) i
++;
2056 else if ((b
->type
== bp_hardware_watchpoint
||
2057 b
->type
== bp_read_watchpoint
||
2058 b
->type
== bp_access_watchpoint
)
2059 && b
->enable
== enabled
)
2060 *other_type_used
= 1;
2066 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
2067 breakpoint at the target of the jmp_buf.
2069 FIXME - This ought to be done by setting a temporary breakpoint that gets
2070 deleted automatically...
2074 set_longjmp_resume_breakpoint(pc
, frame
)
2078 register struct breakpoint
*b
;
2081 if (b
->type
== bp_longjmp_resume
)
2084 b
->enable
= enabled
;
2086 b
->frame
= FRAME_FP(frame
);
2089 check_duplicates (b
->address
);
2094 /* Set a breakpoint that will evaporate an end of command
2095 at address specified by SAL.
2096 Restrict it to frame FRAME if FRAME is nonzero. */
2099 set_momentary_breakpoint (sal
, frame
, type
)
2100 struct symtab_and_line sal
;
2104 register struct breakpoint
*b
;
2105 b
= set_raw_breakpoint (sal
);
2107 b
->enable
= enabled
;
2108 b
->disposition
= donttouch
;
2109 b
->frame
= (frame
? FRAME_FP (frame
) : 0);
2115 clear_momentary_breakpoints ()
2117 register struct breakpoint
*b
;
2119 if (b
->disposition
== delete)
2121 delete_breakpoint (b
);
2127 /* Tell the user we have just set a breakpoint B. */
2130 struct breakpoint
*b
;
2135 printf_filtered ("Watchpoint %d: ", b
->number
);
2136 print_expression (b
->exp
, gdb_stdout
);
2138 case bp_hardware_watchpoint
:
2139 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
2140 print_expression (b
->exp
, gdb_stdout
);
2142 case bp_read_watchpoint
:
2143 printf_filtered ("Hardware read watchpoint %d: ", b
->number
);
2144 print_expression (b
->exp
, gdb_stdout
);
2146 case bp_access_watchpoint
:
2147 printf_filtered ("Hardware access(read/write) watchpoint %d: ",b
->number
);
2148 print_expression (b
->exp
, gdb_stdout
);
2151 printf_filtered ("Breakpoint %d at ", b
->number
);
2152 print_address_numeric (b
->address
, 1, gdb_stdout
);
2154 printf_filtered (": file %s, line %d.",
2155 b
->source_file
, b
->line_number
);
2157 case bp_hardware_breakpoint
:
2158 printf_filtered ("Hardware assisted breakpoint %d at ", b
->number
);
2159 print_address_numeric (b
->address
, 1, gdb_stdout
);
2161 printf_filtered (": file %s, line %d.",
2162 b
->source_file
, b
->line_number
);
2167 case bp_longjmp_resume
:
2168 case bp_step_resume
:
2169 case bp_through_sigtramp
:
2171 case bp_watchpoint_scope
:
2174 printf_filtered ("\n");
2178 /* Nobody calls this currently. */
2179 /* Set a breakpoint from a symtab and line.
2180 If TEMPFLAG is nonzero, it is a temporary breakpoint.
2181 ADDR_STRING is a malloc'd string holding the name of where we are
2182 setting the breakpoint. This is used later to re-set it after the
2183 program is relinked and symbols are reloaded.
2184 Print the same confirmation messages that the breakpoint command prints. */
2187 set_breakpoint (s
, line
, tempflag
, addr_string
)
2193 register struct breakpoint
*b
;
2194 struct symtab_and_line sal
;
2199 resolve_sal_pc (&sal
); /* Might error out */
2200 describe_other_breakpoints (sal
.pc
);
2202 b
= set_raw_breakpoint (sal
);
2203 set_breakpoint_count (breakpoint_count
+ 1);
2204 b
->number
= breakpoint_count
;
2205 b
->type
= bp_breakpoint
;
2207 b
->addr_string
= addr_string
;
2208 b
->enable
= enabled
;
2209 b
->disposition
= tempflag
? delete : donttouch
;
2215 /* Set a breakpoint according to ARG (function, linenum or *address)
2216 flag: first bit : 0 non-temporary, 1 temporary.
2217 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
2220 break_command_1 (arg
, flag
, from_tty
)
2224 int tempflag
, hardwareflag
;
2225 struct symtabs_and_lines sals
;
2226 struct symtab_and_line sal
;
2227 register struct expression
*cond
= 0;
2228 register struct breakpoint
*b
;
2230 /* Pointers in arg to the start, and one past the end, of the condition. */
2231 char *cond_start
= NULL
;
2232 char *cond_end
= NULL
;
2233 /* Pointers in arg to the start, and one past the end,
2234 of the address part. */
2235 char *addr_start
= NULL
;
2236 char *addr_end
= NULL
;
2237 struct cleanup
*old_chain
;
2238 struct cleanup
*canonical_strings_chain
= NULL
;
2239 char **canonical
= (char **)NULL
;
2243 hardwareflag
= flag
& 2;
2244 tempflag
= flag
& 1;
2249 sal
.line
= sal
.pc
= sal
.end
= 0;
2252 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2254 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2255 && (arg
[2] == ' ' || arg
[2] == '\t')))
2257 if (default_breakpoint_valid
)
2259 sals
.sals
= (struct symtab_and_line
*)
2260 xmalloc (sizeof (struct symtab_and_line
));
2261 sal
.pc
= default_breakpoint_address
;
2262 sal
.line
= default_breakpoint_line
;
2263 sal
.symtab
= default_breakpoint_symtab
;
2268 error ("No default breakpoint address now.");
2274 /* Force almost all breakpoints to be in terms of the
2275 current_source_symtab (which is decode_line_1's default). This
2276 should produce the results we want almost all of the time while
2277 leaving default_breakpoint_* alone. */
2278 if (default_breakpoint_valid
2279 && (!current_source_symtab
2280 || (arg
&& (*arg
== '+' || *arg
== '-'))))
2281 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2282 default_breakpoint_line
, &canonical
);
2284 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
2292 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2293 the following `for' loop errors out. */
2294 old_chain
= make_cleanup (free
, sals
.sals
);
2295 if (canonical
!= (char **)NULL
)
2297 make_cleanup (free
, canonical
);
2298 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
2299 for (i
= 0; i
< sals
.nelts
; i
++)
2301 if (canonical
[i
] != NULL
)
2302 make_cleanup (free
, canonical
[i
]);
2306 thread
= -1; /* No specific thread yet */
2308 /* Resolve all line numbers to PC's, and verify that conditions
2309 can be parsed, before setting any breakpoints. */
2310 for (i
= 0; i
< sals
.nelts
; i
++)
2312 char *tok
, *end_tok
;
2315 resolve_sal_pc (&sals
.sals
[i
]);
2321 while (*tok
== ' ' || *tok
== '\t')
2326 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2329 toklen
= end_tok
- tok
;
2331 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2333 tok
= cond_start
= end_tok
+ 1;
2334 cond
= parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
2337 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
2343 thread
= strtol (tok
, &tok
, 0);
2345 error ("Junk after thread keyword.");
2346 if (!valid_thread_id (thread
))
2347 error ("Unknown thread %d\n", thread
);
2350 error ("Junk at end of arguments.");
2355 int i
, other_type_used
, target_resources_ok
;
2356 i
= hw_breakpoint_used_count();
2357 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2358 bp_hardware_breakpoint
, i
+sals
.nelts
, 0);
2359 if (target_resources_ok
== 0)
2360 error ("No hardware breakpoint support in the target.");
2361 else if (target_resources_ok
< 0)
2362 error ("Hardware breakpoints used exceeds limit.");
2365 /* Remove the canonical strings from the cleanup, they are needed below. */
2366 if (canonical
!= (char **)NULL
)
2367 discard_cleanups (canonical_strings_chain
);
2369 /* Now set all the breakpoints. */
2370 for (i
= 0; i
< sals
.nelts
; i
++)
2375 describe_other_breakpoints (sal
.pc
);
2377 b
= set_raw_breakpoint (sal
);
2378 set_breakpoint_count (breakpoint_count
+ 1);
2379 b
->number
= breakpoint_count
;
2380 b
->type
= hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
;
2384 /* If a canonical line spec is needed use that instead of the
2386 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
2387 b
->addr_string
= canonical
[i
];
2388 else if (addr_start
)
2389 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
2391 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2393 b
->enable
= enabled
;
2394 b
->disposition
= tempflag
? delete : donttouch
;
2401 printf_filtered ("Multiple breakpoints were set.\n");
2402 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2404 do_cleanups (old_chain
);
2407 /* Helper function for break_command_1 and disassemble_command. */
2410 resolve_sal_pc (sal
)
2411 struct symtab_and_line
*sal
;
2415 if (sal
->pc
== 0 && sal
->symtab
!= 0)
2417 pc
= find_line_pc (sal
->symtab
, sal
->line
);
2419 error ("No line %d in file \"%s\".",
2420 sal
->line
, sal
->symtab
->filename
);
2425 #define BP_TEMPFLAG 1
2426 #define BP_HARDWAREFLAG 2
2428 break_command (arg
, from_tty
)
2432 break_command_1 (arg
, 0, from_tty
);
2436 tbreak_command (arg
, from_tty
)
2440 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
2444 hbreak_command (arg
, from_tty
)
2448 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
2452 thbreak_command (arg
, from_tty
)
2456 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
2460 /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write)
2463 watch_command_1 (arg
, accessflag
, from_tty
)
2468 struct breakpoint
*b
;
2469 struct symtab_and_line sal
;
2470 struct expression
*exp
;
2471 struct block
*exp_valid_block
;
2472 struct value
*val
, *mark
;
2473 FRAME frame
, prev_frame
;
2474 char *exp_start
= NULL
;
2475 char *exp_end
= NULL
;
2476 char *tok
, *end_tok
;
2478 char *cond_start
= NULL
;
2479 char *cond_end
= NULL
;
2480 struct expression
*cond
= NULL
;
2481 int i
, other_type_used
, target_resources_ok
;
2482 enum bptype bp_type
;
2489 /* Parse arguments. */
2490 innermost_block
= NULL
;
2492 exp
= parse_exp_1 (&arg
, 0, 0);
2494 exp_valid_block
= innermost_block
;
2495 mark
= value_mark ();
2496 val
= evaluate_expression (exp
);
2497 release_value (val
);
2498 if (VALUE_LAZY (val
))
2499 value_fetch_lazy (val
);
2502 while (*tok
== ' ' || *tok
== '\t')
2506 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2509 toklen
= end_tok
- tok
;
2510 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2512 tok
= cond_start
= end_tok
+ 1;
2513 cond
= parse_exp_1 (&tok
, 0, 0);
2517 error("Junk at end of command.");
2519 if (accessflag
== 1) bp_type
= bp_read_watchpoint
;
2520 else if (accessflag
== 2) bp_type
= bp_access_watchpoint
;
2521 else bp_type
= bp_hardware_watchpoint
;
2523 mem_cnt
= can_use_hardware_watchpoint (val
);
2524 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
2525 error ("Expression cannot be implemented with read/access watchpoint.");
2527 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
2528 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2529 bp_type
, i
+ mem_cnt
, other_type_used
);
2530 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
2531 error ("Target does not have this type of hardware watchpoint support.");
2532 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
2533 error ("Target resources have been allocated for other types of watchpoints.");
2536 /* Now set up the breakpoint. */
2537 b
= set_raw_breakpoint (sal
);
2538 set_breakpoint_count (breakpoint_count
+ 1);
2539 b
->number
= breakpoint_count
;
2540 b
->disposition
= donttouch
;
2542 b
->exp_valid_block
= exp_valid_block
;
2543 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
2547 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2551 frame
= block_innermost_frame (exp_valid_block
);
2554 prev_frame
= get_prev_frame (frame
);
2555 b
->watchpoint_frame
= FRAME_FP (frame
);
2558 b
->watchpoint_frame
= (CORE_ADDR
)0;
2560 if (mem_cnt
&& target_resources_ok
> 0)
2563 b
->type
= bp_watchpoint
;
2565 /* If the expression is "local", then set up a "watchpoint scope"
2566 breakpoint at the point where we've left the scope of the watchpoint
2568 if (innermost_block
)
2570 struct breakpoint
*scope_breakpoint
;
2571 struct symtab_and_line scope_sal
;
2575 scope_sal
.pc
= get_frame_pc (prev_frame
);
2576 scope_sal
.symtab
= NULL
;
2579 scope_breakpoint
= set_raw_breakpoint (scope_sal
);
2580 set_breakpoint_count (breakpoint_count
+ 1);
2581 scope_breakpoint
->number
= breakpoint_count
;
2583 scope_breakpoint
->type
= bp_watchpoint_scope
;
2584 scope_breakpoint
->enable
= enabled
;
2586 /* Automatically delete the breakpoint when it hits. */
2587 scope_breakpoint
->disposition
= delete;
2589 /* Only break in the proper frame (help with recursion). */
2590 scope_breakpoint
->frame
= prev_frame
->frame
;
2592 /* Set the address at which we will stop. */
2593 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
2595 /* The scope breakpoint is related to the watchpoint. We
2596 will need to act on them together. */
2597 b
->related_breakpoint
= scope_breakpoint
;
2600 value_free_to_mark (mark
);
2604 /* Return count of locations need to be watched and can be handled
2605 in hardware. If the watchpoint can not be handled
2606 in hardware return zero. */
2609 can_use_hardware_watchpoint (v
)
2612 int found_memory_cnt
= 0;
2614 /* Make sure all the intermediate values are in memory. Also make sure
2615 we found at least one memory expression. Guards against watch 0x12345,
2616 which is meaningless, but could cause errors if one tries to insert a
2617 hardware watchpoint for the constant expression. */
2618 for ( ; v
; v
= v
->next
)
2620 if (v
->lval
== lval_memory
)
2622 if (TYPE_LENGTH (VALUE_TYPE (v
)) <= REGISTER_SIZE
)
2625 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
2629 /* The expression itself looks suitable for using a hardware
2630 watchpoint, but give the target machine a chance to reject it. */
2631 return found_memory_cnt
;
2634 static void watch_command (arg
, from_tty
)
2638 watch_command_1 (arg
, 0, from_tty
);
2641 static void rwatch_command (arg
, from_tty
)
2645 watch_command_1 (arg
, 1, from_tty
);
2648 static void awatch_command (arg
, from_tty
)
2652 watch_command_1 (arg
, 2, from_tty
);
2657 * Helper routine for the until_command routine in infcmd.c. Here
2658 * because it uses the mechanisms of breakpoints.
2662 until_break_command (arg
, from_tty
)
2666 struct symtabs_and_lines sals
;
2667 struct symtab_and_line sal
;
2668 FRAME prev_frame
= get_prev_frame (selected_frame
);
2669 struct breakpoint
*breakpoint
;
2670 struct cleanup
*old_chain
;
2672 clear_proceed_status ();
2674 /* Set a breakpoint where the user wants it and at return from
2677 if (default_breakpoint_valid
)
2678 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2679 default_breakpoint_line
, (char ***)NULL
);
2681 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2683 if (sals
.nelts
!= 1)
2684 error ("Couldn't get information on specified line.");
2687 free ((PTR
)sals
.sals
); /* malloc'd, so freed */
2690 error ("Junk at end of arguments.");
2692 resolve_sal_pc (&sal
);
2694 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
2696 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
2698 /* Keep within the current frame */
2702 struct frame_info
*fi
;
2704 fi
= get_frame_info (prev_frame
);
2705 sal
= find_pc_line (fi
->pc
, 0);
2707 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
2708 make_cleanup(delete_breakpoint
, breakpoint
);
2711 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
2712 do_cleanups(old_chain
);
2716 /* These aren't used; I don't konw what they were for. */
2717 /* Set a breakpoint at the catch clause for NAME. */
2719 catch_breakpoint (name
)
2725 disable_catch_breakpoint ()
2730 delete_catch_breakpoint ()
2735 enable_catch_breakpoint ()
2742 struct sal_chain
*next
;
2743 struct symtab_and_line sal
;
2747 /* This isn't used; I don't know what it was for. */
2748 /* For each catch clause identified in ARGS, run FUNCTION
2749 with that clause as an argument. */
2750 static struct symtabs_and_lines
2751 map_catch_names (args
, function
)
2755 register char *p
= args
;
2757 struct symtabs_and_lines sals
;
2759 struct sal_chain
*sal_chain
= 0;
2763 error_no_arg ("one or more catch names");
2771 /* Don't swallow conditional part. */
2772 if (p1
[0] == 'i' && p1
[1] == 'f'
2773 && (p1
[2] == ' ' || p1
[2] == '\t'))
2779 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
2783 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
2784 error ("Arguments must be catch names.");
2790 struct sal_chain
*next
2791 = (struct sal_chain
*)alloca (sizeof (struct sal_chain
));
2792 next
->next
= sal_chain
;
2793 next
->sal
= get_catch_sal (p
);
2798 printf_unfiltered ("No catch clause for exception %s.\n", p
);
2803 while (*p
== ' ' || *p
== '\t') p
++;
2808 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2810 static struct symtabs_and_lines
2811 get_catch_sals (this_level_only
)
2812 int this_level_only
;
2814 register struct blockvector
*bl
;
2815 register struct block
*block
;
2816 int index
, have_default
= 0;
2817 struct frame_info
*fi
;
2819 struct symtabs_and_lines sals
;
2820 struct sal_chain
*sal_chain
= 0;
2821 char *blocks_searched
;
2823 /* Not sure whether an error message is always the correct response,
2824 but it's better than a core dump. */
2825 if (selected_frame
== NULL
)
2826 error ("No selected frame.");
2827 block
= get_frame_block (selected_frame
);
2828 fi
= get_frame_info (selected_frame
);
2835 error ("No symbol table info available.\n");
2837 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
2838 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2839 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2843 CORE_ADDR end
= BLOCK_END (block
) - 4;
2846 if (bl
!= blockvector_for_pc (end
, &index
))
2847 error ("blockvector blotch");
2848 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
2849 error ("blockvector botch");
2850 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
2853 /* Don't print out blocks that have gone by. */
2854 while (index
< last_index
2855 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
2858 while (index
< last_index
2859 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
2861 if (blocks_searched
[index
] == 0)
2863 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
2866 register struct symbol
*sym
;
2868 nsyms
= BLOCK_NSYMS (b
);
2870 for (i
= 0; i
< nsyms
; i
++)
2872 sym
= BLOCK_SYM (b
, i
);
2873 if (STREQ (SYMBOL_NAME (sym
), "default"))
2879 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
2881 struct sal_chain
*next
= (struct sal_chain
*)
2882 alloca (sizeof (struct sal_chain
));
2883 next
->next
= sal_chain
;
2884 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
2888 blocks_searched
[index
] = 1;
2894 if (sal_chain
&& this_level_only
)
2897 /* After handling the function's top-level block, stop.
2898 Don't continue to its superblock, the block of
2899 per-file symbols. */
2900 if (BLOCK_FUNCTION (block
))
2902 block
= BLOCK_SUPERBLOCK (block
);
2907 struct sal_chain
*tmp_chain
;
2909 /* Count the number of entries. */
2910 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
2911 tmp_chain
= tmp_chain
->next
)
2915 sals
.sals
= (struct symtab_and_line
*)
2916 xmalloc (index
* sizeof (struct symtab_and_line
));
2917 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
2918 sals
.sals
[index
] = sal_chain
->sal
;
2924 /* Commands to deal with catching exceptions. */
2927 catch_command_1 (arg
, tempflag
, from_tty
)
2932 /* First, translate ARG into something we can deal with in terms
2935 struct symtabs_and_lines sals
;
2936 struct symtab_and_line sal
;
2937 register struct expression
*cond
= 0;
2938 register struct breakpoint
*b
;
2942 sal
.line
= sal
.pc
= sal
.end
= 0;
2945 /* If no arg given, or if first arg is 'if ', all active catch clauses
2946 are breakpointed. */
2948 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2949 && (arg
[2] == ' ' || arg
[2] == '\t')))
2951 /* Grab all active catch clauses. */
2952 sals
= get_catch_sals (0);
2956 /* Grab selected catch clauses. */
2957 error ("catch NAME not implemented");
2959 /* This isn't used; I don't know what it was for. */
2960 sals
= map_catch_names (arg
, catch_breakpoint
);
2968 for (i
= 0; i
< sals
.nelts
; i
++)
2970 resolve_sal_pc (&sals
.sals
[i
]);
2974 if (arg
[0] == 'i' && arg
[1] == 'f'
2975 && (arg
[2] == ' ' || arg
[2] == '\t'))
2976 cond
= parse_exp_1 ((arg
+= 2, &arg
),
2977 block_for_pc (sals
.sals
[i
].pc
), 0);
2979 error ("Junk at end of arguments.");
2984 for (i
= 0; i
< sals
.nelts
; i
++)
2989 describe_other_breakpoints (sal
.pc
);
2991 b
= set_raw_breakpoint (sal
);
2992 set_breakpoint_count (breakpoint_count
+ 1);
2993 b
->number
= breakpoint_count
;
2994 b
->type
= bp_breakpoint
;
2996 b
->enable
= enabled
;
2997 b
->disposition
= tempflag
? delete : donttouch
;
3004 printf_unfiltered ("Multiple breakpoints were set.\n");
3005 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
3007 free ((PTR
)sals
.sals
);
3011 /* These aren't used; I don't know what they were for. */
3012 /* Disable breakpoints on all catch clauses described in ARGS. */
3014 disable_catch (args
)
3017 /* Map the disable command to catch clauses described in ARGS. */
3020 /* Enable breakpoints on all catch clauses described in ARGS. */
3025 /* Map the disable command to catch clauses described in ARGS. */
3028 /* Delete breakpoints on all catch clauses in the active scope. */
3033 /* Map the delete command to catch clauses described in ARGS. */
3038 catch_command (arg
, from_tty
)
3042 catch_command_1 (arg
, 0, from_tty
);
3046 clear_command (arg
, from_tty
)
3050 register struct breakpoint
*b
, *b1
;
3051 struct symtabs_and_lines sals
;
3052 struct symtab_and_line sal
;
3053 register struct breakpoint
*found
;
3058 sals
= decode_line_spec (arg
, 1);
3062 sals
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
3063 sal
.line
= default_breakpoint_line
;
3064 sal
.symtab
= default_breakpoint_symtab
;
3066 if (sal
.symtab
== 0)
3067 error ("No source file specified.");
3073 for (i
= 0; i
< sals
.nelts
; i
++)
3075 /* If exact pc given, clear bpts at that pc.
3076 But if sal.pc is zero, clear all bpts on specified line. */
3078 found
= (struct breakpoint
*) 0;
3079 while (breakpoint_chain
3081 ? breakpoint_chain
->address
== sal
.pc
3082 : (breakpoint_chain
->source_file
!= NULL
3083 && sal
.symtab
!= NULL
3084 && STREQ (breakpoint_chain
->source_file
,
3085 sal
.symtab
->filename
)
3086 && breakpoint_chain
->line_number
== sal
.line
)))
3088 b1
= breakpoint_chain
;
3089 breakpoint_chain
= b1
->next
;
3096 && b
->next
->type
!= bp_watchpoint
3097 && b
->next
->type
!= bp_hardware_watchpoint
3098 && b
->next
->type
!= bp_read_watchpoint
3099 && b
->next
->type
!= bp_access_watchpoint
3101 ? b
->next
->address
== sal
.pc
3102 : (b
->next
->source_file
!= NULL
3103 && sal
.symtab
!= NULL
3104 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
3105 && b
->next
->line_number
== sal
.line
)))
3116 error ("No breakpoint at %s.", arg
);
3118 error ("No breakpoint at this line.");
3121 if (found
->next
) from_tty
= 1; /* Always report if deleted more than one */
3122 if (from_tty
) printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
3123 breakpoints_changed ();
3126 if (from_tty
) printf_unfiltered ("%d ", found
->number
);
3128 delete_breakpoint (found
);
3131 if (from_tty
) putchar_unfiltered ('\n');
3133 free ((PTR
)sals
.sals
);
3136 /* Delete breakpoint in BS if they are `delete' breakpoints.
3137 This is called after any breakpoint is hit, or after errors. */
3140 breakpoint_auto_delete (bs
)
3143 for (; bs
; bs
= bs
->next
)
3144 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== delete
3146 delete_breakpoint (bs
->breakpoint_at
);
3149 /* Delete a breakpoint and clean up all traces of it in the data structures. */
3152 delete_breakpoint (bpt
)
3153 struct breakpoint
*bpt
;
3155 register struct breakpoint
*b
;
3159 remove_breakpoint (bpt
);
3161 if (breakpoint_chain
== bpt
)
3162 breakpoint_chain
= bpt
->next
;
3167 b
->next
= bpt
->next
;
3171 check_duplicates (bpt
->address
);
3172 /* If this breakpoint was inserted, and there is another breakpoint
3173 at the same address, we need to insert the other breakpoint. */
3175 && bpt
->type
!= bp_hardware_watchpoint
3176 && bpt
->type
!= bp_read_watchpoint
3177 && bpt
->type
!= bp_access_watchpoint
)
3180 if (b
->address
== bpt
->address
3182 && b
->enable
!= disabled
)
3185 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
3188 target_terminal_ours_for_output ();
3189 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
3190 memory_error (val
, b
->address
); /* which bombs us out */
3197 free_command_lines (&bpt
->commands
);
3200 if (bpt
->cond_string
!= NULL
)
3201 free (bpt
->cond_string
);
3202 if (bpt
->addr_string
!= NULL
)
3203 free (bpt
->addr_string
);
3204 if (bpt
->exp_string
!= NULL
)
3205 free (bpt
->exp_string
);
3206 if (bpt
->source_file
!= NULL
)
3207 free (bpt
->source_file
);
3209 breakpoints_changed ();
3211 /* Be sure no bpstat's are pointing at it after it's been freed. */
3212 /* FIXME, how can we find all bpstat's?
3213 We just check stop_bpstat for now. */
3214 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
3215 if (bs
->breakpoint_at
== bpt
)
3216 bs
->breakpoint_at
= NULL
;
3221 delete_command (arg
, from_tty
)
3228 /* Ask user only if there are some breakpoints to delete. */
3230 || (breakpoint_chain
&& query ("Delete all breakpoints? ", 0, 0)))
3232 /* No arg; clear all breakpoints. */
3233 while (breakpoint_chain
)
3234 delete_breakpoint (breakpoint_chain
);
3238 map_breakpoint_numbers (arg
, delete_breakpoint
);
3241 /* Reset a breakpoint given it's struct breakpoint * BINT.
3242 The value we return ends up being the return value from catch_errors.
3243 Unused in this case. */
3246 breakpoint_re_set_one (bint
)
3249 struct breakpoint
*b
= (struct breakpoint
*)bint
; /* get past catch_errs */
3252 struct symtabs_and_lines sals
;
3254 enum enable save_enable
;
3259 case bp_hardware_breakpoint
:
3260 if (b
->addr_string
== NULL
)
3262 /* Anything without a string can't be re-set. */
3263 delete_breakpoint (b
);
3266 /* In case we have a problem, disable this breakpoint. We'll restore
3267 its status if we succeed. */
3268 save_enable
= b
->enable
;
3269 b
->enable
= disabled
;
3272 sals
= decode_line_1 (&s
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
3273 for (i
= 0; i
< sals
.nelts
; i
++)
3275 resolve_sal_pc (&sals
.sals
[i
]);
3277 /* Reparse conditions, they might contain references to the
3279 if (b
->cond_string
!= NULL
)
3283 free ((PTR
)b
->cond
);
3284 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
3287 /* We need to re-set the breakpoint if the address changes...*/
3288 if (b
->address
!= sals
.sals
[i
].pc
3289 /* ...or new and old breakpoints both have source files, and
3290 the source file name or the line number changes... */
3291 || (b
->source_file
!= NULL
3292 && sals
.sals
[i
].symtab
!= NULL
3293 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
3294 || b
->line_number
!= sals
.sals
[i
].line
)
3296 /* ...or we switch between having a source file and not having
3298 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
3301 if (b
->source_file
!= NULL
)
3302 free (b
->source_file
);
3303 if (sals
.sals
[i
].symtab
== NULL
)
3304 b
->source_file
= NULL
;
3307 savestring (sals
.sals
[i
].symtab
->filename
,
3308 strlen (sals
.sals
[i
].symtab
->filename
));
3309 b
->line_number
= sals
.sals
[i
].line
;
3310 b
->address
= sals
.sals
[i
].pc
;
3312 check_duplicates (b
->address
);
3316 /* Might be better to do this just once per breakpoint_re_set,
3317 rather than once for every breakpoint. */
3318 breakpoints_changed ();
3320 b
->enable
= save_enable
; /* Restore it, this worked. */
3322 free ((PTR
)sals
.sals
);
3326 case bp_hardware_watchpoint
:
3327 case bp_read_watchpoint
:
3328 case bp_access_watchpoint
:
3329 innermost_block
= NULL
;
3330 /* The issue arises of what context to evaluate this in. The same
3331 one as when it was set, but what does that mean when symbols have
3332 been re-read? We could save the filename and functionname, but
3333 if the context is more local than that, the best we could do would
3334 be something like how many levels deep and which index at that
3335 particular level, but that's going to be less stable than filenames
3336 or functionnames. */
3337 /* So for now, just use a global context. */
3338 b
->exp
= parse_expression (b
->exp_string
);
3339 b
->exp_valid_block
= innermost_block
;
3340 mark
= value_mark ();
3341 b
->val
= evaluate_expression (b
->exp
);
3342 release_value (b
->val
);
3343 if (VALUE_LAZY (b
->val
))
3344 value_fetch_lazy (b
->val
);
3346 if (b
->cond_string
!= NULL
)
3349 b
->cond
= parse_exp_1 (&s
, (struct block
*)0, 0);
3351 if (b
->enable
== enabled
)
3353 value_free_to_mark (mark
);
3357 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
3362 case bp_longjmp_resume
:
3363 case bp_watchpoint_scope
:
3365 delete_breakpoint (b
);
3372 /* Re-set all breakpoints after symbols have been re-loaded. */
3374 breakpoint_re_set ()
3376 struct breakpoint
*b
, *temp
;
3377 static char message1
[] = "Error in re-setting breakpoint %d:\n";
3378 char message
[sizeof (message1
) + 30 /* slop */];
3380 ALL_BREAKPOINTS_SAFE (b
, temp
)
3382 sprintf (message
, message1
, b
->number
); /* Format possible error msg */
3383 catch_errors (breakpoint_re_set_one
, (char *) b
, message
,
3387 create_longjmp_breakpoint("longjmp");
3388 create_longjmp_breakpoint("_longjmp");
3389 create_longjmp_breakpoint("siglongjmp");
3390 create_longjmp_breakpoint(NULL
);
3393 /* Took this out (temporaliy at least), since it produces an extra
3394 blank line at startup. This messes up the gdbtests. -PB */
3395 /* Blank line to finish off all those mention() messages we just printed. */
3396 printf_filtered ("\n");
3400 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3401 If from_tty is nonzero, it prints a message to that effect,
3402 which ends with a period (no newline). */
3405 set_ignore_count (bptnum
, count
, from_tty
)
3406 int bptnum
, count
, from_tty
;
3408 register struct breakpoint
*b
;
3414 if (b
->number
== bptnum
)
3416 b
->ignore_count
= count
;
3419 else if (count
== 0)
3420 printf_filtered ("Will stop next time breakpoint %d is reached.",
3422 else if (count
== 1)
3423 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3426 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3428 breakpoints_changed ();
3432 error ("No breakpoint number %d.", bptnum
);
3435 /* Clear the ignore counts of all breakpoints. */
3437 breakpoint_clear_ignore_counts ()
3439 struct breakpoint
*b
;
3442 b
->ignore_count
= 0;
3445 /* Command to set ignore-count of breakpoint N to COUNT. */
3448 ignore_command (args
, from_tty
)
3456 error_no_arg ("a breakpoint number");
3458 num
= get_number (&p
);
3461 error ("Second argument (specified ignore-count) is missing.");
3463 set_ignore_count (num
,
3464 longest_to_int (value_as_long (parse_and_eval (p
))),
3466 printf_filtered ("\n");
3467 breakpoints_changed ();
3470 /* Call FUNCTION on each of the breakpoints
3471 whose numbers are given in ARGS. */
3474 map_breakpoint_numbers (args
, function
)
3476 void (*function
) PARAMS ((struct breakpoint
*));
3478 register char *p
= args
;
3481 register struct breakpoint
*b
;
3484 error_no_arg ("one or more breakpoint numbers");
3490 num
= get_number (&p1
);
3493 if (b
->number
== num
)
3495 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
3497 if (related_breakpoint
)
3498 function (related_breakpoint
);
3501 printf_unfiltered ("No breakpoint number %d.\n", num
);
3508 enable_breakpoint (bpt
)
3509 struct breakpoint
*bpt
;
3511 FRAME save_selected_frame
= NULL
;
3512 int save_selected_frame_level
= -1;
3513 int target_resources_ok
, other_type_used
;
3516 if (bpt
->type
== bp_hardware_breakpoint
)
3519 i
= hw_breakpoint_used_count();
3520 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3521 bp_hardware_breakpoint
, i
+1, 0);
3522 if (target_resources_ok
== 0)
3523 error ("No hardware breakpoint support in the target.");
3524 else if (target_resources_ok
< 0)
3525 error ("Hardware breakpoints used exceeds limit.");
3527 bpt
->enable
= enabled
;
3528 breakpoints_changed ();
3529 check_duplicates (bpt
->address
);
3531 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3532 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3534 if (bpt
->exp_valid_block
!= NULL
)
3536 FRAME fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3540 Cannot enable watchpoint %d because the block in which its expression\n\
3541 is valid is not currently in scope.\n", bpt
->number
);
3542 bpt
->enable
= disabled
;
3546 save_selected_frame
= selected_frame
;
3547 save_selected_frame_level
= selected_frame_level
;
3548 select_frame (fr
, -1);
3551 value_free (bpt
->val
);
3552 mark
= value_mark ();
3553 bpt
->val
= evaluate_expression (bpt
->exp
);
3554 release_value (bpt
->val
);
3555 if (VALUE_LAZY (bpt
->val
))
3556 value_fetch_lazy (bpt
->val
);
3558 if (bpt
->type
== bp_hardware_watchpoint
||
3559 bpt
->type
== bp_read_watchpoint
||
3560 bpt
->type
== bp_access_watchpoint
)
3562 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3563 int mem_cnt
= can_use_hardware_watchpoint(bpt
->val
);
3564 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3565 bpt
->type
, i
+mem_cnt
, other_type_used
);
3566 /* we can consider of type is bp_hardware_watchpoint, convert to
3567 bp_watchpoint in the following condition */
3568 if (target_resources_ok
< 0)
3571 Cannot enable watchpoint %d because target watch resources\n\
3572 have been allocated for other watchpoints.\n", bpt
->number
);
3573 bpt
->enable
= disabled
;
3574 value_free_to_mark (mark
);
3579 if (save_selected_frame_level
>= 0)
3580 select_frame (save_selected_frame
, save_selected_frame_level
);
3581 value_free_to_mark (mark
);
3587 enable_command (args
, from_tty
)
3591 struct breakpoint
*bpt
;
3593 ALL_BREAKPOINTS (bpt
)
3597 case bp_hardware_breakpoint
:
3599 case bp_hardware_watchpoint
:
3600 case bp_read_watchpoint
:
3601 case bp_access_watchpoint
:
3602 enable_breakpoint (bpt
);
3607 map_breakpoint_numbers (args
, enable_breakpoint
);
3611 disable_breakpoint (bpt
)
3612 struct breakpoint
*bpt
;
3614 /* Never disable a watchpoint scope breakpoint; we want to
3615 hit them when we leave scope so we can delete both the
3616 watchpoint and its scope breakpoint at that time. */
3617 if (bpt
->type
== bp_watchpoint_scope
)
3620 bpt
->enable
= disabled
;
3622 breakpoints_changed ();
3624 check_duplicates (bpt
->address
);
3629 disable_command (args
, from_tty
)
3633 register struct breakpoint
*bpt
;
3635 ALL_BREAKPOINTS (bpt
)
3639 case bp_hardware_breakpoint
:
3641 case bp_hardware_watchpoint
:
3642 case bp_read_watchpoint
:
3643 case bp_access_watchpoint
:
3644 disable_breakpoint (bpt
);
3649 map_breakpoint_numbers (args
, disable_breakpoint
);
3653 enable_once_breakpoint (bpt
)
3654 struct breakpoint
*bpt
;
3656 FRAME save_selected_frame
= NULL
;
3657 int save_selected_frame_level
= -1;
3658 int target_resources_ok
, other_type_used
;
3661 if (bpt
->type
== bp_hardware_breakpoint
)
3664 i
= hw_breakpoint_used_count();
3665 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3666 bp_hardware_breakpoint
, i
+1, 0);
3667 if (target_resources_ok
== 0)
3668 error ("No hardware breakpoint support in the target.");
3669 else if (target_resources_ok
< 0)
3670 error ("Hardware breakpoints used exceeds limit.");
3673 bpt
->enable
= enabled
;
3674 bpt
->disposition
= disable
;
3675 check_duplicates (bpt
->address
);
3676 breakpoints_changed ();
3678 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3679 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3681 if (bpt
->exp_valid_block
!= NULL
)
3683 FRAME fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3687 Cannot enable watchpoint %d because the block in which its expression\n\
3688 is valid is not currently in scope.\n", bpt
->number
);
3689 bpt
->enable
= disabled
;
3693 save_selected_frame
= selected_frame
;
3694 save_selected_frame_level
= selected_frame_level
;
3695 select_frame (fr
, -1);
3698 value_free (bpt
->val
);
3699 mark
= value_mark ();
3700 bpt
->val
= evaluate_expression (bpt
->exp
);
3701 release_value (bpt
->val
);
3702 if (VALUE_LAZY (bpt
->val
))
3703 value_fetch_lazy (bpt
->val
);
3705 if (bpt
->type
== bp_hardware_watchpoint
||
3706 bpt
->type
== bp_read_watchpoint
||
3707 bpt
->type
== bp_access_watchpoint
)
3709 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3710 int mem_cnt
= can_use_hardware_watchpoint(bpt
->val
);
3711 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3712 bpt
->type
, i
+mem_cnt
, other_type_used
);
3713 /* we can consider of type is bp_hardware_watchpoint, convert to
3714 bp_watchpoint in the following condition */
3715 if (target_resources_ok
< 0)
3718 Cannot enable watchpoint %d because target watch resources\n\
3719 have been allocated for other watchpoints.\n", bpt
->number
);
3720 bpt
->enable
= disabled
;
3721 value_free_to_mark (mark
);
3725 if (save_selected_frame_level
>= 0)
3726 select_frame (save_selected_frame
, save_selected_frame_level
);
3727 value_free_to_mark (mark
);
3733 enable_once_command (args
, from_tty
)
3737 map_breakpoint_numbers (args
, enable_once_breakpoint
);
3741 enable_delete_breakpoint (bpt
)
3742 struct breakpoint
*bpt
;
3744 bpt
->enable
= enabled
;
3745 bpt
->disposition
= delete;
3747 check_duplicates (bpt
->address
);
3748 breakpoints_changed ();
3753 enable_delete_command (args
, from_tty
)
3757 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
3761 * Use default_breakpoint_'s, or nothing if they aren't valid.
3763 struct symtabs_and_lines
3764 decode_line_spec_1 (string
, funfirstline
)
3768 struct symtabs_and_lines sals
;
3770 error ("Empty line specification.");
3771 if (default_breakpoint_valid
)
3772 sals
= decode_line_1 (&string
, funfirstline
,
3773 default_breakpoint_symtab
, default_breakpoint_line
,
3776 sals
= decode_line_1 (&string
, funfirstline
,
3777 (struct symtab
*)NULL
, 0, (char ***)NULL
);
3779 error ("Junk at end of line specification: %s", string
);
3784 _initialize_breakpoint ()
3786 breakpoint_chain
= 0;
3787 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3788 before a breakpoint is set. */
3789 breakpoint_count
= 0;
3791 add_com ("ignore", class_breakpoint
, ignore_command
,
3792 "Set ignore-count of breakpoint number N to COUNT.");
3794 add_com ("commands", class_breakpoint
, commands_command
,
3795 "Set commands to be executed when a breakpoint is hit.\n\
3796 Give breakpoint number as argument after \"commands\".\n\
3797 With no argument, the targeted breakpoint is the last one set.\n\
3798 The commands themselves follow starting on the next line.\n\
3799 Type a line containing \"end\" to indicate the end of them.\n\
3800 Give \"silent\" as the first line to make the breakpoint silent;\n\
3801 then no output is printed when it is hit, except what the commands print.");
3803 add_com ("condition", class_breakpoint
, condition_command
,
3804 "Specify breakpoint number N to break only if COND is true.\n\
3805 N is an integer; COND is an expression to be evaluated whenever\n\
3806 breakpoint N is reached. ");
3808 add_com ("tbreak", class_breakpoint
, tbreak_command
,
3809 "Set a temporary breakpoint. Args like \"break\" command.\n\
3810 Like \"break\" except the breakpoint is only temporary,\n\
3811 so it will be deleted when hit. Equivalent to \"break\" followed\n\
3812 by using \"enable delete\" on the breakpoint number.");
3814 add_com ("hbreak", class_breakpoint
, hbreak_command
,
3815 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
3816 Like \"break\" except the breakpoint requires hardware support,\n\
3817 some target hardware may not have this support.");
3819 add_com ("thbreak", class_breakpoint
, thbreak_command
,
3820 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
3821 Like \"hbreak\" except the breakpoint is only temporary,\n\
3822 so it will be deleted when hit.");
3824 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
3825 "Enable some breakpoints.\n\
3826 Give breakpoint numbers (separated by spaces) as arguments.\n\
3827 With no subcommand, breakpoints are enabled until you command otherwise.\n\
3828 This is used to cancel the effect of the \"disable\" command.\n\
3829 With a subcommand you can enable temporarily.",
3830 &enablelist
, "enable ", 1, &cmdlist
);
3832 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
3833 "Enable some breakpoints.\n\
3834 Give breakpoint numbers (separated by spaces) as arguments.\n\
3835 This is used to cancel the effect of the \"disable\" command.\n\
3836 May be abbreviated to simply \"enable\".\n",
3837 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
3839 add_cmd ("once", no_class
, enable_once_command
,
3840 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3841 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3844 add_cmd ("delete", no_class
, enable_delete_command
,
3845 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3846 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3849 add_cmd ("delete", no_class
, enable_delete_command
,
3850 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3851 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3854 add_cmd ("once", no_class
, enable_once_command
,
3855 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3856 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3859 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
3860 "Disable some breakpoints.\n\
3861 Arguments are breakpoint numbers with spaces in between.\n\
3862 To disable all breakpoints, give no argument.\n\
3863 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3864 &disablelist
, "disable ", 1, &cmdlist
);
3865 add_com_alias ("dis", "disable", class_breakpoint
, 1);
3866 add_com_alias ("disa", "disable", class_breakpoint
, 1);
3868 add_cmd ("breakpoints", class_alias
, disable_command
,
3869 "Disable some breakpoints.\n\
3870 Arguments are breakpoint numbers with spaces in between.\n\
3871 To disable all breakpoints, give no argument.\n\
3872 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3873 This command may be abbreviated \"disable\".",
3876 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
3877 "Delete some breakpoints or auto-display expressions.\n\
3878 Arguments are breakpoint numbers with spaces in between.\n\
3879 To delete all breakpoints, give no argument.\n\
3881 Also a prefix command for deletion of other GDB objects.\n\
3882 The \"unset\" command is also an alias for \"delete\".",
3883 &deletelist
, "delete ", 1, &cmdlist
);
3884 add_com_alias ("d", "delete", class_breakpoint
, 1);
3886 add_cmd ("breakpoints", class_alias
, delete_command
,
3887 "Delete some breakpoints or auto-display expressions.\n\
3888 Arguments are breakpoint numbers with spaces in between.\n\
3889 To delete all breakpoints, give no argument.\n\
3890 This command may be abbreviated \"delete\".",
3893 add_com ("clear", class_breakpoint
, clear_command
,
3894 "Clear breakpoint at specified line or function.\n\
3895 Argument may be line number, function name, or \"*\" and an address.\n\
3896 If line number is specified, all breakpoints in that line are cleared.\n\
3897 If function is specified, breakpoints at beginning of function are cleared.\n\
3898 If an address is specified, breakpoints at that address are cleared.\n\n\
3899 With no argument, clears all breakpoints in the line that the selected frame\n\
3902 See also the \"delete\" command which clears breakpoints by number.");
3904 add_com ("break", class_breakpoint
, break_command
,
3905 "Set breakpoint at specified line or function.\n\
3906 Argument may be line number, function name, or \"*\" and an address.\n\
3907 If line number is specified, break at start of code for that line.\n\
3908 If function is specified, break at start of code for that function.\n\
3909 If an address is specified, break at that exact address.\n\
3910 With no arg, uses current execution address of selected stack frame.\n\
3911 This is useful for breaking on return to a stack frame.\n\
3913 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3915 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3916 add_com_alias ("b", "break", class_run
, 1);
3917 add_com_alias ("br", "break", class_run
, 1);
3918 add_com_alias ("bre", "break", class_run
, 1);
3919 add_com_alias ("brea", "break", class_run
, 1);
3921 add_info ("breakpoints", breakpoints_info
,
3922 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3923 The \"Type\" column indicates one of:\n\
3924 \tbreakpoint - normal breakpoint\n\
3925 \twatchpoint - watchpoint\n\
3926 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3927 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3928 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3929 address and file/line number respectively.\n\n\
3930 Convenience variable \"$_\" and default examine address for \"x\"\n\
3931 are set to the address of the last breakpoint listed.\n\n\
3932 Convenience variable \"$bpnum\" contains the number of the last\n\
3935 #if MAINTENANCE_CMDS
3937 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
3938 "Status of all breakpoints, or breakpoint number NUMBER.\n\
3939 The \"Type\" column indicates one of:\n\
3940 \tbreakpoint - normal breakpoint\n\
3941 \twatchpoint - watchpoint\n\
3942 \tlongjmp - internal breakpoint used to step through longjmp()\n\
3943 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
3944 \tuntil - internal breakpoint used by the \"until\" command\n\
3945 \tfinish - internal breakpoint used by the \"finish\" command\n\
3946 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3947 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3948 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3949 address and file/line number respectively.\n\n\
3950 Convenience variable \"$_\" and default examine address for \"x\"\n\
3951 are set to the address of the last breakpoint listed.\n\n\
3952 Convenience variable \"$bpnum\" contains the number of the last\n\
3954 &maintenanceinfolist
);
3956 #endif /* MAINTENANCE_CMDS */
3958 add_com ("catch", class_breakpoint
, catch_command
,
3959 "Set breakpoints to catch exceptions that are raised.\n\
3960 Argument may be a single exception to catch, multiple exceptions\n\
3961 to catch, or the default exception \"default\". If no arguments\n\
3962 are given, breakpoints are set at all exception handlers catch clauses\n\
3963 within the current scope.\n\
3965 A condition specified for the catch applies to all breakpoints set\n\
3966 with this command\n\
3968 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3970 add_com ("watch", class_breakpoint
, watch_command
,
3971 "Set a watchpoint for an expression.\n\
3972 A watchpoint stops execution of your program whenever the value of\n\
3973 an expression changes.");
3975 add_com ("rwatch", class_breakpoint
, rwatch_command
,
3976 "Set a read watchpoint for an expression.\n\
3977 A watchpoint stops execution of your program whenever the value of\n\
3978 an expression is read.");
3980 add_com ("awatch", class_breakpoint
, awatch_command
,
3981 "Set a watchpoint for an expression.\n\
3982 A watchpoint stops execution of your program whenever the value of\n\
3983 an expression is either read or written.");
3985 add_info ("watchpoints", breakpoints_info
,
3986 "Synonym for ``info breakpoints''.");
3989 /* OK, when we call objfile_relocate, we need to relocate breakpoints
3990 too. breakpoint_re_set is not a good choice--for example, if
3991 addr_string contains just a line number without a file name the
3992 breakpoint might get set in a different file. In general, there is
3993 no need to go all the way back to the user's string (though this might
3994 work if some effort were made to canonicalize it), since symtabs and
3995 everything except addresses are still valid.
3997 Probably the best way to solve this is to have each breakpoint save
3998 the objfile and the section number that was used to set it (if set
3999 by "*addr", probably it is best to use find_pc_line to get a symtab
4000 and use the objfile and block_line_section for that symtab). Then
4001 objfile_relocate can call fixup_breakpoints with the objfile and
4002 the new_offsets, and it can relocate only the appropriate breakpoints. */
4004 #ifdef IBM6000_TARGET
4005 /* But for now, just kludge it based on the concept that before an
4006 objfile is relocated the breakpoint is below 0x10000000, and afterwards
4007 it is higher, so that way we only relocate each breakpoint once. */
4010 fixup_breakpoints (low
, high
, delta
)
4015 struct breakpoint
*b
;
4019 if (b
->address
>= low
&& b
->address
<= high
)
4020 b
->address
+= delta
;