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"
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;
142 enum language funlang = language_unknown;
145 #ifdef CORE_NEEDS_RELOCATION
146 CORE_NEEDS_RELOCATION(fi->pc);
149 sal = find_pc_line (fi->pc, fi->next_frame);
150 func = find_pc_function (fi->pc);
153 /* In certain pathological cases, the symtabs give the wrong
154 function (when we are in the first function in a file which
155 is compiled without debugging symbols, the previous function
156 is compiled with debugging symbols, and the "foo.o" symbol
157 that is supposed to tell us where the file with debugging symbols
158 ends has been truncated by ar because it is longer than 15
161 So look in the minimal symbol tables as well, and if it comes
162 up with a larger address for the function use that instead.
163 I don't think this can ever cause any problems; there shouldn't
164 be any minimal symbols in the middle of a function.
165 FIXME: (Not necessarily true. What about text labels) */
167 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
169 && (SYMBOL_VALUE_ADDRESS (msymbol)
170 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
172 /* In this case we have no way of knowing the source file
173 and line number, so don't print them. */
175 /* We also don't know anything about the function besides
176 its address and name. */
178 funname = SYMBOL_NAME (msymbol);
179 funlang = SYMBOL_LANGUAGE (msymbol);
183 funname = SYMBOL_NAME (func);
184 funlang = SYMBOL_LANGUAGE (func);
189 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
192 funname = SYMBOL_NAME (msymbol);
193 funlang = SYMBOL_LANGUAGE (msymbol);
197 if (source >= 0 || !sal.symtab)
200 printf_filtered ("#%-2d ", level);
202 if (fi->pc != sal.pc || !sal.symtab)
203 printf_filtered ("%s in ", local_hex_string(fi->pc));
204 fprintf_symbol_filtered (stdout, funname ? funname : "??", funlang,
207 fputs_filtered (" (", stdout);
210 FRAME_NUM_ARGS (numargs, fi);
211 print_frame_args (func, fi, numargs, stdout);
213 printf_filtered (")");
214 if (sal.symtab && sal.symtab->filename)
217 printf_filtered (" at %s:%d", sal.symtab->filename, sal.line);
220 #ifdef PC_LOAD_SEGMENT
221 /* If we couldn't print out function name but if can figure out what
222 load segment this pc value is from, at least print out some info
223 about its load segment. */
226 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
229 printf_filtered ("\n");
232 if ((source != 0) && sal.symtab)
235 int mid_statement = source < 0 && fi->pc != sal.pc;
236 if (frame_file_full_name)
237 done = identify_source_line (sal.symtab, sal.line, mid_statement);
240 if (addressprint && mid_statement)
241 printf_filtered ("%s\t", local_hex_string(fi->pc));
242 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
244 current_source_line = max (sal.line - lines_to_list/2, 1);
247 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
253 * Read a frame specification in whatever the appropriate format is.
254 * Call error() if the specification is in any way invalid (i.e.
255 * this function never returns NULL).
258 parse_frame_specification (frame_exp)
262 int arg1, arg2, arg3;
268 char *addr_string, *p;
269 struct cleanup *tmp_cleanup;
271 while (*frame_exp == ' ') frame_exp++;
275 if (numargs > MAXARGS)
276 error ("Too many args in frame specification");
277 /* Parse an argument. */
278 for (p = frame_exp; *p && *p != ' '; p++)
280 addr_string = savestring(frame_exp, p - frame_exp);
283 tmp_cleanup = make_cleanup (free, addr_string);
284 args[numargs++] = parse_and_eval_address (addr_string);
285 do_cleanups (tmp_cleanup);
288 /* Skip spaces, move to possible next arg. */
289 while (*p == ' ') p++;
297 if (selected_frame == NULL)
298 error ("No selected frame.");
299 return selected_frame;
304 FRAME fid = find_relative_frame (get_current_frame (), &level);
308 /* find_relative_frame was successful */
311 /* If (s)he specifies the frame with an address, he deserves what
312 (s)he gets. Still, give the highest one that matches. */
314 for (fid = get_current_frame ();
315 fid && FRAME_FP (fid) != args[0];
316 fid = get_prev_frame (fid))
320 while ((tfid = get_prev_frame (fid)) &&
321 (FRAME_FP (tfid) == args[0]))
324 /* We couldn't identify the frame as an existing frame, but
325 perhaps we can create one with a single argument.
326 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
327 to complain if it doesn't like a single arg. */
331 #ifdef SETUP_ARBITRARY_FRAME
332 return SETUP_ARBITRARY_FRAME (numargs, args);
334 /* Usual case. Do it here rather than have everyone supply
335 a SETUP_ARBITRARY_FRAME that does this. */
337 return create_new_frame (args[0], 0);
338 error ("Too many args in frame specification");
345 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
346 that if it is unsure about the answer, it returns 0
347 instead of guessing (this happens on the VAX and i960, for example).
349 On most machines, we never have to guess about the args address,
350 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
351 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
352 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
355 /* Print verbosely the selected frame or the frame at address ADDR.
356 This means absolutely all information in the frame is printed. */
359 frame_info (addr_exp, from_tty)
364 struct frame_info *fi;
365 struct frame_saved_regs fsr;
366 struct symtab_and_line sal;
372 enum language funlang = language_unknown;
374 if (!target_has_stack)
375 error ("No inferior or core file.");
377 frame = parse_frame_specification (addr_exp);
379 error ("Invalid frame specified.");
381 fi = get_frame_info (frame);
382 sal = find_pc_line (fi->pc, fi->next_frame);
383 func = get_frame_function (frame);
384 s = find_pc_symtab(fi->pc);
387 funname = SYMBOL_NAME (func);
388 funlang = SYMBOL_LANGUAGE (func);
392 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
395 funname = SYMBOL_NAME (msymbol);
396 funlang = SYMBOL_LANGUAGE (msymbol);
399 calling_frame = get_prev_frame (frame);
401 if (!addr_exp && selected_frame_level >= 0) {
402 printf_filtered ("Stack level %d, frame at %s:\n",
403 selected_frame_level,
404 local_hex_string(FRAME_FP(frame)));
406 printf_filtered ("Stack frame at %s:\n",
407 local_hex_string(FRAME_FP(frame)));
409 printf_filtered (" %s = %s",
410 reg_names[PC_REGNUM],
411 local_hex_string(fi->pc));
416 printf_filtered (" in ");
417 fprintf_symbol_filtered (stdout, funname, funlang,
418 DMGL_ANSI | DMGL_PARAMS);
422 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
423 puts_filtered ("; ");
425 printf_filtered ("saved %s %s\n", reg_names[PC_REGNUM],
426 local_hex_string(FRAME_SAVED_PC (frame)));
430 #ifdef FRAMELESS_FUNCTION_INVOCATION
431 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
434 printf_filtered (" (FRAMELESS),");
438 printf_filtered (" called by frame at %s",
439 local_hex_string(FRAME_FP (calling_frame)));
440 if (fi->next_frame && calling_frame)
444 printf_filtered (" caller of frame at %s", local_hex_string(fi->next_frame));
445 if (fi->next_frame || calling_frame)
446 puts_filtered ("\n");
448 printf_filtered(" source language %s.\n", language_str(s->language));
450 #ifdef PRINT_EXTRA_FRAME_INFO
451 PRINT_EXTRA_FRAME_INFO (fi);
455 /* Address of the argument list for this frame, or 0. */
456 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
457 /* Number of args for this frame, or -1 if unknown. */
461 printf_filtered (" Arglist at unknown address.\n");
464 printf_filtered (" Arglist at %s,", local_hex_string(arg_list));
466 FRAME_NUM_ARGS (numargs, fi);
468 puts_filtered (" args: ");
469 else if (numargs == 0)
470 puts_filtered (" no args.");
471 else if (numargs == 1)
472 puts_filtered (" 1 arg: ");
474 printf_filtered (" %d args: ", numargs);
475 print_frame_args (func, fi, numargs, stdout);
476 puts_filtered ("\n");
480 /* Address of the local variables for this frame, or 0. */
481 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
484 printf_filtered (" Locals at unknown address,");
486 printf_filtered (" Locals at %s,", local_hex_string(arg_list));
489 #if defined (FRAME_FIND_SAVED_REGS)
490 get_frame_saved_regs (fi, &fsr);
491 /* The sp is special; what's returned isn't the save address, but
492 actually the value of the previous frame's sp. */
493 printf_filtered (" Previous frame's sp is %s\n",
494 local_hex_string(fsr.regs[SP_REGNUM]));
496 for (i = 0; i < NUM_REGS; i++)
497 if (fsr.regs[i] && i != SP_REGNUM)
500 puts_filtered (" Saved registers:\n ");
504 printf_filtered (" %s at %s", reg_names[i],
505 local_hex_string(fsr.regs[i]));
509 puts_filtered ("\n");
510 #endif /* Have FRAME_FIND_SAVED_REGS. */
514 /* Set a limit on the number of frames printed by default in a
517 static int backtrace_limit;
520 set_backtrace_limit_command (count_exp, from_tty)
524 int count = parse_and_eval_address (count_exp);
527 error ("Negative argument not meaningful as backtrace limit.");
529 backtrace_limit = count;
533 backtrace_limit_info (arg, from_tty)
538 error ("\"Info backtrace-limit\" takes no arguments.");
540 printf ("Backtrace limit: %d.\n", backtrace_limit);
544 /* Print briefly all stack frames or just the innermost COUNT frames. */
547 backtrace_command (count_exp, from_tty)
551 struct frame_info *fi;
553 register FRAME frame;
555 register FRAME trailing;
556 register int trailing_level;
558 if (!target_has_stack)
561 /* The following code must do two things. First, it must
562 set the variable TRAILING to the frame from which we should start
563 printing. Second, it must set the variable count to the number
564 of frames which we should print, or -1 if all of them. */
565 trailing = get_current_frame ();
569 count = parse_and_eval_address (count_exp);
577 while (current && count--)
580 current = get_prev_frame (current);
583 /* Will stop when CURRENT reaches the top of the stack. TRAILING
584 will be COUNT below it. */
588 trailing = get_prev_frame (trailing);
589 current = get_prev_frame (current);
601 struct partial_symtab *ps;
603 /* Read in symbols for all of the frames. Need to do this in
604 a separate pass so that "Reading in symbols for xxx" messages
605 don't screw up the appearance of the backtrace. Also
606 if people have strong opinions against reading symbols for
607 backtrace this may have to be an option. */
609 for (frame = trailing;
610 frame != NULL && i--;
611 frame = get_prev_frame (frame))
614 fi = get_frame_info (frame);
615 ps = find_pc_psymtab (fi->pc);
617 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
621 for (i = 0, frame = trailing;
623 i++, frame = get_prev_frame (frame))
626 fi = get_frame_info (frame);
627 print_frame_info (fi, trailing_level + i, 0, 1);
630 /* If we've stopped before the end, mention that. */
631 if (frame && from_tty)
632 printf_filtered ("(More stack frames follow...)\n");
635 /* Print the local variables of a block B active in FRAME.
636 Return 1 if any variables were printed; 0 otherwise. */
639 print_block_frame_locals (b, frame, stream)
641 register FRAME frame;
642 register FILE *stream;
646 register struct symbol *sym;
647 register int values_printed = 0;
649 nsyms = BLOCK_NSYMS (b);
651 for (i = 0; i < nsyms; i++)
653 sym = BLOCK_SYM (b, i);
654 if (SYMBOL_CLASS (sym) == LOC_LOCAL
655 || SYMBOL_CLASS (sym) == LOC_REGISTER
656 || SYMBOL_CLASS (sym) == LOC_STATIC)
659 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
660 fputs_filtered (" = ", stream);
661 print_variable_value (sym, frame, stream);
662 fprintf_filtered (stream, "\n");
665 return values_printed;
668 /* Same, but print labels. */
671 print_block_frame_labels (b, have_default, stream)
674 register FILE *stream;
678 register struct symbol *sym;
679 register int values_printed = 0;
681 nsyms = BLOCK_NSYMS (b);
683 for (i = 0; i < nsyms; i++)
685 sym = BLOCK_SYM (b, i);
686 if (STREQ (SYMBOL_NAME (sym), "default"))
692 if (SYMBOL_CLASS (sym) == LOC_LABEL)
694 struct symtab_and_line sal;
695 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
697 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
699 fprintf_filtered (stream, " %s",
700 local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
701 fprintf_filtered (stream, " in file %s, line %d\n",
702 sal.symtab->filename, sal.line);
705 return values_printed;
708 /* Print on STREAM all the local variables in frame FRAME,
709 including all the blocks active in that frame
712 Returns 1 if the job was done,
713 or 0 if nothing was printed because we have no info
714 on the function running in FRAME. */
717 print_frame_local_vars (frame, stream)
718 register FRAME frame;
719 register FILE *stream;
721 register struct block *block = get_frame_block (frame);
722 register int values_printed = 0;
726 fprintf_filtered (stream, "No symbol table info available.\n");
732 if (print_block_frame_locals (block, frame, stream))
734 /* After handling the function's top-level block, stop.
735 Don't continue to its superblock, the block of
737 if (BLOCK_FUNCTION (block))
739 block = BLOCK_SUPERBLOCK (block);
744 fprintf_filtered (stream, "No locals.\n");
748 /* Same, but print labels. */
751 print_frame_label_vars (frame, this_level_only, stream)
752 register FRAME frame;
754 register FILE *stream;
756 register struct blockvector *bl;
757 register struct block *block = get_frame_block (frame);
758 register int values_printed = 0;
759 int index, have_default = 0;
760 char *blocks_printed;
761 struct frame_info *fi = get_frame_info (frame);
762 CORE_ADDR pc = fi->pc;
766 fprintf_filtered (stream, "No symbol table info available.\n");
770 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
771 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
772 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
776 CORE_ADDR end = BLOCK_END (block) - 4;
779 if (bl != blockvector_for_pc (end, &index))
780 error ("blockvector blotch");
781 if (BLOCKVECTOR_BLOCK (bl, index) != block)
782 error ("blockvector botch");
783 last_index = BLOCKVECTOR_NBLOCKS (bl);
786 /* Don't print out blocks that have gone by. */
787 while (index < last_index
788 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
791 while (index < last_index
792 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
794 if (blocks_printed[index] == 0)
796 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
798 blocks_printed[index] = 1;
804 if (values_printed && this_level_only)
807 /* After handling the function's top-level block, stop.
808 Don't continue to its superblock, the block of
810 if (BLOCK_FUNCTION (block))
812 block = BLOCK_SUPERBLOCK (block);
815 if (!values_printed && !this_level_only)
817 fprintf_filtered (stream, "No catches.\n");
823 locals_info (args, from_tty)
828 error ("No frame selected.");
829 print_frame_local_vars (selected_frame, stdout);
833 catch_info (ignore, from_tty)
838 error ("No frame selected.");
839 print_frame_label_vars (selected_frame, 0, stdout);
843 print_frame_arg_vars (frame, stream)
844 register FRAME frame;
845 register FILE *stream;
847 struct symbol *func = get_frame_function (frame);
848 register struct block *b;
851 register struct symbol *sym, *sym2;
852 register int values_printed = 0;
856 fprintf_filtered (stream, "No symbol table info available.\n");
860 b = SYMBOL_BLOCK_VALUE (func);
861 nsyms = BLOCK_NSYMS (b);
863 for (i = 0; i < nsyms; i++)
865 sym = BLOCK_SYM (b, i);
866 if (SYMBOL_CLASS (sym) == LOC_ARG
867 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
868 || SYMBOL_CLASS (sym) == LOC_REF_ARG
869 || SYMBOL_CLASS (sym) == LOC_REGPARM)
872 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
873 fputs_filtered (" = ", stream);
874 /* We have to look up the symbol because arguments often have
875 two entries (one a parameter, one a register) and the one
876 we want is the register, which lookup_symbol will find for
878 sym2 = lookup_symbol (SYMBOL_NAME (sym),
879 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
880 print_variable_value (sym2, frame, stream);
881 fprintf_filtered (stream, "\n");
887 fprintf_filtered (stream, "No arguments.\n");
892 args_info (ignore, from_tty)
897 error ("No frame selected.");
898 print_frame_arg_vars (selected_frame, stdout);
901 /* Select frame FRAME, and note that its stack level is LEVEL.
902 LEVEL may be -1 if an actual level number is not known. */
905 select_frame (frame, level)
909 register struct symtab *s;
911 selected_frame = frame;
912 selected_frame_level = level;
914 /* Ensure that symbols for this frame are read in. Also, determine the
915 source language of this frame, and switch to it if desired. */
918 s = find_pc_symtab (get_frame_info (frame)->pc);
920 && s->language != current_language->la_language
921 && s->language != language_unknown
922 && language_mode == language_mode_auto) {
923 set_language(s->language);
928 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
929 If there is no selected frame, *FRAMEP is set to NULL. */
932 record_selected_frame (frameaddrp, levelp)
933 FRAME_ADDR *frameaddrp;
936 *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
937 *levelp = selected_frame_level;
940 /* Return the symbol-block in which the selected frame is executing.
941 Can return zero under various legitimate circumstances. */
944 get_selected_block ()
946 if (!target_has_stack)
950 return get_current_block ();
951 return get_frame_block (selected_frame);
954 /* Find a frame a certain number of levels away from FRAME.
955 LEVEL_OFFSET_PTR points to an int containing the number of levels.
956 Positive means go to earlier frames (up); negative, the reverse.
957 The int that contains the number of levels is counted toward
958 zero as the frames for those levels are found.
959 If the top or bottom frame is reached, that frame is returned,
960 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
961 how much farther the original request asked to go. */
964 find_relative_frame (frame, level_offset_ptr)
965 register FRAME frame;
966 register int* level_offset_ptr;
969 register FRAME frame1;
971 /* Going up is simple: just do get_prev_frame enough times
972 or until initial frame is reached. */
973 while (*level_offset_ptr > 0)
975 prev = get_prev_frame (frame);
978 (*level_offset_ptr)--;
981 /* Going down is just as simple. */
982 if (*level_offset_ptr < 0)
984 while (*level_offset_ptr < 0) {
985 frame1 = get_next_frame (frame);
989 (*level_offset_ptr)++;
995 /* The "select_frame" command. With no arg, NOP.
996 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
997 valid level. Otherwise, treat level_exp as an address expression
998 and select it. See parse_frame_specification for more info on proper
999 frame expressions. */
1003 select_frame_command (level_exp, from_tty)
1007 register FRAME frame, frame1;
1008 unsigned int level = 0;
1010 if (!target_has_stack)
1011 error ("No stack.");
1013 frame = parse_frame_specification (level_exp);
1015 /* Try to figure out what level this frame is. But if there is
1016 no current stack, don't error out -- let the user set one. */
1018 if (get_current_frame()) {
1019 for (frame1 = get_prev_frame (0);
1020 frame1 && frame1 != frame;
1021 frame1 = get_prev_frame (frame1))
1028 select_frame (frame, level);
1031 /* The "frame" command. With no arg, print selected frame briefly.
1032 With arg, behaves like select_frame and then prints the selected
1036 frame_command (level_exp, from_tty)
1040 select_frame_command (level_exp, from_tty);
1041 print_stack_frame (selected_frame, selected_frame_level, 1);
1044 /* Select the frame up one or COUNT stack levels
1045 from the previously selected frame, and print it briefly. */
1049 up_silently_command (count_exp, from_tty)
1053 register FRAME frame;
1054 int count = 1, count1;
1056 count = parse_and_eval_address (count_exp);
1059 if (target_has_stack == 0 || selected_frame == 0)
1060 error ("No stack.");
1062 frame = find_relative_frame (selected_frame, &count1);
1063 if (count1 != 0 && count_exp == 0)
1064 error ("Initial frame selected; you cannot go up.");
1065 select_frame (frame, selected_frame_level + count - count1);
1069 up_command (count_exp, from_tty)
1073 up_silently_command (count_exp, from_tty);
1074 print_stack_frame (selected_frame, selected_frame_level, 1);
1077 /* Select the frame down one or COUNT stack levels
1078 from the previously selected frame, and print it briefly. */
1082 down_silently_command (count_exp, from_tty)
1086 register FRAME frame;
1087 int count = -1, count1;
1089 count = - parse_and_eval_address (count_exp);
1092 if (target_has_stack == 0 || selected_frame == 0)
1093 error ("No stack.");
1095 frame = find_relative_frame (selected_frame, &count1);
1096 if (count1 != 0 && count_exp == 0)
1097 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1098 select_frame (frame, selected_frame_level + count - count1);
1103 down_command (count_exp, from_tty)
1107 down_silently_command (count_exp, from_tty);
1108 print_stack_frame (selected_frame, selected_frame_level, 1);
1112 return_command (retval_exp, from_tty)
1116 struct symbol *thisfun;
1117 FRAME_ADDR selected_frame_addr;
1118 CORE_ADDR selected_frame_pc;
1122 if (selected_frame == NULL)
1123 error ("No selected frame.");
1124 thisfun = get_frame_function (selected_frame);
1125 selected_frame_addr = FRAME_FP (selected_frame);
1126 selected_frame_pc = (get_frame_info (selected_frame))->pc;
1128 /* Compute the return value (if any -- possibly getting errors here).
1129 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1130 it might live in the stack frame we're about to pop. */
1134 return_value = parse_and_eval (retval_exp);
1135 VALUE_CONTENTS (return_value);
1138 /* If interactive, require confirmation. */
1144 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
1146 error ("Not confirmed.");
1151 if (!query ("Make selected stack frame return now? "))
1152 error ("Not confirmed.");
1155 /* Do the real work. Pop until the specified frame is current. We
1156 use this method because the selected_frame is not valid after
1157 a POP_FRAME. The pc comparison makes this work even if the
1158 selected frame shares its fp with another frame. */
1160 while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
1161 || selected_frame_pc != (get_frame_info (frame))->pc )
1164 /* Then pop that frame. */
1168 /* Compute the return value (if any) and store in the place
1169 for return values. */
1172 set_return_value (return_value);
1174 /* If interactive, print the frame that is now current. */
1177 frame_command ("0", 1);
1180 /* Gets the language of the current frame. */
1182 get_frame_language()
1184 register struct symtab *s;
1186 enum language flang; /* The language of the current frame */
1188 fr = get_frame_info(selected_frame);
1191 s = find_pc_symtab(fr->pc);
1193 flang = s->language;
1195 flang = language_unknown;
1198 flang = language_unknown;
1204 _initialize_stack ()
1207 backtrace_limit = 30;
1210 add_com ("return", class_stack, return_command,
1211 "Make selected stack frame return to its caller.\n\
1212 Control remains in the debugger, but when you continue\n\
1213 execution will resume in the frame above the one now selected.\n\
1214 If an argument is given, it is an expression for the value to return.");
1216 add_com ("up", class_stack, up_command,
1217 "Select and print stack frame that called this one.\n\
1218 An argument says how many frames up to go.");
1219 add_com ("up-silently", class_support, up_silently_command,
1220 "Same as the `up' command, but does not print anything.\n\
1221 This is useful in command scripts.");
1223 add_com ("down", class_stack, down_command,
1224 "Select and print stack frame called by this one.\n\
1225 An argument says how many frames down to go.");
1226 add_com_alias ("do", "down", class_stack, 1);
1227 add_com_alias ("dow", "down", class_stack, 1);
1228 add_com ("down-silently", class_support, down_silently_command,
1229 "Same as the `down' command, but does not print anything.\n\
1230 This is useful in command scripts.");
1232 add_com ("frame", class_stack, frame_command,
1233 "Select and print a stack frame.\n\
1234 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1235 An argument specifies the frame to select.\n\
1236 It can be a stack frame number or the address of the frame.\n\
1237 With argument, nothing is printed if input is coming from\n\
1238 a command file or a user-defined command.");
1240 add_com_alias ("f", "frame", class_stack, 1);
1242 add_com ("select-frame", class_stack, select_frame_command,
1243 "Select a stack frame without printing anything.\n\
1244 An argument specifies the frame to select.\n\
1245 It can be a stack frame number or the address of the frame.\n");
1247 add_com ("backtrace", class_stack, backtrace_command,
1248 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1249 With a negative argument, print outermost -COUNT frames.");
1250 add_com_alias ("bt", "backtrace", class_stack, 0);
1251 add_com_alias ("where", "backtrace", class_alias, 0);
1252 add_info ("stack", backtrace_command,
1253 "Backtrace of the stack, or innermost COUNT frames.");
1254 add_info_alias ("s", "stack", 1);
1255 add_info ("frame", frame_info,
1256 "All about selected stack frame, or frame at ADDR.");
1257 add_info_alias ("f", "frame", 1);
1258 add_info ("locals", locals_info,
1259 "Local variables of current stack frame.");
1260 add_info ("args", args_info,
1261 "Argument variables of current stack frame.");
1262 add_info ("catch", catch_info,
1263 "Exceptions that can be caught in the current stack frame.");
1266 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
1267 "Specify maximum number of frames for \"backtrace\" to print by default.",
1269 add_info ("backtrace-limit", backtrace_limit_info,
1270 "The maximum number of frames for \"backtrace\" to print by default.");