1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994
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 disable_breakpoint
PARAMS ((struct breakpoint
*));
65 enable_command
PARAMS ((char *, int));
68 enable_breakpoint
PARAMS ((struct breakpoint
*));
71 map_breakpoint_numbers
PARAMS ((char *, void (*)(struct breakpoint
*)));
74 ignore_command
PARAMS ((char *, int));
77 breakpoint_re_set_one
PARAMS ((char *));
80 delete_command
PARAMS ((char *, int));
83 clear_command
PARAMS ((char *, int));
86 catch_command
PARAMS ((char *, int));
88 static struct symtabs_and_lines
89 get_catch_sals
PARAMS ((int));
92 watch_command
PARAMS ((char *, int));
95 can_use_hardware_watchpoint
PARAMS ((struct value
*));
98 tbreak_command
PARAMS ((char *, int));
101 break_command_1
PARAMS ((char *, int, int));
104 mention
PARAMS ((struct breakpoint
*));
106 static struct breakpoint
*
107 set_raw_breakpoint
PARAMS ((struct symtab_and_line
));
110 check_duplicates
PARAMS ((CORE_ADDR
));
113 describe_other_breakpoints
PARAMS ((CORE_ADDR
));
116 breakpoints_info
PARAMS ((char *, int));
119 breakpoint_1
PARAMS ((int, int));
122 bpstat_alloc
PARAMS ((struct breakpoint
*, bpstat
));
125 breakpoint_cond_eval
PARAMS ((char *));
128 cleanup_executing_breakpoints
PARAMS ((int));
131 commands_command
PARAMS ((char *, int));
134 condition_command
PARAMS ((char *, int));
137 get_number
PARAMS ((char **));
140 set_breakpoint_count
PARAMS ((int));
143 remove_breakpoint
PARAMS ((struct breakpoint
*));
145 extern int addressprint
; /* Print machine addresses? */
147 /* Are we executing breakpoint commands? */
148 static int executing_breakpoint_commands
;
150 /* Walk the following statement or block through all breakpoints.
151 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
154 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
156 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
157 for (b = breakpoint_chain; \
158 b? (tmp=b->next, 1): 0; \
161 /* By default no support for hardware watchpoints is assumed. */
162 #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT
163 #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) 0
164 #define target_remove_watchpoint(ADDR,LEN,TYPE) -1
165 #define target_insert_watchpoint(ADDR,LEN,TYPE) -1
168 #ifndef target_insert_hw_breakpoint
169 #define target_remove_hw_breakpoint(ADDR,SHADOW) -1
170 #define target_insert_hw_breakpoint(ADDR,SHADOW) -1
173 #ifndef target_stopped_data_address
174 #define target_stopped_data_address() 0
177 /* True if breakpoint hit counts should be displayed in breakpoint info. */
179 int show_breakpoint_hit_counts
= 1;
181 /* Chain of all breakpoints defined. */
183 static struct breakpoint
*breakpoint_chain
;
185 /* Number of last breakpoint made. */
187 static int breakpoint_count
;
189 /* Set breakpoint count to NUM. */
192 set_breakpoint_count (num
)
195 breakpoint_count
= num
;
196 set_internalvar (lookup_internalvar ("bpnum"),
197 value_from_longest (builtin_type_int
, (LONGEST
) num
));
200 /* Used in run_command to zero the hit count when a new run starts. */
203 clear_breakpoint_hit_counts ()
205 struct breakpoint
*b
;
211 /* Default address, symtab and line to put a breakpoint at
212 for "break" command with no arg.
213 if default_breakpoint_valid is zero, the other three are
214 not valid, and "break" with no arg is an error.
216 This set by print_stack_frame, which calls set_default_breakpoint. */
218 int default_breakpoint_valid
;
219 CORE_ADDR default_breakpoint_address
;
220 struct symtab
*default_breakpoint_symtab
;
221 int default_breakpoint_line
;
223 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
224 Advance *PP after the string and any trailing whitespace.
226 Currently the string can either be a number or "$" followed by the name
227 of a convenience variable. Making it an expression wouldn't work well
228 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
237 /* Empty line means refer to the last breakpoint. */
238 return breakpoint_count
;
241 /* Make a copy of the name, so we can null-terminate it
242 to pass to lookup_internalvar(). */
247 while (isalnum (*p
) || *p
== '_')
249 varname
= (char *) alloca (p
- start
+ 1);
250 strncpy (varname
, start
, p
- start
);
251 varname
[p
- start
] = '\0';
252 val
= value_of_internalvar (lookup_internalvar (varname
));
253 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
255 "Convenience variables used to specify breakpoints must have integer values."
257 retval
= (int) value_as_long (val
);
263 while (*p
>= '0' && *p
<= '9')
266 /* There is no number here. (e.g. "cond a == b"). */
267 error_no_arg ("breakpoint number");
270 if (!(isspace (*p
) || *p
== '\0'))
271 error ("breakpoint number expected");
278 /* condition N EXP -- set break condition of breakpoint N to EXP. */
281 condition_command (arg
, from_tty
)
285 register struct breakpoint
*b
;
290 error_no_arg ("breakpoint number");
293 bnum
= get_number (&p
);
296 if (b
->number
== bnum
)
303 if (b
->cond_string
!= NULL
)
304 free ((PTR
)b
->cond_string
);
309 b
->cond_string
= NULL
;
311 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
316 /* I don't know if it matters whether this is the string the user
317 typed in or the decompiled expression. */
318 b
->cond_string
= savestring (arg
, strlen (arg
));
319 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
321 error ("Junk at end of expression");
326 error ("No breakpoint number %d.", bnum
);
331 commands_command (arg
, from_tty
)
335 register struct breakpoint
*b
;
338 struct command_line
*l
;
340 /* If we allowed this, we would have problems with when to
341 free the storage, if we change the commands currently
344 if (executing_breakpoint_commands
)
345 error ("Can't use the \"commands\" command among a breakpoint's commands.");
348 bnum
= get_number (&p
);
350 error ("Unexpected extra arguments following breakpoint number.");
353 if (b
->number
== bnum
)
355 if (from_tty
&& input_from_terminal_p ())
356 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
357 End with a line saying just \"end\".\n", bnum
);
358 l
= read_command_lines ();
359 free_command_lines (&b
->commands
);
361 breakpoints_changed ();
364 error ("No breakpoint number %d.", bnum
);
367 extern int memory_breakpoint_size
; /* from mem-break.c */
369 /* Like target_read_memory() but if breakpoints are inserted, return
370 the shadow contents instead of the breakpoints themselves.
372 Read "memory data" from whatever target or inferior we have.
373 Returns zero if successful, errno value if not. EIO is used
374 for address out of bounds. If breakpoints are inserted, returns
375 shadow contents, not the breakpoints themselves. From breakpoint.c. */
378 read_memory_nobpt (memaddr
, myaddr
, len
)
384 struct breakpoint
*b
;
386 if (memory_breakpoint_size
< 0)
387 /* No breakpoints on this machine. FIXME: This should be
388 dependent on the debugging target. Probably want
389 target_insert_breakpoint to return a size, saying how many
390 bytes of the shadow contents are used, or perhaps have
391 something like target_xfer_shadow. */
392 return target_read_memory (memaddr
, myaddr
, len
);
396 if (b
->type
== bp_watchpoint
397 || b
->type
== bp_hardware_watchpoint
398 || b
->type
== bp_read_watchpoint
399 || b
->type
== bp_access_watchpoint
402 else if (b
->address
+ memory_breakpoint_size
<= memaddr
)
403 /* The breakpoint is entirely before the chunk of memory
406 else if (b
->address
>= memaddr
+ len
)
407 /* The breakpoint is entirely after the chunk of memory we
412 /* Copy the breakpoint from the shadow contents, and recurse
413 for the things before and after. */
415 /* Addresses and length of the part of the breakpoint that
417 CORE_ADDR membpt
= b
->address
;
418 unsigned int bptlen
= memory_breakpoint_size
;
419 /* Offset within shadow_contents. */
422 if (membpt
< memaddr
)
424 /* Only copy the second part of the breakpoint. */
425 bptlen
-= memaddr
- membpt
;
426 bptoffset
= memaddr
- membpt
;
430 if (membpt
+ bptlen
> memaddr
+ len
)
432 /* Only copy the first part of the breakpoint. */
433 bptlen
-= (membpt
+ bptlen
) - (memaddr
+ len
);
436 memcpy (myaddr
+ membpt
- memaddr
,
437 b
->shadow_contents
+ bptoffset
, bptlen
);
439 if (membpt
> memaddr
)
441 /* Copy the section of memory before the breakpoint. */
442 status
= read_memory_nobpt (memaddr
, myaddr
, membpt
- memaddr
);
447 if (membpt
+ bptlen
< memaddr
+ len
)
449 /* Copy the section of memory after the breakpoint. */
450 status
= read_memory_nobpt
452 myaddr
+ membpt
+ bptlen
- memaddr
,
453 memaddr
+ len
- (membpt
+ bptlen
));
460 /* Nothing overlaps. Just call read_memory_noerr. */
461 return target_read_memory (memaddr
, myaddr
, len
);
464 /* insert_breakpoints is used when starting or continuing the program.
465 remove_breakpoints is used when the program stops.
466 Both return zero if successful,
467 or an `errno' value if could not write the inferior. */
470 insert_breakpoints ()
472 register struct breakpoint
*b
;
474 int disabled_breaks
= 0;
477 if (b
->type
!= bp_watchpoint
478 && b
->type
!= bp_hardware_watchpoint
479 && b
->type
!= bp_read_watchpoint
480 && b
->type
!= bp_access_watchpoint
481 && b
->enable
!= disabled
485 if (b
->type
== bp_hardware_breakpoint
)
486 val
= target_insert_hw_breakpoint(b
->address
, b
->shadow_contents
);
488 val
= target_insert_breakpoint(b
->address
, b
->shadow_contents
);
491 /* Can't set the breakpoint. */
492 #if defined (DISABLE_UNSETTABLE_BREAK)
493 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
496 b
->enable
= disabled
;
497 if (!disabled_breaks
)
499 target_terminal_ours_for_output ();
500 fprintf_unfiltered (gdb_stderr
,
501 "Cannot insert breakpoint %d:\n", b
->number
);
502 printf_filtered ("Disabling shared library breakpoints:\n");
505 printf_filtered ("%d ", b
->number
);
510 target_terminal_ours_for_output ();
511 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
512 #ifdef ONE_PROCESS_WRITETEXT
513 fprintf_unfiltered (gdb_stderr
,
514 "The same program may be running in another process.\n");
516 memory_error (val
, b
->address
); /* which bombs us out */
522 else if ((b
->type
== bp_hardware_watchpoint
||
523 b
->type
== bp_read_watchpoint
||
524 b
->type
== bp_access_watchpoint
)
525 && b
->enable
== enabled
530 int saved_level
, within_current_scope
;
531 value_ptr mark
= value_mark ();
534 /* Save the current frame and level so we can restore it after
535 evaluating the watchpoint expression on its own frame. */
536 saved_frame
= selected_frame
;
537 saved_level
= selected_frame_level
;
539 /* Determine if the watchpoint is within scope. */
540 if (b
->exp_valid_block
== NULL
)
541 within_current_scope
= 1;
544 FRAME fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
545 within_current_scope
= (fr
!= NULL
);
546 if (within_current_scope
)
547 select_frame (fr
, -1);
550 if (within_current_scope
)
552 /* Evaluate the expression and cut the chain of values
553 produced off from the value chain. */
554 v
= evaluate_expression (b
->exp
);
555 value_release_to_mark (mark
);
560 /* Look at each value on the value chain. */
561 for ( ; v
; v
=v
->next
)
563 /* If it's a memory location, then we must watch it. */
564 if (v
->lval
== lval_memory
)
568 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
569 len
= TYPE_LENGTH (VALUE_TYPE (v
));
571 if (b
->type
== bp_read_watchpoint
)
573 else if (b
->type
== bp_access_watchpoint
)
576 val
= target_insert_watchpoint (addr
, len
, type
);
585 /* Failure to insert a watchpoint on any memory value in the
586 value chain brings us here. */
588 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
594 Hardware watchpoint %d deleted because the program has left the block in\n\
595 which its expression is valid.\n", b
->number
);
596 if (b
->related_breakpoint
)
597 delete_breakpoint (b
->related_breakpoint
);
598 delete_breakpoint (b
);
601 /* Restore the frame and level. */
602 select_frame (saved_frame
, saved_level
);
605 printf_filtered ("\n");
611 remove_breakpoints ()
613 register struct breakpoint
*b
;
620 val
= remove_breakpoint (b
);
630 remove_breakpoint (b
)
631 struct breakpoint
*b
;
635 if (b
->type
!= bp_watchpoint
636 && b
->type
!= bp_hardware_watchpoint
637 && b
->type
!= bp_read_watchpoint
638 && b
->type
!= bp_access_watchpoint
)
640 if (b
->type
== bp_hardware_breakpoint
)
641 val
= target_remove_hw_breakpoint(b
->address
, b
->shadow_contents
);
643 val
= target_remove_breakpoint(b
->address
, b
->shadow_contents
);
648 else if ((b
->type
== bp_hardware_watchpoint
||
649 b
->type
== bp_read_watchpoint
||
650 b
->type
== bp_access_watchpoint
)
651 && b
->enable
== enabled
657 /* Walk down the saved value chain. */
658 for (v
= b
->val_chain
; v
; v
= v
->next
)
660 /* For each memory reference remove the watchpoint
662 if (v
->lval
== lval_memory
)
666 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
667 len
= TYPE_LENGTH (VALUE_TYPE (v
));
668 val
= target_remove_watchpoint (addr
, len
, b
->type
);
674 /* Failure to remove any of the hardware watchpoints comes here. */
676 error ("Hardware watchpoint %d: Could not remove watchpoint\n",
679 /* Free the saved value chain. We will construct a new one
680 the next time the watchpoint is inserted. */
681 for (v
= b
->val_chain
; v
; v
= n
)
691 /* Clear the "inserted" flag in all breakpoints. */
694 mark_breakpoints_out ()
696 register struct breakpoint
*b
;
702 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
703 which should go away between runs of the program. */
706 breakpoint_init_inferior ()
708 register struct breakpoint
*b
, *temp
;
710 ALL_BREAKPOINTS_SAFE (b
, temp
)
714 /* If the call dummy breakpoint is at the entry point it will
715 cause problems when the inferior is rerun, so we better
717 if (b
->type
== bp_call_dummy
)
718 delete_breakpoint (b
);
720 /* Likewise for scope breakpoints. */
721 if (b
->type
== bp_watchpoint_scope
)
722 delete_breakpoint (b
);
724 /* Likewise for watchpoints on local expressions. */
725 if ((b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
||
726 b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
727 && b
->exp_valid_block
!= NULL
)
728 delete_breakpoint (b
);
732 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
733 When continuing from a location with a breakpoint,
734 we actually single step once before calling insert_breakpoints. */
737 breakpoint_here_p (pc
)
740 register struct breakpoint
*b
;
743 if (b
->enable
!= disabled
&& b
->address
== pc
)
749 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
750 because figuring out the saved SP would take too much time, at least using
751 get_saved_register on the 68k. This means that for this function to
752 work right a port must use the bp_call_dummy breakpoint. */
755 frame_in_dummy (frame
)
758 struct breakpoint
*b
;
763 static unsigned LONGEST dummy
[] = CALL_DUMMY
;
765 if (b
->type
== bp_call_dummy
766 && b
->frame
== frame
->frame
768 /* We need to check the PC as well as the frame on the sparc,
769 for signals.exp in the testsuite. */
772 - sizeof (dummy
) / sizeof (LONGEST
) * REGISTER_SIZE
))
773 && frame
->pc
<= b
->address
)
776 #endif /* CALL_DUMMY */
780 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
781 is valid for process/thread PID. */
784 breakpoint_thread_match (pc
, pid
)
788 struct breakpoint
*b
;
791 thread
= pid_to_thread_id (pid
);
794 if (b
->enable
!= disabled
796 && (b
->thread
== -1 || b
->thread
== thread
))
803 /* bpstat stuff. External routines' interfaces are documented
806 /* Clear a bpstat so that it says we are not at any breakpoint.
807 Also free any storage that is part of a bpstat. */
822 if (p
->old_val
!= NULL
)
823 value_free (p
->old_val
);
830 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
831 is part of the bpstat is copied as well. */
839 bpstat retval
= NULL
;
844 for (; bs
!= NULL
; bs
= bs
->next
)
846 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
847 memcpy (tmp
, bs
, sizeof (*tmp
));
849 /* This is the first thing in the chain. */
859 /* Find the bpstat associated with this breakpoint */
862 bpstat_find_breakpoint(bsp
, breakpoint
)
864 struct breakpoint
*breakpoint
;
866 if (bsp
== NULL
) return NULL
;
868 for (;bsp
!= NULL
; bsp
= bsp
->next
) {
869 if (bsp
->breakpoint_at
== breakpoint
) return bsp
;
874 /* Return the breakpoint number of the first breakpoint we are stopped
875 at. *BSP upon return is a bpstat which points to the remaining
876 breakpoints stopped at (but which is not guaranteed to be good for
877 anything but further calls to bpstat_num).
878 Return 0 if passed a bpstat which does not indicate any breakpoints. */
884 struct breakpoint
*b
;
887 return 0; /* No more breakpoint values */
890 b
= (*bsp
)->breakpoint_at
;
893 return -1; /* breakpoint that's been deleted since */
895 return b
->number
; /* We have its number */
899 /* Modify BS so that the actions will not be performed. */
902 bpstat_clear_actions (bs
)
905 for (; bs
!= NULL
; bs
= bs
->next
)
908 if (bs
->old_val
!= NULL
)
910 value_free (bs
->old_val
);
916 /* Stub for cleaning up our state if we error-out of a breakpoint command */
919 cleanup_executing_breakpoints (ignore
)
922 executing_breakpoint_commands
= 0;
925 /* Execute all the commands associated with all the breakpoints at this
926 location. Any of these commands could cause the process to proceed
927 beyond this point, etc. We look out for such changes by checking
928 the global "breakpoint_proceeded" after each command. */
931 bpstat_do_actions (bsp
)
935 struct cleanup
*old_chain
;
937 executing_breakpoint_commands
= 1;
938 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
943 breakpoint_proceeded
= 0;
944 for (; bs
!= NULL
; bs
= bs
->next
)
948 char *line
= bs
->commands
->line
;
949 bs
->commands
= bs
->commands
->next
;
950 execute_command (line
, 0);
951 /* If the inferior is proceeded by the command, bomb out now.
952 The bpstat chain has been blown away by wait_for_inferior.
953 But since execution has stopped again, there is a new bpstat
954 to look at, so start over. */
955 if (breakpoint_proceeded
)
960 executing_breakpoint_commands
= 0;
961 discard_cleanups (old_chain
);
964 /* This is the normal print_it function for a bpstat. In the future,
965 much of this logic could (should?) be moved to bpstat_stop_status,
966 by having it set different print_it functions. */
972 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
973 which has since been deleted. */
974 if (bs
->breakpoint_at
== NULL
975 || (bs
->breakpoint_at
->type
!= bp_breakpoint
976 && bs
->breakpoint_at
->type
!= bp_hardware_breakpoint
977 && bs
->breakpoint_at
->type
!= bp_watchpoint
978 && bs
->breakpoint_at
->type
!= bp_read_watchpoint
979 && bs
->breakpoint_at
->type
!= bp_access_watchpoint
980 && bs
->breakpoint_at
->type
!= bp_hardware_watchpoint
))
983 if (bs
->breakpoint_at
->type
== bp_breakpoint
||
984 bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
986 /* I think the user probably only wants to see one breakpoint
987 number, not all of them. */
988 annotate_breakpoint (bs
->breakpoint_at
->number
);
989 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
992 else if ((bs
->old_val
!= NULL
) &&
993 (bs
->breakpoint_at
->type
== bp_watchpoint
||
994 bs
->breakpoint_at
->type
== bp_access_watchpoint
||
995 bs
->breakpoint_at
->type
== bp_hardware_watchpoint
))
997 annotate_watchpoint (bs
->breakpoint_at
->number
);
998 mention (bs
->breakpoint_at
);
999 printf_filtered ("\nOld value = ");
1000 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
1001 printf_filtered ("\nNew value = ");
1002 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1003 Val_pretty_default
);
1004 printf_filtered ("\n");
1005 value_free (bs
->old_val
);
1007 /* More than one watchpoint may have been triggered. */
1010 else if (bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1011 bs
->breakpoint_at
->type
== bp_read_watchpoint
)
1013 mention (bs
->breakpoint_at
);
1014 printf_filtered ("\nValue = ");
1015 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1016 Val_pretty_default
);
1017 printf_filtered ("\n");
1020 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1024 /* Print a message indicating what happened. Returns nonzero to
1025 say that only the source line should be printed after this (zero
1026 return means print the frame as well as the source line). */
1027 /* Currently we always return zero. */
1037 val
= (*bs
->print_it
) (bs
);
1041 /* Maybe another breakpoint in the chain caused us to stop.
1042 (Currently all watchpoints go on the bpstat whether hit or
1043 not. That probably could (should) be changed, provided care is taken
1044 with respect to bpstat_explains_signal). */
1046 return bpstat_print (bs
->next
);
1048 /* We reached the end of the chain without printing anything. */
1052 /* Evaluate the expression EXP and return 1 if value is zero.
1053 This is used inside a catch_errors to evaluate the breakpoint condition.
1054 The argument is a "struct expression *" that has been cast to char * to
1055 make it pass through catch_errors. */
1058 breakpoint_cond_eval (exp
)
1061 value_ptr mark
= value_mark ();
1062 int i
= !value_true (evaluate_expression ((struct expression
*)exp
));
1063 value_free_to_mark (mark
);
1067 /* Allocate a new bpstat and chain it to the current one. */
1070 bpstat_alloc (b
, cbs
)
1071 register struct breakpoint
*b
;
1072 bpstat cbs
; /* Current "bs" value */
1076 bs
= (bpstat
) xmalloc (sizeof (*bs
));
1078 bs
->breakpoint_at
= b
;
1079 /* If the condition is false, etc., don't do the commands. */
1080 bs
->commands
= NULL
;
1082 bs
->print_it
= print_it_normal
;
1086 /* Possible return values for watchpoint_check (this can't be an enum
1087 because of check_errors). */
1088 /* The watchpoint has been deleted. */
1089 #define WP_DELETED 1
1090 /* The value has changed. */
1091 #define WP_VALUE_CHANGED 2
1092 /* The value has not changed. */
1093 #define WP_VALUE_NOT_CHANGED 3
1095 /* Check watchpoint condition. */
1098 watchpoint_check (p
)
1101 bpstat bs
= (bpstat
) p
;
1102 struct breakpoint
*b
;
1103 FRAME saved_frame
, fr
;
1104 int within_current_scope
, saved_level
;
1106 /* Save the current frame and level so we can restore it after
1107 evaluating the watchpoint expression on its own frame. */
1108 saved_frame
= selected_frame
;
1109 saved_level
= selected_frame_level
;
1111 b
= bs
->breakpoint_at
;
1113 if (b
->exp_valid_block
== NULL
)
1114 within_current_scope
= 1;
1117 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
1118 within_current_scope
= (fr
!= NULL
);
1119 if (within_current_scope
)
1120 /* If we end up stopping, the current frame will get selected
1121 in normal_stop. So this call to select_frame won't affect
1123 select_frame (fr
, -1);
1126 if (within_current_scope
)
1128 /* We use value_{,free_to_}mark because it could be a
1129 *long* time before we return to the command level and
1130 call free_all_values. We can't call free_all_values because
1131 we might be in the middle of evaluating a function call. */
1133 value_ptr mark
= value_mark ();
1134 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
1135 if (!value_equal (b
->val
, new_val
))
1137 release_value (new_val
);
1138 value_free_to_mark (mark
);
1139 bs
->old_val
= b
->val
;
1141 /* We will stop here */
1142 select_frame (saved_frame
, saved_level
);
1143 return WP_VALUE_CHANGED
;
1147 /* Nothing changed, don't do anything. */
1148 value_free_to_mark (mark
);
1149 /* We won't stop here */
1150 select_frame (saved_frame
, saved_level
);
1151 return WP_VALUE_NOT_CHANGED
;
1156 /* This seems like the only logical thing to do because
1157 if we temporarily ignored the watchpoint, then when
1158 we reenter the block in which it is valid it contains
1159 garbage (in the case of a function, it may have two
1160 garbage values, one before and one after the prologue).
1161 So we can't even detect the first assignment to it and
1162 watch after that (since the garbage may or may not equal
1163 the first value assigned). */
1165 Watchpoint %d deleted because the program has left the block in\n\
1166 which its expression is valid.\n", bs
->breakpoint_at
->number
);
1167 if (b
->related_breakpoint
)
1168 delete_breakpoint (b
->related_breakpoint
);
1169 delete_breakpoint (b
);
1171 select_frame (saved_frame
, saved_level
);
1176 /* This is used when everything which needs to be printed has
1177 already been printed. But we still want to print the frame. */
1185 /* This is used when nothing should be printed for this bpstat entry. */
1194 /* Get a bpstat associated with having just stopped at address *PC
1195 and frame address FRAME_ADDRESS. Update *PC to point at the
1196 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1197 if this is known to not be a real breakpoint (it could still be a
1198 watchpoint, though). */
1200 /* Determine whether we stopped at a breakpoint, etc, or whether we
1201 don't understand this stop. Result is a chain of bpstat's such that:
1203 if we don't understand the stop, the result is a null pointer.
1205 if we understand why we stopped, the result is not null.
1207 Each element of the chain refers to a particular breakpoint or
1208 watchpoint at which we have stopped. (We may have stopped for
1209 several reasons concurrently.)
1211 Each element of the chain has valid next, breakpoint_at,
1212 commands, FIXME??? fields.
1217 bpstat_stop_status (pc
, frame_address
, not_a_breakpoint
)
1219 FRAME_ADDR frame_address
;
1220 int not_a_breakpoint
;
1222 register struct breakpoint
*b
;
1224 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1225 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1226 int real_breakpoint
= 0;
1228 /* Root of the chain of bpstat's */
1229 struct bpstat root_bs
[1];
1230 /* Pointer to the last thing in the chain currently. */
1231 bpstat bs
= root_bs
;
1232 static char message1
[] =
1233 "Error evaluating expression for watchpoint %d\n";
1234 char message
[sizeof (message1
) + 30 /* slop */];
1236 /* Get the address where the breakpoint would have been. */
1237 bp_addr
= *pc
- DECR_PC_AFTER_BREAK
;
1241 if (b
->enable
== disabled
)
1244 if (b
->type
!= bp_watchpoint
1245 && b
->type
!= bp_hardware_watchpoint
1246 && b
->type
!= bp_read_watchpoint
1247 && b
->type
!= bp_access_watchpoint
1248 && b
->type
!= bp_hardware_breakpoint
1249 && b
->address
!= bp_addr
)
1252 #ifndef DECR_PC_AFTER_HW_BREAK
1253 #define DECR_PC_AFTER_HW_BREAK 0
1255 if (b
->type
== bp_hardware_breakpoint
1256 && b
->address
!= (bp_addr
- DECR_PC_AFTER_HW_BREAK
))
1259 if (b
->type
!= bp_watchpoint
1260 && b
->type
!= bp_hardware_watchpoint
1261 && b
->type
!= bp_read_watchpoint
1262 && b
->type
!= bp_access_watchpoint
1263 && not_a_breakpoint
)
1266 /* Come here if it's a watchpoint, or if the break address matches */
1270 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
1275 sprintf (message
, message1
, b
->number
);
1276 if (b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1278 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1282 /* We've already printed what needs to be printed. */
1283 bs
->print_it
= print_it_done
;
1286 case WP_VALUE_CHANGED
:
1289 case WP_VALUE_NOT_CHANGED
:
1291 bs
->print_it
= print_it_noop
;
1298 /* Error from catch_errors. */
1299 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1300 if (b
->related_breakpoint
)
1301 delete_breakpoint (b
->related_breakpoint
);
1302 delete_breakpoint (b
);
1303 /* We've already printed what needs to be printed. */
1304 bs
->print_it
= print_it_done
;
1310 else if (b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
1316 addr
= target_stopped_data_address();
1317 if (addr
== 0) continue;
1318 for (v
= b
->val_chain
; v
; v
= v
->next
)
1320 if (v
->lval
== lval_memory
)
1324 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1330 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1334 /* We've already printed what needs to be printed. */
1335 bs
->print_it
= print_it_done
;
1338 case WP_VALUE_CHANGED
:
1339 case WP_VALUE_NOT_CHANGED
:
1345 /* Error from catch_errors. */
1346 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1347 if (b
->related_breakpoint
)
1348 delete_breakpoint (b
->related_breakpoint
);
1349 delete_breakpoint (b
);
1350 /* We've already printed what needs to be printed. */
1351 bs
->print_it
= print_it_done
;
1355 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1357 real_breakpoint
= 1;
1360 if (b
->frame
&& b
->frame
!= frame_address
)
1364 int value_is_zero
= 0;
1368 /* Need to select the frame, with all that implies
1369 so that the conditions will have the right context. */
1370 select_frame (get_current_frame (), 0);
1372 = catch_errors (breakpoint_cond_eval
, (char *)(b
->cond
),
1373 "Error in testing breakpoint condition:\n",
1375 /* FIXME-someday, should give breakpoint # */
1378 if (b
->cond
&& value_is_zero
)
1382 else if (b
->ignore_count
> 0)
1389 /* We will stop here */
1390 if (b
->disposition
== disable
)
1391 b
->enable
= disabled
;
1392 bs
->commands
= b
->commands
;
1395 if (bs
->commands
&& STREQ ("silent", bs
->commands
->line
))
1397 bs
->commands
= bs
->commands
->next
;
1402 /* Print nothing for this entry if we dont stop or if we dont print. */
1403 if (bs
->stop
== 0 || bs
->print
== 0)
1404 bs
->print_it
= print_it_noop
;
1407 bs
->next
= NULL
; /* Terminate the chain */
1408 bs
= root_bs
->next
; /* Re-grab the head of the chain */
1409 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1412 if (real_breakpoint
)
1415 #if defined (SHIFT_INST_REGS)
1417 #else /* No SHIFT_INST_REGS. */
1419 #endif /* No SHIFT_INST_REGS. */
1422 #endif /* DECR_PC_AFTER_BREAK != 0. */
1424 /* The value of a hardware watchpoint hasn't changed, but the
1425 intermediate memory locations we are watching may have. */
1426 if (bs
&& ! bs
->stop
&&
1427 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
1428 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
1429 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
1431 remove_breakpoints ();
1432 insert_breakpoints ();
1437 /* Tell what to do about this bpstat. */
1442 /* Classify each bpstat as one of the following. */
1444 /* This bpstat element has no effect on the main_action. */
1447 /* There was a watchpoint, stop but don't print. */
1450 /* There was a watchpoint, stop and print. */
1453 /* There was a breakpoint but we're not stopping. */
1456 /* There was a breakpoint, stop but don't print. */
1459 /* There was a breakpoint, stop and print. */
1462 /* We hit the longjmp breakpoint. */
1465 /* We hit the longjmp_resume breakpoint. */
1468 /* We hit the step_resume breakpoint. */
1471 /* We hit the through_sigtramp breakpoint. */
1474 /* This is just used to count how many enums there are. */
1478 /* Here is the table which drives this routine. So that we can
1479 format it pretty, we define some abbreviations for the
1480 enum bpstat_what codes. */
1481 #define keep_c BPSTAT_WHAT_KEEP_CHECKING
1482 #define stop_s BPSTAT_WHAT_STOP_SILENT
1483 #define stop_n BPSTAT_WHAT_STOP_NOISY
1484 #define single BPSTAT_WHAT_SINGLE
1485 #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME
1486 #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1487 #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1488 #define sr BPSTAT_WHAT_STEP_RESUME
1489 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1491 /* "Can't happen." Might want to print an error message.
1492 abort() is not out of the question, but chances are GDB is just
1493 a bit confused, not unusable. */
1494 #define err BPSTAT_WHAT_STOP_NOISY
1496 /* Given an old action and a class, come up with a new action. */
1497 /* One interesting property of this table is that wp_silent is the same
1498 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1499 after stopping, the check for whether to step over a breakpoint
1500 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1501 reference to how we stopped. We retain separate wp_silent and bp_silent
1502 codes in case we want to change that someday. */
1504 /* step_resume entries: a step resume breakpoint overrides another
1505 breakpoint of signal handling (see comment in wait_for_inferior
1506 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1507 /* We handle the through_sigtramp_breakpoint the same way; having both
1508 one of those and a step_resume_breakpoint is probably very rare (?). */
1510 static const enum bpstat_what_main_action
1511 table
[(int)class_last
][(int)BPSTAT_WHAT_LAST
] =
1514 /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts
1516 /*no_effect*/ {keep_c
,stop_s
,stop_n
,single
, setlr
, clrlr
, clrlrs
, sr
, ts
},
1517 /*wp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1518 /*wp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1519 /*bp_nostop*/ {single
,stop_s
,stop_n
,single
, setlr
, clrlrs
, clrlrs
, sr
, ts
},
1520 /*bp_silent*/ {stop_s
,stop_s
,stop_n
,stop_s
, stop_s
, stop_s
, stop_s
, sr
, ts
},
1521 /*bp_noisy*/ {stop_n
,stop_n
,stop_n
,stop_n
, stop_n
, stop_n
, stop_n
, sr
, ts
},
1522 /*long_jump*/ {setlr
,stop_s
,stop_n
,setlr
, err
, err
, err
, sr
, ts
},
1523 /*long_resume*/ {clrlr
,stop_s
,stop_n
,clrlrs
, err
, err
, err
, sr
, ts
},
1524 /*step_resume*/ {sr
,sr
,sr
,sr
, sr
, sr
, sr
, sr
, ts
},
1525 /*through_sig*/ {ts
,ts
,ts
,ts
, ts
, ts
, ts
, ts
, ts
}
1537 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
1538 struct bpstat_what retval
;
1540 retval
.call_dummy
= 0;
1541 for (; bs
!= NULL
; bs
= bs
->next
)
1543 enum class bs_class
= no_effect
;
1544 if (bs
->breakpoint_at
== NULL
)
1545 /* I suspect this can happen if it was a momentary breakpoint
1546 which has since been deleted. */
1548 switch (bs
->breakpoint_at
->type
)
1551 case bp_hardware_breakpoint
:
1557 bs_class
= bp_noisy
;
1559 bs_class
= bp_silent
;
1562 bs_class
= bp_nostop
;
1565 case bp_hardware_watchpoint
:
1566 case bp_read_watchpoint
:
1567 case bp_access_watchpoint
:
1571 bs_class
= wp_noisy
;
1573 bs_class
= wp_silent
;
1576 /* There was a watchpoint, but we're not stopping. This requires
1577 no further action. */
1578 bs_class
= no_effect
;
1581 bs_class
= long_jump
;
1583 case bp_longjmp_resume
:
1584 bs_class
= long_resume
;
1586 case bp_step_resume
:
1589 bs_class
= step_resume
;
1592 /* It is for the wrong frame. */
1593 bs_class
= bp_nostop
;
1595 case bp_through_sigtramp
:
1596 bs_class
= through_sig
;
1598 case bp_watchpoint_scope
:
1599 bs_class
= bp_nostop
;
1603 /* Make sure the action is stop (silent or noisy), so infrun.c
1604 pops the dummy frame. */
1605 bs_class
= bp_silent
;
1606 retval
.call_dummy
= 1;
1609 current_action
= table
[(int)bs_class
][(int)current_action
];
1611 retval
.main_action
= current_action
;
1615 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1616 without hardware support). This isn't related to a specific bpstat,
1617 just to things like whether watchpoints are set. */
1620 bpstat_should_step ()
1622 struct breakpoint
*b
;
1624 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
1629 /* Print information on breakpoint number BNUM, or -1 if all.
1630 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1631 is nonzero, process only watchpoints. */
1634 breakpoint_1 (bnum
, allflag
)
1638 register struct breakpoint
*b
;
1639 register struct command_line
*l
;
1640 register struct symbol
*sym
;
1641 CORE_ADDR last_addr
= (CORE_ADDR
)-1;
1642 int found_a_breakpoint
= 0;
1643 static char *bptypes
[] = {"breakpoint", "hw breakpoint",
1644 "until", "finish", "watchpoint",
1645 "hw watchpoint", "read watchpoint",
1646 "acc watchpoint", "longjmp",
1647 "longjmp resume", "step resume",
1648 "watchpoint scope", "call dummy" };
1649 static char *bpdisps
[] = {"del", "dis", "keep"};
1650 static char bpenables
[] = "ny";
1651 char wrap_indent
[80];
1655 || bnum
== b
->number
)
1657 /* We only print out user settable breakpoints unless the allflag is set. */
1659 && b
->type
!= bp_breakpoint
1660 && b
->type
!= bp_hardware_breakpoint
1661 && b
->type
!= bp_watchpoint
1662 && b
->type
!= bp_read_watchpoint
1663 && b
->type
!= bp_access_watchpoint
1664 && b
->type
!= bp_hardware_watchpoint
)
1667 if (!found_a_breakpoint
++)
1669 annotate_breakpoints_headers ();
1672 printf_filtered ("Num ");
1674 printf_filtered ("Type ");
1676 printf_filtered ("Disp ");
1678 printf_filtered ("Enb ");
1682 printf_filtered ("Address ");
1685 printf_filtered ("What\n");
1687 annotate_breakpoints_table ();
1692 printf_filtered ("%-3d ", b
->number
);
1694 printf_filtered ("%-14s ", bptypes
[(int)b
->type
]);
1696 printf_filtered ("%-4s ", bpdisps
[(int)b
->disposition
]);
1698 printf_filtered ("%-3c ", bpenables
[(int)b
->enable
]);
1700 strcpy (wrap_indent
, " ");
1702 strcat (wrap_indent
, " ");
1706 case bp_hardware_watchpoint
:
1707 case bp_read_watchpoint
:
1708 case bp_access_watchpoint
:
1709 /* Field 4, the address, is omitted (which makes the columns
1710 not line up too nicely with the headers, but the effect
1711 is relatively readable). */
1713 print_expression (b
->exp
, gdb_stdout
);
1717 case bp_hardware_breakpoint
:
1721 case bp_longjmp_resume
:
1722 case bp_step_resume
:
1723 case bp_through_sigtramp
:
1724 case bp_watchpoint_scope
:
1729 /* FIXME-32x64: need a print_address_numeric with
1733 local_hex_string_custom
1734 ((unsigned long) b
->address
, "08l"));
1739 last_addr
= b
->address
;
1742 sym
= find_pc_function (b
->address
);
1745 fputs_filtered ("in ", gdb_stdout
);
1746 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
1747 wrap_here (wrap_indent
);
1748 fputs_filtered (" at ", gdb_stdout
);
1750 fputs_filtered (b
->source_file
, gdb_stdout
);
1751 printf_filtered (":%d", b
->line_number
);
1754 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
1758 printf_filtered ("\n");
1764 printf_filtered ("\tstop only in stack frame at ");
1765 print_address_numeric (b
->frame
, 1, gdb_stdout
);
1766 printf_filtered ("\n");
1773 printf_filtered ("\tstop only if ");
1774 print_expression (b
->cond
, gdb_stdout
);
1775 printf_filtered ("\n");
1778 if (show_breakpoint_hit_counts
&& b
->hit_count
)
1780 /* FIXME should make an annotation for this */
1782 printf_filtered ("\tbreakpoint already hit %d times\n",
1786 if (b
->ignore_count
)
1790 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
1793 if ((l
= b
->commands
))
1799 fputs_filtered ("\t", gdb_stdout
);
1800 fputs_filtered (l
->line
, gdb_stdout
);
1801 fputs_filtered ("\n", gdb_stdout
);
1807 if (!found_a_breakpoint
)
1810 printf_filtered ("No breakpoints or watchpoints.\n");
1812 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
1815 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1816 that a comparison of an unsigned with -1 is always false. */
1817 if (last_addr
!= (CORE_ADDR
)-1)
1818 set_next_address (last_addr
);
1820 annotate_breakpoints_table_end ();
1825 breakpoints_info (bnum_exp
, from_tty
)
1832 bnum
= parse_and_eval_address (bnum_exp
);
1834 breakpoint_1 (bnum
, 0);
1837 #if MAINTENANCE_CMDS
1841 maintenance_info_breakpoints (bnum_exp
, from_tty
)
1848 bnum
= parse_and_eval_address (bnum_exp
);
1850 breakpoint_1 (bnum
, 1);
1855 /* Print a message describing any breakpoints set at PC. */
1858 describe_other_breakpoints (pc
)
1859 register CORE_ADDR pc
;
1861 register int others
= 0;
1862 register struct breakpoint
*b
;
1865 if (b
->address
== pc
)
1869 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
1871 if (b
->address
== pc
)
1877 (b
->enable
== disabled
) ? " (disabled)" : "",
1878 (others
> 1) ? "," : ((others
== 1) ? " and" : ""));
1880 printf_filtered ("also set at pc ");
1881 print_address_numeric (pc
, 1, gdb_stdout
);
1882 printf_filtered (".\n");
1886 /* Set the default place to put a breakpoint
1887 for the `break' command with no arguments. */
1890 set_default_breakpoint (valid
, addr
, symtab
, line
)
1893 struct symtab
*symtab
;
1896 default_breakpoint_valid
= valid
;
1897 default_breakpoint_address
= addr
;
1898 default_breakpoint_symtab
= symtab
;
1899 default_breakpoint_line
= line
;
1902 /* Rescan breakpoints at address ADDRESS,
1903 marking the first one as "first" and any others as "duplicates".
1904 This is so that the bpt instruction is only inserted once. */
1907 check_duplicates (address
)
1910 register struct breakpoint
*b
;
1911 register int count
= 0;
1913 if (address
== 0) /* Watchpoints are uninteresting */
1917 if (b
->enable
!= disabled
&& b
->address
== address
)
1920 b
->duplicate
= count
> 1;
1924 /* Low level routine to set a breakpoint.
1925 Takes as args the three things that every breakpoint must have.
1926 Returns the breakpoint object so caller can set other things.
1927 Does not set the breakpoint number!
1928 Does not print anything.
1930 ==> This routine should not be called if there is a chance of later
1931 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1932 your arguments BEFORE calling this routine! */
1934 static struct breakpoint
*
1935 set_raw_breakpoint (sal
)
1936 struct symtab_and_line sal
;
1938 register struct breakpoint
*b
, *b1
;
1940 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
1941 memset (b
, 0, sizeof (*b
));
1942 b
->address
= sal
.pc
;
1943 if (sal
.symtab
== NULL
)
1944 b
->source_file
= NULL
;
1946 b
->source_file
= savestring (sal
.symtab
->filename
,
1947 strlen (sal
.symtab
->filename
));
1949 b
->line_number
= sal
.line
;
1950 b
->enable
= enabled
;
1953 b
->ignore_count
= 0;
1957 /* Add this breakpoint to the end of the chain
1958 so that a list of breakpoints will come out in order
1959 of increasing numbers. */
1961 b1
= breakpoint_chain
;
1963 breakpoint_chain
= b
;
1971 check_duplicates (sal
.pc
);
1972 breakpoints_changed ();
1978 create_longjmp_breakpoint(func_name
)
1981 struct symtab_and_line sal
;
1982 struct breakpoint
*b
;
1983 static int internal_breakpoint_number
= -1;
1985 if (func_name
!= NULL
)
1987 struct minimal_symbol
*m
;
1989 m
= lookup_minimal_symbol(func_name
, (struct objfile
*)NULL
);
1991 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
2001 b
= set_raw_breakpoint(sal
);
2004 b
->type
= func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
;
2005 b
->disposition
= donttouch
;
2006 b
->enable
= disabled
;
2009 b
->addr_string
= strsave(func_name
);
2010 b
->number
= internal_breakpoint_number
--;
2013 /* Call this routine when stepping and nexting to enable a breakpoint if we do
2014 a longjmp(). When we hit that breakpoint, call
2015 set_longjmp_resume_breakpoint() to figure out where we are going. */
2018 enable_longjmp_breakpoint()
2020 register struct breakpoint
*b
;
2023 if (b
->type
== bp_longjmp
)
2025 b
->enable
= enabled
;
2026 check_duplicates (b
->address
);
2031 disable_longjmp_breakpoint()
2033 register struct breakpoint
*b
;
2036 if ( b
->type
== bp_longjmp
2037 || b
->type
== bp_longjmp_resume
)
2039 b
->enable
= disabled
;
2040 check_duplicates (b
->address
);
2045 hw_breakpoint_used_count()
2047 register struct breakpoint
*b
;
2052 if (b
->type
== bp_hardware_breakpoint
&& b
->enable
== enabled
)
2060 hw_watchpoint_used_count(type
, other_type_used
)
2062 int *other_type_used
;
2064 register struct breakpoint
*b
;
2067 *other_type_used
= 0;
2070 if (b
->enable
== enabled
)
2072 if (b
->type
== type
) i
++;
2073 else if ((b
->type
== bp_hardware_watchpoint
||
2074 b
->type
== bp_read_watchpoint
||
2075 b
->type
== bp_access_watchpoint
)
2076 && b
->enable
== enabled
)
2077 *other_type_used
= 1;
2083 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
2084 breakpoint at the target of the jmp_buf.
2086 FIXME - This ought to be done by setting a temporary breakpoint that gets
2087 deleted automatically...
2091 set_longjmp_resume_breakpoint(pc
, frame
)
2095 register struct breakpoint
*b
;
2098 if (b
->type
== bp_longjmp_resume
)
2101 b
->enable
= enabled
;
2103 b
->frame
= FRAME_FP(frame
);
2106 check_duplicates (b
->address
);
2111 /* Set a breakpoint that will evaporate an end of command
2112 at address specified by SAL.
2113 Restrict it to frame FRAME if FRAME is nonzero. */
2116 set_momentary_breakpoint (sal
, frame
, type
)
2117 struct symtab_and_line sal
;
2121 register struct breakpoint
*b
;
2122 b
= set_raw_breakpoint (sal
);
2124 b
->enable
= enabled
;
2125 b
->disposition
= donttouch
;
2126 b
->frame
= (frame
? FRAME_FP (frame
) : 0);
2132 clear_momentary_breakpoints ()
2134 register struct breakpoint
*b
;
2136 if (b
->disposition
== delete)
2138 delete_breakpoint (b
);
2144 /* Tell the user we have just set a breakpoint B. */
2148 struct breakpoint
*b
;
2155 printf_filtered ("Watchpoint %d: ", b
->number
);
2156 print_expression (b
->exp
, gdb_stdout
);
2158 case bp_hardware_watchpoint
:
2159 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
2160 print_expression (b
->exp
, gdb_stdout
);
2162 case bp_read_watchpoint
:
2163 printf_filtered ("Hardware read watchpoint %d: ", b
->number
);
2164 print_expression (b
->exp
, gdb_stdout
);
2166 case bp_access_watchpoint
:
2167 printf_filtered ("Hardware access(read/write) watchpoint %d: ",b
->number
);
2168 print_expression (b
->exp
, gdb_stdout
);
2171 printf_filtered ("Breakpoint %d", b
->number
);
2174 case bp_hardware_breakpoint
:
2175 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
2181 case bp_longjmp_resume
:
2182 case bp_step_resume
:
2183 case bp_through_sigtramp
:
2185 case bp_watchpoint_scope
:
2190 if (addressprint
|| b
->source_file
== NULL
)
2192 printf_filtered (" at ");
2193 print_address_numeric (b
->address
, 1, gdb_stdout
);
2196 printf_filtered (": file %s, line %d.",
2197 b
->source_file
, b
->line_number
);
2199 printf_filtered ("\n");
2203 /* Nobody calls this currently. */
2204 /* Set a breakpoint from a symtab and line.
2205 If TEMPFLAG is nonzero, it is a temporary breakpoint.
2206 ADDR_STRING is a malloc'd string holding the name of where we are
2207 setting the breakpoint. This is used later to re-set it after the
2208 program is relinked and symbols are reloaded.
2209 Print the same confirmation messages that the breakpoint command prints. */
2212 set_breakpoint (s
, line
, tempflag
, addr_string
)
2218 register struct breakpoint
*b
;
2219 struct symtab_and_line sal
;
2224 resolve_sal_pc (&sal
); /* Might error out */
2225 describe_other_breakpoints (sal
.pc
);
2227 b
= set_raw_breakpoint (sal
);
2228 set_breakpoint_count (breakpoint_count
+ 1);
2229 b
->number
= breakpoint_count
;
2230 b
->type
= bp_breakpoint
;
2232 b
->addr_string
= addr_string
;
2233 b
->enable
= enabled
;
2234 b
->disposition
= tempflag
? delete : donttouch
;
2240 /* Set a breakpoint according to ARG (function, linenum or *address)
2241 flag: first bit : 0 non-temporary, 1 temporary.
2242 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
2245 break_command_1 (arg
, flag
, from_tty
)
2249 int tempflag
, hardwareflag
;
2250 struct symtabs_and_lines sals
;
2251 struct symtab_and_line sal
;
2252 register struct expression
*cond
= 0;
2253 register struct breakpoint
*b
;
2255 /* Pointers in arg to the start, and one past the end, of the condition. */
2256 char *cond_start
= NULL
;
2257 char *cond_end
= NULL
;
2258 /* Pointers in arg to the start, and one past the end,
2259 of the address part. */
2260 char *addr_start
= NULL
;
2261 char *addr_end
= NULL
;
2262 struct cleanup
*old_chain
;
2263 struct cleanup
*canonical_strings_chain
= NULL
;
2264 char **canonical
= (char **)NULL
;
2268 hardwareflag
= flag
& 2;
2269 tempflag
= flag
& 1;
2274 sal
.line
= sal
.pc
= sal
.end
= 0;
2277 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2279 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2280 && (arg
[2] == ' ' || arg
[2] == '\t')))
2282 if (default_breakpoint_valid
)
2284 sals
.sals
= (struct symtab_and_line
*)
2285 xmalloc (sizeof (struct symtab_and_line
));
2286 sal
.pc
= default_breakpoint_address
;
2287 sal
.line
= default_breakpoint_line
;
2288 sal
.symtab
= default_breakpoint_symtab
;
2293 error ("No default breakpoint address now.");
2299 /* Force almost all breakpoints to be in terms of the
2300 current_source_symtab (which is decode_line_1's default). This
2301 should produce the results we want almost all of the time while
2302 leaving default_breakpoint_* alone. */
2303 if (default_breakpoint_valid
2304 && (!current_source_symtab
2305 || (arg
&& (*arg
== '+' || *arg
== '-'))))
2306 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2307 default_breakpoint_line
, &canonical
);
2309 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
2317 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2318 the following `for' loop errors out. */
2319 old_chain
= make_cleanup (free
, sals
.sals
);
2320 if (canonical
!= (char **)NULL
)
2322 make_cleanup (free
, canonical
);
2323 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
2324 for (i
= 0; i
< sals
.nelts
; i
++)
2326 if (canonical
[i
] != NULL
)
2327 make_cleanup (free
, canonical
[i
]);
2331 thread
= -1; /* No specific thread yet */
2333 /* Resolve all line numbers to PC's, and verify that conditions
2334 can be parsed, before setting any breakpoints. */
2335 for (i
= 0; i
< sals
.nelts
; i
++)
2337 char *tok
, *end_tok
;
2340 resolve_sal_pc (&sals
.sals
[i
]);
2346 while (*tok
== ' ' || *tok
== '\t')
2351 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2354 toklen
= end_tok
- tok
;
2356 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2358 tok
= cond_start
= end_tok
+ 1;
2359 cond
= parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
2362 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
2368 thread
= strtol (tok
, &tok
, 0);
2370 error ("Junk after thread keyword.");
2371 if (!valid_thread_id (thread
))
2372 error ("Unknown thread %d\n", thread
);
2375 error ("Junk at end of arguments.");
2380 int i
, target_resources_ok
;
2382 i
= hw_breakpoint_used_count ();
2383 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
2384 bp_hardware_breakpoint
, i
+ sals
.nelts
, 0);
2385 if (target_resources_ok
== 0)
2386 error ("No hardware breakpoint support in the target.");
2387 else if (target_resources_ok
< 0)
2388 error ("Hardware breakpoints used exceeds limit.");
2391 /* Remove the canonical strings from the cleanup, they are needed below. */
2392 if (canonical
!= (char **)NULL
)
2393 discard_cleanups (canonical_strings_chain
);
2395 /* Now set all the breakpoints. */
2396 for (i
= 0; i
< sals
.nelts
; i
++)
2401 describe_other_breakpoints (sal
.pc
);
2403 b
= set_raw_breakpoint (sal
);
2404 set_breakpoint_count (breakpoint_count
+ 1);
2405 b
->number
= breakpoint_count
;
2406 b
->type
= hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
;
2410 /* If a canonical line spec is needed use that instead of the
2412 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
2413 b
->addr_string
= canonical
[i
];
2414 else if (addr_start
)
2415 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
2417 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2419 b
->enable
= enabled
;
2420 b
->disposition
= tempflag
? delete : donttouch
;
2427 printf_filtered ("Multiple breakpoints were set.\n");
2428 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2430 do_cleanups (old_chain
);
2433 /* Helper function for break_command_1 and disassemble_command. */
2436 resolve_sal_pc (sal
)
2437 struct symtab_and_line
*sal
;
2441 if (sal
->pc
== 0 && sal
->symtab
!= 0)
2443 pc
= find_line_pc (sal
->symtab
, sal
->line
);
2445 error ("No line %d in file \"%s\".",
2446 sal
->line
, sal
->symtab
->filename
);
2451 #define BP_TEMPFLAG 1
2452 #define BP_HARDWAREFLAG 2
2454 break_command (arg
, from_tty
)
2458 break_command_1 (arg
, 0, from_tty
);
2462 tbreak_command (arg
, from_tty
)
2466 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
2470 hbreak_command (arg
, from_tty
)
2474 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
2478 thbreak_command (arg
, from_tty
)
2482 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
2486 /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write)
2489 watch_command_1 (arg
, accessflag
, from_tty
)
2494 struct breakpoint
*b
;
2495 struct symtab_and_line sal
;
2496 struct expression
*exp
;
2497 struct block
*exp_valid_block
;
2498 struct value
*val
, *mark
;
2499 FRAME frame
, prev_frame
;
2500 char *exp_start
= NULL
;
2501 char *exp_end
= NULL
;
2502 char *tok
, *end_tok
;
2504 char *cond_start
= NULL
;
2505 char *cond_end
= NULL
;
2506 struct expression
*cond
= NULL
;
2507 int i
, other_type_used
, target_resources_ok
;
2508 enum bptype bp_type
;
2515 /* Parse arguments. */
2516 innermost_block
= NULL
;
2518 exp
= parse_exp_1 (&arg
, 0, 0);
2520 exp_valid_block
= innermost_block
;
2521 mark
= value_mark ();
2522 val
= evaluate_expression (exp
);
2523 release_value (val
);
2524 if (VALUE_LAZY (val
))
2525 value_fetch_lazy (val
);
2528 while (*tok
== ' ' || *tok
== '\t')
2532 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2535 toklen
= end_tok
- tok
;
2536 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2538 tok
= cond_start
= end_tok
+ 1;
2539 cond
= parse_exp_1 (&tok
, 0, 0);
2543 error("Junk at end of command.");
2545 if (accessflag
== 1) bp_type
= bp_read_watchpoint
;
2546 else if (accessflag
== 2) bp_type
= bp_access_watchpoint
;
2547 else bp_type
= bp_hardware_watchpoint
;
2549 mem_cnt
= can_use_hardware_watchpoint (val
);
2550 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
2551 error ("Expression cannot be implemented with read/access watchpoint.");
2553 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
2554 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2555 bp_type
, i
+ mem_cnt
, other_type_used
);
2556 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
2557 error ("Target does not have this type of hardware watchpoint support.");
2558 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
2559 error ("Target resources have been allocated for other types of watchpoints.");
2562 /* Now set up the breakpoint. */
2563 b
= set_raw_breakpoint (sal
);
2564 set_breakpoint_count (breakpoint_count
+ 1);
2565 b
->number
= breakpoint_count
;
2566 b
->disposition
= donttouch
;
2568 b
->exp_valid_block
= exp_valid_block
;
2569 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
2573 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2577 frame
= block_innermost_frame (exp_valid_block
);
2580 prev_frame
= get_prev_frame (frame
);
2581 b
->watchpoint_frame
= FRAME_FP (frame
);
2584 b
->watchpoint_frame
= (CORE_ADDR
)0;
2586 if (mem_cnt
&& target_resources_ok
> 0)
2589 b
->type
= bp_watchpoint
;
2591 /* If the expression is "local", then set up a "watchpoint scope"
2592 breakpoint at the point where we've left the scope of the watchpoint
2594 if (innermost_block
)
2596 struct breakpoint
*scope_breakpoint
;
2597 struct symtab_and_line scope_sal
;
2601 scope_sal
.pc
= get_frame_pc (prev_frame
);
2602 scope_sal
.symtab
= NULL
;
2605 scope_breakpoint
= set_raw_breakpoint (scope_sal
);
2606 set_breakpoint_count (breakpoint_count
+ 1);
2607 scope_breakpoint
->number
= breakpoint_count
;
2609 scope_breakpoint
->type
= bp_watchpoint_scope
;
2610 scope_breakpoint
->enable
= enabled
;
2612 /* Automatically delete the breakpoint when it hits. */
2613 scope_breakpoint
->disposition
= delete;
2615 /* Only break in the proper frame (help with recursion). */
2616 scope_breakpoint
->frame
= prev_frame
->frame
;
2618 /* Set the address at which we will stop. */
2619 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
2621 /* The scope breakpoint is related to the watchpoint. We
2622 will need to act on them together. */
2623 b
->related_breakpoint
= scope_breakpoint
;
2626 value_free_to_mark (mark
);
2630 /* Return count of locations need to be watched and can be handled
2631 in hardware. If the watchpoint can not be handled
2632 in hardware return zero. */
2635 can_use_hardware_watchpoint (v
)
2638 int found_memory_cnt
= 0;
2640 /* Make sure all the intermediate values are in memory. Also make sure
2641 we found at least one memory expression. Guards against watch 0x12345,
2642 which is meaningless, but could cause errors if one tries to insert a
2643 hardware watchpoint for the constant expression. */
2644 for ( ; v
; v
= v
->next
)
2646 if (v
->lval
== lval_memory
)
2648 if (TYPE_LENGTH (VALUE_TYPE (v
)) <= REGISTER_SIZE
)
2651 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
2655 /* The expression itself looks suitable for using a hardware
2656 watchpoint, but give the target machine a chance to reject it. */
2657 return found_memory_cnt
;
2660 static void watch_command (arg
, from_tty
)
2664 watch_command_1 (arg
, 0, from_tty
);
2667 static void rwatch_command (arg
, from_tty
)
2671 watch_command_1 (arg
, 1, from_tty
);
2674 static void awatch_command (arg
, from_tty
)
2678 watch_command_1 (arg
, 2, from_tty
);
2683 * Helper routine for the until_command routine in infcmd.c. Here
2684 * because it uses the mechanisms of breakpoints.
2688 until_break_command (arg
, from_tty
)
2692 struct symtabs_and_lines sals
;
2693 struct symtab_and_line sal
;
2694 FRAME prev_frame
= get_prev_frame (selected_frame
);
2695 struct breakpoint
*breakpoint
;
2696 struct cleanup
*old_chain
;
2698 clear_proceed_status ();
2700 /* Set a breakpoint where the user wants it and at return from
2703 if (default_breakpoint_valid
)
2704 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2705 default_breakpoint_line
, (char ***)NULL
);
2707 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2709 if (sals
.nelts
!= 1)
2710 error ("Couldn't get information on specified line.");
2713 free ((PTR
)sals
.sals
); /* malloc'd, so freed */
2716 error ("Junk at end of arguments.");
2718 resolve_sal_pc (&sal
);
2720 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
2722 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
2724 /* Keep within the current frame */
2728 struct frame_info
*fi
;
2730 fi
= get_frame_info (prev_frame
);
2731 sal
= find_pc_line (fi
->pc
, 0);
2733 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
2734 make_cleanup(delete_breakpoint
, breakpoint
);
2737 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
2738 do_cleanups(old_chain
);
2742 /* These aren't used; I don't konw what they were for. */
2743 /* Set a breakpoint at the catch clause for NAME. */
2745 catch_breakpoint (name
)
2751 disable_catch_breakpoint ()
2756 delete_catch_breakpoint ()
2761 enable_catch_breakpoint ()
2768 struct sal_chain
*next
;
2769 struct symtab_and_line sal
;
2773 /* This isn't used; I don't know what it was for. */
2774 /* For each catch clause identified in ARGS, run FUNCTION
2775 with that clause as an argument. */
2776 static struct symtabs_and_lines
2777 map_catch_names (args
, function
)
2781 register char *p
= args
;
2783 struct symtabs_and_lines sals
;
2785 struct sal_chain
*sal_chain
= 0;
2789 error_no_arg ("one or more catch names");
2797 /* Don't swallow conditional part. */
2798 if (p1
[0] == 'i' && p1
[1] == 'f'
2799 && (p1
[2] == ' ' || p1
[2] == '\t'))
2805 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
2809 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
2810 error ("Arguments must be catch names.");
2816 struct sal_chain
*next
2817 = (struct sal_chain
*)alloca (sizeof (struct sal_chain
));
2818 next
->next
= sal_chain
;
2819 next
->sal
= get_catch_sal (p
);
2824 printf_unfiltered ("No catch clause for exception %s.\n", p
);
2829 while (*p
== ' ' || *p
== '\t') p
++;
2834 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2836 static struct symtabs_and_lines
2837 get_catch_sals (this_level_only
)
2838 int this_level_only
;
2840 register struct blockvector
*bl
;
2841 register struct block
*block
;
2842 int index
, have_default
= 0;
2843 struct frame_info
*fi
;
2845 struct symtabs_and_lines sals
;
2846 struct sal_chain
*sal_chain
= 0;
2847 char *blocks_searched
;
2849 /* Not sure whether an error message is always the correct response,
2850 but it's better than a core dump. */
2851 if (selected_frame
== NULL
)
2852 error ("No selected frame.");
2853 block
= get_frame_block (selected_frame
);
2854 fi
= get_frame_info (selected_frame
);
2861 error ("No symbol table info available.\n");
2863 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
2864 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2865 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2869 CORE_ADDR end
= BLOCK_END (block
) - 4;
2872 if (bl
!= blockvector_for_pc (end
, &index
))
2873 error ("blockvector blotch");
2874 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
2875 error ("blockvector botch");
2876 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
2879 /* Don't print out blocks that have gone by. */
2880 while (index
< last_index
2881 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
2884 while (index
< last_index
2885 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
2887 if (blocks_searched
[index
] == 0)
2889 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
2892 register struct symbol
*sym
;
2894 nsyms
= BLOCK_NSYMS (b
);
2896 for (i
= 0; i
< nsyms
; i
++)
2898 sym
= BLOCK_SYM (b
, i
);
2899 if (STREQ (SYMBOL_NAME (sym
), "default"))
2905 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
2907 struct sal_chain
*next
= (struct sal_chain
*)
2908 alloca (sizeof (struct sal_chain
));
2909 next
->next
= sal_chain
;
2910 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
2914 blocks_searched
[index
] = 1;
2920 if (sal_chain
&& this_level_only
)
2923 /* After handling the function's top-level block, stop.
2924 Don't continue to its superblock, the block of
2925 per-file symbols. */
2926 if (BLOCK_FUNCTION (block
))
2928 block
= BLOCK_SUPERBLOCK (block
);
2933 struct sal_chain
*tmp_chain
;
2935 /* Count the number of entries. */
2936 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
2937 tmp_chain
= tmp_chain
->next
)
2941 sals
.sals
= (struct symtab_and_line
*)
2942 xmalloc (index
* sizeof (struct symtab_and_line
));
2943 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
2944 sals
.sals
[index
] = sal_chain
->sal
;
2950 /* Commands to deal with catching exceptions. */
2953 catch_command_1 (arg
, tempflag
, from_tty
)
2958 /* First, translate ARG into something we can deal with in terms
2961 struct symtabs_and_lines sals
;
2962 struct symtab_and_line sal
;
2963 register struct expression
*cond
= 0;
2964 register struct breakpoint
*b
;
2968 sal
.line
= sal
.pc
= sal
.end
= 0;
2971 /* If no arg given, or if first arg is 'if ', all active catch clauses
2972 are breakpointed. */
2974 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2975 && (arg
[2] == ' ' || arg
[2] == '\t')))
2977 /* Grab all active catch clauses. */
2978 sals
= get_catch_sals (0);
2982 /* Grab selected catch clauses. */
2983 error ("catch NAME not implemented");
2985 /* This isn't used; I don't know what it was for. */
2986 sals
= map_catch_names (arg
, catch_breakpoint
);
2994 for (i
= 0; i
< sals
.nelts
; i
++)
2996 resolve_sal_pc (&sals
.sals
[i
]);
3000 if (arg
[0] == 'i' && arg
[1] == 'f'
3001 && (arg
[2] == ' ' || arg
[2] == '\t'))
3002 cond
= parse_exp_1 ((arg
+= 2, &arg
),
3003 block_for_pc (sals
.sals
[i
].pc
), 0);
3005 error ("Junk at end of arguments.");
3010 for (i
= 0; i
< sals
.nelts
; i
++)
3015 describe_other_breakpoints (sal
.pc
);
3017 b
= set_raw_breakpoint (sal
);
3018 set_breakpoint_count (breakpoint_count
+ 1);
3019 b
->number
= breakpoint_count
;
3020 b
->type
= bp_breakpoint
;
3022 b
->enable
= enabled
;
3023 b
->disposition
= tempflag
? delete : donttouch
;
3030 printf_unfiltered ("Multiple breakpoints were set.\n");
3031 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
3033 free ((PTR
)sals
.sals
);
3037 /* These aren't used; I don't know what they were for. */
3038 /* Disable breakpoints on all catch clauses described in ARGS. */
3040 disable_catch (args
)
3043 /* Map the disable command to catch clauses described in ARGS. */
3046 /* Enable breakpoints on all catch clauses described in ARGS. */
3051 /* Map the disable command to catch clauses described in ARGS. */
3054 /* Delete breakpoints on all catch clauses in the active scope. */
3059 /* Map the delete command to catch clauses described in ARGS. */
3064 catch_command (arg
, from_tty
)
3068 catch_command_1 (arg
, 0, from_tty
);
3072 clear_command (arg
, from_tty
)
3076 register struct breakpoint
*b
, *b1
;
3077 struct symtabs_and_lines sals
;
3078 struct symtab_and_line sal
;
3079 register struct breakpoint
*found
;
3084 sals
= decode_line_spec (arg
, 1);
3088 sals
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
3089 sal
.line
= default_breakpoint_line
;
3090 sal
.symtab
= default_breakpoint_symtab
;
3092 if (sal
.symtab
== 0)
3093 error ("No source file specified.");
3099 for (i
= 0; i
< sals
.nelts
; i
++)
3101 /* If exact pc given, clear bpts at that pc.
3102 But if sal.pc is zero, clear all bpts on specified line. */
3104 found
= (struct breakpoint
*) 0;
3105 while (breakpoint_chain
3107 ? breakpoint_chain
->address
== sal
.pc
3108 : (breakpoint_chain
->source_file
!= NULL
3109 && sal
.symtab
!= NULL
3110 && STREQ (breakpoint_chain
->source_file
,
3111 sal
.symtab
->filename
)
3112 && breakpoint_chain
->line_number
== sal
.line
)))
3114 b1
= breakpoint_chain
;
3115 breakpoint_chain
= b1
->next
;
3122 && b
->next
->type
!= bp_watchpoint
3123 && b
->next
->type
!= bp_hardware_watchpoint
3124 && b
->next
->type
!= bp_read_watchpoint
3125 && b
->next
->type
!= bp_access_watchpoint
3127 ? b
->next
->address
== sal
.pc
3128 : (b
->next
->source_file
!= NULL
3129 && sal
.symtab
!= NULL
3130 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
3131 && b
->next
->line_number
== sal
.line
)))
3142 error ("No breakpoint at %s.", arg
);
3144 error ("No breakpoint at this line.");
3147 if (found
->next
) from_tty
= 1; /* Always report if deleted more than one */
3148 if (from_tty
) printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
3149 breakpoints_changed ();
3152 if (from_tty
) printf_unfiltered ("%d ", found
->number
);
3154 delete_breakpoint (found
);
3157 if (from_tty
) putchar_unfiltered ('\n');
3159 free ((PTR
)sals
.sals
);
3162 /* Delete breakpoint in BS if they are `delete' breakpoints.
3163 This is called after any breakpoint is hit, or after errors. */
3166 breakpoint_auto_delete (bs
)
3169 for (; bs
; bs
= bs
->next
)
3170 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== delete
3172 delete_breakpoint (bs
->breakpoint_at
);
3175 /* Delete a breakpoint and clean up all traces of it in the data structures. */
3178 delete_breakpoint (bpt
)
3179 struct breakpoint
*bpt
;
3181 register struct breakpoint
*b
;
3185 remove_breakpoint (bpt
);
3187 if (breakpoint_chain
== bpt
)
3188 breakpoint_chain
= bpt
->next
;
3193 b
->next
= bpt
->next
;
3197 check_duplicates (bpt
->address
);
3198 /* If this breakpoint was inserted, and there is another breakpoint
3199 at the same address, we need to insert the other breakpoint. */
3201 && bpt
->type
!= bp_hardware_watchpoint
3202 && bpt
->type
!= bp_read_watchpoint
3203 && bpt
->type
!= bp_access_watchpoint
)
3206 if (b
->address
== bpt
->address
3208 && b
->enable
!= disabled
)
3211 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
3214 target_terminal_ours_for_output ();
3215 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
3216 memory_error (val
, b
->address
); /* which bombs us out */
3223 free_command_lines (&bpt
->commands
);
3226 if (bpt
->cond_string
!= NULL
)
3227 free (bpt
->cond_string
);
3228 if (bpt
->addr_string
!= NULL
)
3229 free (bpt
->addr_string
);
3230 if (bpt
->exp_string
!= NULL
)
3231 free (bpt
->exp_string
);
3232 if (bpt
->source_file
!= NULL
)
3233 free (bpt
->source_file
);
3235 breakpoints_changed ();
3237 /* Be sure no bpstat's are pointing at it after it's been freed. */
3238 /* FIXME, how can we find all bpstat's?
3239 We just check stop_bpstat for now. */
3240 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
3241 if (bs
->breakpoint_at
== bpt
)
3242 bs
->breakpoint_at
= NULL
;
3247 delete_command (arg
, from_tty
)
3254 /* Ask user only if there are some breakpoints to delete. */
3256 || (breakpoint_chain
&& query ("Delete all breakpoints? ", 0, 0)))
3258 /* No arg; clear all breakpoints. */
3259 while (breakpoint_chain
)
3260 delete_breakpoint (breakpoint_chain
);
3264 map_breakpoint_numbers (arg
, delete_breakpoint
);
3267 /* Reset a breakpoint given it's struct breakpoint * BINT.
3268 The value we return ends up being the return value from catch_errors.
3269 Unused in this case. */
3272 breakpoint_re_set_one (bint
)
3275 struct breakpoint
*b
= (struct breakpoint
*)bint
; /* get past catch_errs */
3278 struct symtabs_and_lines sals
;
3280 enum enable save_enable
;
3285 case bp_hardware_breakpoint
:
3286 if (b
->addr_string
== NULL
)
3288 /* Anything without a string can't be re-set. */
3289 delete_breakpoint (b
);
3292 /* In case we have a problem, disable this breakpoint. We'll restore
3293 its status if we succeed. */
3294 save_enable
= b
->enable
;
3295 b
->enable
= disabled
;
3298 sals
= decode_line_1 (&s
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
3299 for (i
= 0; i
< sals
.nelts
; i
++)
3301 resolve_sal_pc (&sals
.sals
[i
]);
3303 /* Reparse conditions, they might contain references to the
3305 if (b
->cond_string
!= NULL
)
3309 free ((PTR
)b
->cond
);
3310 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
3313 /* We need to re-set the breakpoint if the address changes...*/
3314 if (b
->address
!= sals
.sals
[i
].pc
3315 /* ...or new and old breakpoints both have source files, and
3316 the source file name or the line number changes... */
3317 || (b
->source_file
!= NULL
3318 && sals
.sals
[i
].symtab
!= NULL
3319 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
3320 || b
->line_number
!= sals
.sals
[i
].line
)
3322 /* ...or we switch between having a source file and not having
3324 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
3327 if (b
->source_file
!= NULL
)
3328 free (b
->source_file
);
3329 if (sals
.sals
[i
].symtab
== NULL
)
3330 b
->source_file
= NULL
;
3333 savestring (sals
.sals
[i
].symtab
->filename
,
3334 strlen (sals
.sals
[i
].symtab
->filename
));
3335 b
->line_number
= sals
.sals
[i
].line
;
3336 b
->address
= sals
.sals
[i
].pc
;
3338 check_duplicates (b
->address
);
3342 /* Might be better to do this just once per breakpoint_re_set,
3343 rather than once for every breakpoint. */
3344 breakpoints_changed ();
3346 b
->enable
= save_enable
; /* Restore it, this worked. */
3348 free ((PTR
)sals
.sals
);
3352 case bp_hardware_watchpoint
:
3353 case bp_read_watchpoint
:
3354 case bp_access_watchpoint
:
3355 innermost_block
= NULL
;
3356 /* The issue arises of what context to evaluate this in. The same
3357 one as when it was set, but what does that mean when symbols have
3358 been re-read? We could save the filename and functionname, but
3359 if the context is more local than that, the best we could do would
3360 be something like how many levels deep and which index at that
3361 particular level, but that's going to be less stable than filenames
3362 or functionnames. */
3363 /* So for now, just use a global context. */
3364 b
->exp
= parse_expression (b
->exp_string
);
3365 b
->exp_valid_block
= innermost_block
;
3366 mark
= value_mark ();
3367 b
->val
= evaluate_expression (b
->exp
);
3368 release_value (b
->val
);
3369 if (VALUE_LAZY (b
->val
))
3370 value_fetch_lazy (b
->val
);
3372 if (b
->cond_string
!= NULL
)
3375 b
->cond
= parse_exp_1 (&s
, (struct block
*)0, 0);
3377 if (b
->enable
== enabled
)
3379 value_free_to_mark (mark
);
3383 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
3388 case bp_longjmp_resume
:
3389 case bp_watchpoint_scope
:
3391 delete_breakpoint (b
);
3398 /* Re-set all breakpoints after symbols have been re-loaded. */
3400 breakpoint_re_set ()
3402 struct breakpoint
*b
, *temp
;
3403 static char message1
[] = "Error in re-setting breakpoint %d:\n";
3404 char message
[sizeof (message1
) + 30 /* slop */];
3406 ALL_BREAKPOINTS_SAFE (b
, temp
)
3408 sprintf (message
, message1
, b
->number
); /* Format possible error msg */
3409 catch_errors (breakpoint_re_set_one
, (char *) b
, message
,
3413 create_longjmp_breakpoint("longjmp");
3414 create_longjmp_breakpoint("_longjmp");
3415 create_longjmp_breakpoint("siglongjmp");
3416 create_longjmp_breakpoint(NULL
);
3419 /* Took this out (temporaliy at least), since it produces an extra
3420 blank line at startup. This messes up the gdbtests. -PB */
3421 /* Blank line to finish off all those mention() messages we just printed. */
3422 printf_filtered ("\n");
3426 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3427 If from_tty is nonzero, it prints a message to that effect,
3428 which ends with a period (no newline). */
3431 set_ignore_count (bptnum
, count
, from_tty
)
3432 int bptnum
, count
, from_tty
;
3434 register struct breakpoint
*b
;
3440 if (b
->number
== bptnum
)
3442 b
->ignore_count
= count
;
3445 else if (count
== 0)
3446 printf_filtered ("Will stop next time breakpoint %d is reached.",
3448 else if (count
== 1)
3449 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3452 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3454 breakpoints_changed ();
3458 error ("No breakpoint number %d.", bptnum
);
3461 /* Clear the ignore counts of all breakpoints. */
3463 breakpoint_clear_ignore_counts ()
3465 struct breakpoint
*b
;
3468 b
->ignore_count
= 0;
3471 /* Command to set ignore-count of breakpoint N to COUNT. */
3474 ignore_command (args
, from_tty
)
3482 error_no_arg ("a breakpoint number");
3484 num
= get_number (&p
);
3487 error ("Second argument (specified ignore-count) is missing.");
3489 set_ignore_count (num
,
3490 longest_to_int (value_as_long (parse_and_eval (p
))),
3492 printf_filtered ("\n");
3493 breakpoints_changed ();
3496 /* Call FUNCTION on each of the breakpoints
3497 whose numbers are given in ARGS. */
3500 map_breakpoint_numbers (args
, function
)
3502 void (*function
) PARAMS ((struct breakpoint
*));
3504 register char *p
= args
;
3507 register struct breakpoint
*b
;
3510 error_no_arg ("one or more breakpoint numbers");
3516 num
= get_number (&p1
);
3519 if (b
->number
== num
)
3521 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
3523 if (related_breakpoint
)
3524 function (related_breakpoint
);
3527 printf_unfiltered ("No breakpoint number %d.\n", num
);
3534 enable_breakpoint (bpt
)
3535 struct breakpoint
*bpt
;
3537 FRAME save_selected_frame
= NULL
;
3538 int save_selected_frame_level
= -1;
3539 int target_resources_ok
, other_type_used
;
3542 if (bpt
->type
== bp_hardware_breakpoint
)
3545 i
= hw_breakpoint_used_count();
3546 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3547 bp_hardware_breakpoint
, i
+1, 0);
3548 if (target_resources_ok
== 0)
3549 error ("No hardware breakpoint support in the target.");
3550 else if (target_resources_ok
< 0)
3551 error ("Hardware breakpoints used exceeds limit.");
3553 bpt
->enable
= enabled
;
3554 breakpoints_changed ();
3555 check_duplicates (bpt
->address
);
3557 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3558 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3560 if (bpt
->exp_valid_block
!= NULL
)
3562 FRAME fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3566 Cannot enable watchpoint %d because the block in which its expression\n\
3567 is valid is not currently in scope.\n", bpt
->number
);
3568 bpt
->enable
= disabled
;
3572 save_selected_frame
= selected_frame
;
3573 save_selected_frame_level
= selected_frame_level
;
3574 select_frame (fr
, -1);
3577 value_free (bpt
->val
);
3578 mark
= value_mark ();
3579 bpt
->val
= evaluate_expression (bpt
->exp
);
3580 release_value (bpt
->val
);
3581 if (VALUE_LAZY (bpt
->val
))
3582 value_fetch_lazy (bpt
->val
);
3584 if (bpt
->type
== bp_hardware_watchpoint
||
3585 bpt
->type
== bp_read_watchpoint
||
3586 bpt
->type
== bp_access_watchpoint
)
3588 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3589 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
3591 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3592 bpt
->type
, i
+ mem_cnt
, other_type_used
);
3593 /* we can consider of type is bp_hardware_watchpoint, convert to
3594 bp_watchpoint in the following condition */
3595 if (target_resources_ok
< 0)
3598 Cannot enable watchpoint %d because target watch resources\n\
3599 have been allocated for other watchpoints.\n", bpt
->number
);
3600 bpt
->enable
= disabled
;
3601 value_free_to_mark (mark
);
3606 if (save_selected_frame_level
>= 0)
3607 select_frame (save_selected_frame
, save_selected_frame_level
);
3608 value_free_to_mark (mark
);
3614 enable_command (args
, from_tty
)
3618 struct breakpoint
*bpt
;
3620 ALL_BREAKPOINTS (bpt
)
3624 case bp_hardware_breakpoint
:
3626 case bp_hardware_watchpoint
:
3627 case bp_read_watchpoint
:
3628 case bp_access_watchpoint
:
3629 enable_breakpoint (bpt
);
3634 map_breakpoint_numbers (args
, enable_breakpoint
);
3638 disable_breakpoint (bpt
)
3639 struct breakpoint
*bpt
;
3641 /* Never disable a watchpoint scope breakpoint; we want to
3642 hit them when we leave scope so we can delete both the
3643 watchpoint and its scope breakpoint at that time. */
3644 if (bpt
->type
== bp_watchpoint_scope
)
3647 bpt
->enable
= disabled
;
3649 breakpoints_changed ();
3651 check_duplicates (bpt
->address
);
3656 disable_command (args
, from_tty
)
3660 register 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 disable_breakpoint (bpt
);
3676 map_breakpoint_numbers (args
, disable_breakpoint
);
3680 enable_once_breakpoint (bpt
)
3681 struct breakpoint
*bpt
;
3683 FRAME save_selected_frame
= NULL
;
3684 int save_selected_frame_level
= -1;
3685 int target_resources_ok
, other_type_used
;
3688 if (bpt
->type
== bp_hardware_breakpoint
)
3691 i
= hw_breakpoint_used_count();
3692 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3693 bp_hardware_breakpoint
, i
+1, 0);
3694 if (target_resources_ok
== 0)
3695 error ("No hardware breakpoint support in the target.");
3696 else if (target_resources_ok
< 0)
3697 error ("Hardware breakpoints used exceeds limit.");
3700 bpt
->enable
= enabled
;
3701 bpt
->disposition
= disable
;
3702 check_duplicates (bpt
->address
);
3703 breakpoints_changed ();
3705 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3706 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3708 if (bpt
->exp_valid_block
!= NULL
)
3710 FRAME fr
= find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3714 Cannot enable watchpoint %d because the block in which its expression\n\
3715 is valid is not currently in scope.\n", bpt
->number
);
3716 bpt
->enable
= disabled
;
3720 save_selected_frame
= selected_frame
;
3721 save_selected_frame_level
= selected_frame_level
;
3722 select_frame (fr
, -1);
3725 value_free (bpt
->val
);
3726 mark
= value_mark ();
3727 bpt
->val
= evaluate_expression (bpt
->exp
);
3728 release_value (bpt
->val
);
3729 if (VALUE_LAZY (bpt
->val
))
3730 value_fetch_lazy (bpt
->val
);
3732 if (bpt
->type
== bp_hardware_watchpoint
||
3733 bpt
->type
== bp_read_watchpoint
||
3734 bpt
->type
== bp_access_watchpoint
)
3736 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3737 int mem_cnt
= can_use_hardware_watchpoint(bpt
->val
);
3738 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3739 bpt
->type
, i
+mem_cnt
, other_type_used
);
3740 /* we can consider of type is bp_hardware_watchpoint, convert to
3741 bp_watchpoint in the following condition */
3742 if (target_resources_ok
< 0)
3745 Cannot enable watchpoint %d because target watch resources\n\
3746 have been allocated for other watchpoints.\n", bpt
->number
);
3747 bpt
->enable
= disabled
;
3748 value_free_to_mark (mark
);
3752 if (save_selected_frame_level
>= 0)
3753 select_frame (save_selected_frame
, save_selected_frame_level
);
3754 value_free_to_mark (mark
);
3760 enable_once_command (args
, from_tty
)
3764 map_breakpoint_numbers (args
, enable_once_breakpoint
);
3768 enable_delete_breakpoint (bpt
)
3769 struct breakpoint
*bpt
;
3771 bpt
->enable
= enabled
;
3772 bpt
->disposition
= delete;
3774 check_duplicates (bpt
->address
);
3775 breakpoints_changed ();
3780 enable_delete_command (args
, from_tty
)
3784 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
3788 * Use default_breakpoint_'s, or nothing if they aren't valid.
3790 struct symtabs_and_lines
3791 decode_line_spec_1 (string
, funfirstline
)
3795 struct symtabs_and_lines sals
;
3797 error ("Empty line specification.");
3798 if (default_breakpoint_valid
)
3799 sals
= decode_line_1 (&string
, funfirstline
,
3800 default_breakpoint_symtab
, default_breakpoint_line
,
3803 sals
= decode_line_1 (&string
, funfirstline
,
3804 (struct symtab
*)NULL
, 0, (char ***)NULL
);
3806 error ("Junk at end of line specification: %s", string
);
3811 _initialize_breakpoint ()
3813 breakpoint_chain
= 0;
3814 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3815 before a breakpoint is set. */
3816 breakpoint_count
= 0;
3818 add_com ("ignore", class_breakpoint
, ignore_command
,
3819 "Set ignore-count of breakpoint number N to COUNT.\n\
3820 Usage is `ignore N COUNT'.");
3822 add_com ("commands", class_breakpoint
, commands_command
,
3823 "Set commands to be executed when a breakpoint is hit.\n\
3824 Give breakpoint number as argument after \"commands\".\n\
3825 With no argument, the targeted breakpoint is the last one set.\n\
3826 The commands themselves follow starting on the next line.\n\
3827 Type a line containing \"end\" to indicate the end of them.\n\
3828 Give \"silent\" as the first line to make the breakpoint silent;\n\
3829 then no output is printed when it is hit, except what the commands print.");
3831 add_com ("condition", class_breakpoint
, condition_command
,
3832 "Specify breakpoint number N to break only if COND is true.\n\
3833 Usage is `condition N COND', where N is an integer and COND is an\n\
3834 expression to be evaluated whenever breakpoint N is reached. ");
3836 add_com ("tbreak", class_breakpoint
, tbreak_command
,
3837 "Set a temporary breakpoint. Args like \"break\" command.\n\
3838 Like \"break\" except the breakpoint is only temporary,\n\
3839 so it will be deleted when hit. Equivalent to \"break\" followed\n\
3840 by using \"enable delete\" on the breakpoint number.");
3842 add_com ("hbreak", class_breakpoint
, hbreak_command
,
3843 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
3844 Like \"break\" except the breakpoint requires hardware support,\n\
3845 some target hardware may not have this support.");
3847 add_com ("thbreak", class_breakpoint
, thbreak_command
,
3848 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
3849 Like \"hbreak\" except the breakpoint is only temporary,\n\
3850 so it will be deleted when hit.");
3852 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
3853 "Enable some breakpoints.\n\
3854 Give breakpoint numbers (separated by spaces) as arguments.\n\
3855 With no subcommand, breakpoints are enabled until you command otherwise.\n\
3856 This is used to cancel the effect of the \"disable\" command.\n\
3857 With a subcommand you can enable temporarily.",
3858 &enablelist
, "enable ", 1, &cmdlist
);
3860 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
3861 "Enable some breakpoints.\n\
3862 Give breakpoint numbers (separated by spaces) as arguments.\n\
3863 This is used to cancel the effect of the \"disable\" command.\n\
3864 May be abbreviated to simply \"enable\".\n",
3865 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
3867 add_cmd ("once", no_class
, enable_once_command
,
3868 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3869 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3872 add_cmd ("delete", no_class
, enable_delete_command
,
3873 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3874 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3877 add_cmd ("delete", no_class
, enable_delete_command
,
3878 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
3879 If a breakpoint is hit while enabled in this fashion, it is deleted.",
3882 add_cmd ("once", no_class
, enable_once_command
,
3883 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
3884 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
3887 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
3888 "Disable some breakpoints.\n\
3889 Arguments are breakpoint numbers with spaces in between.\n\
3890 To disable all breakpoints, give no argument.\n\
3891 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
3892 &disablelist
, "disable ", 1, &cmdlist
);
3893 add_com_alias ("dis", "disable", class_breakpoint
, 1);
3894 add_com_alias ("disa", "disable", class_breakpoint
, 1);
3896 add_cmd ("breakpoints", class_alias
, disable_command
,
3897 "Disable some breakpoints.\n\
3898 Arguments are breakpoint numbers with spaces in between.\n\
3899 To disable all breakpoints, give no argument.\n\
3900 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
3901 This command may be abbreviated \"disable\".",
3904 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
3905 "Delete some breakpoints or auto-display expressions.\n\
3906 Arguments are breakpoint numbers with spaces in between.\n\
3907 To delete all breakpoints, give no argument.\n\
3909 Also a prefix command for deletion of other GDB objects.\n\
3910 The \"unset\" command is also an alias for \"delete\".",
3911 &deletelist
, "delete ", 1, &cmdlist
);
3912 add_com_alias ("d", "delete", class_breakpoint
, 1);
3914 add_cmd ("breakpoints", class_alias
, delete_command
,
3915 "Delete some breakpoints or auto-display expressions.\n\
3916 Arguments are breakpoint numbers with spaces in between.\n\
3917 To delete all breakpoints, give no argument.\n\
3918 This command may be abbreviated \"delete\".",
3921 add_com ("clear", class_breakpoint
, clear_command
,
3922 "Clear breakpoint at specified line or function.\n\
3923 Argument may be line number, function name, or \"*\" and an address.\n\
3924 If line number is specified, all breakpoints in that line are cleared.\n\
3925 If function is specified, breakpoints at beginning of function are cleared.\n\
3926 If an address is specified, breakpoints at that address are cleared.\n\n\
3927 With no argument, clears all breakpoints in the line that the selected frame\n\
3930 See also the \"delete\" command which clears breakpoints by number.");
3932 add_com ("break", class_breakpoint
, break_command
,
3933 "Set breakpoint at specified line or function.\n\
3934 Argument may be line number, function name, or \"*\" and an address.\n\
3935 If line number is specified, break at start of code for that line.\n\
3936 If function is specified, break at start of code for that function.\n\
3937 If an address is specified, break at that exact address.\n\
3938 With no arg, uses current execution address of selected stack frame.\n\
3939 This is useful for breaking on return to a stack frame.\n\
3941 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
3943 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3944 add_com_alias ("b", "break", class_run
, 1);
3945 add_com_alias ("br", "break", class_run
, 1);
3946 add_com_alias ("bre", "break", class_run
, 1);
3947 add_com_alias ("brea", "break", class_run
, 1);
3949 add_info ("breakpoints", breakpoints_info
,
3950 "Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
3951 The \"Type\" column indicates one of:\n\
3952 \tbreakpoint - normal breakpoint\n\
3953 \twatchpoint - watchpoint\n\
3954 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3955 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3956 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3957 address and file/line number respectively.\n\n\
3958 Convenience variable \"$_\" and default examine address for \"x\"\n\
3959 are set to the address of the last breakpoint listed.\n\n\
3960 Convenience variable \"$bpnum\" contains the number of the last\n\
3963 #if MAINTENANCE_CMDS
3965 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
3966 "Status of all breakpoints, or breakpoint number NUMBER.\n\
3967 The \"Type\" column indicates one of:\n\
3968 \tbreakpoint - normal breakpoint\n\
3969 \twatchpoint - watchpoint\n\
3970 \tlongjmp - internal breakpoint used to step through longjmp()\n\
3971 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
3972 \tuntil - internal breakpoint used by the \"until\" command\n\
3973 \tfinish - internal breakpoint used by the \"finish\" command\n\
3974 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
3975 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
3976 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
3977 address and file/line number respectively.\n\n\
3978 Convenience variable \"$_\" and default examine address for \"x\"\n\
3979 are set to the address of the last breakpoint listed.\n\n\
3980 Convenience variable \"$bpnum\" contains the number of the last\n\
3982 &maintenanceinfolist
);
3984 #endif /* MAINTENANCE_CMDS */
3986 add_com ("catch", class_breakpoint
, catch_command
,
3987 "Set breakpoints to catch exceptions that are raised.\n\
3988 Argument may be a single exception to catch, multiple exceptions\n\
3989 to catch, or the default exception \"default\". If no arguments\n\
3990 are given, breakpoints are set at all exception handlers catch clauses\n\
3991 within the current scope.\n\
3993 A condition specified for the catch applies to all breakpoints set\n\
3994 with this command\n\
3996 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
3998 add_com ("watch", class_breakpoint
, watch_command
,
3999 "Set a watchpoint for an expression.\n\
4000 A watchpoint stops execution of your program whenever the value of\n\
4001 an expression changes.");
4003 add_com ("rwatch", class_breakpoint
, rwatch_command
,
4004 "Set a read watchpoint for an expression.\n\
4005 A watchpoint stops execution of your program whenever the value of\n\
4006 an expression is read.");
4008 add_com ("awatch", class_breakpoint
, awatch_command
,
4009 "Set a watchpoint for an expression.\n\
4010 A watchpoint stops execution of your program whenever the value of\n\
4011 an expression is either read or written.");
4013 add_info ("watchpoints", breakpoints_info
,
4014 "Synonym for ``info breakpoints''.");
4018 /* OK, when we call objfile_relocate, we need to relocate breakpoints
4019 too. breakpoint_re_set is not a good choice--for example, if
4020 addr_string contains just a line number without a file name the
4021 breakpoint might get set in a different file. In general, there is
4022 no need to go all the way back to the user's string (though this might
4023 work if some effort were made to canonicalize it), since symtabs and
4024 everything except addresses are still valid.
4026 Probably the best way to solve this is to have each breakpoint save
4027 the objfile and the section number that was used to set it (if set
4028 by "*addr", probably it is best to use find_pc_line to get a symtab
4029 and use the objfile and block_line_section for that symtab). Then
4030 objfile_relocate can call fixup_breakpoints with the objfile and
4031 the new_offsets, and it can relocate only the appropriate breakpoints. */
4033 #ifdef IBM6000_TARGET
4034 /* But for now, just kludge it based on the concept that before an
4035 objfile is relocated the breakpoint is below 0x10000000, and afterwards
4036 it is higher, so that way we only relocate each breakpoint once. */
4039 fixup_breakpoints (low
, high
, delta
)
4044 struct breakpoint
*b
;
4048 if (b
->address
>= low
&& b
->address
<= high
)
4049 b
->address
+= delta
;