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);
133 struct print_args_args {
135 struct frame_info *fi;
138 static int print_args_stub PARAMS ((char *));
140 /* Pass the args the way catch_errors wants them. */
142 print_args_stub (args)
146 struct print_args_args *p = (struct print_args_args *)args;
147 FRAME_NUM_ARGS (numargs, (p->fi));
148 print_frame_args (p->func, p->fi, numargs, stdout);
153 print_frame_info (fi, level, source, args)
154 struct frame_info *fi;
159 struct symtab_and_line sal;
161 register char *funname = 0;
162 enum language funlang = language_unknown;
165 if (PC_IN_CALL_DUMMY (fi->pc, read_sp (), fi->frame))
167 /* Do this regardless of SOURCE because we don't have any source
168 to list for this frame. */
170 printf_filtered ("#%-2d ", level);
171 printf_filtered ("<function called from gdb>\n");
174 if (fi->signal_handler_caller)
176 /* Do this regardless of SOURCE because we don't have any source
177 to list for this frame. */
179 printf_filtered ("#%-2d ", level);
180 printf_filtered ("<signal handler called>\n");
184 sal = find_pc_line (fi->pc, fi->next != NULL);
185 func = find_pc_function (fi->pc);
188 /* In certain pathological cases, the symtabs give the wrong
189 function (when we are in the first function in a file which
190 is compiled without debugging symbols, the previous function
191 is compiled with debugging symbols, and the "foo.o" symbol
192 that is supposed to tell us where the file with debugging symbols
193 ends has been truncated by ar because it is longer than 15
196 So look in the minimal symbol tables as well, and if it comes
197 up with a larger address for the function use that instead.
198 I don't think this can ever cause any problems; there shouldn't
199 be any minimal symbols in the middle of a function.
200 FIXME: (Not necessarily true. What about text labels) */
202 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
204 && (SYMBOL_VALUE_ADDRESS (msymbol)
205 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
207 /* In this case we have no way of knowing the source file
208 and line number, so don't print them. */
210 /* We also don't know anything about the function besides
211 its address and name. */
213 funname = SYMBOL_NAME (msymbol);
214 funlang = SYMBOL_LANGUAGE (msymbol);
218 funname = SYMBOL_NAME (func);
219 funlang = SYMBOL_LANGUAGE (func);
224 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
227 funname = SYMBOL_NAME (msymbol);
228 funlang = SYMBOL_LANGUAGE (msymbol);
232 if (source >= 0 || !sal.symtab)
235 printf_filtered ("#%-2d ", level);
237 if (fi->pc != sal.pc || !sal.symtab)
238 printf_filtered ("%s in ", local_hex_string(fi->pc));
239 fprintf_symbol_filtered (stdout, funname ? funname : "??", funlang,
242 fputs_filtered (" (", stdout);
245 struct print_args_args args;
248 catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR);
250 printf_filtered (")");
251 if (sal.symtab && sal.symtab->filename)
254 printf_filtered (" at %s:%d", sal.symtab->filename, sal.line);
257 #ifdef PC_LOAD_SEGMENT
258 /* If we couldn't print out function name but if can figure out what
259 load segment this pc value is from, at least print out some info
260 about its load segment. */
263 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
266 printf_filtered ("\n");
269 if ((source != 0) && sal.symtab)
272 int mid_statement = source < 0 && fi->pc != sal.pc;
273 if (frame_file_full_name)
274 done = identify_source_line (sal.symtab, sal.line, mid_statement,
278 if (addressprint && mid_statement)
279 printf_filtered ("%s\t", local_hex_string(fi->pc));
280 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
282 current_source_line = max (sal.line - lines_to_list/2, 1);
285 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
291 * Read a frame specification in whatever the appropriate format is.
292 * Call error() if the specification is in any way invalid (i.e.
293 * this function never returns NULL).
296 parse_frame_specification (frame_exp)
300 int arg1, arg2, arg3;
306 char *addr_string, *p;
307 struct cleanup *tmp_cleanup;
309 while (*frame_exp == ' ') frame_exp++;
313 if (numargs > MAXARGS)
314 error ("Too many args in frame specification");
315 /* Parse an argument. */
316 for (p = frame_exp; *p && *p != ' '; p++)
318 addr_string = savestring(frame_exp, p - frame_exp);
321 tmp_cleanup = make_cleanup (free, addr_string);
322 args[numargs++] = parse_and_eval_address (addr_string);
323 do_cleanups (tmp_cleanup);
326 /* Skip spaces, move to possible next arg. */
327 while (*p == ' ') p++;
335 if (selected_frame == NULL)
336 error ("No selected frame.");
337 return selected_frame;
342 FRAME fid = find_relative_frame (get_current_frame (), &level);
346 /* find_relative_frame was successful */
349 /* If (s)he specifies the frame with an address, he deserves what
350 (s)he gets. Still, give the highest one that matches. */
352 for (fid = get_current_frame ();
353 fid && FRAME_FP (fid) != args[0];
354 fid = get_prev_frame (fid))
358 while ((tfid = get_prev_frame (fid)) &&
359 (FRAME_FP (tfid) == args[0]))
362 /* We couldn't identify the frame as an existing frame, but
363 perhaps we can create one with a single argument.
364 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
365 to complain if it doesn't like a single arg. */
369 #ifdef SETUP_ARBITRARY_FRAME
370 return SETUP_ARBITRARY_FRAME (numargs, args);
372 /* Usual case. Do it here rather than have everyone supply
373 a SETUP_ARBITRARY_FRAME that does this. */
375 return create_new_frame (args[0], 0);
376 error ("Too many args in frame specification");
383 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
384 that if it is unsure about the answer, it returns 0
385 instead of guessing (this happens on the VAX and i960, for example).
387 On most machines, we never have to guess about the args address,
388 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
389 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
390 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
393 /* Print verbosely the selected frame or the frame at address ADDR.
394 This means absolutely all information in the frame is printed. */
397 frame_info (addr_exp, from_tty)
402 struct frame_info *fi;
403 struct frame_saved_regs fsr;
404 struct symtab_and_line sal;
410 enum language funlang = language_unknown;
412 if (!target_has_stack)
415 frame = parse_frame_specification (addr_exp);
417 error ("Invalid frame specified.");
419 fi = get_frame_info (frame);
420 sal = find_pc_line (fi->pc, fi->next != NULL);
421 func = get_frame_function (frame);
422 s = find_pc_symtab(fi->pc);
425 funname = SYMBOL_NAME (func);
426 funlang = SYMBOL_LANGUAGE (func);
430 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
433 funname = SYMBOL_NAME (msymbol);
434 funlang = SYMBOL_LANGUAGE (msymbol);
437 calling_frame = get_prev_frame (frame);
439 if (!addr_exp && selected_frame_level >= 0) {
440 printf_filtered ("Stack level %d, frame at %s:\n",
441 selected_frame_level,
442 local_hex_string(FRAME_FP(frame)));
444 printf_filtered ("Stack frame at %s:\n",
445 local_hex_string(FRAME_FP(frame)));
447 printf_filtered (" %s = %s",
448 reg_names[PC_REGNUM],
449 local_hex_string(fi->pc));
454 printf_filtered (" in ");
455 fprintf_symbol_filtered (stdout, funname, funlang,
456 DMGL_ANSI | DMGL_PARAMS);
460 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
461 puts_filtered ("; ");
463 printf_filtered ("saved %s %s\n", reg_names[PC_REGNUM],
464 local_hex_string(FRAME_SAVED_PC (frame)));
468 #ifdef FRAMELESS_FUNCTION_INVOCATION
469 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
472 printf_filtered (" (FRAMELESS),");
476 printf_filtered (" called by frame at %s",
477 local_hex_string(FRAME_FP (calling_frame)));
478 if (fi->next && calling_frame)
482 printf_filtered (" caller of frame at %s",
483 local_hex_string (fi->next->frame));
484 if (fi->next || calling_frame)
485 puts_filtered ("\n");
487 printf_filtered(" source language %s.\n", language_str(s->language));
489 #ifdef PRINT_EXTRA_FRAME_INFO
490 PRINT_EXTRA_FRAME_INFO (fi);
494 /* Address of the argument list for this frame, or 0. */
495 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
496 /* Number of args for this frame, or -1 if unknown. */
500 printf_filtered (" Arglist at unknown address.\n");
503 printf_filtered (" Arglist at %s,", local_hex_string(arg_list));
505 FRAME_NUM_ARGS (numargs, fi);
507 puts_filtered (" args: ");
508 else if (numargs == 0)
509 puts_filtered (" no args.");
510 else if (numargs == 1)
511 puts_filtered (" 1 arg: ");
513 printf_filtered (" %d args: ", numargs);
514 print_frame_args (func, fi, numargs, stdout);
515 puts_filtered ("\n");
519 /* Address of the local variables for this frame, or 0. */
520 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
523 printf_filtered (" Locals at unknown address,");
525 printf_filtered (" Locals at %s,", local_hex_string(arg_list));
528 #if defined (FRAME_FIND_SAVED_REGS)
529 get_frame_saved_regs (fi, &fsr);
530 /* The sp is special; what's returned isn't the save address, but
531 actually the value of the previous frame's sp. */
532 printf_filtered (" Previous frame's sp is %s\n",
533 local_hex_string(fsr.regs[SP_REGNUM]));
535 for (i = 0; i < NUM_REGS; i++)
536 if (fsr.regs[i] && i != SP_REGNUM)
539 puts_filtered (" Saved registers:\n ");
543 printf_filtered (" %s at %s", reg_names[i],
544 local_hex_string(fsr.regs[i]));
548 puts_filtered ("\n");
549 #endif /* Have FRAME_FIND_SAVED_REGS. */
553 /* Set a limit on the number of frames printed by default in a
556 static int backtrace_limit;
559 set_backtrace_limit_command (count_exp, from_tty)
563 int count = parse_and_eval_address (count_exp);
566 error ("Negative argument not meaningful as backtrace limit.");
568 backtrace_limit = count;
572 backtrace_limit_info (arg, from_tty)
577 error ("\"Info backtrace-limit\" takes no arguments.");
579 printf ("Backtrace limit: %d.\n", backtrace_limit);
583 /* Print briefly all stack frames or just the innermost COUNT frames. */
586 backtrace_command (count_exp, from_tty)
590 struct frame_info *fi;
592 register FRAME frame;
594 register FRAME trailing;
595 register int trailing_level;
597 if (!target_has_stack)
600 /* The following code must do two things. First, it must
601 set the variable TRAILING to the frame from which we should start
602 printing. Second, it must set the variable count to the number
603 of frames which we should print, or -1 if all of them. */
604 trailing = get_current_frame ();
608 count = parse_and_eval_address (count_exp);
616 while (current && count--)
619 current = get_prev_frame (current);
622 /* Will stop when CURRENT reaches the top of the stack. TRAILING
623 will be COUNT below it. */
627 trailing = get_prev_frame (trailing);
628 current = get_prev_frame (current);
640 struct partial_symtab *ps;
642 /* Read in symbols for all of the frames. Need to do this in
643 a separate pass so that "Reading in symbols for xxx" messages
644 don't screw up the appearance of the backtrace. Also
645 if people have strong opinions against reading symbols for
646 backtrace this may have to be an option. */
648 for (frame = trailing;
649 frame != NULL && i--;
650 frame = get_prev_frame (frame))
653 fi = get_frame_info (frame);
654 ps = find_pc_psymtab (fi->pc);
656 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
660 for (i = 0, frame = trailing;
662 i++, frame = get_prev_frame (frame))
665 fi = get_frame_info (frame);
666 print_frame_info (fi, trailing_level + i, 0, 1);
669 /* If we've stopped before the end, mention that. */
670 if (frame && from_tty)
671 printf_filtered ("(More stack frames follow...)\n");
674 /* Print the local variables of a block B active in FRAME.
675 Return 1 if any variables were printed; 0 otherwise. */
678 print_block_frame_locals (b, frame, stream)
680 register FRAME frame;
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 (SYMBOL_CLASS (sym) == LOC_LOCAL
694 || SYMBOL_CLASS (sym) == LOC_REGISTER
695 || SYMBOL_CLASS (sym) == LOC_STATIC)
698 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
699 fputs_filtered (" = ", stream);
700 print_variable_value (sym, frame, stream);
701 fprintf_filtered (stream, "\n");
704 return values_printed;
707 /* Same, but print labels. */
710 print_block_frame_labels (b, have_default, stream)
713 register FILE *stream;
717 register struct symbol *sym;
718 register int values_printed = 0;
720 nsyms = BLOCK_NSYMS (b);
722 for (i = 0; i < nsyms; i++)
724 sym = BLOCK_SYM (b, i);
725 if (STREQ (SYMBOL_NAME (sym), "default"))
731 if (SYMBOL_CLASS (sym) == LOC_LABEL)
733 struct symtab_and_line sal;
734 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
736 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
738 fprintf_filtered (stream, " %s",
739 local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
740 fprintf_filtered (stream, " in file %s, line %d\n",
741 sal.symtab->filename, sal.line);
744 return values_printed;
747 /* Print on STREAM all the local variables in frame FRAME,
748 including all the blocks active in that frame
751 Returns 1 if the job was done,
752 or 0 if nothing was printed because we have no info
753 on the function running in FRAME. */
756 print_frame_local_vars (frame, stream)
757 register FRAME frame;
758 register FILE *stream;
760 register struct block *block = get_frame_block (frame);
761 register int values_printed = 0;
765 fprintf_filtered (stream, "No symbol table info available.\n");
771 if (print_block_frame_locals (block, frame, stream))
773 /* After handling the function's top-level block, stop.
774 Don't continue to its superblock, the block of
776 if (BLOCK_FUNCTION (block))
778 block = BLOCK_SUPERBLOCK (block);
783 fprintf_filtered (stream, "No locals.\n");
787 /* Same, but print labels. */
790 print_frame_label_vars (frame, this_level_only, stream)
791 register FRAME frame;
793 register FILE *stream;
795 register struct blockvector *bl;
796 register struct block *block = get_frame_block (frame);
797 register int values_printed = 0;
798 int index, have_default = 0;
799 char *blocks_printed;
800 struct frame_info *fi = get_frame_info (frame);
801 CORE_ADDR pc = fi->pc;
805 fprintf_filtered (stream, "No symbol table info available.\n");
809 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
810 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
811 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
815 CORE_ADDR end = BLOCK_END (block) - 4;
818 if (bl != blockvector_for_pc (end, &index))
819 error ("blockvector blotch");
820 if (BLOCKVECTOR_BLOCK (bl, index) != block)
821 error ("blockvector botch");
822 last_index = BLOCKVECTOR_NBLOCKS (bl);
825 /* Don't print out blocks that have gone by. */
826 while (index < last_index
827 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
830 while (index < last_index
831 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
833 if (blocks_printed[index] == 0)
835 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
837 blocks_printed[index] = 1;
843 if (values_printed && this_level_only)
846 /* After handling the function's top-level block, stop.
847 Don't continue to its superblock, the block of
849 if (BLOCK_FUNCTION (block))
851 block = BLOCK_SUPERBLOCK (block);
854 if (!values_printed && !this_level_only)
856 fprintf_filtered (stream, "No catches.\n");
862 locals_info (args, from_tty)
867 error ("No frame selected.");
868 print_frame_local_vars (selected_frame, stdout);
872 catch_info (ignore, from_tty)
877 error ("No frame selected.");
878 print_frame_label_vars (selected_frame, 0, stdout);
882 print_frame_arg_vars (frame, stream)
883 register FRAME frame;
884 register FILE *stream;
886 struct symbol *func = get_frame_function (frame);
887 register struct block *b;
890 register struct symbol *sym, *sym2;
891 register int values_printed = 0;
895 fprintf_filtered (stream, "No symbol table info available.\n");
899 b = SYMBOL_BLOCK_VALUE (func);
900 nsyms = BLOCK_NSYMS (b);
902 for (i = 0; i < nsyms; i++)
904 sym = BLOCK_SYM (b, i);
905 if (SYMBOL_CLASS (sym) == LOC_ARG
906 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
907 || SYMBOL_CLASS (sym) == LOC_REF_ARG
908 || SYMBOL_CLASS (sym) == LOC_REGPARM
909 || SYMBOL_CLASS (sym) == LOC_REGPARM_ADDR)
912 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
913 fputs_filtered (" = ", stream);
915 /* We have to look up the symbol because arguments can have
916 two entries (one a parameter, one a local) and the one we
917 want is the local, which lookup_symbol will find for us.
918 This includes gcc1 (not gcc2) on the sparc when passing a
919 small structure and gcc2 when the argument type is float
920 and it is passed as a double and converted to float by
921 the prologue (in the latter case the type of the LOC_ARG
922 symbol is double and the type of the LOC_LOCAL symbol is
923 float). There are also LOC_ARG/LOC_REGISTER pairs which
924 are not combined in symbol-reading. */
926 sym2 = lookup_symbol (SYMBOL_NAME (sym),
927 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
928 print_variable_value (sym2, frame, stream);
929 fprintf_filtered (stream, "\n");
935 fprintf_filtered (stream, "No arguments.\n");
940 args_info (ignore, from_tty)
945 error ("No frame selected.");
946 print_frame_arg_vars (selected_frame, stdout);
949 /* Select frame FRAME, and note that its stack level is LEVEL.
950 LEVEL may be -1 if an actual level number is not known. */
953 select_frame (frame, level)
957 register struct symtab *s;
959 selected_frame = frame;
960 selected_frame_level = level;
962 /* Ensure that symbols for this frame are read in. Also, determine the
963 source language of this frame, and switch to it if desired. */
966 s = find_pc_symtab (get_frame_info (frame)->pc);
968 && s->language != current_language->la_language
969 && s->language != language_unknown
970 && language_mode == language_mode_auto) {
971 set_language(s->language);
976 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
977 If there is no selected frame, *FRAMEP is set to NULL. */
980 record_selected_frame (frameaddrp, levelp)
981 FRAME_ADDR *frameaddrp;
984 *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
985 *levelp = selected_frame_level;
988 /* Return the symbol-block in which the selected frame is executing.
989 Can return zero under various legitimate circumstances. */
992 get_selected_block ()
994 if (!target_has_stack)
998 return get_current_block ();
999 return get_frame_block (selected_frame);
1002 /* Find a frame a certain number of levels away from FRAME.
1003 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1004 Positive means go to earlier frames (up); negative, the reverse.
1005 The int that contains the number of levels is counted toward
1006 zero as the frames for those levels are found.
1007 If the top or bottom frame is reached, that frame is returned,
1008 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1009 how much farther the original request asked to go. */
1012 find_relative_frame (frame, level_offset_ptr)
1013 register FRAME frame;
1014 register int* level_offset_ptr;
1016 register FRAME prev;
1017 register FRAME frame1;
1019 /* Going up is simple: just do get_prev_frame enough times
1020 or until initial frame is reached. */
1021 while (*level_offset_ptr > 0)
1023 prev = get_prev_frame (frame);
1026 (*level_offset_ptr)--;
1029 /* Going down is just as simple. */
1030 if (*level_offset_ptr < 0)
1032 while (*level_offset_ptr < 0) {
1033 frame1 = get_next_frame (frame);
1037 (*level_offset_ptr)++;
1043 /* The "select_frame" command. With no arg, NOP.
1044 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1045 valid level. Otherwise, treat level_exp as an address expression
1046 and select it. See parse_frame_specification for more info on proper
1047 frame expressions. */
1051 select_frame_command (level_exp, from_tty)
1055 register FRAME frame, frame1;
1056 unsigned int level = 0;
1058 if (!target_has_stack)
1059 error ("No stack.");
1061 frame = parse_frame_specification (level_exp);
1063 /* Try to figure out what level this frame is. But if there is
1064 no current stack, don't error out -- let the user set one. */
1066 if (get_current_frame()) {
1067 for (frame1 = get_prev_frame (0);
1068 frame1 && frame1 != frame;
1069 frame1 = get_prev_frame (frame1))
1076 select_frame (frame, level);
1079 /* The "frame" command. With no arg, print selected frame briefly.
1080 With arg, behaves like select_frame and then prints the selected
1084 frame_command (level_exp, from_tty)
1088 select_frame_command (level_exp, from_tty);
1089 print_stack_frame (selected_frame, selected_frame_level, 1);
1092 /* Select the frame up one or COUNT stack levels
1093 from the previously selected frame, and print it briefly. */
1097 up_silently_command (count_exp, from_tty)
1101 register FRAME frame;
1102 int count = 1, count1;
1104 count = parse_and_eval_address (count_exp);
1107 if (target_has_stack == 0 || selected_frame == 0)
1108 error ("No stack.");
1110 frame = find_relative_frame (selected_frame, &count1);
1111 if (count1 != 0 && count_exp == 0)
1112 error ("Initial frame selected; you cannot go up.");
1113 select_frame (frame, selected_frame_level + count - count1);
1117 up_command (count_exp, from_tty)
1121 up_silently_command (count_exp, from_tty);
1122 print_stack_frame (selected_frame, selected_frame_level, 1);
1125 /* Select the frame down one or COUNT stack levels
1126 from the previously selected frame, and print it briefly. */
1130 down_silently_command (count_exp, from_tty)
1134 register FRAME frame;
1135 int count = -1, count1;
1137 count = - parse_and_eval_address (count_exp);
1140 if (target_has_stack == 0 || selected_frame == 0)
1141 error ("No stack.");
1143 frame = find_relative_frame (selected_frame, &count1);
1144 if (count1 != 0 && count_exp == 0)
1145 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1146 select_frame (frame, selected_frame_level + count - count1);
1151 down_command (count_exp, from_tty)
1155 down_silently_command (count_exp, from_tty);
1156 print_stack_frame (selected_frame, selected_frame_level, 1);
1160 return_command (retval_exp, from_tty)
1164 struct symbol *thisfun;
1165 FRAME_ADDR selected_frame_addr;
1166 CORE_ADDR selected_frame_pc;
1170 if (selected_frame == NULL)
1171 error ("No selected frame.");
1172 thisfun = get_frame_function (selected_frame);
1173 selected_frame_addr = FRAME_FP (selected_frame);
1174 selected_frame_pc = (get_frame_info (selected_frame))->pc;
1176 /* Compute the return value (if any -- possibly getting errors here).
1177 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1178 it might live in the stack frame we're about to pop. */
1182 return_value = parse_and_eval (retval_exp);
1183 VALUE_CONTENTS (return_value);
1186 /* If interactive, require confirmation. */
1192 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
1194 error ("Not confirmed.");
1199 if (!query ("Make selected stack frame return now? "))
1200 error ("Not confirmed.");
1203 /* Do the real work. Pop until the specified frame is current. We
1204 use this method because the selected_frame is not valid after
1205 a POP_FRAME. The pc comparison makes this work even if the
1206 selected frame shares its fp with another frame. */
1208 while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
1209 || selected_frame_pc != (get_frame_info (frame))->pc )
1212 /* Then pop that frame. */
1216 /* Compute the return value (if any) and store in the place
1217 for return values. */
1220 set_return_value (return_value);
1222 /* If interactive, print the frame that is now current. */
1225 frame_command ("0", 1);
1228 /* Gets the language of the current frame. */
1230 get_frame_language()
1232 register struct symtab *s;
1234 enum language flang; /* The language of the current frame */
1236 fr = get_frame_info(selected_frame);
1239 s = find_pc_symtab(fr->pc);
1241 flang = s->language;
1243 flang = language_unknown;
1246 flang = language_unknown;
1252 _initialize_stack ()
1255 backtrace_limit = 30;
1258 add_com ("return", class_stack, return_command,
1259 "Make selected stack frame return to its caller.\n\
1260 Control remains in the debugger, but when you continue\n\
1261 execution will resume in the frame above the one now selected.\n\
1262 If an argument is given, it is an expression for the value to return.");
1264 add_com ("up", class_stack, up_command,
1265 "Select and print stack frame that called this one.\n\
1266 An argument says how many frames up to go.");
1267 add_com ("up-silently", class_support, up_silently_command,
1268 "Same as the `up' command, but does not print anything.\n\
1269 This is useful in command scripts.");
1271 add_com ("down", class_stack, down_command,
1272 "Select and print stack frame called by this one.\n\
1273 An argument says how many frames down to go.");
1274 add_com_alias ("do", "down", class_stack, 1);
1275 add_com_alias ("dow", "down", class_stack, 1);
1276 add_com ("down-silently", class_support, down_silently_command,
1277 "Same as the `down' command, but does not print anything.\n\
1278 This is useful in command scripts.");
1280 add_com ("frame", class_stack, frame_command,
1281 "Select and print a stack frame.\n\
1282 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1283 An argument specifies the frame to select.\n\
1284 It can be a stack frame number or the address of the frame.\n\
1285 With argument, nothing is printed if input is coming from\n\
1286 a command file or a user-defined command.");
1288 add_com_alias ("f", "frame", class_stack, 1);
1290 add_com ("select-frame", class_stack, select_frame_command,
1291 "Select a stack frame without printing anything.\n\
1292 An argument specifies the frame to select.\n\
1293 It can be a stack frame number or the address of the frame.\n");
1295 add_com ("backtrace", class_stack, backtrace_command,
1296 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1297 With a negative argument, print outermost -COUNT frames.");
1298 add_com_alias ("bt", "backtrace", class_stack, 0);
1299 add_com_alias ("where", "backtrace", class_alias, 0);
1300 add_info ("stack", backtrace_command,
1301 "Backtrace of the stack, or innermost COUNT frames.");
1302 add_info_alias ("s", "stack", 1);
1303 add_info ("frame", frame_info,
1304 "All about selected stack frame, or frame at ADDR.");
1305 add_info_alias ("f", "frame", 1);
1306 add_info ("locals", locals_info,
1307 "Local variables of current stack frame.");
1308 add_info ("args", args_info,
1309 "Argument variables of current stack frame.");
1310 add_info ("catch", catch_info,
1311 "Exceptions that can be caught in the current stack frame.");
1314 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
1315 "Specify maximum number of frames for \"backtrace\" to print by default.",
1317 add_info ("backtrace-limit", backtrace_limit_info,
1318 "The maximum number of frames for \"backtrace\" to print by default.");