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_register (SP_REGNUM), 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_frame);
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, "");
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_frame);
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_frame && calling_frame)
482 printf_filtered (" caller of frame at %s", local_hex_string(fi->next_frame));
483 if (fi->next_frame || calling_frame)
484 puts_filtered ("\n");
486 printf_filtered(" source language %s.\n", language_str(s->language));
488 #ifdef PRINT_EXTRA_FRAME_INFO
489 PRINT_EXTRA_FRAME_INFO (fi);
493 /* Address of the argument list for this frame, or 0. */
494 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
495 /* Number of args for this frame, or -1 if unknown. */
499 printf_filtered (" Arglist at unknown address.\n");
502 printf_filtered (" Arglist at %s,", local_hex_string(arg_list));
504 FRAME_NUM_ARGS (numargs, fi);
506 puts_filtered (" args: ");
507 else if (numargs == 0)
508 puts_filtered (" no args.");
509 else if (numargs == 1)
510 puts_filtered (" 1 arg: ");
512 printf_filtered (" %d args: ", numargs);
513 print_frame_args (func, fi, numargs, stdout);
514 puts_filtered ("\n");
518 /* Address of the local variables for this frame, or 0. */
519 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
522 printf_filtered (" Locals at unknown address,");
524 printf_filtered (" Locals at %s,", local_hex_string(arg_list));
527 #if defined (FRAME_FIND_SAVED_REGS)
528 get_frame_saved_regs (fi, &fsr);
529 /* The sp is special; what's returned isn't the save address, but
530 actually the value of the previous frame's sp. */
531 printf_filtered (" Previous frame's sp is %s\n",
532 local_hex_string(fsr.regs[SP_REGNUM]));
534 for (i = 0; i < NUM_REGS; i++)
535 if (fsr.regs[i] && i != SP_REGNUM)
538 puts_filtered (" Saved registers:\n ");
542 printf_filtered (" %s at %s", reg_names[i],
543 local_hex_string(fsr.regs[i]));
547 puts_filtered ("\n");
548 #endif /* Have FRAME_FIND_SAVED_REGS. */
552 /* Set a limit on the number of frames printed by default in a
555 static int backtrace_limit;
558 set_backtrace_limit_command (count_exp, from_tty)
562 int count = parse_and_eval_address (count_exp);
565 error ("Negative argument not meaningful as backtrace limit.");
567 backtrace_limit = count;
571 backtrace_limit_info (arg, from_tty)
576 error ("\"Info backtrace-limit\" takes no arguments.");
578 printf ("Backtrace limit: %d.\n", backtrace_limit);
582 /* Print briefly all stack frames or just the innermost COUNT frames. */
585 backtrace_command (count_exp, from_tty)
589 struct frame_info *fi;
591 register FRAME frame;
593 register FRAME trailing;
594 register int trailing_level;
596 if (!target_has_stack)
599 /* The following code must do two things. First, it must
600 set the variable TRAILING to the frame from which we should start
601 printing. Second, it must set the variable count to the number
602 of frames which we should print, or -1 if all of them. */
603 trailing = get_current_frame ();
607 count = parse_and_eval_address (count_exp);
615 while (current && count--)
618 current = get_prev_frame (current);
621 /* Will stop when CURRENT reaches the top of the stack. TRAILING
622 will be COUNT below it. */
626 trailing = get_prev_frame (trailing);
627 current = get_prev_frame (current);
639 struct partial_symtab *ps;
641 /* Read in symbols for all of the frames. Need to do this in
642 a separate pass so that "Reading in symbols for xxx" messages
643 don't screw up the appearance of the backtrace. Also
644 if people have strong opinions against reading symbols for
645 backtrace this may have to be an option. */
647 for (frame = trailing;
648 frame != NULL && i--;
649 frame = get_prev_frame (frame))
652 fi = get_frame_info (frame);
653 ps = find_pc_psymtab (fi->pc);
655 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
659 for (i = 0, frame = trailing;
661 i++, frame = get_prev_frame (frame))
664 fi = get_frame_info (frame);
665 print_frame_info (fi, trailing_level + i, 0, 1);
668 /* If we've stopped before the end, mention that. */
669 if (frame && from_tty)
670 printf_filtered ("(More stack frames follow...)\n");
673 /* Print the local variables of a block B active in FRAME.
674 Return 1 if any variables were printed; 0 otherwise. */
677 print_block_frame_locals (b, frame, stream)
679 register FRAME frame;
680 register FILE *stream;
684 register struct symbol *sym;
685 register int values_printed = 0;
687 nsyms = BLOCK_NSYMS (b);
689 for (i = 0; i < nsyms; i++)
691 sym = BLOCK_SYM (b, i);
692 if (SYMBOL_CLASS (sym) == LOC_LOCAL
693 || SYMBOL_CLASS (sym) == LOC_REGISTER
694 || SYMBOL_CLASS (sym) == LOC_STATIC)
697 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
698 fputs_filtered (" = ", stream);
699 print_variable_value (sym, frame, stream);
700 fprintf_filtered (stream, "\n");
703 return values_printed;
706 /* Same, but print labels. */
709 print_block_frame_labels (b, have_default, stream)
712 register FILE *stream;
716 register struct symbol *sym;
717 register int values_printed = 0;
719 nsyms = BLOCK_NSYMS (b);
721 for (i = 0; i < nsyms; i++)
723 sym = BLOCK_SYM (b, i);
724 if (STREQ (SYMBOL_NAME (sym), "default"))
730 if (SYMBOL_CLASS (sym) == LOC_LABEL)
732 struct symtab_and_line sal;
733 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
735 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
737 fprintf_filtered (stream, " %s",
738 local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
739 fprintf_filtered (stream, " in file %s, line %d\n",
740 sal.symtab->filename, sal.line);
743 return values_printed;
746 /* Print on STREAM all the local variables in frame FRAME,
747 including all the blocks active in that frame
750 Returns 1 if the job was done,
751 or 0 if nothing was printed because we have no info
752 on the function running in FRAME. */
755 print_frame_local_vars (frame, stream)
756 register FRAME frame;
757 register FILE *stream;
759 register struct block *block = get_frame_block (frame);
760 register int values_printed = 0;
764 fprintf_filtered (stream, "No symbol table info available.\n");
770 if (print_block_frame_locals (block, frame, stream))
772 /* After handling the function's top-level block, stop.
773 Don't continue to its superblock, the block of
775 if (BLOCK_FUNCTION (block))
777 block = BLOCK_SUPERBLOCK (block);
782 fprintf_filtered (stream, "No locals.\n");
786 /* Same, but print labels. */
789 print_frame_label_vars (frame, this_level_only, stream)
790 register FRAME frame;
792 register FILE *stream;
794 register struct blockvector *bl;
795 register struct block *block = get_frame_block (frame);
796 register int values_printed = 0;
797 int index, have_default = 0;
798 char *blocks_printed;
799 struct frame_info *fi = get_frame_info (frame);
800 CORE_ADDR pc = fi->pc;
804 fprintf_filtered (stream, "No symbol table info available.\n");
808 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
809 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
810 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
814 CORE_ADDR end = BLOCK_END (block) - 4;
817 if (bl != blockvector_for_pc (end, &index))
818 error ("blockvector blotch");
819 if (BLOCKVECTOR_BLOCK (bl, index) != block)
820 error ("blockvector botch");
821 last_index = BLOCKVECTOR_NBLOCKS (bl);
824 /* Don't print out blocks that have gone by. */
825 while (index < last_index
826 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
829 while (index < last_index
830 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
832 if (blocks_printed[index] == 0)
834 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
836 blocks_printed[index] = 1;
842 if (values_printed && this_level_only)
845 /* After handling the function's top-level block, stop.
846 Don't continue to its superblock, the block of
848 if (BLOCK_FUNCTION (block))
850 block = BLOCK_SUPERBLOCK (block);
853 if (!values_printed && !this_level_only)
855 fprintf_filtered (stream, "No catches.\n");
861 locals_info (args, from_tty)
866 error ("No frame selected.");
867 print_frame_local_vars (selected_frame, stdout);
871 catch_info (ignore, from_tty)
876 error ("No frame selected.");
877 print_frame_label_vars (selected_frame, 0, stdout);
881 print_frame_arg_vars (frame, stream)
882 register FRAME frame;
883 register FILE *stream;
885 struct symbol *func = get_frame_function (frame);
886 register struct block *b;
889 register struct symbol *sym, *sym2;
890 register int values_printed = 0;
894 fprintf_filtered (stream, "No symbol table info available.\n");
898 b = SYMBOL_BLOCK_VALUE (func);
899 nsyms = BLOCK_NSYMS (b);
901 for (i = 0; i < nsyms; i++)
903 sym = BLOCK_SYM (b, i);
904 if (SYMBOL_CLASS (sym) == LOC_ARG
905 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
906 || SYMBOL_CLASS (sym) == LOC_REF_ARG
907 || SYMBOL_CLASS (sym) == LOC_REGPARM
908 || SYMBOL_CLASS (sym) == LOC_REGPARM_ADDR)
911 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
912 fputs_filtered (" = ", stream);
914 /* We have to look up the symbol because arguments can have
915 two entries (one a parameter, one a local) and the one we
916 want is the local, which lookup_symbol will find for us.
917 This includes gcc1 (not gcc2) on the sparc when passing a
918 small structure and gcc2 when the argument type is float
919 and it is passed as a double and converted to float by
920 the prologue (in the latter case the type of the LOC_ARG
921 symbol is double and the type of the LOC_LOCAL symbol is
922 float). There are also LOC_ARG/LOC_REGISTER pairs which
923 are not combined in symbol-reading. */
925 sym2 = lookup_symbol (SYMBOL_NAME (sym),
926 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
927 print_variable_value (sym2, frame, stream);
928 fprintf_filtered (stream, "\n");
934 fprintf_filtered (stream, "No arguments.\n");
939 args_info (ignore, from_tty)
944 error ("No frame selected.");
945 print_frame_arg_vars (selected_frame, stdout);
948 /* Select frame FRAME, and note that its stack level is LEVEL.
949 LEVEL may be -1 if an actual level number is not known. */
952 select_frame (frame, level)
956 register struct symtab *s;
958 selected_frame = frame;
959 selected_frame_level = level;
961 /* Ensure that symbols for this frame are read in. Also, determine the
962 source language of this frame, and switch to it if desired. */
965 s = find_pc_symtab (get_frame_info (frame)->pc);
967 && s->language != current_language->la_language
968 && s->language != language_unknown
969 && language_mode == language_mode_auto) {
970 set_language(s->language);
975 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
976 If there is no selected frame, *FRAMEP is set to NULL. */
979 record_selected_frame (frameaddrp, levelp)
980 FRAME_ADDR *frameaddrp;
983 *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
984 *levelp = selected_frame_level;
987 /* Return the symbol-block in which the selected frame is executing.
988 Can return zero under various legitimate circumstances. */
991 get_selected_block ()
993 if (!target_has_stack)
997 return get_current_block ();
998 return get_frame_block (selected_frame);
1001 /* Find a frame a certain number of levels away from FRAME.
1002 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1003 Positive means go to earlier frames (up); negative, the reverse.
1004 The int that contains the number of levels is counted toward
1005 zero as the frames for those levels are found.
1006 If the top or bottom frame is reached, that frame is returned,
1007 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1008 how much farther the original request asked to go. */
1011 find_relative_frame (frame, level_offset_ptr)
1012 register FRAME frame;
1013 register int* level_offset_ptr;
1015 register FRAME prev;
1016 register FRAME frame1;
1018 /* Going up is simple: just do get_prev_frame enough times
1019 or until initial frame is reached. */
1020 while (*level_offset_ptr > 0)
1022 prev = get_prev_frame (frame);
1025 (*level_offset_ptr)--;
1028 /* Going down is just as simple. */
1029 if (*level_offset_ptr < 0)
1031 while (*level_offset_ptr < 0) {
1032 frame1 = get_next_frame (frame);
1036 (*level_offset_ptr)++;
1042 /* The "select_frame" command. With no arg, NOP.
1043 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1044 valid level. Otherwise, treat level_exp as an address expression
1045 and select it. See parse_frame_specification for more info on proper
1046 frame expressions. */
1050 select_frame_command (level_exp, from_tty)
1054 register FRAME frame, frame1;
1055 unsigned int level = 0;
1057 if (!target_has_stack)
1058 error ("No stack.");
1060 frame = parse_frame_specification (level_exp);
1062 /* Try to figure out what level this frame is. But if there is
1063 no current stack, don't error out -- let the user set one. */
1065 if (get_current_frame()) {
1066 for (frame1 = get_prev_frame (0);
1067 frame1 && frame1 != frame;
1068 frame1 = get_prev_frame (frame1))
1075 select_frame (frame, level);
1078 /* The "frame" command. With no arg, print selected frame briefly.
1079 With arg, behaves like select_frame and then prints the selected
1083 frame_command (level_exp, from_tty)
1087 select_frame_command (level_exp, from_tty);
1088 print_stack_frame (selected_frame, selected_frame_level, 1);
1091 /* Select the frame up one or COUNT stack levels
1092 from the previously selected frame, and print it briefly. */
1096 up_silently_command (count_exp, from_tty)
1100 register FRAME frame;
1101 int count = 1, count1;
1103 count = parse_and_eval_address (count_exp);
1106 if (target_has_stack == 0 || selected_frame == 0)
1107 error ("No stack.");
1109 frame = find_relative_frame (selected_frame, &count1);
1110 if (count1 != 0 && count_exp == 0)
1111 error ("Initial frame selected; you cannot go up.");
1112 select_frame (frame, selected_frame_level + count - count1);
1116 up_command (count_exp, from_tty)
1120 up_silently_command (count_exp, from_tty);
1121 print_stack_frame (selected_frame, selected_frame_level, 1);
1124 /* Select the frame down one or COUNT stack levels
1125 from the previously selected frame, and print it briefly. */
1129 down_silently_command (count_exp, from_tty)
1133 register FRAME frame;
1134 int count = -1, count1;
1136 count = - parse_and_eval_address (count_exp);
1139 if (target_has_stack == 0 || selected_frame == 0)
1140 error ("No stack.");
1142 frame = find_relative_frame (selected_frame, &count1);
1143 if (count1 != 0 && count_exp == 0)
1144 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1145 select_frame (frame, selected_frame_level + count - count1);
1150 down_command (count_exp, from_tty)
1154 down_silently_command (count_exp, from_tty);
1155 print_stack_frame (selected_frame, selected_frame_level, 1);
1159 return_command (retval_exp, from_tty)
1163 struct symbol *thisfun;
1164 FRAME_ADDR selected_frame_addr;
1165 CORE_ADDR selected_frame_pc;
1169 if (selected_frame == NULL)
1170 error ("No selected frame.");
1171 thisfun = get_frame_function (selected_frame);
1172 selected_frame_addr = FRAME_FP (selected_frame);
1173 selected_frame_pc = (get_frame_info (selected_frame))->pc;
1175 /* Compute the return value (if any -- possibly getting errors here).
1176 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1177 it might live in the stack frame we're about to pop. */
1181 return_value = parse_and_eval (retval_exp);
1182 VALUE_CONTENTS (return_value);
1185 /* If interactive, require confirmation. */
1191 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
1193 error ("Not confirmed.");
1198 if (!query ("Make selected stack frame return now? "))
1199 error ("Not confirmed.");
1202 /* Do the real work. Pop until the specified frame is current. We
1203 use this method because the selected_frame is not valid after
1204 a POP_FRAME. The pc comparison makes this work even if the
1205 selected frame shares its fp with another frame. */
1207 while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
1208 || selected_frame_pc != (get_frame_info (frame))->pc )
1211 /* Then pop that frame. */
1215 /* Compute the return value (if any) and store in the place
1216 for return values. */
1219 set_return_value (return_value);
1221 /* If interactive, print the frame that is now current. */
1224 frame_command ("0", 1);
1227 /* Gets the language of the current frame. */
1229 get_frame_language()
1231 register struct symtab *s;
1233 enum language flang; /* The language of the current frame */
1235 fr = get_frame_info(selected_frame);
1238 s = find_pc_symtab(fr->pc);
1240 flang = s->language;
1242 flang = language_unknown;
1245 flang = language_unknown;
1251 _initialize_stack ()
1254 backtrace_limit = 30;
1257 add_com ("return", class_stack, return_command,
1258 "Make selected stack frame return to its caller.\n\
1259 Control remains in the debugger, but when you continue\n\
1260 execution will resume in the frame above the one now selected.\n\
1261 If an argument is given, it is an expression for the value to return.");
1263 add_com ("up", class_stack, up_command,
1264 "Select and print stack frame that called this one.\n\
1265 An argument says how many frames up to go.");
1266 add_com ("up-silently", class_support, up_silently_command,
1267 "Same as the `up' command, but does not print anything.\n\
1268 This is useful in command scripts.");
1270 add_com ("down", class_stack, down_command,
1271 "Select and print stack frame called by this one.\n\
1272 An argument says how many frames down to go.");
1273 add_com_alias ("do", "down", class_stack, 1);
1274 add_com_alias ("dow", "down", class_stack, 1);
1275 add_com ("down-silently", class_support, down_silently_command,
1276 "Same as the `down' command, but does not print anything.\n\
1277 This is useful in command scripts.");
1279 add_com ("frame", class_stack, frame_command,
1280 "Select and print a stack frame.\n\
1281 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1282 An argument specifies the frame to select.\n\
1283 It can be a stack frame number or the address of the frame.\n\
1284 With argument, nothing is printed if input is coming from\n\
1285 a command file or a user-defined command.");
1287 add_com_alias ("f", "frame", class_stack, 1);
1289 add_com ("select-frame", class_stack, select_frame_command,
1290 "Select a stack frame without printing anything.\n\
1291 An argument specifies the frame to select.\n\
1292 It can be a stack frame number or the address of the frame.\n");
1294 add_com ("backtrace", class_stack, backtrace_command,
1295 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1296 With a negative argument, print outermost -COUNT frames.");
1297 add_com_alias ("bt", "backtrace", class_stack, 0);
1298 add_com_alias ("where", "backtrace", class_alias, 0);
1299 add_info ("stack", backtrace_command,
1300 "Backtrace of the stack, or innermost COUNT frames.");
1301 add_info_alias ("s", "stack", 1);
1302 add_info ("frame", frame_info,
1303 "All about selected stack frame, or frame at ADDR.");
1304 add_info_alias ("f", "frame", 1);
1305 add_info ("locals", locals_info,
1306 "Local variables of current stack frame.");
1307 add_info ("args", args_info,
1308 "Argument variables of current stack frame.");
1309 add_info ("catch", catch_info,
1310 "Exceptions that can be caught in the current stack frame.");
1313 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
1314 "Specify maximum number of frames for \"backtrace\" to print by default.",
1316 add_info ("backtrace-limit", backtrace_limit_info,
1317 "The maximum number of frames for \"backtrace\" to print by default.");