1 /* Print and select stack frames for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "expression.h"
30 #include "breakpoint.h"
34 return_command
PARAMS ((char *, int));
37 down_command
PARAMS ((char *, int));
40 down_silently_command
PARAMS ((char *, int));
43 up_command
PARAMS ((char *, int));
46 up_silently_command
PARAMS ((char *, int));
49 frame_command
PARAMS ((char *, int));
52 select_frame_command
PARAMS ((char *, int));
55 args_info
PARAMS ((char *, int));
58 print_frame_arg_vars
PARAMS ((FRAME
, FILE *));
61 catch_info
PARAMS ((char *, int));
64 locals_info
PARAMS ((char *, int));
67 print_frame_label_vars
PARAMS ((FRAME
, int, FILE *));
70 print_frame_local_vars
PARAMS ((FRAME
, FILE *));
73 print_block_frame_labels
PARAMS ((struct block
*, int *, FILE *));
76 print_block_frame_locals
PARAMS ((struct block
*, FRAME
, FILE *));
79 backtrace_command
PARAMS ((char *, int));
82 parse_frame_specification
PARAMS ((char *));
85 frame_info
PARAMS ((char *, int));
88 extern int addressprint
; /* Print addresses, or stay symbolic only? */
89 extern int info_verbose
; /* Verbosity of symbol reading msgs */
90 extern int lines_to_list
; /* # of lines "list" command shows by default */
92 /* The "selected" stack frame is used by default for local and arg access.
93 May be zero, for no selected frame. */
97 /* Level of the selected frame:
98 0 for innermost, 1 for its caller, ...
99 or -1 for frame specified by address with no defined level. */
101 int selected_frame_level
;
103 /* Nonzero means print the full filename and linenumber
104 when a frame is printed, and do so in a format programs can parse. */
106 int frame_file_full_name
= 0;
109 /* Print a stack frame briefly. FRAME should be the frame id
110 and LEVEL should be its level in the stack (or -1 for level not defined).
111 This prints the level, the function executing, the arguments,
112 and the file name and line number.
113 If the pc is not at the beginning of the source line,
114 the actual pc is printed at the beginning.
116 If SOURCE is 1, print the source line as well.
117 If SOURCE is -1, print ONLY the source line. */
120 print_stack_frame (frame
, level
, source
)
125 struct frame_info
*fi
;
127 fi
= get_frame_info (frame
);
129 print_frame_info (fi
, level
, source
, 1);
133 print_frame_info (fi
, level
, source
, args
)
134 struct frame_info
*fi
;
139 struct symtab_and_line sal
;
141 register char *funname
= 0;
142 enum language funlang
= language_unknown
;
145 #ifdef CORE_NEEDS_RELOCATION
146 CORE_NEEDS_RELOCATION(fi
->pc
);
149 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
150 func
= find_pc_function (fi
->pc
);
153 /* In certain pathological cases, the symtabs give the wrong
154 function (when we are in the first function in a file which
155 is compiled without debugging symbols, the previous function
156 is compiled with debugging symbols, and the "foo.o" symbol
157 that is supposed to tell us where the file with debugging symbols
158 ends has been truncated by ar because it is longer than 15
161 So look in the minimal symbol tables as well, and if it comes
162 up with a larger address for the function use that instead.
163 I don't think this can ever cause any problems; there shouldn't
164 be any minimal symbols in the middle of a function.
165 FIXME: (Not necessarily true. What about text labels) */
167 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
169 && (SYMBOL_VALUE_ADDRESS (msymbol
)
170 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
172 /* In this case we have no way of knowing the source file
173 and line number, so don't print them. */
175 /* We also don't know anything about the function besides
176 its address and name. */
178 funname
= SYMBOL_NAME (msymbol
);
179 funlang
= SYMBOL_LANGUAGE (msymbol
);
183 funname
= SYMBOL_NAME (func
);
184 funlang
= SYMBOL_LANGUAGE (func
);
189 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
192 funname
= SYMBOL_NAME (msymbol
);
193 funlang
= SYMBOL_LANGUAGE (msymbol
);
197 if (source
>= 0 || !sal
.symtab
)
200 printf_filtered ("#%-2d ", level
);
202 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
)
203 printf_filtered ("%s in ", local_hex_string(fi
->pc
));
204 fputs_demangled (funname
? funname
: "??", stdout
, 0, funlang
);
206 fputs_filtered (" (", stdout
);
209 FRAME_NUM_ARGS (numargs
, fi
);
210 print_frame_args (func
, fi
, numargs
, stdout
);
212 printf_filtered (")");
213 if (sal
.symtab
&& sal
.symtab
->filename
)
216 printf_filtered (" at %s:%d", sal
.symtab
->filename
, sal
.line
);
219 #ifdef PC_LOAD_SEGMENT
220 /* If we couldn't print out function name but if can figure out what
221 load segment this pc value is from, at least print out some info
222 about its load segment. */
225 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi
->pc
));
228 printf_filtered ("\n");
231 if ((source
!= 0) && sal
.symtab
)
234 int mid_statement
= source
< 0 && fi
->pc
!= sal
.pc
;
235 if (frame_file_full_name
)
236 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
);
239 if (addressprint
&& mid_statement
)
240 printf_filtered ("%s\t", local_hex_string(fi
->pc
));
241 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
243 current_source_line
= max (sal
.line
- lines_to_list
/2, 1);
246 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
252 * Read a frame specification in whatever the appropriate format is.
253 * Call error() if the specification is in any way invalid (i.e.
254 * this function never returns NULL).
257 parse_frame_specification (frame_exp
)
261 int arg1
, arg2
, arg3
;
267 char *addr_string
, *p
;
268 struct cleanup
*tmp_cleanup
;
270 while (*frame_exp
== ' ') frame_exp
++;
274 if (numargs
> MAXARGS
)
275 error ("Too many args in frame specification");
276 /* Parse an argument. */
277 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
279 addr_string
= savestring(frame_exp
, p
- frame_exp
);
282 tmp_cleanup
= make_cleanup (free
, addr_string
);
283 args
[numargs
++] = parse_and_eval_address (addr_string
);
284 do_cleanups (tmp_cleanup
);
287 /* Skip spaces, move to possible next arg. */
288 while (*p
== ' ') p
++;
296 if (selected_frame
== NULL
)
297 error ("No selected frame.");
298 return selected_frame
;
303 FRAME fid
= find_relative_frame (get_current_frame (), &level
);
307 /* find_relative_frame was successful */
310 /* If (s)he specifies the frame with an address, he deserves what
311 (s)he gets. Still, give the highest one that matches. */
313 for (fid
= get_current_frame ();
314 fid
&& FRAME_FP (fid
) != args
[0];
315 fid
= get_prev_frame (fid
))
319 while ((tfid
= get_prev_frame (fid
)) &&
320 (FRAME_FP (tfid
) == args
[0]))
323 /* We couldn't identify the frame as an existing frame, but
324 perhaps we can create one with a single argument.
325 Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
326 to complain if it doesn't like a single arg. */
330 #ifdef SETUP_ARBITRARY_FRAME
331 return SETUP_ARBITRARY_FRAME (numargs
, args
);
333 /* Usual case. Do it here rather than have everyone supply
334 a SETUP_ARBITRARY_FRAME that does this. */
336 return create_new_frame (args
[0], 0);
337 error ("Too many args in frame specification");
344 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
345 that if it is unsure about the answer, it returns 0
346 instead of guessing (this happens on the VAX and i960, for example).
348 On most machines, we never have to guess about the args address,
349 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
350 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
351 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
354 /* Print verbosely the selected frame or the frame at address ADDR.
355 This means absolutely all information in the frame is printed. */
358 frame_info (addr_exp
, from_tty
)
363 struct frame_info
*fi
;
364 struct frame_saved_regs fsr
;
365 struct symtab_and_line sal
;
371 enum language funlang
= language_unknown
;
373 if (!target_has_stack
)
374 error ("No inferior or core file.");
376 frame
= parse_frame_specification (addr_exp
);
378 error ("Invalid frame specified.");
380 fi
= get_frame_info (frame
);
381 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
382 func
= get_frame_function (frame
);
383 s
= find_pc_symtab(fi
->pc
);
386 funname
= SYMBOL_NAME (func
);
387 funlang
= SYMBOL_LANGUAGE (func
);
391 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
394 funname
= SYMBOL_NAME (msymbol
);
395 funlang
= SYMBOL_LANGUAGE (msymbol
);
398 calling_frame
= get_prev_frame (frame
);
400 if (!addr_exp
&& selected_frame_level
>= 0) {
401 printf_filtered ("Stack level %d, frame at %s:\n",
402 selected_frame_level
,
403 local_hex_string(FRAME_FP(frame
)));
405 printf_filtered ("Stack frame at %s:\n",
406 local_hex_string(FRAME_FP(frame
)));
408 printf_filtered (" %s = %s",
409 reg_names
[PC_REGNUM
],
410 local_hex_string(fi
->pc
));
415 printf_filtered (" in ");
416 fputs_demangled (funname
, stdout
, DMGL_ANSI
| DMGL_PARAMS
, funlang
);
420 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
421 puts_filtered ("; ");
423 printf_filtered ("saved %s %s\n", reg_names
[PC_REGNUM
],
424 local_hex_string(FRAME_SAVED_PC (frame
)));
428 #ifdef FRAMELESS_FUNCTION_INVOCATION
429 FRAMELESS_FUNCTION_INVOCATION (fi
, frameless
);
432 printf_filtered (" (FRAMELESS),");
436 printf_filtered (" called by frame at %s",
437 local_hex_string(FRAME_FP (calling_frame
)));
438 if (fi
->next_frame
&& calling_frame
)
442 printf_filtered (" caller of frame at %s", local_hex_string(fi
->next_frame
));
443 if (fi
->next_frame
|| calling_frame
)
444 puts_filtered ("\n");
446 printf_filtered(" source language %s.\n", language_str(s
->language
));
448 #ifdef PRINT_EXTRA_FRAME_INFO
449 PRINT_EXTRA_FRAME_INFO (fi
);
453 /* Address of the argument list for this frame, or 0. */
454 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
455 /* Number of args for this frame, or -1 if unknown. */
459 printf_filtered (" Arglist at unknown address.\n");
462 printf_filtered (" Arglist at %s,", local_hex_string(arg_list
));
464 FRAME_NUM_ARGS (numargs
, fi
);
466 puts_filtered (" args: ");
467 else if (numargs
== 0)
468 puts_filtered (" no args.");
469 else if (numargs
== 1)
470 puts_filtered (" 1 arg: ");
472 printf_filtered (" %d args: ", numargs
);
473 print_frame_args (func
, fi
, numargs
, stdout
);
474 puts_filtered ("\n");
478 /* Address of the local variables for this frame, or 0. */
479 CORE_ADDR arg_list
= FRAME_LOCALS_ADDRESS (fi
);
482 printf_filtered (" Locals at unknown address,");
484 printf_filtered (" Locals at %s,", local_hex_string(arg_list
));
487 #if defined (FRAME_FIND_SAVED_REGS)
488 get_frame_saved_regs (fi
, &fsr
);
489 /* The sp is special; what's returned isn't the save address, but
490 actually the value of the previous frame's sp. */
491 printf_filtered (" Previous frame's sp is %s\n",
492 local_hex_string(fsr
.regs
[SP_REGNUM
]));
494 for (i
= 0; i
< NUM_REGS
; i
++)
495 if (fsr
.regs
[i
] && i
!= SP_REGNUM
)
498 puts_filtered (" Saved registers:\n ");
502 printf_filtered (" %s at %s", reg_names
[i
],
503 local_hex_string(fsr
.regs
[i
]));
507 puts_filtered ("\n");
508 #endif /* Have FRAME_FIND_SAVED_REGS. */
512 /* Set a limit on the number of frames printed by default in a
515 static int backtrace_limit
;
518 set_backtrace_limit_command (count_exp
, from_tty
)
522 int count
= parse_and_eval_address (count_exp
);
525 error ("Negative argument not meaningful as backtrace limit.");
527 backtrace_limit
= count
;
531 backtrace_limit_info (arg
, from_tty
)
536 error ("\"Info backtrace-limit\" takes no arguments.");
538 printf ("Backtrace limit: %d.\n", backtrace_limit
);
542 /* Print briefly all stack frames or just the innermost COUNT frames. */
545 backtrace_command (count_exp
, from_tty
)
549 struct frame_info
*fi
;
551 register FRAME frame
;
553 register FRAME trailing
;
554 register int trailing_level
;
556 if (!target_has_stack
)
559 /* The following code must do two things. First, it must
560 set the variable TRAILING to the frame from which we should start
561 printing. Second, it must set the variable count to the number
562 of frames which we should print, or -1 if all of them. */
563 trailing
= get_current_frame ();
567 count
= parse_and_eval_address (count_exp
);
575 while (current
&& count
--)
578 current
= get_prev_frame (current
);
581 /* Will stop when CURRENT reaches the top of the stack. TRAILING
582 will be COUNT below it. */
586 trailing
= get_prev_frame (trailing
);
587 current
= get_prev_frame (current
);
599 struct partial_symtab
*ps
;
601 /* Read in symbols for all of the frames. Need to do this in
602 a separate pass so that "Reading in symbols for xxx" messages
603 don't screw up the appearance of the backtrace. Also
604 if people have strong opinions against reading symbols for
605 backtrace this may have to be an option. */
607 for (frame
= trailing
;
608 frame
!= NULL
&& i
--;
609 frame
= get_prev_frame (frame
))
612 fi
= get_frame_info (frame
);
613 ps
= find_pc_psymtab (fi
->pc
);
615 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
619 for (i
= 0, frame
= trailing
;
621 i
++, frame
= get_prev_frame (frame
))
624 fi
= get_frame_info (frame
);
625 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
628 /* If we've stopped before the end, mention that. */
629 if (frame
&& from_tty
)
630 printf_filtered ("(More stack frames follow...)\n");
633 /* Print the local variables of a block B active in FRAME.
634 Return 1 if any variables were printed; 0 otherwise. */
637 print_block_frame_locals (b
, frame
, stream
)
639 register FRAME frame
;
640 register FILE *stream
;
644 register struct symbol
*sym
;
645 register int values_printed
= 0;
647 nsyms
= BLOCK_NSYMS (b
);
649 for (i
= 0; i
< nsyms
; i
++)
651 sym
= BLOCK_SYM (b
, i
);
652 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
653 || SYMBOL_CLASS (sym
) == LOC_REGISTER
654 || SYMBOL_CLASS (sym
) == LOC_STATIC
)
657 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
658 fputs_filtered (" = ", stream
);
659 print_variable_value (sym
, frame
, stream
);
660 fprintf_filtered (stream
, "\n");
663 return values_printed
;
666 /* Same, but print labels. */
669 print_block_frame_labels (b
, have_default
, stream
)
672 register FILE *stream
;
676 register struct symbol
*sym
;
677 register int values_printed
= 0;
679 nsyms
= BLOCK_NSYMS (b
);
681 for (i
= 0; i
< nsyms
; i
++)
683 sym
= BLOCK_SYM (b
, i
);
684 if (STREQ (SYMBOL_NAME (sym
), "default"))
690 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
692 struct symtab_and_line sal
;
693 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
695 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
697 fprintf_filtered (stream
, " %s",
698 local_hex_string(SYMBOL_VALUE_ADDRESS (sym
)));
699 fprintf_filtered (stream
, " in file %s, line %d\n",
700 sal
.symtab
->filename
, sal
.line
);
703 return values_printed
;
706 /* Print on STREAM all the local variables in frame FRAME,
707 including all the blocks active in that frame
710 Returns 1 if the job was done,
711 or 0 if nothing was printed because we have no info
712 on the function running in FRAME. */
715 print_frame_local_vars (frame
, stream
)
716 register FRAME frame
;
717 register FILE *stream
;
719 register struct block
*block
= get_frame_block (frame
);
720 register int values_printed
= 0;
724 fprintf_filtered (stream
, "No symbol table info available.\n");
730 if (print_block_frame_locals (block
, frame
, stream
))
732 /* After handling the function's top-level block, stop.
733 Don't continue to its superblock, the block of
735 if (BLOCK_FUNCTION (block
))
737 block
= BLOCK_SUPERBLOCK (block
);
742 fprintf_filtered (stream
, "No locals.\n");
746 /* Same, but print labels. */
749 print_frame_label_vars (frame
, this_level_only
, stream
)
750 register FRAME frame
;
752 register FILE *stream
;
754 register struct blockvector
*bl
;
755 register struct block
*block
= get_frame_block (frame
);
756 register int values_printed
= 0;
757 int index
, have_default
= 0;
758 char *blocks_printed
;
759 struct frame_info
*fi
= get_frame_info (frame
);
760 CORE_ADDR pc
= fi
->pc
;
764 fprintf_filtered (stream
, "No symbol table info available.\n");
768 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
769 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
770 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
774 CORE_ADDR end
= BLOCK_END (block
) - 4;
777 if (bl
!= blockvector_for_pc (end
, &index
))
778 error ("blockvector blotch");
779 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
780 error ("blockvector botch");
781 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
784 /* Don't print out blocks that have gone by. */
785 while (index
< last_index
786 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
789 while (index
< last_index
790 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
792 if (blocks_printed
[index
] == 0)
794 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
796 blocks_printed
[index
] = 1;
802 if (values_printed
&& this_level_only
)
805 /* After handling the function's top-level block, stop.
806 Don't continue to its superblock, the block of
808 if (BLOCK_FUNCTION (block
))
810 block
= BLOCK_SUPERBLOCK (block
);
813 if (!values_printed
&& !this_level_only
)
815 fprintf_filtered (stream
, "No catches.\n");
821 locals_info (args
, from_tty
)
826 error ("No frame selected.");
827 print_frame_local_vars (selected_frame
, stdout
);
831 catch_info (ignore
, from_tty
)
836 error ("No frame selected.");
837 print_frame_label_vars (selected_frame
, 0, stdout
);
841 print_frame_arg_vars (frame
, stream
)
842 register FRAME frame
;
843 register FILE *stream
;
845 struct symbol
*func
= get_frame_function (frame
);
846 register struct block
*b
;
849 register struct symbol
*sym
, *sym2
;
850 register int values_printed
= 0;
854 fprintf_filtered (stream
, "No symbol table info available.\n");
858 b
= SYMBOL_BLOCK_VALUE (func
);
859 nsyms
= BLOCK_NSYMS (b
);
861 for (i
= 0; i
< nsyms
; i
++)
863 sym
= BLOCK_SYM (b
, i
);
864 if (SYMBOL_CLASS (sym
) == LOC_ARG
865 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
866 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
867 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
870 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
871 fputs_filtered (" = ", stream
);
872 /* We have to look up the symbol because arguments often have
873 two entries (one a parameter, one a register) and the one
874 we want is the register, which lookup_symbol will find for
876 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
877 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
878 print_variable_value (sym2
, frame
, stream
);
879 fprintf_filtered (stream
, "\n");
885 fprintf_filtered (stream
, "No arguments.\n");
890 args_info (ignore
, from_tty
)
895 error ("No frame selected.");
896 print_frame_arg_vars (selected_frame
, stdout
);
899 /* Select frame FRAME, and note that its stack level is LEVEL.
900 LEVEL may be -1 if an actual level number is not known. */
903 select_frame (frame
, level
)
907 register struct symtab
*s
;
909 selected_frame
= frame
;
910 selected_frame_level
= level
;
912 /* Ensure that symbols for this frame are read in. Also, determine the
913 source language of this frame, and switch to it if desired. */
916 s
= find_pc_symtab (get_frame_info (frame
)->pc
);
918 && s
->language
!= current_language
->la_language
919 && s
->language
!= language_unknown
920 && language_mode
== language_mode_auto
) {
921 set_language(s
->language
);
926 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
927 If there is no selected frame, *FRAMEP is set to NULL. */
930 record_selected_frame (frameaddrp
, levelp
)
931 FRAME_ADDR
*frameaddrp
;
934 *frameaddrp
= selected_frame
? FRAME_FP (selected_frame
) : 0;
935 *levelp
= selected_frame_level
;
938 /* Return the symbol-block in which the selected frame is executing.
939 Can return zero under various legitimate circumstances. */
942 get_selected_block ()
944 if (!target_has_stack
)
948 return get_current_block ();
949 return get_frame_block (selected_frame
);
952 /* Find a frame a certain number of levels away from FRAME.
953 LEVEL_OFFSET_PTR points to an int containing the number of levels.
954 Positive means go to earlier frames (up); negative, the reverse.
955 The int that contains the number of levels is counted toward
956 zero as the frames for those levels are found.
957 If the top or bottom frame is reached, that frame is returned,
958 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
959 how much farther the original request asked to go. */
962 find_relative_frame (frame
, level_offset_ptr
)
963 register FRAME frame
;
964 register int* level_offset_ptr
;
967 register FRAME frame1
;
969 /* Going up is simple: just do get_prev_frame enough times
970 or until initial frame is reached. */
971 while (*level_offset_ptr
> 0)
973 prev
= get_prev_frame (frame
);
976 (*level_offset_ptr
)--;
979 /* Going down is just as simple. */
980 if (*level_offset_ptr
< 0)
982 while (*level_offset_ptr
< 0) {
983 frame1
= get_next_frame (frame
);
987 (*level_offset_ptr
)++;
993 /* The "select_frame" command. With no arg, NOP.
994 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
995 valid level. Otherwise, treat level_exp as an address expression
996 and select it. See parse_frame_specification for more info on proper
997 frame expressions. */
1001 select_frame_command (level_exp
, from_tty
)
1005 register FRAME frame
, frame1
;
1006 unsigned int level
= 0;
1008 if (!target_has_stack
)
1009 error ("No stack.");
1011 frame
= parse_frame_specification (level_exp
);
1013 /* Try to figure out what level this frame is. But if there is
1014 no current stack, don't error out -- let the user set one. */
1016 if (get_current_frame()) {
1017 for (frame1
= get_prev_frame (0);
1018 frame1
&& frame1
!= frame
;
1019 frame1
= get_prev_frame (frame1
))
1026 select_frame (frame
, level
);
1029 /* The "frame" command. With no arg, print selected frame briefly.
1030 With arg, behaves like select_frame and then prints the selected
1034 frame_command (level_exp
, from_tty
)
1038 select_frame_command (level_exp
, from_tty
);
1039 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1042 /* Select the frame up one or COUNT stack levels
1043 from the previously selected frame, and print it briefly. */
1047 up_silently_command (count_exp
, from_tty
)
1051 register FRAME frame
;
1052 int count
= 1, count1
;
1054 count
= parse_and_eval_address (count_exp
);
1057 if (target_has_stack
== 0 || selected_frame
== 0)
1058 error ("No stack.");
1060 frame
= find_relative_frame (selected_frame
, &count1
);
1061 if (count1
!= 0 && count_exp
== 0)
1062 error ("Initial frame selected; you cannot go up.");
1063 select_frame (frame
, selected_frame_level
+ count
- count1
);
1067 up_command (count_exp
, from_tty
)
1071 up_silently_command (count_exp
, from_tty
);
1072 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1075 /* Select the frame down one or COUNT stack levels
1076 from the previously selected frame, and print it briefly. */
1080 down_silently_command (count_exp
, from_tty
)
1084 register FRAME frame
;
1085 int count
= -1, count1
;
1087 count
= - parse_and_eval_address (count_exp
);
1090 if (target_has_stack
== 0 || selected_frame
== 0)
1091 error ("No stack.");
1093 frame
= find_relative_frame (selected_frame
, &count1
);
1094 if (count1
!= 0 && count_exp
== 0)
1095 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1096 select_frame (frame
, selected_frame_level
+ count
- count1
);
1101 down_command (count_exp
, from_tty
)
1105 down_silently_command (count_exp
, from_tty
);
1106 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1110 return_command (retval_exp
, from_tty
)
1114 struct symbol
*thisfun
;
1115 FRAME_ADDR selected_frame_addr
;
1116 CORE_ADDR selected_frame_pc
;
1120 if (selected_frame
== NULL
)
1121 error ("No selected frame.");
1122 thisfun
= get_frame_function (selected_frame
);
1123 selected_frame_addr
= FRAME_FP (selected_frame
);
1124 selected_frame_pc
= (get_frame_info (selected_frame
))->pc
;
1126 /* Compute the return value (if any -- possibly getting errors here).
1127 Call VALUE_CONTENTS to make sure we have fully evaluated it, since
1128 it might live in the stack frame we're about to pop. */
1132 return_value
= parse_and_eval (retval_exp
);
1133 VALUE_CONTENTS (return_value
);
1136 /* If interactive, require confirmation. */
1142 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun
)))
1144 error ("Not confirmed.");
1149 if (!query ("Make selected stack frame return now? "))
1150 error ("Not confirmed.");
1153 /* Do the real work. Pop until the specified frame is current. We
1154 use this method because the selected_frame is not valid after
1155 a POP_FRAME. The pc comparison makes this work even if the
1156 selected frame shares its fp with another frame. */
1158 while ( selected_frame_addr
!= FRAME_FP (frame
= get_current_frame())
1159 || selected_frame_pc
!= (get_frame_info (frame
))->pc
)
1162 /* Then pop that frame. */
1166 /* Compute the return value (if any) and store in the place
1167 for return values. */
1170 set_return_value (return_value
);
1172 /* If interactive, print the frame that is now current. */
1175 frame_command ("0", 1);
1178 /* Gets the language of the current frame. */
1180 get_frame_language()
1182 register struct symtab
*s
;
1184 enum language flang
; /* The language of the current frame */
1186 fr
= get_frame_info(selected_frame
);
1189 s
= find_pc_symtab(fr
->pc
);
1191 flang
= s
->language
;
1193 flang
= language_unknown
;
1196 flang
= language_unknown
;
1202 _initialize_stack ()
1205 backtrace_limit
= 30;
1208 add_com ("return", class_stack
, return_command
,
1209 "Make selected stack frame return to its caller.\n\
1210 Control remains in the debugger, but when you continue\n\
1211 execution will resume in the frame above the one now selected.\n\
1212 If an argument is given, it is an expression for the value to return.");
1214 add_com ("up", class_stack
, up_command
,
1215 "Select and print stack frame that called this one.\n\
1216 An argument says how many frames up to go.");
1217 add_com ("up-silently", class_support
, up_silently_command
,
1218 "Same as the `up' command, but does not print anything.\n\
1219 This is useful in command scripts.");
1221 add_com ("down", class_stack
, down_command
,
1222 "Select and print stack frame called by this one.\n\
1223 An argument says how many frames down to go.");
1224 add_com_alias ("do", "down", class_stack
, 1);
1225 add_com_alias ("dow", "down", class_stack
, 1);
1226 add_com ("down-silently", class_support
, down_silently_command
,
1227 "Same as the `down' command, but does not print anything.\n\
1228 This is useful in command scripts.");
1230 add_com ("frame", class_stack
, frame_command
,
1231 "Select and print a stack frame.\n\
1232 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1233 An argument specifies the frame to select.\n\
1234 It can be a stack frame number or the address of the frame.\n\
1235 With argument, nothing is printed if input is coming from\n\
1236 a command file or a user-defined command.");
1238 add_com_alias ("f", "frame", class_stack
, 1);
1240 add_com ("select-frame", class_stack
, select_frame_command
,
1241 "Select a stack frame without printing anything.\n\
1242 An argument specifies the frame to select.\n\
1243 It can be a stack frame number or the address of the frame.\n");
1245 add_com ("backtrace", class_stack
, backtrace_command
,
1246 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1247 With a negative argument, print outermost -COUNT frames.");
1248 add_com_alias ("bt", "backtrace", class_stack
, 0);
1249 add_com_alias ("where", "backtrace", class_alias
, 0);
1250 add_info ("stack", backtrace_command
,
1251 "Backtrace of the stack, or innermost COUNT frames.");
1252 add_info_alias ("s", "stack", 1);
1253 add_info ("frame", frame_info
,
1254 "All about selected stack frame, or frame at ADDR.");
1255 add_info_alias ("f", "frame", 1);
1256 add_info ("locals", locals_info
,
1257 "Local variables of current stack frame.");
1258 add_info ("args", args_info
,
1259 "Argument variables of current stack frame.");
1260 add_info ("catch", catch_info
,
1261 "Exceptions that can be caught in the current stack frame.");
1264 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1265 "Specify maximum number of frames for \"backtrace\" to print by default.",
1267 add_info ("backtrace-limit", backtrace_limit_info
,
1268 "The maximum number of frames for \"backtrace\" to print by default.");