1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "breakpoint.h"
27 #include "expression.h"
41 /* local function prototypes */
44 catch_command_1
PARAMS ((char *, int, int));
47 enable_delete_command
PARAMS ((char *, int));
50 enable_delete_breakpoint
PARAMS ((struct breakpoint
*));
53 enable_once_command
PARAMS ((char *, int));
56 enable_once_breakpoint
PARAMS ((struct breakpoint
*));
59 disable_command
PARAMS ((char *, int));
62 enable_command
PARAMS ((char *, int));
65 map_breakpoint_numbers
PARAMS ((char *, void (*)(struct breakpoint
*)));
68 ignore_command
PARAMS ((char *, int));
71 breakpoint_re_set_one
PARAMS ((char *));
74 delete_command
PARAMS ((char *, int));
77 clear_command
PARAMS ((char *, int));
80 catch_command
PARAMS ((char *, int));
82 static struct symtabs_and_lines
83 get_catch_sals
PARAMS ((int));
86 watch_command
PARAMS ((char *, int));
89 can_use_hardware_watchpoint
PARAMS ((struct value
*));
92 tbreak_command
PARAMS ((char *, int));
95 break_command_1
PARAMS ((char *, int, int));
98 mention
PARAMS ((struct breakpoint
*));
100 static struct breakpoint
*
101 set_raw_breakpoint
PARAMS ((struct symtab_and_line
));
104 check_duplicates
PARAMS ((CORE_ADDR
));
107 describe_other_breakpoints
PARAMS ((CORE_ADDR
));
110 breakpoints_info
PARAMS ((char *, int));
113 breakpoint_1
PARAMS ((int, int));
116 bpstat_alloc
PARAMS ((struct breakpoint
*, bpstat
));
119 breakpoint_cond_eval
PARAMS ((char *));
122 cleanup_executing_breakpoints
PARAMS ((int));
125 commands_command
PARAMS ((char *, int));
128 condition_command
PARAMS ((char *, int));
131 get_number
PARAMS ((char **));
134 set_breakpoint_count
PARAMS ((int));
137 remove_breakpoint
PARAMS ((struct breakpoint
*));
139 extern int addressprint
; /* Print machine addresses? */
141 /* Are we executing breakpoint commands? */
142 static int executing_breakpoint_commands
;
144 /* Walk the following statement or block through all breakpoints.
145 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
148 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
150 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
151 for (b = breakpoint_chain; \
152 b? (tmp=b->next, 1): 0; \
155 /* Provide defaults for systems that don't support hardware watchpoints. */
157 #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT
159 /* Returns non-zero if we can set a hardware watchpoint of type TYPE. TYPE is
160 one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint, or
161 bp_hardware_breakpoint. CNT is the number of such watchpoints used so far
162 (including this one?). OTHERTYPE is who knows what... */
164 #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) 0
166 /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes. TYPE is 1
167 for read and 2 for read/write accesses. Returns 0 for success, non-zero for
170 #define target_remove_watchpoint(ADDR,LEN,TYPE) -1
171 #define target_insert_watchpoint(ADDR,LEN,TYPE) -1
174 #ifndef target_insert_hw_breakpoint
175 #define target_remove_hw_breakpoint(ADDR,SHADOW) -1
176 #define target_insert_hw_breakpoint(ADDR,SHADOW) -1
179 #ifndef target_stopped_data_address
180 #define target_stopped_data_address() 0
183 /* True if breakpoint hit counts should be displayed in breakpoint info. */
185 int show_breakpoint_hit_counts
= 1;
187 /* Chain of all breakpoints defined. */
189 struct breakpoint
*breakpoint_chain
;
191 /* Number of last breakpoint made. */
193 static int breakpoint_count
;
195 /* Set breakpoint count to NUM. */
198 set_breakpoint_count (num
)
201 breakpoint_count
= num
;
202 set_internalvar (lookup_internalvar ("bpnum"),
203 value_from_longest (builtin_type_int
, (LONGEST
) num
));
206 /* Used in run_command to zero the hit count when a new run starts. */
209 clear_breakpoint_hit_counts ()
211 struct breakpoint
*b
;
217 /* Default address, symtab and line to put a breakpoint at
218 for "break" command with no arg.
219 if default_breakpoint_valid is zero, the other three are
220 not valid, and "break" with no arg is an error.
222 This set by print_stack_frame, which calls set_default_breakpoint. */
224 int default_breakpoint_valid
;
225 CORE_ADDR default_breakpoint_address
;
226 struct symtab
*default_breakpoint_symtab
;
227 int default_breakpoint_line
;
229 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
230 Advance *PP after the string and any trailing whitespace.
232 Currently the string can either be a number or "$" followed by the name
233 of a convenience variable. Making it an expression wouldn't work well
234 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
243 /* Empty line means refer to the last breakpoint. */
244 return breakpoint_count
;
247 /* Make a copy of the name, so we can null-terminate it
248 to pass to lookup_internalvar(). */
253 while (isalnum (*p
) || *p
== '_')
255 varname
= (char *) alloca (p
- start
+ 1);
256 strncpy (varname
, start
, p
- start
);
257 varname
[p
- start
] = '\0';
258 val
= value_of_internalvar (lookup_internalvar (varname
));
259 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
261 "Convenience variables used to specify breakpoints must have integer values."
263 retval
= (int) value_as_long (val
);
269 while (*p
>= '0' && *p
<= '9')
272 /* There is no number here. (e.g. "cond a == b"). */
273 error_no_arg ("breakpoint number");
276 if (!(isspace (*p
) || *p
== '\0'))
277 error ("breakpoint number expected");
284 /* condition N EXP -- set break condition of breakpoint N to EXP. */
287 condition_command (arg
, from_tty
)
291 register struct breakpoint
*b
;
296 error_no_arg ("breakpoint number");
299 bnum
= get_number (&p
);
302 if (b
->number
== bnum
)
309 if (b
->cond_string
!= NULL
)
310 free ((PTR
)b
->cond_string
);
315 b
->cond_string
= NULL
;
317 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
322 /* I don't know if it matters whether this is the string the user
323 typed in or the decompiled expression. */
324 b
->cond_string
= savestring (arg
, strlen (arg
));
325 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
327 error ("Junk at end of expression");
329 breakpoints_changed ();
333 error ("No breakpoint number %d.", bnum
);
338 commands_command (arg
, from_tty
)
342 register struct breakpoint
*b
;
345 struct command_line
*l
;
347 /* If we allowed this, we would have problems with when to
348 free the storage, if we change the commands currently
351 if (executing_breakpoint_commands
)
352 error ("Can't use the \"commands\" command among a breakpoint's commands.");
355 bnum
= get_number (&p
);
357 error ("Unexpected extra arguments following breakpoint number.");
360 if (b
->number
== bnum
)
362 if (from_tty
&& input_from_terminal_p ())
363 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
364 End with a line saying just \"end\".\n", bnum
);
365 l
= read_command_lines ();
366 free_command_lines (&b
->commands
);
368 breakpoints_changed ();
371 error ("No breakpoint number %d.", bnum
);
374 extern int memory_breakpoint_size
; /* from mem-break.c */
376 /* Like target_read_memory() but if breakpoints are inserted, return
377 the shadow contents instead of the breakpoints themselves.
379 Read "memory data" from whatever target or inferior we have.
380 Returns zero if successful, errno value if not. EIO is used
381 for address out of bounds. If breakpoints are inserted, returns
382 shadow contents, not the breakpoints themselves. From breakpoint.c. */
385 read_memory_nobpt (memaddr
, myaddr
, len
)
391 struct breakpoint
*b
;
393 if (memory_breakpoint_size
< 0)
394 /* No breakpoints on this machine. FIXME: This should be
395 dependent on the debugging target. Probably want
396 target_insert_breakpoint to return a size, saying how many
397 bytes of the shadow contents are used, or perhaps have
398 something like target_xfer_shadow. */
399 return target_read_memory (memaddr
, myaddr
, len
);
403 if (b
->type
== bp_watchpoint
404 || b
->type
== bp_hardware_watchpoint
405 || b
->type
== bp_read_watchpoint
406 || b
->type
== bp_access_watchpoint
409 else if (b
->address
+ memory_breakpoint_size
<= memaddr
)
410 /* The breakpoint is entirely before the chunk of memory
413 else if (b
->address
>= memaddr
+ len
)
414 /* The breakpoint is entirely after the chunk of memory we
419 /* Copy the breakpoint from the shadow contents, and recurse
420 for the things before and after. */
422 /* Addresses and length of the part of the breakpoint that
424 CORE_ADDR membpt
= b
->address
;
425 unsigned int bptlen
= memory_breakpoint_size
;
426 /* Offset within shadow_contents. */
429 if (membpt
< memaddr
)
431 /* Only copy the second part of the breakpoint. */
432 bptlen
-= memaddr
- membpt
;
433 bptoffset
= memaddr
- membpt
;
437 if (membpt
+ bptlen
> memaddr
+ len
)
439 /* Only copy the first part of the breakpoint. */
440 bptlen
-= (membpt
+ bptlen
) - (memaddr
+ len
);
443 memcpy (myaddr
+ membpt
- memaddr
,
444 b
->shadow_contents
+ bptoffset
, bptlen
);
446 if (membpt
> memaddr
)
448 /* Copy the section of memory before the breakpoint. */
449 status
= read_memory_nobpt (memaddr
, myaddr
, membpt
- memaddr
);
454 if (membpt
+ bptlen
< memaddr
+ len
)
456 /* Copy the section of memory after the breakpoint. */
457 status
= read_memory_nobpt
459 myaddr
+ membpt
+ bptlen
- memaddr
,
460 memaddr
+ len
- (membpt
+ bptlen
));
467 /* Nothing overlaps. Just call read_memory_noerr. */
468 return target_read_memory (memaddr
, myaddr
, len
);
471 /* insert_breakpoints is used when starting or continuing the program.
472 remove_breakpoints is used when the program stops.
473 Both return zero if successful,
474 or an `errno' value if could not write the inferior. */
477 insert_breakpoints ()
479 register struct breakpoint
*b
;
481 int disabled_breaks
= 0;
484 if (b
->type
!= bp_watchpoint
485 && b
->type
!= bp_hardware_watchpoint
486 && b
->type
!= bp_read_watchpoint
487 && b
->type
!= bp_access_watchpoint
488 && b
->enable
!= disabled
492 if (b
->type
== bp_hardware_breakpoint
)
493 val
= target_insert_hw_breakpoint(b
->address
, b
->shadow_contents
);
495 val
= target_insert_breakpoint(b
->address
, b
->shadow_contents
);
498 /* Can't set the breakpoint. */
499 #if defined (DISABLE_UNSETTABLE_BREAK)
500 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
503 b
->enable
= disabled
;
504 if (!disabled_breaks
)
506 target_terminal_ours_for_output ();
507 fprintf_unfiltered (gdb_stderr
,
508 "Cannot insert breakpoint %d:\n", b
->number
);
509 printf_filtered ("Disabling shared library breakpoints:\n");
512 printf_filtered ("%d ", b
->number
);
517 target_terminal_ours_for_output ();
518 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
519 #ifdef ONE_PROCESS_WRITETEXT
520 fprintf_unfiltered (gdb_stderr
,
521 "The same program may be running in another process.\n");
523 memory_error (val
, b
->address
); /* which bombs us out */
529 else if ((b
->type
== bp_hardware_watchpoint
||
530 b
->type
== bp_read_watchpoint
||
531 b
->type
== bp_access_watchpoint
)
532 && b
->enable
== enabled
536 struct frame_info
*saved_frame
;
537 int saved_level
, within_current_scope
;
538 value_ptr mark
= value_mark ();
541 /* Save the current frame and level so we can restore it after
542 evaluating the watchpoint expression on its own frame. */
543 saved_frame
= selected_frame
;
544 saved_level
= selected_frame_level
;
546 /* Determine if the watchpoint is within scope. */
547 if (b
->exp_valid_block
== NULL
)
548 within_current_scope
= 1;
551 struct frame_info
*fi
=
552 find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
553 within_current_scope
= (fi
!= NULL
);
554 if (within_current_scope
)
555 select_frame (fi
, -1);
558 if (within_current_scope
)
560 /* Evaluate the expression and cut the chain of values
561 produced off from the value chain. */
562 v
= evaluate_expression (b
->exp
);
563 value_release_to_mark (mark
);
568 /* Look at each value on the value chain. */
569 for ( ; v
; v
=v
->next
)
571 /* If it's a memory location, then we must watch it. */
572 if (v
->lval
== lval_memory
)
576 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
577 len
= TYPE_LENGTH (VALUE_TYPE (v
));
579 if (b
->type
== bp_read_watchpoint
)
581 else if (b
->type
== bp_access_watchpoint
)
584 val
= target_insert_watchpoint (addr
, len
, type
);
593 /* Failure to insert a watchpoint on any memory value in the
594 value chain brings us here. */
596 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
602 Hardware watchpoint %d deleted because the program has left the block in\n\
603 which its expression is valid.\n", b
->number
);
604 if (b
->related_breakpoint
)
605 delete_breakpoint (b
->related_breakpoint
);
606 delete_breakpoint (b
);
609 /* Restore the frame and level. */
610 select_frame (saved_frame
, saved_level
);
613 printf_filtered ("\n");
619 remove_breakpoints ()
621 register struct breakpoint
*b
;
628 val
= remove_breakpoint (b
);
638 remove_breakpoint (b
)
639 struct breakpoint
*b
;
643 if (b
->type
!= bp_watchpoint
644 && b
->type
!= bp_hardware_watchpoint
645 && b
->type
!= bp_read_watchpoint
646 && b
->type
!= bp_access_watchpoint
)
648 if (b
->type
== bp_hardware_breakpoint
)
649 val
= target_remove_hw_breakpoint(b
->address
, b
->shadow_contents
);
651 val
= target_remove_breakpoint(b
->address
, b
->shadow_contents
);
656 else if ((b
->type
== bp_hardware_watchpoint
||
657 b
->type
== bp_read_watchpoint
||
658 b
->type
== bp_access_watchpoint
)
659 && b
->enable
== enabled
665 /* Walk down the saved value chain. */
666 for (v
= b
->val_chain
; v
; v
= v
->next
)
668 /* For each memory reference remove the watchpoint
670 if (v
->lval
== lval_memory
)
674 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
675 len
= TYPE_LENGTH (VALUE_TYPE (v
));
676 val
= target_remove_watchpoint (addr
, len
, b
->type
);
682 /* Failure to remove any of the hardware watchpoints comes here. */
684 error ("Hardware watchpoint %d: Could not remove watchpoint\n",
687 /* Free the saved value chain. We will construct a new one
688 the next time the watchpoint is inserted. */
689 for (v
= b
->val_chain
; v
; v
= n
)
699 /* Clear the "inserted" flag in all breakpoints. */
702 mark_breakpoints_out ()
704 register struct breakpoint
*b
;
710 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
711 which should go away between runs of the program. */
714 breakpoint_init_inferior ()
716 register struct breakpoint
*b
, *temp
;
718 ALL_BREAKPOINTS_SAFE (b
, temp
)
722 /* If the call dummy breakpoint is at the entry point it will
723 cause problems when the inferior is rerun, so we better
725 if (b
->type
== bp_call_dummy
)
726 delete_breakpoint (b
);
728 /* Likewise for scope breakpoints. */
729 if (b
->type
== bp_watchpoint_scope
)
730 delete_breakpoint (b
);
732 /* Likewise for watchpoints on local expressions. */
733 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
||
734 b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
735 && b
->exp_valid_block
!= NULL
)
736 delete_breakpoint (b
);
740 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
741 When continuing from a location with a breakpoint,
742 we actually single step once before calling insert_breakpoints. */
745 breakpoint_here_p (pc
)
748 register struct breakpoint
*b
;
751 if (b
->enable
!= disabled
&& b
->address
== pc
)
757 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
758 because figuring out the saved SP would take too much time, at least using
759 get_saved_register on the 68k. This means that for this function to
760 work right a port must use the bp_call_dummy breakpoint. */
763 frame_in_dummy (frame
)
764 struct frame_info
*frame
;
766 struct breakpoint
*b
;
771 static unsigned LONGEST dummy
[] = CALL_DUMMY
;
773 if (b
->type
== bp_call_dummy
774 && b
->frame
== frame
->frame
776 /* We need to check the PC as well as the frame on the sparc,
777 for signals.exp in the testsuite. */
780 - sizeof (dummy
) / sizeof (LONGEST
) * REGISTER_SIZE
))
781 && frame
->pc
<= b
->address
)
784 #endif /* CALL_DUMMY */
788 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
789 is valid for process/thread PID. */
792 breakpoint_thread_match (pc
, pid
)
796 struct breakpoint
*b
;
799 thread
= pid_to_thread_id (pid
);
802 if (b
->enable
!= disabled
804 && (b
->thread
== -1 || b
->thread
== thread
))
811 /* bpstat stuff. External routines' interfaces are documented
814 /* Clear a bpstat so that it says we are not at any breakpoint.
815 Also free any storage that is part of a bpstat. */
830 if (p
->old_val
!= NULL
)
831 value_free (p
->old_val
);
838 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
839 is part of the bpstat is copied as well. */
847 bpstat retval
= NULL
;
852 for (; bs
!= NULL
; bs
= bs
->next
)
854 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
855 memcpy (tmp
, bs
, sizeof (*tmp
));
857 /* This is the first thing in the chain. */
867 /* Find the bpstat associated with this breakpoint */
870 bpstat_find_breakpoint(bsp
, breakpoint
)
872 struct breakpoint
*breakpoint
;
874 if (bsp
== NULL
) return NULL
;
876 for (;bsp
!= NULL
; bsp
= bsp
->next
) {
877 if (bsp
->breakpoint_at
== breakpoint
) return bsp
;
882 /* Return the breakpoint number of the first breakpoint we are stopped
883 at. *BSP upon return is a bpstat which points to the remaining
884 breakpoints stopped at (but which is not guaranteed to be good for
885 anything but further calls to bpstat_num).
886 Return 0 if passed a bpstat which does not indicate any breakpoints. */
892 struct breakpoint
*b
;
895 return 0; /* No more breakpoint values */
898 b
= (*bsp
)->breakpoint_at
;
901 return -1; /* breakpoint that's been deleted since */
903 return b
->number
; /* We have its number */
907 /* Modify BS so that the actions will not be performed. */
910 bpstat_clear_actions (bs
)
913 for (; bs
!= NULL
; bs
= bs
->next
)
916 if (bs
->old_val
!= NULL
)
918 value_free (bs
->old_val
);
924 /* Stub for cleaning up our state if we error-out of a breakpoint command */
927 cleanup_executing_breakpoints (ignore
)
930 executing_breakpoint_commands
= 0;
933 /* Execute all the commands associated with all the breakpoints at this
934 location. Any of these commands could cause the process to proceed
935 beyond this point, etc. We look out for such changes by checking
936 the global "breakpoint_proceeded" after each command. */
939 bpstat_do_actions (bsp
)
943 struct cleanup
*old_chain
;
944 struct command_line
*cmd
;
946 executing_breakpoint_commands
= 1;
947 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
952 breakpoint_proceeded
= 0;
953 for (; bs
!= NULL
; bs
= bs
->next
)
958 execute_control_command (cmd
);
961 if (breakpoint_proceeded
)
962 /* The inferior is proceeded by the command; bomb out now.
963 The bpstat chain has been blown away by wait_for_inferior.
964 But since execution has stopped again, there is a new bpstat
965 to look at, so start over. */
971 executing_breakpoint_commands
= 0;
972 discard_cleanups (old_chain
);
975 /* This is the normal print_it function for a bpstat. In the future,
976 much of this logic could (should?) be moved to bpstat_stop_status,
977 by having it set different print_it functions. */
983 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
984 which has since been deleted. */
985 if (bs
->breakpoint_at
== NULL
986 || (bs
->breakpoint_at
->type
!= bp_breakpoint
987 && bs
->breakpoint_at
->type
!= bp_hardware_breakpoint
988 && bs
->breakpoint_at
->type
!= bp_watchpoint
989 && bs
->breakpoint_at
->type
!= bp_read_watchpoint
990 && bs
->breakpoint_at
->type
!= bp_access_watchpoint
991 && bs
->breakpoint_at
->type
!= bp_hardware_watchpoint
))
994 if (bs
->breakpoint_at
->type
== bp_breakpoint
||
995 bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
997 /* I think the user probably only wants to see one breakpoint
998 number, not all of them. */
999 annotate_breakpoint (bs
->breakpoint_at
->number
);
1000 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
1003 else if ((bs
->old_val
!= NULL
) &&
1004 (bs
->breakpoint_at
->type
== bp_watchpoint
||
1005 bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1006 bs
->breakpoint_at
->type
== bp_hardware_watchpoint
))
1008 annotate_watchpoint (bs
->breakpoint_at
->number
);
1009 mention (bs
->breakpoint_at
);
1010 printf_filtered ("\nOld value = ");
1011 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
1012 printf_filtered ("\nNew value = ");
1013 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1014 Val_pretty_default
);
1015 printf_filtered ("\n");
1016 value_free (bs
->old_val
);
1018 /* More than one watchpoint may have been triggered. */
1021 else if (bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1022 bs
->breakpoint_at
->type
== bp_read_watchpoint
)
1024 mention (bs
->breakpoint_at
);
1025 printf_filtered ("\nValue = ");
1026 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1027 Val_pretty_default
);
1028 printf_filtered ("\n");
1031 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1035 /* Print a message indicating what happened. Returns nonzero to
1036 say that only the source line should be printed after this (zero
1037 return means print the frame as well as the source line). */
1038 /* Currently we always return zero. */
1048 val
= (*bs
->print_it
) (bs
);
1052 /* Maybe another breakpoint in the chain caused us to stop.
1053 (Currently all watchpoints go on the bpstat whether hit or
1054 not. That probably could (should) be changed, provided care is taken
1055 with respect to bpstat_explains_signal). */
1057 return bpstat_print (bs
->next
);
1059 /* We reached the end of the chain without printing anything. */
1063 /* Evaluate the expression EXP and return 1 if value is zero.
1064 This is used inside a catch_errors to evaluate the breakpoint condition.
1065 The argument is a "struct expression *" that has been cast to char * to
1066 make it pass through catch_errors. */
1069 breakpoint_cond_eval (exp
)
1072 value_ptr mark
= value_mark ();
1073 int i
= !value_true (evaluate_expression ((struct expression
*)exp
));
1074 value_free_to_mark (mark
);
1078 /* Allocate a new bpstat and chain it to the current one. */
1081 bpstat_alloc (b
, cbs
)
1082 register struct breakpoint
*b
;
1083 bpstat cbs
; /* Current "bs" value */
1087 bs
= (bpstat
) xmalloc (sizeof (*bs
));
1089 bs
->breakpoint_at
= b
;
1090 /* If the condition is false, etc., don't do the commands. */
1091 bs
->commands
= NULL
;
1093 bs
->print_it
= print_it_normal
;
1097 /* Possible return values for watchpoint_check (this can't be an enum
1098 because of check_errors). */
1099 /* The watchpoint has been deleted. */
1100 #define WP_DELETED 1
1101 /* The value has changed. */
1102 #define WP_VALUE_CHANGED 2
1103 /* The value has not changed. */
1104 #define WP_VALUE_NOT_CHANGED 3
1106 #define BP_TEMPFLAG 1
1107 #define BP_HARDWAREFLAG 2
1109 /* Check watchpoint condition. */
1112 watchpoint_check (p
)
1115 bpstat bs
= (bpstat
) p
;
1116 struct breakpoint
*b
;
1117 struct frame_info
*saved_frame
, *fr
;
1118 int within_current_scope
, saved_level
;
1120 b
= bs
->breakpoint_at
;
1122 if (b
->exp_valid_block
== NULL
)
1123 within_current_scope
= 1;
1126 /* There is no current frame at this moment. If we're going to have
1127 any chance of handling watchpoints on local variables, we'll need
1128 the frame chain (so we can determine if we're in scope). */
1129 reinit_frame_cache();
1130 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
1131 within_current_scope
= (fr
!= NULL
);
1132 if (within_current_scope
)
1133 /* If we end up stopping, the current frame will get selected
1134 in normal_stop. So this call to select_frame won't affect
1136 select_frame (fr
, -1);
1139 if (within_current_scope
)
1141 /* We use value_{,free_to_}mark because it could be a
1142 *long* time before we return to the command level and
1143 call free_all_values. We can't call free_all_values because
1144 we might be in the middle of evaluating a function call. */
1146 value_ptr mark
= value_mark ();
1147 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
1148 if (!value_equal (b
->val
, new_val
))
1150 release_value (new_val
);
1151 value_free_to_mark (mark
);
1152 bs
->old_val
= b
->val
;
1154 /* We will stop here */
1155 return WP_VALUE_CHANGED
;
1159 /* Nothing changed, don't do anything. */
1160 value_free_to_mark (mark
);
1161 /* We won't stop here */
1162 return WP_VALUE_NOT_CHANGED
;
1167 /* This seems like the only logical thing to do because
1168 if we temporarily ignored the watchpoint, then when
1169 we reenter the block in which it is valid it contains
1170 garbage (in the case of a function, it may have two
1171 garbage values, one before and one after the prologue).
1172 So we can't even detect the first assignment to it and
1173 watch after that (since the garbage may or may not equal
1174 the first value assigned). */
1176 Watchpoint %d deleted because the program has left the block in\n\
1177 which its expression is valid.\n", bs
->breakpoint_at
->number
);
1178 if (b
->related_breakpoint
)
1179 delete_breakpoint (b
->related_breakpoint
);
1180 delete_breakpoint (b
);
1186 /* This is used when everything which needs to be printed has
1187 already been printed. But we still want to print the frame. */
1195 /* This is used when nothing should be printed for this bpstat entry. */
1204 /* Get a bpstat associated with having just stopped at address *PC
1205 and frame address CORE_ADDRESS. Update *PC to point at the
1206 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1207 if this is known to not be a real breakpoint (it could still be a
1208 watchpoint, though). */
1210 /* Determine whether we stopped at a breakpoint, etc, or whether we
1211 don't understand this stop. Result is a chain of bpstat's such that:
1213 if we don't understand the stop, the result is a null pointer.
1215 if we understand why we stopped, the result is not null.
1217 Each element of the chain refers to a particular breakpoint or
1218 watchpoint at which we have stopped. (We may have stopped for
1219 several reasons concurrently.)
1221 Each element of the chain has valid next, breakpoint_at,
1222 commands, FIXME??? fields.
1227 bpstat_stop_status (pc
, not_a_breakpoint
)
1229 int not_a_breakpoint
;
1231 register struct breakpoint
*b
;
1233 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1234 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1235 int real_breakpoint
= 0;
1237 /* Root of the chain of bpstat's */
1238 struct bpstats root_bs
[1];
1239 /* Pointer to the last thing in the chain currently. */
1240 bpstat bs
= root_bs
;
1241 static char message1
[] =
1242 "Error evaluating expression for watchpoint %d\n";
1243 char message
[sizeof (message1
) + 30 /* slop */];
1245 /* Get the address where the breakpoint would have been. */
1246 bp_addr
= *pc
- DECR_PC_AFTER_BREAK
;
1250 if (b
->enable
== disabled
)
1253 if (b
->type
!= bp_watchpoint
1254 && b
->type
!= bp_hardware_watchpoint
1255 && b
->type
!= bp_read_watchpoint
1256 && b
->type
!= bp_access_watchpoint
1257 && b
->type
!= bp_hardware_breakpoint
1258 && b
->address
!= bp_addr
)
1261 /* If defined, then we need to decr pc by this much after a hardware break-
1262 point. Presumably should override DECR_PC_AFTER_BREAK, though it doesn't
1265 #ifndef DECR_PC_AFTER_HW_BREAK
1266 #define DECR_PC_AFTER_HW_BREAK 0
1269 if (b
->type
== bp_hardware_breakpoint
1270 && b
->address
!= (bp_addr
- DECR_PC_AFTER_HW_BREAK
))
1273 if (b
->type
!= bp_watchpoint
1274 && b
->type
!= bp_hardware_watchpoint
1275 && b
->type
!= bp_read_watchpoint
1276 && b
->type
!= bp_access_watchpoint
1277 && not_a_breakpoint
)
1280 /* Come here if it's a watchpoint, or if the break address matches */
1284 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
1289 sprintf (message
, message1
, b
->number
);
1290 if (b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1292 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1296 /* We've already printed what needs to be printed. */
1297 bs
->print_it
= print_it_done
;
1300 case WP_VALUE_CHANGED
:
1303 case WP_VALUE_NOT_CHANGED
:
1305 bs
->print_it
= print_it_noop
;
1312 /* Error from catch_errors. */
1313 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1314 if (b
->related_breakpoint
)
1315 delete_breakpoint (b
->related_breakpoint
);
1316 delete_breakpoint (b
);
1317 /* We've already printed what needs to be printed. */
1318 bs
->print_it
= print_it_done
;
1324 else if (b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
1330 addr
= target_stopped_data_address();
1331 if (addr
== 0) continue;
1332 for (v
= b
->val_chain
; v
; v
= v
->next
)
1334 if (v
->lval
== lval_memory
)
1338 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1344 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1348 /* We've already printed what needs to be printed. */
1349 bs
->print_it
= print_it_done
;
1352 case WP_VALUE_CHANGED
:
1353 case WP_VALUE_NOT_CHANGED
:
1359 /* Error from catch_errors. */
1360 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1361 if (b
->related_breakpoint
)
1362 delete_breakpoint (b
->related_breakpoint
);
1363 delete_breakpoint (b
);
1364 /* We've already printed what needs to be printed. */
1365 bs
->print_it
= print_it_done
;
1369 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1371 real_breakpoint
= 1;
1374 if (b
->frame
&& b
->frame
!= (get_current_frame ())->frame
)
1378 int value_is_zero
= 0;
1382 /* Need to select the frame, with all that implies
1383 so that the conditions will have the right context. */
1384 select_frame (get_current_frame (), 0);
1386 = catch_errors (breakpoint_cond_eval
, (char *)(b
->cond
),
1387 "Error in testing breakpoint condition:\n",
1389 /* FIXME-someday, should give breakpoint # */
1392 if (b
->cond
&& value_is_zero
)
1396 else if (b
->ignore_count
> 0)
1403 /* We will stop here */
1404 if (b
->disposition
== disable
)
1405 b
->enable
= disabled
;
1406 bs
->commands
= b
->commands
;
1409 if (bs
->commands
&& STREQ ("silent", bs
->commands
->line
))
1411 bs
->commands
= bs
->commands
->next
;
1416 /* Print nothing for this entry if we dont stop or if we dont print. */
1417 if (bs
->stop
== 0 || bs
->print
== 0)
1418 bs
->print_it
= print_it_noop
;
1421 bs
->next
= NULL
; /* Terminate the chain */
1422 bs
= root_bs
->next
; /* Re-grab the head of the chain */
1423 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1426 if (real_breakpoint
)
1429 #if defined (SHIFT_INST_REGS)
1431 #else /* No SHIFT_INST_REGS. */
1433 #endif /* No SHIFT_INST_REGS. */
1436 #endif /* DECR_PC_AFTER_BREAK != 0. */
1438 /* The value of a hardware watchpoint hasn't changed, but the
1439 intermediate memory locations we are watching may have. */
1440 if (bs
&& ! bs
->stop
&&
1441 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
1442 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
1443 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
1445 remove_breakpoints ();
1446 insert_breakpoints ();
1451 /* Tell what to do about this bpstat. */
1456 /* Classify each bpstat as one of the following. */
1458 /* This bpstat element has no effect on the main_action. */
1461 /* There was a watchpoint, stop but don't print. */
1464 /* There was a watchpoint, stop and print. */
1467 /* There was a breakpoint but we're not stopping. */
1470 /* There was a breakpoint, stop but don't print. */
1473 /* There was a breakpoint, stop and print. */
1476 /* We hit the longjmp breakpoint. */
1479 /* We hit the longjmp_resume breakpoint. */
1482 /* We hit the step_resume breakpoint. */
1485 /* We hit the through_sigtramp breakpoint. */
1488 /* This is just used to count how many enums there are. */
1492 /* Here is the table which drives this routine. So that we can
1493 format it pretty, we define some abbreviations for the
1494 enum bpstat_what codes. */
1495 #define keep_c BPSTAT_WHAT_KEEP_CHECKING
1496 #define stop_s BPSTAT_WHAT_STOP_SILENT
1497 #define stop_n BPSTAT_WHAT_STOP_NOISY
1498 #define single BPSTAT_WHAT_SINGLE
1499 #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1500 #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1501 #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1502 #define sr BPSTAT_WHAT_STEP_RESUME
1503 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1505 /* "Can't happen." Might want to print an error message.
1506 abort() is not out of the question, but chances are GDB is just
1507 a bit confused, not unusable. */
1508 #define err BPSTAT_WHAT_STOP_NOISY
1510 /* Given an old action and a class, come up with a new action. */
1511 /* One interesting property of this table is that wp_silent is the same
1512 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1513 after stopping, the check for whether to step over a breakpoint
1514 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1515 reference to how we stopped. We retain separate wp_silent and bp_silent
1516 codes in case we want to change that someday. */
1518 /* step_resume entries: a step resume breakpoint overrides another
1519 breakpoint of signal handling (see comment in wait_for_inferior
1520 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1521 /* We handle the through_sigtramp_breakpoint the same way; having both
1522 one of those and a step_resume_breakpoint is probably very rare (?). */
1524 static const enum bpstat_what_main_action
1525 table
[(int)class_last
][(int)BPSTAT_WHAT_LAST
] =
1528 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts
1530 /*no_effect*/ {keep_c
,stop_s
,stop_n
,single
, setlr
, clrlr
, clrlrs
, sr
, ts
},
1531 /*wp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1532 /*wp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1533 /*bp_nostop*/ {single
,stop_s
,stop_n
,single
, setlr
, clrlrs
, clrlrs
, sr
, ts
},
1534 /*bp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1535 /*bp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1536 /*long_jump*/ {setlr
,stop_s
,stop_n
,setlr
, err
, err
, err
, sr
, ts
},
1537 /*long_resume*/ {clrlr
,stop_s
,stop_n
,clrlrs
, err
, err
, err
, sr
, ts
},
1538 /*step_resume*/ {sr
,sr
,sr
,sr
, sr
, sr
, sr
, sr
, ts
},
1539 /*through_sig*/ {ts
,ts
,ts
,ts
, ts
, ts
, ts
, ts
, ts
}
1551 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
1552 struct bpstat_what retval
;
1554 retval
.call_dummy
= 0;
1555 for (; bs
!= NULL
; bs
= bs
->next
)
1557 enum class bs_class
= no_effect
;
1558 if (bs
->breakpoint_at
== NULL
)
1559 /* I suspect this can happen if it was a momentary breakpoint
1560 which has since been deleted. */
1562 switch (bs
->breakpoint_at
->type
)
1565 case bp_hardware_breakpoint
:
1571 bs_class
= bp_noisy
;
1573 bs_class
= bp_silent
;
1576 bs_class
= bp_nostop
;
1579 case bp_hardware_watchpoint
:
1580 case bp_read_watchpoint
:
1581 case bp_access_watchpoint
:
1585 bs_class
= wp_noisy
;
1587 bs_class
= wp_silent
;
1590 /* There was a watchpoint, but we're not stopping. This requires
1591 no further action. */
1592 bs_class
= no_effect
;
1595 bs_class
= long_jump
;
1597 case bp_longjmp_resume
:
1598 bs_class
= long_resume
;
1600 case bp_step_resume
:
1603 bs_class
= step_resume
;
1606 /* It is for the wrong frame. */
1607 bs_class
= bp_nostop
;
1609 case bp_through_sigtramp
:
1610 bs_class
= through_sig
;
1612 case bp_watchpoint_scope
:
1613 bs_class
= bp_nostop
;
1617 /* Make sure the action is stop (silent or noisy), so infrun.c
1618 pops the dummy frame. */
1619 bs_class
= bp_silent
;
1620 retval
.call_dummy
= 1;
1623 current_action
= table
[(int)bs_class
][(int)current_action
];
1625 retval
.main_action
= current_action
;
1629 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1630 without hardware support). This isn't related to a specific bpstat,
1631 just to things like whether watchpoints are set. */
1634 bpstat_should_step ()
1636 struct breakpoint
*b
;
1638 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
1643 /* Print information on breakpoint number BNUM, or -1 if all.
1644 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1645 is nonzero, process only watchpoints. */
1648 breakpoint_1 (bnum
, allflag
)
1652 register struct breakpoint
*b
;
1653 register struct command_line
*l
;
1654 register struct symbol
*sym
;
1655 CORE_ADDR last_addr
= (CORE_ADDR
)-1;
1656 int found_a_breakpoint
= 0;
1657 static char *bptypes
[] = {"breakpoint", "hw breakpoint",
1658 "until", "finish", "watchpoint",
1659 "hw watchpoint", "read watchpoint",
1660 "acc watchpoint", "longjmp",
1661 "longjmp resume", "step resume",
1662 "watchpoint scope", "call dummy" };
1663 static char *bpdisps
[] = {"del", "dis", "keep"};
1664 static char bpenables
[] = "ny";
1665 char wrap_indent
[80];
1669 || bnum
== b
->number
)
1671 /* We only print out user settable breakpoints unless the allflag is set. */
1673 && b
->type
!= bp_breakpoint
1674 && b
->type
!= bp_hardware_breakpoint
1675 && b
->type
!= bp_watchpoint
1676 && b
->type
!= bp_read_watchpoint
1677 && b
->type
!= bp_access_watchpoint
1678 && b
->type
!= bp_hardware_watchpoint
)
1681 if (!found_a_breakpoint
++)
1683 annotate_breakpoints_headers ();
1686 printf_filtered ("Num ");
1688 printf_filtered ("Type ");
1690 printf_filtered ("Disp ");
1692 printf_filtered ("Enb ");
1696 printf_filtered ("Address ");
1699 printf_filtered ("What\n");
1701 annotate_breakpoints_table ();
1706 printf_filtered ("%-3d ", b
->number
);
1708 printf_filtered ("%-14s ", bptypes
[(int)b
->type
]);
1710 printf_filtered ("%-4s ", bpdisps
[(int)b
->disposition
]);
1712 printf_filtered ("%-3c ", bpenables
[(int)b
->enable
]);
1714 strcpy (wrap_indent
, " ");
1716 strcat (wrap_indent
, " ");
1720 case bp_hardware_watchpoint
:
1721 case bp_read_watchpoint
:
1722 case bp_access_watchpoint
:
1723 /* Field 4, the address, is omitted (which makes the columns
1724 not line up too nicely with the headers, but the effect
1725 is relatively readable). */
1727 print_expression (b
->exp
, gdb_stdout
);
1731 case bp_hardware_breakpoint
:
1735 case bp_longjmp_resume
:
1736 case bp_step_resume
:
1737 case bp_through_sigtramp
:
1738 case bp_watchpoint_scope
:
1743 /* FIXME-32x64: need a print_address_numeric with
1747 local_hex_string_custom
1748 ((unsigned long) b
->address
, "08l"));
1753 last_addr
= b
->address
;
1756 sym
= find_pc_function (b
->address
);
1759 fputs_filtered ("in ", gdb_stdout
);
1760 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
1761 wrap_here (wrap_indent
);
1762 fputs_filtered (" at ", gdb_stdout
);
1764 fputs_filtered (b
->source_file
, gdb_stdout
);
1765 printf_filtered (":%d", b
->line_number
);
1768 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
1772 printf_filtered ("\n");
1778 printf_filtered ("\tstop only in stack frame at ");
1779 print_address_numeric (b
->frame
, 1, gdb_stdout
);
1780 printf_filtered ("\n");
1787 printf_filtered ("\tstop only if ");
1788 print_expression (b
->cond
, gdb_stdout
);
1789 printf_filtered ("\n");
1792 if (show_breakpoint_hit_counts
&& b
->hit_count
)
1794 /* FIXME should make an annotation for this */
1796 printf_filtered ("\tbreakpoint already hit %d time%s\n",
1797 b
->hit_count
, (b
->hit_count
== 1 ? "" : "s"));
1800 if (b
->ignore_count
)
1804 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
1807 if ((l
= b
->commands
))
1813 print_command_line (l
, 4);
1819 if (!found_a_breakpoint
)
1822 printf_filtered ("No breakpoints or watchpoints.\n");
1824 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
1827 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1828 that a comparison of an unsigned with -1 is always false. */
1829 if (last_addr
!= (CORE_ADDR
)-1)
1830 set_next_address (last_addr
);
1832 annotate_breakpoints_table_end ();
1837 breakpoints_info (bnum_exp
, from_tty
)
1844 bnum
= parse_and_eval_address (bnum_exp
);
1846 breakpoint_1 (bnum
, 0);
1849 #if MAINTENANCE_CMDS
1853 maintenance_info_breakpoints (bnum_exp
, from_tty
)
1860 bnum
= parse_and_eval_address (bnum_exp
);
1862 breakpoint_1 (bnum
, 1);
1867 /* Print a message describing any breakpoints set at PC. */
1870 describe_other_breakpoints (pc
)
1871 register CORE_ADDR pc
;
1873 register int others
= 0;
1874 register struct breakpoint
*b
;
1877 if (b
->address
== pc
)
1881 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
1883 if (b
->address
== pc
)
1889 (b
->enable
== disabled
) ? " (disabled)" : "",
1890 (others
> 1) ? "," : ((others
== 1) ? " and" : ""));
1892 printf_filtered ("also set at pc ");
1893 print_address_numeric (pc
, 1, gdb_stdout
);
1894 printf_filtered (".\n");
1898 /* Set the default place to put a breakpoint
1899 for the `break' command with no arguments. */
1902 set_default_breakpoint (valid
, addr
, symtab
, line
)
1905 struct symtab
*symtab
;
1908 default_breakpoint_valid
= valid
;
1909 default_breakpoint_address
= addr
;
1910 default_breakpoint_symtab
= symtab
;
1911 default_breakpoint_line
= line
;
1914 /* Rescan breakpoints at address ADDRESS,
1915 marking the first one as "first" and any others as "duplicates".
1916 This is so that the bpt instruction is only inserted once. */
1919 check_duplicates (address
)
1922 register struct breakpoint
*b
;
1923 register int count
= 0;
1925 if (address
== 0) /* Watchpoints are uninteresting */
1929 if (b
->enable
!= disabled
&& b
->address
== address
)
1932 b
->duplicate
= count
> 1;
1936 /* Low level routine to set a breakpoint.
1937 Takes as args the three things that every breakpoint must have.
1938 Returns the breakpoint object so caller can set other things.
1939 Does not set the breakpoint number!
1940 Does not print anything.
1942 ==> This routine should not be called if there is a chance of later
1943 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1944 your arguments BEFORE calling this routine! */
1946 static struct breakpoint
*
1947 set_raw_breakpoint (sal
)
1948 struct symtab_and_line sal
;
1950 register struct breakpoint
*b
, *b1
;
1952 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
1953 memset (b
, 0, sizeof (*b
));
1954 b
->address
= sal
.pc
;
1955 if (sal
.symtab
== NULL
)
1956 b
->source_file
= NULL
;
1958 b
->source_file
= savestring (sal
.symtab
->filename
,
1959 strlen (sal
.symtab
->filename
));
1960 b
->language
= current_language
->la_language
;
1961 b
->input_radix
= input_radix
;
1963 b
->line_number
= sal
.line
;
1964 b
->enable
= enabled
;
1967 b
->ignore_count
= 0;
1971 /* Add this breakpoint to the end of the chain
1972 so that a list of breakpoints will come out in order
1973 of increasing numbers. */
1975 b1
= breakpoint_chain
;
1977 breakpoint_chain
= b
;
1985 check_duplicates (sal
.pc
);
1986 breakpoints_changed ();
1992 create_longjmp_breakpoint(func_name
)
1995 struct symtab_and_line sal
;
1996 struct breakpoint
*b
;
1997 static int internal_breakpoint_number
= -1;
1999 if (func_name
!= NULL
)
2001 struct minimal_symbol
*m
;
2003 m
= lookup_minimal_symbol_text (func_name
, NULL
, (struct objfile
*)NULL
);
2005 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
2015 b
= set_raw_breakpoint(sal
);
2018 b
->type
= func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
;
2019 b
->disposition
= donttouch
;
2020 b
->enable
= disabled
;
2023 b
->addr_string
= strsave(func_name
);
2024 b
->number
= internal_breakpoint_number
--;
2027 /* Call this routine when stepping and nexting to enable a breakpoint if we do
2028 a longjmp(). When we hit that breakpoint, call
2029 set_longjmp_resume_breakpoint() to figure out where we are going. */
2032 enable_longjmp_breakpoint()
2034 register struct breakpoint
*b
;
2037 if (b
->type
== bp_longjmp
)
2039 b
->enable
= enabled
;
2040 check_duplicates (b
->address
);
2045 disable_longjmp_breakpoint()
2047 register struct breakpoint
*b
;
2050 if ( b
->type
== bp_longjmp
2051 || b
->type
== bp_longjmp_resume
)
2053 b
->enable
= disabled
;
2054 check_duplicates (b
->address
);
2059 hw_breakpoint_used_count()
2061 register struct breakpoint
*b
;
2066 if (b
->type
== bp_hardware_breakpoint
&& b
->enable
== enabled
)
2074 hw_watchpoint_used_count(type
, other_type_used
)
2076 int *other_type_used
;
2078 register struct breakpoint
*b
;
2081 *other_type_used
= 0;
2084 if (b
->enable
== enabled
)
2086 if (b
->type
== type
) i
++;
2087 else if ((b
->type
== bp_hardware_watchpoint
||
2088 b
->type
== bp_read_watchpoint
||
2089 b
->type
== bp_access_watchpoint
)
2090 && b
->enable
== enabled
)
2091 *other_type_used
= 1;
2097 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
2098 breakpoint at the target of the jmp_buf.
2100 FIXME - This ought to be done by setting a temporary breakpoint that gets
2101 deleted automatically...
2105 set_longjmp_resume_breakpoint(pc
, frame
)
2107 struct frame_info
*frame
;
2109 register struct breakpoint
*b
;
2112 if (b
->type
== bp_longjmp_resume
)
2115 b
->enable
= enabled
;
2117 b
->frame
= frame
->frame
;
2120 check_duplicates (b
->address
);
2125 /* Set a breakpoint that will evaporate an end of command
2126 at address specified by SAL.
2127 Restrict it to frame FRAME if FRAME is nonzero. */
2130 set_momentary_breakpoint (sal
, frame
, type
)
2131 struct symtab_and_line sal
;
2132 struct frame_info
*frame
;
2135 register struct breakpoint
*b
;
2136 b
= set_raw_breakpoint (sal
);
2138 b
->enable
= enabled
;
2139 b
->disposition
= donttouch
;
2140 b
->frame
= (frame
? frame
->frame
: 0);
2146 clear_momentary_breakpoints ()
2148 register struct breakpoint
*b
;
2150 if (b
->disposition
== delete)
2152 delete_breakpoint (b
);
2158 /* Tell the user we have just set a breakpoint B. */
2162 struct breakpoint
*b
;
2166 /* FIXME: This is misplaced; mention() is called by things (like hitting a
2167 watchpoint) other than breakpoint creation. It should be possible to
2168 clean this up and at the same time replace the random calls to
2169 breakpoint_changed with this hook, as has already been done for
2170 delete_breakpoint_hook and so on. */
2171 if (create_breakpoint_hook
)
2172 create_breakpoint_hook (b
);
2177 printf_filtered ("Watchpoint %d: ", b
->number
);
2178 print_expression (b
->exp
, gdb_stdout
);
2180 case bp_hardware_watchpoint
:
2181 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
2182 print_expression (b
->exp
, gdb_stdout
);
2184 case bp_read_watchpoint
:
2185 printf_filtered ("Hardware read watchpoint %d: ", b
->number
);
2186 print_expression (b
->exp
, gdb_stdout
);
2188 case bp_access_watchpoint
:
2189 printf_filtered ("Hardware access(read/write) watchpoint %d: ",b
->number
);
2190 print_expression (b
->exp
, gdb_stdout
);
2193 printf_filtered ("Breakpoint %d", b
->number
);
2196 case bp_hardware_breakpoint
:
2197 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
2203 case bp_longjmp_resume
:
2204 case bp_step_resume
:
2205 case bp_through_sigtramp
:
2207 case bp_watchpoint_scope
:
2212 if (addressprint
|| b
->source_file
== NULL
)
2214 printf_filtered (" at ");
2215 print_address_numeric (b
->address
, 1, gdb_stdout
);
2218 printf_filtered (": file %s, line %d.",
2219 b
->source_file
, b
->line_number
);
2221 printf_filtered ("\n");
2225 /* Nobody calls this currently. */
2226 /* Set a breakpoint from a symtab and line.
2227 If TEMPFLAG is nonzero, it is a temporary breakpoint.
2228 ADDR_STRING is a malloc'd string holding the name of where we are
2229 setting the breakpoint. This is used later to re-set it after the
2230 program is relinked and symbols are reloaded.
2231 Print the same confirmation messages that the breakpoint command prints. */
2234 set_breakpoint (s
, line
, tempflag
, addr_string
)
2240 register struct breakpoint
*b
;
2241 struct symtab_and_line sal
;
2246 resolve_sal_pc (&sal
); /* Might error out */
2247 describe_other_breakpoints (sal
.pc
);
2249 b
= set_raw_breakpoint (sal
);
2250 set_breakpoint_count (breakpoint_count
+ 1);
2251 b
->number
= breakpoint_count
;
2252 b
->type
= bp_breakpoint
;
2254 b
->addr_string
= addr_string
;
2255 b
->enable
= enabled
;
2256 b
->disposition
= tempflag
? delete : donttouch
;
2262 /* Set a breakpoint according to ARG (function, linenum or *address)
2263 flag: first bit : 0 non-temporary, 1 temporary.
2264 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
2267 break_command_1 (arg
, flag
, from_tty
)
2271 int tempflag
, hardwareflag
;
2272 struct symtabs_and_lines sals
;
2273 struct symtab_and_line sal
;
2274 register struct expression
*cond
= 0;
2275 register struct breakpoint
*b
;
2277 /* Pointers in arg to the start, and one past the end, of the condition. */
2278 char *cond_start
= NULL
;
2279 char *cond_end
= NULL
;
2280 /* Pointers in arg to the start, and one past the end,
2281 of the address part. */
2282 char *addr_start
= NULL
;
2283 char *addr_end
= NULL
;
2284 struct cleanup
*old_chain
;
2285 struct cleanup
*canonical_strings_chain
= NULL
;
2286 char **canonical
= (char **)NULL
;
2290 hardwareflag
= flag
& BP_HARDWAREFLAG
;
2291 tempflag
= flag
& BP_TEMPFLAG
;
2296 sal
.line
= sal
.pc
= sal
.end
= 0;
2299 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2301 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2302 && (arg
[2] == ' ' || arg
[2] == '\t')))
2304 if (default_breakpoint_valid
)
2306 sals
.sals
= (struct symtab_and_line
*)
2307 xmalloc (sizeof (struct symtab_and_line
));
2308 sal
.pc
= default_breakpoint_address
;
2309 sal
.line
= default_breakpoint_line
;
2310 sal
.symtab
= default_breakpoint_symtab
;
2315 error ("No default breakpoint address now.");
2321 /* Force almost all breakpoints to be in terms of the
2322 current_source_symtab (which is decode_line_1's default). This
2323 should produce the results we want almost all of the time while
2324 leaving default_breakpoint_* alone. */
2325 if (default_breakpoint_valid
2326 && (!current_source_symtab
2327 || (arg
&& (*arg
== '+' || *arg
== '-'))))
2328 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2329 default_breakpoint_line
, &canonical
);
2331 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
2339 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2340 the following `for' loop errors out. */
2341 old_chain
= make_cleanup (free
, sals
.sals
);
2342 if (canonical
!= (char **)NULL
)
2344 make_cleanup (free
, canonical
);
2345 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
2346 for (i
= 0; i
< sals
.nelts
; i
++)
2348 if (canonical
[i
] != NULL
)
2349 make_cleanup (free
, canonical
[i
]);
2353 thread
= -1; /* No specific thread yet */
2355 /* Resolve all line numbers to PC's, and verify that conditions
2356 can be parsed, before setting any breakpoints. */
2357 for (i
= 0; i
< sals
.nelts
; i
++)
2359 char *tok
, *end_tok
;
2362 resolve_sal_pc (&sals
.sals
[i
]);
2368 while (*tok
== ' ' || *tok
== '\t')
2373 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2376 toklen
= end_tok
- tok
;
2378 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2380 tok
= cond_start
= end_tok
+ 1;
2381 cond
= parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
2384 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
2390 thread
= strtol (tok
, &tok
, 0);
2392 error ("Junk after thread keyword.");
2393 if (!valid_thread_id (thread
))
2394 error ("Unknown thread %d\n", thread
);
2397 error ("Junk at end of arguments.");
2402 int i
, target_resources_ok
;
2404 i
= hw_breakpoint_used_count ();
2405 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
2406 bp_hardware_breakpoint
, i
+ sals
.nelts
, 0);
2407 if (target_resources_ok
== 0)
2408 error ("No hardware breakpoint support in the target.");
2409 else if (target_resources_ok
< 0)
2410 error ("Hardware breakpoints used exceeds limit.");
2413 /* Remove the canonical strings from the cleanup, they are needed below. */
2414 if (canonical
!= (char **)NULL
)
2415 discard_cleanups (canonical_strings_chain
);
2417 /* Now set all the breakpoints. */
2418 for (i
= 0; i
< sals
.nelts
; i
++)
2423 describe_other_breakpoints (sal
.pc
);
2425 b
= set_raw_breakpoint (sal
);
2426 set_breakpoint_count (breakpoint_count
+ 1);
2427 b
->number
= breakpoint_count
;
2428 b
->type
= hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
;
2432 /* If a canonical line spec is needed use that instead of the
2434 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
2435 b
->addr_string
= canonical
[i
];
2436 else if (addr_start
)
2437 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
2439 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2441 b
->enable
= enabled
;
2442 b
->disposition
= tempflag
? del
: donttouch
;
2449 printf_filtered ("Multiple breakpoints were set.\n");
2450 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2452 do_cleanups (old_chain
);
2455 /* Helper function for break_command_1 and disassemble_command. */
2458 resolve_sal_pc (sal
)
2459 struct symtab_and_line
*sal
;
2463 if (sal
->pc
== 0 && sal
->symtab
!= 0)
2465 pc
= find_line_pc (sal
->symtab
, sal
->line
);
2467 error ("No line %d in file \"%s\".",
2468 sal
->line
, sal
->symtab
->filename
);
2474 break_command (arg
, from_tty
)
2478 break_command_1 (arg
, 0, from_tty
);
2482 tbreak_command (arg
, from_tty
)
2486 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
2490 hbreak_command (arg
, from_tty
)
2494 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
2498 thbreak_command (arg
, from_tty
)
2502 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
2506 /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write)
2509 watch_command_1 (arg
, accessflag
, from_tty
)
2514 struct breakpoint
*b
;
2515 struct symtab_and_line sal
;
2516 struct expression
*exp
;
2517 struct block
*exp_valid_block
;
2518 struct value
*val
, *mark
;
2519 struct frame_info
*frame
, *prev_frame
;
2520 char *exp_start
= NULL
;
2521 char *exp_end
= NULL
;
2522 char *tok
, *end_tok
;
2524 char *cond_start
= NULL
;
2525 char *cond_end
= NULL
;
2526 struct expression
*cond
= NULL
;
2527 int i
, other_type_used
, target_resources_ok
;
2528 enum bptype bp_type
;
2535 /* Parse arguments. */
2536 innermost_block
= NULL
;
2538 exp
= parse_exp_1 (&arg
, 0, 0);
2540 exp_valid_block
= innermost_block
;
2541 mark
= value_mark ();
2542 val
= evaluate_expression (exp
);
2543 release_value (val
);
2544 if (VALUE_LAZY (val
))
2545 value_fetch_lazy (val
);
2548 while (*tok
== ' ' || *tok
== '\t')
2552 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2555 toklen
= end_tok
- tok
;
2556 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2558 tok
= cond_start
= end_tok
+ 1;
2559 cond
= parse_exp_1 (&tok
, 0, 0);
2563 error("Junk at end of command.");
2565 if (accessflag
== 1) bp_type
= bp_read_watchpoint
;
2566 else if (accessflag
== 2) bp_type
= bp_access_watchpoint
;
2567 else bp_type
= bp_hardware_watchpoint
;
2569 mem_cnt
= can_use_hardware_watchpoint (val
);
2570 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
2571 error ("Expression cannot be implemented with read/access watchpoint.");
2573 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
2574 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2575 bp_type
, i
+ mem_cnt
, other_type_used
);
2576 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
2577 error ("Target does not have this type of hardware watchpoint support.");
2578 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
2579 error ("Target resources have been allocated for other types of watchpoints.");
2582 /* Now set up the breakpoint. */
2583 b
= set_raw_breakpoint (sal
);
2584 set_breakpoint_count (breakpoint_count
+ 1);
2585 b
->number
= breakpoint_count
;
2586 b
->disposition
= donttouch
;
2588 b
->exp_valid_block
= exp_valid_block
;
2589 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
2593 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2597 frame
= block_innermost_frame (exp_valid_block
);
2600 prev_frame
= get_prev_frame (frame
);
2601 b
->watchpoint_frame
= frame
->frame
;
2604 b
->watchpoint_frame
= (CORE_ADDR
)0;
2606 if (mem_cnt
&& target_resources_ok
> 0)
2609 b
->type
= bp_watchpoint
;
2611 /* If the expression is "local", then set up a "watchpoint scope"
2612 breakpoint at the point where we've left the scope of the watchpoint
2614 if (innermost_block
)
2616 struct breakpoint
*scope_breakpoint
;
2617 struct symtab_and_line scope_sal
;
2621 scope_sal
.pc
= get_frame_pc (prev_frame
);
2622 scope_sal
.symtab
= NULL
;
2625 scope_breakpoint
= set_raw_breakpoint (scope_sal
);
2626 set_breakpoint_count (breakpoint_count
+ 1);
2627 scope_breakpoint
->number
= breakpoint_count
;
2629 scope_breakpoint
->type
= bp_watchpoint_scope
;
2630 scope_breakpoint
->enable
= enabled
;
2632 /* Automatically delete the breakpoint when it hits. */
2633 scope_breakpoint
->disposition
= del
;
2635 /* Only break in the proper frame (help with recursion). */
2636 scope_breakpoint
->frame
= prev_frame
->frame
;
2638 /* Set the address at which we will stop. */
2639 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
2641 /* The scope breakpoint is related to the watchpoint. We
2642 will need to act on them together. */
2643 b
->related_breakpoint
= scope_breakpoint
;
2646 value_free_to_mark (mark
);
2650 /* Return count of locations need to be watched and can be handled
2651 in hardware. If the watchpoint can not be handled
2652 in hardware return zero. */
2655 can_use_hardware_watchpoint (v
)
2658 int found_memory_cnt
= 0;
2660 /* Make sure all the intermediate values are in memory. Also make sure
2661 we found at least one memory expression. Guards against watch 0x12345,
2662 which is meaningless, but could cause errors if one tries to insert a
2663 hardware watchpoint for the constant expression. */
2664 for ( ; v
; v
= v
->next
)
2666 if (v
->lval
== lval_memory
)
2668 if (TYPE_LENGTH (VALUE_TYPE (v
)) <= REGISTER_SIZE
)
2671 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
2675 /* The expression itself looks suitable for using a hardware
2676 watchpoint, but give the target machine a chance to reject it. */
2677 return found_memory_cnt
;
2680 static void watch_command (arg
, from_tty
)
2684 watch_command_1 (arg
, 0, from_tty
);
2687 static void rwatch_command (arg
, from_tty
)
2691 watch_command_1 (arg
, 1, from_tty
);
2694 static void awatch_command (arg
, from_tty
)
2698 watch_command_1 (arg
, 2, from_tty
);
2702 /* Helper routine for the until_command routine in infcmd.c. Here
2703 because it uses the mechanisms of breakpoints. */
2707 until_break_command (arg
, from_tty
)
2711 struct symtabs_and_lines sals
;
2712 struct symtab_and_line sal
;
2713 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
2714 struct breakpoint
*breakpoint
;
2715 struct cleanup
*old_chain
;
2717 clear_proceed_status ();
2719 /* Set a breakpoint where the user wants it and at return from
2722 if (default_breakpoint_valid
)
2723 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2724 default_breakpoint_line
, (char ***)NULL
);
2726 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2728 if (sals
.nelts
!= 1)
2729 error ("Couldn't get information on specified line.");
2732 free ((PTR
)sals
.sals
); /* malloc'd, so freed */
2735 error ("Junk at end of arguments.");
2737 resolve_sal_pc (&sal
);
2739 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
2741 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
2743 /* Keep within the current frame */
2747 sal
= find_pc_line (prev_frame
->pc
, 0);
2748 sal
.pc
= prev_frame
->pc
;
2749 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
2750 make_cleanup(delete_breakpoint
, breakpoint
);
2753 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
2754 do_cleanups(old_chain
);
2758 /* These aren't used; I don't konw what they were for. */
2759 /* Set a breakpoint at the catch clause for NAME. */
2761 catch_breakpoint (name
)
2767 disable_catch_breakpoint ()
2772 delete_catch_breakpoint ()
2777 enable_catch_breakpoint ()
2784 struct sal_chain
*next
;
2785 struct symtab_and_line sal
;
2789 /* This isn't used; I don't know what it was for. */
2790 /* For each catch clause identified in ARGS, run FUNCTION
2791 with that clause as an argument. */
2792 static struct symtabs_and_lines
2793 map_catch_names (args
, function
)
2797 register char *p
= args
;
2799 struct symtabs_and_lines sals
;
2801 struct sal_chain
*sal_chain
= 0;
2805 error_no_arg ("one or more catch names");
2813 /* Don't swallow conditional part. */
2814 if (p1
[0] == 'i' && p1
[1] == 'f'
2815 && (p1
[2] == ' ' || p1
[2] == '\t'))
2821 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
2825 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
2826 error ("Arguments must be catch names.");
2832 struct sal_chain
*next
2833 = (struct sal_chain
*)alloca (sizeof (struct sal_chain
));
2834 next
->next
= sal_chain
;
2835 next
->sal
= get_catch_sal (p
);
2840 printf_unfiltered ("No catch clause for exception %s.\n", p
);
2845 while (*p
== ' ' || *p
== '\t') p
++;
2850 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2852 static struct symtabs_and_lines
2853 get_catch_sals (this_level_only
)
2854 int this_level_only
;
2856 register struct blockvector
*bl
;
2857 register struct block
*block
;
2858 int index
, have_default
= 0;
2860 struct symtabs_and_lines sals
;
2861 struct sal_chain
*sal_chain
= 0;
2862 char *blocks_searched
;
2864 /* Not sure whether an error message is always the correct response,
2865 but it's better than a core dump. */
2866 if (selected_frame
== NULL
)
2867 error ("No selected frame.");
2868 block
= get_frame_block (selected_frame
);
2869 pc
= selected_frame
->pc
;
2875 error ("No symbol table info available.\n");
2877 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
2878 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2879 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2883 CORE_ADDR end
= BLOCK_END (block
) - 4;
2886 if (bl
!= blockvector_for_pc (end
, &index
))
2887 error ("blockvector blotch");
2888 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
2889 error ("blockvector botch");
2890 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
2893 /* Don't print out blocks that have gone by. */
2894 while (index
< last_index
2895 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
2898 while (index
< last_index
2899 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
2901 if (blocks_searched
[index
] == 0)
2903 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
2906 register struct symbol
*sym
;
2908 nsyms
= BLOCK_NSYMS (b
);
2910 for (i
= 0; i
< nsyms
; i
++)
2912 sym
= BLOCK_SYM (b
, i
);
2913 if (STREQ (SYMBOL_NAME (sym
), "default"))
2919 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
2921 struct sal_chain
*next
= (struct sal_chain
*)
2922 alloca (sizeof (struct sal_chain
));
2923 next
->next
= sal_chain
;
2924 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
2928 blocks_searched
[index
] = 1;
2934 if (sal_chain
&& this_level_only
)
2937 /* After handling the function's top-level block, stop.
2938 Don't continue to its superblock, the block of
2939 per-file symbols. */
2940 if (BLOCK_FUNCTION (block
))
2942 block
= BLOCK_SUPERBLOCK (block
);
2947 struct sal_chain
*tmp_chain
;
2949 /* Count the number of entries. */
2950 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
2951 tmp_chain
= tmp_chain
->next
)
2955 sals
.sals
= (struct symtab_and_line
*)
2956 xmalloc (index
* sizeof (struct symtab_and_line
));
2957 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
2958 sals
.sals
[index
] = sal_chain
->sal
;
2964 /* Commands to deal with catching exceptions. */
2967 catch_command_1 (arg
, tempflag
, from_tty
)
2972 /* First, translate ARG into something we can deal with in terms
2975 struct symtabs_and_lines sals
;
2976 struct symtab_and_line sal
;
2977 register struct expression
*cond
= 0;
2978 register struct breakpoint
*b
;
2982 sal
.line
= sal
.pc
= sal
.end
= 0;
2985 /* If no arg given, or if first arg is 'if ', all active catch clauses
2986 are breakpointed. */
2988 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2989 && (arg
[2] == ' ' || arg
[2] == '\t')))
2991 /* Grab all active catch clauses. */
2992 sals
= get_catch_sals (0);
2996 /* Grab selected catch clauses. */
2997 error ("catch NAME not implemented");
2999 /* This isn't used; I don't know what it was for. */
3000 sals
= map_catch_names (arg
, catch_breakpoint
);
3008 for (i
= 0; i
< sals
.nelts
; i
++)
3010 resolve_sal_pc (&sals
.sals
[i
]);
3014 if (arg
[0] == 'i' && arg
[1] == 'f'
3015 && (arg
[2] == ' ' || arg
[2] == '\t'))
3016 cond
= parse_exp_1 ((arg
+= 2, &arg
),
3017 block_for_pc (sals
.sals
[i
].pc
), 0);
3019 error ("Junk at end of arguments.");
3024 for (i
= 0; i
< sals
.nelts
; i
++)
3029 describe_other_breakpoints (sal
.pc
);
3031 b
= set_raw_breakpoint (sal
);
3032 set_breakpoint_count (breakpoint_count
+ 1);
3033 b
->number
= breakpoint_count
;
3034 b
->type
= bp_breakpoint
;
3036 b
->enable
= enabled
;
3037 b
->disposition
= tempflag
? del
: donttouch
;
3044 printf_unfiltered ("Multiple breakpoints were set.\n");
3045 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
3047 free ((PTR
)sals
.sals
);
3050 /* Used by the gui, could be made a worker for other things. */
3053 set_breakpoint_sal (sal
)
3054 struct symtab_and_line sal
;
3056 struct breakpoint
*b
;
3057 b
= set_raw_breakpoint (sal
);
3058 set_breakpoint_count (breakpoint_count
+ 1);
3059 b
->number
= breakpoint_count
;
3060 b
->type
= bp_breakpoint
;
3067 /* These aren't used; I don't know what they were for. */
3068 /* Disable breakpoints on all catch clauses described in ARGS. */
3070 disable_catch (args
)
3073 /* Map the disable command to catch clauses described in ARGS. */
3076 /* Enable breakpoints on all catch clauses described in ARGS. */
3081 /* Map the disable command to catch clauses described in ARGS. */
3084 /* Delete breakpoints on all catch clauses in the active scope. */
3089 /* Map the delete command to catch clauses described in ARGS. */
3094 catch_command (arg
, from_tty
)
3098 catch_command_1 (arg
, 0, from_tty
);
3102 clear_command (arg
, from_tty
)
3106 register struct breakpoint
*b
, *b1
;
3107 struct symtabs_and_lines sals
;
3108 struct symtab_and_line sal
;
3109 register struct breakpoint
*found
;
3114 sals
= decode_line_spec (arg
, 1);
3118 sals
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
3119 sal
.line
= default_breakpoint_line
;
3120 sal
.symtab
= default_breakpoint_symtab
;
3122 if (sal
.symtab
== 0)
3123 error ("No source file specified.");
3129 for (i
= 0; i
< sals
.nelts
; i
++)
3131 /* If exact pc given, clear bpts at that pc.
3132 But if sal.pc is zero, clear all bpts on specified line. */
3134 found
= (struct breakpoint
*) 0;
3135 while (breakpoint_chain
3137 ? breakpoint_chain
->address
== sal
.pc
3138 : (breakpoint_chain
->source_file
!= NULL
3139 && sal
.symtab
!= NULL
3140 && STREQ (breakpoint_chain
->source_file
,
3141 sal
.symtab
->filename
)
3142 && breakpoint_chain
->line_number
== sal
.line
)))
3144 b1
= breakpoint_chain
;
3145 breakpoint_chain
= b1
->next
;
3152 && b
->next
->type
!= bp_watchpoint
3153 && b
->next
->type
!= bp_hardware_watchpoint
3154 && b
->next
->type
!= bp_read_watchpoint
3155 && b
->next
->type
!= bp_access_watchpoint
3157 ? b
->next
->address
== sal
.pc
3158 : (b
->next
->source_file
!= NULL
3159 && sal
.symtab
!= NULL
3160 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
3161 && b
->next
->line_number
== sal
.line
)))
3172 error ("No breakpoint at %s.", arg
);
3174 error ("No breakpoint at this line.");
3177 if (found
->next
) from_tty
= 1; /* Always report if deleted more than one */
3178 if (from_tty
) printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
3179 breakpoints_changed ();
3182 if (from_tty
) printf_unfiltered ("%d ", found
->number
);
3184 delete_breakpoint (found
);
3187 if (from_tty
) putchar_unfiltered ('\n');
3189 free ((PTR
)sals
.sals
);
3192 /* Delete breakpoint in BS if they are `delete' breakpoints.
3193 This is called after any breakpoint is hit, or after errors. */
3196 breakpoint_auto_delete (bs
)
3199 for (; bs
; bs
= bs
->next
)
3200 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== del
3202 delete_breakpoint (bs
->breakpoint_at
);
3205 /* Delete a breakpoint and clean up all traces of it in the data structures. */
3208 delete_breakpoint (bpt
)
3209 struct breakpoint
*bpt
;
3211 register struct breakpoint
*b
;
3214 if (delete_breakpoint_hook
)
3215 delete_breakpoint_hook (bpt
);
3218 remove_breakpoint (bpt
);
3220 if (breakpoint_chain
== bpt
)
3221 breakpoint_chain
= bpt
->next
;
3226 b
->next
= bpt
->next
;
3230 check_duplicates (bpt
->address
);
3231 /* If this breakpoint was inserted, and there is another breakpoint
3232 at the same address, we need to insert the other breakpoint. */
3234 && bpt
->type
!= bp_hardware_watchpoint
3235 && bpt
->type
!= bp_read_watchpoint
3236 && bpt
->type
!= bp_access_watchpoint
)
3239 if (b
->address
== bpt
->address
3241 && b
->enable
!= disabled
)
3244 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
3247 target_terminal_ours_for_output ();
3248 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
3249 memory_error (val
, b
->address
); /* which bombs us out */
3256 free_command_lines (&bpt
->commands
);
3259 if (bpt
->cond_string
!= NULL
)
3260 free (bpt
->cond_string
);
3261 if (bpt
->addr_string
!= NULL
)
3262 free (bpt
->addr_string
);
3263 if (bpt
->exp_string
!= NULL
)
3264 free (bpt
->exp_string
);
3265 if (bpt
->source_file
!= NULL
)
3266 free (bpt
->source_file
);
3268 /* Be sure no bpstat's are pointing at it after it's been freed. */
3269 /* FIXME, how can we find all bpstat's?
3270 We just check stop_bpstat for now. */
3271 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
3272 if (bs
->breakpoint_at
== bpt
)
3273 bs
->breakpoint_at
= NULL
;
3278 delete_command (arg
, from_tty
)
3285 /* Ask user only if there are some breakpoints to delete. */
3287 || (breakpoint_chain
&& query ("Delete all breakpoints? ")))
3289 /* No arg; clear all breakpoints. */
3290 while (breakpoint_chain
)
3291 delete_breakpoint (breakpoint_chain
);
3295 map_breakpoint_numbers (arg
, delete_breakpoint
);
3298 /* Reset a breakpoint given it's struct breakpoint * BINT.
3299 The value we return ends up being the return value from catch_errors.
3300 Unused in this case. */
3303 breakpoint_re_set_one (bint
)
3306 struct breakpoint
*b
= (struct breakpoint
*)bint
; /* get past catch_errs */
3309 struct symtabs_and_lines sals
;
3311 enum enable save_enable
;
3316 case bp_hardware_breakpoint
:
3317 if (b
->addr_string
== NULL
)
3319 /* Anything without a string can't be re-set. */
3320 delete_breakpoint (b
);
3323 /* In case we have a problem, disable this breakpoint. We'll restore
3324 its status if we succeed. */
3325 save_enable
= b
->enable
;
3326 b
->enable
= disabled
;
3328 set_language (b
->language
);
3329 input_radix
= b
->input_radix
;
3331 sals
= decode_line_1 (&s
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
3332 for (i
= 0; i
< sals
.nelts
; i
++)
3334 resolve_sal_pc (&sals
.sals
[i
]);
3336 /* Reparse conditions, they might contain references to the
3338 if (b
->cond_string
!= NULL
)
3342 free ((PTR
)b
->cond
);
3343 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
3346 /* We need to re-set the breakpoint if the address changes...*/
3347 if (b
->address
!= sals
.sals
[i
].pc
3348 /* ...or new and old breakpoints both have source files, and
3349 the source file name or the line number changes... */
3350 || (b
->source_file
!= NULL
3351 && sals
.sals
[i
].symtab
!= NULL
3352 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
3353 || b
->line_number
!= sals
.sals
[i
].line
)
3355 /* ...or we switch between having a source file and not having
3357 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
3360 if (b
->source_file
!= NULL
)
3361 free (b
->source_file
);
3362 if (sals
.sals
[i
].symtab
== NULL
)
3363 b
->source_file
= NULL
;
3366 savestring (sals
.sals
[i
].symtab
->filename
,
3367 strlen (sals
.sals
[i
].symtab
->filename
));
3368 b
->line_number
= sals
.sals
[i
].line
;
3369 b
->address
= sals
.sals
[i
].pc
;
3371 check_duplicates (b
->address
);
3375 /* Might be better to do this just once per breakpoint_re_set,
3376 rather than once for every breakpoint. */
3377 breakpoints_changed ();
3379 b
->enable
= save_enable
; /* Restore it, this worked. */
3381 free ((PTR
)sals
.sals
);
3385 case bp_hardware_watchpoint
:
3386 case bp_read_watchpoint
:
3387 case bp_access_watchpoint
:
3388 innermost_block
= NULL
;
3389 /* The issue arises of what context to evaluate this in. The same
3390 one as when it was set, but what does that mean when symbols have
3391 been re-read? We could save the filename and functionname, but
3392 if the context is more local than that, the best we could do would
3393 be something like how many levels deep and which index at that
3394 particular level, but that's going to be less stable than filenames
3395 or functionnames. */
3396 /* So for now, just use a global context. */
3397 b
->exp
= parse_expression (b
->exp_string
);
3398 b
->exp_valid_block
= innermost_block
;
3399 mark
= value_mark ();
3400 b
->val
= evaluate_expression (b
->exp
);
3401 release_value (b
->val
);
3402 if (VALUE_LAZY (b
->val
))
3403 value_fetch_lazy (b
->val
);
3405 if (b
->cond_string
!= NULL
)
3408 b
->cond
= parse_exp_1 (&s
, (struct block
*)0, 0);
3410 if (b
->enable
== enabled
)
3412 value_free_to_mark (mark
);
3416 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
3421 case bp_longjmp_resume
:
3422 case bp_watchpoint_scope
:
3424 delete_breakpoint (b
);
3431 /* Re-set all breakpoints after symbols have been re-loaded. */
3433 breakpoint_re_set ()
3435 struct breakpoint
*b
, *temp
;
3436 enum language save_language
;
3437 int save_input_radix
;
3438 static char message1
[] = "Error in re-setting breakpoint %d:\n";
3439 char message
[sizeof (message1
) + 30 /* slop */];
3441 save_language
= current_language
->la_language
;
3442 save_input_radix
= input_radix
;
3443 ALL_BREAKPOINTS_SAFE (b
, temp
)
3445 sprintf (message
, message1
, b
->number
); /* Format possible error msg */
3446 catch_errors (breakpoint_re_set_one
, (char *) b
, message
,
3449 set_language (save_language
);
3450 input_radix
= save_input_radix
;
3452 create_longjmp_breakpoint("longjmp");
3453 create_longjmp_breakpoint("_longjmp");
3454 create_longjmp_breakpoint("siglongjmp");
3455 create_longjmp_breakpoint(NULL
);
3458 /* Took this out (temporaliy at least), since it produces an extra
3459 blank line at startup. This messes up the gdbtests. -PB */
3460 /* Blank line to finish off all those mention() messages we just printed. */
3461 printf_filtered ("\n");
3465 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3466 If from_tty is nonzero, it prints a message to that effect,
3467 which ends with a period (no newline). */
3470 set_ignore_count (bptnum
, count
, from_tty
)
3471 int bptnum
, count
, from_tty
;
3473 register struct breakpoint
*b
;
3479 if (b
->number
== bptnum
)
3481 b
->ignore_count
= count
;
3484 else if (count
== 0)
3485 printf_filtered ("Will stop next time breakpoint %d is reached.",
3487 else if (count
== 1)
3488 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3491 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3493 breakpoints_changed ();
3497 error ("No breakpoint number %d.", bptnum
);
3500 /* Clear the ignore counts of all breakpoints. */
3502 breakpoint_clear_ignore_counts ()
3504 struct breakpoint
*b
;
3507 b
->ignore_count
= 0;
3510 /* Command to set ignore-count of breakpoint N to COUNT. */
3513 ignore_command (args
, from_tty
)
3521 error_no_arg ("a breakpoint number");
3523 num
= get_number (&p
);
3526 error ("Second argument (specified ignore-count) is missing.");
3528 set_ignore_count (num
,
3529 longest_to_int (value_as_long (parse_and_eval (p
))),
3531 printf_filtered ("\n");
3532 breakpoints_changed ();
3535 /* Call FUNCTION on each of the breakpoints
3536 whose numbers are given in ARGS. */
3539 map_breakpoint_numbers (args
, function
)
3541 void (*function
) PARAMS ((struct breakpoint
*));
3543 register char *p
= args
;
3546 register struct breakpoint
*b
;
3549 error_no_arg ("one or more breakpoint numbers");
3555 num
= get_number (&p1
);
3558 if (b
->number
== num
)
3560 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
3562 if (related_breakpoint
)
3563 function (related_breakpoint
);
3566 printf_unfiltered ("No breakpoint number %d.\n", num
);
3573 enable_breakpoint (bpt
)
3574 struct breakpoint
*bpt
;
3576 struct frame_info
*save_selected_frame
= NULL
;
3577 int save_selected_frame_level
= -1;
3578 int target_resources_ok
, other_type_used
;
3581 if (bpt
->type
== bp_hardware_breakpoint
)
3584 i
= hw_breakpoint_used_count();
3585 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3586 bp_hardware_breakpoint
, i
+1, 0);
3587 if (target_resources_ok
== 0)
3588 error ("No hardware breakpoint support in the target.");
3589 else if (target_resources_ok
< 0)
3590 error ("Hardware breakpoints used exceeds limit.");
3592 bpt
->enable
= enabled
;
3593 check_duplicates (bpt
->address
);
3595 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3596 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3598 if (bpt
->exp_valid_block
!= NULL
)
3600 struct frame_info
*fr
=
3601 find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3605 Cannot enable watchpoint %d because the block in which its expression\n\
3606 is valid is not currently in scope.\n", bpt
->number
);
3607 bpt
->enable
= disabled
;
3611 save_selected_frame
= selected_frame
;
3612 save_selected_frame_level
= selected_frame_level
;
3613 select_frame (fr
, -1);
3616 value_free (bpt
->val
);
3617 mark
= value_mark ();
3618 bpt
->val
= evaluate_expression (bpt
->exp
);
3619 release_value (bpt
->val
);
3620 if (VALUE_LAZY (bpt
->val
))
3621 value_fetch_lazy (bpt
->val
);
3623 if (bpt
->type
== bp_hardware_watchpoint
||
3624 bpt
->type
== bp_read_watchpoint
||
3625 bpt
->type
== bp_access_watchpoint
)
3627 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3628 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
3630 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3631 bpt
->type
, i
+ mem_cnt
, other_type_used
);
3632 /* we can consider of type is bp_hardware_watchpoint, convert to
3633 bp_watchpoint in the following condition */
3634 if (target_resources_ok
< 0)
3637 Cannot enable watchpoint %d because target watch resources\n\
3638 have been allocated for other watchpoints.\n", bpt
->number
);
3639 bpt
->enable
= disabled
;
3640 value_free_to_mark (mark
);
3645 if (save_selected_frame_level
>= 0)
3646 select_frame (save_selected_frame
, save_selected_frame_level
);
3647 value_free_to_mark (mark
);
3650 if (modify_breakpoint_hook
)
3651 modify_breakpoint_hook (bpt
);
3656 enable_command (args
, from_tty
)
3660 struct breakpoint
*bpt
;
3662 ALL_BREAKPOINTS (bpt
)
3666 case bp_hardware_breakpoint
:
3668 case bp_hardware_watchpoint
:
3669 case bp_read_watchpoint
:
3670 case bp_access_watchpoint
:
3671 enable_breakpoint (bpt
);
3676 map_breakpoint_numbers (args
, enable_breakpoint
);
3680 disable_breakpoint (bpt
)
3681 struct breakpoint
*bpt
;
3683 /* Never disable a watchpoint scope breakpoint; we want to
3684 hit them when we leave scope so we can delete both the
3685 watchpoint and its scope breakpoint at that time. */
3686 if (bpt
->type
== bp_watchpoint_scope
)
3689 bpt
->enable
= disabled
;
3691 check_duplicates (bpt
->address
);
3693 if (modify_breakpoint_hook
)
3694 modify_breakpoint_hook (bpt
);
3699 disable_command (args
, from_tty
)
3703 register struct breakpoint
*bpt
;
3705 ALL_BREAKPOINTS (bpt
)
3709 case bp_hardware_breakpoint
:
3711 case bp_hardware_watchpoint
:
3712 case bp_read_watchpoint
:
3713 case bp_access_watchpoint
:
3714 disable_breakpoint (bpt
);
3719 map_breakpoint_numbers (args
, disable_breakpoint
);
3723 enable_once_breakpoint (bpt
)
3724 struct breakpoint
*bpt
;
3726 struct frame_info
*save_selected_frame
= NULL
;
3727 int save_selected_frame_level
= -1;
3728 int target_resources_ok
, other_type_used
;
3731 if (bpt
->type
== bp_hardware_breakpoint
)
3734 i
= hw_breakpoint_used_count();
3735 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3736 bp_hardware_breakpoint
, i
+1, 0);
3737 if (target_resources_ok
== 0)
3738 error ("No hardware breakpoint support in the target.");
3739 else if (target_resources_ok
< 0)
3740 error ("Hardware breakpoints used exceeds limit.");
3743 bpt
->enable
= enabled
;
3744 bpt
->disposition
= disable
;
3745 check_duplicates (bpt
->address
);
3746 breakpoints_changed ();
3748 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3749 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3751 if (bpt
->exp_valid_block
!= NULL
)
3753 struct frame_info
*fr
=
3754 find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3758 Cannot enable watchpoint %d because the block in which its expression\n\
3759 is valid is not currently in scope.\n", bpt
->number
);
3760 bpt
->enable
= disabled
;
3764 save_selected_frame
= selected_frame
;
3765 save_selected_frame_level
= selected_frame_level
;
3766 select_frame (fr
, -1);
3769 value_free (bpt
->val
);
3770 mark
= value_mark ();
3771 bpt
->val
= evaluate_expression (bpt
->exp
);
3772 release_value (bpt
->val
);
3773 if (VALUE_LAZY (bpt
->val
))
3774 value_fetch_lazy (bpt
->val
);
3776 if (bpt
->type
== bp_hardware_watchpoint
||
3777 bpt
->type
== bp_read_watchpoint
||
3778 bpt
->type
== bp_access_watchpoint
)
3780 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3781 int mem_cnt
= can_use_hardware_watchpoint(bpt
->val
);
3782 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3783 bpt
->type
, i
+mem_cnt
, other_type_used
);
3784 /* we can consider of type is bp_hardware_watchpoint, convert to
3785 bp_watchpoint in the following condition */
3786 if (target_resources_ok
< 0)
3789 Cannot enable watchpoint %d because target watch resources\n\
3790 have been allocated for other watchpoints.\n", bpt
->number
);
3791 bpt
->enable
= disabled
;
3792 value_free_to_mark (mark
);
3796 if (save_selected_frame_level
>= 0)
3797 select_frame (save_selected_frame
, save_selected_frame_level
);
3798 value_free_to_mark (mark
);
3804 enable_once_command (args
, from_tty
)
3808 map_breakpoint_numbers (args
, enable_once_breakpoint
);
3812 enable_delete_breakpoint (bpt
)
3813 struct breakpoint
*bpt
;
3815 bpt
->enable
= enabled
;
3816 bpt
->disposition
= del
;
3818 check_duplicates (bpt
->address
);
3819 breakpoints_changed ();
3824 enable_delete_command (args
, from_tty
)
3828 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
3831 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
3833 struct symtabs_and_lines
3834 decode_line_spec_1 (string
, funfirstline
)
3838 struct symtabs_and_lines sals
;
3840 error ("Empty line specification.");
3841 if (default_breakpoint_valid
)
3842 sals
= decode_line_1 (&string
, funfirstline
,
3843 default_breakpoint_symtab
, default_breakpoint_line
,
3846 sals
= decode_line_1 (&string
, funfirstline
,
3847 (struct symtab
*)NULL
, 0, (char ***)NULL
);
3849 error ("Junk at end of line specification: %s", string
);
3854 _initialize_breakpoint ()
3856 breakpoint_chain
= 0;
3857 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3858 before a breakpoint is set. */
3859 breakpoint_count
= 0;
3861 add_com ("ignore", class_breakpoint
, ignore_command
,
3862 "Set ignore-count of breakpoint number N to COUNT.\n\
3863 Usage is `ignore N COUNT'.");
3865 add_com ("commands", class_breakpoint
, commands_command
,
3866 "Set commands to be executed when a breakpoint is hit.\n\
3867 Give breakpoint number as argument after \"commands\".\n\
3868 With no argument, the targeted breakpoint is the last one set.\n\
3869 The commands themselves follow starting on the next line.\n\
3870 Type a line containing \"end\" to indicate the end of them.\n\
3871 Give \"silent\" as the first line to make the breakpoint silent;\n\
3872 then no output is printed when it is hit, except what the commands print.");
3874 add_com ("condition", class_breakpoint
, condition_command
,
3875 "Specify breakpoint number N to break only if COND is true.\n\
3876 Usage is `condition N COND', where N is an integer and COND is an\n\
3877 expression to be evaluated whenever breakpoint N is reached. ");
3879 add_com ("tbreak", class_breakpoint
, tbreak_command
,
3880 "Set a temporary breakpoint. Args like \"break\" command.\n\
3881 Like \"break\" except the breakpoint is only temporary,\n\
3882 so it will be deleted when hit. Equivalent to \"break\" followed\n\
3883 by using \"enable delete\" on the breakpoint number.");
3885 add_com ("hbreak", class_breakpoint
, hbreak_command
,
3886 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
3887 Like \"break\" except the breakpoint requires hardware support,\n\
3888 some target hardware may not have this support.");
3890 add_com ("thbreak", class_breakpoint
, thbreak_command
,
3891 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
3892 Like \"hbreak\" except the breakpoint is only temporary,\n\
3893 so it will be deleted when hit.");
3895 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
3896 "Enable some breakpoints.\n\
3897 Give breakpoint numbers (separated by spaces) as arguments.\n\
3898 With no subcommand, breakpoints are enabled until you command otherwise.\n\
3899 This is used to cancel the effect of the \"disable\" command.\n\
3900 With a subcommand you can enable temporarily.",
3901 &enablelist
, "enable ", 1, &cmdlist
);
3903 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
3904 "Enable some breakpoints.\n\
3905 Give breakpoint numbers (separated by spaces) as arguments.\n\
3906 This is used to cancel the effect of the \"disable\" command.\n\
3907 May be abbreviated to simply \"enable\".\n",
3908 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
3910 add_cmd ("once", no_class
, enable_once_command
,
3911 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3912 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3915 add_cmd ("delete", no_class
, enable_delete_command
,
3916 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3917 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3920 add_cmd ("delete", no_class
, enable_delete_command
,
3921 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3922 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3925 add_cmd ("once", no_class
, enable_once_command
,
3926 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3927 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3930 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
3931 "Disable some breakpoints.\n\
3932 Arguments are breakpoint numbers with spaces in between.\n\
3933 To disable all breakpoints, give no argument.\n\
3934 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3935 &disablelist
, "disable ", 1, &cmdlist
);
3936 add_com_alias ("dis", "disable", class_breakpoint
, 1);
3937 add_com_alias ("disa", "disable", class_breakpoint
, 1);
3939 add_cmd ("breakpoints", class_alias
, disable_command
,
3940 "Disable some breakpoints.\n\
3941 Arguments are breakpoint numbers with spaces in between.\n\
3942 To disable all breakpoints, give no argument.\n\
3943 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3944 This command may be abbreviated \"disable\".",
3947 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
3948 "Delete some breakpoints or auto-display expressions.\n\
3949 Arguments are breakpoint numbers with spaces in between.\n\
3950 To delete all breakpoints, give no argument.\n\
3952 Also a prefix command for deletion of other GDB objects.\n\
3953 The \"unset\" command is also an alias for \"delete\".",
3954 &deletelist
, "delete ", 1, &cmdlist
);
3955 add_com_alias ("d", "delete", class_breakpoint
, 1);
3957 add_cmd ("breakpoints", class_alias
, delete_command
,
3958 "Delete some breakpoints or auto-display expressions.\n\
3959 Arguments are breakpoint numbers with spaces in between.\n\
3960 To delete all breakpoints, give no argument.\n\
3961 This command may be abbreviated \"delete\".",
3964 add_com ("clear", class_breakpoint
, clear_command
,
3965 concat ("Clear breakpoint at specified line or function.\n\
3966 Argument may be line number, function name, or \"*\" and an address.\n\
3967 If line number is specified, all breakpoints in that line are cleared.\n\
3968 If function is specified, breakpoints at beginning of function are cleared.\n\
3969 If an address is specified, breakpoints at that address are cleared.\n\n",
3970 "With no argument, clears all breakpoints in the line that the selected frame\n\
3973 See also the \"delete\" command which clears breakpoints by number.", NULL
));
3975 add_com ("break", class_breakpoint
, break_command
,
3976 concat ("Set breakpoint at specified line or function.\n\
3977 Argument may be line number, function name, or \"*\" and an address.\n\
3978 If line number is specified, break at start of code for that line.\n\
3979 If function is specified, break at start of code for that function.\n\
3980 If an address is specified, break at that exact address.\n",
3981 "With no arg, uses current execution address of selected stack frame.\n\
3982 This is useful for breaking on return to a stack frame.\n\
3984 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3986 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
3987 add_com_alias ("b", "break", class_run
, 1);
3988 add_com_alias ("br", "break", class_run
, 1);
3989 add_com_alias ("bre", "break", class_run
, 1);
3990 add_com_alias ("brea", "break", class_run
, 1);
3992 add_info ("breakpoints", breakpoints_info
,
3993 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3994 The \"Type\" column indicates one of:\n\
3995 \tbreakpoint - normal breakpoint\n\
3996 \twatchpoint - watchpoint\n\
3997 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3998 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3999 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
4000 address and file/line number respectively.\n\n",
4001 "Convenience variable \"$_\" and default examine address for \"x\"\n\
4002 are set to the address of the last breakpoint listed.\n\n\
4003 Convenience variable \"$bpnum\" contains the number of the last\n\
4004 breakpoint set.", NULL
));
4006 #if MAINTENANCE_CMDS
4008 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
4009 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
4010 The \"Type\" column indicates one of:\n\
4011 \tbreakpoint - normal breakpoint\n\
4012 \twatchpoint - watchpoint\n\
4013 \tlongjmp - internal breakpoint used to step through longjmp()\n\
4014 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
4015 \tuntil - internal breakpoint used by the \"until\" command\n\
4016 \tfinish - internal breakpoint used by the \"finish\" command\n",
4017 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
4018 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4019 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
4020 address and file/line number respectively.\n\n",
4021 "Convenience variable \"$_\" and default examine address for \"x\"\n\
4022 are set to the address of the last breakpoint listed.\n\n\
4023 Convenience variable \"$bpnum\" contains the number of the last\n\
4024 breakpoint set.", NULL
),
4025 &maintenanceinfolist
);
4027 #endif /* MAINTENANCE_CMDS */
4029 add_com ("catch", class_breakpoint
, catch_command
,
4030 "Set breakpoints to catch exceptions that are raised.\n\
4031 Argument may be a single exception to catch, multiple exceptions\n\
4032 to catch, or the default exception \"default\". If no arguments\n\
4033 are given, breakpoints are set at all exception handlers catch clauses\n\
4034 within the current scope.\n\
4036 A condition specified for the catch applies to all breakpoints set\n\
4037 with this command\n\
4039 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
4041 add_com ("watch", class_breakpoint
, watch_command
,
4042 "Set a watchpoint for an expression.\n\
4043 A watchpoint stops execution of your program whenever the value of\n\
4044 an expression changes.");
4046 add_com ("rwatch", class_breakpoint
, rwatch_command
,
4047 "Set a read watchpoint for an expression.\n\
4048 A watchpoint stops execution of your program whenever the value of\n\
4049 an expression is read.");
4051 add_com ("awatch", class_breakpoint
, awatch_command
,
4052 "Set a watchpoint for an expression.\n\
4053 A watchpoint stops execution of your program whenever the value of\n\
4054 an expression is either read or written.");
4056 add_info ("watchpoints", breakpoints_info
,
4057 "Synonym for ``info breakpoints''.");