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;
164 char buf[MAX_REGISTER_RAW_SIZE];
167 /* Get the value of SP_REGNUM relative to the frame. */
168 get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
169 FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL);
170 sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
172 /* This is not a perfect test, because if a function alloca's some
173 memory, puts some code there, and then jumps into it, then the test
174 will succeed even though there is no call dummy. A better
175 solution would be to keep track of where the call dummies are.
176 Probably the best way to do that is by setting a breakpoint.c
177 breakpoint at the end of the call dummy (wanted anyway, to clean
178 up wait_for_inferior). Then we know that the sizeof (CALL_DUMMY)
179 (or some such) bytes before that breakpoint are a call dummy.
180 Only problem I see with this approach is figuring out to get rid
181 of the breakpoint whenever the call dummy vanishes (e.g.
182 return_command, or longjmp out of the called function), which we
183 probably can solve (it's very similar to figuring out when a
184 watchpoint on a local variable goes out of scope if it is being
185 watched via something like a 386 debug register). */
186 if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
188 /* Do this regardless of SOURCE because we don't have any source
189 to list for this frame. */
191 printf_filtered ("#%-2d ", level);
192 printf_filtered ("<function called from gdb>\n");
195 if (fi->signal_handler_caller)
197 /* Do this regardless of SOURCE because we don't have any source
198 to list for this frame. */
200 printf_filtered ("#%-2d ", level);
201 printf_filtered ("<signal handler called>\n");
205 sal = find_pc_line (fi->pc,
206 fi->next != NULL && fi->next->signal_handler_caller == 0);
207 func = find_pc_function (fi->pc);
210 /* In certain pathological cases, the symtabs give the wrong
211 function (when we are in the first function in a file which
212 is compiled without debugging symbols, the previous function
213 is compiled with debugging symbols, and the "foo.o" symbol
214 that is supposed to tell us where the file with debugging symbols
215 ends has been truncated by ar because it is longer than 15
216 characters). This also occurs if the user uses asm() to create
217 a function but not stabs for it (in a file compiled -g).
219 So look in the minimal symbol tables as well, and if it comes
220 up with a larger address for the function use that instead.
221 I don't think this can ever cause any problems; there shouldn't
222 be any minimal symbols in the middle of a function; if this is
223 ever changed many parts of GDB will need to be changed (and we'll
224 create a find_pc_minimal_function or some such). */
226 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
228 && (SYMBOL_VALUE_ADDRESS (msymbol)
229 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
231 /* In this case we have no way of knowing the source file
232 and line number, so don't print them. */
234 /* We also don't know anything about the function besides
235 its address and name. */
237 funname = SYMBOL_NAME (msymbol);
238 funlang = SYMBOL_LANGUAGE (msymbol);
242 funname = SYMBOL_NAME (func);
243 funlang = SYMBOL_LANGUAGE (func);
248 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
251 funname = SYMBOL_NAME (msymbol);
252 funlang = SYMBOL_LANGUAGE (msymbol);
256 if (source >= 0 || !sal.symtab)
259 printf_filtered ("#%-2d ", level);
261 if (fi->pc != sal.pc || !sal.symtab)
262 printf_filtered ("%s in ", local_hex_string(fi->pc));
263 fprintf_symbol_filtered (stdout, funname ? funname : "??", funlang,
266 fputs_filtered (" (", stdout);
269 struct print_args_args args;
272 catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR);
274 printf_filtered (")");
275 if (sal.symtab && sal.symtab->filename)
278 printf_filtered (" at %s:%d", sal.symtab->filename, sal.line);
281 #ifdef PC_LOAD_SEGMENT
282 /* If we couldn't print out function name but if can figure out what
283 load segment this pc value is from, at least print out some info
284 about its load segment. */
287 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
290 printf_filtered ("\n");
293 if ((source != 0) && sal.symtab)
296 int mid_statement = source < 0 && fi->pc != sal.pc;
297 if (frame_file_full_name)
298 done = identify_source_line (sal.symtab, sal.line, mid_statement,
302 if (addressprint && mid_statement)
303 printf_filtered ("%s\t", local_hex_string(fi->pc));
304 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
306 current_source_line = max (sal.line - lines_to_list/2, 1);
309 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
315 * Read a frame specification in whatever the appropriate format is.
316 * Call error() if the specification is in any way invalid (i.e.
317 * this function never returns NULL).
320 parse_frame_specification (frame_exp)
324 int arg1, arg2, arg3;
330 char *addr_string, *p;
331 struct cleanup *tmp_cleanup;
333 while (*frame_exp == ' ') frame_exp++;
337 if (numargs > MAXARGS)
338 error ("Too many args in frame specification");
339 /* Parse an argument. */
340 for (p = frame_exp; *p && *p != ' '; p++)
342 addr_string = savestring(frame_exp, p - frame_exp);
345 tmp_cleanup = make_cleanup (free, addr_string);
346 args[numargs++] = parse_and_eval_address (addr_string);
347 do_cleanups (tmp_cleanup);
350 /* Skip spaces, move to possible next arg. */
351 while (*p == ' ') p++;
359 if (selected_frame == NULL)
360 error ("No selected frame.");
361 return selected_frame;
366 FRAME fid = find_relative_frame (get_current_frame (), &level);
370 /* find_relative_frame was successful */
373 /* If (s)he specifies the frame with an address, he deserves what
374 (s)he gets. Still, give the highest one that matches. */
376 for (fid = get_current_frame ();
377 fid && FRAME_FP (fid) != args[0];
378 fid = get_prev_frame (fid))
382 while ((tfid = get_prev_frame (fid)) &&
383 (FRAME_FP (tfid) == args[0]))
386 /* We couldn't identify the frame as an existing frame, but
387 perhaps we can create one with a single argument.
388 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
389 to complain if it doesn't like a single arg. */
393 #ifdef SETUP_ARBITRARY_FRAME
394 return SETUP_ARBITRARY_FRAME (numargs, args);
396 /* Usual case. Do it here rather than have everyone supply
397 a SETUP_ARBITRARY_FRAME that does this. */
399 return create_new_frame (args[0], 0);
400 error ("Too many args in frame specification");
407 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
408 that if it is unsure about the answer, it returns 0
409 instead of guessing (this happens on the VAX and i960, for example).
411 On most machines, we never have to guess about the args address,
412 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
413 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
414 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
417 /* Print verbosely the selected frame or the frame at address ADDR.
418 This means absolutely all information in the frame is printed. */
421 frame_info (addr_exp, from_tty)
426 struct frame_info *fi;
427 struct frame_saved_regs fsr;
428 struct symtab_and_line sal;
434 enum language funlang = language_unknown;
436 if (!target_has_stack)
439 frame = parse_frame_specification (addr_exp);
441 error ("Invalid frame specified.");
443 fi = get_frame_info (frame);
444 sal = find_pc_line (fi->pc,
445 fi->next != NULL && fi->next->signal_handler_caller == 0);
446 func = get_frame_function (frame);
447 s = find_pc_symtab(fi->pc);
450 funname = SYMBOL_NAME (func);
451 funlang = SYMBOL_LANGUAGE (func);
455 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
458 funname = SYMBOL_NAME (msymbol);
459 funlang = SYMBOL_LANGUAGE (msymbol);
462 calling_frame = get_prev_frame (frame);
464 if (!addr_exp && selected_frame_level >= 0) {
465 printf_filtered ("Stack level %d, frame at %s:\n",
466 selected_frame_level,
467 local_hex_string(FRAME_FP(frame)));
469 printf_filtered ("Stack frame at %s:\n",
470 local_hex_string(FRAME_FP(frame)));
472 printf_filtered (" %s = %s",
473 reg_names[PC_REGNUM],
474 local_hex_string(fi->pc));
479 printf_filtered (" in ");
480 fprintf_symbol_filtered (stdout, funname, funlang,
481 DMGL_ANSI | DMGL_PARAMS);
485 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
486 puts_filtered ("; ");
488 printf_filtered ("saved %s %s\n", reg_names[PC_REGNUM],
489 local_hex_string(FRAME_SAVED_PC (frame)));
493 #ifdef FRAMELESS_FUNCTION_INVOCATION
494 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
497 printf_filtered (" (FRAMELESS),");
501 printf_filtered (" called by frame at %s",
502 local_hex_string(FRAME_FP (calling_frame)));
503 if (fi->next && calling_frame)
507 printf_filtered (" caller of frame at %s",
508 local_hex_string (fi->next->frame));
509 if (fi->next || calling_frame)
510 puts_filtered ("\n");
512 printf_filtered(" source language %s.\n", language_str(s->language));
514 #ifdef PRINT_EXTRA_FRAME_INFO
515 PRINT_EXTRA_FRAME_INFO (fi);
519 /* Address of the argument list for this frame, or 0. */
520 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
521 /* Number of args for this frame, or -1 if unknown. */
525 printf_filtered (" Arglist at unknown address.\n");
528 printf_filtered (" Arglist at %s,", local_hex_string(arg_list));
530 FRAME_NUM_ARGS (numargs, fi);
532 puts_filtered (" args: ");
533 else if (numargs == 0)
534 puts_filtered (" no args.");
535 else if (numargs == 1)
536 puts_filtered (" 1 arg: ");
538 printf_filtered (" %d args: ", numargs);
539 print_frame_args (func, fi, numargs, stdout);
540 puts_filtered ("\n");
544 /* Address of the local variables for this frame, or 0. */
545 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
548 printf_filtered (" Locals at unknown address,");
550 printf_filtered (" Locals at %s,", local_hex_string(arg_list));
553 #if defined (FRAME_FIND_SAVED_REGS)
554 get_frame_saved_regs (fi, &fsr);
555 /* The sp is special; what's returned isn't the save address, but
556 actually the value of the previous frame's sp. */
557 printf_filtered (" Previous frame's sp is %s\n",
558 local_hex_string(fsr.regs[SP_REGNUM]));
560 for (i = 0; i < NUM_REGS; i++)
561 if (fsr.regs[i] && i != SP_REGNUM)
564 puts_filtered (" Saved registers:\n ");
568 printf_filtered (" %s at %s", reg_names[i],
569 local_hex_string(fsr.regs[i]));
573 puts_filtered ("\n");
574 #endif /* Have FRAME_FIND_SAVED_REGS. */
578 /* Set a limit on the number of frames printed by default in a
581 static int backtrace_limit;
584 set_backtrace_limit_command (count_exp, from_tty)
588 int count = parse_and_eval_address (count_exp);
591 error ("Negative argument not meaningful as backtrace limit.");
593 backtrace_limit = count;
597 backtrace_limit_info (arg, from_tty)
602 error ("\"Info backtrace-limit\" takes no arguments.");
604 printf ("Backtrace limit: %d.\n", backtrace_limit);
608 /* Print briefly all stack frames or just the innermost COUNT frames. */
611 backtrace_command (count_exp, from_tty)
615 struct frame_info *fi;
617 register FRAME frame;
619 register FRAME trailing;
620 register int trailing_level;
622 if (!target_has_stack)
625 /* The following code must do two things. First, it must
626 set the variable TRAILING to the frame from which we should start
627 printing. Second, it must set the variable count to the number
628 of frames which we should print, or -1 if all of them. */
629 trailing = get_current_frame ();
633 count = parse_and_eval_address (count_exp);
641 while (current && count--)
644 current = get_prev_frame (current);
647 /* Will stop when CURRENT reaches the top of the stack. TRAILING
648 will be COUNT below it. */
652 trailing = get_prev_frame (trailing);
653 current = get_prev_frame (current);
665 struct partial_symtab *ps;
667 /* Read in symbols for all of the frames. Need to do this in
668 a separate pass so that "Reading in symbols for xxx" messages
669 don't screw up the appearance of the backtrace. Also
670 if people have strong opinions against reading symbols for
671 backtrace this may have to be an option. */
673 for (frame = trailing;
674 frame != NULL && i--;
675 frame = get_prev_frame (frame))
678 fi = get_frame_info (frame);
679 ps = find_pc_psymtab (fi->pc);
681 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
685 for (i = 0, frame = trailing;
687 i++, frame = get_prev_frame (frame))
690 fi = get_frame_info (frame);
691 print_frame_info (fi, trailing_level + i, 0, 1);
694 /* If we've stopped before the end, mention that. */
695 if (frame && from_tty)
696 printf_filtered ("(More stack frames follow...)\n");
699 /* Print the local variables of a block B active in FRAME.
700 Return 1 if any variables were printed; 0 otherwise. */
703 print_block_frame_locals (b, frame, stream)
705 register FRAME frame;
706 register FILE *stream;
710 register struct symbol *sym;
711 register int values_printed = 0;
713 nsyms = BLOCK_NSYMS (b);
715 for (i = 0; i < nsyms; i++)
717 sym = BLOCK_SYM (b, i);
718 if (SYMBOL_CLASS (sym) == LOC_LOCAL
719 || SYMBOL_CLASS (sym) == LOC_REGISTER
720 || SYMBOL_CLASS (sym) == LOC_STATIC)
723 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
724 fputs_filtered (" = ", stream);
725 print_variable_value (sym, frame, stream);
726 fprintf_filtered (stream, "\n");
729 return values_printed;
732 /* Same, but print labels. */
735 print_block_frame_labels (b, have_default, stream)
738 register FILE *stream;
742 register struct symbol *sym;
743 register int values_printed = 0;
745 nsyms = BLOCK_NSYMS (b);
747 for (i = 0; i < nsyms; i++)
749 sym = BLOCK_SYM (b, i);
750 if (STREQ (SYMBOL_NAME (sym), "default"))
756 if (SYMBOL_CLASS (sym) == LOC_LABEL)
758 struct symtab_and_line sal;
759 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
761 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
763 fprintf_filtered (stream, " %s",
764 local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
765 fprintf_filtered (stream, " in file %s, line %d\n",
766 sal.symtab->filename, sal.line);
769 return values_printed;
772 /* Print on STREAM all the local variables in frame FRAME,
773 including all the blocks active in that frame
776 Returns 1 if the job was done,
777 or 0 if nothing was printed because we have no info
778 on the function running in FRAME. */
781 print_frame_local_vars (frame, stream)
782 register FRAME frame;
783 register FILE *stream;
785 register struct block *block = get_frame_block (frame);
786 register int values_printed = 0;
790 fprintf_filtered (stream, "No symbol table info available.\n");
796 if (print_block_frame_locals (block, frame, stream))
798 /* After handling the function's top-level block, stop.
799 Don't continue to its superblock, the block of
801 if (BLOCK_FUNCTION (block))
803 block = BLOCK_SUPERBLOCK (block);
808 fprintf_filtered (stream, "No locals.\n");
812 /* Same, but print labels. */
815 print_frame_label_vars (frame, this_level_only, stream)
816 register FRAME frame;
818 register FILE *stream;
820 register struct blockvector *bl;
821 register struct block *block = get_frame_block (frame);
822 register int values_printed = 0;
823 int index, have_default = 0;
824 char *blocks_printed;
825 struct frame_info *fi = get_frame_info (frame);
826 CORE_ADDR pc = fi->pc;
830 fprintf_filtered (stream, "No symbol table info available.\n");
834 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
835 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
836 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
840 CORE_ADDR end = BLOCK_END (block) - 4;
843 if (bl != blockvector_for_pc (end, &index))
844 error ("blockvector blotch");
845 if (BLOCKVECTOR_BLOCK (bl, index) != block)
846 error ("blockvector botch");
847 last_index = BLOCKVECTOR_NBLOCKS (bl);
850 /* Don't print out blocks that have gone by. */
851 while (index < last_index
852 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
855 while (index < last_index
856 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
858 if (blocks_printed[index] == 0)
860 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
862 blocks_printed[index] = 1;
868 if (values_printed && this_level_only)
871 /* After handling the function's top-level block, stop.
872 Don't continue to its superblock, the block of
874 if (BLOCK_FUNCTION (block))
876 block = BLOCK_SUPERBLOCK (block);
879 if (!values_printed && !this_level_only)
881 fprintf_filtered (stream, "No catches.\n");
887 locals_info (args, from_tty)
892 error ("No frame selected.");
893 print_frame_local_vars (selected_frame, stdout);
897 catch_info (ignore, from_tty)
902 error ("No frame selected.");
903 print_frame_label_vars (selected_frame, 0, stdout);
907 print_frame_arg_vars (frame, stream)
908 register FRAME frame;
909 register FILE *stream;
911 struct symbol *func = get_frame_function (frame);
912 register struct block *b;
915 register struct symbol *sym, *sym2;
916 register int values_printed = 0;
920 fprintf_filtered (stream, "No symbol table info available.\n");
924 b = SYMBOL_BLOCK_VALUE (func);
925 nsyms = BLOCK_NSYMS (b);
927 for (i = 0; i < nsyms; i++)
929 sym = BLOCK_SYM (b, i);
930 if (SYMBOL_CLASS (sym) == LOC_ARG
931 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
932 || SYMBOL_CLASS (sym) == LOC_REF_ARG
933 || SYMBOL_CLASS (sym) == LOC_REGPARM
934 || SYMBOL_CLASS (sym) == LOC_REGPARM_ADDR)
937 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
938 fputs_filtered (" = ", stream);
940 /* We have to look up the symbol because arguments can have
941 two entries (one a parameter, one a local) and the one we
942 want is the local, which lookup_symbol will find for us.
943 This includes gcc1 (not gcc2) on the sparc when passing a
944 small structure and gcc2 when the argument type is float
945 and it is passed as a double and converted to float by
946 the prologue (in the latter case the type of the LOC_ARG
947 symbol is double and the type of the LOC_LOCAL symbol is
948 float). There are also LOC_ARG/LOC_REGISTER pairs which
949 are not combined in symbol-reading. */
951 sym2 = lookup_symbol (SYMBOL_NAME (sym),
952 b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
953 print_variable_value (sym2, frame, stream);
954 fprintf_filtered (stream, "\n");
960 fprintf_filtered (stream, "No arguments.\n");
965 args_info (ignore, from_tty)
970 error ("No frame selected.");
971 print_frame_arg_vars (selected_frame, stdout);
974 /* Select frame FRAME, and note that its stack level is LEVEL.
975 LEVEL may be -1 if an actual level number is not known. */
978 select_frame (frame, level)
982 register struct symtab *s;
984 selected_frame = frame;
985 selected_frame_level = level;
987 /* Ensure that symbols for this frame are read in. Also, determine the
988 source language of this frame, and switch to it if desired. */
991 s = find_pc_symtab (get_frame_info (frame)->pc);
993 && s->language != current_language->la_language
994 && s->language != language_unknown
995 && language_mode == language_mode_auto) {
996 set_language(s->language);
1001 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
1002 If there is no selected frame, *FRAMEP is set to NULL. */
1005 record_selected_frame (frameaddrp, levelp)
1006 FRAME_ADDR *frameaddrp;
1009 *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
1010 *levelp = selected_frame_level;
1013 /* Return the symbol-block in which the selected frame is executing.
1014 Can return zero under various legitimate circumstances. */
1017 get_selected_block ()
1019 if (!target_has_stack)
1022 if (!selected_frame)
1023 return get_current_block ();
1024 return get_frame_block (selected_frame);
1027 /* Find a frame a certain number of levels away from FRAME.
1028 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1029 Positive means go to earlier frames (up); negative, the reverse.
1030 The int that contains the number of levels is counted toward
1031 zero as the frames for those levels are found.
1032 If the top or bottom frame is reached, that frame is returned,
1033 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1034 how much farther the original request asked to go. */
1037 find_relative_frame (frame, level_offset_ptr)
1038 register FRAME frame;
1039 register int* level_offset_ptr;
1041 register FRAME prev;
1042 register FRAME frame1;
1044 /* Going up is simple: just do get_prev_frame enough times
1045 or until initial frame is reached. */
1046 while (*level_offset_ptr > 0)
1048 prev = get_prev_frame (frame);
1051 (*level_offset_ptr)--;
1054 /* Going down is just as simple. */
1055 if (*level_offset_ptr < 0)
1057 while (*level_offset_ptr < 0) {
1058 frame1 = get_next_frame (frame);
1062 (*level_offset_ptr)++;
1068 /* The "select_frame" command. With no arg, NOP.
1069 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1070 valid level. Otherwise, treat level_exp as an address expression
1071 and select it. See parse_frame_specification for more info on proper
1072 frame expressions. */
1076 select_frame_command (level_exp, from_tty)
1080 register FRAME frame, frame1;
1081 unsigned int level = 0;
1083 if (!target_has_stack)
1084 error ("No stack.");
1086 frame = parse_frame_specification (level_exp);
1088 /* Try to figure out what level this frame is. But if there is
1089 no current stack, don't error out -- let the user set one. */
1091 if (get_current_frame()) {
1092 for (frame1 = get_prev_frame (0);
1093 frame1 && frame1 != frame;
1094 frame1 = get_prev_frame (frame1))
1101 select_frame (frame, level);
1104 /* The "frame" command. With no arg, print selected frame briefly.
1105 With arg, behaves like select_frame and then prints the selected
1109 frame_command (level_exp, from_tty)
1113 select_frame_command (level_exp, from_tty);
1114 print_stack_frame (selected_frame, selected_frame_level, 1);
1117 /* Select the frame up one or COUNT stack levels
1118 from the previously selected frame, and print it briefly. */
1122 up_silently_command (count_exp, from_tty)
1126 register FRAME frame;
1127 int count = 1, count1;
1129 count = parse_and_eval_address (count_exp);
1132 if (target_has_stack == 0 || selected_frame == 0)
1133 error ("No stack.");
1135 frame = find_relative_frame (selected_frame, &count1);
1136 if (count1 != 0 && count_exp == 0)
1137 error ("Initial frame selected; you cannot go up.");
1138 select_frame (frame, selected_frame_level + count - count1);
1142 up_command (count_exp, from_tty)
1146 up_silently_command (count_exp, from_tty);
1147 print_stack_frame (selected_frame, selected_frame_level, 1);
1150 /* Select the frame down one or COUNT stack levels
1151 from the previously selected frame, and print it briefly. */
1155 down_silently_command (count_exp, from_tty)
1159 register FRAME frame;
1160 int count = -1, count1;
1162 count = - parse_and_eval_address (count_exp);
1165 if (target_has_stack == 0 || selected_frame == 0)
1166 error ("No stack.");
1168 frame = find_relative_frame (selected_frame, &count1);
1169 if (count1 != 0 && count_exp == 0)
1170 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1171 select_frame (frame, selected_frame_level + count - count1);
1176 down_command (count_exp, from_tty)
1180 down_silently_command (count_exp, from_tty);
1181 print_stack_frame (selected_frame, selected_frame_level, 1);
1185 return_command (retval_exp, from_tty)
1189 struct symbol *thisfun;
1190 FRAME_ADDR selected_frame_addr;
1191 CORE_ADDR selected_frame_pc;
1195 if (selected_frame == NULL)
1196 error ("No selected frame.");
1197 thisfun = get_frame_function (selected_frame);
1198 selected_frame_addr = FRAME_FP (selected_frame);
1199 selected_frame_pc = (get_frame_info (selected_frame))->pc;
1201 /* Compute the return value (if any -- possibly getting errors here).
1202 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1203 it might live in the stack frame we're about to pop. */
1207 return_value = parse_and_eval (retval_exp);
1208 VALUE_CONTENTS (return_value);
1211 /* If interactive, require confirmation. */
1217 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
1219 error ("Not confirmed.");
1224 if (!query ("Make selected stack frame return now? "))
1225 error ("Not confirmed.");
1228 /* Do the real work. Pop until the specified frame is current. We
1229 use this method because the selected_frame is not valid after
1230 a POP_FRAME. The pc comparison makes this work even if the
1231 selected frame shares its fp with another frame. */
1233 while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
1234 || selected_frame_pc != (get_frame_info (frame))->pc )
1237 /* Then pop that frame. */
1241 /* Compute the return value (if any) and store in the place
1242 for return values. */
1245 set_return_value (return_value);
1247 /* If interactive, print the frame that is now current. */
1250 frame_command ("0", 1);
1253 /* Gets the language of the current frame. */
1255 get_frame_language()
1257 register struct symtab *s;
1259 enum language flang; /* The language of the current frame */
1261 fr = get_frame_info(selected_frame);
1264 s = find_pc_symtab(fr->pc);
1266 flang = s->language;
1268 flang = language_unknown;
1271 flang = language_unknown;
1277 _initialize_stack ()
1280 backtrace_limit = 30;
1283 add_com ("return", class_stack, return_command,
1284 "Make selected stack frame return to its caller.\n\
1285 Control remains in the debugger, but when you continue\n\
1286 execution will resume in the frame above the one now selected.\n\
1287 If an argument is given, it is an expression for the value to return.");
1289 add_com ("up", class_stack, up_command,
1290 "Select and print stack frame that called this one.\n\
1291 An argument says how many frames up to go.");
1292 add_com ("up-silently", class_support, up_silently_command,
1293 "Same as the `up' command, but does not print anything.\n\
1294 This is useful in command scripts.");
1296 add_com ("down", class_stack, down_command,
1297 "Select and print stack frame called by this one.\n\
1298 An argument says how many frames down to go.");
1299 add_com_alias ("do", "down", class_stack, 1);
1300 add_com_alias ("dow", "down", class_stack, 1);
1301 add_com ("down-silently", class_support, down_silently_command,
1302 "Same as the `down' command, but does not print anything.\n\
1303 This is useful in command scripts.");
1305 add_com ("frame", class_stack, frame_command,
1306 "Select and print a stack frame.\n\
1307 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1308 An argument specifies the frame to select.\n\
1309 It can be a stack frame number or the address of the frame.\n\
1310 With argument, nothing is printed if input is coming from\n\
1311 a command file or a user-defined command.");
1313 add_com_alias ("f", "frame", class_stack, 1);
1315 add_com ("select-frame", class_stack, select_frame_command,
1316 "Select a stack frame without printing anything.\n\
1317 An argument specifies the frame to select.\n\
1318 It can be a stack frame number or the address of the frame.\n");
1320 add_com ("backtrace", class_stack, backtrace_command,
1321 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1322 With a negative argument, print outermost -COUNT frames.");
1323 add_com_alias ("bt", "backtrace", class_stack, 0);
1324 add_com_alias ("where", "backtrace", class_alias, 0);
1325 add_info ("stack", backtrace_command,
1326 "Backtrace of the stack, or innermost COUNT frames.");
1327 add_info_alias ("s", "stack", 1);
1328 add_info ("frame", frame_info,
1329 "All about selected stack frame, or frame at ADDR.");
1330 add_info_alias ("f", "frame", 1);
1331 add_info ("locals", locals_info,
1332 "Local variables of current stack frame.");
1333 add_info ("args", args_info,
1334 "Argument variables of current stack frame.");
1335 add_info ("catch", catch_info,
1336 "Exceptions that can be caught in the current stack frame.");
1339 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
1340 "Specify maximum number of frames for \"backtrace\" to print by default.",
1342 add_info ("backtrace-limit", backtrace_limit_info,
1343 "The maximum number of frames for \"backtrace\" to print by default.");