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;
163 char buf[MAX_REGISTER_RAW_SIZE];
166 /* Get the value of SP_REGNUM relative to the frame. */
167 get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
168 FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL);
169 sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
171 /* This is not a perfect test, because if a function alloca's some
172 memory, puts some code there, and then jumps into it, then the test
173 will succeed even though there is no call dummy. A better
174 solution would be to keep track of where the call dummies are.
175 Probably the best way to do that is by setting a breakpoint.c
176 breakpoint at the end of the call dummy (wanted anyway, to clean
177 up wait_for_inferior). Then we know that the sizeof (CALL_DUMMY)
178 (or some such) bytes before that breakpoint are a call dummy.
179 Only problem I see with this approach is figuring out to get rid
180 of the breakpoint whenever the call dummy vanishes (e.g.
181 return_command, or longjmp out of the called function), which we
182 probably can solve (it's very similar to figuring out when a
183 watchpoint on a local variable goes out of scope if it is being
184 watched via something like a 386 debug register). */
185 if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
187 /* Do this regardless of SOURCE because we don't have any source
188 to list for this frame. */
190 printf_filtered ("#%-2d ", level);
191 printf_filtered ("<function called from gdb>\n");
194 if (fi->signal_handler_caller)
196 /* Do this regardless of SOURCE because we don't have any source
197 to list for this frame. */
199 printf_filtered ("#%-2d ", level);
200 printf_filtered ("<signal handler called>\n");
204 /* If fi is not the innermost frame, that normally means that fi->pc
205 points to *after* the call instruction, and we want to get the line
206 containing the call, never the next line. But if the next frame is
207 a signal_handler_caller frame, then the next frame was not entered
208 as the result of a call, and we want to get the line containing
211 find_pc_line (fi->pc,
212 fi->next != NULL && fi->next->signal_handler_caller == 0);
214 func = find_pc_function (fi->pc);
217 /* In certain pathological cases, the symtabs give the wrong
218 function (when we are in the first function in a file which
219 is compiled without debugging symbols, the previous function
220 is compiled with debugging symbols, and the "foo.o" symbol
221 that is supposed to tell us where the file with debugging symbols
222 ends has been truncated by ar because it is longer than 15
223 characters). This also occurs if the user uses asm() to create
224 a function but not stabs for it (in a file compiled -g).
226 So look in the minimal symbol tables as well, and if it comes
227 up with a larger address for the function use that instead.
228 I don't think this can ever cause any problems; there shouldn't
229 be any minimal symbols in the middle of a function; if this is
230 ever changed many parts of GDB will need to be changed (and we'll
231 create a find_pc_minimal_function or some such). */
233 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
235 && (SYMBOL_VALUE_ADDRESS (msymbol)
236 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
238 /* In this case we have no way of knowing the source file
239 and line number, so don't print them. */
241 /* We also don't know anything about the function besides
242 its address and name. */
244 funname = SYMBOL_NAME (msymbol);
245 funlang = SYMBOL_LANGUAGE (msymbol);
249 funname = SYMBOL_NAME (func);
250 funlang = SYMBOL_LANGUAGE (func);
255 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
258 funname = SYMBOL_NAME (msymbol);
259 funlang = SYMBOL_LANGUAGE (msymbol);
263 if (source >= 0 || !sal.symtab)
266 printf_filtered ("#%-2d ", level);
268 if (fi->pc != sal.pc || !sal.symtab)
269 printf_filtered ("%s in ", local_hex_string(fi->pc));
270 fprintf_symbol_filtered (stdout, funname ? funname : "??", funlang,
273 fputs_filtered (" (", stdout);
276 struct print_args_args args;
279 catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR);
281 printf_filtered (")");
282 if (sal.symtab && sal.symtab->filename)
285 printf_filtered (" at %s:%d", sal.symtab->filename, sal.line);
288 #ifdef PC_LOAD_SEGMENT
289 /* If we couldn't print out function name but if can figure out what
290 load segment this pc value is from, at least print out some info
291 about its load segment. */
294 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
297 printf_filtered ("\n");
300 if ((source != 0) && sal.symtab)
303 int mid_statement = source < 0 && fi->pc != sal.pc;
304 if (frame_file_full_name)
305 done = identify_source_line (sal.symtab, sal.line, mid_statement,
309 if (addressprint && mid_statement)
310 printf_filtered ("%s\t", local_hex_string(fi->pc));
311 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
313 current_source_line = max (sal.line - lines_to_list/2, 1);
316 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
322 * Read a frame specification in whatever the appropriate format is.
323 * Call error() if the specification is in any way invalid (i.e.
324 * this function never returns NULL).
327 parse_frame_specification (frame_exp)
336 char *addr_string, *p;
337 struct cleanup *tmp_cleanup;
339 while (*frame_exp == ' ') frame_exp++;
343 if (numargs > MAXARGS)
344 error ("Too many args in frame specification");
345 /* Parse an argument. */
346 for (p = frame_exp; *p && *p != ' '; p++)
348 addr_string = savestring(frame_exp, p - frame_exp);
351 tmp_cleanup = make_cleanup (free, addr_string);
352 args[numargs++] = parse_and_eval_address (addr_string);
353 do_cleanups (tmp_cleanup);
356 /* Skip spaces, move to possible next arg. */
357 while (*p == ' ') p++;
365 if (selected_frame == NULL)
366 error ("No selected frame.");
367 return selected_frame;
372 FRAME fid = find_relative_frame (get_current_frame (), &level);
376 /* find_relative_frame was successful */
379 /* If (s)he specifies the frame with an address, he deserves what
380 (s)he gets. Still, give the highest one that matches. */
382 for (fid = get_current_frame ();
383 fid && FRAME_FP (fid) != args[0];
384 fid = get_prev_frame (fid))
388 while ((tfid = get_prev_frame (fid)) &&
389 (FRAME_FP (tfid) == args[0]))
392 /* We couldn't identify the frame as an existing frame, but
393 perhaps we can create one with a single argument.
394 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
395 to complain if it doesn't like a single arg. */
399 #ifdef SETUP_ARBITRARY_FRAME
400 return SETUP_ARBITRARY_FRAME (numargs, args);
402 /* Usual case. Do it here rather than have everyone supply
403 a SETUP_ARBITRARY_FRAME that does this. */
405 return create_new_frame (args[0], 0);
406 error ("Too many args in frame specification");
413 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
414 that if it is unsure about the answer, it returns 0
415 instead of guessing (this happens on the VAX and i960, for example).
417 On most machines, we never have to guess about the args address,
418 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
419 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
420 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
423 /* Print verbosely the selected frame or the frame at address ADDR.
424 This means absolutely all information in the frame is printed. */
427 frame_info (addr_exp, from_tty)
432 struct frame_info *fi;
433 struct frame_saved_regs fsr;
434 struct symtab_and_line sal;
440 enum language funlang = language_unknown;
442 if (!target_has_stack)
445 frame = parse_frame_specification (addr_exp);
447 error ("Invalid frame specified.");
449 fi = get_frame_info (frame);
450 sal = find_pc_line (fi->pc,
451 fi->next != NULL && fi->next->signal_handler_caller == 0);
452 func = get_frame_function (frame);
453 s = find_pc_symtab(fi->pc);
456 funname = SYMBOL_NAME (func);
457 funlang = SYMBOL_LANGUAGE (func);
461 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
464 funname = SYMBOL_NAME (msymbol);
465 funlang = SYMBOL_LANGUAGE (msymbol);
468 calling_frame = get_prev_frame (frame);
470 if (!addr_exp && selected_frame_level >= 0) {
471 printf_filtered ("Stack level %d, frame at %s:\n",
472 selected_frame_level,
473 local_hex_string(FRAME_FP(frame)));
475 printf_filtered ("Stack frame at %s:\n",
476 local_hex_string(FRAME_FP(frame)));
478 printf_filtered (" %s = %s",
479 reg_names[PC_REGNUM],
480 local_hex_string(fi->pc));
485 printf_filtered (" in ");
486 fprintf_symbol_filtered (stdout, funname, funlang,
487 DMGL_ANSI | DMGL_PARAMS);
491 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
492 puts_filtered ("; ");
494 printf_filtered ("saved %s %s\n", reg_names[PC_REGNUM],
495 local_hex_string(FRAME_SAVED_PC (frame)));
499 #ifdef FRAMELESS_FUNCTION_INVOCATION
500 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
503 printf_filtered (" (FRAMELESS),");
507 printf_filtered (" called by frame at %s",
508 local_hex_string(FRAME_FP (calling_frame)));
509 if (fi->next && calling_frame)
513 printf_filtered (" caller of frame at %s",
514 local_hex_string (fi->next->frame));
515 if (fi->next || calling_frame)
516 puts_filtered ("\n");
518 printf_filtered(" source language %s.\n", language_str(s->language));
520 #ifdef PRINT_EXTRA_FRAME_INFO
521 PRINT_EXTRA_FRAME_INFO (fi);
525 /* Address of the argument list for this frame, or 0. */
526 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
527 /* Number of args for this frame, or -1 if unknown. */
531 printf_filtered (" Arglist at unknown address.\n");
534 printf_filtered (" Arglist at %s,", local_hex_string(arg_list));
536 FRAME_NUM_ARGS (numargs, fi);
538 puts_filtered (" args: ");
539 else if (numargs == 0)
540 puts_filtered (" no args.");
541 else if (numargs == 1)
542 puts_filtered (" 1 arg: ");
544 printf_filtered (" %d args: ", numargs);
545 print_frame_args (func, fi, numargs, stdout);
546 puts_filtered ("\n");
550 /* Address of the local variables for this frame, or 0. */
551 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
554 printf_filtered (" Locals at unknown address,");
556 printf_filtered (" Locals at %s,", local_hex_string(arg_list));
559 #if defined (FRAME_FIND_SAVED_REGS)
560 get_frame_saved_regs (fi, &fsr);
561 /* The sp is special; what's returned isn't the save address, but
562 actually the value of the previous frame's sp. */
563 printf_filtered (" Previous frame's sp is %s\n",
564 local_hex_string(fsr.regs[SP_REGNUM]));
566 for (i = 0; i < NUM_REGS; i++)
567 if (fsr.regs[i] && i != SP_REGNUM)
570 puts_filtered (" Saved registers:\n ");
574 printf_filtered (" %s at %s", reg_names[i],
575 local_hex_string(fsr.regs[i]));
579 puts_filtered ("\n");
580 #endif /* Have FRAME_FIND_SAVED_REGS. */
584 /* Set a limit on the number of frames printed by default in a
587 static int backtrace_limit;
590 set_backtrace_limit_command (count_exp, from_tty)
594 int count = parse_and_eval_address (count_exp);
597 error ("Negative argument not meaningful as backtrace limit.");
599 backtrace_limit = count;
603 backtrace_limit_info (arg, from_tty)
608 error ("\"Info backtrace-limit\" takes no arguments.");
610 printf ("Backtrace limit: %d.\n", backtrace_limit);
614 /* Print briefly all stack frames or just the innermost COUNT frames. */
617 backtrace_command (count_exp, from_tty)
621 struct frame_info *fi;
623 register FRAME frame;
625 register FRAME trailing;
626 register int trailing_level;
628 if (!target_has_stack)
631 /* The following code must do two things. First, it must
632 set the variable TRAILING to the frame from which we should start
633 printing. Second, it must set the variable count to the number
634 of frames which we should print, or -1 if all of them. */
635 trailing = get_current_frame ();
639 count = parse_and_eval_address (count_exp);
647 while (current && count--)
650 current = get_prev_frame (current);
653 /* Will stop when CURRENT reaches the top of the stack. TRAILING
654 will be COUNT below it. */
658 trailing = get_prev_frame (trailing);
659 current = get_prev_frame (current);
671 struct partial_symtab *ps;
673 /* Read in symbols for all of the frames. Need to do this in
674 a separate pass so that "Reading in symbols for xxx" messages
675 don't screw up the appearance of the backtrace. Also
676 if people have strong opinions against reading symbols for
677 backtrace this may have to be an option. */
679 for (frame = trailing;
680 frame != NULL && i--;
681 frame = get_prev_frame (frame))
684 fi = get_frame_info (frame);
685 ps = find_pc_psymtab (fi->pc);
687 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
691 for (i = 0, frame = trailing;
693 i++, frame = get_prev_frame (frame))
696 fi = get_frame_info (frame);
697 print_frame_info (fi, trailing_level + i, 0, 1);
700 /* If we've stopped before the end, mention that. */
701 if (frame && from_tty)
702 printf_filtered ("(More stack frames follow...)\n");
705 /* Print the local variables of a block B active in FRAME.
706 Return 1 if any variables were printed; 0 otherwise. */
709 print_block_frame_locals (b, frame, stream)
711 register FRAME frame;
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 (SYMBOL_CLASS (sym) == LOC_LOCAL
725 || SYMBOL_CLASS (sym) == LOC_REGISTER
726 || SYMBOL_CLASS (sym) == LOC_STATIC)
729 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
730 fputs_filtered (" = ", stream);
731 print_variable_value (sym, frame, stream);
732 fprintf_filtered (stream, "\n");
735 return values_printed;
738 /* Same, but print labels. */
741 print_block_frame_labels (b, have_default, stream)
744 register FILE *stream;
748 register struct symbol *sym;
749 register int values_printed = 0;
751 nsyms = BLOCK_NSYMS (b);
753 for (i = 0; i < nsyms; i++)
755 sym = BLOCK_SYM (b, i);
756 if (STREQ (SYMBOL_NAME (sym), "default"))
762 if (SYMBOL_CLASS (sym) == LOC_LABEL)
764 struct symtab_and_line sal;
765 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
767 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
769 fprintf_filtered (stream, " %s",
770 local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
771 fprintf_filtered (stream, " in file %s, line %d\n",
772 sal.symtab->filename, sal.line);
775 return values_printed;
778 /* Print on STREAM all the local variables in frame FRAME,
779 including all the blocks active in that frame
782 Returns 1 if the job was done,
783 or 0 if nothing was printed because we have no info
784 on the function running in FRAME. */
787 print_frame_local_vars (frame, stream)
788 register FRAME frame;
789 register FILE *stream;
791 register struct block *block = get_frame_block (frame);
792 register int values_printed = 0;
796 fprintf_filtered (stream, "No symbol table info available.\n");
802 if (print_block_frame_locals (block, frame, stream))
804 /* After handling the function's top-level block, stop.
805 Don't continue to its superblock, the block of
807 if (BLOCK_FUNCTION (block))
809 block = BLOCK_SUPERBLOCK (block);
814 fprintf_filtered (stream, "No locals.\n");
818 /* Same, but print labels. */
821 print_frame_label_vars (frame, this_level_only, stream)
822 register FRAME frame;
824 register FILE *stream;
826 register struct blockvector *bl;
827 register struct block *block = get_frame_block (frame);
828 register int values_printed = 0;
829 int index, have_default = 0;
830 char *blocks_printed;
831 struct frame_info *fi = get_frame_info (frame);
832 CORE_ADDR pc = fi->pc;
836 fprintf_filtered (stream, "No symbol table info available.\n");
840 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
841 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
842 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
846 CORE_ADDR end = BLOCK_END (block) - 4;
849 if (bl != blockvector_for_pc (end, &index))
850 error ("blockvector blotch");
851 if (BLOCKVECTOR_BLOCK (bl, index) != block)
852 error ("blockvector botch");
853 last_index = BLOCKVECTOR_NBLOCKS (bl);
856 /* Don't print out blocks that have gone by. */
857 while (index < last_index
858 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
861 while (index < last_index
862 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
864 if (blocks_printed[index] == 0)
866 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
868 blocks_printed[index] = 1;
874 if (values_printed && this_level_only)
877 /* After handling the function's top-level block, stop.
878 Don't continue to its superblock, the block of
880 if (BLOCK_FUNCTION (block))
882 block = BLOCK_SUPERBLOCK (block);
885 if (!values_printed && !this_level_only)
887 fprintf_filtered (stream, "No catches.\n");
893 locals_info (args, from_tty)
898 error ("No frame selected.");
899 print_frame_local_vars (selected_frame, stdout);
903 catch_info (ignore, from_tty)
908 error ("No frame selected.");
909 print_frame_label_vars (selected_frame, 0, stdout);
913 print_frame_arg_vars (frame, stream)
914 register FRAME frame;
915 register FILE *stream;
917 struct symbol *func = get_frame_function (frame);
918 register struct block *b;
921 register struct symbol *sym, *sym2;
922 register int values_printed = 0;
926 fprintf_filtered (stream, "No symbol table info available.\n");
930 b = SYMBOL_BLOCK_VALUE (func);
931 nsyms = BLOCK_NSYMS (b);
933 for (i = 0; i < nsyms; i++)
935 sym = BLOCK_SYM (b, i);
936 switch (SYMBOL_CLASS (sym))
942 case LOC_REGPARM_ADDR:
943 case LOC_BASEREG_ARG:
945 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
946 fputs_filtered (" = ", stream);
948 /* We have to look up the symbol because arguments can have
949 two entries (one a parameter, one a local) and the one we
950 want is the local, which lookup_symbol will find for us.
951 This includes gcc1 (not gcc2) on the sparc when passing a
952 small structure and gcc2 when the argument type is float
953 and it is passed as a double and converted to float by
954 the prologue (in the latter case the type of the LOC_ARG
955 symbol is double and the type of the LOC_LOCAL symbol is
956 float). There are also LOC_ARG/LOC_REGISTER pairs which
957 are not combined in symbol-reading. */
959 sym2 = lookup_symbol (SYMBOL_NAME (sym),
960 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
961 print_variable_value (sym2, frame, stream);
962 fprintf_filtered (stream, "\n");
966 /* Don't worry about things which aren't arguments. */
973 fprintf_filtered (stream, "No arguments.\n");
978 args_info (ignore, from_tty)
983 error ("No frame selected.");
984 print_frame_arg_vars (selected_frame, stdout);
987 /* Select frame FRAME, and note that its stack level is LEVEL.
988 LEVEL may be -1 if an actual level number is not known. */
991 select_frame (frame, level)
995 register struct symtab *s;
997 selected_frame = frame;
998 selected_frame_level = level;
1000 /* Ensure that symbols for this frame are read in. Also, determine the
1001 source language of this frame, and switch to it if desired. */
1004 s = find_pc_symtab (get_frame_info (frame)->pc);
1006 && s->language != current_language->la_language
1007 && s->language != language_unknown
1008 && language_mode == language_mode_auto) {
1009 set_language(s->language);
1014 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
1015 If there is no selected frame, *FRAMEP is set to NULL. */
1018 record_selected_frame (frameaddrp, levelp)
1019 FRAME_ADDR *frameaddrp;
1022 *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
1023 *levelp = selected_frame_level;
1026 /* Return the symbol-block in which the selected frame is executing.
1027 Can return zero under various legitimate circumstances. */
1030 get_selected_block ()
1032 if (!target_has_stack)
1035 if (!selected_frame)
1036 return get_current_block ();
1037 return get_frame_block (selected_frame);
1040 /* Find a frame a certain number of levels away from FRAME.
1041 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1042 Positive means go to earlier frames (up); negative, the reverse.
1043 The int that contains the number of levels is counted toward
1044 zero as the frames for those levels are found.
1045 If the top or bottom frame is reached, that frame is returned,
1046 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1047 how much farther the original request asked to go. */
1050 find_relative_frame (frame, level_offset_ptr)
1051 register FRAME frame;
1052 register int* level_offset_ptr;
1054 register FRAME prev;
1055 register FRAME frame1;
1057 /* Going up is simple: just do get_prev_frame enough times
1058 or until initial frame is reached. */
1059 while (*level_offset_ptr > 0)
1061 prev = get_prev_frame (frame);
1064 (*level_offset_ptr)--;
1067 /* Going down is just as simple. */
1068 if (*level_offset_ptr < 0)
1070 while (*level_offset_ptr < 0) {
1071 frame1 = get_next_frame (frame);
1075 (*level_offset_ptr)++;
1081 /* The "select_frame" command. With no arg, NOP.
1082 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1083 valid level. Otherwise, treat level_exp as an address expression
1084 and select it. See parse_frame_specification for more info on proper
1085 frame expressions. */
1089 select_frame_command (level_exp, from_tty)
1093 register FRAME frame, frame1;
1094 unsigned int level = 0;
1096 if (!target_has_stack)
1097 error ("No stack.");
1099 frame = parse_frame_specification (level_exp);
1101 /* Try to figure out what level this frame is. But if there is
1102 no current stack, don't error out -- let the user set one. */
1104 if (get_current_frame()) {
1105 for (frame1 = get_prev_frame (0);
1106 frame1 && frame1 != frame;
1107 frame1 = get_prev_frame (frame1))
1114 select_frame (frame, level);
1117 /* The "frame" command. With no arg, print selected frame briefly.
1118 With arg, behaves like select_frame and then prints the selected
1122 frame_command (level_exp, from_tty)
1126 select_frame_command (level_exp, from_tty);
1127 print_stack_frame (selected_frame, selected_frame_level, 1);
1130 /* Select the frame up one or COUNT stack levels
1131 from the previously selected frame, and print it briefly. */
1135 up_silently_command (count_exp, from_tty)
1139 register FRAME frame;
1140 int count = 1, count1;
1142 count = parse_and_eval_address (count_exp);
1145 if (target_has_stack == 0 || selected_frame == 0)
1146 error ("No stack.");
1148 frame = find_relative_frame (selected_frame, &count1);
1149 if (count1 != 0 && count_exp == 0)
1150 error ("Initial frame selected; you cannot go up.");
1151 select_frame (frame, selected_frame_level + count - count1);
1155 up_command (count_exp, from_tty)
1159 up_silently_command (count_exp, from_tty);
1160 print_stack_frame (selected_frame, selected_frame_level, 1);
1163 /* Select the frame down one or COUNT stack levels
1164 from the previously selected frame, and print it briefly. */
1168 down_silently_command (count_exp, from_tty)
1172 register FRAME frame;
1173 int count = -1, count1;
1175 count = - parse_and_eval_address (count_exp);
1178 if (target_has_stack == 0 || selected_frame == 0)
1179 error ("No stack.");
1181 frame = find_relative_frame (selected_frame, &count1);
1182 if (count1 != 0 && count_exp == 0)
1183 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1184 select_frame (frame, selected_frame_level + count - count1);
1189 down_command (count_exp, from_tty)
1193 down_silently_command (count_exp, from_tty);
1194 print_stack_frame (selected_frame, selected_frame_level, 1);
1198 return_command (retval_exp, from_tty)
1202 struct symbol *thisfun;
1203 FRAME_ADDR selected_frame_addr;
1204 CORE_ADDR selected_frame_pc;
1206 value return_value = NULL;
1208 if (selected_frame == NULL)
1209 error ("No selected frame.");
1210 thisfun = get_frame_function (selected_frame);
1211 selected_frame_addr = FRAME_FP (selected_frame);
1212 selected_frame_pc = (get_frame_info (selected_frame))->pc;
1214 /* Compute the return value (if any -- possibly getting errors here).
1215 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1216 it might live in the stack frame we're about to pop. */
1220 return_value = parse_and_eval (retval_exp);
1221 VALUE_CONTENTS (return_value);
1224 /* If interactive, require confirmation. */
1230 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
1232 error ("Not confirmed.");
1237 if (!query ("Make selected stack frame return now? "))
1238 error ("Not confirmed.");
1241 /* Do the real work. Pop until the specified frame is current. We
1242 use this method because the selected_frame is not valid after
1243 a POP_FRAME. The pc comparison makes this work even if the
1244 selected frame shares its fp with another frame. */
1246 while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
1247 || selected_frame_pc != (get_frame_info (frame))->pc )
1250 /* Then pop that frame. */
1254 /* Compute the return value (if any) and store in the place
1255 for return values. */
1258 set_return_value (return_value);
1260 /* If interactive, print the frame that is now current. */
1263 frame_command ("0", 1);
1266 /* Gets the language of the current frame. */
1268 get_frame_language()
1270 register struct symtab *s;
1272 enum language flang; /* The language of the current frame */
1274 fr = get_frame_info(selected_frame);
1277 s = find_pc_symtab(fr->pc);
1279 flang = s->language;
1281 flang = language_unknown;
1284 flang = language_unknown;
1290 _initialize_stack ()
1293 backtrace_limit = 30;
1296 add_com ("return", class_stack, return_command,
1297 "Make selected stack frame return to its caller.\n\
1298 Control remains in the debugger, but when you continue\n\
1299 execution will resume in the frame above the one now selected.\n\
1300 If an argument is given, it is an expression for the value to return.");
1302 add_com ("up", class_stack, up_command,
1303 "Select and print stack frame that called this one.\n\
1304 An argument says how many frames up to go.");
1305 add_com ("up-silently", class_support, up_silently_command,
1306 "Same as the `up' command, but does not print anything.\n\
1307 This is useful in command scripts.");
1309 add_com ("down", class_stack, down_command,
1310 "Select and print stack frame called by this one.\n\
1311 An argument says how many frames down to go.");
1312 add_com_alias ("do", "down", class_stack, 1);
1313 add_com_alias ("dow", "down", class_stack, 1);
1314 add_com ("down-silently", class_support, down_silently_command,
1315 "Same as the `down' command, but does not print anything.\n\
1316 This is useful in command scripts.");
1318 add_com ("frame", class_stack, frame_command,
1319 "Select and print a stack frame.\n\
1320 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1321 An argument specifies the frame to select.\n\
1322 It can be a stack frame number or the address of the frame.\n\
1323 With argument, nothing is printed if input is coming from\n\
1324 a command file or a user-defined command.");
1326 add_com_alias ("f", "frame", class_stack, 1);
1328 add_com ("select-frame", class_stack, select_frame_command,
1329 "Select a stack frame without printing anything.\n\
1330 An argument specifies the frame to select.\n\
1331 It can be a stack frame number or the address of the frame.\n");
1333 add_com ("backtrace", class_stack, backtrace_command,
1334 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1335 With a negative argument, print outermost -COUNT frames.");
1336 add_com_alias ("bt", "backtrace", class_stack, 0);
1337 add_com_alias ("where", "backtrace", class_alias, 0);
1338 add_info ("stack", backtrace_command,
1339 "Backtrace of the stack, or innermost COUNT frames.");
1340 add_info_alias ("s", "stack", 1);
1341 add_info ("frame", frame_info,
1342 "All about selected stack frame, or frame at ADDR.");
1343 add_info_alias ("f", "frame", 1);
1344 add_info ("locals", locals_info,
1345 "Local variables of current stack frame.");
1346 add_info ("args", args_info,
1347 "Argument variables of current stack frame.");
1348 add_info ("catch", catch_info,
1349 "Exceptions that can be caught in the current stack frame.");
1352 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
1353 "Specify maximum number of frames for \"backtrace\" to print by default.",
1355 add_info ("backtrace-limit", backtrace_limit_info,
1356 "The maximum number of frames for \"backtrace\" to print by default.");