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 breakpoint
*));
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(B) 0
163 #define target_remove_watchpoint(ADDR,LEN) -1
164 #define target_insert_watchpoint(ADDR,LEN) -1
167 /* Chain of all breakpoints defined. */
169 static struct breakpoint
*breakpoint_chain
;
171 /* Number of last breakpoint made. */
173 static int breakpoint_count
;
175 /* Set breakpoint count to NUM. */
177 set_breakpoint_count (num
)
180 breakpoint_count
= num
;
181 set_internalvar (lookup_internalvar ("bpnum"),
182 value_from_longest (builtin_type_int
, (LONGEST
) num
));
185 /* Default address, symtab and line to put a breakpoint at
186 for "break" command with no arg.
187 if default_breakpoint_valid is zero, the other three are
188 not valid, and "break" with no arg is an error.
190 This set by print_stack_frame, which calls set_default_breakpoint. */
192 int default_breakpoint_valid
;
193 CORE_ADDR default_breakpoint_address
;
194 struct symtab
*default_breakpoint_symtab
;
195 int default_breakpoint_line
;
197 /* Flag indicating extra verbosity for xgdb. */
198 extern int xgdb_verbose
;
201 breakpoints_changed ()
203 if (annotation_level
> 1)
205 target_terminal_ours ();
206 printf_unfiltered ("\n\032\032breakpoints-invalid\n");
210 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
211 Advance *PP after the string and any trailing whitespace.
213 Currently the string can either be a number or "$" followed by the name
214 of a convenience variable. Making it an expression wouldn't work well
215 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
224 /* Empty line means refer to the last breakpoint. */
225 return breakpoint_count
;
228 /* Make a copy of the name, so we can null-terminate it
229 to pass to lookup_internalvar(). */
234 while (isalnum (*p
) || *p
== '_')
236 varname
= (char *) alloca (p
- start
+ 1);
237 strncpy (varname
, start
, p
- start
);
238 varname
[p
- start
] = '\0';
239 val
= value_of_internalvar (lookup_internalvar (varname
));
240 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
242 "Convenience variables used to specify breakpoints must have integer values."
244 retval
= (int) value_as_long (val
);
250 while (*p
>= '0' && *p
<= '9')
253 /* There is no number here. (e.g. "cond a == b"). */
254 error_no_arg ("breakpoint number");
257 if (!(isspace (*p
) || *p
== '\0'))
258 error ("breakpoint number expected");
265 /* condition N EXP -- set break condition of breakpoint N to EXP. */
268 condition_command (arg
, from_tty
)
272 register struct breakpoint
*b
;
277 error_no_arg ("breakpoint number");
280 bnum
= get_number (&p
);
283 if (b
->number
== bnum
)
290 if (b
->cond_string
!= NULL
)
291 free ((PTR
)b
->cond_string
);
296 b
->cond_string
= NULL
;
298 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
303 /* I don't know if it matters whether this is the string the user
304 typed in or the decompiled expression. */
305 b
->cond_string
= savestring (arg
, strlen (arg
));
306 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
308 error ("Junk at end of expression");
313 error ("No breakpoint number %d.", bnum
);
318 commands_command (arg
, from_tty
)
322 register struct breakpoint
*b
;
325 struct command_line
*l
;
327 /* If we allowed this, we would have problems with when to
328 free the storage, if we change the commands currently
331 if (executing_breakpoint_commands
)
332 error ("Can't use the \"commands\" command among a breakpoint's commands.");
335 bnum
= get_number (&p
);
337 error ("Unexpected extra arguments following breakpoint number.");
340 if (b
->number
== bnum
)
342 if (from_tty
&& input_from_terminal_p ())
343 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
344 End with a line saying just \"end\".\n", bnum
);
345 l
= read_command_lines ();
346 free_command_lines (&b
->commands
);
348 breakpoints_changed ();
351 error ("No breakpoint number %d.", bnum
);
354 extern int memory_breakpoint_size
; /* from mem-break.c */
356 /* Like target_read_memory() but if breakpoints are inserted, return
357 the shadow contents instead of the breakpoints themselves.
359 Read "memory data" from whatever target or inferior we have.
360 Returns zero if successful, errno value if not. EIO is used
361 for address out of bounds. If breakpoints are inserted, returns
362 shadow contents, not the breakpoints themselves. From breakpoint.c. */
365 read_memory_nobpt (memaddr
, myaddr
, len
)
371 struct breakpoint
*b
;
373 if (memory_breakpoint_size
< 0)
374 /* No breakpoints on this machine. FIXME: This should be
375 dependent on the debugging target. Probably want
376 target_insert_breakpoint to return a size, saying how many
377 bytes of the shadow contents are used, or perhaps have
378 something like target_xfer_shadow. */
379 return target_read_memory (memaddr
, myaddr
, len
);
383 if (b
->type
== bp_watchpoint
384 || b
->type
== bp_hardware_watchpoint
387 else if (b
->address
+ memory_breakpoint_size
<= memaddr
)
388 /* The breakpoint is entirely before the chunk of memory
391 else if (b
->address
>= memaddr
+ len
)
392 /* The breakpoint is entirely after the chunk of memory we
397 /* Copy the breakpoint from the shadow contents, and recurse
398 for the things before and after. */
400 /* Addresses and length of the part of the breakpoint that
402 CORE_ADDR membpt
= b
->address
;
403 unsigned int bptlen
= memory_breakpoint_size
;
404 /* Offset within shadow_contents. */
407 if (membpt
< memaddr
)
409 /* Only copy the second part of the breakpoint. */
410 bptlen
-= memaddr
- membpt
;
411 bptoffset
= memaddr
- membpt
;
415 if (membpt
+ bptlen
> memaddr
+ len
)
417 /* Only copy the first part of the breakpoint. */
418 bptlen
-= (membpt
+ bptlen
) - (memaddr
+ len
);
421 memcpy (myaddr
+ membpt
- memaddr
,
422 b
->shadow_contents
+ bptoffset
, bptlen
);
424 if (membpt
> memaddr
)
426 /* Copy the section of memory before the breakpoint. */
427 status
= read_memory_nobpt (memaddr
, myaddr
, membpt
- memaddr
);
432 if (membpt
+ bptlen
< memaddr
+ len
)
434 /* Copy the section of memory after the breakpoint. */
435 status
= read_memory_nobpt
437 myaddr
+ membpt
+ bptlen
- memaddr
,
438 memaddr
+ len
- (membpt
+ bptlen
));
445 /* Nothing overlaps. Just call read_memory_noerr. */
446 return target_read_memory (memaddr
, myaddr
, len
);
449 /* insert_breakpoints is used when starting or continuing the program.
450 remove_breakpoints is used when the program stops.
451 Both return zero if successful,
452 or an `errno' value if could not write the inferior. */
455 insert_breakpoints ()
457 register struct breakpoint
*b
;
459 int disabled_breaks
= 0;
462 if (b
->type
!= bp_watchpoint
463 && b
->type
!= bp_hardware_watchpoint
464 && b
->enable
!= disabled
468 val
= target_insert_breakpoint(b
->address
, b
->shadow_contents
);
471 /* Can't set the breakpoint. */
472 #if defined (DISABLE_UNSETTABLE_BREAK)
473 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
476 b
->enable
= disabled
;
477 if (!disabled_breaks
)
479 target_terminal_ours_for_output ();
480 fprintf_unfiltered (gdb_stderr
,
481 "Cannot insert breakpoint %d:\n", b
->number
);
482 printf_filtered ("Disabling shared library breakpoints:\n");
485 printf_filtered ("%d ", b
->number
);
490 target_terminal_ours_for_output ();
491 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
492 #ifdef ONE_PROCESS_WRITETEXT
493 fprintf_unfiltered (gdb_stderr
,
494 "The same program may be running in another process.\n");
496 memory_error (val
, b
->address
); /* which bombs us out */
502 else if (b
->type
== bp_hardware_watchpoint
503 && b
->enable
== enabled
508 int saved_level
, within_current_scope
;
509 value_ptr mark
= value_mark ();
512 /* Save the current frame and level so we can restore it after
513 evaluating the watchpoint expression on its own frame. */
514 saved_frame
= selected_frame
;
515 saved_level
= selected_frame_level
;
517 /* Determine if the watchpoint is within scope. */
518 if (b
->exp_valid_block
== NULL
)
519 within_current_scope
= 1;
522 FRAME fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
523 within_current_scope
= (fr
!= NULL
);
524 if (within_current_scope
)
525 select_frame (fr
, -1);
528 if (within_current_scope
)
530 /* Evaluate the expression and cut the chain of values
531 produced off from the value chain. */
532 v
= evaluate_expression (b
->exp
);
533 value_release_to_mark (mark
);
538 /* Look at each value on the value chain. */
539 for ( ; v
; v
=v
->next
)
541 /* If it's a memory location, then we must watch it. */
542 if (v
->lval
== lval_memory
)
546 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
547 len
= TYPE_LENGTH (VALUE_TYPE (v
));
548 val
= target_insert_watchpoint (addr
, len
);
557 /* Failure to insert a watchpoint on any memory value in the
558 value chain brings us here. */
560 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
566 Hardware watchpoint %d deleted because the program has left the block in\n\
567 which its expression is valid.\n", b
->number
);
568 if (b
->related_breakpoint
)
569 delete_breakpoint (b
->related_breakpoint
);
570 delete_breakpoint (b
);
573 /* Restore the frame and level. */
574 select_frame (saved_frame
, saved_level
);
577 printf_filtered ("\n");
583 remove_breakpoints ()
585 register struct breakpoint
*b
;
592 val
= remove_breakpoint (b
);
602 remove_breakpoint (b
)
603 struct breakpoint
*b
;
607 if (b
->type
!= bp_watchpoint
608 && b
->type
!= bp_hardware_watchpoint
)
610 val
= target_remove_breakpoint(b
->address
, b
->shadow_contents
);
615 else if (b
->type
== bp_hardware_watchpoint
616 && b
->enable
== enabled
622 /* Walk down the saved value chain. */
623 for (v
= b
->val_chain
; v
; v
= v
->next
)
625 /* For each memory reference remove the watchpoint
627 if (v
->lval
== lval_memory
)
631 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
632 len
= TYPE_LENGTH (VALUE_TYPE (v
));
633 val
= target_remove_watchpoint (addr
, len
);
639 /* Failure to remove any of the hardware watchpoints comes here. */
641 error ("Hardware watchpoint %d: Could not remove watchpoint\n",
644 /* Free the saved value chain. We will construct a new one
645 the next time the watchpoint is inserted. */
646 for (v
= b
->val_chain
; v
; v
= n
)
656 /* Clear the "inserted" flag in all breakpoints. */
659 mark_breakpoints_out ()
661 register struct breakpoint
*b
;
667 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
668 which should go away between runs of the program. */
671 breakpoint_init_inferior ()
673 register struct breakpoint
*b
, *temp
;
675 ALL_BREAKPOINTS_SAFE (b
, temp
)
679 /* If the call dummy breakpoint is at the entry point it will
680 cause problems when the inferior is rerun, so we better
682 if (b
->type
== bp_call_dummy
)
683 delete_breakpoint (b
);
685 /* Likewise for scope breakpoints. */
686 if (b
->type
== bp_watchpoint_scope
)
687 delete_breakpoint (b
);
689 /* Likewise for watchpoints on local expressions. */
690 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
691 && b
->exp_valid_block
!= NULL
)
692 delete_breakpoint (b
);
696 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
697 When continuing from a location with a breakpoint,
698 we actually single step once before calling insert_breakpoints. */
701 breakpoint_here_p (pc
)
704 register struct breakpoint
*b
;
707 if (b
->enable
!= disabled
&& b
->address
== pc
)
713 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
714 because figuring out the saved SP would take too much time, at least using
715 get_saved_register on the 68k. This means that for this function to
716 work right a port must use the bp_call_dummy breakpoint. */
719 frame_in_dummy (frame
)
722 struct breakpoint
*b
;
727 static unsigned LONGEST dummy
[] = CALL_DUMMY
;
729 if (b
->type
== bp_call_dummy
730 && b
->frame
== frame
->frame
732 /* We need to check the PC as well as the frame on the sparc,
733 for signals.exp in the testsuite. */
736 - sizeof (dummy
) / sizeof (LONGEST
) * REGISTER_SIZE
))
737 && frame
->pc
<= b
->address
)
740 #endif /* CALL_DUMMY */
744 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
745 is valid for process/thread PID. */
748 breakpoint_thread_match (pc
, pid
)
752 struct breakpoint
*b
;
755 thread
= pid_to_thread_id (pid
);
758 if (b
->enable
!= disabled
760 && (b
->thread
== -1 || b
->thread
== thread
))
767 /* bpstat stuff. External routines' interfaces are documented
770 /* Clear a bpstat so that it says we are not at any breakpoint.
771 Also free any storage that is part of a bpstat. */
786 if (p
->old_val
!= NULL
)
787 value_free (p
->old_val
);
794 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
795 is part of the bpstat is copied as well. */
803 bpstat retval
= NULL
;
808 for (; bs
!= NULL
; bs
= bs
->next
)
810 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
811 memcpy (tmp
, bs
, sizeof (*tmp
));
813 /* This is the first thing in the chain. */
823 /* Find the bpstat associated with this breakpoint */
826 bpstat_find_breakpoint(bsp
, breakpoint
)
828 struct breakpoint
*breakpoint
;
830 if (bsp
== NULL
) return NULL
;
832 for (;bsp
!= NULL
; bsp
= bsp
->next
) {
833 if (bsp
->breakpoint_at
== breakpoint
) return bsp
;
838 /* Return the breakpoint number of the first breakpoint we are stopped
839 at. *BSP upon return is a bpstat which points to the remaining
840 breakpoints stopped at (but which is not guaranteed to be good for
841 anything but further calls to bpstat_num).
842 Return 0 if passed a bpstat which does not indicate any breakpoints. */
848 struct breakpoint
*b
;
851 return 0; /* No more breakpoint values */
854 b
= (*bsp
)->breakpoint_at
;
857 return -1; /* breakpoint that's been deleted since */
859 return b
->number
; /* We have its number */
863 /* Modify BS so that the actions will not be performed. */
866 bpstat_clear_actions (bs
)
869 for (; bs
!= NULL
; bs
= bs
->next
)
872 if (bs
->old_val
!= NULL
)
874 value_free (bs
->old_val
);
880 /* Stub for cleaning up our state if we error-out of a breakpoint command */
883 cleanup_executing_breakpoints (ignore
)
886 executing_breakpoint_commands
= 0;
889 /* Execute all the commands associated with all the breakpoints at this
890 location. Any of these commands could cause the process to proceed
891 beyond this point, etc. We look out for such changes by checking
892 the global "breakpoint_proceeded" after each command. */
895 bpstat_do_actions (bsp
)
899 struct cleanup
*old_chain
;
901 executing_breakpoint_commands
= 1;
902 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
907 breakpoint_proceeded
= 0;
908 for (; bs
!= NULL
; bs
= bs
->next
)
912 char *line
= bs
->commands
->line
;
913 bs
->commands
= bs
->commands
->next
;
914 execute_command (line
, 0);
915 /* If the inferior is proceeded by the command, bomb out now.
916 The bpstat chain has been blown away by wait_for_inferior.
917 But since execution has stopped again, there is a new bpstat
918 to look at, so start over. */
919 if (breakpoint_proceeded
)
924 executing_breakpoint_commands
= 0;
925 discard_cleanups (old_chain
);
928 /* This is the normal print_it function for a bpstat. In the future,
929 much of this logic could (should?) be moved to bpstat_stop_status,
930 by having it set different print_it functions. */
936 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
937 which has since been deleted. */
938 if (bs
->breakpoint_at
== NULL
939 || (bs
->breakpoint_at
->type
!= bp_breakpoint
940 && bs
->breakpoint_at
->type
!= bp_watchpoint
941 && bs
->breakpoint_at
->type
!= bp_hardware_watchpoint
))
944 if (bs
->breakpoint_at
->type
== bp_breakpoint
)
946 /* I think the user probably only wants to see one breakpoint
947 number, not all of them. */
948 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
952 if (bs
->old_val
!= NULL
)
954 printf_filtered ("\nWatchpoint %d, ", bs
->breakpoint_at
->number
);
955 print_expression (bs
->breakpoint_at
->exp
, gdb_stdout
);
956 printf_filtered ("\nOld value = ");
957 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
958 printf_filtered ("\nNew value = ");
959 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
961 printf_filtered ("\n");
962 value_free (bs
->old_val
);
964 /* More than one watchpoint may have been triggered. */
967 /* We can't deal with it. Maybe another member of the bpstat chain can. */
971 /* Print a message indicating what happened. Returns nonzero to
972 say that only the source line should be printed after this (zero
973 return means print the frame as well as the source line). */
974 /* Currently we always return zero. */
984 val
= (*bs
->print_it
) (bs
);
988 /* Maybe another breakpoint in the chain caused us to stop.
989 (Currently all watchpoints go on the bpstat whether hit or
990 not. That probably could (should) be changed, provided care is taken
991 with respect to bpstat_explains_signal). */
993 return bpstat_print (bs
->next
);
995 /* We reached the end of the chain without printing anything. */
999 /* Evaluate the expression EXP and return 1 if value is zero.
1000 This is used inside a catch_errors to evaluate the breakpoint condition.
1001 The argument is a "struct expression *" that has been cast to char * to
1002 make it pass through catch_errors. */
1005 breakpoint_cond_eval (exp
)
1008 return !value_true (evaluate_expression ((struct expression
*)exp
));
1011 /* Allocate a new bpstat and chain it to the current one. */
1014 bpstat_alloc (b
, cbs
)
1015 register struct breakpoint
*b
;
1016 bpstat cbs
; /* Current "bs" value */
1020 bs
= (bpstat
) xmalloc (sizeof (*bs
));
1022 bs
->breakpoint_at
= b
;
1023 /* If the condition is false, etc., don't do the commands. */
1024 bs
->commands
= NULL
;
1026 bs
->print_it
= print_it_normal
;
1032 /* Possible return values for watchpoint_check (this can't be an enum
1033 because of check_errors). */
1034 /* The watchpoint has been deleted. */
1035 #define WP_DELETED 1
1036 /* The value has changed. */
1037 #define WP_VALUE_CHANGED 2
1038 /* The value has not changed. */
1039 #define WP_VALUE_NOT_CHANGED 3
1041 /* Check watchpoint condition. */
1043 watchpoint_check (p
)
1046 bpstat bs
= (bpstat
) p
;
1047 struct breakpoint
*b
;
1048 FRAME saved_frame
, fr
;
1049 int within_current_scope
, saved_level
;
1051 /* Save the current frame and level so we can restore it after
1052 evaluating the watchpoint expression on its own frame. */
1053 saved_frame
= selected_frame
;
1054 saved_level
= selected_frame_level
;
1056 if (bs
->breakpoint_at
->exp_valid_block
== NULL
)
1057 within_current_scope
= 1;
1060 fr
= find_frame_addr_in_frame_chain (bs
->breakpoint_at
->watchpoint_frame
);
1061 within_current_scope
= (fr
!= NULL
);
1062 if (within_current_scope
)
1063 /* If we end up stopping, the current frame will get selected
1064 in normal_stop. So this call to select_frame won't affect
1066 select_frame (fr
, -1);
1069 if (within_current_scope
)
1071 /* We use value_{,free_to_}mark because it could be a
1072 *long* time before we return to the command level and
1073 call free_all_values. We can't call free_all_values because
1074 we might be in the middle of evaluating a function call. */
1076 value_ptr mark
= value_mark ();
1077 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
1078 if (!value_equal (bs
->breakpoint_at
->val
, new_val
))
1080 release_value (new_val
);
1081 value_free_to_mark (mark
);
1082 bs
->old_val
= bs
->breakpoint_at
->val
;
1083 bs
->breakpoint_at
->val
= new_val
;
1084 /* We will stop here */
1085 select_frame (saved_frame
, saved_level
);
1086 return WP_VALUE_CHANGED
;
1090 /* Nothing changed, don't do anything. */
1091 value_free_to_mark (mark
);
1092 /* We won't stop here */
1093 select_frame (saved_frame
, saved_level
);
1094 return WP_VALUE_NOT_CHANGED
;
1099 /* This seems like the only logical thing to do because
1100 if we temporarily ignored the watchpoint, then when
1101 we reenter the block in which it is valid it contains
1102 garbage (in the case of a function, it may have two
1103 garbage values, one before and one after the prologue).
1104 So we can't even detect the first assignment to it and
1105 watch after that (since the garbage may or may not equal
1106 the first value assigned). */
1108 Watchpoint %d deleted because the program has left the block in\n\
1109 which its expression is valid.\n", bs
->breakpoint_at
->number
);
1110 if (bs
->breakpoint_at
->related_breakpoint
)
1111 delete_breakpoint (bs
->breakpoint_at
->related_breakpoint
);
1112 delete_breakpoint (bs
->breakpoint_at
);
1114 select_frame (saved_frame
, saved_level
);
1119 /* This is used when everything which needs to be printed has
1120 already been printed. But we still want to print the frame. */
1128 /* This is used when nothing should be printed for this bpstat entry. */
1137 /* Get a bpstat associated with having just stopped at address *PC
1138 and frame address FRAME_ADDRESS. Update *PC to point at the
1139 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1140 if this is known to not be a real breakpoint (it could still be a
1141 watchpoint, though). */
1143 /* Determine whether we stopped at a breakpoint, etc, or whether we
1144 don't understand this stop. Result is a chain of bpstat's such that:
1146 if we don't understand the stop, the result is a null pointer.
1148 if we understand why we stopped, the result is not null.
1150 Each element of the chain refers to a particular breakpoint or
1151 watchpoint at which we have stopped. (We may have stopped for
1152 several reasons concurrently.)
1154 Each element of the chain has valid next, breakpoint_at,
1155 commands, FIXME??? fields.
1160 bpstat_stop_status (pc
, frame_address
, not_a_breakpoint
)
1162 FRAME_ADDR frame_address
;
1163 int not_a_breakpoint
;
1165 register struct breakpoint
*b
;
1167 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1168 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1169 int real_breakpoint
= 0;
1171 /* Root of the chain of bpstat's */
1172 struct bpstat root_bs
[1];
1173 /* Pointer to the last thing in the chain currently. */
1174 bpstat bs
= root_bs
;
1176 /* Get the address where the breakpoint would have been. */
1177 bp_addr
= *pc
- DECR_PC_AFTER_BREAK
;
1181 if (b
->enable
== disabled
)
1184 if (b
->type
!= bp_watchpoint
1185 && b
->type
!= bp_hardware_watchpoint
1186 && b
->address
!= bp_addr
)
1189 if (b
->type
!= bp_watchpoint
1190 && b
->type
!= bp_hardware_watchpoint
1191 && not_a_breakpoint
)
1194 /* Come here if it's a watchpoint, or if the break address matches */
1196 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
1201 if (b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1203 static char message1
[] =
1204 "Error evaluating expression for watchpoint %d\n";
1205 char message
[sizeof (message1
) + 30 /* slop */];
1206 sprintf (message
, message1
, b
->number
);
1207 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1211 /* We've already printed what needs to be printed. */
1212 bs
->print_it
= print_it_done
;
1215 case WP_VALUE_CHANGED
:
1218 case WP_VALUE_NOT_CHANGED
:
1220 bs
->print_it
= print_it_noop
;
1227 /* Error from catch_errors. */
1228 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1229 if (b
->related_breakpoint
)
1230 delete_breakpoint (b
->related_breakpoint
);
1231 delete_breakpoint (b
);
1232 /* We've already printed what needs to be printed. */
1233 bs
->print_it
= print_it_done
;
1239 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1241 real_breakpoint
= 1;
1244 if (b
->frame
&& b
->frame
!= frame_address
)
1248 int value_is_zero
= 0;
1252 /* Need to select the frame, with all that implies
1253 so that the conditions will have the right context. */
1254 select_frame (get_current_frame (), 0);
1256 = catch_errors (breakpoint_cond_eval
, (char *)(b
->cond
),
1257 "Error in testing breakpoint condition:\n",
1259 /* FIXME-someday, should give breakpoint # */
1262 if (b
->cond
&& value_is_zero
)
1266 else if (b
->ignore_count
> 0)
1273 /* We will stop here */
1274 if (b
->disposition
== disable
)
1275 b
->enable
= disabled
;
1276 bs
->commands
= b
->commands
;
1279 if (bs
->commands
&& STREQ ("silent", bs
->commands
->line
))
1281 bs
->commands
= bs
->commands
->next
;
1286 /* Print nothing for this entry if we dont stop or if we dont print. */
1287 if (bs
->stop
== 0 || bs
->print
== 0)
1288 bs
->print_it
= print_it_noop
;
1291 bs
->next
= NULL
; /* Terminate the chain */
1292 bs
= root_bs
->next
; /* Re-grab the head of the chain */
1293 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1296 if (real_breakpoint
)
1299 #if defined (SHIFT_INST_REGS)
1301 #else /* No SHIFT_INST_REGS. */
1303 #endif /* No SHIFT_INST_REGS. */
1306 #endif /* DECR_PC_AFTER_BREAK != 0. */
1308 /* The value of a hardware watchpoint hasn't changed, but the
1309 intermediate memory locations we are watching may have. */
1310 if (bs
&& ! bs
->stop
1311 && bs
->breakpoint_at
->type
== bp_hardware_watchpoint
)
1313 remove_breakpoints ();
1314 insert_breakpoints ();
1319 /* Tell what to do about this bpstat. */
1324 /* Classify each bpstat as one of the following. */
1326 /* This bpstat element has no effect on the main_action. */
1329 /* There was a watchpoint, stop but don't print. */
1332 /* There was a watchpoint, stop and print. */
1335 /* There was a breakpoint but we're not stopping. */
1338 /* There was a breakpoint, stop but don't print. */
1341 /* There was a breakpoint, stop and print. */
1344 /* We hit the longjmp breakpoint. */
1347 /* We hit the longjmp_resume breakpoint. */
1350 /* We hit the step_resume breakpoint. */
1353 /* We hit the through_sigtramp breakpoint. */
1356 /* This is just used to count how many enums there are. */
1360 /* Here is the table which drives this routine. So that we can
1361 format it pretty, we define some abbreviations for the
1362 enum bpstat_what codes. */
1363 #define keep_c BPSTAT_WHAT_KEEP_CHECKING
1364 #define stop_s BPSTAT_WHAT_STOP_SILENT
1365 #define stop_n BPSTAT_WHAT_STOP_NOISY
1366 #define single BPSTAT_WHAT_SINGLE
1367 #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1368 #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1369 #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1370 #define sr BPSTAT_WHAT_STEP_RESUME
1371 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1373 /* "Can't happen." Might want to print an error message.
1374 abort() is not out of the question, but chances are GDB is just
1375 a bit confused, not unusable. */
1376 #define err BPSTAT_WHAT_STOP_NOISY
1378 /* Given an old action and a class, come up with a new action. */
1379 /* One interesting property of this table is that wp_silent is the same
1380 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1381 after stopping, the check for whether to step over a breakpoint
1382 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1383 reference to how we stopped. We retain separate wp_silent and bp_silent
1384 codes in case we want to change that someday. */
1386 /* step_resume entries: a step resume breakpoint overrides another
1387 breakpoint of signal handling (see comment in wait_for_inferior
1388 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1389 /* We handle the through_sigtramp_breakpoint the same way; having both
1390 one of those and a step_resume_breakpoint is probably very rare (?). */
1392 static const enum bpstat_what_main_action
1393 table
[(int)class_last
][(int)BPSTAT_WHAT_LAST
] =
1396 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts
1398 /*no_effect*/ {keep_c
,stop_s
,stop_n
,single
, setlr
, clrlr
, clrlrs
, sr
, ts
},
1399 /*wp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1400 /*wp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1401 /*bp_nostop*/ {single
,stop_s
,stop_n
,single
, setlr
, clrlrs
, clrlrs
, sr
, ts
},
1402 /*bp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1403 /*bp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1404 /*long_jump*/ {setlr
,stop_s
,stop_n
,setlr
, err
, err
, err
, sr
, ts
},
1405 /*long_resume*/ {clrlr
,stop_s
,stop_n
,clrlrs
, err
, err
, err
, sr
, ts
},
1406 /*step_resume*/ {sr
,sr
,sr
,sr
, sr
, sr
, sr
, sr
, ts
},
1407 /*through_sig*/ {ts
,ts
,ts
,ts
, ts
, ts
, ts
, ts
, ts
}
1419 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
1420 struct bpstat_what retval
;
1422 retval
.call_dummy
= 0;
1423 for (; bs
!= NULL
; bs
= bs
->next
)
1425 enum class bs_class
= no_effect
;
1426 if (bs
->breakpoint_at
== NULL
)
1427 /* I suspect this can happen if it was a momentary breakpoint
1428 which has since been deleted. */
1430 switch (bs
->breakpoint_at
->type
)
1438 bs_class
= bp_noisy
;
1440 bs_class
= bp_silent
;
1443 bs_class
= bp_nostop
;
1446 case bp_hardware_watchpoint
:
1450 bs_class
= wp_noisy
;
1452 bs_class
= wp_silent
;
1455 /* There was a watchpoint, but we're not stopping. This requires
1456 no further action. */
1457 bs_class
= no_effect
;
1460 bs_class
= long_jump
;
1462 case bp_longjmp_resume
:
1463 bs_class
= long_resume
;
1465 case bp_step_resume
:
1468 bs_class
= step_resume
;
1471 /* It is for the wrong frame. */
1472 bs_class
= bp_nostop
;
1474 case bp_through_sigtramp
:
1475 bs_class
= through_sig
;
1477 case bp_watchpoint_scope
:
1478 bs_class
= bp_nostop
;
1482 /* Make sure the action is stop (silent or noisy), so infrun.c
1483 pops the dummy frame. */
1484 bs_class
= bp_silent
;
1485 retval
.call_dummy
= 1;
1488 current_action
= table
[(int)bs_class
][(int)current_action
];
1490 retval
.main_action
= current_action
;
1494 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1495 without hardware support). This isn't related to a specific bpstat,
1496 just to things like whether watchpoints are set. */
1499 bpstat_should_step ()
1501 struct breakpoint
*b
;
1503 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
1508 /* Print information on breakpoint number BNUM, or -1 if all.
1509 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1510 is nonzero, process only watchpoints. */
1513 breakpoint_1 (bnum
, allflag
)
1517 register struct breakpoint
*b
;
1518 register struct command_line
*l
;
1519 register struct symbol
*sym
;
1520 CORE_ADDR last_addr
= (CORE_ADDR
)-1;
1521 int found_a_breakpoint
= 0;
1522 static char *bptypes
[] = {"breakpoint", "until", "finish", "watchpoint",
1523 "hardware watchpoint", "longjmp",
1524 "longjmp resume", "step resume",
1525 "watchpoint scope", "call dummy" };
1526 static char *bpdisps
[] = {"del", "dis", "keep"};
1527 static char bpenables
[] = "ny";
1528 char wrap_indent
[80];
1532 || bnum
== b
->number
)
1534 /* We only print out user settable breakpoints unless the allflag is set. */
1536 && b
->type
!= bp_breakpoint
1537 && b
->type
!= bp_watchpoint
1538 && b
->type
!= bp_hardware_watchpoint
)
1541 if (!found_a_breakpoint
++)
1542 printf_filtered ("Num Type Disp Enb %sWhat\n",
1543 addressprint
? "Address " : "");
1545 printf_filtered ("%-3d %-14s %-4s %-3c ",
1547 bptypes
[(int)b
->type
],
1548 bpdisps
[(int)b
->disposition
],
1549 bpenables
[(int)b
->enable
]);
1550 strcpy (wrap_indent
, " ");
1552 strcat (wrap_indent
, " ");
1556 case bp_hardware_watchpoint
:
1557 print_expression (b
->exp
, gdb_stdout
);
1564 case bp_longjmp_resume
:
1565 case bp_step_resume
:
1566 case bp_through_sigtramp
:
1567 case bp_watchpoint_scope
:
1570 printf_filtered ("%s ", local_hex_string_custom ((unsigned long) b
->address
, "08l"));
1572 last_addr
= b
->address
;
1575 sym
= find_pc_function (b
->address
);
1578 fputs_filtered ("in ", gdb_stdout
);
1579 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
1580 wrap_here (wrap_indent
);
1581 fputs_filtered (" at ", gdb_stdout
);
1583 fputs_filtered (b
->source_file
, gdb_stdout
);
1584 printf_filtered (":%d", b
->line_number
);
1587 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
1591 printf_filtered ("\n");
1595 printf_filtered ("\tstop only in stack frame at ");
1596 print_address_numeric (b
->frame
, gdb_stdout
);
1597 printf_filtered ("\n");
1601 printf_filtered ("\tstop only if ");
1602 print_expression (b
->cond
, gdb_stdout
);
1603 printf_filtered ("\n");
1605 if (b
->ignore_count
)
1606 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
1607 if ((l
= b
->commands
))
1610 fputs_filtered ("\t", gdb_stdout
);
1611 fputs_filtered (l
->line
, gdb_stdout
);
1612 fputs_filtered ("\n", gdb_stdout
);
1617 if (!found_a_breakpoint
)
1620 printf_filtered ("No breakpoints or watchpoints.\n");
1622 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
1625 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1626 that a comparison of an unsigned with -1 is always false. */
1627 if (last_addr
!= (CORE_ADDR
)-1)
1628 set_next_address (last_addr
);
1633 breakpoints_info (bnum_exp
, from_tty
)
1640 bnum
= parse_and_eval_address (bnum_exp
);
1642 breakpoint_1 (bnum
, 0);
1645 #if MAINTENANCE_CMDS
1649 maintenance_info_breakpoints (bnum_exp
, from_tty
)
1656 bnum
= parse_and_eval_address (bnum_exp
);
1658 breakpoint_1 (bnum
, 1);
1663 /* Print a message describing any breakpoints set at PC. */
1666 describe_other_breakpoints (pc
)
1667 register CORE_ADDR pc
;
1669 register int others
= 0;
1670 register struct breakpoint
*b
;
1673 if (b
->address
== pc
)
1677 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
1679 if (b
->address
== pc
)
1685 (b
->enable
== disabled
) ? " (disabled)" : "",
1686 (others
> 1) ? "," : ((others
== 1) ? " and" : ""));
1688 printf_filtered ("also set at pc ");
1689 print_address_numeric (pc
, gdb_stdout
);
1690 printf_filtered (".\n");
1694 /* Set the default place to put a breakpoint
1695 for the `break' command with no arguments. */
1698 set_default_breakpoint (valid
, addr
, symtab
, line
)
1701 struct symtab
*symtab
;
1704 default_breakpoint_valid
= valid
;
1705 default_breakpoint_address
= addr
;
1706 default_breakpoint_symtab
= symtab
;
1707 default_breakpoint_line
= line
;
1710 /* Rescan breakpoints at address ADDRESS,
1711 marking the first one as "first" and any others as "duplicates".
1712 This is so that the bpt instruction is only inserted once. */
1715 check_duplicates (address
)
1718 register struct breakpoint
*b
;
1719 register int count
= 0;
1721 if (address
== 0) /* Watchpoints are uninteresting */
1725 if (b
->enable
!= disabled
&& b
->address
== address
)
1728 b
->duplicate
= count
> 1;
1732 /* Low level routine to set a breakpoint.
1733 Takes as args the three things that every breakpoint must have.
1734 Returns the breakpoint object so caller can set other things.
1735 Does not set the breakpoint number!
1736 Does not print anything.
1738 ==> This routine should not be called if there is a chance of later
1739 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1740 your arguments BEFORE calling this routine! */
1742 static struct breakpoint
*
1743 set_raw_breakpoint (sal
)
1744 struct symtab_and_line sal
;
1746 register struct breakpoint
*b
, *b1
;
1748 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
1749 memset (b
, 0, sizeof (*b
));
1750 b
->address
= sal
.pc
;
1751 if (sal
.symtab
== NULL
)
1752 b
->source_file
= NULL
;
1754 b
->source_file
= savestring (sal
.symtab
->filename
,
1755 strlen (sal
.symtab
->filename
));
1757 b
->line_number
= sal
.line
;
1758 b
->enable
= enabled
;
1761 b
->ignore_count
= 0;
1765 /* Add this breakpoint to the end of the chain
1766 so that a list of breakpoints will come out in order
1767 of increasing numbers. */
1769 b1
= breakpoint_chain
;
1771 breakpoint_chain
= b
;
1779 check_duplicates (sal
.pc
);
1780 breakpoints_changed ();
1786 create_longjmp_breakpoint(func_name
)
1789 struct symtab_and_line sal
;
1790 struct breakpoint
*b
;
1791 static int internal_breakpoint_number
= -1;
1793 if (func_name
!= NULL
)
1795 struct minimal_symbol
*m
;
1797 m
= lookup_minimal_symbol(func_name
, (struct objfile
*)NULL
);
1799 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
1809 b
= set_raw_breakpoint(sal
);
1812 b
->type
= func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
;
1813 b
->disposition
= donttouch
;
1814 b
->enable
= disabled
;
1817 b
->addr_string
= strsave(func_name
);
1818 b
->number
= internal_breakpoint_number
--;
1821 /* Call this routine when stepping and nexting to enable a breakpoint if we do
1822 a longjmp(). When we hit that breakpoint, call
1823 set_longjmp_resume_breakpoint() to figure out where we are going. */
1826 enable_longjmp_breakpoint()
1828 register struct breakpoint
*b
;
1831 if (b
->type
== bp_longjmp
)
1833 b
->enable
= enabled
;
1834 check_duplicates (b
->address
);
1839 disable_longjmp_breakpoint()
1841 register struct breakpoint
*b
;
1844 if ( b
->type
== bp_longjmp
1845 || b
->type
== bp_longjmp_resume
)
1847 b
->enable
= disabled
;
1848 check_duplicates (b
->address
);
1852 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
1853 breakpoint at the target of the jmp_buf.
1855 FIXME - This ought to be done by setting a temporary breakpoint that gets
1856 deleted automatically...
1860 set_longjmp_resume_breakpoint(pc
, frame
)
1864 register struct breakpoint
*b
;
1867 if (b
->type
== bp_longjmp_resume
)
1870 b
->enable
= enabled
;
1872 b
->frame
= FRAME_FP(frame
);
1875 check_duplicates (b
->address
);
1880 /* Set a breakpoint that will evaporate an end of command
1881 at address specified by SAL.
1882 Restrict it to frame FRAME if FRAME is nonzero. */
1885 set_momentary_breakpoint (sal
, frame
, type
)
1886 struct symtab_and_line sal
;
1890 register struct breakpoint
*b
;
1891 b
= set_raw_breakpoint (sal
);
1893 b
->enable
= enabled
;
1894 b
->disposition
= donttouch
;
1895 b
->frame
= (frame
? FRAME_FP (frame
) : 0);
1901 clear_momentary_breakpoints ()
1903 register struct breakpoint
*b
;
1905 if (b
->disposition
== delete)
1907 delete_breakpoint (b
);
1913 /* Tell the user we have just set a breakpoint B. */
1916 struct breakpoint
*b
;
1921 printf_filtered ("Watchpoint %d: ", b
->number
);
1922 print_expression (b
->exp
, gdb_stdout
);
1924 case bp_hardware_watchpoint
:
1925 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
1926 print_expression (b
->exp
, gdb_stdout
);
1929 printf_filtered ("Breakpoint %d at ", b
->number
);
1930 print_address_numeric (b
->address
, gdb_stdout
);
1932 printf_filtered (": file %s, line %d.",
1933 b
->source_file
, b
->line_number
);
1938 case bp_longjmp_resume
:
1939 case bp_step_resume
:
1940 case bp_through_sigtramp
:
1942 case bp_watchpoint_scope
:
1945 printf_filtered ("\n");
1949 /* Nobody calls this currently. */
1950 /* Set a breakpoint from a symtab and line.
1951 If TEMPFLAG is nonzero, it is a temporary breakpoint.
1952 ADDR_STRING is a malloc'd string holding the name of where we are
1953 setting the breakpoint. This is used later to re-set it after the
1954 program is relinked and symbols are reloaded.
1955 Print the same confirmation messages that the breakpoint command prints. */
1958 set_breakpoint (s
, line
, tempflag
, addr_string
)
1964 register struct breakpoint
*b
;
1965 struct symtab_and_line sal
;
1970 resolve_sal_pc (&sal
); /* Might error out */
1971 describe_other_breakpoints (sal
.pc
);
1973 b
= set_raw_breakpoint (sal
);
1974 set_breakpoint_count (breakpoint_count
+ 1);
1975 b
->number
= breakpoint_count
;
1976 b
->type
= bp_breakpoint
;
1978 b
->addr_string
= addr_string
;
1979 b
->enable
= enabled
;
1980 b
->disposition
= tempflag
? delete : donttouch
;
1986 /* Set a breakpoint according to ARG (function, linenum or *address)
1987 and make it temporary if TEMPFLAG is nonzero. */
1990 break_command_1 (arg
, tempflag
, from_tty
)
1992 int tempflag
, from_tty
;
1994 struct symtabs_and_lines sals
;
1995 struct symtab_and_line sal
;
1996 register struct expression
*cond
= 0;
1997 register struct breakpoint
*b
;
1999 /* Pointers in arg to the start, and one past the end, of the condition. */
2000 char *cond_start
= NULL
;
2001 char *cond_end
= NULL
;
2002 /* Pointers in arg to the start, and one past the end,
2003 of the address part. */
2004 char *addr_start
= NULL
;
2005 char *addr_end
= NULL
;
2006 struct cleanup
*old_chain
;
2007 struct cleanup
*canonical_strings_chain
= NULL
;
2008 char **canonical
= (char **)NULL
;
2015 sal
.line
= sal
.pc
= sal
.end
= 0;
2018 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2020 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2021 && (arg
[2] == ' ' || arg
[2] == '\t')))
2023 if (default_breakpoint_valid
)
2025 sals
.sals
= (struct symtab_and_line
*)
2026 xmalloc (sizeof (struct symtab_and_line
));
2027 sal
.pc
= default_breakpoint_address
;
2028 sal
.line
= default_breakpoint_line
;
2029 sal
.symtab
= default_breakpoint_symtab
;
2034 error ("No default breakpoint address now.");
2040 /* Force almost all breakpoints to be in terms of the
2041 current_source_symtab (which is decode_line_1's default). This
2042 should produce the results we want almost all of the time while
2043 leaving default_breakpoint_* alone. */
2044 if (default_breakpoint_valid
2045 && (!current_source_symtab
2046 || (arg
&& (*arg
== '+' || *arg
== '-'))))
2047 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2048 default_breakpoint_line
, &canonical
);
2050 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
2058 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2059 the following `for' loop errors out. */
2060 old_chain
= make_cleanup (free
, sals
.sals
);
2061 if (canonical
!= (char **)NULL
)
2063 make_cleanup (free
, canonical
);
2064 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
2065 for (i
= 0; i
< sals
.nelts
; i
++)
2067 if (canonical
[i
] != NULL
)
2068 make_cleanup (free
, canonical
[i
]);
2072 thread
= -1; /* No specific thread yet */
2074 /* Resolve all line numbers to PC's, and verify that conditions
2075 can be parsed, before setting any breakpoints. */
2076 for (i
= 0; i
< sals
.nelts
; i
++)
2078 char *tok
, *end_tok
;
2081 resolve_sal_pc (&sals
.sals
[i
]);
2087 while (*tok
== ' ' || *tok
== '\t')
2092 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2095 toklen
= end_tok
- tok
;
2097 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2099 tok
= cond_start
= end_tok
+ 1;
2100 cond
= parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
2103 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
2109 thread
= strtol (tok
, &tok
, 0);
2111 error ("Junk after thread keyword.");
2112 if (!valid_thread_id (thread
))
2113 error ("Unknown thread %d\n", thread
);
2116 error ("Junk at end of arguments.");
2120 /* Remove the canonical strings from the cleanup, they are needed below. */
2121 if (canonical
!= (char **)NULL
)
2122 discard_cleanups (canonical_strings_chain
);
2124 /* Now set all the breakpoints. */
2125 for (i
= 0; i
< sals
.nelts
; i
++)
2130 describe_other_breakpoints (sal
.pc
);
2132 b
= set_raw_breakpoint (sal
);
2133 set_breakpoint_count (breakpoint_count
+ 1);
2134 b
->number
= breakpoint_count
;
2135 b
->type
= bp_breakpoint
;
2139 /* If a canonical line spec is needed use that instead of the
2141 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
2142 b
->addr_string
= canonical
[i
];
2143 else if (addr_start
)
2144 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
2146 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2148 b
->enable
= enabled
;
2149 b
->disposition
= tempflag
? delete : donttouch
;
2156 printf_filtered ("Multiple breakpoints were set.\n");
2157 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2159 do_cleanups (old_chain
);
2162 /* Helper function for break_command_1 and disassemble_command. */
2165 resolve_sal_pc (sal
)
2166 struct symtab_and_line
*sal
;
2170 if (sal
->pc
== 0 && sal
->symtab
!= 0)
2172 pc
= find_line_pc (sal
->symtab
, sal
->line
);
2174 error ("No line %d in file \"%s\".",
2175 sal
->line
, sal
->symtab
->filename
);
2181 break_command (arg
, from_tty
)
2185 break_command_1 (arg
, 0, from_tty
);
2189 tbreak_command (arg
, from_tty
)
2193 break_command_1 (arg
, 1, from_tty
);
2198 watch_command (arg
, from_tty
)
2202 struct breakpoint
*b
;
2203 struct symtab_and_line sal
;
2204 struct expression
*exp
;
2205 struct block
*exp_valid_block
;
2207 FRAME frame
, prev_frame
;
2213 /* Parse arguments. */
2214 innermost_block
= NULL
;
2215 exp
= parse_expression (arg
);
2216 exp_valid_block
= innermost_block
;
2217 val
= evaluate_expression (exp
);
2218 release_value (val
);
2219 if (VALUE_LAZY (val
))
2220 value_fetch_lazy (val
);
2222 /* Now set up the breakpoint. */
2223 b
= set_raw_breakpoint (sal
);
2224 set_breakpoint_count (breakpoint_count
+ 1);
2225 b
->number
= breakpoint_count
;
2226 b
->disposition
= donttouch
;
2228 b
->exp_valid_block
= exp_valid_block
;
2231 b
->cond_string
= NULL
;
2232 b
->exp_string
= savestring (arg
, strlen (arg
));
2234 frame
= block_innermost_frame (exp_valid_block
);
2237 prev_frame
= get_prev_frame (frame
);
2238 b
->watchpoint_frame
= FRAME_FP (frame
);
2241 b
->watchpoint_frame
= NULL
;
2243 if (can_use_hardware_watchpoint (b
))
2244 b
->type
= bp_hardware_watchpoint
;
2246 b
->type
= bp_watchpoint
;
2248 /* If the expression is "local", then set up a "watchpoint scope"
2249 breakpoint at the point where we've left the scope of the watchpoint
2251 if (innermost_block
)
2253 struct breakpoint
*scope_breakpoint
;
2254 struct symtab_and_line scope_sal
;
2258 scope_sal
.pc
= get_frame_pc (prev_frame
);
2259 scope_sal
.symtab
= NULL
;
2262 scope_breakpoint
= set_raw_breakpoint (scope_sal
);
2263 set_breakpoint_count (breakpoint_count
+ 1);
2264 scope_breakpoint
->number
= breakpoint_count
;
2266 scope_breakpoint
->type
= bp_watchpoint_scope
;
2267 scope_breakpoint
->enable
= enabled
;
2269 /* Automatically delete the breakpoint when it hits. */
2270 scope_breakpoint
->disposition
= delete;
2272 /* Only break in the proper frame (help with recursion). */
2273 scope_breakpoint
->frame
= prev_frame
->frame
;
2275 /* Set the address at which we will stop. */
2276 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
2278 /* The scope breakpoint is related to the watchpoint. We
2279 will need to act on them together. */
2280 b
->related_breakpoint
= scope_breakpoint
;
2287 /* Return nonzero if the watchpoint described by B can be handled
2288 completely in hardware. If the watchpoint can not be handled
2289 in hardware return zero. */
2292 can_use_hardware_watchpoint (b
)
2293 struct breakpoint
*b
;
2295 value_ptr mark
= value_mark ();
2296 value_ptr v
= evaluate_expression (b
->exp
);
2297 int found_memory
= 0;
2299 /* Make sure all the intermediate values are in memory. Also make sure
2300 we found at least one memory expression. Guards against watch 0x12345,
2301 which is meaningless, but could cause errors if one tries to insert a
2302 hardware watchpoint for the constant expression. */
2303 for ( ; v
!= mark
; v
= v
->next
)
2305 if (!(v
->lval
== lval_memory
)
2306 || v
->lval
== not_lval
2307 || (v
->lval
!= not_lval
2308 && v
->modifiable
== 0))
2311 if (v
->lval
== lval_memory
)
2315 /* The expression itself looks suitable for using a hardware
2316 watchpoint, but give the target machine a chance to reject it. */
2317 return found_memory
&& TARGET_CAN_USE_HARDWARE_WATCHPOINT (b
);
2322 * Helper routine for the until_command routine in infcmd.c. Here
2323 * because it uses the mechanisms of breakpoints.
2327 until_break_command (arg
, from_tty
)
2331 struct symtabs_and_lines sals
;
2332 struct symtab_and_line sal
;
2333 FRAME prev_frame
= get_prev_frame (selected_frame
);
2334 struct breakpoint
*breakpoint
;
2335 struct cleanup
*old_chain
;
2337 clear_proceed_status ();
2339 /* Set a breakpoint where the user wants it and at return from
2342 if (default_breakpoint_valid
)
2343 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2344 default_breakpoint_line
, (char ***)NULL
);
2346 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2348 if (sals
.nelts
!= 1)
2349 error ("Couldn't get information on specified line.");
2352 free ((PTR
)sals
.sals
); /* malloc'd, so freed */
2355 error ("Junk at end of arguments.");
2357 resolve_sal_pc (&sal
);
2359 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
2361 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
2363 /* Keep within the current frame */
2367 struct frame_info
*fi
;
2369 fi
= get_frame_info (prev_frame
);
2370 sal
= find_pc_line (fi
->pc
, 0);
2372 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
2373 make_cleanup(delete_breakpoint
, breakpoint
);
2376 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
2377 do_cleanups(old_chain
);
2381 /* These aren't used; I don't konw what they were for. */
2382 /* Set a breakpoint at the catch clause for NAME. */
2384 catch_breakpoint (name
)
2390 disable_catch_breakpoint ()
2395 delete_catch_breakpoint ()
2400 enable_catch_breakpoint ()
2407 struct sal_chain
*next
;
2408 struct symtab_and_line sal
;
2412 /* This isn't used; I don't know what it was for. */
2413 /* For each catch clause identified in ARGS, run FUNCTION
2414 with that clause as an argument. */
2415 static struct symtabs_and_lines
2416 map_catch_names (args
, function
)
2420 register char *p
= args
;
2422 struct symtabs_and_lines sals
;
2424 struct sal_chain
*sal_chain
= 0;
2428 error_no_arg ("one or more catch names");
2436 /* Don't swallow conditional part. */
2437 if (p1
[0] == 'i' && p1
[1] == 'f'
2438 && (p1
[2] == ' ' || p1
[2] == '\t'))
2444 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
2448 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
2449 error ("Arguments must be catch names.");
2455 struct sal_chain
*next
2456 = (struct sal_chain
*)alloca (sizeof (struct sal_chain
));
2457 next
->next
= sal_chain
;
2458 next
->sal
= get_catch_sal (p
);
2463 printf_unfiltered ("No catch clause for exception %s.\n", p
);
2468 while (*p
== ' ' || *p
== '\t') p
++;
2473 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2475 static struct symtabs_and_lines
2476 get_catch_sals (this_level_only
)
2477 int this_level_only
;
2479 register struct blockvector
*bl
;
2480 register struct block
*block
;
2481 int index
, have_default
= 0;
2482 struct frame_info
*fi
;
2484 struct symtabs_and_lines sals
;
2485 struct sal_chain
*sal_chain
= 0;
2486 char *blocks_searched
;
2488 /* Not sure whether an error message is always the correct response,
2489 but it's better than a core dump. */
2490 if (selected_frame
== NULL
)
2491 error ("No selected frame.");
2492 block
= get_frame_block (selected_frame
);
2493 fi
= get_frame_info (selected_frame
);
2500 error ("No symbol table info available.\n");
2502 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
2503 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2504 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2508 CORE_ADDR end
= BLOCK_END (block
) - 4;
2511 if (bl
!= blockvector_for_pc (end
, &index
))
2512 error ("blockvector blotch");
2513 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
2514 error ("blockvector botch");
2515 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
2518 /* Don't print out blocks that have gone by. */
2519 while (index
< last_index
2520 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
2523 while (index
< last_index
2524 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
2526 if (blocks_searched
[index
] == 0)
2528 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
2531 register struct symbol
*sym
;
2533 nsyms
= BLOCK_NSYMS (b
);
2535 for (i
= 0; i
< nsyms
; i
++)
2537 sym
= BLOCK_SYM (b
, i
);
2538 if (STREQ (SYMBOL_NAME (sym
), "default"))
2544 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
2546 struct sal_chain
*next
= (struct sal_chain
*)
2547 alloca (sizeof (struct sal_chain
));
2548 next
->next
= sal_chain
;
2549 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
2553 blocks_searched
[index
] = 1;
2559 if (sal_chain
&& this_level_only
)
2562 /* After handling the function's top-level block, stop.
2563 Don't continue to its superblock, the block of
2564 per-file symbols. */
2565 if (BLOCK_FUNCTION (block
))
2567 block
= BLOCK_SUPERBLOCK (block
);
2572 struct sal_chain
*tmp_chain
;
2574 /* Count the number of entries. */
2575 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
2576 tmp_chain
= tmp_chain
->next
)
2580 sals
.sals
= (struct symtab_and_line
*)
2581 xmalloc (index
* sizeof (struct symtab_and_line
));
2582 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
2583 sals
.sals
[index
] = sal_chain
->sal
;
2589 /* Commands to deal with catching exceptions. */
2592 catch_command_1 (arg
, tempflag
, from_tty
)
2597 /* First, translate ARG into something we can deal with in terms
2600 struct symtabs_and_lines sals
;
2601 struct symtab_and_line sal
;
2602 register struct expression
*cond
= 0;
2603 register struct breakpoint
*b
;
2607 sal
.line
= sal
.pc
= sal
.end
= 0;
2610 /* If no arg given, or if first arg is 'if ', all active catch clauses
2611 are breakpointed. */
2613 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2614 && (arg
[2] == ' ' || arg
[2] == '\t')))
2616 /* Grab all active catch clauses. */
2617 sals
= get_catch_sals (0);
2621 /* Grab selected catch clauses. */
2622 error ("catch NAME not implemented");
2624 /* This isn't used; I don't know what it was for. */
2625 sals
= map_catch_names (arg
, catch_breakpoint
);
2633 for (i
= 0; i
< sals
.nelts
; i
++)
2635 resolve_sal_pc (&sals
.sals
[i
]);
2639 if (arg
[0] == 'i' && arg
[1] == 'f'
2640 && (arg
[2] == ' ' || arg
[2] == '\t'))
2641 cond
= parse_exp_1 ((arg
+= 2, &arg
),
2642 block_for_pc (sals
.sals
[i
].pc
), 0);
2644 error ("Junk at end of arguments.");
2649 for (i
= 0; i
< sals
.nelts
; i
++)
2654 describe_other_breakpoints (sal
.pc
);
2656 b
= set_raw_breakpoint (sal
);
2657 set_breakpoint_count (breakpoint_count
+ 1);
2658 b
->number
= breakpoint_count
;
2659 b
->type
= bp_breakpoint
;
2661 b
->enable
= enabled
;
2662 b
->disposition
= tempflag
? delete : donttouch
;
2669 printf_unfiltered ("Multiple breakpoints were set.\n");
2670 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2672 free ((PTR
)sals
.sals
);
2676 /* These aren't used; I don't know what they were for. */
2677 /* Disable breakpoints on all catch clauses described in ARGS. */
2679 disable_catch (args
)
2682 /* Map the disable command to catch clauses described in ARGS. */
2685 /* Enable breakpoints on all catch clauses described in ARGS. */
2690 /* Map the disable command to catch clauses described in ARGS. */
2693 /* Delete breakpoints on all catch clauses in the active scope. */
2698 /* Map the delete command to catch clauses described in ARGS. */
2703 catch_command (arg
, from_tty
)
2707 catch_command_1 (arg
, 0, from_tty
);
2711 clear_command (arg
, from_tty
)
2715 register struct breakpoint
*b
, *b1
;
2716 struct symtabs_and_lines sals
;
2717 struct symtab_and_line sal
;
2718 register struct breakpoint
*found
;
2723 sals
= decode_line_spec (arg
, 1);
2727 sals
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
2728 sal
.line
= default_breakpoint_line
;
2729 sal
.symtab
= default_breakpoint_symtab
;
2731 if (sal
.symtab
== 0)
2732 error ("No source file specified.");
2738 for (i
= 0; i
< sals
.nelts
; i
++)
2740 /* If exact pc given, clear bpts at that pc.
2741 But if sal.pc is zero, clear all bpts on specified line. */
2743 found
= (struct breakpoint
*) 0;
2744 while (breakpoint_chain
2746 ? breakpoint_chain
->address
== sal
.pc
2747 : (breakpoint_chain
->source_file
!= NULL
2748 && sal
.symtab
!= NULL
2749 && STREQ (breakpoint_chain
->source_file
,
2750 sal
.symtab
->filename
)
2751 && breakpoint_chain
->line_number
== sal
.line
)))
2753 b1
= breakpoint_chain
;
2754 breakpoint_chain
= b1
->next
;
2761 && b
->next
->type
!= bp_watchpoint
2762 && b
->next
->type
!= bp_hardware_watchpoint
2764 ? b
->next
->address
== sal
.pc
2765 : (b
->next
->source_file
!= NULL
2766 && sal
.symtab
!= NULL
2767 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
2768 && b
->next
->line_number
== sal
.line
)))
2779 error ("No breakpoint at %s.", arg
);
2781 error ("No breakpoint at this line.");
2784 if (found
->next
) from_tty
= 1; /* Always report if deleted more than one */
2785 if (from_tty
) printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
2786 breakpoints_changed ();
2789 if (from_tty
) printf_unfiltered ("%d ", found
->number
);
2791 delete_breakpoint (found
);
2794 if (from_tty
) putchar_unfiltered ('\n');
2796 free ((PTR
)sals
.sals
);
2799 /* Delete breakpoint in BS if they are `delete' breakpoints.
2800 This is called after any breakpoint is hit, or after errors. */
2803 breakpoint_auto_delete (bs
)
2806 for (; bs
; bs
= bs
->next
)
2807 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== delete
2809 delete_breakpoint (bs
->breakpoint_at
);
2812 /* Delete a breakpoint and clean up all traces of it in the data structures. */
2815 delete_breakpoint (bpt
)
2816 struct breakpoint
*bpt
;
2818 register struct breakpoint
*b
;
2822 remove_breakpoint (bpt
);
2824 if (breakpoint_chain
== bpt
)
2825 breakpoint_chain
= bpt
->next
;
2830 b
->next
= bpt
->next
;
2834 check_duplicates (bpt
->address
);
2835 /* If this breakpoint was inserted, and there is another breakpoint
2836 at the same address, we need to insert the other breakpoint. */
2838 && bpt
->type
!= bp_hardware_watchpoint
)
2841 if (b
->address
== bpt
->address
2843 && b
->enable
!= disabled
)
2846 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
2849 target_terminal_ours_for_output ();
2850 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
2851 memory_error (val
, b
->address
); /* which bombs us out */
2858 free_command_lines (&bpt
->commands
);
2861 if (bpt
->cond_string
!= NULL
)
2862 free (bpt
->cond_string
);
2863 if (bpt
->addr_string
!= NULL
)
2864 free (bpt
->addr_string
);
2865 if (bpt
->exp_string
!= NULL
)
2866 free (bpt
->exp_string
);
2867 if (bpt
->source_file
!= NULL
)
2868 free (bpt
->source_file
);
2870 breakpoints_changed ();
2872 /* Be sure no bpstat's are pointing at it after it's been freed. */
2873 /* FIXME, how can we find all bpstat's?
2874 We just check stop_bpstat for now. */
2875 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
2876 if (bs
->breakpoint_at
== bpt
)
2877 bs
->breakpoint_at
= NULL
;
2882 delete_command (arg
, from_tty
)
2889 /* Ask user only if there are some breakpoints to delete. */
2891 || (breakpoint_chain
&& query ("Delete all breakpoints? ", 0, 0)))
2893 /* No arg; clear all breakpoints. */
2894 while (breakpoint_chain
)
2895 delete_breakpoint (breakpoint_chain
);
2899 map_breakpoint_numbers (arg
, delete_breakpoint
);
2902 /* Reset a breakpoint given it's struct breakpoint * BINT.
2903 The value we return ends up being the return value from catch_errors.
2904 Unused in this case. */
2907 breakpoint_re_set_one (bint
)
2910 struct breakpoint
*b
= (struct breakpoint
*)bint
; /* get past catch_errs */
2912 struct symtabs_and_lines sals
;
2914 enum enable save_enable
;
2919 if (b
->addr_string
== NULL
)
2921 /* Anything without a string can't be re-set. */
2922 delete_breakpoint (b
);
2925 /* In case we have a problem, disable this breakpoint. We'll restore
2926 its status if we succeed. */
2927 save_enable
= b
->enable
;
2928 b
->enable
= disabled
;
2931 sals
= decode_line_1 (&s
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2932 for (i
= 0; i
< sals
.nelts
; i
++)
2934 resolve_sal_pc (&sals
.sals
[i
]);
2936 /* Reparse conditions, they might contain references to the
2938 if (b
->cond_string
!= NULL
)
2942 free ((PTR
)b
->cond
);
2943 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
2946 /* We need to re-set the breakpoint if the address changes...*/
2947 if (b
->address
!= sals
.sals
[i
].pc
2948 /* ...or new and old breakpoints both have source files, and
2949 the source file name or the line number changes... */
2950 || (b
->source_file
!= NULL
2951 && sals
.sals
[i
].symtab
!= NULL
2952 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
2953 || b
->line_number
!= sals
.sals
[i
].line
)
2955 /* ...or we switch between having a source file and not having
2957 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
2960 if (b
->source_file
!= NULL
)
2961 free (b
->source_file
);
2962 if (sals
.sals
[i
].symtab
== NULL
)
2963 b
->source_file
= NULL
;
2966 savestring (sals
.sals
[i
].symtab
->filename
,
2967 strlen (sals
.sals
[i
].symtab
->filename
));
2968 b
->line_number
= sals
.sals
[i
].line
;
2969 b
->address
= sals
.sals
[i
].pc
;
2971 check_duplicates (b
->address
);
2975 /* Might be better to do this just once per breakpoint_re_set,
2976 rather than once for every breakpoint. */
2977 breakpoints_changed ();
2979 b
->enable
= save_enable
; /* Restore it, this worked. */
2981 free ((PTR
)sals
.sals
);
2985 case bp_hardware_watchpoint
:
2986 innermost_block
= NULL
;
2987 /* The issue arises of what context to evaluate this in. The same
2988 one as when it was set, but what does that mean when symbols have
2989 been re-read? We could save the filename and functionname, but
2990 if the context is more local than that, the best we could do would
2991 be something like how many levels deep and which index at that
2992 particular level, but that's going to be less stable than filenames
2993 or functionnames. */
2994 /* So for now, just use a global context. */
2995 b
->exp
= parse_expression (b
->exp_string
);
2996 b
->exp_valid_block
= innermost_block
;
2997 b
->val
= evaluate_expression (b
->exp
);
2998 release_value (b
->val
);
2999 if (VALUE_LAZY (b
->val
))
3000 value_fetch_lazy (b
->val
);
3002 if (b
->cond_string
!= NULL
)
3005 b
->cond
= parse_exp_1 (&s
, (struct block
*)0, 0);
3007 if (b
->enable
== enabled
)
3012 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
3017 case bp_longjmp_resume
:
3018 case bp_watchpoint_scope
:
3020 delete_breakpoint (b
);
3027 /* Re-set all breakpoints after symbols have been re-loaded. */
3029 breakpoint_re_set ()
3031 struct breakpoint
*b
, *temp
;
3032 static char message1
[] = "Error in re-setting breakpoint %d:\n";
3033 char message
[sizeof (message1
) + 30 /* slop */];
3035 ALL_BREAKPOINTS_SAFE (b
, temp
)
3037 sprintf (message
, message1
, b
->number
); /* Format possible error msg */
3038 catch_errors (breakpoint_re_set_one
, (char *) b
, message
,
3042 create_longjmp_breakpoint("longjmp");
3043 create_longjmp_breakpoint("_longjmp");
3044 create_longjmp_breakpoint("siglongjmp");
3045 create_longjmp_breakpoint(NULL
);
3048 /* Took this out (temporaliy at least), since it produces an extra
3049 blank line at startup. This messes up the gdbtests. -PB */
3050 /* Blank line to finish off all those mention() messages we just printed. */
3051 printf_filtered ("\n");
3055 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3056 If from_tty is nonzero, it prints a message to that effect,
3057 which ends with a period (no newline). */
3060 set_ignore_count (bptnum
, count
, from_tty
)
3061 int bptnum
, count
, from_tty
;
3063 register struct breakpoint
*b
;
3069 if (b
->number
== bptnum
)
3071 b
->ignore_count
= count
;
3074 else if (count
== 0)
3075 printf_filtered ("Will stop next time breakpoint %d is reached.",
3077 else if (count
== 1)
3078 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3081 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3083 breakpoints_changed ();
3087 error ("No breakpoint number %d.", bptnum
);
3090 /* Clear the ignore counts of all breakpoints. */
3092 breakpoint_clear_ignore_counts ()
3094 struct breakpoint
*b
;
3097 b
->ignore_count
= 0;
3100 /* Command to set ignore-count of breakpoint N to COUNT. */
3103 ignore_command (args
, from_tty
)
3111 error_no_arg ("a breakpoint number");
3113 num
= get_number (&p
);
3116 error ("Second argument (specified ignore-count) is missing.");
3118 set_ignore_count (num
,
3119 longest_to_int (value_as_long (parse_and_eval (p
))),
3121 printf_filtered ("\n");
3122 breakpoints_changed ();
3125 /* Call FUNCTION on each of the breakpoints
3126 whose numbers are given in ARGS. */
3129 map_breakpoint_numbers (args
, function
)
3131 void (*function
) PARAMS ((struct breakpoint
*));
3133 register char *p
= args
;
3136 register struct breakpoint
*b
;
3139 error_no_arg ("one or more breakpoint numbers");
3145 num
= get_number (&p1
);
3148 if (b
->number
== num
)
3150 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
3152 if (related_breakpoint
)
3153 function (related_breakpoint
);
3156 printf_unfiltered ("No breakpoint number %d.\n", num
);
3163 enable_breakpoint (bpt
)
3164 struct breakpoint
*bpt
;
3166 FRAME save_selected_frame
= NULL
;
3167 int save_selected_frame_level
= -1;
3169 bpt
->enable
= enabled
;
3171 breakpoints_changed ();
3173 check_duplicates (bpt
->address
);
3174 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
)
3176 if (bpt
->exp_valid_block
!= NULL
)
3178 FRAME fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3182 Cannot enable watchpoint %d because the block in which its expression\n\
3183 is valid is not currently in scope.\n", bpt
->number
);
3184 bpt
->enable
= disabled
;
3188 save_selected_frame
= selected_frame
;
3189 save_selected_frame_level
= selected_frame_level
;
3190 select_frame (fr
, -1);
3193 value_free (bpt
->val
);
3195 bpt
->val
= evaluate_expression (bpt
->exp
);
3196 release_value (bpt
->val
);
3197 if (VALUE_LAZY (bpt
->val
))
3198 value_fetch_lazy (bpt
->val
);
3200 if (save_selected_frame_level
>= 0)
3201 select_frame (save_selected_frame
, save_selected_frame_level
);
3207 enable_command (args
, from_tty
)
3211 struct breakpoint
*bpt
;
3213 ALL_BREAKPOINTS (bpt
)
3218 case bp_hardware_watchpoint
:
3219 enable_breakpoint (bpt
);
3224 map_breakpoint_numbers (args
, enable_breakpoint
);
3228 disable_breakpoint (bpt
)
3229 struct breakpoint
*bpt
;
3231 /* Never disable a watchpoint scope breakpoint; we want to
3232 hit them when we leave scope so we can delete both the
3233 watchpoint and its scope breakpoint at that time. */
3234 if (bpt
->type
== bp_watchpoint_scope
)
3237 bpt
->enable
= disabled
;
3239 breakpoints_changed ();
3241 check_duplicates (bpt
->address
);
3246 disable_command (args
, from_tty
)
3250 register struct breakpoint
*bpt
;
3252 ALL_BREAKPOINTS (bpt
)
3257 case bp_hardware_watchpoint
:
3258 disable_breakpoint (bpt
);
3263 map_breakpoint_numbers (args
, disable_breakpoint
);
3267 enable_once_breakpoint (bpt
)
3268 struct breakpoint
*bpt
;
3270 bpt
->enable
= enabled
;
3271 bpt
->disposition
= disable
;
3273 check_duplicates (bpt
->address
);
3274 breakpoints_changed ();
3279 enable_once_command (args
, from_tty
)
3283 map_breakpoint_numbers (args
, enable_once_breakpoint
);
3287 enable_delete_breakpoint (bpt
)
3288 struct breakpoint
*bpt
;
3290 bpt
->enable
= enabled
;
3291 bpt
->disposition
= delete;
3293 check_duplicates (bpt
->address
);
3294 breakpoints_changed ();
3299 enable_delete_command (args
, from_tty
)
3303 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
3307 * Use default_breakpoint_'s, or nothing if they aren't valid.
3309 struct symtabs_and_lines
3310 decode_line_spec_1 (string
, funfirstline
)
3314 struct symtabs_and_lines sals
;
3316 error ("Empty line specification.");
3317 if (default_breakpoint_valid
)
3318 sals
= decode_line_1 (&string
, funfirstline
,
3319 default_breakpoint_symtab
, default_breakpoint_line
,
3322 sals
= decode_line_1 (&string
, funfirstline
,
3323 (struct symtab
*)NULL
, 0, (char ***)NULL
);
3325 error ("Junk at end of line specification: %s", string
);
3330 _initialize_breakpoint ()
3332 breakpoint_chain
= 0;
3333 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3334 before a breakpoint is set. */
3335 breakpoint_count
= 0;
3337 add_com ("ignore", class_breakpoint
, ignore_command
,
3338 "Set ignore-count of breakpoint number N to COUNT.");
3340 add_com ("commands", class_breakpoint
, commands_command
,
3341 "Set commands to be executed when a breakpoint is hit.\n\
3342 Give breakpoint number as argument after \"commands\".\n\
3343 With no argument, the targeted breakpoint is the last one set.\n\
3344 The commands themselves follow starting on the next line.\n\
3345 Type a line containing \"end\" to indicate the end of them.\n\
3346 Give \"silent\" as the first line to make the breakpoint silent;\n\
3347 then no output is printed when it is hit, except what the commands print.");
3349 add_com ("condition", class_breakpoint
, condition_command
,
3350 "Specify breakpoint number N to break only if COND is true.\n\
3351 N is an integer; COND is an expression to be evaluated whenever\n\
3352 breakpoint N is reached. ");
3354 add_com ("tbreak", class_breakpoint
, tbreak_command
,
3355 "Set a temporary breakpoint. Args like \"break\" command.\n\
3356 Like \"break\" except the breakpoint is only temporary,\n\
3357 so it will be deleted when hit. Equivalent to \"break\" followed\n\
3358 by using \"enable delete\" on the breakpoint number.");
3360 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
3361 "Enable some breakpoints.\n\
3362 Give breakpoint numbers (separated by spaces) as arguments.\n\
3363 With no subcommand, breakpoints are enabled until you command otherwise.\n\
3364 This is used to cancel the effect of the \"disable\" command.\n\
3365 With a subcommand you can enable temporarily.",
3366 &enablelist
, "enable ", 1, &cmdlist
);
3368 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
3369 "Enable some breakpoints.\n\
3370 Give breakpoint numbers (separated by spaces) as arguments.\n\
3371 This is used to cancel the effect of the \"disable\" command.\n\
3372 May be abbreviated to simply \"enable\".\n",
3373 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
3375 add_cmd ("once", no_class
, enable_once_command
,
3376 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3377 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3380 add_cmd ("delete", no_class
, enable_delete_command
,
3381 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3382 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3385 add_cmd ("delete", no_class
, enable_delete_command
,
3386 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3387 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3390 add_cmd ("once", no_class
, enable_once_command
,
3391 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3392 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3395 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
3396 "Disable some breakpoints.\n\
3397 Arguments are breakpoint numbers with spaces in between.\n\
3398 To disable all breakpoints, give no argument.\n\
3399 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3400 &disablelist
, "disable ", 1, &cmdlist
);
3401 add_com_alias ("dis", "disable", class_breakpoint
, 1);
3402 add_com_alias ("disa", "disable", class_breakpoint
, 1);
3404 add_cmd ("breakpoints", class_alias
, disable_command
,
3405 "Disable some breakpoints.\n\
3406 Arguments are breakpoint numbers with spaces in between.\n\
3407 To disable all breakpoints, give no argument.\n\
3408 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3409 This command may be abbreviated \"disable\".",
3412 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
3413 "Delete some breakpoints or auto-display expressions.\n\
3414 Arguments are breakpoint numbers with spaces in between.\n\
3415 To delete all breakpoints, give no argument.\n\
3417 Also a prefix command for deletion of other GDB objects.\n\
3418 The \"unset\" command is also an alias for \"delete\".",
3419 &deletelist
, "delete ", 1, &cmdlist
);
3420 add_com_alias ("d", "delete", class_breakpoint
, 1);
3422 add_cmd ("breakpoints", class_alias
, delete_command
,
3423 "Delete some breakpoints or auto-display expressions.\n\
3424 Arguments are breakpoint numbers with spaces in between.\n\
3425 To delete all breakpoints, give no argument.\n\
3426 This command may be abbreviated \"delete\".",
3429 add_com ("clear", class_breakpoint
, clear_command
,
3430 "Clear breakpoint at specified line or function.\n\
3431 Argument may be line number, function name, or \"*\" and an address.\n\
3432 If line number is specified, all breakpoints in that line are cleared.\n\
3433 If function is specified, breakpoints at beginning of function are cleared.\n\
3434 If an address is specified, breakpoints at that address are cleared.\n\n\
3435 With no argument, clears all breakpoints in the line that the selected frame\n\
3438 See also the \"delete\" command which clears breakpoints by number.");
3440 add_com ("break", class_breakpoint
, break_command
,
3441 "Set breakpoint at specified line or function.\n\
3442 Argument may be line number, function name, or \"*\" and an address.\n\
3443 If line number is specified, break at start of code for that line.\n\
3444 If function is specified, break at start of code for that function.\n\
3445 If an address is specified, break at that exact address.\n\
3446 With no arg, uses current execution address of selected stack frame.\n\
3447 This is useful for breaking on return to a stack frame.\n\
3449 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3451 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3452 add_com_alias ("b", "break", class_run
, 1);
3453 add_com_alias ("br", "break", class_run
, 1);
3454 add_com_alias ("bre", "break", class_run
, 1);
3455 add_com_alias ("brea", "break", class_run
, 1);
3457 add_info ("breakpoints", breakpoints_info
,
3458 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3459 The \"Type\" column indicates one of:\n\
3460 \tbreakpoint - normal breakpoint\n\
3461 \twatchpoint - watchpoint\n\
3462 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3463 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3464 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3465 address and file/line number respectively.\n\n\
3466 Convenience variable \"$_\" and default examine address for \"x\"\n\
3467 are set to the address of the last breakpoint listed.\n\n\
3468 Convenience variable \"$bpnum\" contains the number of the last\n\
3471 #if MAINTENANCE_CMDS
3473 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
3474 "Status of all breakpoints, or breakpoint number NUMBER.\n\
3475 The \"Type\" column indicates one of:\n\
3476 \tbreakpoint - normal breakpoint\n\
3477 \twatchpoint - watchpoint\n\
3478 \tlongjmp - internal breakpoint used to step through longjmp()\n\
3479 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
3480 \tuntil - internal breakpoint used by the \"until\" command\n\
3481 \tfinish - internal breakpoint used by the \"finish\" command\n\
3482 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3483 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3484 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3485 address and file/line number respectively.\n\n\
3486 Convenience variable \"$_\" and default examine address for \"x\"\n\
3487 are set to the address of the last breakpoint listed.\n\n\
3488 Convenience variable \"$bpnum\" contains the number of the last\n\
3490 &maintenanceinfolist
);
3492 #endif /* MAINTENANCE_CMDS */
3494 add_com ("catch", class_breakpoint
, catch_command
,
3495 "Set breakpoints to catch exceptions that are raised.\n\
3496 Argument may be a single exception to catch, multiple exceptions\n\
3497 to catch, or the default exception \"default\". If no arguments\n\
3498 are given, breakpoints are set at all exception handlers catch clauses\n\
3499 within the current scope.\n\
3501 A condition specified for the catch applies to all breakpoints set\n\
3502 with this command\n\
3504 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3506 add_com ("watch", class_breakpoint
, watch_command
,
3507 "Set a watchpoint for an expression.\n\
3508 A watchpoint stops execution of your program whenever the value of\n\
3509 an expression changes.");
3511 add_info ("watchpoints", breakpoints_info
,
3512 "Synonym for ``info breakpoints''.");
3515 /* OK, when we call objfile_relocate, we need to relocate breakpoints
3516 too. breakpoint_re_set is not a good choice--for example, if
3517 addr_string contains just a line number without a file name the
3518 breakpoint might get set in a different file. In general, there is
3519 no need to go all the way back to the user's string (though this might
3520 work if some effort were made to canonicalize it), since symtabs and
3521 everything except addresses are still valid.
3523 Probably the best way to solve this is to have each breakpoint save
3524 the objfile and the section number that was used to set it (if set
3525 by "*addr", probably it is best to use find_pc_line to get a symtab
3526 and use the objfile and block_line_section for that symtab). Then
3527 objfile_relocate can call fixup_breakpoints with the objfile and
3528 the new_offsets, and it can relocate only the appropriate breakpoints. */
3530 #ifdef IBM6000_TARGET
3531 /* But for now, just kludge it based on the concept that before an
3532 objfile is relocated the breakpoint is below 0x10000000, and afterwards
3533 it is higher, so that way we only relocate each breakpoint once. */
3536 fixup_breakpoints (low
, high
, delta
)
3541 struct breakpoint
*b
;
3545 if (b
->address
>= low
&& b
->address
<= high
)
3546 b
->address
+= delta
;