1 /* Print and select stack frames for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989, 1991 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. */
31 #include "breakpoint.h"
33 extern int addressprint
; /* Print addresses, or stay symbolic only? */
34 extern int info_verbose
; /* Verbosity of symbol reading msgs */
35 extern int lines_to_list
; /* # of lines "list" command shows by default */
36 extern char *reg_names
[]; /* Names of registers */
38 /* Thie "selected" stack frame is used by default for local and arg access.
39 May be zero, for no selected frame. */
43 /* Level of the selected frame:
44 0 for innermost, 1 for its caller, ...
45 or -1 for frame specified by address with no defined level. */
47 int selected_frame_level
;
49 /* Nonzero means print the full filename and linenumber
50 when a frame is printed, and do so in a format programs can parse. */
52 int frame_file_full_name
= 0;
54 void print_frame_info ();
56 /* Print a stack frame briefly. FRAME should be the frame id
57 and LEVEL should be its level in the stack (or -1 for level not defined).
58 This prints the level, the function executing, the arguments,
59 and the file name and line number.
60 If the pc is not at the beginning of the source line,
61 the actual pc is printed at the beginning.
63 If SOURCE is 1, print the source line as well.
64 If SOURCE is -1, print ONLY the source line. */
67 print_stack_frame (frame
, level
, source
)
72 struct frame_info
*fi
;
74 fi
= get_frame_info (frame
);
76 print_frame_info (fi
, level
, source
, 1);
80 print_frame_info (fi
, level
, source
, args
)
81 struct frame_info
*fi
;
86 struct symtab_and_line sal
;
88 register char *funname
= 0;
91 #if 0 /* Symbol reading is fast enough now */
92 struct partial_symtab
*pst
;
94 /* Don't give very much information if we haven't readin the
96 pst
= find_pc_psymtab (fi
->pc
);
97 if (pst
&& !pst
->readin
)
99 /* Abbreviated information. */
102 if (!find_pc_partial_function (fi
->pc
, &fname
, 0))
105 printf_filtered ("#%-2d ", level
);
107 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
109 fputs_demangled (fname
, stdout
, -1);
110 fputs_filtered (" (...)\n", stdout
);
116 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
117 func
= find_pc_function (fi
->pc
);
120 /* In certain pathological cases, the symtabs give the wrong
121 function (when we are in the first function in a file which
122 is compiled without debugging symbols, the previous function
123 is compiled with debugging symbols, and the "foo.o" symbol
124 that is supposed to tell us where the file with debugging symbols
125 ends has been truncated by ar because it is longer than 15
128 So look in the misc_function_vector as well, and if it comes
129 up with a larger address for the function use that instead.
130 I don't think this can ever cause any problems;
131 there shouldn't be any
132 misc_function_vector symbols in the middle of a function. */
133 int misc_index
= find_pc_misc_function (fi
->pc
);
135 && (misc_function_vector
[misc_index
].address
136 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
138 /* In this case we have no way of knowing the source file
139 and line number, so don't print them. */
141 /* We also don't know anything about the function besides
142 its address and name. */
144 funname
= misc_function_vector
[misc_index
].name
;
147 funname
= SYMBOL_NAME (func
);
151 register int misc_index
= find_pc_misc_function (fi
->pc
);
153 funname
= misc_function_vector
[misc_index
].name
;
156 if (source
>= 0 || !sal
.symtab
)
159 printf_filtered ("#%-2d ", level
);
161 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
)
162 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
163 fputs_demangled (funname
? funname
: "??", stdout
, -1);
165 fputs_filtered (" (", stdout
);
168 FRAME_NUM_ARGS (numargs
, fi
);
169 print_frame_args (func
, fi
, numargs
, stdout
);
171 printf_filtered (")");
172 if (sal
.symtab
&& sal
.symtab
->filename
)
175 printf_filtered (" at %s:%d", sal
.symtab
->filename
, sal
.line
);
177 printf_filtered ("\n");
180 if ((source
!= 0) && sal
.symtab
)
183 int mid_statement
= source
< 0 && fi
->pc
!= sal
.pc
;
184 if (frame_file_full_name
)
185 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
);
188 if (addressprint
&& mid_statement
)
189 printf_filtered ("%s\t", local_hex_string(fi
->pc
));
190 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
192 current_source_line
= max (sal
.line
- lines_to_list
/2, 1);
195 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
200 void flush_cached_frames ();
202 #ifdef FRAME_SPECIFICATION_DYADIC
203 extern FRAME
setup_arbitrary_frame ();
207 * Read a frame specification in whatever the appropriate format is.
208 * Call error() if the specification is in any way invalid (i.e.
209 * this function never returns NULL).
212 parse_frame_specification (frame_exp
)
220 char *addr_string
, *p
;
221 struct cleanup
*tmp_cleanup
;
223 while (*frame_exp
== ' ') frame_exp
++;
224 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
230 addr_string
= savestring(frame_exp
, p
- frame_exp
);
233 tmp_cleanup
= make_cleanup (free
, addr_string
);
234 arg1
= parse_and_eval_address (addr_string
);
235 do_cleanups (tmp_cleanup
);
238 while (*p
== ' ') p
++;
243 arg2
= parse_and_eval_address (p
);
251 if (selected_frame
== NULL
)
252 error ("No selected frame.");
253 return selected_frame
;
258 FRAME fid
= find_relative_frame (get_current_frame (), &level
);
262 /* find_relative_frame was successful */
265 /* If (s)he specifies the frame with an address, he deserves what
266 (s)he gets. Still, give the highest one that matches. */
268 for (fid
= get_current_frame ();
269 fid
&& FRAME_FP (fid
) != arg1
;
270 fid
= get_prev_frame (fid
))
274 while ((tfid
= get_prev_frame (fid
)) &&
275 (FRAME_FP (tfid
) == arg1
))
278 #ifdef FRAME_SPECIFICATION_DYADIC
280 error ("Incorrect number of args in frame specification");
284 return create_new_frame (arg1
, 0);
289 /* Must be addresses */
290 #ifndef FRAME_SPECIFICATION_DYADIC
291 error ("Incorrect number of args in frame specification");
293 return setup_arbitrary_frame (arg1
, arg2
);
297 fatal ("Internal: Error in parsing in parse_frame_specification");
301 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
302 that if it is unsure about the answer, it returns 0
303 instead of guessing (this happens on the VAX and i960, for example).
305 On most machines, we never have to guess about the args address,
306 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
307 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
308 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
311 /* Print verbosely the selected frame or the frame at address ADDR.
312 This means absolutely all information in the frame is printed. */
315 frame_info (addr_exp
)
319 struct frame_info
*fi
;
320 struct frame_saved_regs fsr
;
321 struct symtab_and_line sal
;
328 if (!target_has_stack
)
329 error ("No inferior or core file.");
331 frame
= parse_frame_specification (addr_exp
);
333 error ("Invalid frame specified.");
335 fi
= get_frame_info (frame
);
336 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
337 func
= get_frame_function (frame
);
338 s
= find_pc_symtab(fi
->pc
);
340 funname
= SYMBOL_NAME (func
);
343 register int misc_index
= find_pc_misc_function (fi
->pc
);
345 funname
= misc_function_vector
[misc_index
].name
;
347 calling_frame
= get_prev_frame (frame
);
349 if (!addr_exp
&& selected_frame_level
>= 0) {
350 printf_filtered ("Stack level %d, frame at %s:\n",
351 selected_frame_level
,
352 local_hex_string(FRAME_FP(frame
)));
354 printf_filtered ("Stack frame at %s:\n",
355 local_hex_string(FRAME_FP(frame
)));
357 printf_filtered (" %s = %s",
358 reg_names
[PC_REGNUM
],
359 local_hex_string(fi
->pc
));
363 printf_filtered (" in %s", funname
);
366 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
367 puts_filtered ("; ");
369 printf_filtered ("saved %s %s\n", reg_names
[PC_REGNUM
],
370 local_hex_string(FRAME_SAVED_PC (frame
)));
372 printf_filtered (" called by frame at %s",
373 local_hex_string(FRAME_FP (calling_frame
)));
374 if (fi
->next_frame
&& calling_frame
)
378 printf_filtered (" caller of frame at %s", local_hex_string(fi
->next_frame
));
379 if (fi
->next_frame
|| calling_frame
)
380 puts_filtered ("\n");
382 printf_filtered(" source language %s.\n", language_str(s
->language
));
385 /* Address of the argument list for this frame, or 0. */
386 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
387 /* Number of args for this frame, or -1 if unknown. */
391 printf_filtered (" Arglist at unknown address.\n");
394 printf_filtered (" Arglist at %s,", local_hex_string(arg_list
));
396 FRAME_NUM_ARGS (numargs
, fi
);
398 puts_filtered (" args: ");
399 else if (numargs
== 0)
400 puts_filtered (" no args.");
401 else if (numargs
== 1)
402 puts_filtered (" 1 arg: ");
404 printf_filtered (" %d args: ", numargs
);
405 print_frame_args (func
, fi
, numargs
, stdout
);
406 puts_filtered ("\n");
410 #if defined (FRAME_FIND_SAVED_REGS)
411 get_frame_saved_regs (fi
, &fsr
);
412 /* The sp is special; what's returned isn't the save address, but
413 actually the value of the previous frame's sp. */
414 printf_filtered (" Previous frame's sp is %s\n",
415 local_hex_string(fsr
.regs
[SP_REGNUM
]));
417 for (i
= 0; i
< NUM_REGS
; i
++)
418 if (fsr
.regs
[i
] && i
!= SP_REGNUM
)
421 puts_filtered (" Saved registers:\n ");
425 printf_filtered (" %s at %s", reg_names
[i
],
426 local_hex_string(fsr
.regs
[i
]));
430 puts_filtered ("\n");
431 #endif /* Have FRAME_FIND_SAVED_REGS. */
435 /* Set a limit on the number of frames printed by default in a
438 static int backtrace_limit
;
441 set_backtrace_limit_command (count_exp
, from_tty
)
445 int count
= parse_and_eval_address (count_exp
);
448 error ("Negative argument not meaningful as backtrace limit.");
450 backtrace_limit
= count
;
454 backtrace_limit_info (arg
, from_tty
)
459 error ("\"Info backtrace-limit\" takes no arguments.");
461 printf ("Backtrace limit: %d.\n", backtrace_limit
);
465 /* Print briefly all stack frames or just the innermost COUNT frames. */
468 backtrace_command (count_exp
, from_tty
)
472 struct frame_info
*fi
;
474 register FRAME frame
;
476 register FRAME trailing
;
477 register int trailing_level
;
479 if (!target_has_stack
)
482 /* The following code must do two things. First, it must
483 set the variable TRAILING to the frame from which we should start
484 printing. Second, it must set the variable count to the number
485 of frames which we should print, or -1 if all of them. */
486 trailing
= get_current_frame ();
490 count
= parse_and_eval_address (count_exp
);
498 while (current
&& count
--)
501 current
= get_prev_frame (current
);
504 /* Will stop when CURRENT reaches the top of the stack. TRAILING
505 will be COUNT below it. */
509 trailing
= get_prev_frame (trailing
);
510 current
= get_prev_frame (current
);
522 struct partial_symtab
*ps
;
524 /* Read in symbols for all of the frames. Need to do this in
525 a separate pass so that "Reading in symbols for xxx" messages
526 don't screw up the appearance of the backtrace. Also
527 if people have strong opinions against reading symbols for
528 backtrace this may have to be an option. */
530 for (frame
= trailing
;
531 frame
!= NULL
&& i
--;
532 frame
= get_prev_frame (frame
))
535 fi
= get_frame_info (frame
);
536 ps
= find_pc_psymtab (fi
->pc
);
538 (void) PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
542 for (i
= 0, frame
= trailing
;
544 i
++, frame
= get_prev_frame (frame
))
547 fi
= get_frame_info (frame
);
548 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
551 /* If we've stopped before the end, mention that. */
552 if (frame
&& from_tty
)
553 printf_filtered ("(More stack frames follow...)\n");
556 /* Print the local variables of a block B active in FRAME.
557 Return 1 if any variables were printed; 0 otherwise. */
560 print_block_frame_locals (b
, frame
, stream
)
562 register FRAME frame
;
563 register FILE *stream
;
567 register struct symbol
*sym
;
568 register int values_printed
= 0;
570 nsyms
= BLOCK_NSYMS (b
);
572 for (i
= 0; i
< nsyms
; i
++)
574 sym
= BLOCK_SYM (b
, i
);
575 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
576 || SYMBOL_CLASS (sym
) == LOC_REGISTER
577 || SYMBOL_CLASS (sym
) == LOC_STATIC
)
580 fprint_symbol (stream
, SYMBOL_NAME (sym
));
581 fputs_filtered (" = ", stream
);
582 print_variable_value (sym
, frame
, stream
);
583 fprintf_filtered (stream
, "\n");
587 return values_printed
;
590 /* Same, but print labels. */
593 print_block_frame_labels (b
, have_default
, stream
)
596 register FILE *stream
;
600 register struct symbol
*sym
;
601 register int values_printed
= 0;
603 nsyms
= BLOCK_NSYMS (b
);
605 for (i
= 0; i
< nsyms
; i
++)
607 sym
= BLOCK_SYM (b
, i
);
608 if (! strcmp (SYMBOL_NAME (sym
), "default"))
614 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
616 struct symtab_and_line sal
;
617 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
619 fputs_demangled (SYMBOL_NAME (sym
), stream
, 1);
621 fprintf_filtered (stream
, " %s",
622 local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
623 fprintf_filtered (stream
, " in file %s, line %d\n",
624 sal
.symtab
->filename
, sal
.line
);
628 return values_printed
;
631 /* Print on STREAM all the local variables in frame FRAME,
632 including all the blocks active in that frame
635 Returns 1 if the job was done,
636 or 0 if nothing was printed because we have no info
637 on the function running in FRAME. */
640 print_frame_local_vars (frame
, stream
)
641 register FRAME frame
;
642 register FILE *stream
;
644 register struct block
*block
= get_frame_block (frame
);
645 register int values_printed
= 0;
649 fprintf_filtered (stream
, "No symbol table info available.\n");
656 if (print_block_frame_locals (block
, frame
, stream
))
658 /* After handling the function's top-level block, stop.
659 Don't continue to its superblock, the block of
661 if (BLOCK_FUNCTION (block
))
663 block
= BLOCK_SUPERBLOCK (block
);
668 fprintf_filtered (stream
, "No locals.\n");
675 /* Same, but print labels. */
678 print_frame_label_vars (frame
, this_level_only
, stream
)
679 register FRAME frame
;
681 register FILE *stream
;
683 extern struct blockvector
*blockvector_for_pc ();
684 register struct blockvector
*bl
;
685 register struct block
*block
= get_frame_block (frame
);
686 register int values_printed
= 0;
687 int index
, have_default
= 0;
688 char *blocks_printed
;
689 struct frame_info
*fi
= get_frame_info (frame
);
690 CORE_ADDR pc
= fi
->pc
;
694 fprintf_filtered (stream
, "No symbol table info available.\n");
699 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
700 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
701 bzero (blocks_printed
, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
705 CORE_ADDR end
= BLOCK_END (block
) - 4;
708 if (bl
!= blockvector_for_pc (end
, &index
))
709 error ("blockvector blotch");
710 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
711 error ("blockvector botch");
712 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
715 /* Don't print out blocks that have gone by. */
716 while (index
< last_index
717 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
720 while (index
< last_index
721 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
723 if (blocks_printed
[index
] == 0)
725 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
727 blocks_printed
[index
] = 1;
733 if (values_printed
&& this_level_only
)
736 /* After handling the function's top-level block, stop.
737 Don't continue to its superblock, the block of
739 if (BLOCK_FUNCTION (block
))
741 block
= BLOCK_SUPERBLOCK (block
);
744 if (!values_printed
&& !this_level_only
)
746 fprintf_filtered (stream
, "No catches.\n");
750 return values_printed
;
755 locals_info (args
, from_tty
)
760 error ("No frame selected.");
761 print_frame_local_vars (selected_frame
, stdout
);
768 error ("No frame selected.");
769 print_frame_label_vars (selected_frame
, 0, stdout
);
773 print_frame_arg_vars (frame
, stream
)
774 register FRAME frame
;
775 register FILE *stream
;
777 struct symbol
*func
= get_frame_function (frame
);
778 register struct block
*b
;
781 register struct symbol
*sym
, *sym2
;
782 register int values_printed
= 0;
786 fprintf_filtered (stream
, "No symbol table info available.\n");
791 b
= SYMBOL_BLOCK_VALUE (func
);
792 nsyms
= BLOCK_NSYMS (b
);
794 for (i
= 0; i
< nsyms
; i
++)
796 sym
= BLOCK_SYM (b
, i
);
797 if (SYMBOL_CLASS (sym
) == LOC_ARG
798 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
799 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
800 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
803 fprint_symbol (stream
, SYMBOL_NAME (sym
));
804 fputs_filtered (" = ", stream
);
805 /* We have to look up the symbol because arguments often have
806 two entries (one a parameter, one a register) and the one
807 we want is the register, which lookup_symbol will find for
809 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
810 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
811 print_variable_value (sym2
, frame
, stream
);
812 fprintf_filtered (stream
, "\n");
819 fprintf_filtered (stream
, "No arguments.\n");
830 error ("No frame selected.");
831 print_frame_arg_vars (selected_frame
, stdout
);
834 /* Select frame FRAME, and note that its stack level is LEVEL.
835 LEVEL may be -1 if an actual level number is not known. */
838 select_frame (frame
, level
)
842 register struct symtab
*s
;
844 selected_frame
= frame
;
845 selected_frame_level
= level
;
847 /* Ensure that symbols for this frame are read in. Also, determine the
848 source language of this frame, and switch to it if desired. */
851 s
= find_pc_symtab (get_frame_info (frame
)->pc
);
853 && s
->language
!= current_language
->la_language
854 && s
->language
!= language_unknown
855 && language_mode
== language_mode_auto
) {
856 set_language(s
->language
);
861 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
862 If there is no selected frame, *FRAMEP is set to NULL. */
865 record_selected_frame (frameaddrp
, levelp
)
866 FRAME_ADDR
*frameaddrp
;
869 *frameaddrp
= selected_frame
? FRAME_FP (selected_frame
) : NULL
;
870 *levelp
= selected_frame_level
;
873 /* Return the symbol-block in which the selected frame is executing.
874 Can return zero under various legitimate circumstances. */
877 get_selected_block ()
879 if (!target_has_stack
)
883 return get_current_block ();
884 return get_frame_block (selected_frame
);
887 /* Find a frame a certain number of levels away from FRAME.
888 LEVEL_OFFSET_PTR points to an int containing the number of levels.
889 Positive means go to earlier frames (up); negative, the reverse.
890 The int that contains the number of levels is counted toward
891 zero as the frames for those levels are found.
892 If the top or bottom frame is reached, that frame is returned,
893 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
894 how much farther the original request asked to go. */
897 find_relative_frame (frame
, level_offset_ptr
)
898 register FRAME frame
;
899 register int* level_offset_ptr
;
902 register FRAME frame1
;
904 /* Going up is simple: just do get_prev_frame enough times
905 or until initial frame is reached. */
906 while (*level_offset_ptr
> 0)
908 prev
= get_prev_frame (frame
);
911 (*level_offset_ptr
)--;
914 /* Going down is just as simple. */
915 if (*level_offset_ptr
< 0)
917 while (*level_offset_ptr
< 0) {
918 frame1
= get_next_frame (frame
);
922 (*level_offset_ptr
)++;
928 /* The "frame" command. With no arg, print selected frame briefly.
929 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
930 valid level. Otherwise, treat level_exp as an address expression
931 and print it. See parse_frame_specification for more info on proper
932 frame expressions. */
935 frame_command (level_exp
, from_tty
)
939 register FRAME frame
, frame1
;
940 unsigned int level
= 0;
942 if (!target_has_stack
)
945 frame
= parse_frame_specification (level_exp
);
947 /* Try to figure out what level this frame is. But if there is
948 no current stack, don't error out -- let the user set one. */
950 if (get_current_frame()) {
951 for (frame1
= get_prev_frame (0);
952 frame1
&& frame1
!= frame
;
953 frame1
= get_prev_frame (frame1
))
960 select_frame (frame
, level
);
965 print_stack_frame (selected_frame
, selected_frame_level
, 1);
968 /* Select the frame up one or COUNT stack levels
969 from the previously selected frame, and print it briefly. */
973 up_silently_command (count_exp
, from_tty
)
977 register FRAME frame
;
978 int count
= 1, count1
;
980 count
= parse_and_eval_address (count_exp
);
983 if (!target_has_stack
)
986 frame
= find_relative_frame (selected_frame
, &count1
);
987 if (count1
!= 0 && count_exp
== 0)
988 error ("Initial frame selected; you cannot go up.");
989 select_frame (frame
, selected_frame_level
+ count
- count1
);
993 up_command (count_exp
, from_tty
)
997 up_silently_command (count_exp
, from_tty
);
998 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1001 /* Select the frame down one or COUNT stack levels
1002 from the previously selected frame, and print it briefly. */
1006 down_silently_command (count_exp
, from_tty
)
1010 register FRAME frame
;
1011 int count
= -1, count1
;
1013 count
= - parse_and_eval_address (count_exp
);
1016 if (!target_has_stack
)
1017 error ("No stack.");
1019 frame
= find_relative_frame (selected_frame
, &count1
);
1020 if (count1
!= 0 && count_exp
== 0)
1021 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1022 select_frame (frame
, selected_frame_level
+ count
- count1
);
1027 down_command (count_exp
, from_tty
)
1031 down_silently_command (count_exp
, from_tty
);
1032 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1036 return_command (retval_exp
, from_tty
)
1040 struct symbol
*thisfun
;
1041 FRAME_ADDR selected_frame_addr
;
1042 CORE_ADDR selected_frame_pc
;
1045 if (selected_frame
== NULL
)
1046 error ("No selected frame.");
1047 thisfun
= get_frame_function (selected_frame
);
1048 selected_frame_addr
= FRAME_FP (selected_frame
);
1049 selected_frame_pc
= (get_frame_info (selected_frame
))->pc
;
1051 /* If interactive, require confirmation. */
1057 if (!query ("Make %s return now? ", SYMBOL_NAME (thisfun
)))
1058 error ("Not confirmed.");
1061 if (!query ("Make selected stack frame return now? "))
1062 error ("Not confirmed.");
1065 /* Do the real work. Pop until the specified frame is current. We
1066 use this method because the selected_frame is not valid after
1067 a POP_FRAME. The pc comparison makes this work even if the
1068 selected frame shares its fp with another frame. */
1070 while ( selected_frame_addr
!= FRAME_FP (frame
= get_current_frame())
1071 || selected_frame_pc
!= (get_frame_info (frame
))->pc
)
1074 /* Then pop that frame. */
1078 /* Compute the return value (if any) and store in the place
1079 for return values. */
1082 set_return_value (parse_and_eval (retval_exp
));
1084 /* If interactive, print the frame that is now current. */
1087 frame_command ("0", 1);
1090 /* Gets the language of the current frame. */
1092 get_frame_language()
1094 register struct symtab
*s
;
1096 enum language flang
; /* The language of the current frame */
1098 fr
= get_frame_info(selected_frame
);
1101 s
= find_pc_symtab(fr
->pc
);
1103 flang
= s
->language
;
1105 flang
= language_unknown
;
1108 flang
= language_unknown
;
1114 _initialize_stack ()
1117 backtrace_limit
= 30;
1120 add_com ("return", class_stack
, return_command
,
1121 "Make selected stack frame return to its caller.\n\
1122 Control remains in the debugger, but when you continue\n\
1123 execution will resume in the frame above the one now selected.\n\
1124 If an argument is given, it is an expression for the value to return.");
1126 add_com ("up", class_stack
, up_command
,
1127 "Select and print stack frame that called this one.\n\
1128 An argument says how many frames up to go.");
1129 add_com ("up-silently", class_support
, up_silently_command
,
1130 "Same as the `up' command, but does not print anything.\n\
1131 This is useful in command scripts.");
1133 add_com ("down", class_stack
, down_command
,
1134 "Select and print stack frame called by this one.\n\
1135 An argument says how many frames down to go.");
1136 add_com_alias ("do", "down", class_stack
, 1);
1137 add_com ("down-silently", class_support
, down_silently_command
,
1138 "Same as the `down' command, but does not print anything.\n\
1139 This is useful in command scripts.");
1141 add_com ("frame", class_stack
, frame_command
,
1142 "Select and print a stack frame.\n\
1143 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1144 An argument specifies the frame to select.\n\
1145 It can be a stack frame number or the address of the frame.\n\
1146 With argument, nothing is printed if input is coming from\n\
1147 a command file or a user-defined command.");
1149 add_com_alias ("f", "frame", class_stack
, 1);
1151 add_com ("backtrace", class_stack
, backtrace_command
,
1152 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1153 With a negative argument, print outermost -COUNT frames.");
1154 add_com_alias ("bt", "backtrace", class_stack
, 0);
1155 add_com_alias ("where", "backtrace", class_alias
, 0);
1156 add_info ("stack", backtrace_command
,
1157 "Backtrace of the stack, or innermost COUNT frames.");
1158 add_info_alias ("s", "stack", 1);
1159 add_info ("frame", frame_info
,
1160 "All about selected stack frame, or frame at ADDR.");
1161 add_info_alias ("f", "frame", 1);
1162 add_info ("locals", locals_info
,
1163 "Local variables of current stack frame.");
1164 add_info ("args", args_info
,
1165 "Argument variables of current stack frame.");
1166 add_info ("catch", catch_info
,
1167 "Exceptions that can be caught in the current stack frame.");
1170 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1171 "Specify maximum number of frames for \"backtrace\" to print by default.",
1173 add_info ("backtrace-limit", backtrace_limit_info
,
1174 "The maximum number of frames for \"backtrace\" to print by default.");