1 /* Print and select stack frames for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989 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. */
30 #include "breakpoint.h"
32 extern int addressprint
; /* Print addresses, or stay symbolic only? */
33 extern int info_verbose
; /* Verbosity of symbol reading msgs */
34 extern unsigned lines_to_list
; /* # of lines "list" command shows by default */
35 extern char *reg_names
[]; /* Names of registers */
37 /* Thie "selected" stack frame is used by default for local and arg access.
38 May be zero, for no selected frame. */
42 /* Level of the selected frame:
43 0 for innermost, 1 for its caller, ...
44 or -1 for frame specified by address with no defined level. */
46 int selected_frame_level
;
48 /* Nonzero means print the full filename and linenumber
49 when a frame is printed, and do so in a format programs can parse. */
51 int frame_file_full_name
= 0;
53 void print_frame_info ();
55 /* Print a stack frame briefly. FRAME should be the frame id
56 and LEVEL should be its level in the stack (or -1 for level not defined).
57 This prints the level, the function executing, the arguments,
58 and the file name and line number.
59 If the pc is not at the beginning of the source line,
60 the actual pc is printed at the beginning.
62 If SOURCE is 1, print the source line as well.
63 If SOURCE is -1, print ONLY the source line. */
66 print_stack_frame (frame
, level
, source
)
71 struct frame_info
*fi
;
73 fi
= get_frame_info (frame
);
75 print_frame_info (fi
, level
, source
, 1);
79 print_frame_info (fi
, level
, source
, args
)
80 struct frame_info
*fi
;
85 struct symtab_and_line sal
;
87 register char *funname
= 0;
90 #if 0 /* Symbol reading is fast enough now */
91 struct partial_symtab
*pst
;
93 /* Don't give very much information if we haven't readin the
95 pst
= find_pc_psymtab (fi
->pc
);
96 if (pst
&& !pst
->readin
)
98 /* Abbreviated information. */
101 if (!find_pc_partial_function (fi
->pc
, &fname
, 0))
104 printf_filtered ("#%-2d ", level
);
106 printf_filtered ("0x%x in ", fi
->pc
);
108 fputs_demangled (fname
, stdout
, -1);
109 fputs_filtered (" (...)\n", stdout
);
115 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
116 func
= find_pc_function (fi
->pc
);
119 /* In certain pathological cases, the symtabs give the wrong
120 function (when we are in the first function in a file which
121 is compiled without debugging symbols, the previous function
122 is compiled with debugging symbols, and the "foo.o" symbol
123 that is supposed to tell us where the file with debugging symbols
124 ends has been truncated by ar because it is longer than 15
127 So look in the misc_function_vector as well, and if it comes
128 up with a larger address for the function use that instead.
129 I don't think this can ever cause any problems;
130 there shouldn't be any
131 misc_function_vector symbols in the middle of a function. */
132 int misc_index
= find_pc_misc_function (fi
->pc
);
134 && (misc_function_vector
[misc_index
].address
135 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
137 /* In this case we have no way of knowing the source file
138 and line number, so don't print them. */
140 /* We also don't know anything about the function besides
141 its address and name. */
143 funname
= misc_function_vector
[misc_index
].name
;
146 funname
= SYMBOL_NAME (func
);
150 register int misc_index
= find_pc_misc_function (fi
->pc
);
152 funname
= misc_function_vector
[misc_index
].name
;
155 if (source
>= 0 || !sal
.symtab
)
158 printf_filtered ("#%-2d ", level
);
160 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
)
161 printf_filtered ("0x%x in ", fi
->pc
);
162 fputs_demangled (funname
? funname
: "??", stdout
, -1);
164 fputs_filtered (" (", stdout
);
167 FRAME_NUM_ARGS (numargs
, fi
);
168 print_frame_args (func
, fi
, numargs
, stdout
);
170 printf_filtered (")");
171 if (sal
.symtab
&& sal
.symtab
->filename
)
174 printf_filtered (" at %s:%d", sal
.symtab
->filename
, sal
.line
);
176 printf_filtered ("\n");
179 if ((source
!= 0) && sal
.symtab
)
182 int mid_statement
= source
< 0 && fi
->pc
!= sal
.pc
;
183 if (frame_file_full_name
)
184 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
);
187 if (addressprint
&& mid_statement
)
188 printf_filtered ("0x%x\t", fi
->pc
);
189 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
191 current_source_line
= max (sal
.line
- lines_to_list
/2, 1);
194 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
199 void flush_cached_frames ();
201 #ifdef FRAME_SPECIFICATION_DYADIC
202 extern FRAME
setup_arbitrary_frame ();
206 * Read a frame specification in whatever the appropriate format is.
207 * Call error() if the specification is in any way invalid (i.e.
208 * this function never returns NULL).
211 parse_frame_specification (frame_exp
)
219 char *addr_string
, *p
;
220 struct cleanup
*tmp_cleanup
;
222 while (*frame_exp
== ' ') frame_exp
++;
223 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
229 addr_string
= savestring(frame_exp
, p
- frame_exp
);
232 tmp_cleanup
= make_cleanup (free
, addr_string
);
233 arg1
= parse_and_eval_address (addr_string
);
234 do_cleanups (tmp_cleanup
);
237 while (*p
== ' ') p
++;
242 arg2
= parse_and_eval_address (p
);
250 if (selected_frame
== NULL
)
251 error ("No selected frame.");
252 return selected_frame
;
257 FRAME fid
= find_relative_frame (get_current_frame (), &level
);
261 /* find_relative_frame was successful */
264 /* If (s)he specifies the frame with an address, he deserves what
265 (s)he gets. Still, give the highest one that matches. */
267 for (fid
= get_current_frame ();
268 fid
&& FRAME_FP (fid
) != arg1
;
269 fid
= get_prev_frame (fid
))
273 while ((tfid
= get_prev_frame (fid
)) &&
274 (FRAME_FP (tfid
) == arg1
))
277 #ifdef FRAME_SPECIFICATION_DYADIC
279 error ("Incorrect number of args in frame specification");
283 return create_new_frame (arg1
, 0);
288 /* Must be addresses */
289 #ifndef FRAME_SPECIFICATION_DYADIC
290 error ("Incorrect number of args in frame specification");
292 return setup_arbitrary_frame (arg1
, arg2
);
296 fatal ("Internal: Error in parsing in parse_frame_specification");
300 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
301 that if it is unsure about the answer, it returns 0
302 instead of guessing (this happens on the VAX and i960, for example).
304 On most machines, we never have to guess about the args address,
305 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
306 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
307 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
310 /* Print verbosely the selected frame or the frame at address ADDR.
311 This means absolutely all information in the frame is printed. */
314 frame_info (addr_exp
)
318 struct frame_info
*fi
;
319 struct frame_saved_regs fsr
;
320 struct symtab_and_line sal
;
326 if (!target_has_stack
)
327 error ("No inferior or core file.");
329 frame
= parse_frame_specification (addr_exp
);
331 error ("Invalid frame specified.");
333 fi
= get_frame_info (frame
);
334 sal
= find_pc_line (fi
->pc
, fi
->next_frame
);
335 func
= get_frame_function (frame
);
337 funname
= SYMBOL_NAME (func
);
340 register int misc_index
= find_pc_misc_function (fi
->pc
);
342 funname
= misc_function_vector
[misc_index
].name
;
344 calling_frame
= get_prev_frame (frame
);
346 if (!addr_exp
&& selected_frame_level
>= 0)
347 printf_filtered ("Stack level %d, frame at 0x%x:\n %s = 0x%x",
348 selected_frame_level
, FRAME_FP(frame
),
349 reg_names
[PC_REGNUM
], fi
->pc
);
351 printf_filtered ("Stack frame at 0x%x:\n %s = 0x%x",
352 FRAME_FP(frame
), reg_names
[PC_REGNUM
], fi
->pc
);
356 printf_filtered (" in %s", funname
);
359 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
360 puts_filtered ("; ");
362 printf_filtered ("saved %s 0x%x\n", reg_names
[PC_REGNUM
],
363 FRAME_SAVED_PC (frame
));
365 printf_filtered (" called by frame at 0x%x", FRAME_FP (calling_frame
));
366 if (fi
->next_frame
&& calling_frame
)
370 printf_filtered (" caller of frame at 0x%x", fi
->next_frame
);
371 if (fi
->next_frame
|| calling_frame
)
372 puts_filtered ("\n");
375 /* Address of the argument list for this frame, or 0. */
376 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
377 /* Number of args for this frame, or -1 if unknown. */
381 printf_filtered (" Arglist at unknown address.\n");
384 printf_filtered (" Arglist at 0x%x,", arg_list
);
386 FRAME_NUM_ARGS (numargs
, fi
);
388 puts_filtered (" args: ");
389 else if (numargs
== 0)
390 puts_filtered (" no args.");
391 else if (numargs
== 1)
392 puts_filtered (" 1 arg: ");
394 printf_filtered (" %d args: ", numargs
);
395 print_frame_args (func
, fi
, numargs
, stdout
);
396 puts_filtered ("\n");
400 #if defined (FRAME_FIND_SAVED_REGS)
401 get_frame_saved_regs (fi
, &fsr
);
402 /* The sp is special; what's returned isn't the save address, but
403 actually the value of the previous frame's sp. */
404 printf_filtered (" Previous frame's sp is 0x%x\n", fsr
.regs
[SP_REGNUM
]);
406 for (i
= 0; i
< NUM_REGS
; i
++)
407 if (fsr
.regs
[i
] && i
!= SP_REGNUM
)
410 puts_filtered (" Saved registers:\n ");
414 printf_filtered (" %s at 0x%x", reg_names
[i
], fsr
.regs
[i
]);
418 puts_filtered ("\n");
419 #endif /* Have FRAME_FIND_SAVED_REGS. */
423 /* Set a limit on the number of frames printed by default in a
426 static int backtrace_limit
;
429 set_backtrace_limit_command (count_exp
, from_tty
)
433 int count
= parse_and_eval_address (count_exp
);
436 error ("Negative argument not meaningful as backtrace limit.");
438 backtrace_limit
= count
;
442 backtrace_limit_info (arg
, from_tty
)
447 error ("\"Info backtrace-limit\" takes no arguments.");
449 printf ("Backtrace limit: %d.\n", backtrace_limit
);
453 /* Print briefly all stack frames or just the innermost COUNT frames. */
456 backtrace_command (count_exp
, from_tty
)
460 struct frame_info
*fi
;
462 register FRAME frame
;
464 register FRAME trailing
;
465 register int trailing_level
;
467 if (!target_has_stack
)
470 /* The following code must do two things. First, it must
471 set the variable TRAILING to the frame from which we should start
472 printing. Second, it must set the variable count to the number
473 of frames which we should print, or -1 if all of them. */
474 trailing
= get_current_frame ();
478 count
= parse_and_eval_address (count_exp
);
486 while (current
&& count
--)
489 current
= get_prev_frame (current
);
492 /* Will stop when CURRENT reaches the top of the stack. TRAILING
493 will be COUNT below it. */
497 trailing
= get_prev_frame (trailing
);
498 current
= get_prev_frame (current
);
510 struct partial_symtab
*ps
;
512 /* Read in symbols for all of the frames. Need to do this in
513 a separate pass so that "Reading in symbols for xxx" messages
514 don't screw up the appearance of the backtrace. Also
515 if people have strong opinions against reading symbols for
516 backtrace this may have to be an option. */
518 for (frame
= trailing
;
519 frame
!= NULL
&& i
--;
520 frame
= get_prev_frame (frame
))
523 fi
= get_frame_info (frame
);
524 ps
= find_pc_psymtab (fi
->pc
);
526 (void) PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
530 for (i
= 0, frame
= trailing
;
532 i
++, frame
= get_prev_frame (frame
))
535 fi
= get_frame_info (frame
);
536 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
539 /* If we've stopped before the end, mention that. */
540 if (frame
&& from_tty
)
541 printf_filtered ("(More stack frames follow...)\n");
544 /* Print the local variables of a block B active in FRAME.
545 Return 1 if any variables were printed; 0 otherwise. */
548 print_block_frame_locals (b
, frame
, stream
)
550 register FRAME frame
;
551 register FILE *stream
;
555 register struct symbol
*sym
;
556 register int values_printed
= 0;
558 nsyms
= BLOCK_NSYMS (b
);
560 for (i
= 0; i
< nsyms
; i
++)
562 sym
= BLOCK_SYM (b
, i
);
563 if (SYMBOL_CLASS (sym
) == LOC_LOCAL
564 || SYMBOL_CLASS (sym
) == LOC_REGISTER
565 || SYMBOL_CLASS (sym
) == LOC_STATIC
)
568 fprint_symbol (stream
, SYMBOL_NAME (sym
));
569 fputs_filtered (" = ", stream
);
570 print_variable_value (sym
, frame
, stream
);
571 fprintf_filtered (stream
, "\n");
575 return values_printed
;
578 /* Same, but print labels. */
581 print_block_frame_labels (b
, have_default
, stream
)
584 register FILE *stream
;
588 register struct symbol
*sym
;
589 register int values_printed
= 0;
591 nsyms
= BLOCK_NSYMS (b
);
593 for (i
= 0; i
< nsyms
; i
++)
595 sym
= BLOCK_SYM (b
, i
);
596 if (! strcmp (SYMBOL_NAME (sym
), "default"))
602 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
604 struct symtab_and_line sal
;
605 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
607 fputs_demangled (SYMBOL_NAME (sym
), stream
, 1);
609 fprintf_filtered (stream
, " 0x%x", SYMBOL_VALUE_ADDRESS (sym
));
610 fprintf_filtered (stream
, " in file %s, line %d\n",
611 sal
.symtab
->filename
, sal
.line
);
615 return values_printed
;
618 /* Print on STREAM all the local variables in frame FRAME,
619 including all the blocks active in that frame
622 Returns 1 if the job was done,
623 or 0 if nothing was printed because we have no info
624 on the function running in FRAME. */
627 print_frame_local_vars (frame
, stream
)
628 register FRAME frame
;
629 register FILE *stream
;
631 register struct block
*block
= get_frame_block (frame
);
632 register int values_printed
= 0;
636 fprintf_filtered (stream
, "No symbol table info available.\n");
643 if (print_block_frame_locals (block
, frame
, stream
))
645 /* After handling the function's top-level block, stop.
646 Don't continue to its superblock, the block of
648 if (BLOCK_FUNCTION (block
))
650 block
= BLOCK_SUPERBLOCK (block
);
655 fprintf_filtered (stream
, "No locals.\n");
662 /* Same, but print labels. */
665 print_frame_label_vars (frame
, this_level_only
, stream
)
666 register FRAME frame
;
668 register FILE *stream
;
670 extern struct blockvector
*blockvector_for_pc ();
671 register struct blockvector
*bl
;
672 register struct block
*block
= get_frame_block (frame
);
673 register int values_printed
= 0;
674 int index
, have_default
= 0;
675 char *blocks_printed
;
676 struct frame_info
*fi
= get_frame_info (frame
);
677 CORE_ADDR pc
= fi
->pc
;
681 fprintf_filtered (stream
, "No symbol table info available.\n");
686 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
687 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
688 bzero (blocks_printed
, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
692 CORE_ADDR end
= BLOCK_END (block
) - 4;
695 if (bl
!= blockvector_for_pc (end
, &index
))
696 error ("blockvector blotch");
697 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
698 error ("blockvector botch");
699 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
702 /* Don't print out blocks that have gone by. */
703 while (index
< last_index
704 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
707 while (index
< last_index
708 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
710 if (blocks_printed
[index
] == 0)
712 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
714 blocks_printed
[index
] = 1;
720 if (values_printed
&& this_level_only
)
723 /* After handling the function's top-level block, stop.
724 Don't continue to its superblock, the block of
726 if (BLOCK_FUNCTION (block
))
728 block
= BLOCK_SUPERBLOCK (block
);
731 if (!values_printed
&& !this_level_only
)
733 fprintf_filtered (stream
, "No catches.\n");
737 return values_printed
;
742 locals_info (args
, from_tty
)
747 error ("No frame selected.");
748 print_frame_local_vars (selected_frame
, stdout
);
755 error ("No frame selected.");
756 print_frame_label_vars (selected_frame
, 0, stdout
);
760 print_frame_arg_vars (frame
, stream
)
761 register FRAME frame
;
762 register FILE *stream
;
764 struct symbol
*func
= get_frame_function (frame
);
765 register struct block
*b
;
768 register struct symbol
*sym
, *sym2
;
769 register int values_printed
= 0;
773 fprintf_filtered (stream
, "No symbol table info available.\n");
778 b
= SYMBOL_BLOCK_VALUE (func
);
779 nsyms
= BLOCK_NSYMS (b
);
781 for (i
= 0; i
< nsyms
; i
++)
783 sym
= BLOCK_SYM (b
, i
);
784 if (SYMBOL_CLASS (sym
) == LOC_ARG
785 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
786 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
787 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
790 fprint_symbol (stream
, SYMBOL_NAME (sym
));
791 fputs_filtered (" = ", stream
);
792 /* We have to look up the symbol because arguments often have
793 two entries (one a parameter, one a register) and the one
794 we want is the register, which lookup_symbol will find for
796 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
797 b
, VAR_NAMESPACE
, (int *)NULL
, (struct symtab
**)NULL
);
798 print_variable_value (sym2
, frame
, stream
);
799 fprintf_filtered (stream
, "\n");
806 fprintf_filtered (stream
, "No arguments.\n");
817 error ("No frame selected.");
818 print_frame_arg_vars (selected_frame
, stdout
);
821 /* Select frame FRAME, and note that its stack level is LEVEL.
822 LEVEL may be -1 if an actual level number is not known. */
825 select_frame (frame
, level
)
829 selected_frame
= frame
;
830 selected_frame_level
= level
;
831 /* Ensure that symbols for this frame are readin. */
833 find_pc_symtab (get_frame_info (frame
)->pc
);
836 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
837 If there is no selected frame, *FRAMEP is set to NULL. */
840 record_selected_frame (frameaddrp
, levelp
)
841 FRAME_ADDR
*frameaddrp
;
844 *frameaddrp
= selected_frame
? FRAME_FP (selected_frame
) : NULL
;
845 *levelp
= selected_frame_level
;
848 /* Return the symbol-block in which the selected frame is executing.
849 Can return zero under various legitimate circumstances. */
852 get_selected_block ()
854 if (!target_has_stack
)
858 return get_current_block ();
859 return get_frame_block (selected_frame
);
862 /* Find a frame a certain number of levels away from FRAME.
863 LEVEL_OFFSET_PTR points to an int containing the number of levels.
864 Positive means go to earlier frames (up); negative, the reverse.
865 The int that contains the number of levels is counted toward
866 zero as the frames for those levels are found.
867 If the top or bottom frame is reached, that frame is returned,
868 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
869 how much farther the original request asked to go. */
872 find_relative_frame (frame
, level_offset_ptr
)
873 register FRAME frame
;
874 register int* level_offset_ptr
;
877 register FRAME frame1
, frame2
;
879 /* Going up is simple: just do get_prev_frame enough times
880 or until initial frame is reached. */
881 while (*level_offset_ptr
> 0)
883 prev
= get_prev_frame (frame
);
886 (*level_offset_ptr
)--;
889 /* Going down could be done by iterating get_frame_info to
890 find the next frame, but that would be quadratic
891 since get_frame_info must scan all the way from the current frame.
892 The following algorithm is linear. */
893 if (*level_offset_ptr
< 0)
896 /* This is ancient and unnecessary? -- gnu@cygnus.com
897 It also loops forever if frame #0 is not current_frame (e.g. when we have
898 used the "frame" command after the stack was invalid). */
900 /* First put frame1 at innermost frame
901 and frame2 N levels up from there. */
902 frame1
= get_current_frame ();
904 while (*level_offset_ptr
< 0 && frame2
!= frame
)
906 frame2
= get_prev_frame (frame2
);
907 (*level_offset_ptr
) ++;
909 /* Then slide frame1 and frame2 up in synchrony
910 and when frame2 reaches our starting point
911 frame1 must be N levels down from there. */
912 while (frame2
!= frame
)
914 frame1
= get_prev_frame (frame1
);
915 frame2
= get_prev_frame (frame2
);
919 while (*level_offset_ptr
< 0) {
920 frame1
= get_next_frame (frame
);
924 (*level_offset_ptr
)++;
931 /* The "frame" command. With no arg, print selected frame briefly.
932 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
933 valid level. Otherwise, treat level_exp as an address expression
934 and print it. See parse_frame_specification for more info on proper
935 frame expressions. */
938 frame_command (level_exp
, from_tty
)
942 register FRAME frame
, frame1
;
943 unsigned int level
= 0;
945 if (!target_has_stack
)
948 frame
= parse_frame_specification (level_exp
);
950 /* Try to figure out what level this frame is. But if there is
951 no current stack, don't error out -- let the user set one. */
953 if (get_current_frame()) {
954 for (frame1
= get_prev_frame (0);
955 frame1
&& frame1
!= frame
;
956 frame1
= get_prev_frame (frame1
))
963 select_frame (frame
, level
);
968 print_stack_frame (selected_frame
, selected_frame_level
, 1);
971 /* Select the frame up one or COUNT stack levels
972 from the previously selected frame, and print it briefly. */
976 up_silently_command (count_exp
, from_tty
)
980 register FRAME frame
;
981 int count
= 1, count1
;
983 count
= parse_and_eval_address (count_exp
);
986 if (!target_has_stack
)
989 frame
= find_relative_frame (selected_frame
, &count1
);
990 if (count1
!= 0 && count_exp
== 0)
991 error ("Initial frame selected; you cannot go up.");
992 select_frame (frame
, selected_frame_level
+ count
- count1
);
996 up_command (count_exp
, from_tty
)
1000 up_silently_command (count_exp
, from_tty
);
1001 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1004 /* Select the frame down one or COUNT stack levels
1005 from the previously selected frame, and print it briefly. */
1009 down_silently_command (count_exp
, from_tty
)
1013 register FRAME frame
;
1014 int count
= -1, count1
;
1016 count
= - parse_and_eval_address (count_exp
);
1019 frame
= find_relative_frame (selected_frame
, &count1
);
1020 if (count1
!= 0 && count_exp
== 0)
1021 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1022 select_frame (frame
, selected_frame_level
+ count
- count1
);
1027 down_command (count_exp
, from_tty
)
1031 down_silently_command (count_exp
, from_tty
);
1032 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1036 return_command (retval_exp
, from_tty
)
1040 struct symbol
*thisfun
;
1041 FRAME_ADDR selected_frame_addr
;
1042 CORE_ADDR selected_frame_pc
;
1045 if (selected_frame
== NULL
)
1046 error ("No selected frame.");
1047 thisfun
= get_frame_function (selected_frame
);
1048 selected_frame_addr
= FRAME_FP (selected_frame
);
1049 selected_frame_pc
= (get_frame_info (selected_frame
))->pc
;
1051 /* If interactive, require confirmation. */
1057 if (!query ("Make %s return now? ", SYMBOL_NAME (thisfun
)))
1058 error ("Not confirmed.");
1061 if (!query ("Make selected stack frame return now? "))
1062 error ("Not confirmed.");
1065 /* Do the real work. Pop until the specified frame is current. We
1066 use this method because the selected_frame is not valid after
1067 a POP_FRAME. The pc comparison makes this work even if the
1068 selected frame shares its fp with another frame. */
1070 while ( selected_frame_addr
!= FRAME_FP (frame
= get_current_frame())
1071 || selected_frame_pc
!= (get_frame_info (frame
))->pc
)
1074 /* Then pop that frame. */
1078 /* Compute the return value (if any) and store in the place
1079 for return values. */
1082 set_return_value (parse_and_eval (retval_exp
));
1084 /* If interactive, print the frame that is now current. */
1087 frame_command ("0", 1);
1091 _initialize_stack ()
1094 backtrace_limit
= 30;
1097 add_com ("return", class_stack
, return_command
,
1098 "Make selected stack frame return to its caller.\n\
1099 Control remains in the debugger, but when you continue\n\
1100 execution will resume in the frame above the one now selected.\n\
1101 If an argument is given, it is an expression for the value to return.");
1103 add_com ("up", class_stack
, up_command
,
1104 "Select and print stack frame that called this one.\n\
1105 An argument says how many frames up to go.");
1106 add_com ("up-silently", class_support
, up_silently_command
,
1107 "Same as the `up' command, but does not print anything.\n\
1108 This is useful in command scripts.");
1110 add_com ("down", class_stack
, down_command
,
1111 "Select and print stack frame called by this one.\n\
1112 An argument says how many frames down to go.");
1113 add_com_alias ("do", "down", class_stack
, 1);
1114 add_com ("down-silently", class_support
, down_silently_command
,
1115 "Same as the `down' command, but does not print anything.\n\
1116 This is useful in command scripts.");
1118 add_com ("frame", class_stack
, frame_command
,
1119 "Select and print a stack frame.\n\
1120 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1121 An argument specifies the frame to select.\n\
1122 It can be a stack frame number or the address of the frame.\n\
1123 With argument, nothing is printed if input is coming from\n\
1124 a command file or a user-defined command.");
1126 add_com_alias ("f", "frame", class_stack
, 1);
1128 add_com ("backtrace", class_stack
, backtrace_command
,
1129 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1130 With a negative argument, print outermost -COUNT frames.");
1131 add_com_alias ("bt", "backtrace", class_stack
, 0);
1132 add_com_alias ("where", "backtrace", class_alias
, 0);
1133 add_info ("stack", backtrace_command
,
1134 "Backtrace of the stack, or innermost COUNT frames.");
1135 add_info_alias ("s", "stack", 1);
1136 add_info ("frame", frame_info
,
1137 "All about selected stack frame, or frame at ADDR.");
1138 add_info_alias ("f", "frame", 1);
1139 add_info ("locals", locals_info
,
1140 "Local variables of current stack frame.");
1141 add_info ("args", args_info
,
1142 "Argument variables of current stack frame.");
1143 add_info ("catch", catch_info
,
1144 "Exceptions that can be caught in the current stack frame.");
1147 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1148 "Specify maximum number of frames for \"backtrace\" to print by default.",
1150 add_info ("backtrace-limit", backtrace_limit_info
,
1151 "The maximum number of frames for \"backtrace\" to print by default.");