1 /* Print and select stack frames for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "expression.h"
30 #include "breakpoint.h"
35 return_command
PARAMS ((char *, int));
38 down_command
PARAMS ((char *, int));
41 down_silently_command
PARAMS ((char *, int));
44 up_command
PARAMS ((char *, int));
47 up_silently_command
PARAMS ((char *, int));
50 frame_command
PARAMS ((char *, int));
53 select_frame_command
PARAMS ((char *, int));
56 args_info
PARAMS ((char *, int));
59 print_frame_arg_vars
PARAMS ((FRAME
, FILE *));
62 catch_info
PARAMS ((char *, int));
65 locals_info
PARAMS ((char *, int));
68 print_frame_label_vars
PARAMS ((FRAME
, int, FILE *));
71 print_frame_local_vars
PARAMS ((FRAME
, FILE *));
74 print_block_frame_labels
PARAMS ((struct block
*, int *, FILE *));
77 print_block_frame_locals
PARAMS ((struct block
*, FRAME
, FILE *));
80 backtrace_command
PARAMS ((char *, int));
83 parse_frame_specification
PARAMS ((char *));
86 frame_info
PARAMS ((char *, int));
89 extern int addressprint
; /* Print addresses, or stay symbolic only? */
90 extern int info_verbose
; /* Verbosity of symbol reading msgs */
91 extern int lines_to_list
; /* # of lines "list" command shows by default */
93 /* The "selected" stack frame is used by default for local and arg access.
94 May be zero, for no selected frame. */
98 /* Level of the selected frame:
99 0 for innermost, 1 for its caller, ...
100 or -1 for frame specified by address with no defined level. */
102 int selected_frame_level
;
104 /* Nonzero means print the full filename and linenumber
105 when a frame is printed, and do so in a format programs can parse. */
107 int frame_file_full_name
= 0;
110 /* Print a stack frame briefly. FRAME should be the frame id
111 and LEVEL should be its level in the stack (or -1 for level not defined).
112 This prints the level, the function executing, the arguments,
113 and the file name and line number.
114 If the pc is not at the beginning of the source line,
115 the actual pc is printed at the beginning.
117 If SOURCE is 1, print the source line as well.
118 If SOURCE is -1, print ONLY the source line. */
121 print_stack_frame (frame
, level
, source
)
126 struct frame_info
*fi
;
128 fi
= get_frame_info (frame
);
130 print_frame_info (fi
, level
, source
, 1);
134 print_frame_info (fi
, level
, source
, args
)
135 struct frame_info
*fi
;
140 struct symtab_and_line sal
;
142 register char *funname
= 0;
143 enum language funlang
= language_unknown
;
146 if (PC_IN_CALL_DUMMY (fi
->pc
, read_register (SP_REGNUM
), fi
->frame
))
148 /* Do this regardless of SOURCE because we don't have any source
149 to list for this frame. */
151 printf_filtered ("#%-2d ", level
);
152 printf_filtered ("<function called from gdb>\n");
155 if (fi
->signal_handler_caller
)
157 /* Do this regardless of SOURCE because we don't have any source
158 to list for this frame. */
160 printf_filtered ("#%-2d ", level
);
161 printf_filtered ("<signal handler called>\n");
165 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
166 func
= find_pc_function (fi
->pc
);
169 /* In certain pathological cases, the symtabs give the wrong
170 function (when we are in the first function in a file which
171 is compiled without debugging symbols, the previous function
172 is compiled with debugging symbols, and the "foo.o" symbol
173 that is supposed to tell us where the file with debugging symbols
174 ends has been truncated by ar because it is longer than 15
177 So look in the minimal symbol tables as well, and if it comes
178 up with a larger address for the function use that instead.
179 I don't think this can ever cause any problems; there shouldn't
180 be any minimal symbols in the middle of a function.
181 FIXME: (Not necessarily true. What about text labels) */
183 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
185 && (SYMBOL_VALUE_ADDRESS (msymbol
)
186 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
188 /* In this case we have no way of knowing the source file
189 and line number, so don't print them. */
191 /* We also don't know anything about the function besides
192 its address and name. */
194 funname
= SYMBOL_NAME (msymbol
);
195 funlang
= SYMBOL_LANGUAGE (msymbol
);
199 funname
= SYMBOL_NAME (func
);
200 funlang
= SYMBOL_LANGUAGE (func
);
205 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
208 funname
= SYMBOL_NAME (msymbol
);
209 funlang
= SYMBOL_LANGUAGE (msymbol
);
213 if (source
>= 0 || !sal
.symtab
)
216 printf_filtered ("#%-2d ", level
);
218 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
)
219 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
220 fprintf_symbol_filtered (stdout
, funname
? funname
: "??", funlang
,
223 fputs_filtered (" (", stdout
);
226 FRAME_NUM_ARGS (numargs
, fi
);
227 print_frame_args (func
, fi
, numargs
, stdout
);
229 printf_filtered (")");
230 if (sal
.symtab
&& sal
.symtab
->filename
)
233 printf_filtered (" at %s:%d", sal
.symtab
->filename
, sal
.line
);
236 #ifdef PC_LOAD_SEGMENT
237 /* If we couldn't print out function name but if can figure out what
238 load segment this pc value is from, at least print out some info
239 about its load segment. */
242 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi
->pc
));
245 printf_filtered ("\n");
248 if ((source
!= 0) && sal
.symtab
)
251 int mid_statement
= source
< 0 && fi
->pc
!= sal
.pc
;
252 if (frame_file_full_name
)
253 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
);
256 if (addressprint
&& mid_statement
)
257 printf_filtered ("%s\t", local_hex_string(fi
->pc
));
258 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
260 current_source_line
= max (sal
.line
- lines_to_list
/2, 1);
263 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
269 * Read a frame specification in whatever the appropriate format is.
270 * Call error() if the specification is in any way invalid (i.e.
271 * this function never returns NULL).
274 parse_frame_specification (frame_exp
)
278 int arg1
, arg2
, arg3
;
284 char *addr_string
, *p
;
285 struct cleanup
*tmp_cleanup
;
287 while (*frame_exp
== ' ') frame_exp
++;
291 if (numargs
> MAXARGS
)
292 error ("Too many args in frame specification");
293 /* Parse an argument. */
294 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
296 addr_string
= savestring(frame_exp
, p
- frame_exp
);
299 tmp_cleanup
= make_cleanup (free
, addr_string
);
300 args
[numargs
++] = parse_and_eval_address (addr_string
);
301 do_cleanups (tmp_cleanup
);
304 /* Skip spaces, move to possible next arg. */
305 while (*p
== ' ') p
++;
313 if (selected_frame
== NULL
)
314 error ("No selected frame.");
315 return selected_frame
;
320 FRAME fid
= find_relative_frame (get_current_frame (), &level
);
324 /* find_relative_frame was successful */
327 /* If (s)he specifies the frame with an address, he deserves what
328 (s)he gets. Still, give the highest one that matches. */
330 for (fid
= get_current_frame ();
331 fid
&& FRAME_FP (fid
) != args
[0];
332 fid
= get_prev_frame (fid
))
336 while ((tfid
= get_prev_frame (fid
)) &&
337 (FRAME_FP (tfid
) == args
[0]))
340 /* We couldn't identify the frame as an existing frame, but
341 perhaps we can create one with a single argument.
342 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
343 to complain if it doesn't like a single arg. */
347 #ifdef SETUP_ARBITRARY_FRAME
348 return SETUP_ARBITRARY_FRAME (numargs
, args
);
350 /* Usual case. Do it here rather than have everyone supply
351 a SETUP_ARBITRARY_FRAME that does this. */
353 return create_new_frame (args
[0], 0);
354 error ("Too many args in frame specification");
361 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
362 that if it is unsure about the answer, it returns 0
363 instead of guessing (this happens on the VAX and i960, for example).
365 On most machines, we never have to guess about the args address,
366 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
367 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
368 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
371 /* Print verbosely the selected frame or the frame at address ADDR.
372 This means absolutely all information in the frame is printed. */
375 frame_info (addr_exp
, from_tty
)
380 struct frame_info
*fi
;
381 struct frame_saved_regs fsr
;
382 struct symtab_and_line sal
;
388 enum language funlang
= language_unknown
;
390 if (!target_has_stack
)
391 error ("No inferior or core file.");
393 frame
= parse_frame_specification (addr_exp
);
395 error ("Invalid frame specified.");
397 fi
= get_frame_info (frame
);
398 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
399 func
= get_frame_function (frame
);
400 s
= find_pc_symtab(fi
->pc
);
403 funname
= SYMBOL_NAME (func
);
404 funlang
= SYMBOL_LANGUAGE (func
);
408 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
411 funname
= SYMBOL_NAME (msymbol
);
412 funlang
= SYMBOL_LANGUAGE (msymbol
);
415 calling_frame
= get_prev_frame (frame
);
417 if (!addr_exp
&& selected_frame_level
>= 0) {
418 printf_filtered ("Stack level %d, frame at %s:\n",
419 selected_frame_level
,
420 local_hex_string(FRAME_FP(frame
)));
422 printf_filtered ("Stack frame at %s:\n",
423 local_hex_string(FRAME_FP(frame
)));
425 printf_filtered (" %s = %s",
426 reg_names
[PC_REGNUM
],
427 local_hex_string(fi
->pc
));
432 printf_filtered (" in ");
433 fprintf_symbol_filtered (stdout
, funname
, funlang
,
434 DMGL_ANSI
| DMGL_PARAMS
);
438 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
439 puts_filtered ("; ");
441 printf_filtered ("saved %s %s\n", reg_names
[PC_REGNUM
],
442 local_hex_string(FRAME_SAVED_PC (frame
)));
446 #ifdef FRAMELESS_FUNCTION_INVOCATION
447 FRAMELESS_FUNCTION_INVOCATION (fi
, frameless
);
450 printf_filtered (" (FRAMELESS),");
454 printf_filtered (" called by frame at %s",
455 local_hex_string(FRAME_FP (calling_frame
)));
456 if (fi
->next_frame
&& calling_frame
)
460 printf_filtered (" caller of frame at %s", local_hex_string(fi
->next_frame
));
461 if (fi
->next_frame
|| calling_frame
)
462 puts_filtered ("\n");
464 printf_filtered(" source language %s.\n", language_str(s
->language
));
466 #ifdef PRINT_EXTRA_FRAME_INFO
467 PRINT_EXTRA_FRAME_INFO (fi
);
471 /* Address of the argument list for this frame, or 0. */
472 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
473 /* Number of args for this frame, or -1 if unknown. */
477 printf_filtered (" Arglist at unknown address.\n");
480 printf_filtered (" Arglist at %s,", local_hex_string(arg_list
));
482 FRAME_NUM_ARGS (numargs
, fi
);
484 puts_filtered (" args: ");
485 else if (numargs
== 0)
486 puts_filtered (" no args.");
487 else if (numargs
== 1)
488 puts_filtered (" 1 arg: ");
490 printf_filtered (" %d args: ", numargs
);
491 print_frame_args (func
, fi
, numargs
, stdout
);
492 puts_filtered ("\n");
496 /* Address of the local variables for this frame, or 0. */
497 CORE_ADDR arg_list
= FRAME_LOCALS_ADDRESS (fi
);
500 printf_filtered (" Locals at unknown address,");
502 printf_filtered (" Locals at %s,", local_hex_string(arg_list
));
505 #if defined (FRAME_FIND_SAVED_REGS)
506 get_frame_saved_regs (fi
, &fsr
);
507 /* The sp is special; what's returned isn't the save address, but
508 actually the value of the previous frame's sp. */
509 printf_filtered (" Previous frame's sp is %s\n",
510 local_hex_string(fsr
.regs
[SP_REGNUM
]));
512 for (i
= 0; i
< NUM_REGS
; i
++)
513 if (fsr
.regs
[i
] && i
!= SP_REGNUM
)
516 puts_filtered (" Saved registers:\n ");
520 printf_filtered (" %s at %s", reg_names
[i
],
521 local_hex_string(fsr
.regs
[i
]));
525 puts_filtered ("\n");
526 #endif /* Have FRAME_FIND_SAVED_REGS. */
530 /* Set a limit on the number of frames printed by default in a
533 static int backtrace_limit
;
536 set_backtrace_limit_command (count_exp
, from_tty
)
540 int count
= parse_and_eval_address (count_exp
);
543 error ("Negative argument not meaningful as backtrace limit.");
545 backtrace_limit
= count
;
549 backtrace_limit_info (arg
, from_tty
)
554 error ("\"Info backtrace-limit\" takes no arguments.");
556 printf ("Backtrace limit: %d.\n", backtrace_limit
);
560 /* Print briefly all stack frames or just the innermost COUNT frames. */
563 backtrace_command (count_exp
, from_tty
)
567 struct frame_info
*fi
;
569 register FRAME frame
;
571 register FRAME trailing
;
572 register int trailing_level
;
574 if (!target_has_stack
)
577 /* The following code must do two things. First, it must
578 set the variable TRAILING to the frame from which we should start
579 printing. Second, it must set the variable count to the number
580 of frames which we should print, or -1 if all of them. */
581 trailing
= get_current_frame ();
585 count
= parse_and_eval_address (count_exp
);
593 while (current
&& count
--)
596 current
= get_prev_frame (current
);
599 /* Will stop when CURRENT reaches the top of the stack. TRAILING
600 will be COUNT below it. */
604 trailing
= get_prev_frame (trailing
);
605 current
= get_prev_frame (current
);
617 struct partial_symtab
*ps
;
619 /* Read in symbols for all of the frames. Need to do this in
620 a separate pass so that "Reading in symbols for xxx" messages
621 don't screw up the appearance of the backtrace. Also
622 if people have strong opinions against reading symbols for
623 backtrace this may have to be an option. */
625 for (frame
= trailing
;
626 frame
!= NULL
&& i
--;
627 frame
= get_prev_frame (frame
))
630 fi
= get_frame_info (frame
);
631 ps
= find_pc_psymtab (fi
->pc
);
633 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
637 for (i
= 0, frame
= trailing
;
639 i
++, frame
= get_prev_frame (frame
))
642 fi
= get_frame_info (frame
);
643 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
646 /* If we've stopped before the end, mention that. */
647 if (frame
&& from_tty
)
648 printf_filtered ("(More stack frames follow...)\n");
651 /* Print the local variables of a block B active in FRAME.
652 Return 1 if any variables were printed; 0 otherwise. */
655 print_block_frame_locals (b
, frame
, stream
)
657 register FRAME frame
;
658 register FILE *stream
;
662 register struct symbol
*sym
;
663 register int values_printed
= 0;
665 nsyms
= BLOCK_NSYMS (b
);
667 for (i
= 0; i
< nsyms
; i
++)
669 sym
= BLOCK_SYM (b
, i
);
670 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
671 || SYMBOL_CLASS (sym
) == LOC_REGISTER
672 || SYMBOL_CLASS (sym
) == LOC_STATIC
)
675 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
676 fputs_filtered (" = ", stream
);
677 print_variable_value (sym
, frame
, stream
);
678 fprintf_filtered (stream
, "\n");
681 return values_printed
;
684 /* Same, but print labels. */
687 print_block_frame_labels (b
, have_default
, stream
)
690 register FILE *stream
;
694 register struct symbol
*sym
;
695 register int values_printed
= 0;
697 nsyms
= BLOCK_NSYMS (b
);
699 for (i
= 0; i
< nsyms
; i
++)
701 sym
= BLOCK_SYM (b
, i
);
702 if (STREQ (SYMBOL_NAME (sym
), "default"))
708 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
710 struct symtab_and_line sal
;
711 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
713 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
715 fprintf_filtered (stream
, " %s",
716 local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
717 fprintf_filtered (stream
, " in file %s, line %d\n",
718 sal
.symtab
->filename
, sal
.line
);
721 return values_printed
;
724 /* Print on STREAM all the local variables in frame FRAME,
725 including all the blocks active in that frame
728 Returns 1 if the job was done,
729 or 0 if nothing was printed because we have no info
730 on the function running in FRAME. */
733 print_frame_local_vars (frame
, stream
)
734 register FRAME frame
;
735 register FILE *stream
;
737 register struct block
*block
= get_frame_block (frame
);
738 register int values_printed
= 0;
742 fprintf_filtered (stream
, "No symbol table info available.\n");
748 if (print_block_frame_locals (block
, frame
, stream
))
750 /* After handling the function's top-level block, stop.
751 Don't continue to its superblock, the block of
753 if (BLOCK_FUNCTION (block
))
755 block
= BLOCK_SUPERBLOCK (block
);
760 fprintf_filtered (stream
, "No locals.\n");
764 /* Same, but print labels. */
767 print_frame_label_vars (frame
, this_level_only
, stream
)
768 register FRAME frame
;
770 register FILE *stream
;
772 register struct blockvector
*bl
;
773 register struct block
*block
= get_frame_block (frame
);
774 register int values_printed
= 0;
775 int index
, have_default
= 0;
776 char *blocks_printed
;
777 struct frame_info
*fi
= get_frame_info (frame
);
778 CORE_ADDR pc
= fi
->pc
;
782 fprintf_filtered (stream
, "No symbol table info available.\n");
786 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
787 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
788 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
792 CORE_ADDR end
= BLOCK_END (block
) - 4;
795 if (bl
!= blockvector_for_pc (end
, &index
))
796 error ("blockvector blotch");
797 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
798 error ("blockvector botch");
799 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
802 /* Don't print out blocks that have gone by. */
803 while (index
< last_index
804 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
807 while (index
< last_index
808 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
810 if (blocks_printed
[index
] == 0)
812 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
814 blocks_printed
[index
] = 1;
820 if (values_printed
&& this_level_only
)
823 /* After handling the function's top-level block, stop.
824 Don't continue to its superblock, the block of
826 if (BLOCK_FUNCTION (block
))
828 block
= BLOCK_SUPERBLOCK (block
);
831 if (!values_printed
&& !this_level_only
)
833 fprintf_filtered (stream
, "No catches.\n");
839 locals_info (args
, from_tty
)
844 error ("No frame selected.");
845 print_frame_local_vars (selected_frame
, stdout
);
849 catch_info (ignore
, from_tty
)
854 error ("No frame selected.");
855 print_frame_label_vars (selected_frame
, 0, stdout
);
859 print_frame_arg_vars (frame
, stream
)
860 register FRAME frame
;
861 register FILE *stream
;
863 struct symbol
*func
= get_frame_function (frame
);
864 register struct block
*b
;
867 register struct symbol
*sym
, *sym2
;
868 register int values_printed
= 0;
872 fprintf_filtered (stream
, "No symbol table info available.\n");
876 b
= SYMBOL_BLOCK_VALUE (func
);
877 nsyms
= BLOCK_NSYMS (b
);
879 for (i
= 0; i
< nsyms
; i
++)
881 sym
= BLOCK_SYM (b
, i
);
882 if (SYMBOL_CLASS (sym
) == LOC_ARG
883 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
884 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
885 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
888 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
889 fputs_filtered (" = ", stream
);
890 /* We have to look up the symbol because arguments often have
891 two entries (one a parameter, one a register) and the one
892 we want is the register, which lookup_symbol will find for
894 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
895 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
896 print_variable_value (sym2
, frame
, stream
);
897 fprintf_filtered (stream
, "\n");
903 fprintf_filtered (stream
, "No arguments.\n");
908 args_info (ignore
, from_tty
)
913 error ("No frame selected.");
914 print_frame_arg_vars (selected_frame
, stdout
);
917 /* Select frame FRAME, and note that its stack level is LEVEL.
918 LEVEL may be -1 if an actual level number is not known. */
921 select_frame (frame
, level
)
925 register struct symtab
*s
;
927 selected_frame
= frame
;
928 selected_frame_level
= level
;
930 /* Ensure that symbols for this frame are read in. Also, determine the
931 source language of this frame, and switch to it if desired. */
934 s
= find_pc_symtab (get_frame_info (frame
)->pc
);
936 && s
->language
!= current_language
->la_language
937 && s
->language
!= language_unknown
938 && language_mode
== language_mode_auto
) {
939 set_language(s
->language
);
944 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
945 If there is no selected frame, *FRAMEP is set to NULL. */
948 record_selected_frame (frameaddrp
, levelp
)
949 FRAME_ADDR
*frameaddrp
;
952 *frameaddrp
= selected_frame
? FRAME_FP (selected_frame
) : 0;
953 *levelp
= selected_frame_level
;
956 /* Return the symbol-block in which the selected frame is executing.
957 Can return zero under various legitimate circumstances. */
960 get_selected_block ()
962 if (!target_has_stack
)
966 return get_current_block ();
967 return get_frame_block (selected_frame
);
970 /* Find a frame a certain number of levels away from FRAME.
971 LEVEL_OFFSET_PTR points to an int containing the number of levels.
972 Positive means go to earlier frames (up); negative, the reverse.
973 The int that contains the number of levels is counted toward
974 zero as the frames for those levels are found.
975 If the top or bottom frame is reached, that frame is returned,
976 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
977 how much farther the original request asked to go. */
980 find_relative_frame (frame
, level_offset_ptr
)
981 register FRAME frame
;
982 register int* level_offset_ptr
;
985 register FRAME frame1
;
987 /* Going up is simple: just do get_prev_frame enough times
988 or until initial frame is reached. */
989 while (*level_offset_ptr
> 0)
991 prev
= get_prev_frame (frame
);
994 (*level_offset_ptr
)--;
997 /* Going down is just as simple. */
998 if (*level_offset_ptr
< 0)
1000 while (*level_offset_ptr
< 0) {
1001 frame1
= get_next_frame (frame
);
1005 (*level_offset_ptr
)++;
1011 /* The "select_frame" command. With no arg, NOP.
1012 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1013 valid level. Otherwise, treat level_exp as an address expression
1014 and select it. See parse_frame_specification for more info on proper
1015 frame expressions. */
1019 select_frame_command (level_exp
, from_tty
)
1023 register FRAME frame
, frame1
;
1024 unsigned int level
= 0;
1026 if (!target_has_stack
)
1027 error ("No stack.");
1029 frame
= parse_frame_specification (level_exp
);
1031 /* Try to figure out what level this frame is. But if there is
1032 no current stack, don't error out -- let the user set one. */
1034 if (get_current_frame()) {
1035 for (frame1
= get_prev_frame (0);
1036 frame1
&& frame1
!= frame
;
1037 frame1
= get_prev_frame (frame1
))
1044 select_frame (frame
, level
);
1047 /* The "frame" command. With no arg, print selected frame briefly.
1048 With arg, behaves like select_frame and then prints the selected
1052 frame_command (level_exp
, from_tty
)
1056 select_frame_command (level_exp
, from_tty
);
1057 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1060 /* Select the frame up one or COUNT stack levels
1061 from the previously selected frame, and print it briefly. */
1065 up_silently_command (count_exp
, from_tty
)
1069 register FRAME frame
;
1070 int count
= 1, count1
;
1072 count
= parse_and_eval_address (count_exp
);
1075 if (target_has_stack
== 0 || selected_frame
== 0)
1076 error ("No stack.");
1078 frame
= find_relative_frame (selected_frame
, &count1
);
1079 if (count1
!= 0 && count_exp
== 0)
1080 error ("Initial frame selected; you cannot go up.");
1081 select_frame (frame
, selected_frame_level
+ count
- count1
);
1085 up_command (count_exp
, from_tty
)
1089 up_silently_command (count_exp
, from_tty
);
1090 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1093 /* Select the frame down one or COUNT stack levels
1094 from the previously selected frame, and print it briefly. */
1098 down_silently_command (count_exp
, from_tty
)
1102 register FRAME frame
;
1103 int count
= -1, count1
;
1105 count
= - parse_and_eval_address (count_exp
);
1108 if (target_has_stack
== 0 || selected_frame
== 0)
1109 error ("No stack.");
1111 frame
= find_relative_frame (selected_frame
, &count1
);
1112 if (count1
!= 0 && count_exp
== 0)
1113 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1114 select_frame (frame
, selected_frame_level
+ count
- count1
);
1119 down_command (count_exp
, from_tty
)
1123 down_silently_command (count_exp
, from_tty
);
1124 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1128 return_command (retval_exp
, from_tty
)
1132 struct symbol
*thisfun
;
1133 FRAME_ADDR selected_frame_addr
;
1134 CORE_ADDR selected_frame_pc
;
1138 if (selected_frame
== NULL
)
1139 error ("No selected frame.");
1140 thisfun
= get_frame_function (selected_frame
);
1141 selected_frame_addr
= FRAME_FP (selected_frame
);
1142 selected_frame_pc
= (get_frame_info (selected_frame
))->pc
;
1144 /* Compute the return value (if any -- possibly getting errors here).
1145 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1146 it might live in the stack frame we're about to pop. */
1150 return_value
= parse_and_eval (retval_exp
);
1151 VALUE_CONTENTS (return_value
);
1154 /* If interactive, require confirmation. */
1160 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun
)))
1162 error ("Not confirmed.");
1167 if (!query ("Make selected stack frame return now? "))
1168 error ("Not confirmed.");
1171 /* Do the real work. Pop until the specified frame is current. We
1172 use this method because the selected_frame is not valid after
1173 a POP_FRAME. The pc comparison makes this work even if the
1174 selected frame shares its fp with another frame. */
1176 while ( selected_frame_addr
!= FRAME_FP (frame
= get_current_frame())
1177 || selected_frame_pc
!= (get_frame_info (frame
))->pc
)
1180 /* Then pop that frame. */
1184 /* Compute the return value (if any) and store in the place
1185 for return values. */
1188 set_return_value (return_value
);
1190 /* If interactive, print the frame that is now current. */
1193 frame_command ("0", 1);
1196 /* Gets the language of the current frame. */
1198 get_frame_language()
1200 register struct symtab
*s
;
1202 enum language flang
; /* The language of the current frame */
1204 fr
= get_frame_info(selected_frame
);
1207 s
= find_pc_symtab(fr
->pc
);
1209 flang
= s
->language
;
1211 flang
= language_unknown
;
1214 flang
= language_unknown
;
1220 _initialize_stack ()
1223 backtrace_limit
= 30;
1226 add_com ("return", class_stack
, return_command
,
1227 "Make selected stack frame return to its caller.\n\
1228 Control remains in the debugger, but when you continue\n\
1229 execution will resume in the frame above the one now selected.\n\
1230 If an argument is given, it is an expression for the value to return.");
1232 add_com ("up", class_stack
, up_command
,
1233 "Select and print stack frame that called this one.\n\
1234 An argument says how many frames up to go.");
1235 add_com ("up-silently", class_support
, up_silently_command
,
1236 "Same as the `up' command, but does not print anything.\n\
1237 This is useful in command scripts.");
1239 add_com ("down", class_stack
, down_command
,
1240 "Select and print stack frame called by this one.\n\
1241 An argument says how many frames down to go.");
1242 add_com_alias ("do", "down", class_stack
, 1);
1243 add_com_alias ("dow", "down", class_stack
, 1);
1244 add_com ("down-silently", class_support
, down_silently_command
,
1245 "Same as the `down' command, but does not print anything.\n\
1246 This is useful in command scripts.");
1248 add_com ("frame", class_stack
, frame_command
,
1249 "Select and print a stack frame.\n\
1250 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1251 An argument specifies the frame to select.\n\
1252 It can be a stack frame number or the address of the frame.\n\
1253 With argument, nothing is printed if input is coming from\n\
1254 a command file or a user-defined command.");
1256 add_com_alias ("f", "frame", class_stack
, 1);
1258 add_com ("select-frame", class_stack
, select_frame_command
,
1259 "Select a stack frame without printing anything.\n\
1260 An argument specifies the frame to select.\n\
1261 It can be a stack frame number or the address of the frame.\n");
1263 add_com ("backtrace", class_stack
, backtrace_command
,
1264 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1265 With a negative argument, print outermost -COUNT frames.");
1266 add_com_alias ("bt", "backtrace", class_stack
, 0);
1267 add_com_alias ("where", "backtrace", class_alias
, 0);
1268 add_info ("stack", backtrace_command
,
1269 "Backtrace of the stack, or innermost COUNT frames.");
1270 add_info_alias ("s", "stack", 1);
1271 add_info ("frame", frame_info
,
1272 "All about selected stack frame, or frame at ADDR.");
1273 add_info_alias ("f", "frame", 1);
1274 add_info ("locals", locals_info
,
1275 "Local variables of current stack frame.");
1276 add_info ("args", args_info
,
1277 "Argument variables of current stack frame.");
1278 add_info ("catch", catch_info
,
1279 "Exceptions that can be caught in the current stack frame.");
1282 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1283 "Specify maximum number of frames for \"backtrace\" to print by default.",
1285 add_info ("backtrace-limit", backtrace_limit_info
,
1286 "The maximum number of frames for \"backtrace\" to print by default.");