1 /* Print and select stack frames for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991-1996, 1998-2000 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
27 #include "expression.h"
33 #include "breakpoint.h"
40 /* Prototypes for exported functions. */
42 void args_info
PARAMS ((char *, int));
44 void locals_info
PARAMS ((char *, int));
46 void (*selected_frame_level_changed_hook
) PARAMS ((int));
48 void _initialize_stack
PARAMS ((void));
50 /* Prototypes for local functions. */
52 static void return_command
PARAMS ((char *, int));
54 static void down_command
PARAMS ((char *, int));
56 static void down_silently_base
PARAMS ((char *));
58 static void down_silently_command
PARAMS ((char *, int));
60 static void up_command
PARAMS ((char *, int));
62 static void up_silently_base
PARAMS ((char *));
64 static void up_silently_command
PARAMS ((char *, int));
66 void frame_command
PARAMS ((char *, int));
68 static void current_frame_command
PARAMS ((char *, int));
70 static void select_frame_command
PARAMS ((char *, int));
72 static void print_frame_arg_vars (struct frame_info
*, struct ui_file
*);
74 static void catch_info
PARAMS ((char *, int));
76 static void args_plus_locals_info
PARAMS ((char *, int));
78 static void print_frame_label_vars (struct frame_info
*, int,
81 static void print_frame_local_vars (struct frame_info
*, int,
84 static int print_block_frame_labels (struct block
*, int *,
87 static int print_block_frame_locals (struct block
*,
92 static void print_frame (struct frame_info
*fi
,
96 struct symtab_and_line sal
);
98 static void print_frame_info_base
PARAMS ((struct frame_info
*, int, int, int));
100 static void print_stack_frame_base
PARAMS ((struct frame_info
*, int, int));
102 static void backtrace_command
PARAMS ((char *, int));
104 struct frame_info
*parse_frame_specification
PARAMS ((char *));
106 static void frame_info
PARAMS ((char *, int));
108 extern int addressprint
; /* Print addresses, or stay symbolic only? */
109 extern int info_verbose
; /* Verbosity of symbol reading msgs */
110 extern int lines_to_list
; /* # of lines "list" command shows by default */
112 /* The "selected" stack frame is used by default for local and arg access.
113 May be zero, for no selected frame. */
115 struct frame_info
*selected_frame
;
117 /* Level of the selected frame:
118 0 for innermost, 1 for its caller, ...
119 or -1 for frame specified by address with no defined level. */
121 int selected_frame_level
;
123 /* Zero means do things normally; we are interacting directly with the
124 user. One means print the full filename and linenumber when a
125 frame is printed, and do so in a format emacs18/emacs19.22 can
126 parse. Two means print similar annotations, but in many more
127 cases and in a slightly different syntax. */
129 int annotation_level
= 0;
132 struct print_stack_frame_args
134 struct frame_info
*fi
;
140 static int print_stack_frame_base_stub
PARAMS ((char *));
142 /* Show and print the frame arguments.
143 Pass the args the way catch_errors wants them. */
144 static int show_and_print_stack_frame_stub
PARAMS ((void *args
));
146 show_and_print_stack_frame_stub (args
)
149 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
151 /* Reversed order of these so tuiDo() doesn't occur
152 * in the middle of "Breakpoint 1 ... [location]" printing = RT
155 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
156 print_frame_info (p
->fi
, p
->level
, p
->source
, p
->args
);
161 /* Show or print the frame arguments.
162 Pass the args the way catch_errors wants them. */
163 static int print_stack_frame_stub
PARAMS ((void *args
));
165 print_stack_frame_stub (args
)
168 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
171 print_frame_info (p
->fi
, p
->level
, p
->source
, p
->args
);
173 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
177 /* Print a stack frame briefly. FRAME_INFI should be the frame info
178 and LEVEL should be its level in the stack (or -1 for level not
181 /* Pass the args the way catch_errors wants them. */
183 print_stack_frame_base_stub (args
)
186 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
188 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
192 /* print the frame arguments to the terminal.
193 Pass the args the way catch_errors wants them. */
194 static int print_only_stack_frame_stub
PARAMS ((void *));
196 print_only_stack_frame_stub (args
)
199 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
201 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
205 /* Print a stack frame briefly. FRAME_INFI should be the frame info
206 and LEVEL should be its level in the stack (or -1 for level not defined).
207 This prints the level, the function executing, the arguments,
208 and the file name and line number.
209 If the pc is not at the beginning of the source line,
210 the actual pc is printed at the beginning.
212 If SOURCE is 1, print the source line as well.
213 If SOURCE is -1, print ONLY the source line. */
216 print_stack_frame_base (fi
, level
, source
)
217 struct frame_info
*fi
;
221 struct print_stack_frame_args args
;
225 args
.source
= source
;
228 catch_errors (print_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
231 /* Show and print a stack frame briefly. FRAME_INFI should be the frame info
232 and LEVEL should be its level in the stack (or -1 for level not defined).
233 This prints the level, the function executing, the arguments,
234 and the file name and line number.
235 If the pc is not at the beginning of the source line,
236 the actual pc is printed at the beginning.
238 If SOURCE is 1, print the source line as well.
239 If SOURCE is -1, print ONLY the source line. */
242 show_and_print_stack_frame (fi
, level
, source
)
243 struct frame_info
*fi
;
247 struct print_stack_frame_args args
;
251 args
.source
= source
;
254 catch_errors (show_and_print_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
258 /* Show or print a stack frame briefly. FRAME_INFI should be the frame info
259 and LEVEL should be its level in the stack (or -1 for level not defined).
260 This prints the level, the function executing, the arguments,
261 and the file name and line number.
262 If the pc is not at the beginning of the source line,
263 the actual pc is printed at the beginning.
265 If SOURCE is 1, print the source line as well.
266 If SOURCE is -1, print ONLY the source line. */
269 print_stack_frame (fi
, level
, source
)
270 struct frame_info
*fi
;
274 struct print_stack_frame_args args
;
278 args
.source
= source
;
281 catch_errors (print_stack_frame_stub
, (char *) &args
, "", RETURN_MASK_ALL
);
284 /* Print a stack frame briefly. FRAME_INFI should be the frame info
285 and LEVEL should be its level in the stack (or -1 for level not defined).
286 This prints the level, the function executing, the arguments,
287 and the file name and line number.
288 If the pc is not at the beginning of the source line,
289 the actual pc is printed at the beginning.
291 If SOURCE is 1, print the source line as well.
292 If SOURCE is -1, print ONLY the source line. */
295 print_only_stack_frame (fi
, level
, source
)
296 struct frame_info
*fi
;
300 struct print_stack_frame_args args
;
304 args
.source
= source
;
307 catch_errors (print_only_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
310 struct print_args_args
313 struct frame_info
*fi
;
314 struct ui_file
*stream
;
317 static int print_args_stub
PARAMS ((PTR
));
319 /* Pass the args the way catch_errors wants them. */
322 print_args_stub (args
)
326 struct print_args_args
*p
= (struct print_args_args
*) args
;
328 numargs
= FRAME_NUM_ARGS (p
->fi
);
329 print_frame_args (p
->func
, p
->fi
, numargs
, p
->stream
);
333 /* Print information about a frame for frame "fi" at level "level".
334 Used in "where" output, also used to emit breakpoint or step
336 LEVEL is the level of the frame, or -1 if it is the
337 innermost frame but we don't want to print the level.
338 The meaning of the SOURCE argument is:
339 SRC_LINE: Print only source line
340 LOCATION: Print only location
341 LOC_AND_SRC: Print location and source line. */
344 print_frame_info_base (fi
, level
, source
, args
)
345 struct frame_info
*fi
;
350 struct symtab_and_line sal
;
355 char buf
[MAX_REGISTER_RAW_SIZE
];
358 /* On the 68k, this spends too much time in m68k_find_saved_regs. */
360 /* Get the value of SP_REGNUM relative to the frame. */
361 get_saved_register (buf
, (int *) NULL
, (CORE_ADDR
*) NULL
,
362 FRAME_INFO_ID (fi
), SP_REGNUM
, (enum lval_type
*) NULL
);
363 sp
= extract_address (buf
, REGISTER_RAW_SIZE (SP_REGNUM
));
365 /* This is not a perfect test, because if a function alloca's some
366 memory, puts some code there, and then jumps into it, then the test
367 will succeed even though there is no call dummy. Probably best is
368 to check for a bp_call_dummy breakpoint. */
369 if (PC_IN_CALL_DUMMY (fi
->pc
, sp
, fi
->frame
))
371 if (frame_in_dummy (fi
))
374 annotate_frame_begin (level
== -1 ? 0 : level
, fi
->pc
);
376 /* Do this regardless of SOURCE because we don't have any source
377 to list for this frame. */
379 printf_filtered ("#%-2d ", level
);
380 annotate_function_call ();
381 printf_filtered ("<function called from gdb>\n");
382 annotate_frame_end ();
385 if (fi
->signal_handler_caller
)
387 annotate_frame_begin (level
== -1 ? 0 : level
, fi
->pc
);
389 /* Do this regardless of SOURCE because we don't have any source
390 to list for this frame. */
392 printf_filtered ("#%-2d ", level
);
393 annotate_signal_handler_caller ();
394 printf_filtered ("<signal handler called>\n");
395 annotate_frame_end ();
399 /* If fi is not the innermost frame, that normally means that fi->pc
400 points to *after* the call instruction, and we want to get the line
401 containing the call, never the next line. But if the next frame is
402 a signal_handler_caller or a dummy frame, then the next frame was
403 not entered as the result of a call, and we want to get the line
404 containing fi->pc. */
406 find_pc_line (fi
->pc
,
408 && !fi
->next
->signal_handler_caller
409 && !frame_in_dummy (fi
->next
));
411 location_print
= (source
== LOCATION
412 || source
== LOC_AND_ADDRESS
413 || source
== SRC_AND_LOC
);
415 if (location_print
|| !sal
.symtab
)
416 print_frame (fi
, level
, source
, args
, sal
);
418 source_print
= (source
== SRC_LINE
|| source
== SRC_AND_LOC
);
420 if (source_print
&& sal
.symtab
)
423 int mid_statement
= (source
== SRC_LINE
) && (fi
->pc
!= sal
.pc
);
425 if (annotation_level
)
426 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
430 if (addressprint
&& mid_statement
&& !tui_version
)
432 print_address_numeric (fi
->pc
, 1, gdb_stdout
);
433 printf_filtered ("\t");
435 if (print_frame_info_listing_hook
)
436 print_frame_info_listing_hook (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
437 else if (!tui_version
)
438 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
440 current_source_line
= max (sal
.line
- lines_to_list
/ 2, 1);
444 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
446 annotate_frame_end ();
448 gdb_flush (gdb_stdout
);
452 print_frame (struct frame_info
*fi
,
456 struct symtab_and_line sal
)
459 register char *funname
= 0;
460 enum language funlang
= language_unknown
;
462 func
= find_pc_function (fi
->pc
);
465 /* In certain pathological cases, the symtabs give the wrong
466 function (when we are in the first function in a file which
467 is compiled without debugging symbols, the previous function
468 is compiled with debugging symbols, and the "foo.o" symbol
469 that is supposed to tell us where the file with debugging symbols
470 ends has been truncated by ar because it is longer than 15
471 characters). This also occurs if the user uses asm() to create
472 a function but not stabs for it (in a file compiled -g).
474 So look in the minimal symbol tables as well, and if it comes
475 up with a larger address for the function use that instead.
476 I don't think this can ever cause any problems; there shouldn't
477 be any minimal symbols in the middle of a function; if this is
478 ever changed many parts of GDB will need to be changed (and we'll
479 create a find_pc_minimal_function or some such). */
481 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
483 && (SYMBOL_VALUE_ADDRESS (msymbol
)
484 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
487 /* There is no particular reason to think the line number
488 information is wrong. Someone might have just put in
489 a label with asm() but left the line numbers alone. */
490 /* In this case we have no way of knowing the source file
491 and line number, so don't print them. */
494 /* We also don't know anything about the function besides
495 its address and name. */
497 funname
= SYMBOL_NAME (msymbol
);
498 funlang
= SYMBOL_LANGUAGE (msymbol
);
502 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display the
503 demangled name that we already have stored in the symbol
504 table, but we stored a version with DMGL_PARAMS turned
505 on, and here we don't want to display parameters. So call
506 the demangler again, with DMGL_ANSI only. (Yes, I know
507 that printf_symbol_filtered() will again try to demangle
508 the name on the fly, but the issue is that if
509 cplus_demangle() fails here, it'll fail there too. So we
510 want to catch the failure ("demangled==NULL" case below)
511 here, while we still have our hands on the function
514 funname
= SYMBOL_NAME (func
);
515 funlang
= SYMBOL_LANGUAGE (func
);
516 if (funlang
== language_cplus
)
518 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
519 if (demangled
== NULL
)
520 /* If the demangler fails, try the demangled name from
521 the symbol table. This'll have parameters, but
522 that's preferable to diplaying a mangled name. */
523 funname
= SYMBOL_SOURCE_NAME (func
);
529 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
532 funname
= SYMBOL_NAME (msymbol
);
533 funlang
= SYMBOL_LANGUAGE (msymbol
);
537 annotate_frame_begin (level
== -1 ? 0 : level
, fi
->pc
);
541 printf_filtered ("#%-2d ", level
);
543 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
|| source
== LOC_AND_ADDRESS
)
545 annotate_frame_address ();
546 print_address_numeric (fi
->pc
, 1, gdb_stdout
);
547 annotate_frame_address_end ();
548 printf_filtered (" in ");
550 annotate_frame_function_name ();
551 fprintf_symbol_filtered (gdb_stdout
, funname
? funname
: "??", funlang
,
554 annotate_frame_args ();
556 fputs_filtered (" (", gdb_stdout
);
559 struct print_args_args args
;
562 args
.stream
= gdb_stdout
;
563 catch_errors (print_args_stub
, &args
, "", RETURN_MASK_ALL
);
566 printf_filtered (")");
567 if (sal
.symtab
&& sal
.symtab
->filename
)
569 annotate_frame_source_begin ();
571 printf_filtered (" at ");
572 annotate_frame_source_file ();
573 printf_filtered ("%s", sal
.symtab
->filename
);
574 annotate_frame_source_file_end ();
575 printf_filtered (":");
576 annotate_frame_source_line ();
577 printf_filtered ("%d", sal
.line
);
578 annotate_frame_source_end ();
581 #ifdef PC_LOAD_SEGMENT
582 /* If we couldn't print out function name but if can figure out what
583 load segment this pc value is from, at least print out some info
584 about its load segment. */
587 annotate_frame_where ();
589 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi
->pc
));
591 #endif /* PC_LOAD_SEGMENT */
594 if (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
))
596 char *lib
= PC_SOLIB (fi
->pc
);
599 annotate_frame_where ();
601 printf_filtered (" from %s", lib
);
604 #endif /* PC_SOLIB */
606 printf_filtered ("\n");
612 stack_publish_stopped_with_no_frame ()
614 TUIDO (((TuiOpaqueFuncPtr
) tuiUpdateOnEnd
));
620 /* Show or print the frame info. If this is the tui, it will be shown in
621 the source display */
623 print_frame_info (fi
, level
, source
, args
)
624 struct frame_info
*fi
;
630 print_frame_info_base (fi
, level
, source
, args
);
633 if (fi
&& (frame_in_dummy (fi
) || fi
->signal_handler_caller
))
634 print_frame_info_base (fi
, level
, source
, args
);
637 TUIDO (((TuiOpaqueFuncPtr
) tui_vShowFrameInfo
, fi
));
642 /* Show the frame info. If this is the tui, it will be shown in
643 the source display otherwise, nothing is done */
645 show_stack_frame (fi
)
646 struct frame_info
*fi
;
648 TUIDO (((TuiOpaqueFuncPtr
) tui_vShowFrameInfo
, fi
));
652 /* Read a frame specification in whatever the appropriate format is.
653 Call error() if the specification is in any way invalid (i.e.
654 this function never returns NULL). */
657 parse_frame_specification (frame_exp
)
662 CORE_ADDR args
[MAXARGS
];
666 char *addr_string
, *p
;
667 struct cleanup
*tmp_cleanup
;
669 while (*frame_exp
== ' ')
674 if (numargs
> MAXARGS
)
675 error ("Too many args in frame specification");
676 /* Parse an argument. */
677 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
679 addr_string
= savestring (frame_exp
, p
- frame_exp
);
682 tmp_cleanup
= make_cleanup (free
, addr_string
);
683 args
[numargs
++] = parse_and_eval_address (addr_string
);
684 do_cleanups (tmp_cleanup
);
687 /* Skip spaces, move to possible next arg. */
697 if (selected_frame
== NULL
)
698 error ("No selected frame.");
699 return selected_frame
;
704 struct frame_info
*fid
=
705 find_relative_frame (get_current_frame (), &level
);
706 struct frame_info
*tfid
;
709 /* find_relative_frame was successful */
712 /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
713 take at least 2 addresses. It is important to detect this case
714 here so that "frame 100" does not give a confusing error message
715 like "frame specification requires two addresses". This of course
716 does not solve the "frame 100" problem for machines on which
717 a frame specification can be made with one address. To solve
718 that, we need a new syntax for a specifying a frame by address.
719 I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
720 two args, etc.), but people might think that is too much typing,
721 so I guess *0x23,0x45 would be a possible alternative (commas
722 really should be used instead of spaces to delimit; using spaces
723 normally works in an expression). */
724 #ifdef SETUP_ARBITRARY_FRAME
725 error ("No frame %d", args
[0]);
728 /* If (s)he specifies the frame with an address, he deserves what
729 (s)he gets. Still, give the highest one that matches. */
731 for (fid
= get_current_frame ();
732 fid
&& fid
->frame
!= args
[0];
733 fid
= get_prev_frame (fid
))
737 while ((tfid
= get_prev_frame (fid
)) &&
738 (tfid
->frame
== args
[0]))
741 /* We couldn't identify the frame as an existing frame, but
742 perhaps we can create one with a single argument. */
746 #ifdef SETUP_ARBITRARY_FRAME
747 return SETUP_ARBITRARY_FRAME (numargs
, args
);
749 /* Usual case. Do it here rather than have everyone supply
750 a SETUP_ARBITRARY_FRAME that does this. */
752 return create_new_frame (args
[0], 0);
753 error ("Too many args in frame specification");
760 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
761 that if it is unsure about the answer, it returns 0
762 instead of guessing (this happens on the VAX and i960, for example).
764 On most machines, we never have to guess about the args address,
765 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
766 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
767 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
770 /* Print verbosely the selected frame or the frame at address ADDR.
771 This means absolutely all information in the frame is printed. */
774 frame_info (addr_exp
, from_tty
)
778 struct frame_info
*fi
;
779 struct symtab_and_line sal
;
782 struct frame_info
*calling_frame_info
;
783 int i
, count
, numregs
;
785 enum language funlang
= language_unknown
;
787 if (!target_has_stack
)
790 fi
= parse_frame_specification (addr_exp
);
792 error ("Invalid frame specified.");
794 sal
= find_pc_line (fi
->pc
,
796 && !fi
->next
->signal_handler_caller
797 && !frame_in_dummy (fi
->next
));
798 func
= get_frame_function (fi
);
799 s
= find_pc_symtab (fi
->pc
);
802 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display
803 * the demangled name that we already have stored in
804 * the symbol table, but we stored a version with
805 * DMGL_PARAMS turned on, and here we don't want
806 * to display parameters. So call the demangler again,
807 * with DMGL_ANSI only. RT
808 * (Yes, I know that printf_symbol_filtered() will
809 * again try to demangle the name on the fly, but
810 * the issue is that if cplus_demangle() fails here,
811 * it'll fail there too. So we want to catch the failure
812 * ("demangled==NULL" case below) here, while we still
813 * have our hands on the function symbol.)
816 funname
= SYMBOL_NAME (func
);
817 funlang
= SYMBOL_LANGUAGE (func
);
818 if (funlang
== language_cplus
)
820 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
821 /* If the demangler fails, try the demangled name
822 * from the symbol table. This'll have parameters,
823 * but that's preferable to diplaying a mangled name.
825 if (demangled
== NULL
)
826 funname
= SYMBOL_SOURCE_NAME (func
);
831 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
834 funname
= SYMBOL_NAME (msymbol
);
835 funlang
= SYMBOL_LANGUAGE (msymbol
);
838 calling_frame_info
= get_prev_frame (fi
);
840 if (!addr_exp
&& selected_frame_level
>= 0)
842 printf_filtered ("Stack level %d, frame at ", selected_frame_level
);
843 print_address_numeric (fi
->frame
, 1, gdb_stdout
);
844 printf_filtered (":\n");
848 printf_filtered ("Stack frame at ");
849 print_address_numeric (fi
->frame
, 1, gdb_stdout
);
850 printf_filtered (":\n");
852 printf_filtered (" %s = ", REGISTER_NAME (PC_REGNUM
));
853 print_address_numeric (fi
->pc
, 1, gdb_stdout
);
858 printf_filtered (" in ");
859 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
860 DMGL_ANSI
| DMGL_PARAMS
);
864 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
865 puts_filtered ("; ");
867 printf_filtered ("saved %s ", REGISTER_NAME (PC_REGNUM
));
868 print_address_numeric (FRAME_SAVED_PC (fi
), 1, gdb_stdout
);
869 printf_filtered ("\n");
873 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
875 printf_filtered (" (FRAMELESS),");
878 if (calling_frame_info
)
880 printf_filtered (" called by frame at ");
881 print_address_numeric (calling_frame_info
->frame
, 1, gdb_stdout
);
883 if (fi
->next
&& calling_frame_info
)
888 printf_filtered (" caller of frame at ");
889 print_address_numeric (fi
->next
->frame
, 1, gdb_stdout
);
891 if (fi
->next
|| calling_frame_info
)
892 puts_filtered ("\n");
894 printf_filtered (" source language %s.\n", language_str (s
->language
));
896 #ifdef PRINT_EXTRA_FRAME_INFO
897 PRINT_EXTRA_FRAME_INFO (fi
);
901 /* Address of the argument list for this frame, or 0. */
902 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
903 /* Number of args for this frame, or -1 if unknown. */
907 printf_filtered (" Arglist at unknown address.\n");
910 printf_filtered (" Arglist at ");
911 print_address_numeric (arg_list
, 1, gdb_stdout
);
912 printf_filtered (",");
914 numargs
= FRAME_NUM_ARGS (fi
);
916 puts_filtered (" args: ");
917 else if (numargs
== 0)
918 puts_filtered (" no args.");
919 else if (numargs
== 1)
920 puts_filtered (" 1 arg: ");
922 printf_filtered (" %d args: ", numargs
);
923 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
924 puts_filtered ("\n");
928 /* Address of the local variables for this frame, or 0. */
929 CORE_ADDR arg_list
= FRAME_LOCALS_ADDRESS (fi
);
932 printf_filtered (" Locals at unknown address,");
935 printf_filtered (" Locals at ");
936 print_address_numeric (arg_list
, 1, gdb_stdout
);
937 printf_filtered (",");
941 FRAME_INIT_SAVED_REGS (fi
);
942 if (fi
->saved_regs
!= NULL
)
944 /* The sp is special; what's returned isn't the save address, but
945 actually the value of the previous frame's sp. */
946 printf_filtered (" Previous frame's sp is ");
947 print_address_numeric (fi
->saved_regs
[SP_REGNUM
], 1, gdb_stdout
);
948 printf_filtered ("\n");
950 numregs
= ARCH_NUM_REGS
;
951 for (i
= 0; i
< numregs
; i
++)
952 if (fi
->saved_regs
[i
] && i
!= SP_REGNUM
)
955 puts_filtered (" Saved registers:\n ");
959 printf_filtered (" %s at ", REGISTER_NAME (i
));
960 print_address_numeric (fi
->saved_regs
[i
], 1, gdb_stdout
);
964 puts_filtered ("\n");
968 /* We could get some information about saved registers by
969 calling get_saved_register on each register. Which info goes
970 with which frame is necessarily lost, however, and I suspect
971 that the users don't care whether they get the info. */
972 puts_filtered ("\n");
977 /* Set a limit on the number of frames printed by default in a
980 static int backtrace_limit
;
983 set_backtrace_limit_command (count_exp
, from_tty
)
987 int count
= parse_and_eval_address (count_exp
);
990 error ("Negative argument not meaningful as backtrace limit.");
992 backtrace_limit
= count
;
996 backtrace_limit_info (arg
, from_tty
)
1001 error ("\"Info backtrace-limit\" takes no arguments.");
1003 printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit
);
1007 /* Print briefly all stack frames or just the innermost COUNT frames. */
1009 static void backtrace_command_1
PARAMS ((char *count_exp
, int show_locals
, int from_tty
));
1011 backtrace_command_1 (count_exp
, show_locals
, from_tty
)
1016 struct frame_info
*fi
;
1019 register struct frame_info
*trailing
;
1020 register int trailing_level
;
1022 if (!target_has_stack
)
1023 error ("No stack.");
1025 /* The following code must do two things. First, it must
1026 set the variable TRAILING to the frame from which we should start
1027 printing. Second, it must set the variable count to the number
1028 of frames which we should print, or -1 if all of them. */
1029 trailing
= get_current_frame ();
1033 count
= parse_and_eval_address (count_exp
);
1036 struct frame_info
*current
;
1041 while (current
&& count
--)
1044 current
= get_prev_frame (current
);
1047 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1048 will be COUNT below it. */
1052 trailing
= get_prev_frame (trailing
);
1053 current
= get_prev_frame (current
);
1065 struct partial_symtab
*ps
;
1067 /* Read in symbols for all of the frames. Need to do this in
1068 a separate pass so that "Reading in symbols for xxx" messages
1069 don't screw up the appearance of the backtrace. Also
1070 if people have strong opinions against reading symbols for
1071 backtrace this may have to be an option. */
1075 fi
= get_prev_frame (fi
))
1078 ps
= find_pc_psymtab (fi
->pc
);
1080 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
1084 for (i
= 0, fi
= trailing
;
1086 i
++, fi
= get_prev_frame (fi
))
1090 /* Don't use print_stack_frame; if an error() occurs it probably
1091 means further attempts to backtrace would fail (on the other
1092 hand, perhaps the code does or could be fixed to make sure
1093 the frame->prev field gets set to NULL in that case). */
1094 print_frame_info_base (fi
, trailing_level
+ i
, 0, 1);
1096 print_frame_local_vars (fi
, 1, gdb_stdout
);
1099 /* If we've stopped before the end, mention that. */
1101 printf_filtered ("(More stack frames follow...)\n");
1105 backtrace_command (arg
, from_tty
)
1109 struct cleanup
*old_chain
= (struct cleanup
*) NULL
;
1110 char **argv
= (char **) NULL
;
1111 int argIndicatingFullTrace
= (-1), totArgLen
= 0, argc
= 0;
1114 if (arg
!= (char *) NULL
)
1118 argv
= buildargv (arg
);
1119 old_chain
= make_cleanup_freeargv (argv
);
1121 for (i
= 0; (argv
[i
] != (char *) NULL
); i
++)
1125 for (j
= 0; (j
< strlen (argv
[i
])); j
++)
1126 argv
[i
][j
] = tolower (argv
[i
][j
]);
1128 if (argIndicatingFullTrace
< 0 && subset_compare (argv
[i
], "full"))
1129 argIndicatingFullTrace
= argc
;
1133 totArgLen
+= strlen (argv
[i
]);
1137 if (argIndicatingFullTrace
>= 0)
1141 argPtr
= (char *) xmalloc (totArgLen
+ 1);
1146 memset (argPtr
, 0, totArgLen
+ 1);
1147 for (i
= 0; (i
< (argc
+ 1)); i
++)
1149 if (i
!= argIndicatingFullTrace
)
1151 strcat (argPtr
, argv
[i
]);
1152 strcat (argPtr
, " ");
1158 argPtr
= (char *) NULL
;
1162 backtrace_command_1 (argPtr
, (argIndicatingFullTrace
>= 0), from_tty
);
1164 if (argIndicatingFullTrace
>= 0 && totArgLen
> 0)
1168 do_cleanups (old_chain
);
1171 static void backtrace_full_command
PARAMS ((char *arg
, int from_tty
));
1173 backtrace_full_command (arg
, from_tty
)
1177 backtrace_command_1 (arg
, 1, from_tty
);
1181 /* Print the local variables of a block B active in FRAME.
1182 Return 1 if any variables were printed; 0 otherwise. */
1185 print_block_frame_locals (b
, fi
, num_tabs
, stream
)
1187 register struct frame_info
*fi
;
1189 register struct ui_file
*stream
;
1193 register struct symbol
*sym
;
1194 register int values_printed
= 0;
1196 nsyms
= BLOCK_NSYMS (b
);
1198 for (i
= 0; i
< nsyms
; i
++)
1200 sym
= BLOCK_SYM (b
, i
);
1201 switch (SYMBOL_CLASS (sym
))
1208 for (j
= 0; j
< num_tabs
; j
++)
1209 fputs_filtered ("\t", stream
);
1210 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
1211 fputs_filtered (" = ", stream
);
1212 print_variable_value (sym
, fi
, stream
);
1213 fprintf_filtered (stream
, "\n");
1217 /* Ignore symbols which are not locals. */
1221 return values_printed
;
1224 /* Same, but print labels. */
1227 print_block_frame_labels (b
, have_default
, stream
)
1230 register struct ui_file
*stream
;
1234 register struct symbol
*sym
;
1235 register int values_printed
= 0;
1237 nsyms
= BLOCK_NSYMS (b
);
1239 for (i
= 0; i
< nsyms
; i
++)
1241 sym
= BLOCK_SYM (b
, i
);
1242 if (STREQ (SYMBOL_NAME (sym
), "default"))
1248 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1250 struct symtab_and_line sal
;
1251 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1253 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
1256 fprintf_filtered (stream
, " ");
1257 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, stream
);
1259 fprintf_filtered (stream
, " in file %s, line %d\n",
1260 sal
.symtab
->filename
, sal
.line
);
1263 return values_printed
;
1266 /* Print on STREAM all the local variables in frame FRAME,
1267 including all the blocks active in that frame
1270 Returns 1 if the job was done,
1271 or 0 if nothing was printed because we have no info
1272 on the function running in FRAME. */
1275 print_frame_local_vars (fi
, num_tabs
, stream
)
1276 register struct frame_info
*fi
;
1277 register int num_tabs
;
1278 register struct ui_file
*stream
;
1280 register struct block
*block
= get_frame_block (fi
);
1281 register int values_printed
= 0;
1285 fprintf_filtered (stream
, "No symbol table info available.\n");
1291 if (print_block_frame_locals (block
, fi
, num_tabs
, stream
))
1293 /* After handling the function's top-level block, stop.
1294 Don't continue to its superblock, the block of
1295 per-file symbols. */
1296 if (BLOCK_FUNCTION (block
))
1298 block
= BLOCK_SUPERBLOCK (block
);
1301 if (!values_printed
)
1303 fprintf_filtered (stream
, "No locals.\n");
1307 /* Same, but print labels. */
1310 print_frame_label_vars (fi
, this_level_only
, stream
)
1311 register struct frame_info
*fi
;
1312 int this_level_only
;
1313 register struct ui_file
*stream
;
1315 register struct blockvector
*bl
;
1316 register struct block
*block
= get_frame_block (fi
);
1317 register int values_printed
= 0;
1318 int index
, have_default
= 0;
1319 char *blocks_printed
;
1320 CORE_ADDR pc
= fi
->pc
;
1324 fprintf_filtered (stream
, "No symbol table info available.\n");
1328 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1329 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1330 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1334 CORE_ADDR end
= BLOCK_END (block
) - 4;
1337 if (bl
!= blockvector_for_pc (end
, &index
))
1338 error ("blockvector blotch");
1339 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1340 error ("blockvector botch");
1341 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1344 /* Don't print out blocks that have gone by. */
1345 while (index
< last_index
1346 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1349 while (index
< last_index
1350 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1352 if (blocks_printed
[index
] == 0)
1354 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
1356 blocks_printed
[index
] = 1;
1362 if (values_printed
&& this_level_only
)
1365 /* After handling the function's top-level block, stop.
1366 Don't continue to its superblock, the block of
1367 per-file symbols. */
1368 if (BLOCK_FUNCTION (block
))
1370 block
= BLOCK_SUPERBLOCK (block
);
1373 if (!values_printed
&& !this_level_only
)
1375 fprintf_filtered (stream
, "No catches.\n");
1381 locals_info (args
, from_tty
)
1385 if (!selected_frame
)
1386 error ("No frame selected.");
1387 print_frame_local_vars (selected_frame
, 0, gdb_stdout
);
1391 catch_info (ignore
, from_tty
)
1395 struct symtab_and_line
*sal
;
1397 /* Check for target support for exception handling */
1398 sal
= target_enable_exception_callback (EX_EVENT_CATCH
, 1);
1401 /* Currently not handling this */
1402 /* Ideally, here we should interact with the C++ runtime
1403 system to find the list of active handlers, etc. */
1404 fprintf_filtered (gdb_stdout
, "Info catch not supported with this target/compiler combination.\n");
1406 if (!selected_frame
)
1407 error ("No frame selected.");
1412 /* Assume g++ compiled code -- old v 4.16 behaviour */
1413 if (!selected_frame
)
1414 error ("No frame selected.");
1416 print_frame_label_vars (selected_frame
, 0, gdb_stdout
);
1421 print_frame_arg_vars (fi
, stream
)
1422 register struct frame_info
*fi
;
1423 register struct ui_file
*stream
;
1425 struct symbol
*func
= get_frame_function (fi
);
1426 register struct block
*b
;
1429 register struct symbol
*sym
, *sym2
;
1430 register int values_printed
= 0;
1434 fprintf_filtered (stream
, "No symbol table info available.\n");
1438 b
= SYMBOL_BLOCK_VALUE (func
);
1439 nsyms
= BLOCK_NSYMS (b
);
1441 for (i
= 0; i
< nsyms
; i
++)
1443 sym
= BLOCK_SYM (b
, i
);
1444 switch (SYMBOL_CLASS (sym
))
1450 case LOC_REGPARM_ADDR
:
1451 case LOC_BASEREG_ARG
:
1453 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
1454 fputs_filtered (" = ", stream
);
1456 /* We have to look up the symbol because arguments can have
1457 two entries (one a parameter, one a local) and the one we
1458 want is the local, which lookup_symbol will find for us.
1459 This includes gcc1 (not gcc2) on the sparc when passing a
1460 small structure and gcc2 when the argument type is float
1461 and it is passed as a double and converted to float by
1462 the prologue (in the latter case the type of the LOC_ARG
1463 symbol is double and the type of the LOC_LOCAL symbol is
1464 float). There are also LOC_ARG/LOC_REGISTER pairs which
1465 are not combined in symbol-reading. */
1467 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
1468 b
, VAR_NAMESPACE
, (int *) NULL
, (struct symtab
**) NULL
);
1469 print_variable_value (sym2
, fi
, stream
);
1470 fprintf_filtered (stream
, "\n");
1474 /* Don't worry about things which aren't arguments. */
1479 if (!values_printed
)
1481 fprintf_filtered (stream
, "No arguments.\n");
1486 args_info (ignore
, from_tty
)
1490 if (!selected_frame
)
1491 error ("No frame selected.");
1492 print_frame_arg_vars (selected_frame
, gdb_stdout
);
1497 args_plus_locals_info (ignore
, from_tty
)
1501 args_info (ignore
, from_tty
);
1502 locals_info (ignore
, from_tty
);
1506 /* Select frame FI, and note that its stack level is LEVEL.
1507 LEVEL may be -1 if an actual level number is not known. */
1510 select_frame (fi
, level
)
1511 struct frame_info
*fi
;
1514 register struct symtab
*s
;
1516 selected_frame
= fi
;
1517 selected_frame_level
= level
;
1518 if (selected_frame_level_changed_hook
)
1519 selected_frame_level_changed_hook (level
);
1521 /* Ensure that symbols for this frame are read in. Also, determine the
1522 source language of this frame, and switch to it if desired. */
1525 s
= find_pc_symtab (fi
->pc
);
1527 && s
->language
!= current_language
->la_language
1528 && s
->language
!= language_unknown
1529 && language_mode
== language_mode_auto
)
1531 set_language (s
->language
);
1533 /* elz: this if here fixes the problem with the pc not being displayed
1534 in the tui asm layout, with no debug symbols. The value of s
1535 would be 0 here, and select_source_symtab would abort the
1536 command by calling the 'error' function */
1539 TUIDO (((TuiOpaqueFuncPtr
) tui_vSelectSourceSymtab
, s
));
1545 /* Select frame FI, noting that its stack level is LEVEL. Also print
1546 the stack frame and show the source if this is the tui version. */
1548 select_and_print_frame (fi
, level
)
1549 struct frame_info
*fi
;
1552 select_frame (fi
, level
);
1555 print_stack_frame (fi
, level
, 1);
1556 TUIDO (((TuiOpaqueFuncPtr
) tui_vCheckDataValues
, fi
));
1561 /* Select frame FI, noting that its stack level is LEVEL. Be silent if
1565 select_and_maybe_print_frame (fi
, level
)
1566 struct frame_info
*fi
;
1570 select_frame (fi
, level
);
1572 select_and_print_frame (fi
, level
);
1577 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
1578 If there is no selected frame, *FRAMEP is set to NULL. */
1581 record_selected_frame (frameaddrp
, levelp
)
1582 CORE_ADDR
*frameaddrp
;
1585 *frameaddrp
= selected_frame
? selected_frame
->frame
: 0;
1586 *levelp
= selected_frame_level
;
1589 /* Return the symbol-block in which the selected frame is executing.
1590 Can return zero under various legitimate circumstances. */
1593 get_selected_block ()
1595 if (!target_has_stack
)
1598 if (!selected_frame
)
1599 return get_current_block ();
1600 return get_frame_block (selected_frame
);
1603 /* Find a frame a certain number of levels away from FRAME.
1604 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1605 Positive means go to earlier frames (up); negative, the reverse.
1606 The int that contains the number of levels is counted toward
1607 zero as the frames for those levels are found.
1608 If the top or bottom frame is reached, that frame is returned,
1609 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1610 how much farther the original request asked to go. */
1613 find_relative_frame (frame
, level_offset_ptr
)
1614 register struct frame_info
*frame
;
1615 register int *level_offset_ptr
;
1617 register struct frame_info
*prev
;
1618 register struct frame_info
*frame1
;
1620 /* Going up is simple: just do get_prev_frame enough times
1621 or until initial frame is reached. */
1622 while (*level_offset_ptr
> 0)
1624 prev
= get_prev_frame (frame
);
1627 (*level_offset_ptr
)--;
1630 /* Going down is just as simple. */
1631 if (*level_offset_ptr
< 0)
1633 while (*level_offset_ptr
< 0)
1635 frame1
= get_next_frame (frame
);
1639 (*level_offset_ptr
)++;
1645 /* The "select_frame" command. With no arg, NOP.
1646 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1647 valid level. Otherwise, treat level_exp as an address expression
1648 and select it. See parse_frame_specification for more info on proper
1649 frame expressions. */
1653 select_frame_command (level_exp
, from_tty
)
1657 register struct frame_info
*frame
, *frame1
;
1658 unsigned int level
= 0;
1660 if (!target_has_stack
)
1661 error ("No stack.");
1663 frame
= parse_frame_specification (level_exp
);
1665 /* Try to figure out what level this frame is. But if there is
1666 no current stack, don't error out -- let the user set one. */
1668 if (get_current_frame ())
1670 for (frame1
= get_prev_frame (0);
1671 frame1
&& frame1
!= frame
;
1672 frame1
= get_prev_frame (frame1
))
1679 select_frame (frame
, level
);
1682 /* The "frame" command. With no arg, print selected frame briefly.
1683 With arg, behaves like select_frame and then prints the selected
1687 frame_command (level_exp
, from_tty
)
1691 select_frame_command (level_exp
, from_tty
);
1692 show_and_print_stack_frame (selected_frame
, selected_frame_level
, 1);
1695 /* The XDB Compatibility command to print the current frame. */
1698 current_frame_command (level_exp
, from_tty
)
1702 if (target_has_stack
== 0 || selected_frame
== 0)
1703 error ("No stack.");
1704 print_only_stack_frame (selected_frame
, selected_frame_level
, 1);
1707 /* Select the frame up one or COUNT stack levels
1708 from the previously selected frame, and print it briefly. */
1712 up_silently_base (count_exp
)
1715 register struct frame_info
*fi
;
1716 int count
= 1, count1
;
1718 count
= parse_and_eval_address (count_exp
);
1721 if (target_has_stack
== 0 || selected_frame
== 0)
1722 error ("No stack.");
1724 fi
= find_relative_frame (selected_frame
, &count1
);
1725 if (count1
!= 0 && count_exp
== 0)
1726 error ("Initial frame selected; you cannot go up.");
1727 select_frame (fi
, selected_frame_level
+ count
- count1
);
1731 up_silently_command (count_exp
, from_tty
)
1735 up_silently_base (count_exp
);
1737 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1741 up_command (count_exp
, from_tty
)
1745 up_silently_base (count_exp
);
1746 show_and_print_stack_frame (selected_frame
, selected_frame_level
, 1);
1749 /* Select the frame down one or COUNT stack levels
1750 from the previously selected frame, and print it briefly. */
1754 down_silently_base (count_exp
)
1757 register struct frame_info
*frame
;
1758 int count
= -1, count1
;
1760 count
= -parse_and_eval_address (count_exp
);
1763 if (target_has_stack
== 0 || selected_frame
== 0)
1764 error ("No stack.");
1766 frame
= find_relative_frame (selected_frame
, &count1
);
1767 if (count1
!= 0 && count_exp
== 0)
1770 /* We only do this if count_exp is not specified. That way "down"
1771 means to really go down (and let me know if that is
1772 impossible), but "down 9999" can be used to mean go all the way
1773 down without getting an error. */
1775 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1778 select_frame (frame
, selected_frame_level
+ count
- count1
);
1783 down_silently_command (count_exp
, from_tty
)
1787 down_silently_base (count_exp
);
1789 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1793 down_command (count_exp
, from_tty
)
1797 down_silently_base (count_exp
);
1798 show_and_print_stack_frame (selected_frame
, selected_frame_level
, 1);
1802 return_command (retval_exp
, from_tty
)
1806 struct symbol
*thisfun
;
1807 CORE_ADDR selected_frame_addr
;
1808 CORE_ADDR selected_frame_pc
;
1809 struct frame_info
*frame
;
1810 value_ptr return_value
= NULL
;
1812 if (selected_frame
== NULL
)
1813 error ("No selected frame.");
1814 thisfun
= get_frame_function (selected_frame
);
1815 selected_frame_addr
= FRAME_FP (selected_frame
);
1816 selected_frame_pc
= selected_frame
->pc
;
1818 /* Compute the return value (if any -- possibly getting errors here). */
1822 struct type
*return_type
= NULL
;
1824 return_value
= parse_and_eval (retval_exp
);
1826 /* Cast return value to the return type of the function. */
1827 if (thisfun
!= NULL
)
1828 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
1829 if (return_type
== NULL
)
1830 return_type
= builtin_type_int
;
1831 return_value
= value_cast (return_type
, return_value
);
1833 /* Make sure we have fully evaluated it, since
1834 it might live in the stack frame we're about to pop. */
1835 if (VALUE_LAZY (return_value
))
1836 value_fetch_lazy (return_value
);
1839 /* If interactive, require confirmation. */
1845 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun
)))
1847 error ("Not confirmed.");
1851 else if (!query ("Make selected stack frame return now? "))
1852 error ("Not confirmed.");
1855 /* Do the real work. Pop until the specified frame is current. We
1856 use this method because the selected_frame is not valid after
1857 a POP_FRAME. The pc comparison makes this work even if the
1858 selected frame shares its fp with another frame. */
1860 while (selected_frame_addr
!= (frame
= get_current_frame ())->frame
1861 || selected_frame_pc
!= frame
->pc
)
1864 /* Then pop that frame. */
1868 /* Compute the return value (if any) and store in the place
1869 for return values. */
1872 set_return_value (return_value
);
1874 /* If interactive, print the frame that is now current. */
1877 frame_command ("0", 1);
1879 select_frame_command ("0", 0);
1882 /* Sets the scope to input function name, provided that the
1883 function is within the current stack frame */
1885 struct function_bounds
1887 CORE_ADDR low
, high
;
1890 static void func_command
PARAMS ((char *arg
, int from_tty
));
1892 func_command (arg
, from_tty
)
1896 struct frame_info
*fp
;
1898 struct symtabs_and_lines sals
;
1901 struct function_bounds
*func_bounds
= (struct function_bounds
*) NULL
;
1903 if (arg
!= (char *) NULL
)
1906 fp
= parse_frame_specification ("0");
1907 sals
= decode_line_spec (arg
, 1);
1908 func_bounds
= (struct function_bounds
*) xmalloc (
1909 sizeof (struct function_bounds
) * sals
.nelts
);
1910 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1912 if (sals
.sals
[i
].pc
== (CORE_ADDR
) 0 ||
1913 find_pc_partial_function (sals
.sals
[i
].pc
,
1915 &func_bounds
[i
].low
,
1916 &func_bounds
[i
].high
) == 0)
1918 func_bounds
[i
].low
=
1919 func_bounds
[i
].high
= (CORE_ADDR
) NULL
;
1925 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1926 found
= (fp
->pc
>= func_bounds
[i
].low
&&
1927 fp
->pc
< func_bounds
[i
].high
);
1931 fp
= find_relative_frame (fp
, &level
);
1934 while (!found
&& level
== 0);
1940 printf_filtered ("'%s' not within current stack frame.\n", arg
);
1941 else if (fp
!= selected_frame
)
1942 select_and_print_frame (fp
, level
);
1945 /* Gets the language of the current frame. */
1948 get_frame_language ()
1950 register struct symtab
*s
;
1951 enum language flang
; /* The language of the current frame */
1955 s
= find_pc_symtab (selected_frame
->pc
);
1957 flang
= s
->language
;
1959 flang
= language_unknown
;
1962 flang
= language_unknown
;
1968 _initialize_stack ()
1971 backtrace_limit
= 30;
1974 add_com ("return", class_stack
, return_command
,
1975 "Make selected stack frame return to its caller.\n\
1976 Control remains in the debugger, but when you continue\n\
1977 execution will resume in the frame above the one now selected.\n\
1978 If an argument is given, it is an expression for the value to return.");
1980 add_com ("up", class_stack
, up_command
,
1981 "Select and print stack frame that called this one.\n\
1982 An argument says how many frames up to go.");
1983 add_com ("up-silently", class_support
, up_silently_command
,
1984 "Same as the `up' command, but does not print anything.\n\
1985 This is useful in command scripts.");
1987 add_com ("down", class_stack
, down_command
,
1988 "Select and print stack frame called by this one.\n\
1989 An argument says how many frames down to go.");
1990 add_com_alias ("do", "down", class_stack
, 1);
1991 add_com_alias ("dow", "down", class_stack
, 1);
1992 add_com ("down-silently", class_support
, down_silently_command
,
1993 "Same as the `down' command, but does not print anything.\n\
1994 This is useful in command scripts.");
1996 add_com ("frame", class_stack
, frame_command
,
1997 "Select and print a stack frame.\n\
1998 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1999 An argument specifies the frame to select.\n\
2000 It can be a stack frame number or the address of the frame.\n\
2001 With argument, nothing is printed if input is coming from\n\
2002 a command file or a user-defined command.");
2004 add_com_alias ("f", "frame", class_stack
, 1);
2008 add_com ("L", class_stack
, current_frame_command
,
2009 "Print the current stack frame.\n");
2010 add_com_alias ("V", "frame", class_stack
, 1);
2012 add_com ("select-frame", class_stack
, select_frame_command
,
2013 "Select a stack frame without printing anything.\n\
2014 An argument specifies the frame to select.\n\
2015 It can be a stack frame number or the address of the frame.\n");
2017 add_com ("backtrace", class_stack
, backtrace_command
,
2018 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
2019 With a negative argument, print outermost -COUNT frames.\n\
2020 Use of the 'full' qualifier also prints the values of the local variables.\n");
2021 add_com_alias ("bt", "backtrace", class_stack
, 0);
2024 add_com_alias ("t", "backtrace", class_stack
, 0);
2025 add_com ("T", class_stack
, backtrace_full_command
,
2026 "Print backtrace of all stack frames, or innermost COUNT frames \n\
2027 and the values of the local variables.\n\
2028 With a negative argument, print outermost -COUNT frames.\n\
2029 Usage: T <count>\n");
2032 add_com_alias ("where", "backtrace", class_alias
, 0);
2033 add_info ("stack", backtrace_command
,
2034 "Backtrace of the stack, or innermost COUNT frames.");
2035 add_info_alias ("s", "stack", 1);
2036 add_info ("frame", frame_info
,
2037 "All about selected stack frame, or frame at ADDR.");
2038 add_info_alias ("f", "frame", 1);
2039 add_info ("locals", locals_info
,
2040 "Local variables of current stack frame.");
2041 add_info ("args", args_info
,
2042 "Argument variables of current stack frame.");
2044 add_com ("l", class_info
, args_plus_locals_info
,
2045 "Argument and local variables of current stack frame.");
2048 add_com ("func", class_stack
, func_command
,
2049 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2051 add_info ("catch", catch_info
,
2052 "Exceptions that can be caught in the current stack frame.");
2055 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
2056 "Specify maximum number of frames for \"backtrace\" to print by default.",
2058 add_info ("backtrace-limit", backtrace_limit_info
,
2059 "The maximum number of frames for \"backtrace\" to print by default.");