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");
156 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
157 func
= find_pc_function (fi
->pc
);
160 /* In certain pathological cases, the symtabs give the wrong
161 function (when we are in the first function in a file which
162 is compiled without debugging symbols, the previous function
163 is compiled with debugging symbols, and the "foo.o" symbol
164 that is supposed to tell us where the file with debugging symbols
165 ends has been truncated by ar because it is longer than 15
168 So look in the minimal symbol tables as well, and if it comes
169 up with a larger address for the function use that instead.
170 I don't think this can ever cause any problems; there shouldn't
171 be any minimal symbols in the middle of a function.
172 FIXME: (Not necessarily true. What about text labels) */
174 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
176 && (SYMBOL_VALUE_ADDRESS (msymbol
)
177 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
179 /* In this case we have no way of knowing the source file
180 and line number, so don't print them. */
182 /* We also don't know anything about the function besides
183 its address and name. */
185 funname
= SYMBOL_NAME (msymbol
);
186 funlang
= SYMBOL_LANGUAGE (msymbol
);
190 funname
= SYMBOL_NAME (func
);
191 funlang
= SYMBOL_LANGUAGE (func
);
196 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
199 funname
= SYMBOL_NAME (msymbol
);
200 funlang
= SYMBOL_LANGUAGE (msymbol
);
204 if (source
>= 0 || !sal
.symtab
)
207 printf_filtered ("#%-2d ", level
);
209 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
)
210 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
211 fprintf_symbol_filtered (stdout
, funname
? funname
: "??", funlang
,
214 fputs_filtered (" (", stdout
);
217 FRAME_NUM_ARGS (numargs
, fi
);
218 print_frame_args (func
, fi
, numargs
, stdout
);
220 printf_filtered (")");
221 if (sal
.symtab
&& sal
.symtab
->filename
)
224 printf_filtered (" at %s:%d", sal
.symtab
->filename
, sal
.line
);
227 #ifdef PC_LOAD_SEGMENT
228 /* If we couldn't print out function name but if can figure out what
229 load segment this pc value is from, at least print out some info
230 about its load segment. */
233 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi
->pc
));
236 printf_filtered ("\n");
239 if ((source
!= 0) && sal
.symtab
)
242 int mid_statement
= source
< 0 && fi
->pc
!= sal
.pc
;
243 if (frame_file_full_name
)
244 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
);
247 if (addressprint
&& mid_statement
)
248 printf_filtered ("%s\t", local_hex_string(fi
->pc
));
249 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
251 current_source_line
= max (sal
.line
- lines_to_list
/2, 1);
254 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
260 * Read a frame specification in whatever the appropriate format is.
261 * Call error() if the specification is in any way invalid (i.e.
262 * this function never returns NULL).
265 parse_frame_specification (frame_exp
)
269 int arg1
, arg2
, arg3
;
275 char *addr_string
, *p
;
276 struct cleanup
*tmp_cleanup
;
278 while (*frame_exp
== ' ') frame_exp
++;
282 if (numargs
> MAXARGS
)
283 error ("Too many args in frame specification");
284 /* Parse an argument. */
285 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
287 addr_string
= savestring(frame_exp
, p
- frame_exp
);
290 tmp_cleanup
= make_cleanup (free
, addr_string
);
291 args
[numargs
++] = parse_and_eval_address (addr_string
);
292 do_cleanups (tmp_cleanup
);
295 /* Skip spaces, move to possible next arg. */
296 while (*p
== ' ') p
++;
304 if (selected_frame
== NULL
)
305 error ("No selected frame.");
306 return selected_frame
;
311 FRAME fid
= find_relative_frame (get_current_frame (), &level
);
315 /* find_relative_frame was successful */
318 /* If (s)he specifies the frame with an address, he deserves what
319 (s)he gets. Still, give the highest one that matches. */
321 for (fid
= get_current_frame ();
322 fid
&& FRAME_FP (fid
) != args
[0];
323 fid
= get_prev_frame (fid
))
327 while ((tfid
= get_prev_frame (fid
)) &&
328 (FRAME_FP (tfid
) == args
[0]))
331 /* We couldn't identify the frame as an existing frame, but
332 perhaps we can create one with a single argument.
333 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
334 to complain if it doesn't like a single arg. */
338 #ifdef SETUP_ARBITRARY_FRAME
339 return SETUP_ARBITRARY_FRAME (numargs
, args
);
341 /* Usual case. Do it here rather than have everyone supply
342 a SETUP_ARBITRARY_FRAME that does this. */
344 return create_new_frame (args
[0], 0);
345 error ("Too many args in frame specification");
352 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
353 that if it is unsure about the answer, it returns 0
354 instead of guessing (this happens on the VAX and i960, for example).
356 On most machines, we never have to guess about the args address,
357 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
358 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
359 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
362 /* Print verbosely the selected frame or the frame at address ADDR.
363 This means absolutely all information in the frame is printed. */
366 frame_info (addr_exp
, from_tty
)
371 struct frame_info
*fi
;
372 struct frame_saved_regs fsr
;
373 struct symtab_and_line sal
;
379 enum language funlang
= language_unknown
;
381 if (!target_has_stack
)
382 error ("No inferior or core file.");
384 frame
= parse_frame_specification (addr_exp
);
386 error ("Invalid frame specified.");
388 fi
= get_frame_info (frame
);
389 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
390 func
= get_frame_function (frame
);
391 s
= find_pc_symtab(fi
->pc
);
394 funname
= SYMBOL_NAME (func
);
395 funlang
= SYMBOL_LANGUAGE (func
);
399 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
402 funname
= SYMBOL_NAME (msymbol
);
403 funlang
= SYMBOL_LANGUAGE (msymbol
);
406 calling_frame
= get_prev_frame (frame
);
408 if (!addr_exp
&& selected_frame_level
>= 0) {
409 printf_filtered ("Stack level %d, frame at %s:\n",
410 selected_frame_level
,
411 local_hex_string(FRAME_FP(frame
)));
413 printf_filtered ("Stack frame at %s:\n",
414 local_hex_string(FRAME_FP(frame
)));
416 printf_filtered (" %s = %s",
417 reg_names
[PC_REGNUM
],
418 local_hex_string(fi
->pc
));
423 printf_filtered (" in ");
424 fprintf_symbol_filtered (stdout
, funname
, funlang
,
425 DMGL_ANSI
| DMGL_PARAMS
);
429 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
430 puts_filtered ("; ");
432 printf_filtered ("saved %s %s\n", reg_names
[PC_REGNUM
],
433 local_hex_string(FRAME_SAVED_PC (frame
)));
437 #ifdef FRAMELESS_FUNCTION_INVOCATION
438 FRAMELESS_FUNCTION_INVOCATION (fi
, frameless
);
441 printf_filtered (" (FRAMELESS),");
445 printf_filtered (" called by frame at %s",
446 local_hex_string(FRAME_FP (calling_frame
)));
447 if (fi
->next_frame
&& calling_frame
)
451 printf_filtered (" caller of frame at %s", local_hex_string(fi
->next_frame
));
452 if (fi
->next_frame
|| calling_frame
)
453 puts_filtered ("\n");
455 printf_filtered(" source language %s.\n", language_str(s
->language
));
457 #ifdef PRINT_EXTRA_FRAME_INFO
458 PRINT_EXTRA_FRAME_INFO (fi
);
462 /* Address of the argument list for this frame, or 0. */
463 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
464 /* Number of args for this frame, or -1 if unknown. */
468 printf_filtered (" Arglist at unknown address.\n");
471 printf_filtered (" Arglist at %s,", local_hex_string(arg_list
));
473 FRAME_NUM_ARGS (numargs
, fi
);
475 puts_filtered (" args: ");
476 else if (numargs
== 0)
477 puts_filtered (" no args.");
478 else if (numargs
== 1)
479 puts_filtered (" 1 arg: ");
481 printf_filtered (" %d args: ", numargs
);
482 print_frame_args (func
, fi
, numargs
, stdout
);
483 puts_filtered ("\n");
487 /* Address of the local variables for this frame, or 0. */
488 CORE_ADDR arg_list
= FRAME_LOCALS_ADDRESS (fi
);
491 printf_filtered (" Locals at unknown address,");
493 printf_filtered (" Locals at %s,", local_hex_string(arg_list
));
496 #if defined (FRAME_FIND_SAVED_REGS)
497 get_frame_saved_regs (fi
, &fsr
);
498 /* The sp is special; what's returned isn't the save address, but
499 actually the value of the previous frame's sp. */
500 printf_filtered (" Previous frame's sp is %s\n",
501 local_hex_string(fsr
.regs
[SP_REGNUM
]));
503 for (i
= 0; i
< NUM_REGS
; i
++)
504 if (fsr
.regs
[i
] && i
!= SP_REGNUM
)
507 puts_filtered (" Saved registers:\n ");
511 printf_filtered (" %s at %s", reg_names
[i
],
512 local_hex_string(fsr
.regs
[i
]));
516 puts_filtered ("\n");
517 #endif /* Have FRAME_FIND_SAVED_REGS. */
521 /* Set a limit on the number of frames printed by default in a
524 static int backtrace_limit
;
527 set_backtrace_limit_command (count_exp
, from_tty
)
531 int count
= parse_and_eval_address (count_exp
);
534 error ("Negative argument not meaningful as backtrace limit.");
536 backtrace_limit
= count
;
540 backtrace_limit_info (arg
, from_tty
)
545 error ("\"Info backtrace-limit\" takes no arguments.");
547 printf ("Backtrace limit: %d.\n", backtrace_limit
);
551 /* Print briefly all stack frames or just the innermost COUNT frames. */
554 backtrace_command (count_exp
, from_tty
)
558 struct frame_info
*fi
;
560 register FRAME frame
;
562 register FRAME trailing
;
563 register int trailing_level
;
565 if (!target_has_stack
)
568 /* The following code must do two things. First, it must
569 set the variable TRAILING to the frame from which we should start
570 printing. Second, it must set the variable count to the number
571 of frames which we should print, or -1 if all of them. */
572 trailing
= get_current_frame ();
576 count
= parse_and_eval_address (count_exp
);
584 while (current
&& count
--)
587 current
= get_prev_frame (current
);
590 /* Will stop when CURRENT reaches the top of the stack. TRAILING
591 will be COUNT below it. */
595 trailing
= get_prev_frame (trailing
);
596 current
= get_prev_frame (current
);
608 struct partial_symtab
*ps
;
610 /* Read in symbols for all of the frames. Need to do this in
611 a separate pass so that "Reading in symbols for xxx" messages
612 don't screw up the appearance of the backtrace. Also
613 if people have strong opinions against reading symbols for
614 backtrace this may have to be an option. */
616 for (frame
= trailing
;
617 frame
!= NULL
&& i
--;
618 frame
= get_prev_frame (frame
))
621 fi
= get_frame_info (frame
);
622 ps
= find_pc_psymtab (fi
->pc
);
624 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
628 for (i
= 0, frame
= trailing
;
630 i
++, frame
= get_prev_frame (frame
))
633 fi
= get_frame_info (frame
);
634 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
637 /* If we've stopped before the end, mention that. */
638 if (frame
&& from_tty
)
639 printf_filtered ("(More stack frames follow...)\n");
642 /* Print the local variables of a block B active in FRAME.
643 Return 1 if any variables were printed; 0 otherwise. */
646 print_block_frame_locals (b
, frame
, stream
)
648 register FRAME frame
;
649 register FILE *stream
;
653 register struct symbol
*sym
;
654 register int values_printed
= 0;
656 nsyms
= BLOCK_NSYMS (b
);
658 for (i
= 0; i
< nsyms
; i
++)
660 sym
= BLOCK_SYM (b
, i
);
661 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
662 || SYMBOL_CLASS (sym
) == LOC_REGISTER
663 || SYMBOL_CLASS (sym
) == LOC_STATIC
)
666 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
667 fputs_filtered (" = ", stream
);
668 print_variable_value (sym
, frame
, stream
);
669 fprintf_filtered (stream
, "\n");
672 return values_printed
;
675 /* Same, but print labels. */
678 print_block_frame_labels (b
, have_default
, stream
)
681 register FILE *stream
;
685 register struct symbol
*sym
;
686 register int values_printed
= 0;
688 nsyms
= BLOCK_NSYMS (b
);
690 for (i
= 0; i
< nsyms
; i
++)
692 sym
= BLOCK_SYM (b
, i
);
693 if (STREQ (SYMBOL_NAME (sym
), "default"))
699 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
701 struct symtab_and_line sal
;
702 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
704 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
706 fprintf_filtered (stream
, " %s",
707 local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
708 fprintf_filtered (stream
, " in file %s, line %d\n",
709 sal
.symtab
->filename
, sal
.line
);
712 return values_printed
;
715 /* Print on STREAM all the local variables in frame FRAME,
716 including all the blocks active in that frame
719 Returns 1 if the job was done,
720 or 0 if nothing was printed because we have no info
721 on the function running in FRAME. */
724 print_frame_local_vars (frame
, stream
)
725 register FRAME frame
;
726 register FILE *stream
;
728 register struct block
*block
= get_frame_block (frame
);
729 register int values_printed
= 0;
733 fprintf_filtered (stream
, "No symbol table info available.\n");
739 if (print_block_frame_locals (block
, frame
, stream
))
741 /* After handling the function's top-level block, stop.
742 Don't continue to its superblock, the block of
744 if (BLOCK_FUNCTION (block
))
746 block
= BLOCK_SUPERBLOCK (block
);
751 fprintf_filtered (stream
, "No locals.\n");
755 /* Same, but print labels. */
758 print_frame_label_vars (frame
, this_level_only
, stream
)
759 register FRAME frame
;
761 register FILE *stream
;
763 register struct blockvector
*bl
;
764 register struct block
*block
= get_frame_block (frame
);
765 register int values_printed
= 0;
766 int index
, have_default
= 0;
767 char *blocks_printed
;
768 struct frame_info
*fi
= get_frame_info (frame
);
769 CORE_ADDR pc
= fi
->pc
;
773 fprintf_filtered (stream
, "No symbol table info available.\n");
777 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
778 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
779 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
783 CORE_ADDR end
= BLOCK_END (block
) - 4;
786 if (bl
!= blockvector_for_pc (end
, &index
))
787 error ("blockvector blotch");
788 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
789 error ("blockvector botch");
790 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
793 /* Don't print out blocks that have gone by. */
794 while (index
< last_index
795 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
798 while (index
< last_index
799 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
801 if (blocks_printed
[index
] == 0)
803 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
805 blocks_printed
[index
] = 1;
811 if (values_printed
&& this_level_only
)
814 /* After handling the function's top-level block, stop.
815 Don't continue to its superblock, the block of
817 if (BLOCK_FUNCTION (block
))
819 block
= BLOCK_SUPERBLOCK (block
);
822 if (!values_printed
&& !this_level_only
)
824 fprintf_filtered (stream
, "No catches.\n");
830 locals_info (args
, from_tty
)
835 error ("No frame selected.");
836 print_frame_local_vars (selected_frame
, stdout
);
840 catch_info (ignore
, from_tty
)
845 error ("No frame selected.");
846 print_frame_label_vars (selected_frame
, 0, stdout
);
850 print_frame_arg_vars (frame
, stream
)
851 register FRAME frame
;
852 register FILE *stream
;
854 struct symbol
*func
= get_frame_function (frame
);
855 register struct block
*b
;
858 register struct symbol
*sym
, *sym2
;
859 register int values_printed
= 0;
863 fprintf_filtered (stream
, "No symbol table info available.\n");
867 b
= SYMBOL_BLOCK_VALUE (func
);
868 nsyms
= BLOCK_NSYMS (b
);
870 for (i
= 0; i
< nsyms
; i
++)
872 sym
= BLOCK_SYM (b
, i
);
873 if (SYMBOL_CLASS (sym
) == LOC_ARG
874 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
875 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
876 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
879 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
880 fputs_filtered (" = ", stream
);
881 /* We have to look up the symbol because arguments often have
882 two entries (one a parameter, one a register) and the one
883 we want is the register, which lookup_symbol will find for
885 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
886 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
887 print_variable_value (sym2
, frame
, stream
);
888 fprintf_filtered (stream
, "\n");
894 fprintf_filtered (stream
, "No arguments.\n");
899 args_info (ignore
, from_tty
)
904 error ("No frame selected.");
905 print_frame_arg_vars (selected_frame
, stdout
);
908 /* Select frame FRAME, and note that its stack level is LEVEL.
909 LEVEL may be -1 if an actual level number is not known. */
912 select_frame (frame
, level
)
916 register struct symtab
*s
;
918 selected_frame
= frame
;
919 selected_frame_level
= level
;
921 /* Ensure that symbols for this frame are read in. Also, determine the
922 source language of this frame, and switch to it if desired. */
925 s
= find_pc_symtab (get_frame_info (frame
)->pc
);
927 && s
->language
!= current_language
->la_language
928 && s
->language
!= language_unknown
929 && language_mode
== language_mode_auto
) {
930 set_language(s
->language
);
935 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
936 If there is no selected frame, *FRAMEP is set to NULL. */
939 record_selected_frame (frameaddrp
, levelp
)
940 FRAME_ADDR
*frameaddrp
;
943 *frameaddrp
= selected_frame
? FRAME_FP (selected_frame
) : 0;
944 *levelp
= selected_frame_level
;
947 /* Return the symbol-block in which the selected frame is executing.
948 Can return zero under various legitimate circumstances. */
951 get_selected_block ()
953 if (!target_has_stack
)
957 return get_current_block ();
958 return get_frame_block (selected_frame
);
961 /* Find a frame a certain number of levels away from FRAME.
962 LEVEL_OFFSET_PTR points to an int containing the number of levels.
963 Positive means go to earlier frames (up); negative, the reverse.
964 The int that contains the number of levels is counted toward
965 zero as the frames for those levels are found.
966 If the top or bottom frame is reached, that frame is returned,
967 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
968 how much farther the original request asked to go. */
971 find_relative_frame (frame
, level_offset_ptr
)
972 register FRAME frame
;
973 register int* level_offset_ptr
;
976 register FRAME frame1
;
978 /* Going up is simple: just do get_prev_frame enough times
979 or until initial frame is reached. */
980 while (*level_offset_ptr
> 0)
982 prev
= get_prev_frame (frame
);
985 (*level_offset_ptr
)--;
988 /* Going down is just as simple. */
989 if (*level_offset_ptr
< 0)
991 while (*level_offset_ptr
< 0) {
992 frame1
= get_next_frame (frame
);
996 (*level_offset_ptr
)++;
1002 /* The "select_frame" command. With no arg, NOP.
1003 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1004 valid level. Otherwise, treat level_exp as an address expression
1005 and select it. See parse_frame_specification for more info on proper
1006 frame expressions. */
1010 select_frame_command (level_exp
, from_tty
)
1014 register FRAME frame
, frame1
;
1015 unsigned int level
= 0;
1017 if (!target_has_stack
)
1018 error ("No stack.");
1020 frame
= parse_frame_specification (level_exp
);
1022 /* Try to figure out what level this frame is. But if there is
1023 no current stack, don't error out -- let the user set one. */
1025 if (get_current_frame()) {
1026 for (frame1
= get_prev_frame (0);
1027 frame1
&& frame1
!= frame
;
1028 frame1
= get_prev_frame (frame1
))
1035 select_frame (frame
, level
);
1038 /* The "frame" command. With no arg, print selected frame briefly.
1039 With arg, behaves like select_frame and then prints the selected
1043 frame_command (level_exp
, from_tty
)
1047 select_frame_command (level_exp
, from_tty
);
1048 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1051 /* Select the frame up one or COUNT stack levels
1052 from the previously selected frame, and print it briefly. */
1056 up_silently_command (count_exp
, from_tty
)
1060 register FRAME frame
;
1061 int count
= 1, count1
;
1063 count
= parse_and_eval_address (count_exp
);
1066 if (target_has_stack
== 0 || selected_frame
== 0)
1067 error ("No stack.");
1069 frame
= find_relative_frame (selected_frame
, &count1
);
1070 if (count1
!= 0 && count_exp
== 0)
1071 error ("Initial frame selected; you cannot go up.");
1072 select_frame (frame
, selected_frame_level
+ count
- count1
);
1076 up_command (count_exp
, from_tty
)
1080 up_silently_command (count_exp
, from_tty
);
1081 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1084 /* Select the frame down one or COUNT stack levels
1085 from the previously selected frame, and print it briefly. */
1089 down_silently_command (count_exp
, from_tty
)
1093 register FRAME frame
;
1094 int count
= -1, count1
;
1096 count
= - parse_and_eval_address (count_exp
);
1099 if (target_has_stack
== 0 || selected_frame
== 0)
1100 error ("No stack.");
1102 frame
= find_relative_frame (selected_frame
, &count1
);
1103 if (count1
!= 0 && count_exp
== 0)
1104 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1105 select_frame (frame
, selected_frame_level
+ count
- count1
);
1110 down_command (count_exp
, from_tty
)
1114 down_silently_command (count_exp
, from_tty
);
1115 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1119 return_command (retval_exp
, from_tty
)
1123 struct symbol
*thisfun
;
1124 FRAME_ADDR selected_frame_addr
;
1125 CORE_ADDR selected_frame_pc
;
1129 if (selected_frame
== NULL
)
1130 error ("No selected frame.");
1131 thisfun
= get_frame_function (selected_frame
);
1132 selected_frame_addr
= FRAME_FP (selected_frame
);
1133 selected_frame_pc
= (get_frame_info (selected_frame
))->pc
;
1135 /* Compute the return value (if any -- possibly getting errors here).
1136 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1137 it might live in the stack frame we're about to pop. */
1141 return_value
= parse_and_eval (retval_exp
);
1142 VALUE_CONTENTS (return_value
);
1145 /* If interactive, require confirmation. */
1151 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun
)))
1153 error ("Not confirmed.");
1158 if (!query ("Make selected stack frame return now? "))
1159 error ("Not confirmed.");
1162 /* Do the real work. Pop until the specified frame is current. We
1163 use this method because the selected_frame is not valid after
1164 a POP_FRAME. The pc comparison makes this work even if the
1165 selected frame shares its fp with another frame. */
1167 while ( selected_frame_addr
!= FRAME_FP (frame
= get_current_frame())
1168 || selected_frame_pc
!= (get_frame_info (frame
))->pc
)
1171 /* Then pop that frame. */
1175 /* Compute the return value (if any) and store in the place
1176 for return values. */
1179 set_return_value (return_value
);
1181 /* If interactive, print the frame that is now current. */
1184 frame_command ("0", 1);
1187 /* Gets the language of the current frame. */
1189 get_frame_language()
1191 register struct symtab
*s
;
1193 enum language flang
; /* The language of the current frame */
1195 fr
= get_frame_info(selected_frame
);
1198 s
= find_pc_symtab(fr
->pc
);
1200 flang
= s
->language
;
1202 flang
= language_unknown
;
1205 flang
= language_unknown
;
1211 _initialize_stack ()
1214 backtrace_limit
= 30;
1217 add_com ("return", class_stack
, return_command
,
1218 "Make selected stack frame return to its caller.\n\
1219 Control remains in the debugger, but when you continue\n\
1220 execution will resume in the frame above the one now selected.\n\
1221 If an argument is given, it is an expression for the value to return.");
1223 add_com ("up", class_stack
, up_command
,
1224 "Select and print stack frame that called this one.\n\
1225 An argument says how many frames up to go.");
1226 add_com ("up-silently", class_support
, up_silently_command
,
1227 "Same as the `up' command, but does not print anything.\n\
1228 This is useful in command scripts.");
1230 add_com ("down", class_stack
, down_command
,
1231 "Select and print stack frame called by this one.\n\
1232 An argument says how many frames down to go.");
1233 add_com_alias ("do", "down", class_stack
, 1);
1234 add_com_alias ("dow", "down", class_stack
, 1);
1235 add_com ("down-silently", class_support
, down_silently_command
,
1236 "Same as the `down' command, but does not print anything.\n\
1237 This is useful in command scripts.");
1239 add_com ("frame", class_stack
, frame_command
,
1240 "Select and print a stack frame.\n\
1241 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1242 An argument specifies the frame to select.\n\
1243 It can be a stack frame number or the address of the frame.\n\
1244 With argument, nothing is printed if input is coming from\n\
1245 a command file or a user-defined command.");
1247 add_com_alias ("f", "frame", class_stack
, 1);
1249 add_com ("select-frame", class_stack
, select_frame_command
,
1250 "Select a stack frame without printing anything.\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");
1254 add_com ("backtrace", class_stack
, backtrace_command
,
1255 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1256 With a negative argument, print outermost -COUNT frames.");
1257 add_com_alias ("bt", "backtrace", class_stack
, 0);
1258 add_com_alias ("where", "backtrace", class_alias
, 0);
1259 add_info ("stack", backtrace_command
,
1260 "Backtrace of the stack, or innermost COUNT frames.");
1261 add_info_alias ("s", "stack", 1);
1262 add_info ("frame", frame_info
,
1263 "All about selected stack frame, or frame at ADDR.");
1264 add_info_alias ("f", "frame", 1);
1265 add_info ("locals", locals_info
,
1266 "Local variables of current stack frame.");
1267 add_info ("args", args_info
,
1268 "Argument variables of current stack frame.");
1269 add_info ("catch", catch_info
,
1270 "Exceptions that can be caught in the current stack frame.");
1273 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1274 "Specify maximum number of frames for \"backtrace\" to print by default.",
1276 add_info ("backtrace-limit", backtrace_limit_info
,
1277 "The maximum number of frames for \"backtrace\" to print by default.");