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. */
24 #include "expression.h"
30 #include "breakpoint.h"
34 return_command
PARAMS ((char *, int));
37 down_command
PARAMS ((char *, int));
40 down_silently_command
PARAMS ((char *, int));
43 up_command
PARAMS ((char *, int));
46 up_silently_command
PARAMS ((char *, int));
49 frame_command
PARAMS ((char *, int));
52 select_frame_command
PARAMS ((char *, int));
55 args_info
PARAMS ((char *, int));
58 print_frame_arg_vars
PARAMS ((FRAME
, FILE *));
61 catch_info
PARAMS ((char *, int));
64 locals_info
PARAMS ((char *, int));
67 print_frame_label_vars
PARAMS ((FRAME
, int, FILE *));
70 print_frame_local_vars
PARAMS ((FRAME
, FILE *));
73 print_block_frame_labels
PARAMS ((struct block
*, int *, FILE *));
76 print_block_frame_locals
PARAMS ((struct block
*, FRAME
, FILE *));
79 backtrace_command
PARAMS ((char *, int));
82 parse_frame_specification
PARAMS ((char *));
85 frame_info
PARAMS ((char *, int));
88 extern int addressprint
; /* Print addresses, or stay symbolic only? */
89 extern int info_verbose
; /* Verbosity of symbol reading msgs */
90 extern int lines_to_list
; /* # of lines "list" command shows by default */
92 /* The "selected" stack frame is used by default for local and arg access.
93 May be zero, for no selected frame. */
97 /* Level of the selected frame:
98 0 for innermost, 1 for its caller, ...
99 or -1 for frame specified by address with no defined level. */
101 int selected_frame_level
;
103 /* Nonzero means print the full filename and linenumber
104 when a frame is printed, and do so in a format programs can parse. */
106 int frame_file_full_name
= 0;
109 /* Print a stack frame briefly. FRAME should be the frame id
110 and LEVEL should be its level in the stack (or -1 for level not defined).
111 This prints the level, the function executing, the arguments,
112 and the file name and line number.
113 If the pc is not at the beginning of the source line,
114 the actual pc is printed at the beginning.
116 If SOURCE is 1, print the source line as well.
117 If SOURCE is -1, print ONLY the source line. */
120 print_stack_frame (frame
, level
, source
)
125 struct frame_info
*fi
;
127 fi
= get_frame_info (frame
);
129 print_frame_info (fi
, level
, source
, 1);
133 print_frame_info (fi
, level
, source
, args
)
134 struct frame_info
*fi
;
139 struct symtab_and_line sal
;
141 register char *funname
= 0;
144 #if 0 /* Symbol reading is fast enough now */
145 struct partial_symtab
*pst
;
147 /* Don't give very much information if we haven't readin the
149 pst
= find_pc_psymtab (fi
->pc
);
150 if (pst
&& !pst
->readin
)
152 /* Abbreviated information. */
155 if (!find_pc_partial_function (fi
->pc
, &fname
, 0))
158 printf_filtered ("#%-2d ", level
);
160 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
162 fputs_demangled (fname
, stdout
, 0);
163 fputs_filtered (" (...)\n", stdout
);
169 #ifdef CORE_NEEDS_RELOCATION
170 CORE_NEEDS_RELOCATION(fi
->pc
);
173 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
174 func
= find_pc_function (fi
->pc
);
177 /* In certain pathological cases, the symtabs give the wrong
178 function (when we are in the first function in a file which
179 is compiled without debugging symbols, the previous function
180 is compiled with debugging symbols, and the "foo.o" symbol
181 that is supposed to tell us where the file with debugging symbols
182 ends has been truncated by ar because it is longer than 15
185 So look in the minimal symbol tables as well, and if it comes
186 up with a larger address for the function use that instead.
187 I don't think this can ever cause any problems; there shouldn't
188 be any minimal symbols in the middle of a function.
189 FIXME: (Not necessarily true. What about text labels) */
191 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
193 && (msymbol
-> address
194 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
196 /* In this case we have no way of knowing the source file
197 and line number, so don't print them. */
199 /* We also don't know anything about the function besides
200 its address and name. */
202 funname
= msymbol
-> name
;
205 funname
= SYMBOL_NAME (func
);
209 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
211 funname
= msymbol
-> name
;
214 if (source
>= 0 || !sal
.symtab
)
217 printf_filtered ("#%-2d ", level
);
219 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
)
220 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
221 fputs_demangled (funname
? funname
: "??", stdout
, 0);
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
);
268 #ifdef FRAME_SPECIFICATION_DYADIC
269 extern FRAME
setup_arbitrary_frame ();
273 * Read a frame specification in whatever the appropriate format is.
274 * Call error() if the specification is in any way invalid (i.e.
275 * this function never returns NULL).
278 parse_frame_specification (frame_exp
)
286 char *addr_string
, *p
;
287 struct cleanup
*tmp_cleanup
;
289 while (*frame_exp
== ' ') frame_exp
++;
290 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 arg1
= parse_and_eval_address (addr_string
);
301 do_cleanups (tmp_cleanup
);
304 while (*p
== ' ') p
++;
309 arg2
= parse_and_eval_address (p
);
317 if (selected_frame
== NULL
)
318 error ("No selected frame.");
319 return selected_frame
;
324 FRAME fid
= find_relative_frame (get_current_frame (), &level
);
328 /* find_relative_frame was successful */
331 /* If (s)he specifies the frame with an address, he deserves what
332 (s)he gets. Still, give the highest one that matches. */
334 for (fid
= get_current_frame ();
335 fid
&& FRAME_FP (fid
) != arg1
;
336 fid
= get_prev_frame (fid
))
340 while ((tfid
= get_prev_frame (fid
)) &&
341 (FRAME_FP (tfid
) == arg1
))
344 #ifdef FRAME_SPECIFICATION_DYADIC
346 error ("Incorrect number of args in frame specification");
350 return create_new_frame (arg1
, 0);
355 /* Must be addresses */
356 #ifndef FRAME_SPECIFICATION_DYADIC
357 error ("Incorrect number of args in frame specification");
359 return setup_arbitrary_frame (arg1
, arg2
);
363 fatal ("Internal: Error in parsing in parse_frame_specification");
367 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
368 that if it is unsure about the answer, it returns 0
369 instead of guessing (this happens on the VAX and i960, for example).
371 On most machines, we never have to guess about the args address,
372 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
373 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
374 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
377 /* Print verbosely the selected frame or the frame at address ADDR.
378 This means absolutely all information in the frame is printed. */
381 frame_info (addr_exp
, from_tty
)
386 struct frame_info
*fi
;
387 struct frame_saved_regs fsr
;
388 struct symtab_and_line sal
;
395 if (!target_has_stack
)
396 error ("No inferior or core file.");
398 frame
= parse_frame_specification (addr_exp
);
400 error ("Invalid frame specified.");
402 fi
= get_frame_info (frame
);
403 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
404 func
= get_frame_function (frame
);
405 s
= find_pc_symtab(fi
->pc
);
407 funname
= SYMBOL_NAME (func
);
410 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
412 funname
= msymbol
-> name
;
414 calling_frame
= get_prev_frame (frame
);
416 if (!addr_exp
&& selected_frame_level
>= 0) {
417 printf_filtered ("Stack level %d, frame at %s:\n",
418 selected_frame_level
,
419 local_hex_string(FRAME_FP(frame
)));
421 printf_filtered ("Stack frame at %s:\n",
422 local_hex_string(FRAME_FP(frame
)));
424 printf_filtered (" %s = %s",
425 reg_names
[PC_REGNUM
],
426 local_hex_string(fi
->pc
));
431 printf_filtered (" in ");
432 fputs_demangled (funname
, stdout
, DMGL_ANSI
| DMGL_PARAMS
);
436 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
437 puts_filtered ("; ");
439 printf_filtered ("saved %s %s\n", reg_names
[PC_REGNUM
],
440 local_hex_string(FRAME_SAVED_PC (frame
)));
444 #ifdef FRAMELESS_FUNCTION_INVOCATION
445 FRAMELESS_FUNCTION_INVOCATION (fi
, frameless
);
448 printf_filtered (" (FRAMELESS),");
452 printf_filtered (" called by frame at %s",
453 local_hex_string(FRAME_FP (calling_frame
)));
454 if (fi
->next_frame
&& calling_frame
)
458 printf_filtered (" caller of frame at %s", local_hex_string(fi
->next_frame
));
459 if (fi
->next_frame
|| calling_frame
)
460 puts_filtered ("\n");
462 printf_filtered(" source language %s.\n", language_str(s
->language
));
465 /* Address of the argument list for this frame, or 0. */
466 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
467 /* Number of args for this frame, or -1 if unknown. */
471 printf_filtered (" Arglist at unknown address.\n");
474 printf_filtered (" Arglist at %s,", local_hex_string(arg_list
));
476 FRAME_NUM_ARGS (numargs
, fi
);
478 puts_filtered (" args: ");
479 else if (numargs
== 0)
480 puts_filtered (" no args.");
481 else if (numargs
== 1)
482 puts_filtered (" 1 arg: ");
484 printf_filtered (" %d args: ", numargs
);
485 print_frame_args (func
, fi
, numargs
, stdout
);
486 puts_filtered ("\n");
490 /* Address of the local variables for this frame, or 0. */
491 CORE_ADDR arg_list
= FRAME_LOCALS_ADDRESS (fi
);
494 printf_filtered (" Locals at unknown address,");
496 printf_filtered (" Locals at %s,", local_hex_string(arg_list
));
499 #if defined (FRAME_FIND_SAVED_REGS)
500 get_frame_saved_regs (fi
, &fsr
);
501 /* The sp is special; what's returned isn't the save address, but
502 actually the value of the previous frame's sp. */
503 printf_filtered (" Previous frame's sp is %s\n",
504 local_hex_string(fsr
.regs
[SP_REGNUM
]));
506 for (i
= 0; i
< NUM_REGS
; i
++)
507 if (fsr
.regs
[i
] && i
!= SP_REGNUM
)
510 puts_filtered (" Saved registers:\n ");
514 printf_filtered (" %s at %s", reg_names
[i
],
515 local_hex_string(fsr
.regs
[i
]));
519 puts_filtered ("\n");
520 #endif /* Have FRAME_FIND_SAVED_REGS. */
524 /* Set a limit on the number of frames printed by default in a
527 static int backtrace_limit
;
530 set_backtrace_limit_command (count_exp
, from_tty
)
534 int count
= parse_and_eval_address (count_exp
);
537 error ("Negative argument not meaningful as backtrace limit.");
539 backtrace_limit
= count
;
543 backtrace_limit_info (arg
, from_tty
)
548 error ("\"Info backtrace-limit\" takes no arguments.");
550 printf ("Backtrace limit: %d.\n", backtrace_limit
);
554 /* Print briefly all stack frames or just the innermost COUNT frames. */
557 backtrace_command (count_exp
, from_tty
)
561 struct frame_info
*fi
;
563 register FRAME frame
;
565 register FRAME trailing
;
566 register int trailing_level
;
568 if (!target_has_stack
)
571 /* The following code must do two things. First, it must
572 set the variable TRAILING to the frame from which we should start
573 printing. Second, it must set the variable count to the number
574 of frames which we should print, or -1 if all of them. */
575 trailing
= get_current_frame ();
579 count
= parse_and_eval_address (count_exp
);
587 while (current
&& count
--)
590 current
= get_prev_frame (current
);
593 /* Will stop when CURRENT reaches the top of the stack. TRAILING
594 will be COUNT below it. */
598 trailing
= get_prev_frame (trailing
);
599 current
= get_prev_frame (current
);
611 struct partial_symtab
*ps
;
613 /* Read in symbols for all of the frames. Need to do this in
614 a separate pass so that "Reading in symbols for xxx" messages
615 don't screw up the appearance of the backtrace. Also
616 if people have strong opinions against reading symbols for
617 backtrace this may have to be an option. */
619 for (frame
= trailing
;
620 frame
!= NULL
&& i
--;
621 frame
= get_prev_frame (frame
))
624 fi
= get_frame_info (frame
);
625 ps
= find_pc_psymtab (fi
->pc
);
627 (void) PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
631 for (i
= 0, frame
= trailing
;
633 i
++, frame
= get_prev_frame (frame
))
636 fi
= get_frame_info (frame
);
637 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
640 /* If we've stopped before the end, mention that. */
641 if (frame
&& from_tty
)
642 printf_filtered ("(More stack frames follow...)\n");
645 /* Print the local variables of a block B active in FRAME.
646 Return 1 if any variables were printed; 0 otherwise. */
649 print_block_frame_locals (b
, frame
, stream
)
651 register FRAME frame
;
652 register FILE *stream
;
656 register struct symbol
*sym
;
657 register int values_printed
= 0;
659 nsyms
= BLOCK_NSYMS (b
);
661 for (i
= 0; i
< nsyms
; i
++)
663 sym
= BLOCK_SYM (b
, i
);
664 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
665 || SYMBOL_CLASS (sym
) == LOC_REGISTER
666 || SYMBOL_CLASS (sym
) == LOC_STATIC
)
669 fprint_symbol (stream
, SYMBOL_NAME (sym
));
670 fputs_filtered (" = ", stream
);
671 print_variable_value (sym
, frame
, stream
);
672 fprintf_filtered (stream
, "\n");
675 return values_printed
;
678 /* Same, but print labels. */
681 print_block_frame_labels (b
, have_default
, stream
)
684 register FILE *stream
;
688 register struct symbol
*sym
;
689 register int values_printed
= 0;
691 nsyms
= BLOCK_NSYMS (b
);
693 for (i
= 0; i
< nsyms
; i
++)
695 sym
= BLOCK_SYM (b
, i
);
696 if (! strcmp (SYMBOL_NAME (sym
), "default"))
702 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
704 struct symtab_and_line sal
;
705 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
707 fputs_demangled (SYMBOL_NAME (sym
), stream
, DMGL_ANSI
| DMGL_PARAMS
);
709 fprintf_filtered (stream
, " %s",
710 local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
711 fprintf_filtered (stream
, " in file %s, line %d\n",
712 sal
.symtab
->filename
, sal
.line
);
715 return values_printed
;
718 /* Print on STREAM all the local variables in frame FRAME,
719 including all the blocks active in that frame
722 Returns 1 if the job was done,
723 or 0 if nothing was printed because we have no info
724 on the function running in FRAME. */
727 print_frame_local_vars (frame
, stream
)
728 register FRAME frame
;
729 register FILE *stream
;
731 register struct block
*block
= get_frame_block (frame
);
732 register int values_printed
= 0;
736 fprintf_filtered (stream
, "No symbol table info available.\n");
742 if (print_block_frame_locals (block
, frame
, stream
))
744 /* After handling the function's top-level block, stop.
745 Don't continue to its superblock, the block of
747 if (BLOCK_FUNCTION (block
))
749 block
= BLOCK_SUPERBLOCK (block
);
754 fprintf_filtered (stream
, "No locals.\n");
758 /* Same, but print labels. */
761 print_frame_label_vars (frame
, this_level_only
, stream
)
762 register FRAME frame
;
764 register FILE *stream
;
766 register struct blockvector
*bl
;
767 register struct block
*block
= get_frame_block (frame
);
768 register int values_printed
= 0;
769 int index
, have_default
= 0;
770 char *blocks_printed
;
771 struct frame_info
*fi
= get_frame_info (frame
);
772 CORE_ADDR pc
= fi
->pc
;
776 fprintf_filtered (stream
, "No symbol table info available.\n");
780 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
781 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
782 (void) memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
786 CORE_ADDR end
= BLOCK_END (block
) - 4;
789 if (bl
!= blockvector_for_pc (end
, &index
))
790 error ("blockvector blotch");
791 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
792 error ("blockvector botch");
793 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
796 /* Don't print out blocks that have gone by. */
797 while (index
< last_index
798 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
801 while (index
< last_index
802 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
804 if (blocks_printed
[index
] == 0)
806 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
808 blocks_printed
[index
] = 1;
814 if (values_printed
&& this_level_only
)
817 /* After handling the function's top-level block, stop.
818 Don't continue to its superblock, the block of
820 if (BLOCK_FUNCTION (block
))
822 block
= BLOCK_SUPERBLOCK (block
);
825 if (!values_printed
&& !this_level_only
)
827 fprintf_filtered (stream
, "No catches.\n");
833 locals_info (args
, from_tty
)
838 error ("No frame selected.");
839 print_frame_local_vars (selected_frame
, stdout
);
843 catch_info (ignore
, from_tty
)
848 error ("No frame selected.");
849 print_frame_label_vars (selected_frame
, 0, stdout
);
853 print_frame_arg_vars (frame
, stream
)
854 register FRAME frame
;
855 register FILE *stream
;
857 struct symbol
*func
= get_frame_function (frame
);
858 register struct block
*b
;
861 register struct symbol
*sym
, *sym2
;
862 register int values_printed
= 0;
866 fprintf_filtered (stream
, "No symbol table info available.\n");
870 b
= SYMBOL_BLOCK_VALUE (func
);
871 nsyms
= BLOCK_NSYMS (b
);
873 for (i
= 0; i
< nsyms
; i
++)
875 sym
= BLOCK_SYM (b
, i
);
876 if (SYMBOL_CLASS (sym
) == LOC_ARG
877 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
878 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
879 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
882 fprint_symbol (stream
, SYMBOL_NAME (sym
));
883 fputs_filtered (" = ", stream
);
884 /* We have to look up the symbol because arguments often have
885 two entries (one a parameter, one a register) and the one
886 we want is the register, which lookup_symbol will find for
888 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
889 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
890 print_variable_value (sym2
, frame
, stream
);
891 fprintf_filtered (stream
, "\n");
897 fprintf_filtered (stream
, "No arguments.\n");
902 args_info (ignore
, from_tty
)
907 error ("No frame selected.");
908 print_frame_arg_vars (selected_frame
, stdout
);
911 /* Select frame FRAME, and note that its stack level is LEVEL.
912 LEVEL may be -1 if an actual level number is not known. */
915 select_frame (frame
, level
)
919 register struct symtab
*s
;
921 selected_frame
= frame
;
922 selected_frame_level
= level
;
924 /* Ensure that symbols for this frame are read in. Also, determine the
925 source language of this frame, and switch to it if desired. */
928 s
= find_pc_symtab (get_frame_info (frame
)->pc
);
930 && s
->language
!= current_language
->la_language
931 && s
->language
!= language_unknown
932 && language_mode
== language_mode_auto
) {
933 set_language(s
->language
);
938 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
939 If there is no selected frame, *FRAMEP is set to NULL. */
942 record_selected_frame (frameaddrp
, levelp
)
943 FRAME_ADDR
*frameaddrp
;
946 *frameaddrp
= selected_frame
? FRAME_FP (selected_frame
) : 0;
947 *levelp
= selected_frame_level
;
950 /* Return the symbol-block in which the selected frame is executing.
951 Can return zero under various legitimate circumstances. */
954 get_selected_block ()
956 if (!target_has_stack
)
960 return get_current_block ();
961 return get_frame_block (selected_frame
);
964 /* Find a frame a certain number of levels away from FRAME.
965 LEVEL_OFFSET_PTR points to an int containing the number of levels.
966 Positive means go to earlier frames (up); negative, the reverse.
967 The int that contains the number of levels is counted toward
968 zero as the frames for those levels are found.
969 If the top or bottom frame is reached, that frame is returned,
970 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
971 how much farther the original request asked to go. */
974 find_relative_frame (frame
, level_offset_ptr
)
975 register FRAME frame
;
976 register int* level_offset_ptr
;
979 register FRAME frame1
;
981 /* Going up is simple: just do get_prev_frame enough times
982 or until initial frame is reached. */
983 while (*level_offset_ptr
> 0)
985 prev
= get_prev_frame (frame
);
988 (*level_offset_ptr
)--;
991 /* Going down is just as simple. */
992 if (*level_offset_ptr
< 0)
994 while (*level_offset_ptr
< 0) {
995 frame1
= get_next_frame (frame
);
999 (*level_offset_ptr
)++;
1005 /* The "select_frame" command. With no arg, NOP.
1006 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1007 valid level. Otherwise, treat level_exp as an address expression
1008 and select it. See parse_frame_specification for more info on proper
1009 frame expressions. */
1013 select_frame_command (level_exp
, from_tty
)
1017 register FRAME frame
, frame1
;
1018 unsigned int level
= 0;
1020 if (!target_has_stack
)
1021 error ("No stack.");
1023 frame
= parse_frame_specification (level_exp
);
1025 /* Try to figure out what level this frame is. But if there is
1026 no current stack, don't error out -- let the user set one. */
1028 if (get_current_frame()) {
1029 for (frame1
= get_prev_frame (0);
1030 frame1
&& frame1
!= frame
;
1031 frame1
= get_prev_frame (frame1
))
1038 select_frame (frame
, level
);
1041 /* The "frame" command. With no arg, print selected frame briefly.
1042 With arg, behaves like select_frame and then prints the selected
1046 frame_command (level_exp
, from_tty
)
1050 select_frame_command (level_exp
, from_tty
);
1051 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1054 /* Select the frame up one or COUNT stack levels
1055 from the previously selected frame, and print it briefly. */
1059 up_silently_command (count_exp
, from_tty
)
1063 register FRAME frame
;
1064 int count
= 1, count1
;
1066 count
= parse_and_eval_address (count_exp
);
1069 if (!target_has_stack
)
1070 error ("No stack.");
1072 frame
= find_relative_frame (selected_frame
, &count1
);
1073 if (count1
!= 0 && count_exp
== 0)
1074 error ("Initial frame selected; you cannot go up.");
1075 select_frame (frame
, selected_frame_level
+ count
- count1
);
1079 up_command (count_exp
, from_tty
)
1083 up_silently_command (count_exp
, from_tty
);
1084 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1087 /* Select the frame down one or COUNT stack levels
1088 from the previously selected frame, and print it briefly. */
1092 down_silently_command (count_exp
, from_tty
)
1096 register FRAME frame
;
1097 int count
= -1, count1
;
1099 count
= - parse_and_eval_address (count_exp
);
1102 if (!target_has_stack
)
1103 error ("No stack.");
1105 frame
= find_relative_frame (selected_frame
, &count1
);
1106 if (count1
!= 0 && count_exp
== 0)
1107 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1108 select_frame (frame
, selected_frame_level
+ count
- count1
);
1113 down_command (count_exp
, from_tty
)
1117 down_silently_command (count_exp
, from_tty
);
1118 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1122 return_command (retval_exp
, from_tty
)
1126 struct symbol
*thisfun
;
1127 FRAME_ADDR selected_frame_addr
;
1128 CORE_ADDR selected_frame_pc
;
1131 struct cleanup
*back_to
;
1133 if (selected_frame
== NULL
)
1134 error ("No selected frame.");
1135 thisfun
= get_frame_function (selected_frame
);
1136 selected_frame_addr
= FRAME_FP (selected_frame
);
1137 selected_frame_pc
= (get_frame_info (selected_frame
))->pc
;
1139 /* If interactive, require confirmation. */
1145 funcname
= strdup_demangled (SYMBOL_NAME (thisfun
));
1146 back_to
= make_cleanup (free
, funcname
);
1147 if (!query ("Make %s return now? ", funcname
))
1149 error ("Not confirmed.");
1152 do_cleanups (back_to
);
1155 if (!query ("Make selected stack frame return now? "))
1156 error ("Not confirmed.");
1159 /* Do the real work. Pop until the specified frame is current. We
1160 use this method because the selected_frame is not valid after
1161 a POP_FRAME. The pc comparison makes this work even if the
1162 selected frame shares its fp with another frame. */
1164 while ( selected_frame_addr
!= FRAME_FP (frame
= get_current_frame())
1165 || selected_frame_pc
!= (get_frame_info (frame
))->pc
)
1168 /* Then pop that frame. */
1172 /* Compute the return value (if any) and store in the place
1173 for return values. */
1176 set_return_value (parse_and_eval (retval_exp
));
1178 /* If interactive, print the frame that is now current. */
1181 frame_command ("0", 1);
1184 /* Gets the language of the current frame. */
1186 get_frame_language()
1188 register struct symtab
*s
;
1190 enum language flang
; /* The language of the current frame */
1192 fr
= get_frame_info(selected_frame
);
1195 s
= find_pc_symtab(fr
->pc
);
1197 flang
= s
->language
;
1199 flang
= language_unknown
;
1202 flang
= language_unknown
;
1208 _initialize_stack ()
1211 backtrace_limit
= 30;
1214 add_com ("return", class_stack
, return_command
,
1215 "Make selected stack frame return to its caller.\n\
1216 Control remains in the debugger, but when you continue\n\
1217 execution will resume in the frame above the one now selected.\n\
1218 If an argument is given, it is an expression for the value to return.");
1220 add_com ("up", class_stack
, up_command
,
1221 "Select and print stack frame that called this one.\n\
1222 An argument says how many frames up to go.");
1223 add_com ("up-silently", class_support
, up_silently_command
,
1224 "Same as the `up' command, but does not print anything.\n\
1225 This is useful in command scripts.");
1227 add_com ("down", class_stack
, down_command
,
1228 "Select and print stack frame called by this one.\n\
1229 An argument says how many frames down to go.");
1230 add_com_alias ("do", "down", class_stack
, 1);
1231 add_com ("down-silently", class_support
, down_silently_command
,
1232 "Same as the `down' command, but does not print anything.\n\
1233 This is useful in command scripts.");
1235 add_com ("frame", class_stack
, frame_command
,
1236 "Select and print a stack frame.\n\
1237 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1238 An argument specifies the frame to select.\n\
1239 It can be a stack frame number or the address of the frame.\n\
1240 With argument, nothing is printed if input is coming from\n\
1241 a command file or a user-defined command.");
1243 add_com_alias ("f", "frame", class_stack
, 1);
1245 add_com ("select-frame", class_stack
, select_frame_command
,
1246 "Select a stack frame without printing anything.\n\
1247 An argument specifies the frame to select.\n\
1248 It can be a stack frame number or the address of the frame.\n");
1250 add_com ("backtrace", class_stack
, backtrace_command
,
1251 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1252 With a negative argument, print outermost -COUNT frames.");
1253 add_com_alias ("bt", "backtrace", class_stack
, 0);
1254 add_com_alias ("where", "backtrace", class_alias
, 0);
1255 add_info ("stack", backtrace_command
,
1256 "Backtrace of the stack, or innermost COUNT frames.");
1257 add_info_alias ("s", "stack", 1);
1258 add_info ("frame", frame_info
,
1259 "All about selected stack frame, or frame at ADDR.");
1260 add_info_alias ("f", "frame", 1);
1261 add_info ("locals", locals_info
,
1262 "Local variables of current stack frame.");
1263 add_info ("args", args_info
,
1264 "Argument variables of current stack frame.");
1265 add_info ("catch", catch_info
,
1266 "Exceptions that can be caught in the current stack frame.");
1269 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1270 "Specify maximum number of frames for \"backtrace\" to print by default.",
1272 add_info ("backtrace-limit", backtrace_limit_info
,
1273 "The maximum number of frames for \"backtrace\" to print by default.");