1 /* Everything about breakpoints, for GDB.
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
27 #include "expression.h"
36 #include "gdb_string.h"
40 /* local function prototypes */
43 catch_command_1
PARAMS ((char *, int, int));
46 enable_delete_command
PARAMS ((char *, int));
49 enable_delete_breakpoint
PARAMS ((struct breakpoint
*));
52 enable_once_command
PARAMS ((char *, int));
55 enable_once_breakpoint
PARAMS ((struct breakpoint
*));
58 disable_command
PARAMS ((char *, int));
61 enable_command
PARAMS ((char *, int));
64 map_breakpoint_numbers
PARAMS ((char *, void (*)(struct breakpoint
*)));
67 ignore_command
PARAMS ((char *, int));
70 breakpoint_re_set_one
PARAMS ((char *));
73 delete_command
PARAMS ((char *, int));
76 clear_command
PARAMS ((char *, int));
79 catch_command
PARAMS ((char *, int));
81 static struct symtabs_and_lines
82 get_catch_sals
PARAMS ((int));
85 watch_command
PARAMS ((char *, int));
88 can_use_hardware_watchpoint
PARAMS ((struct value
*));
91 tbreak_command
PARAMS ((char *, int));
94 break_command_1
PARAMS ((char *, int, int));
97 mention
PARAMS ((struct breakpoint
*));
99 static struct breakpoint
*
100 set_raw_breakpoint
PARAMS ((struct symtab_and_line
));
103 check_duplicates
PARAMS ((CORE_ADDR
));
106 describe_other_breakpoints
PARAMS ((CORE_ADDR
));
109 breakpoints_info
PARAMS ((char *, int));
112 breakpoint_1
PARAMS ((int, int));
115 bpstat_alloc
PARAMS ((struct breakpoint
*, bpstat
));
118 breakpoint_cond_eval
PARAMS ((char *));
121 cleanup_executing_breakpoints
PARAMS ((int));
124 commands_command
PARAMS ((char *, int));
127 condition_command
PARAMS ((char *, int));
130 get_number
PARAMS ((char **));
133 set_breakpoint_count
PARAMS ((int));
136 remove_breakpoint
PARAMS ((struct breakpoint
*));
138 extern int addressprint
; /* Print machine addresses? */
140 /* Are we executing breakpoint commands? */
141 static int executing_breakpoint_commands
;
143 /* Walk the following statement or block through all breakpoints.
144 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
147 #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next)
149 #define ALL_BREAKPOINTS_SAFE(b,tmp) \
150 for (b = breakpoint_chain; \
151 b? (tmp=b->next, 1): 0; \
154 /* True if breakpoint hit counts should be displayed in breakpoint info. */
156 int show_breakpoint_hit_counts
= 1;
158 /* Chain of all breakpoints defined. */
160 struct breakpoint
*breakpoint_chain
;
162 /* Number of last breakpoint made. */
164 static int breakpoint_count
;
166 /* Set breakpoint count to NUM. */
169 set_breakpoint_count (num
)
172 breakpoint_count
= num
;
173 set_internalvar (lookup_internalvar ("bpnum"),
174 value_from_longest (builtin_type_int
, (LONGEST
) num
));
177 /* Used in run_command to zero the hit count when a new run starts. */
180 clear_breakpoint_hit_counts ()
182 struct breakpoint
*b
;
188 /* Default address, symtab and line to put a breakpoint at
189 for "break" command with no arg.
190 if default_breakpoint_valid is zero, the other three are
191 not valid, and "break" with no arg is an error.
193 This set by print_stack_frame, which calls set_default_breakpoint. */
195 int default_breakpoint_valid
;
196 CORE_ADDR default_breakpoint_address
;
197 struct symtab
*default_breakpoint_symtab
;
198 int default_breakpoint_line
;
200 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
201 Advance *PP after the string and any trailing whitespace.
203 Currently the string can either be a number or "$" followed by the name
204 of a convenience variable. Making it an expression wouldn't work well
205 for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */
214 /* Empty line means refer to the last breakpoint. */
215 return breakpoint_count
;
218 /* Make a copy of the name, so we can null-terminate it
219 to pass to lookup_internalvar(). */
224 while (isalnum (*p
) || *p
== '_')
226 varname
= (char *) alloca (p
- start
+ 1);
227 strncpy (varname
, start
, p
- start
);
228 varname
[p
- start
] = '\0';
229 val
= value_of_internalvar (lookup_internalvar (varname
));
230 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
232 "Convenience variables used to specify breakpoints must have integer values."
234 retval
= (int) value_as_long (val
);
240 while (*p
>= '0' && *p
<= '9')
243 /* There is no number here. (e.g. "cond a == b"). */
244 error_no_arg ("breakpoint number");
247 if (!(isspace (*p
) || *p
== '\0'))
248 error ("breakpoint number expected");
255 /* condition N EXP -- set break condition of breakpoint N to EXP. */
258 condition_command (arg
, from_tty
)
262 register struct breakpoint
*b
;
267 error_no_arg ("breakpoint number");
270 bnum
= get_number (&p
);
273 if (b
->number
== bnum
)
280 if (b
->cond_string
!= NULL
)
281 free ((PTR
)b
->cond_string
);
286 b
->cond_string
= NULL
;
288 printf_filtered ("Breakpoint %d now unconditional.\n", bnum
);
293 /* I don't know if it matters whether this is the string the user
294 typed in or the decompiled expression. */
295 b
->cond_string
= savestring (arg
, strlen (arg
));
296 b
->cond
= parse_exp_1 (&arg
, block_for_pc (b
->address
), 0);
298 error ("Junk at end of expression");
300 breakpoints_changed ();
304 error ("No breakpoint number %d.", bnum
);
309 commands_command (arg
, from_tty
)
313 register struct breakpoint
*b
;
316 struct command_line
*l
;
318 /* If we allowed this, we would have problems with when to
319 free the storage, if we change the commands currently
322 if (executing_breakpoint_commands
)
323 error ("Can't use the \"commands\" command among a breakpoint's commands.");
326 bnum
= get_number (&p
);
328 error ("Unexpected extra arguments following breakpoint number.");
331 if (b
->number
== bnum
)
333 if (from_tty
&& input_from_terminal_p ())
334 printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\
335 End with a line saying just \"end\".\n", bnum
);
336 l
= read_command_lines ();
337 free_command_lines (&b
->commands
);
339 breakpoints_changed ();
342 error ("No breakpoint number %d.", bnum
);
345 extern int memory_breakpoint_size
; /* from mem-break.c */
347 /* Like target_read_memory() but if breakpoints are inserted, return
348 the shadow contents instead of the breakpoints themselves.
350 Read "memory data" from whatever target or inferior we have.
351 Returns zero if successful, errno value if not. EIO is used
352 for address out of bounds. If breakpoints are inserted, returns
353 shadow contents, not the breakpoints themselves. From breakpoint.c. */
356 read_memory_nobpt (memaddr
, myaddr
, len
)
362 struct breakpoint
*b
;
364 if (memory_breakpoint_size
< 0)
365 /* No breakpoints on this machine. FIXME: This should be
366 dependent on the debugging target. Probably want
367 target_insert_breakpoint to return a size, saying how many
368 bytes of the shadow contents are used, or perhaps have
369 something like target_xfer_shadow. */
370 return target_read_memory (memaddr
, myaddr
, len
);
374 if (b
->type
== bp_watchpoint
375 || b
->type
== bp_hardware_watchpoint
376 || b
->type
== bp_read_watchpoint
377 || b
->type
== bp_access_watchpoint
380 else if (b
->address
+ memory_breakpoint_size
<= memaddr
)
381 /* The breakpoint is entirely before the chunk of memory
384 else if (b
->address
>= memaddr
+ len
)
385 /* The breakpoint is entirely after the chunk of memory we
390 /* Copy the breakpoint from the shadow contents, and recurse
391 for the things before and after. */
393 /* Addresses and length of the part of the breakpoint that
395 CORE_ADDR membpt
= b
->address
;
396 unsigned int bptlen
= memory_breakpoint_size
;
397 /* Offset within shadow_contents. */
400 if (membpt
< memaddr
)
402 /* Only copy the second part of the breakpoint. */
403 bptlen
-= memaddr
- membpt
;
404 bptoffset
= memaddr
- membpt
;
408 if (membpt
+ bptlen
> memaddr
+ len
)
410 /* Only copy the first part of the breakpoint. */
411 bptlen
-= (membpt
+ bptlen
) - (memaddr
+ len
);
414 memcpy (myaddr
+ membpt
- memaddr
,
415 b
->shadow_contents
+ bptoffset
, bptlen
);
417 if (membpt
> memaddr
)
419 /* Copy the section of memory before the breakpoint. */
420 status
= read_memory_nobpt (memaddr
, myaddr
, membpt
- memaddr
);
425 if (membpt
+ bptlen
< memaddr
+ len
)
427 /* Copy the section of memory after the breakpoint. */
428 status
= read_memory_nobpt
430 myaddr
+ membpt
+ bptlen
- memaddr
,
431 memaddr
+ len
- (membpt
+ bptlen
));
438 /* Nothing overlaps. Just call read_memory_noerr. */
439 return target_read_memory (memaddr
, myaddr
, len
);
442 /* insert_breakpoints is used when starting or continuing the program.
443 remove_breakpoints is used when the program stops.
444 Both return zero if successful,
445 or an `errno' value if could not write the inferior. */
448 insert_breakpoints ()
450 register struct breakpoint
*b
, *temp
;
452 int disabled_breaks
= 0;
454 ALL_BREAKPOINTS_SAFE (b
, temp
)
455 if (b
->type
!= bp_watchpoint
456 && b
->type
!= bp_hardware_watchpoint
457 && b
->type
!= bp_read_watchpoint
458 && b
->type
!= bp_access_watchpoint
459 && b
->enable
!= disabled
460 && b
->enable
!= shlib_disabled
464 if (b
->type
== bp_hardware_breakpoint
)
465 val
= target_insert_hw_breakpoint(b
->address
, b
->shadow_contents
);
467 val
= target_insert_breakpoint(b
->address
, b
->shadow_contents
);
470 /* Can't set the breakpoint. */
471 #if defined (DISABLE_UNSETTABLE_BREAK)
472 if (DISABLE_UNSETTABLE_BREAK (b
->address
))
475 b
->enable
= shlib_disabled
;
476 if (!disabled_breaks
)
478 target_terminal_ours_for_output ();
479 fprintf_unfiltered (gdb_stderr
,
480 "Cannot insert breakpoint %d:\n", b
->number
);
481 printf_filtered ("Temporarily disabling shared library breakpoints:\n");
484 printf_filtered ("%d ", b
->number
);
489 target_terminal_ours_for_output ();
490 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
491 #ifdef ONE_PROCESS_WRITETEXT
492 fprintf_unfiltered (gdb_stderr
,
493 "The same program may be running in another process.\n");
495 memory_error (val
, b
->address
); /* which bombs us out */
501 else if ((b
->type
== bp_hardware_watchpoint
||
502 b
->type
== bp_read_watchpoint
||
503 b
->type
== bp_access_watchpoint
)
504 && b
->enable
== enabled
508 struct frame_info
*saved_frame
;
509 int saved_level
, within_current_scope
;
510 value_ptr mark
= value_mark ();
513 /* Save the current frame and level so we can restore it after
514 evaluating the watchpoint expression on its own frame. */
515 saved_frame
= selected_frame
;
516 saved_level
= selected_frame_level
;
518 /* Determine if the watchpoint is within scope. */
519 if (b
->exp_valid_block
== NULL
)
520 within_current_scope
= 1;
523 struct frame_info
*fi
=
524 find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
525 within_current_scope
= (fi
!= NULL
);
526 if (within_current_scope
)
527 select_frame (fi
, -1);
530 if (within_current_scope
)
532 /* Evaluate the expression and cut the chain of values
533 produced off from the value chain. */
534 v
= evaluate_expression (b
->exp
);
535 value_release_to_mark (mark
);
540 /* Look at each value on the value chain. */
541 for ( ; v
; v
=v
->next
)
543 /* If it's a memory location, then we must watch it. */
544 if (v
->lval
== lval_memory
)
548 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
549 len
= TYPE_LENGTH (VALUE_TYPE (v
));
551 if (b
->type
== bp_read_watchpoint
)
553 else if (b
->type
== bp_access_watchpoint
)
556 val
= target_insert_watchpoint (addr
, len
, type
);
565 /* Failure to insert a watchpoint on any memory value in the
566 value chain brings us here. */
568 warning ("Hardware watchpoint %d: Could not insert watchpoint\n",
574 Hardware watchpoint %d deleted because the program has left the block in\n\
575 which its expression is valid.\n", b
->number
);
576 if (b
->related_breakpoint
)
578 b
->related_breakpoint
->enable
= disable
;
579 b
->related_breakpoint
->disposition
= del_at_next_stop
;
582 b
->disposition
= del_at_next_stop
;
585 /* Restore the frame and level. */
586 select_frame (saved_frame
, saved_level
);
589 printf_filtered ("\n");
595 remove_breakpoints ()
597 register struct breakpoint
*b
;
604 val
= remove_breakpoint (b
);
614 remove_breakpoint (b
)
615 struct breakpoint
*b
;
619 if (b
->type
!= bp_watchpoint
620 && b
->type
!= bp_hardware_watchpoint
621 && b
->type
!= bp_read_watchpoint
622 && b
->type
!= bp_access_watchpoint
)
624 if (b
->type
== bp_hardware_breakpoint
)
625 val
= target_remove_hw_breakpoint(b
->address
, b
->shadow_contents
);
627 val
= target_remove_breakpoint(b
->address
, b
->shadow_contents
);
632 else if ((b
->type
== bp_hardware_watchpoint
||
633 b
->type
== bp_read_watchpoint
||
634 b
->type
== bp_access_watchpoint
)
635 && b
->enable
== enabled
641 /* Walk down the saved value chain. */
642 for (v
= b
->val_chain
; v
; v
= v
->next
)
644 /* For each memory reference remove the watchpoint
646 if (v
->lval
== lval_memory
)
650 addr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
651 len
= TYPE_LENGTH (VALUE_TYPE (v
));
652 val
= target_remove_watchpoint (addr
, len
, b
->type
);
658 /* Failure to remove any of the hardware watchpoints comes here. */
660 warning ("Hardware watchpoint %d: Could not remove watchpoint\n",
663 /* Free the saved value chain. We will construct a new one
664 the next time the watchpoint is inserted. */
665 for (v
= b
->val_chain
; v
; v
= n
)
675 /* Clear the "inserted" flag in all breakpoints. */
678 mark_breakpoints_out ()
680 register struct breakpoint
*b
;
686 /* Clear the "inserted" flag in all breakpoints and delete any breakpoints
687 which should go away between runs of the program. */
690 breakpoint_init_inferior ()
692 register struct breakpoint
*b
, *temp
;
694 ALL_BREAKPOINTS_SAFE (b
, temp
)
701 case bp_watchpoint_scope
:
703 /* If the call dummy breakpoint is at the entry point it will
704 cause problems when the inferior is rerun, so we better
707 Also get rid of scope breakpoints. */
708 delete_breakpoint (b
);
712 case bp_hardware_watchpoint
:
713 case bp_read_watchpoint
:
714 case bp_access_watchpoint
:
716 /* Likewise for watchpoints on local expressions. */
717 if (b
->exp_valid_block
!= NULL
)
718 delete_breakpoint (b
);
727 /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
728 When continuing from a location with a breakpoint,
729 we actually single step once before calling insert_breakpoints. */
732 breakpoint_here_p (pc
)
735 register struct breakpoint
*b
;
738 if (b
->enable
!= disabled
739 && b
->enable
!= shlib_disabled
746 /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY
747 because figuring out the saved SP would take too much time, at least using
748 get_saved_register on the 68k. This means that for this function to
749 work right a port must use the bp_call_dummy breakpoint. */
752 frame_in_dummy (frame
)
753 struct frame_info
*frame
;
755 struct breakpoint
*b
;
760 static unsigned LONGEST dummy
[] = CALL_DUMMY
;
762 if (b
->type
== bp_call_dummy
763 && b
->frame
== frame
->frame
765 /* We need to check the PC as well as the frame on the sparc,
766 for signals.exp in the testsuite. */
769 - sizeof (dummy
) / sizeof (LONGEST
) * REGISTER_SIZE
))
770 && frame
->pc
<= b
->address
)
773 #endif /* CALL_DUMMY */
777 /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC
778 is valid for process/thread PID. */
781 breakpoint_thread_match (pc
, pid
)
785 struct breakpoint
*b
;
788 thread
= pid_to_thread_id (pid
);
791 if (b
->enable
!= disabled
792 && b
->enable
!= shlib_disabled
794 && (b
->thread
== -1 || b
->thread
== thread
))
801 /* bpstat stuff. External routines' interfaces are documented
804 /* Clear a bpstat so that it says we are not at any breakpoint.
805 Also free any storage that is part of a bpstat. */
820 if (p
->old_val
!= NULL
)
821 value_free (p
->old_val
);
828 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
829 is part of the bpstat is copied as well. */
837 bpstat retval
= NULL
;
842 for (; bs
!= NULL
; bs
= bs
->next
)
844 tmp
= (bpstat
) xmalloc (sizeof (*tmp
));
845 memcpy (tmp
, bs
, sizeof (*tmp
));
847 /* This is the first thing in the chain. */
857 /* Find the bpstat associated with this breakpoint */
860 bpstat_find_breakpoint(bsp
, breakpoint
)
862 struct breakpoint
*breakpoint
;
864 if (bsp
== NULL
) return NULL
;
866 for (;bsp
!= NULL
; bsp
= bsp
->next
) {
867 if (bsp
->breakpoint_at
== breakpoint
) return bsp
;
872 /* Return the breakpoint number of the first breakpoint we are stopped
873 at. *BSP upon return is a bpstat which points to the remaining
874 breakpoints stopped at (but which is not guaranteed to be good for
875 anything but further calls to bpstat_num).
876 Return 0 if passed a bpstat which does not indicate any breakpoints. */
882 struct breakpoint
*b
;
885 return 0; /* No more breakpoint values */
888 b
= (*bsp
)->breakpoint_at
;
891 return -1; /* breakpoint that's been deleted since */
893 return b
->number
; /* We have its number */
897 /* Modify BS so that the actions will not be performed. */
900 bpstat_clear_actions (bs
)
903 for (; bs
!= NULL
; bs
= bs
->next
)
906 if (bs
->old_val
!= NULL
)
908 value_free (bs
->old_val
);
914 /* Stub for cleaning up our state if we error-out of a breakpoint command */
917 cleanup_executing_breakpoints (ignore
)
920 executing_breakpoint_commands
= 0;
923 /* Execute all the commands associated with all the breakpoints at this
924 location. Any of these commands could cause the process to proceed
925 beyond this point, etc. We look out for such changes by checking
926 the global "breakpoint_proceeded" after each command. */
929 bpstat_do_actions (bsp
)
933 struct cleanup
*old_chain
;
934 struct command_line
*cmd
;
936 executing_breakpoint_commands
= 1;
937 old_chain
= make_cleanup (cleanup_executing_breakpoints
, 0);
942 breakpoint_proceeded
= 0;
943 for (; bs
!= NULL
; bs
= bs
->next
)
948 execute_control_command (cmd
);
951 if (breakpoint_proceeded
)
952 /* The inferior is proceeded by the command; bomb out now.
953 The bpstat chain has been blown away by wait_for_inferior.
954 But since execution has stopped again, there is a new bpstat
955 to look at, so start over. */
961 executing_breakpoint_commands
= 0;
962 discard_cleanups (old_chain
);
965 /* This is the normal print_it function for a bpstat. In the future,
966 much of this logic could (should?) be moved to bpstat_stop_status,
967 by having it set different print_it functions. */
973 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
974 which has since been deleted. */
975 if (bs
->breakpoint_at
== NULL
976 || (bs
->breakpoint_at
->type
!= bp_breakpoint
977 && bs
->breakpoint_at
->type
!= bp_hardware_breakpoint
978 && bs
->breakpoint_at
->type
!= bp_watchpoint
979 && bs
->breakpoint_at
->type
!= bp_read_watchpoint
980 && bs
->breakpoint_at
->type
!= bp_access_watchpoint
981 && bs
->breakpoint_at
->type
!= bp_hardware_watchpoint
))
984 if (bs
->breakpoint_at
->type
== bp_breakpoint
||
985 bs
->breakpoint_at
->type
== bp_hardware_breakpoint
)
987 /* I think the user probably only wants to see one breakpoint
988 number, not all of them. */
989 annotate_breakpoint (bs
->breakpoint_at
->number
);
990 printf_filtered ("\nBreakpoint %d, ", bs
->breakpoint_at
->number
);
993 else if ((bs
->old_val
!= NULL
) &&
994 (bs
->breakpoint_at
->type
== bp_watchpoint
||
995 bs
->breakpoint_at
->type
== bp_access_watchpoint
||
996 bs
->breakpoint_at
->type
== bp_hardware_watchpoint
))
998 annotate_watchpoint (bs
->breakpoint_at
->number
);
999 mention (bs
->breakpoint_at
);
1000 printf_filtered ("\nOld value = ");
1001 value_print (bs
->old_val
, gdb_stdout
, 0, Val_pretty_default
);
1002 printf_filtered ("\nNew value = ");
1003 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1004 Val_pretty_default
);
1005 printf_filtered ("\n");
1006 value_free (bs
->old_val
);
1008 /* More than one watchpoint may have been triggered. */
1011 else if (bs
->breakpoint_at
->type
== bp_access_watchpoint
||
1012 bs
->breakpoint_at
->type
== bp_read_watchpoint
)
1014 mention (bs
->breakpoint_at
);
1015 printf_filtered ("\nValue = ");
1016 value_print (bs
->breakpoint_at
->val
, gdb_stdout
, 0,
1017 Val_pretty_default
);
1018 printf_filtered ("\n");
1021 /* We can't deal with it. Maybe another member of the bpstat chain can. */
1025 /* Print a message indicating what happened. Returns nonzero to
1026 say that only the source line should be printed after this (zero
1027 return means print the frame as well as the source line). */
1028 /* Currently we always return zero. */
1038 val
= (*bs
->print_it
) (bs
);
1042 /* Maybe another breakpoint in the chain caused us to stop.
1043 (Currently all watchpoints go on the bpstat whether hit or
1044 not. That probably could (should) be changed, provided care is taken
1045 with respect to bpstat_explains_signal). */
1047 return bpstat_print (bs
->next
);
1049 /* We reached the end of the chain without printing anything. */
1053 /* Evaluate the expression EXP and return 1 if value is zero.
1054 This is used inside a catch_errors to evaluate the breakpoint condition.
1055 The argument is a "struct expression *" that has been cast to char * to
1056 make it pass through catch_errors. */
1059 breakpoint_cond_eval (exp
)
1062 value_ptr mark
= value_mark ();
1063 int i
= !value_true (evaluate_expression ((struct expression
*)exp
));
1064 value_free_to_mark (mark
);
1068 /* Allocate a new bpstat and chain it to the current one. */
1071 bpstat_alloc (b
, cbs
)
1072 register struct breakpoint
*b
;
1073 bpstat cbs
; /* Current "bs" value */
1077 bs
= (bpstat
) xmalloc (sizeof (*bs
));
1079 bs
->breakpoint_at
= b
;
1080 /* If the condition is false, etc., don't do the commands. */
1081 bs
->commands
= NULL
;
1083 bs
->print_it
= print_it_normal
;
1087 /* Possible return values for watchpoint_check (this can't be an enum
1088 because of check_errors). */
1089 /* The watchpoint has been deleted. */
1090 #define WP_DELETED 1
1091 /* The value has changed. */
1092 #define WP_VALUE_CHANGED 2
1093 /* The value has not changed. */
1094 #define WP_VALUE_NOT_CHANGED 3
1096 #define BP_TEMPFLAG 1
1097 #define BP_HARDWAREFLAG 2
1099 /* Check watchpoint condition. */
1102 watchpoint_check (p
)
1105 bpstat bs
= (bpstat
) p
;
1106 struct breakpoint
*b
;
1107 struct frame_info
*fr
;
1108 int within_current_scope
;
1110 b
= bs
->breakpoint_at
;
1112 if (b
->exp_valid_block
== NULL
)
1113 within_current_scope
= 1;
1116 /* There is no current frame at this moment. If we're going to have
1117 any chance of handling watchpoints on local variables, we'll need
1118 the frame chain (so we can determine if we're in scope). */
1119 reinit_frame_cache();
1120 fr
= find_frame_addr_in_frame_chain (b
->watchpoint_frame
);
1121 within_current_scope
= (fr
!= NULL
);
1122 if (within_current_scope
)
1123 /* If we end up stopping, the current frame will get selected
1124 in normal_stop. So this call to select_frame won't affect
1126 select_frame (fr
, -1);
1129 if (within_current_scope
)
1131 /* We use value_{,free_to_}mark because it could be a
1132 *long* time before we return to the command level and
1133 call free_all_values. We can't call free_all_values because
1134 we might be in the middle of evaluating a function call. */
1136 value_ptr mark
= value_mark ();
1137 value_ptr new_val
= evaluate_expression (bs
->breakpoint_at
->exp
);
1138 if (!value_equal (b
->val
, new_val
))
1140 release_value (new_val
);
1141 value_free_to_mark (mark
);
1142 bs
->old_val
= b
->val
;
1144 /* We will stop here */
1145 return WP_VALUE_CHANGED
;
1149 /* Nothing changed, don't do anything. */
1150 value_free_to_mark (mark
);
1151 /* We won't stop here */
1152 return WP_VALUE_NOT_CHANGED
;
1157 /* This seems like the only logical thing to do because
1158 if we temporarily ignored the watchpoint, then when
1159 we reenter the block in which it is valid it contains
1160 garbage (in the case of a function, it may have two
1161 garbage values, one before and one after the prologue).
1162 So we can't even detect the first assignment to it and
1163 watch after that (since the garbage may or may not equal
1164 the first value assigned). */
1166 Watchpoint %d deleted because the program has left the block in\n\
1167 which its expression is valid.\n", bs
->breakpoint_at
->number
);
1168 if (b
->related_breakpoint
)
1170 b
->related_breakpoint
->enable
= disable
;
1171 b
->related_breakpoint
->disposition
= del_at_next_stop
;
1173 b
->enable
= disable
;
1174 b
->disposition
= del_at_next_stop
;
1180 /* This is used when everything which needs to be printed has
1181 already been printed. But we still want to print the frame. */
1189 /* This is used when nothing should be printed for this bpstat entry. */
1198 /* Get a bpstat associated with having just stopped at address *PC
1199 and frame address CORE_ADDRESS. Update *PC to point at the
1200 breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero
1201 if this is known to not be a real breakpoint (it could still be a
1202 watchpoint, though). */
1204 /* Determine whether we stopped at a breakpoint, etc, or whether we
1205 don't understand this stop. Result is a chain of bpstat's such that:
1207 if we don't understand the stop, the result is a null pointer.
1209 if we understand why we stopped, the result is not null.
1211 Each element of the chain refers to a particular breakpoint or
1212 watchpoint at which we have stopped. (We may have stopped for
1213 several reasons concurrently.)
1215 Each element of the chain has valid next, breakpoint_at,
1216 commands, FIXME??? fields.
1221 bpstat_stop_status (pc
, not_a_breakpoint
)
1223 int not_a_breakpoint
;
1225 register struct breakpoint
*b
, *temp
;
1227 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1228 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
1229 int real_breakpoint
= 0;
1231 /* Root of the chain of bpstat's */
1232 struct bpstats root_bs
[1];
1233 /* Pointer to the last thing in the chain currently. */
1234 bpstat bs
= root_bs
;
1235 static char message1
[] =
1236 "Error evaluating expression for watchpoint %d\n";
1237 char message
[sizeof (message1
) + 30 /* slop */];
1239 /* Get the address where the breakpoint would have been. */
1240 bp_addr
= *pc
- DECR_PC_AFTER_BREAK
;
1242 ALL_BREAKPOINTS_SAFE (b
, temp
)
1244 if (b
->enable
== disabled
1245 || b
->enable
== shlib_disabled
)
1248 if (b
->type
!= bp_watchpoint
1249 && b
->type
!= bp_hardware_watchpoint
1250 && b
->type
!= bp_read_watchpoint
1251 && b
->type
!= bp_access_watchpoint
1252 && b
->type
!= bp_hardware_breakpoint
1253 && b
->address
!= bp_addr
)
1256 if (b
->type
== bp_hardware_breakpoint
1257 && b
->address
!= (bp_addr
- DECR_PC_AFTER_HW_BREAK
))
1260 if (b
->type
!= bp_watchpoint
1261 && b
->type
!= bp_hardware_watchpoint
1262 && b
->type
!= bp_read_watchpoint
1263 && b
->type
!= bp_access_watchpoint
1264 && not_a_breakpoint
)
1267 /* Come here if it's a watchpoint, or if the break address matches */
1271 bs
= bpstat_alloc (b
, bs
); /* Alloc a bpstat to explain stop */
1276 sprintf (message
, message1
, b
->number
);
1277 if (b
->type
== bp_watchpoint
|| b
->type
== bp_hardware_watchpoint
)
1279 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1283 /* We've already printed what needs to be printed. */
1284 bs
->print_it
= print_it_done
;
1287 case WP_VALUE_CHANGED
:
1290 case WP_VALUE_NOT_CHANGED
:
1292 bs
->print_it
= print_it_noop
;
1299 /* Error from catch_errors. */
1300 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1301 if (b
->related_breakpoint
)
1303 b
->related_breakpoint
->enable
= disable
;
1304 b
->related_breakpoint
->disposition
= del_at_next_stop
;
1306 b
->enable
= disable
;
1307 b
->disposition
= del_at_next_stop
;
1308 /* We've already printed what needs to be printed. */
1309 bs
->print_it
= print_it_done
;
1315 else if (b
->type
== bp_read_watchpoint
|| b
->type
== bp_access_watchpoint
)
1321 addr
= target_stopped_data_address();
1322 if (addr
== 0) continue;
1323 for (v
= b
->val_chain
; v
; v
= v
->next
)
1325 if (v
->lval
== lval_memory
)
1329 vaddr
= VALUE_ADDRESS (v
) + VALUE_OFFSET (v
);
1335 switch (catch_errors (watchpoint_check
, (char *) bs
, message
,
1339 /* We've already printed what needs to be printed. */
1340 bs
->print_it
= print_it_done
;
1343 case WP_VALUE_CHANGED
:
1344 case WP_VALUE_NOT_CHANGED
:
1350 /* Error from catch_errors. */
1351 printf_filtered ("Watchpoint %d deleted.\n", b
->number
);
1352 if (b
->related_breakpoint
)
1354 b
->related_breakpoint
->enable
= disable
;
1355 b
->related_breakpoint
->disposition
= del_at_next_stop
;
1357 b
->enable
= disable
;
1358 b
->disposition
= del_at_next_stop
;
1359 /* We've already printed what needs to be printed. */
1360 bs
->print_it
= print_it_done
;
1364 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1366 real_breakpoint
= 1;
1369 if (b
->frame
&& b
->frame
!= (get_current_frame ())->frame
)
1373 int value_is_zero
= 0;
1377 /* Need to select the frame, with all that implies
1378 so that the conditions will have the right context. */
1379 select_frame (get_current_frame (), 0);
1381 = catch_errors (breakpoint_cond_eval
, (char *)(b
->cond
),
1382 "Error in testing breakpoint condition:\n",
1384 /* FIXME-someday, should give breakpoint # */
1387 if (b
->cond
&& value_is_zero
)
1391 else if (b
->ignore_count
> 0)
1398 /* We will stop here */
1399 if (b
->disposition
== disable
)
1400 b
->enable
= disabled
;
1401 bs
->commands
= b
->commands
;
1404 if (bs
->commands
&& STREQ ("silent", bs
->commands
->line
))
1406 bs
->commands
= bs
->commands
->next
;
1411 /* Print nothing for this entry if we dont stop or if we dont print. */
1412 if (bs
->stop
== 0 || bs
->print
== 0)
1413 bs
->print_it
= print_it_noop
;
1416 bs
->next
= NULL
; /* Terminate the chain */
1417 bs
= root_bs
->next
; /* Re-grab the head of the chain */
1418 #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
1421 if (real_breakpoint
)
1424 #if defined (SHIFT_INST_REGS)
1426 #else /* No SHIFT_INST_REGS. */
1428 #endif /* No SHIFT_INST_REGS. */
1431 #endif /* DECR_PC_AFTER_BREAK != 0. */
1433 /* The value of a hardware watchpoint hasn't changed, but the
1434 intermediate memory locations we are watching may have. */
1435 if (bs
&& ! bs
->stop
&&
1436 (bs
->breakpoint_at
->type
== bp_hardware_watchpoint
||
1437 bs
->breakpoint_at
->type
== bp_read_watchpoint
||
1438 bs
->breakpoint_at
->type
== bp_access_watchpoint
))
1440 remove_breakpoints ();
1441 insert_breakpoints ();
1446 /* Tell what to do about this bpstat. */
1451 /* Classify each bpstat as one of the following. */
1453 /* This bpstat element has no effect on the main_action. */
1456 /* There was a watchpoint, stop but don't print. */
1459 /* There was a watchpoint, stop and print. */
1462 /* There was a breakpoint but we're not stopping. */
1465 /* There was a breakpoint, stop but don't print. */
1468 /* There was a breakpoint, stop and print. */
1471 /* We hit the longjmp breakpoint. */
1474 /* We hit the longjmp_resume breakpoint. */
1477 /* We hit the step_resume breakpoint. */
1480 /* We hit the through_sigtramp breakpoint. */
1483 /* We hit the shared library event breakpoint. */
1486 /* This is just used to count how many enums there are. */
1490 /* Here is the table which drives this routine. So that we can
1491 format it pretty, we define some abbreviations for the
1492 enum bpstat_what codes. */
1493 #define kc BPSTAT_WHAT_KEEP_CHECKING
1494 #define ss BPSTAT_WHAT_STOP_SILENT
1495 #define sn BPSTAT_WHAT_STOP_NOISY
1496 #define sgl BPSTAT_WHAT_SINGLE
1497 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
1498 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
1499 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
1500 #define sr BPSTAT_WHAT_STEP_RESUME
1501 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
1502 #define shl BPSTAT_WHAT_CHECK_SHLIBS
1504 /* "Can't happen." Might want to print an error message.
1505 abort() is not out of the question, but chances are GDB is just
1506 a bit confused, not unusable. */
1507 #define err BPSTAT_WHAT_STOP_NOISY
1509 /* Given an old action and a class, come up with a new action. */
1510 /* One interesting property of this table is that wp_silent is the same
1511 as bp_silent and wp_noisy is the same as bp_noisy. That is because
1512 after stopping, the check for whether to step over a breakpoint
1513 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
1514 reference to how we stopped. We retain separate wp_silent and bp_silent
1515 codes in case we want to change that someday. */
1517 /* step_resume entries: a step resume breakpoint overrides another
1518 breakpoint of signal handling (see comment in wait_for_inferior
1519 at first IN_SIGTRAMP where we set the step_resume breakpoint). */
1520 /* We handle the through_sigtramp_breakpoint the same way; having both
1521 one of those and a step_resume_breakpoint is probably very rare (?). */
1523 static const enum bpstat_what_main_action
1524 table
[(int)class_last
][(int)BPSTAT_WHAT_LAST
] =
1527 /* kc ss sn sgl slr clr clrs sr ts shl
1529 /*no_effect*/ {kc
, ss
, sn
, sgl
, slr
, clr
, clrs
, sr
, ts
, shl
},
1530 /*wp_silent*/ {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
},
1531 /*wp_noisy*/ {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
},
1532 /*bp_nostop*/ {sgl
, ss
, sn
, sgl
, slr
, clrs
, clrs
, sr
, ts
, shl
},
1533 /*bp_silent*/ {ss
, ss
, sn
, ss
, ss
, ss
, ss
, sr
, ts
, shl
},
1534 /*bp_noisy*/ {sn
, sn
, sn
, sn
, sn
, sn
, sn
, sr
, ts
, shl
},
1535 /*long_jump*/ {slr
, ss
, sn
, slr
, err
, err
, err
, sr
, ts
, shl
},
1536 /*long_resume*/ {clr
, ss
, sn
, clrs
, err
, err
, err
, sr
, ts
, shl
},
1537 /*step_resume*/ {sr
, sr
, sr
, sr
, sr
, sr
, sr
, sr
, ts
, shl
},
1538 /*through_sig*/ {ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, ts
, shl
},
1539 /*shlib*/ {shl
, shl
, shl
, shl
, shl
, shl
, shl
, shl
, ts
, shl
}
1552 enum bpstat_what_main_action current_action
= BPSTAT_WHAT_KEEP_CHECKING
;
1553 struct bpstat_what retval
;
1555 retval
.call_dummy
= 0;
1556 for (; bs
!= NULL
; bs
= bs
->next
)
1558 enum class bs_class
= no_effect
;
1559 if (bs
->breakpoint_at
== NULL
)
1560 /* I suspect this can happen if it was a momentary breakpoint
1561 which has since been deleted. */
1563 switch (bs
->breakpoint_at
->type
)
1566 case bp_hardware_breakpoint
:
1572 bs_class
= bp_noisy
;
1574 bs_class
= bp_silent
;
1577 bs_class
= bp_nostop
;
1580 case bp_hardware_watchpoint
:
1581 case bp_read_watchpoint
:
1582 case bp_access_watchpoint
:
1586 bs_class
= wp_noisy
;
1588 bs_class
= wp_silent
;
1591 /* There was a watchpoint, but we're not stopping. This requires
1592 no further action. */
1593 bs_class
= no_effect
;
1596 bs_class
= long_jump
;
1598 case bp_longjmp_resume
:
1599 bs_class
= long_resume
;
1601 case bp_step_resume
:
1604 bs_class
= step_resume
;
1607 /* It is for the wrong frame. */
1608 bs_class
= bp_nostop
;
1610 case bp_through_sigtramp
:
1611 bs_class
= through_sig
;
1613 case bp_watchpoint_scope
:
1614 bs_class
= bp_nostop
;
1616 case bp_shlib_event
:
1617 bs_class
= shlib_event
;
1620 /* Make sure the action is stop (silent or noisy), so infrun.c
1621 pops the dummy frame. */
1622 bs_class
= bp_silent
;
1623 retval
.call_dummy
= 1;
1626 current_action
= table
[(int)bs_class
][(int)current_action
];
1628 retval
.main_action
= current_action
;
1632 /* Nonzero if we should step constantly (e.g. watchpoints on machines
1633 without hardware support). This isn't related to a specific bpstat,
1634 just to things like whether watchpoints are set. */
1637 bpstat_should_step ()
1639 struct breakpoint
*b
;
1641 if (b
->enable
== enabled
&& b
->type
== bp_watchpoint
)
1646 /* Print information on breakpoint number BNUM, or -1 if all.
1647 If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
1648 is nonzero, process only watchpoints. */
1651 breakpoint_1 (bnum
, allflag
)
1655 register struct breakpoint
*b
;
1656 register struct command_line
*l
;
1657 register struct symbol
*sym
;
1658 CORE_ADDR last_addr
= (CORE_ADDR
)-1;
1659 int found_a_breakpoint
= 0;
1660 static char *bptypes
[] = {"breakpoint", "hw breakpoint",
1661 "until", "finish", "watchpoint",
1662 "hw watchpoint", "read watchpoint",
1663 "acc watchpoint", "longjmp",
1664 "longjmp resume", "step resume",
1666 "watchpoint scope", "call dummy",
1668 static char *bpdisps
[] = {"del", "dstp", "dis", "keep"};
1669 static char bpenables
[] = "ny";
1670 char wrap_indent
[80];
1674 || bnum
== b
->number
)
1676 /* We only print out user settable breakpoints unless the allflag is set. */
1678 && b
->type
!= bp_breakpoint
1679 && b
->type
!= bp_hardware_breakpoint
1680 && b
->type
!= bp_watchpoint
1681 && b
->type
!= bp_read_watchpoint
1682 && b
->type
!= bp_access_watchpoint
1683 && b
->type
!= bp_hardware_watchpoint
)
1686 if (!found_a_breakpoint
++)
1688 annotate_breakpoints_headers ();
1691 printf_filtered ("Num ");
1693 printf_filtered ("Type ");
1695 printf_filtered ("Disp ");
1697 printf_filtered ("Enb ");
1701 printf_filtered ("Address ");
1704 printf_filtered ("What\n");
1706 annotate_breakpoints_table ();
1711 printf_filtered ("%-3d ", b
->number
);
1713 printf_filtered ("%-14s ", bptypes
[(int)b
->type
]);
1715 printf_filtered ("%-4s ", bpdisps
[(int)b
->disposition
]);
1717 printf_filtered ("%-3c ", bpenables
[(int)b
->enable
]);
1719 strcpy (wrap_indent
, " ");
1721 strcat (wrap_indent
, " ");
1725 case bp_hardware_watchpoint
:
1726 case bp_read_watchpoint
:
1727 case bp_access_watchpoint
:
1728 /* Field 4, the address, is omitted (which makes the columns
1729 not line up too nicely with the headers, but the effect
1730 is relatively readable). */
1732 print_expression (b
->exp
, gdb_stdout
);
1736 case bp_hardware_breakpoint
:
1740 case bp_longjmp_resume
:
1741 case bp_step_resume
:
1742 case bp_through_sigtramp
:
1743 case bp_watchpoint_scope
:
1745 case bp_shlib_event
:
1749 /* FIXME-32x64: need a print_address_numeric with
1753 local_hex_string_custom
1754 ((unsigned long) b
->address
, "08l"));
1759 last_addr
= b
->address
;
1762 sym
= find_pc_function (b
->address
);
1765 fputs_filtered ("in ", gdb_stdout
);
1766 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
1767 wrap_here (wrap_indent
);
1768 fputs_filtered (" at ", gdb_stdout
);
1770 fputs_filtered (b
->source_file
, gdb_stdout
);
1771 printf_filtered (":%d", b
->line_number
);
1774 print_address_symbolic (b
->address
, gdb_stdout
, demangle
, " ");
1778 printf_filtered ("\n");
1784 printf_filtered ("\tstop only in stack frame at ");
1785 print_address_numeric (b
->frame
, 1, gdb_stdout
);
1786 printf_filtered ("\n");
1793 printf_filtered ("\tstop only if ");
1794 print_expression (b
->cond
, gdb_stdout
);
1795 printf_filtered ("\n");
1798 if (show_breakpoint_hit_counts
&& b
->hit_count
)
1800 /* FIXME should make an annotation for this */
1802 printf_filtered ("\tbreakpoint already hit %d time%s\n",
1803 b
->hit_count
, (b
->hit_count
== 1 ? "" : "s"));
1806 if (b
->ignore_count
)
1810 printf_filtered ("\tignore next %d hits\n", b
->ignore_count
);
1813 if ((l
= b
->commands
))
1819 print_command_line (l
, 4);
1825 if (!found_a_breakpoint
)
1828 printf_filtered ("No breakpoints or watchpoints.\n");
1830 printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum
);
1833 /* Compare against (CORE_ADDR)-1 in case some compiler decides
1834 that a comparison of an unsigned with -1 is always false. */
1835 if (last_addr
!= (CORE_ADDR
)-1)
1836 set_next_address (last_addr
);
1838 annotate_breakpoints_table_end ();
1843 breakpoints_info (bnum_exp
, from_tty
)
1850 bnum
= parse_and_eval_address (bnum_exp
);
1852 breakpoint_1 (bnum
, 0);
1855 #if MAINTENANCE_CMDS
1859 maintenance_info_breakpoints (bnum_exp
, from_tty
)
1866 bnum
= parse_and_eval_address (bnum_exp
);
1868 breakpoint_1 (bnum
, 1);
1873 /* Print a message describing any breakpoints set at PC. */
1876 describe_other_breakpoints (pc
)
1877 register CORE_ADDR pc
;
1879 register int others
= 0;
1880 register struct breakpoint
*b
;
1883 if (b
->address
== pc
)
1887 printf_filtered ("Note: breakpoint%s ", (others
> 1) ? "s" : "");
1889 if (b
->address
== pc
)
1895 ((b
->enable
== disabled
|| b
->enable
== shlib_disabled
)
1896 ? " (disabled)" : ""),
1897 (others
> 1) ? "," : ((others
== 1) ? " and" : ""));
1899 printf_filtered ("also set at pc ");
1900 print_address_numeric (pc
, 1, gdb_stdout
);
1901 printf_filtered (".\n");
1905 /* Set the default place to put a breakpoint
1906 for the `break' command with no arguments. */
1909 set_default_breakpoint (valid
, addr
, symtab
, line
)
1912 struct symtab
*symtab
;
1915 default_breakpoint_valid
= valid
;
1916 default_breakpoint_address
= addr
;
1917 default_breakpoint_symtab
= symtab
;
1918 default_breakpoint_line
= line
;
1921 /* Rescan breakpoints at address ADDRESS,
1922 marking the first one as "first" and any others as "duplicates".
1923 This is so that the bpt instruction is only inserted once. */
1926 check_duplicates (address
)
1929 register struct breakpoint
*b
;
1930 register int count
= 0;
1932 if (address
== 0) /* Watchpoints are uninteresting */
1936 if (b
->enable
!= disabled
1937 && b
->enable
!= shlib_disabled
1938 && b
->address
== address
)
1941 b
->duplicate
= count
> 1;
1945 /* Low level routine to set a breakpoint.
1946 Takes as args the three things that every breakpoint must have.
1947 Returns the breakpoint object so caller can set other things.
1948 Does not set the breakpoint number!
1949 Does not print anything.
1951 ==> This routine should not be called if there is a chance of later
1952 error(); otherwise it leaves a bogus breakpoint on the chain. Validate
1953 your arguments BEFORE calling this routine! */
1955 static struct breakpoint
*
1956 set_raw_breakpoint (sal
)
1957 struct symtab_and_line sal
;
1959 register struct breakpoint
*b
, *b1
;
1961 b
= (struct breakpoint
*) xmalloc (sizeof (struct breakpoint
));
1962 memset (b
, 0, sizeof (*b
));
1963 b
->address
= sal
.pc
;
1964 if (sal
.symtab
== NULL
)
1965 b
->source_file
= NULL
;
1967 b
->source_file
= savestring (sal
.symtab
->filename
,
1968 strlen (sal
.symtab
->filename
));
1969 b
->language
= current_language
->la_language
;
1970 b
->input_radix
= input_radix
;
1972 b
->line_number
= sal
.line
;
1973 b
->enable
= enabled
;
1976 b
->ignore_count
= 0;
1980 /* Add this breakpoint to the end of the chain
1981 so that a list of breakpoints will come out in order
1982 of increasing numbers. */
1984 b1
= breakpoint_chain
;
1986 breakpoint_chain
= b
;
1994 check_duplicates (sal
.pc
);
1995 breakpoints_changed ();
2000 static int internal_breakpoint_number
= -1;
2002 #ifdef GET_LONGJMP_TARGET
2005 create_longjmp_breakpoint (func_name
)
2008 struct symtab_and_line sal
;
2009 struct breakpoint
*b
;
2011 if (func_name
!= NULL
)
2013 struct minimal_symbol
*m
;
2015 m
= lookup_minimal_symbol_text (func_name
, NULL
, (struct objfile
*)NULL
);
2017 sal
.pc
= SYMBOL_VALUE_ADDRESS (m
);
2027 b
= set_raw_breakpoint (sal
);
2030 b
->type
= func_name
!= NULL
? bp_longjmp
: bp_longjmp_resume
;
2031 b
->disposition
= donttouch
;
2032 b
->enable
= disabled
;
2035 b
->addr_string
= strsave(func_name
);
2036 b
->number
= internal_breakpoint_number
--;
2039 #endif /* #ifdef GET_LONGJMP_TARGET */
2041 /* Call this routine when stepping and nexting to enable a breakpoint if we do
2042 a longjmp(). When we hit that breakpoint, call
2043 set_longjmp_resume_breakpoint() to figure out where we are going. */
2046 enable_longjmp_breakpoint()
2048 register struct breakpoint
*b
;
2051 if (b
->type
== bp_longjmp
)
2053 b
->enable
= enabled
;
2054 check_duplicates (b
->address
);
2059 disable_longjmp_breakpoint()
2061 register struct breakpoint
*b
;
2064 if ( b
->type
== bp_longjmp
2065 || b
->type
== bp_longjmp_resume
)
2067 b
->enable
= disabled
;
2068 check_duplicates (b
->address
);
2074 remove_solib_event_breakpoints ()
2076 register struct breakpoint
*b
, *temp
;
2078 ALL_BREAKPOINTS_SAFE (b
, temp
)
2079 if (b
->type
== bp_shlib_event
)
2080 delete_breakpoint (b
);
2084 create_solib_event_breakpoint (address
)
2087 struct breakpoint
*b
;
2088 struct symtab_and_line sal
;
2093 b
= set_raw_breakpoint (sal
);
2094 b
->number
= internal_breakpoint_number
--;
2095 b
->disposition
= donttouch
;
2096 b
->type
= bp_shlib_event
;
2099 /* Try to reenable any breakpoints in shared libraries. */
2101 re_enable_breakpoints_in_shlibs ()
2103 struct breakpoint
*b
;
2106 if (b
->enable
== shlib_disabled
)
2110 /* Do not reenable the breakpoint if the shared library
2111 is still not mapped in. */
2112 if (target_read_memory (b
->address
, buf
, 1) == 0)
2113 b
->enable
= enabled
;
2120 hw_breakpoint_used_count()
2122 register struct breakpoint
*b
;
2127 if (b
->type
== bp_hardware_breakpoint
&& b
->enable
== enabled
)
2135 hw_watchpoint_used_count(type
, other_type_used
)
2137 int *other_type_used
;
2139 register struct breakpoint
*b
;
2142 *other_type_used
= 0;
2145 if (b
->enable
== enabled
)
2147 if (b
->type
== type
) i
++;
2148 else if ((b
->type
== bp_hardware_watchpoint
||
2149 b
->type
== bp_read_watchpoint
||
2150 b
->type
== bp_access_watchpoint
)
2151 && b
->enable
== enabled
)
2152 *other_type_used
= 1;
2158 /* Call this after hitting the longjmp() breakpoint. Use this to set a new
2159 breakpoint at the target of the jmp_buf.
2161 FIXME - This ought to be done by setting a temporary breakpoint that gets
2162 deleted automatically...
2166 set_longjmp_resume_breakpoint(pc
, frame
)
2168 struct frame_info
*frame
;
2170 register struct breakpoint
*b
;
2173 if (b
->type
== bp_longjmp_resume
)
2176 b
->enable
= enabled
;
2178 b
->frame
= frame
->frame
;
2181 check_duplicates (b
->address
);
2186 /* Set a breakpoint that will evaporate an end of command
2187 at address specified by SAL.
2188 Restrict it to frame FRAME if FRAME is nonzero. */
2191 set_momentary_breakpoint (sal
, frame
, type
)
2192 struct symtab_and_line sal
;
2193 struct frame_info
*frame
;
2196 register struct breakpoint
*b
;
2197 b
= set_raw_breakpoint (sal
);
2199 b
->enable
= enabled
;
2200 b
->disposition
= donttouch
;
2201 b
->frame
= (frame
? frame
->frame
: 0);
2203 /* If we're debugging a multi-threaded program, then we
2204 want momentary breakpoints to be active in only a
2205 single thread of control. */
2206 if (in_thread_list (inferior_pid
))
2207 b
->thread
= pid_to_thread_id (inferior_pid
);
2214 clear_momentary_breakpoints ()
2216 register struct breakpoint
*b
, *temp
;
2217 ALL_BREAKPOINTS_SAFE (b
, temp
)
2218 if (b
->disposition
== delete)
2220 delete_breakpoint (b
);
2226 /* Tell the user we have just set a breakpoint B. */
2230 struct breakpoint
*b
;
2234 /* FIXME: This is misplaced; mention() is called by things (like hitting a
2235 watchpoint) other than breakpoint creation. It should be possible to
2236 clean this up and at the same time replace the random calls to
2237 breakpoint_changed with this hook, as has already been done for
2238 delete_breakpoint_hook and so on. */
2239 if (create_breakpoint_hook
)
2240 create_breakpoint_hook (b
);
2245 printf_filtered ("Watchpoint %d: ", b
->number
);
2246 print_expression (b
->exp
, gdb_stdout
);
2248 case bp_hardware_watchpoint
:
2249 printf_filtered ("Hardware watchpoint %d: ", b
->number
);
2250 print_expression (b
->exp
, gdb_stdout
);
2252 case bp_read_watchpoint
:
2253 printf_filtered ("Hardware read watchpoint %d: ", b
->number
);
2254 print_expression (b
->exp
, gdb_stdout
);
2256 case bp_access_watchpoint
:
2257 printf_filtered ("Hardware access(read/write) watchpoint %d: ",b
->number
);
2258 print_expression (b
->exp
, gdb_stdout
);
2261 printf_filtered ("Breakpoint %d", b
->number
);
2264 case bp_hardware_breakpoint
:
2265 printf_filtered ("Hardware assisted breakpoint %d", b
->number
);
2271 case bp_longjmp_resume
:
2272 case bp_step_resume
:
2273 case bp_through_sigtramp
:
2275 case bp_watchpoint_scope
:
2276 case bp_shlib_event
:
2281 if (addressprint
|| b
->source_file
== NULL
)
2283 printf_filtered (" at ");
2284 print_address_numeric (b
->address
, 1, gdb_stdout
);
2287 printf_filtered (": file %s, line %d.",
2288 b
->source_file
, b
->line_number
);
2290 printf_filtered ("\n");
2294 /* Nobody calls this currently. */
2295 /* Set a breakpoint from a symtab and line.
2296 If TEMPFLAG is nonzero, it is a temporary breakpoint.
2297 ADDR_STRING is a malloc'd string holding the name of where we are
2298 setting the breakpoint. This is used later to re-set it after the
2299 program is relinked and symbols are reloaded.
2300 Print the same confirmation messages that the breakpoint command prints. */
2303 set_breakpoint (s
, line
, tempflag
, addr_string
)
2309 register struct breakpoint
*b
;
2310 struct symtab_and_line sal
;
2315 resolve_sal_pc (&sal
); /* Might error out */
2316 describe_other_breakpoints (sal
.pc
);
2318 b
= set_raw_breakpoint (sal
);
2319 set_breakpoint_count (breakpoint_count
+ 1);
2320 b
->number
= breakpoint_count
;
2321 b
->type
= bp_breakpoint
;
2323 b
->addr_string
= addr_string
;
2324 b
->enable
= enabled
;
2325 b
->disposition
= tempflag
? delete : donttouch
;
2331 /* Set a breakpoint according to ARG (function, linenum or *address)
2332 flag: first bit : 0 non-temporary, 1 temporary.
2333 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
2336 break_command_1 (arg
, flag
, from_tty
)
2340 int tempflag
, hardwareflag
;
2341 struct symtabs_and_lines sals
;
2342 struct symtab_and_line sal
;
2343 register struct expression
*cond
= 0;
2344 register struct breakpoint
*b
;
2346 /* Pointers in arg to the start, and one past the end, of the condition. */
2347 char *cond_start
= NULL
;
2348 char *cond_end
= NULL
;
2349 /* Pointers in arg to the start, and one past the end,
2350 of the address part. */
2351 char *addr_start
= NULL
;
2352 char *addr_end
= NULL
;
2353 struct cleanup
*old_chain
;
2354 struct cleanup
*canonical_strings_chain
= NULL
;
2355 char **canonical
= (char **)NULL
;
2359 hardwareflag
= flag
& BP_HARDWAREFLAG
;
2360 tempflag
= flag
& BP_TEMPFLAG
;
2365 sal
.line
= sal
.pc
= sal
.end
= 0;
2368 /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
2370 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
2371 && (arg
[2] == ' ' || arg
[2] == '\t')))
2373 if (default_breakpoint_valid
)
2375 sals
.sals
= (struct symtab_and_line
*)
2376 xmalloc (sizeof (struct symtab_and_line
));
2377 sal
.pc
= default_breakpoint_address
;
2378 sal
.line
= default_breakpoint_line
;
2379 sal
.symtab
= default_breakpoint_symtab
;
2384 error ("No default breakpoint address now.");
2390 /* Force almost all breakpoints to be in terms of the
2391 current_source_symtab (which is decode_line_1's default). This
2392 should produce the results we want almost all of the time while
2393 leaving default_breakpoint_* alone. */
2394 if (default_breakpoint_valid
2395 && (!current_source_symtab
2396 || (arg
&& (*arg
== '+' || *arg
== '-'))))
2397 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2398 default_breakpoint_line
, &canonical
);
2400 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
2408 /* Make sure that all storage allocated in decode_line_1 gets freed in case
2409 the following `for' loop errors out. */
2410 old_chain
= make_cleanup (free
, sals
.sals
);
2411 if (canonical
!= (char **)NULL
)
2413 make_cleanup (free
, canonical
);
2414 canonical_strings_chain
= make_cleanup (null_cleanup
, 0);
2415 for (i
= 0; i
< sals
.nelts
; i
++)
2417 if (canonical
[i
] != NULL
)
2418 make_cleanup (free
, canonical
[i
]);
2422 thread
= -1; /* No specific thread yet */
2424 /* Resolve all line numbers to PC's, and verify that conditions
2425 can be parsed, before setting any breakpoints. */
2426 for (i
= 0; i
< sals
.nelts
; i
++)
2428 char *tok
, *end_tok
;
2431 resolve_sal_pc (&sals
.sals
[i
]);
2437 while (*tok
== ' ' || *tok
== '\t')
2442 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2445 toklen
= end_tok
- tok
;
2447 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2449 tok
= cond_start
= end_tok
+ 1;
2450 cond
= parse_exp_1 (&tok
, block_for_pc (sals
.sals
[i
].pc
), 0);
2453 else if (toklen
>= 1 && strncmp (tok
, "thread", toklen
) == 0)
2459 thread
= strtol (tok
, &tok
, 0);
2461 error ("Junk after thread keyword.");
2462 if (!valid_thread_id (thread
))
2463 error ("Unknown thread %d\n", thread
);
2466 error ("Junk at end of arguments.");
2471 int i
, target_resources_ok
;
2473 i
= hw_breakpoint_used_count ();
2474 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT (
2475 bp_hardware_breakpoint
, i
+ sals
.nelts
, 0);
2476 if (target_resources_ok
== 0)
2477 error ("No hardware breakpoint support in the target.");
2478 else if (target_resources_ok
< 0)
2479 error ("Hardware breakpoints used exceeds limit.");
2482 /* Remove the canonical strings from the cleanup, they are needed below. */
2483 if (canonical
!= (char **)NULL
)
2484 discard_cleanups (canonical_strings_chain
);
2486 /* Now set all the breakpoints. */
2487 for (i
= 0; i
< sals
.nelts
; i
++)
2492 describe_other_breakpoints (sal
.pc
);
2494 b
= set_raw_breakpoint (sal
);
2495 set_breakpoint_count (breakpoint_count
+ 1);
2496 b
->number
= breakpoint_count
;
2497 b
->type
= hardwareflag
? bp_hardware_breakpoint
: bp_breakpoint
;
2501 /* If a canonical line spec is needed use that instead of the
2503 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
2504 b
->addr_string
= canonical
[i
];
2505 else if (addr_start
)
2506 b
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
2508 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2510 b
->enable
= enabled
;
2511 b
->disposition
= tempflag
? del
: donttouch
;
2518 printf_filtered ("Multiple breakpoints were set.\n");
2519 printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
2521 do_cleanups (old_chain
);
2524 /* Helper function for break_command_1 and disassemble_command. */
2527 resolve_sal_pc (sal
)
2528 struct symtab_and_line
*sal
;
2532 if (sal
->pc
== 0 && sal
->symtab
!= 0)
2534 pc
= find_line_pc (sal
->symtab
, sal
->line
);
2536 error ("No line %d in file \"%s\".",
2537 sal
->line
, sal
->symtab
->filename
);
2543 break_command (arg
, from_tty
)
2547 break_command_1 (arg
, 0, from_tty
);
2551 tbreak_command (arg
, from_tty
)
2555 break_command_1 (arg
, BP_TEMPFLAG
, from_tty
);
2559 hbreak_command (arg
, from_tty
)
2563 break_command_1 (arg
, BP_HARDWAREFLAG
, from_tty
);
2567 thbreak_command (arg
, from_tty
)
2571 break_command_1 (arg
, (BP_TEMPFLAG
| BP_HARDWAREFLAG
), from_tty
);
2575 /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write)
2578 watch_command_1 (arg
, accessflag
, from_tty
)
2583 struct breakpoint
*b
;
2584 struct symtab_and_line sal
;
2585 struct expression
*exp
;
2586 struct block
*exp_valid_block
;
2587 struct value
*val
, *mark
;
2588 struct frame_info
*frame
, *prev_frame
;
2589 char *exp_start
= NULL
;
2590 char *exp_end
= NULL
;
2591 char *tok
, *end_tok
;
2593 char *cond_start
= NULL
;
2594 char *cond_end
= NULL
;
2595 struct expression
*cond
= NULL
;
2596 int i
, other_type_used
, target_resources_ok
;
2597 enum bptype bp_type
;
2604 /* Parse arguments. */
2605 innermost_block
= NULL
;
2607 exp
= parse_exp_1 (&arg
, 0, 0);
2609 exp_valid_block
= innermost_block
;
2610 mark
= value_mark ();
2611 val
= evaluate_expression (exp
);
2612 release_value (val
);
2613 if (VALUE_LAZY (val
))
2614 value_fetch_lazy (val
);
2617 while (*tok
== ' ' || *tok
== '\t')
2621 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
2624 toklen
= end_tok
- tok
;
2625 if (toklen
>= 1 && strncmp (tok
, "if", toklen
) == 0)
2627 tok
= cond_start
= end_tok
+ 1;
2628 cond
= parse_exp_1 (&tok
, 0, 0);
2632 error("Junk at end of command.");
2634 if (accessflag
== 1) bp_type
= bp_read_watchpoint
;
2635 else if (accessflag
== 2) bp_type
= bp_access_watchpoint
;
2636 else bp_type
= bp_hardware_watchpoint
;
2638 mem_cnt
= can_use_hardware_watchpoint (val
);
2639 if (mem_cnt
== 0 && bp_type
!= bp_hardware_watchpoint
)
2640 error ("Expression cannot be implemented with read/access watchpoint.");
2642 i
= hw_watchpoint_used_count (bp_type
, &other_type_used
);
2643 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
2644 bp_type
, i
+ mem_cnt
, other_type_used
);
2645 if (target_resources_ok
== 0 && bp_type
!= bp_hardware_watchpoint
)
2646 error ("Target does not have this type of hardware watchpoint support.");
2647 if (target_resources_ok
< 0 && bp_type
!= bp_hardware_watchpoint
)
2648 error ("Target resources have been allocated for other types of watchpoints.");
2651 /* Now set up the breakpoint. */
2652 b
= set_raw_breakpoint (sal
);
2653 set_breakpoint_count (breakpoint_count
+ 1);
2654 b
->number
= breakpoint_count
;
2655 b
->disposition
= donttouch
;
2657 b
->exp_valid_block
= exp_valid_block
;
2658 b
->exp_string
= savestring (exp_start
, exp_end
- exp_start
);
2662 b
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
2666 frame
= block_innermost_frame (exp_valid_block
);
2669 prev_frame
= get_prev_frame (frame
);
2670 b
->watchpoint_frame
= frame
->frame
;
2673 b
->watchpoint_frame
= (CORE_ADDR
)0;
2675 if (mem_cnt
&& target_resources_ok
> 0)
2678 b
->type
= bp_watchpoint
;
2680 /* If the expression is "local", then set up a "watchpoint scope"
2681 breakpoint at the point where we've left the scope of the watchpoint
2683 if (innermost_block
)
2685 struct breakpoint
*scope_breakpoint
;
2686 struct symtab_and_line scope_sal
;
2690 scope_sal
.pc
= get_frame_pc (prev_frame
);
2691 scope_sal
.symtab
= NULL
;
2694 scope_breakpoint
= set_raw_breakpoint (scope_sal
);
2695 set_breakpoint_count (breakpoint_count
+ 1);
2696 scope_breakpoint
->number
= breakpoint_count
;
2698 scope_breakpoint
->type
= bp_watchpoint_scope
;
2699 scope_breakpoint
->enable
= enabled
;
2701 /* Automatically delete the breakpoint when it hits. */
2702 scope_breakpoint
->disposition
= del
;
2704 /* Only break in the proper frame (help with recursion). */
2705 scope_breakpoint
->frame
= prev_frame
->frame
;
2707 /* Set the address at which we will stop. */
2708 scope_breakpoint
->address
= get_frame_pc (prev_frame
);
2710 /* The scope breakpoint is related to the watchpoint. We
2711 will need to act on them together. */
2712 b
->related_breakpoint
= scope_breakpoint
;
2715 value_free_to_mark (mark
);
2719 /* Return count of locations need to be watched and can be handled
2720 in hardware. If the watchpoint can not be handled
2721 in hardware return zero. */
2724 can_use_hardware_watchpoint (v
)
2727 int found_memory_cnt
= 0;
2729 /* Make sure all the intermediate values are in memory. Also make sure
2730 we found at least one memory expression. Guards against watch 0x12345,
2731 which is meaningless, but could cause errors if one tries to insert a
2732 hardware watchpoint for the constant expression. */
2733 for ( ; v
; v
= v
->next
)
2735 if (v
->lval
== lval_memory
)
2737 if (TYPE_LENGTH (VALUE_TYPE (v
)) <= REGISTER_SIZE
)
2740 else if (v
->lval
!= not_lval
&& v
->modifiable
== 0)
2744 /* The expression itself looks suitable for using a hardware
2745 watchpoint, but give the target machine a chance to reject it. */
2746 return found_memory_cnt
;
2749 static void watch_command (arg
, from_tty
)
2753 watch_command_1 (arg
, 0, from_tty
);
2756 static void rwatch_command (arg
, from_tty
)
2760 watch_command_1 (arg
, 1, from_tty
);
2763 static void awatch_command (arg
, from_tty
)
2767 watch_command_1 (arg
, 2, from_tty
);
2771 /* Helper routine for the until_command routine in infcmd.c. Here
2772 because it uses the mechanisms of breakpoints. */
2776 until_break_command (arg
, from_tty
)
2780 struct symtabs_and_lines sals
;
2781 struct symtab_and_line sal
;
2782 struct frame_info
*prev_frame
= get_prev_frame (selected_frame
);
2783 struct breakpoint
*breakpoint
;
2784 struct cleanup
*old_chain
;
2786 clear_proceed_status ();
2788 /* Set a breakpoint where the user wants it and at return from
2791 if (default_breakpoint_valid
)
2792 sals
= decode_line_1 (&arg
, 1, default_breakpoint_symtab
,
2793 default_breakpoint_line
, (char ***)NULL
);
2795 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
2797 if (sals
.nelts
!= 1)
2798 error ("Couldn't get information on specified line.");
2801 free ((PTR
)sals
.sals
); /* malloc'd, so freed */
2804 error ("Junk at end of arguments.");
2806 resolve_sal_pc (&sal
);
2808 breakpoint
= set_momentary_breakpoint (sal
, selected_frame
, bp_until
);
2810 old_chain
= make_cleanup(delete_breakpoint
, breakpoint
);
2812 /* Keep within the current frame */
2816 sal
= find_pc_line (prev_frame
->pc
, 0);
2817 sal
.pc
= prev_frame
->pc
;
2818 breakpoint
= set_momentary_breakpoint (sal
, prev_frame
, bp_until
);
2819 make_cleanup(delete_breakpoint
, breakpoint
);
2822 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
2823 do_cleanups(old_chain
);
2827 /* These aren't used; I don't konw what they were for. */
2828 /* Set a breakpoint at the catch clause for NAME. */
2830 catch_breakpoint (name
)
2836 disable_catch_breakpoint ()
2841 delete_catch_breakpoint ()
2846 enable_catch_breakpoint ()
2853 struct sal_chain
*next
;
2854 struct symtab_and_line sal
;
2858 /* This isn't used; I don't know what it was for. */
2859 /* For each catch clause identified in ARGS, run FUNCTION
2860 with that clause as an argument. */
2861 static struct symtabs_and_lines
2862 map_catch_names (args
, function
)
2866 register char *p
= args
;
2868 struct symtabs_and_lines sals
;
2870 struct sal_chain
*sal_chain
= 0;
2874 error_no_arg ("one or more catch names");
2882 /* Don't swallow conditional part. */
2883 if (p1
[0] == 'i' && p1
[1] == 'f'
2884 && (p1
[2] == ' ' || p1
[2] == '\t'))
2890 while (isalnum (*p1
) || *p1
== '_' || *p1
== '$')
2894 if (*p1
&& *p1
!= ' ' && *p1
!= '\t')
2895 error ("Arguments must be catch names.");
2901 struct sal_chain
*next
2902 = (struct sal_chain
*)alloca (sizeof (struct sal_chain
));
2903 next
->next
= sal_chain
;
2904 next
->sal
= get_catch_sal (p
);
2909 printf_unfiltered ("No catch clause for exception %s.\n", p
);
2914 while (*p
== ' ' || *p
== '\t') p
++;
2919 /* This shares a lot of code with `print_frame_label_vars' from stack.c. */
2921 static struct symtabs_and_lines
2922 get_catch_sals (this_level_only
)
2923 int this_level_only
;
2925 register struct blockvector
*bl
;
2926 register struct block
*block
;
2927 int index
, have_default
= 0;
2929 struct symtabs_and_lines sals
;
2930 struct sal_chain
*sal_chain
= 0;
2931 char *blocks_searched
;
2933 /* Not sure whether an error message is always the correct response,
2934 but it's better than a core dump. */
2935 if (selected_frame
== NULL
)
2936 error ("No selected frame.");
2937 block
= get_frame_block (selected_frame
);
2938 pc
= selected_frame
->pc
;
2944 error ("No symbol table info available.\n");
2946 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
2947 blocks_searched
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2948 memset (blocks_searched
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
2952 CORE_ADDR end
= BLOCK_END (block
) - 4;
2955 if (bl
!= blockvector_for_pc (end
, &index
))
2956 error ("blockvector blotch");
2957 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
2958 error ("blockvector botch");
2959 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
2962 /* Don't print out blocks that have gone by. */
2963 while (index
< last_index
2964 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
2967 while (index
< last_index
2968 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
2970 if (blocks_searched
[index
] == 0)
2972 struct block
*b
= BLOCKVECTOR_BLOCK (bl
, index
);
2975 register struct symbol
*sym
;
2977 nsyms
= BLOCK_NSYMS (b
);
2979 for (i
= 0; i
< nsyms
; i
++)
2981 sym
= BLOCK_SYM (b
, i
);
2982 if (STREQ (SYMBOL_NAME (sym
), "default"))
2988 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
2990 struct sal_chain
*next
= (struct sal_chain
*)
2991 alloca (sizeof (struct sal_chain
));
2992 next
->next
= sal_chain
;
2993 next
->sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
2997 blocks_searched
[index
] = 1;
3003 if (sal_chain
&& this_level_only
)
3006 /* After handling the function's top-level block, stop.
3007 Don't continue to its superblock, the block of
3008 per-file symbols. */
3009 if (BLOCK_FUNCTION (block
))
3011 block
= BLOCK_SUPERBLOCK (block
);
3016 struct sal_chain
*tmp_chain
;
3018 /* Count the number of entries. */
3019 for (index
= 0, tmp_chain
= sal_chain
; tmp_chain
;
3020 tmp_chain
= tmp_chain
->next
)
3024 sals
.sals
= (struct symtab_and_line
*)
3025 xmalloc (index
* sizeof (struct symtab_and_line
));
3026 for (index
= 0; sal_chain
; sal_chain
= sal_chain
->next
, index
++)
3027 sals
.sals
[index
] = sal_chain
->sal
;
3033 /* Commands to deal with catching exceptions. */
3036 catch_command_1 (arg
, tempflag
, from_tty
)
3041 /* First, translate ARG into something we can deal with in terms
3044 struct symtabs_and_lines sals
;
3045 struct symtab_and_line sal
;
3046 register struct expression
*cond
= 0;
3047 register struct breakpoint
*b
;
3051 sal
.line
= sal
.pc
= sal
.end
= 0;
3054 /* If no arg given, or if first arg is 'if ', all active catch clauses
3055 are breakpointed. */
3057 if (!arg
|| (arg
[0] == 'i' && arg
[1] == 'f'
3058 && (arg
[2] == ' ' || arg
[2] == '\t')))
3060 /* Grab all active catch clauses. */
3061 sals
= get_catch_sals (0);
3065 /* Grab selected catch clauses. */
3066 error ("catch NAME not implemented");
3068 /* This isn't used; I don't know what it was for. */
3069 sals
= map_catch_names (arg
, catch_breakpoint
);
3077 for (i
= 0; i
< sals
.nelts
; i
++)
3079 resolve_sal_pc (&sals
.sals
[i
]);
3083 if (arg
[0] == 'i' && arg
[1] == 'f'
3084 && (arg
[2] == ' ' || arg
[2] == '\t'))
3085 cond
= parse_exp_1 ((arg
+= 2, &arg
),
3086 block_for_pc (sals
.sals
[i
].pc
), 0);
3088 error ("Junk at end of arguments.");
3093 for (i
= 0; i
< sals
.nelts
; i
++)
3098 describe_other_breakpoints (sal
.pc
);
3100 b
= set_raw_breakpoint (sal
);
3101 set_breakpoint_count (breakpoint_count
+ 1);
3102 b
->number
= breakpoint_count
;
3103 b
->type
= bp_breakpoint
;
3105 b
->enable
= enabled
;
3106 b
->disposition
= tempflag
? del
: donttouch
;
3113 printf_unfiltered ("Multiple breakpoints were set.\n");
3114 printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n");
3116 free ((PTR
)sals
.sals
);
3119 /* Used by the gui, could be made a worker for other things. */
3122 set_breakpoint_sal (sal
)
3123 struct symtab_and_line sal
;
3125 struct breakpoint
*b
;
3126 b
= set_raw_breakpoint (sal
);
3127 set_breakpoint_count (breakpoint_count
+ 1);
3128 b
->number
= breakpoint_count
;
3129 b
->type
= bp_breakpoint
;
3136 /* These aren't used; I don't know what they were for. */
3137 /* Disable breakpoints on all catch clauses described in ARGS. */
3139 disable_catch (args
)
3142 /* Map the disable command to catch clauses described in ARGS. */
3145 /* Enable breakpoints on all catch clauses described in ARGS. */
3150 /* Map the disable command to catch clauses described in ARGS. */
3153 /* Delete breakpoints on all catch clauses in the active scope. */
3158 /* Map the delete command to catch clauses described in ARGS. */
3163 catch_command (arg
, from_tty
)
3167 catch_command_1 (arg
, 0, from_tty
);
3171 clear_command (arg
, from_tty
)
3175 register struct breakpoint
*b
, *b1
;
3176 struct symtabs_and_lines sals
;
3177 struct symtab_and_line sal
;
3178 register struct breakpoint
*found
;
3183 sals
= decode_line_spec (arg
, 1);
3187 sals
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (struct symtab_and_line
));
3188 sal
.line
= default_breakpoint_line
;
3189 sal
.symtab
= default_breakpoint_symtab
;
3191 if (sal
.symtab
== 0)
3192 error ("No source file specified.");
3198 for (i
= 0; i
< sals
.nelts
; i
++)
3200 /* If exact pc given, clear bpts at that pc.
3201 But if sal.pc is zero, clear all bpts on specified line. */
3203 found
= (struct breakpoint
*) 0;
3204 while (breakpoint_chain
3206 ? breakpoint_chain
->address
== sal
.pc
3207 : (breakpoint_chain
->source_file
!= NULL
3208 && sal
.symtab
!= NULL
3209 && STREQ (breakpoint_chain
->source_file
,
3210 sal
.symtab
->filename
)
3211 && breakpoint_chain
->line_number
== sal
.line
)))
3213 b1
= breakpoint_chain
;
3214 breakpoint_chain
= b1
->next
;
3221 && b
->next
->type
!= bp_watchpoint
3222 && b
->next
->type
!= bp_hardware_watchpoint
3223 && b
->next
->type
!= bp_read_watchpoint
3224 && b
->next
->type
!= bp_access_watchpoint
3226 ? b
->next
->address
== sal
.pc
3227 : (b
->next
->source_file
!= NULL
3228 && sal
.symtab
!= NULL
3229 && STREQ (b
->next
->source_file
, sal
.symtab
->filename
)
3230 && b
->next
->line_number
== sal
.line
)))
3241 error ("No breakpoint at %s.", arg
);
3243 error ("No breakpoint at this line.");
3246 if (found
->next
) from_tty
= 1; /* Always report if deleted more than one */
3247 if (from_tty
) printf_unfiltered ("Deleted breakpoint%s ", found
->next
? "s" : "");
3248 breakpoints_changed ();
3251 if (from_tty
) printf_unfiltered ("%d ", found
->number
);
3253 delete_breakpoint (found
);
3256 if (from_tty
) putchar_unfiltered ('\n');
3258 free ((PTR
)sals
.sals
);
3261 /* Delete breakpoint in BS if they are `delete' breakpoints and
3262 all breakpoints that are marked for deletion, whether hit or not.
3263 This is called after any breakpoint is hit, or after errors. */
3266 breakpoint_auto_delete (bs
)
3269 struct breakpoint
*b
, *temp
;
3271 for (; bs
; bs
= bs
->next
)
3272 if (bs
->breakpoint_at
&& bs
->breakpoint_at
->disposition
== del
3274 delete_breakpoint (bs
->breakpoint_at
);
3276 ALL_BREAKPOINTS_SAFE (b
, temp
)
3278 if (b
->disposition
== del_at_next_stop
)
3279 delete_breakpoint (b
);
3283 /* Delete a breakpoint and clean up all traces of it in the data structures. */
3286 delete_breakpoint (bpt
)
3287 struct breakpoint
*bpt
;
3289 register struct breakpoint
*b
;
3292 if (delete_breakpoint_hook
)
3293 delete_breakpoint_hook (bpt
);
3296 remove_breakpoint (bpt
);
3298 if (breakpoint_chain
== bpt
)
3299 breakpoint_chain
= bpt
->next
;
3304 b
->next
= bpt
->next
;
3308 check_duplicates (bpt
->address
);
3309 /* If this breakpoint was inserted, and there is another breakpoint
3310 at the same address, we need to insert the other breakpoint. */
3312 && bpt
->type
!= bp_hardware_watchpoint
3313 && bpt
->type
!= bp_read_watchpoint
3314 && bpt
->type
!= bp_access_watchpoint
)
3317 if (b
->address
== bpt
->address
3319 && b
->enable
!= disabled
3320 && b
->enable
!= shlib_disabled
)
3323 val
= target_insert_breakpoint (b
->address
, b
->shadow_contents
);
3326 target_terminal_ours_for_output ();
3327 fprintf_unfiltered (gdb_stderr
, "Cannot insert breakpoint %d:\n", b
->number
);
3328 memory_error (val
, b
->address
); /* which bombs us out */
3335 free_command_lines (&bpt
->commands
);
3338 if (bpt
->cond_string
!= NULL
)
3339 free (bpt
->cond_string
);
3340 if (bpt
->addr_string
!= NULL
)
3341 free (bpt
->addr_string
);
3342 if (bpt
->exp
!= NULL
)
3344 if (bpt
->exp_string
!= NULL
)
3345 free (bpt
->exp_string
);
3346 if (bpt
->val
!= NULL
)
3347 value_free (bpt
->val
);
3348 if (bpt
->source_file
!= NULL
)
3349 free (bpt
->source_file
);
3351 /* Be sure no bpstat's are pointing at it after it's been freed. */
3352 /* FIXME, how can we find all bpstat's?
3353 We just check stop_bpstat for now. */
3354 for (bs
= stop_bpstat
; bs
; bs
= bs
->next
)
3355 if (bs
->breakpoint_at
== bpt
)
3356 bs
->breakpoint_at
= NULL
;
3361 delete_command (arg
, from_tty
)
3368 /* Ask user only if there are some breakpoints to delete. */
3370 || (breakpoint_chain
&& query ("Delete all breakpoints? ")))
3372 /* No arg; clear all breakpoints. */
3373 while (breakpoint_chain
)
3374 delete_breakpoint (breakpoint_chain
);
3378 map_breakpoint_numbers (arg
, delete_breakpoint
);
3381 /* Reset a breakpoint given it's struct breakpoint * BINT.
3382 The value we return ends up being the return value from catch_errors.
3383 Unused in this case. */
3386 breakpoint_re_set_one (bint
)
3389 struct breakpoint
*b
= (struct breakpoint
*)bint
; /* get past catch_errs */
3392 struct symtabs_and_lines sals
;
3394 enum enable save_enable
;
3399 case bp_hardware_breakpoint
:
3400 if (b
->addr_string
== NULL
)
3402 /* Anything without a string can't be re-set. */
3403 delete_breakpoint (b
);
3406 /* In case we have a problem, disable this breakpoint. We'll restore
3407 its status if we succeed. */
3408 save_enable
= b
->enable
;
3409 b
->enable
= disabled
;
3411 set_language (b
->language
);
3412 input_radix
= b
->input_radix
;
3414 sals
= decode_line_1 (&s
, 1, (struct symtab
*)NULL
, 0, (char ***)NULL
);
3415 for (i
= 0; i
< sals
.nelts
; i
++)
3417 resolve_sal_pc (&sals
.sals
[i
]);
3419 /* Reparse conditions, they might contain references to the
3421 if (b
->cond_string
!= NULL
)
3425 free ((PTR
)b
->cond
);
3426 b
->cond
= parse_exp_1 (&s
, block_for_pc (sals
.sals
[i
].pc
), 0);
3429 /* We need to re-set the breakpoint if the address changes...*/
3430 if (b
->address
!= sals
.sals
[i
].pc
3431 /* ...or new and old breakpoints both have source files, and
3432 the source file name or the line number changes... */
3433 || (b
->source_file
!= NULL
3434 && sals
.sals
[i
].symtab
!= NULL
3435 && (!STREQ (b
->source_file
, sals
.sals
[i
].symtab
->filename
)
3436 || b
->line_number
!= sals
.sals
[i
].line
)
3438 /* ...or we switch between having a source file and not having
3440 || ((b
->source_file
== NULL
) != (sals
.sals
[i
].symtab
== NULL
))
3443 if (b
->source_file
!= NULL
)
3444 free (b
->source_file
);
3445 if (sals
.sals
[i
].symtab
== NULL
)
3446 b
->source_file
= NULL
;
3449 savestring (sals
.sals
[i
].symtab
->filename
,
3450 strlen (sals
.sals
[i
].symtab
->filename
));
3451 b
->line_number
= sals
.sals
[i
].line
;
3452 b
->address
= sals
.sals
[i
].pc
;
3454 check_duplicates (b
->address
);
3458 /* Might be better to do this just once per breakpoint_re_set,
3459 rather than once for every breakpoint. */
3460 breakpoints_changed ();
3462 b
->enable
= save_enable
; /* Restore it, this worked. */
3464 free ((PTR
)sals
.sals
);
3468 case bp_hardware_watchpoint
:
3469 case bp_read_watchpoint
:
3470 case bp_access_watchpoint
:
3471 innermost_block
= NULL
;
3472 /* The issue arises of what context to evaluate this in. The same
3473 one as when it was set, but what does that mean when symbols have
3474 been re-read? We could save the filename and functionname, but
3475 if the context is more local than that, the best we could do would
3476 be something like how many levels deep and which index at that
3477 particular level, but that's going to be less stable than filenames
3478 or functionnames. */
3479 /* So for now, just use a global context. */
3482 b
->exp
= parse_expression (b
->exp_string
);
3483 b
->exp_valid_block
= innermost_block
;
3484 mark
= value_mark ();
3486 value_free (b
->val
);
3487 b
->val
= evaluate_expression (b
->exp
);
3488 release_value (b
->val
);
3489 if (VALUE_LAZY (b
->val
))
3490 value_fetch_lazy (b
->val
);
3492 if (b
->cond_string
!= NULL
)
3496 free ((PTR
)b
->cond
);
3497 b
->cond
= parse_exp_1 (&s
, (struct block
*)0, 0);
3499 if (b
->enable
== enabled
)
3501 value_free_to_mark (mark
);
3505 printf_filtered ("Deleting unknown breakpoint type %d\n", b
->type
);
3507 /* Delete longjmp breakpoints, they will be reset later by
3508 breakpoint_re_set. */
3510 case bp_longjmp_resume
:
3511 delete_breakpoint (b
);
3514 /* This breakpoint is special, it's set up when the inferior
3515 starts and we really don't want to touch it. */
3516 case bp_shlib_event
:
3518 /* Keep temporary breakpoints, which can be encountered when we step
3519 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
3520 Otherwise these should have been blown away via the cleanup chain
3521 or by breakpoint_init_inferior when we rerun the executable. */
3524 case bp_watchpoint_scope
:
3526 case bp_step_resume
:
3533 /* Re-set all breakpoints after symbols have been re-loaded. */
3535 breakpoint_re_set ()
3537 struct breakpoint
*b
, *temp
;
3538 enum language save_language
;
3539 int save_input_radix
;
3540 static char message1
[] = "Error in re-setting breakpoint %d:\n";
3541 char message
[sizeof (message1
) + 30 /* slop */];
3543 save_language
= current_language
->la_language
;
3544 save_input_radix
= input_radix
;
3545 ALL_BREAKPOINTS_SAFE (b
, temp
)
3547 sprintf (message
, message1
, b
->number
); /* Format possible error msg */
3548 catch_errors (breakpoint_re_set_one
, (char *) b
, message
,
3551 set_language (save_language
);
3552 input_radix
= save_input_radix
;
3554 #ifdef GET_LONGJMP_TARGET
3555 create_longjmp_breakpoint ("longjmp");
3556 create_longjmp_breakpoint ("_longjmp");
3557 create_longjmp_breakpoint ("siglongjmp");
3558 create_longjmp_breakpoint (NULL
);
3562 /* Took this out (temporarily at least), since it produces an extra
3563 blank line at startup. This messes up the gdbtests. -PB */
3564 /* Blank line to finish off all those mention() messages we just printed. */
3565 printf_filtered ("\n");
3569 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
3570 If from_tty is nonzero, it prints a message to that effect,
3571 which ends with a period (no newline). */
3574 set_ignore_count (bptnum
, count
, from_tty
)
3575 int bptnum
, count
, from_tty
;
3577 register struct breakpoint
*b
;
3583 if (b
->number
== bptnum
)
3585 b
->ignore_count
= count
;
3588 else if (count
== 0)
3589 printf_filtered ("Will stop next time breakpoint %d is reached.",
3591 else if (count
== 1)
3592 printf_filtered ("Will ignore next crossing of breakpoint %d.",
3595 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
3597 breakpoints_changed ();
3601 error ("No breakpoint number %d.", bptnum
);
3604 /* Clear the ignore counts of all breakpoints. */
3606 breakpoint_clear_ignore_counts ()
3608 struct breakpoint
*b
;
3611 b
->ignore_count
= 0;
3614 /* Command to set ignore-count of breakpoint N to COUNT. */
3617 ignore_command (args
, from_tty
)
3625 error_no_arg ("a breakpoint number");
3627 num
= get_number (&p
);
3630 error ("Second argument (specified ignore-count) is missing.");
3632 set_ignore_count (num
,
3633 longest_to_int (value_as_long (parse_and_eval (p
))),
3635 printf_filtered ("\n");
3636 breakpoints_changed ();
3639 /* Call FUNCTION on each of the breakpoints
3640 whose numbers are given in ARGS. */
3643 map_breakpoint_numbers (args
, function
)
3645 void (*function
) PARAMS ((struct breakpoint
*));
3647 register char *p
= args
;
3650 register struct breakpoint
*b
;
3653 error_no_arg ("one or more breakpoint numbers");
3659 num
= get_number (&p1
);
3662 if (b
->number
== num
)
3664 struct breakpoint
*related_breakpoint
= b
->related_breakpoint
;
3666 if (related_breakpoint
)
3667 function (related_breakpoint
);
3670 printf_unfiltered ("No breakpoint number %d.\n", num
);
3677 enable_breakpoint (bpt
)
3678 struct breakpoint
*bpt
;
3680 struct frame_info
*save_selected_frame
= NULL
;
3681 int save_selected_frame_level
= -1;
3682 int target_resources_ok
, other_type_used
;
3685 if (bpt
->type
== bp_hardware_breakpoint
)
3688 i
= hw_breakpoint_used_count();
3689 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3690 bp_hardware_breakpoint
, i
+1, 0);
3691 if (target_resources_ok
== 0)
3692 error ("No hardware breakpoint support in the target.");
3693 else if (target_resources_ok
< 0)
3694 error ("Hardware breakpoints used exceeds limit.");
3696 bpt
->enable
= enabled
;
3697 check_duplicates (bpt
->address
);
3699 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3700 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3702 if (bpt
->exp_valid_block
!= NULL
)
3704 struct frame_info
*fr
=
3705 find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3709 Cannot enable watchpoint %d because the block in which its expression\n\
3710 is valid is not currently in scope.\n", bpt
->number
);
3711 bpt
->enable
= disabled
;
3715 save_selected_frame
= selected_frame
;
3716 save_selected_frame_level
= selected_frame_level
;
3717 select_frame (fr
, -1);
3720 value_free (bpt
->val
);
3721 mark
= value_mark ();
3722 bpt
->val
= evaluate_expression (bpt
->exp
);
3723 release_value (bpt
->val
);
3724 if (VALUE_LAZY (bpt
->val
))
3725 value_fetch_lazy (bpt
->val
);
3727 if (bpt
->type
== bp_hardware_watchpoint
||
3728 bpt
->type
== bp_read_watchpoint
||
3729 bpt
->type
== bp_access_watchpoint
)
3731 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3732 int mem_cnt
= can_use_hardware_watchpoint (bpt
->val
);
3734 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3735 bpt
->type
, i
+ mem_cnt
, other_type_used
);
3736 /* we can consider of type is bp_hardware_watchpoint, convert to
3737 bp_watchpoint in the following condition */
3738 if (target_resources_ok
< 0)
3741 Cannot enable watchpoint %d because target watch resources\n\
3742 have been allocated for other watchpoints.\n", bpt
->number
);
3743 bpt
->enable
= disabled
;
3744 value_free_to_mark (mark
);
3749 if (save_selected_frame_level
>= 0)
3750 select_frame (save_selected_frame
, save_selected_frame_level
);
3751 value_free_to_mark (mark
);
3754 if (modify_breakpoint_hook
)
3755 modify_breakpoint_hook (bpt
);
3760 enable_command (args
, from_tty
)
3764 struct breakpoint
*bpt
;
3766 ALL_BREAKPOINTS (bpt
)
3770 case bp_hardware_breakpoint
:
3772 case bp_hardware_watchpoint
:
3773 case bp_read_watchpoint
:
3774 case bp_access_watchpoint
:
3775 enable_breakpoint (bpt
);
3780 map_breakpoint_numbers (args
, enable_breakpoint
);
3784 disable_breakpoint (bpt
)
3785 struct breakpoint
*bpt
;
3787 /* Never disable a watchpoint scope breakpoint; we want to
3788 hit them when we leave scope so we can delete both the
3789 watchpoint and its scope breakpoint at that time. */
3790 if (bpt
->type
== bp_watchpoint_scope
)
3793 bpt
->enable
= disabled
;
3795 check_duplicates (bpt
->address
);
3797 if (modify_breakpoint_hook
)
3798 modify_breakpoint_hook (bpt
);
3803 disable_command (args
, from_tty
)
3807 register struct breakpoint
*bpt
;
3809 ALL_BREAKPOINTS (bpt
)
3813 case bp_hardware_breakpoint
:
3815 case bp_hardware_watchpoint
:
3816 case bp_read_watchpoint
:
3817 case bp_access_watchpoint
:
3818 disable_breakpoint (bpt
);
3823 map_breakpoint_numbers (args
, disable_breakpoint
);
3827 enable_once_breakpoint (bpt
)
3828 struct breakpoint
*bpt
;
3830 struct frame_info
*save_selected_frame
= NULL
;
3831 int save_selected_frame_level
= -1;
3832 int target_resources_ok
, other_type_used
;
3835 if (bpt
->type
== bp_hardware_breakpoint
)
3838 i
= hw_breakpoint_used_count();
3839 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3840 bp_hardware_breakpoint
, i
+1, 0);
3841 if (target_resources_ok
== 0)
3842 error ("No hardware breakpoint support in the target.");
3843 else if (target_resources_ok
< 0)
3844 error ("Hardware breakpoints used exceeds limit.");
3847 bpt
->enable
= enabled
;
3848 bpt
->disposition
= disable
;
3849 check_duplicates (bpt
->address
);
3850 breakpoints_changed ();
3852 if (bpt
->type
== bp_watchpoint
|| bpt
->type
== bp_hardware_watchpoint
||
3853 bpt
->type
== bp_read_watchpoint
|| bpt
->type
== bp_access_watchpoint
)
3855 if (bpt
->exp_valid_block
!= NULL
)
3857 struct frame_info
*fr
=
3858 find_frame_addr_in_frame_chain (bpt
->watchpoint_frame
);
3862 Cannot enable watchpoint %d because the block in which its expression\n\
3863 is valid is not currently in scope.\n", bpt
->number
);
3864 bpt
->enable
= disabled
;
3868 save_selected_frame
= selected_frame
;
3869 save_selected_frame_level
= selected_frame_level
;
3870 select_frame (fr
, -1);
3873 value_free (bpt
->val
);
3874 mark
= value_mark ();
3875 bpt
->val
= evaluate_expression (bpt
->exp
);
3876 release_value (bpt
->val
);
3877 if (VALUE_LAZY (bpt
->val
))
3878 value_fetch_lazy (bpt
->val
);
3880 if (bpt
->type
== bp_hardware_watchpoint
||
3881 bpt
->type
== bp_read_watchpoint
||
3882 bpt
->type
== bp_access_watchpoint
)
3884 int i
= hw_watchpoint_used_count (bpt
->type
, &other_type_used
);
3885 int mem_cnt
= can_use_hardware_watchpoint(bpt
->val
);
3886 target_resources_ok
= TARGET_CAN_USE_HARDWARE_WATCHPOINT(
3887 bpt
->type
, i
+mem_cnt
, other_type_used
);
3888 /* we can consider of type is bp_hardware_watchpoint, convert to
3889 bp_watchpoint in the following condition */
3890 if (target_resources_ok
< 0)
3893 Cannot enable watchpoint %d because target watch resources\n\
3894 have been allocated for other watchpoints.\n", bpt
->number
);
3895 bpt
->enable
= disabled
;
3896 value_free_to_mark (mark
);
3900 if (save_selected_frame_level
>= 0)
3901 select_frame (save_selected_frame
, save_selected_frame_level
);
3902 value_free_to_mark (mark
);
3908 enable_once_command (args
, from_tty
)
3912 map_breakpoint_numbers (args
, enable_once_breakpoint
);
3916 enable_delete_breakpoint (bpt
)
3917 struct breakpoint
*bpt
;
3919 bpt
->enable
= enabled
;
3920 bpt
->disposition
= del
;
3922 check_duplicates (bpt
->address
);
3923 breakpoints_changed ();
3928 enable_delete_command (args
, from_tty
)
3932 map_breakpoint_numbers (args
, enable_delete_breakpoint
);
3935 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
3937 struct symtabs_and_lines
3938 decode_line_spec_1 (string
, funfirstline
)
3942 struct symtabs_and_lines sals
;
3944 error ("Empty line specification.");
3945 if (default_breakpoint_valid
)
3946 sals
= decode_line_1 (&string
, funfirstline
,
3947 default_breakpoint_symtab
, default_breakpoint_line
,
3950 sals
= decode_line_1 (&string
, funfirstline
,
3951 (struct symtab
*)NULL
, 0, (char ***)NULL
);
3953 error ("Junk at end of line specification: %s", string
);
3958 _initialize_breakpoint ()
3960 breakpoint_chain
= 0;
3961 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
3962 before a breakpoint is set. */
3963 breakpoint_count
= 0;
3965 add_com ("ignore", class_breakpoint
, ignore_command
,
3966 "Set ignore-count of breakpoint number N to COUNT.\n\
3967 Usage is `ignore N COUNT'.");
3969 add_com ("commands", class_breakpoint
, commands_command
,
3970 "Set commands to be executed when a breakpoint is hit.\n\
3971 Give breakpoint number as argument after \"commands\".\n\
3972 With no argument, the targeted breakpoint is the last one set.\n\
3973 The commands themselves follow starting on the next line.\n\
3974 Type a line containing \"end\" to indicate the end of them.\n\
3975 Give \"silent\" as the first line to make the breakpoint silent;\n\
3976 then no output is printed when it is hit, except what the commands print.");
3978 add_com ("condition", class_breakpoint
, condition_command
,
3979 "Specify breakpoint number N to break only if COND is true.\n\
3980 Usage is `condition N COND', where N is an integer and COND is an\n\
3981 expression to be evaluated whenever breakpoint N is reached. ");
3983 add_com ("tbreak", class_breakpoint
, tbreak_command
,
3984 "Set a temporary breakpoint. Args like \"break\" command.\n\
3985 Like \"break\" except the breakpoint is only temporary,\n\
3986 so it will be deleted when hit. Equivalent to \"break\" followed\n\
3987 by using \"enable delete\" on the breakpoint number.");
3989 add_com ("hbreak", class_breakpoint
, hbreak_command
,
3990 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
3991 Like \"break\" except the breakpoint requires hardware support,\n\
3992 some target hardware may not have this support.");
3994 add_com ("thbreak", class_breakpoint
, thbreak_command
,
3995 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
3996 Like \"hbreak\" except the breakpoint is only temporary,\n\
3997 so it will be deleted when hit.");
3999 add_prefix_cmd ("enable", class_breakpoint
, enable_command
,
4000 "Enable some breakpoints.\n\
4001 Give breakpoint numbers (separated by spaces) as arguments.\n\
4002 With no subcommand, breakpoints are enabled until you command otherwise.\n\
4003 This is used to cancel the effect of the \"disable\" command.\n\
4004 With a subcommand you can enable temporarily.",
4005 &enablelist
, "enable ", 1, &cmdlist
);
4007 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint
, enable_command
,
4008 "Enable some breakpoints.\n\
4009 Give breakpoint numbers (separated by spaces) as arguments.\n\
4010 This is used to cancel the effect of the \"disable\" command.\n\
4011 May be abbreviated to simply \"enable\".\n",
4012 &enablebreaklist
, "enable breakpoints ", 1, &enablelist
);
4014 add_cmd ("once", no_class
, enable_once_command
,
4015 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
4016 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
4019 add_cmd ("delete", no_class
, enable_delete_command
,
4020 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
4021 If a breakpoint is hit while enabled in this fashion, it is deleted.",
4024 add_cmd ("delete", no_class
, enable_delete_command
,
4025 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
4026 If a breakpoint is hit while enabled in this fashion, it is deleted.",
4029 add_cmd ("once", no_class
, enable_once_command
,
4030 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
4031 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
4034 add_prefix_cmd ("disable", class_breakpoint
, disable_command
,
4035 "Disable some breakpoints.\n\
4036 Arguments are breakpoint numbers with spaces in between.\n\
4037 To disable all breakpoints, give no argument.\n\
4038 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
4039 &disablelist
, "disable ", 1, &cmdlist
);
4040 add_com_alias ("dis", "disable", class_breakpoint
, 1);
4041 add_com_alias ("disa", "disable", class_breakpoint
, 1);
4043 add_cmd ("breakpoints", class_alias
, disable_command
,
4044 "Disable some breakpoints.\n\
4045 Arguments are breakpoint numbers with spaces in between.\n\
4046 To disable all breakpoints, give no argument.\n\
4047 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
4048 This command may be abbreviated \"disable\".",
4051 add_prefix_cmd ("delete", class_breakpoint
, delete_command
,
4052 "Delete some breakpoints or auto-display expressions.\n\
4053 Arguments are breakpoint numbers with spaces in between.\n\
4054 To delete all breakpoints, give no argument.\n\
4056 Also a prefix command for deletion of other GDB objects.\n\
4057 The \"unset\" command is also an alias for \"delete\".",
4058 &deletelist
, "delete ", 1, &cmdlist
);
4059 add_com_alias ("d", "delete", class_breakpoint
, 1);
4061 add_cmd ("breakpoints", class_alias
, delete_command
,
4062 "Delete some breakpoints or auto-display expressions.\n\
4063 Arguments are breakpoint numbers with spaces in between.\n\
4064 To delete all breakpoints, give no argument.\n\
4065 This command may be abbreviated \"delete\".",
4068 add_com ("clear", class_breakpoint
, clear_command
,
4069 concat ("Clear breakpoint at specified line or function.\n\
4070 Argument may be line number, function name, or \"*\" and an address.\n\
4071 If line number is specified, all breakpoints in that line are cleared.\n\
4072 If function is specified, breakpoints at beginning of function are cleared.\n\
4073 If an address is specified, breakpoints at that address are cleared.\n\n",
4074 "With no argument, clears all breakpoints in the line that the selected frame\n\
4077 See also the \"delete\" command which clears breakpoints by number.", NULL
));
4079 add_com ("break", class_breakpoint
, break_command
,
4080 concat ("Set breakpoint at specified line or function.\n\
4081 Argument may be line number, function name, or \"*\" and an address.\n\
4082 If line number is specified, break at start of code for that line.\n\
4083 If function is specified, break at start of code for that function.\n\
4084 If an address is specified, break at that exact address.\n",
4085 "With no arg, uses current execution address of selected stack frame.\n\
4086 This is useful for breaking on return to a stack frame.\n\
4088 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
4090 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL
));
4091 add_com_alias ("b", "break", class_run
, 1);
4092 add_com_alias ("br", "break", class_run
, 1);
4093 add_com_alias ("bre", "break", class_run
, 1);
4094 add_com_alias ("brea", "break", class_run
, 1);
4096 add_info ("breakpoints", breakpoints_info
,
4097 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
4098 The \"Type\" column indicates one of:\n\
4099 \tbreakpoint - normal breakpoint\n\
4100 \twatchpoint - watchpoint\n\
4101 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
4102 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4103 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
4104 address and file/line number respectively.\n\n",
4105 "Convenience variable \"$_\" and default examine address for \"x\"\n\
4106 are set to the address of the last breakpoint listed.\n\n\
4107 Convenience variable \"$bpnum\" contains the number of the last\n\
4108 breakpoint set.", NULL
));
4110 #if MAINTENANCE_CMDS
4112 add_cmd ("breakpoints", class_maintenance
, maintenance_info_breakpoints
,
4113 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
4114 The \"Type\" column indicates one of:\n\
4115 \tbreakpoint - normal breakpoint\n\
4116 \twatchpoint - watchpoint\n\
4117 \tlongjmp - internal breakpoint used to step through longjmp()\n\
4118 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
4119 \tuntil - internal breakpoint used by the \"until\" command\n\
4120 \tfinish - internal breakpoint used by the \"finish\" command\n",
4121 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
4122 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
4123 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
4124 address and file/line number respectively.\n\n",
4125 "Convenience variable \"$_\" and default examine address for \"x\"\n\
4126 are set to the address of the last breakpoint listed.\n\n\
4127 Convenience variable \"$bpnum\" contains the number of the last\n\
4128 breakpoint set.", NULL
),
4129 &maintenanceinfolist
);
4131 #endif /* MAINTENANCE_CMDS */
4133 add_com ("catch", class_breakpoint
, catch_command
,
4134 "Set breakpoints to catch exceptions that are raised.\n\
4135 Argument may be a single exception to catch, multiple exceptions\n\
4136 to catch, or the default exception \"default\". If no arguments\n\
4137 are given, breakpoints are set at all exception handlers catch clauses\n\
4138 within the current scope.\n\
4140 A condition specified for the catch applies to all breakpoints set\n\
4141 with this command\n\
4143 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
4145 add_com ("watch", class_breakpoint
, watch_command
,
4146 "Set a watchpoint for an expression.\n\
4147 A watchpoint stops execution of your program whenever the value of\n\
4148 an expression changes.");
4150 add_com ("rwatch", class_breakpoint
, rwatch_command
,
4151 "Set a read watchpoint for an expression.\n\
4152 A watchpoint stops execution of your program whenever the value of\n\
4153 an expression is read.");
4155 add_com ("awatch", class_breakpoint
, awatch_command
,
4156 "Set a watchpoint for an expression.\n\
4157 A watchpoint stops execution of your program whenever the value of\n\
4158 an expression is either read or written.");
4160 add_info ("watchpoints", breakpoints_info
,
4161 "Synonym for ``info breakpoints''.");