1 /* Print and select stack frames for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
30 #include "expression.h"
37 #include "breakpoint.h"
43 /* Prototypes for exported functions. */
45 void args_info (char *, int);
47 void locals_info (char *, int);
49 void (*selected_frame_level_changed_hook
) (int);
51 void _initialize_stack (void);
53 void return_command (char *, int);
55 /* Prototypes for local functions. */
57 static void down_command (char *, int);
59 static void down_silently_base (char *);
61 static void down_silently_command (char *, int);
63 static void up_command (char *, int);
65 static void up_silently_base (char *);
67 static void up_silently_command (char *, int);
69 void frame_command (char *, int);
71 static void current_frame_command (char *, int);
73 static void select_frame_command (char *, int);
75 static void print_frame_arg_vars (struct frame_info
*, struct ui_file
*);
77 static void catch_info (char *, int);
79 static void args_plus_locals_info (char *, int);
81 static void print_frame_label_vars (struct frame_info
*, int,
84 static void print_frame_local_vars (struct frame_info
*, int,
87 static int print_block_frame_labels (struct block
*, int *,
90 static int print_block_frame_locals (struct block
*,
95 static void print_frame (struct frame_info
*fi
,
99 struct symtab_and_line sal
);
101 static void print_frame_info_base (struct frame_info
*, int, int, int);
103 static void print_stack_frame_base (struct frame_info
*, int, int);
105 static void backtrace_command (char *, int);
107 struct frame_info
*parse_frame_specification (char *);
109 static void frame_info (char *, int);
111 extern int addressprint
; /* Print addresses, or stay symbolic only? */
113 /* Zero means do things normally; we are interacting directly with the
114 user. One means print the full filename and linenumber when a
115 frame is printed, and do so in a format emacs18/emacs19.22 can
116 parse. Two means print similar annotations, but in many more
117 cases and in a slightly different syntax. */
119 int annotation_level
= 0;
122 struct print_stack_frame_args
124 struct frame_info
*fi
;
130 static int print_stack_frame_base_stub (char *);
132 /* Show and print the frame arguments.
133 Pass the args the way catch_errors wants them. */
134 static int show_and_print_stack_frame_stub (void *args
);
136 show_and_print_stack_frame_stub (void *args
)
138 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
140 print_frame_info (p
->fi
, p
->level
, p
->source
, p
->args
);
145 /* Show or print the frame arguments.
146 Pass the args the way catch_errors wants them. */
147 static int print_stack_frame_stub (void *args
);
149 print_stack_frame_stub (void *args
)
151 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
153 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
157 /* Print a stack frame briefly. FRAME_INFI should be the frame info
158 and LEVEL should be its level in the stack (or -1 for level not
161 /* Pass the args the way catch_errors wants them. */
163 print_stack_frame_base_stub (char *args
)
165 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
167 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
171 /* print the frame arguments to the terminal.
172 Pass the args the way catch_errors wants them. */
173 static int print_only_stack_frame_stub (void *);
175 print_only_stack_frame_stub (void *args
)
177 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
179 print_frame_info_base (p
->fi
, p
->level
, p
->source
, p
->args
);
183 /* Print a stack frame briefly. FRAME_INFI should be the frame info
184 and LEVEL should be its level in the stack (or -1 for level not defined).
185 This prints the level, the function executing, the arguments,
186 and the file name and line number.
187 If the pc is not at the beginning of the source line,
188 the actual pc is printed at the beginning.
190 If SOURCE is 1, print the source line as well.
191 If SOURCE is -1, print ONLY the source line. */
194 print_stack_frame_base (struct frame_info
*fi
, int level
, int source
)
196 struct print_stack_frame_args args
;
200 args
.source
= source
;
203 catch_errors (print_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
206 /* Show and print a stack frame briefly. FRAME_INFI should be the frame info
207 and LEVEL should be its level in the stack (or -1 for level not defined).
208 This prints the level, the function executing, the arguments,
209 and the file name and line number.
210 If the pc is not at the beginning of the source line,
211 the actual pc is printed at the beginning.
213 If SOURCE is 1, print the source line as well.
214 If SOURCE is -1, print ONLY the source line. */
217 show_and_print_stack_frame (struct frame_info
*fi
, int level
, int source
)
219 struct print_stack_frame_args args
;
223 args
.source
= source
;
226 catch_errors (show_and_print_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
230 /* Show or print a stack frame briefly. FRAME_INFI should be the frame info
231 and LEVEL should be its level in the stack (or -1 for level not defined).
232 This prints the level, the function executing, the arguments,
233 and the file name and line number.
234 If the pc is not at the beginning of the source line,
235 the actual pc is printed at the beginning.
237 If SOURCE is 1, print the source line as well.
238 If SOURCE is -1, print ONLY the source line. */
241 print_stack_frame (struct frame_info
*fi
, int level
, int source
)
243 struct print_stack_frame_args args
;
247 args
.source
= source
;
250 catch_errors (print_stack_frame_stub
, (char *) &args
, "", RETURN_MASK_ALL
);
253 /* Print a stack frame briefly. FRAME_INFI should be the frame info
254 and LEVEL should be its level in the stack (or -1 for level not defined).
255 This prints the level, the function executing, the arguments,
256 and the file name and line number.
257 If the pc is not at the beginning of the source line,
258 the actual pc is printed at the beginning.
260 If SOURCE is 1, print the source line as well.
261 If SOURCE is -1, print ONLY the source line. */
264 print_only_stack_frame (struct frame_info
*fi
, int level
, int source
)
266 struct print_stack_frame_args args
;
270 args
.source
= source
;
273 catch_errors (print_only_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
276 struct print_args_args
279 struct frame_info
*fi
;
280 struct ui_file
*stream
;
283 static int print_args_stub (PTR
);
285 /* Pass the args the way catch_errors wants them. */
288 print_args_stub (PTR args
)
291 struct print_args_args
*p
= (struct print_args_args
*) args
;
293 numargs
= FRAME_NUM_ARGS (p
->fi
);
294 print_frame_args (p
->func
, p
->fi
, numargs
, p
->stream
);
298 /* Print information about a frame for frame "fi" at level "level".
299 Used in "where" output, also used to emit breakpoint or step
301 LEVEL is the level of the frame, or -1 if it is the
302 innermost frame but we don't want to print the level.
303 The meaning of the SOURCE argument is:
304 SRC_LINE: Print only source line
305 LOCATION: Print only location
306 LOC_AND_SRC: Print location and source line. */
309 print_frame_info_base (struct frame_info
*fi
, int level
, int source
, int args
)
311 struct symtab_and_line sal
;
315 if (get_frame_type (fi
) == DUMMY_FRAME
)
317 annotate_frame_begin (level
== -1 ? 0 : level
, fi
->pc
);
319 /* Do this regardless of SOURCE because we don't have any source
320 to list for this frame. */
323 ui_out_text (uiout
, "#");
324 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level", level
);
326 annotate_function_call ();
327 printf_filtered ("<function called from gdb>\n");
328 annotate_frame_end ();
331 if ((get_frame_type (fi
) == SIGTRAMP_FRAME
))
333 annotate_frame_begin (level
== -1 ? 0 : level
, fi
->pc
);
335 /* Do this regardless of SOURCE because we don't have any source
336 to list for this frame. */
339 ui_out_text (uiout
, "#");
340 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level", level
);
342 annotate_signal_handler_caller ();
343 printf_filtered ("<signal handler called>\n");
344 annotate_frame_end ();
348 /* If fi is not the innermost frame, that normally means that fi->pc
349 points to *after* the call instruction, and we want to get the
350 line containing the call, never the next line. But if the next
351 frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame
352 was not entered as the result of a call, and we want to get the
353 line containing fi->pc. */
354 find_frame_sal (fi
, &sal
);
356 location_print
= (source
== LOCATION
357 || source
== LOC_AND_ADDRESS
358 || source
== SRC_AND_LOC
);
360 if (location_print
|| !sal
.symtab
)
361 print_frame (fi
, level
, source
, args
, sal
);
363 source_print
= (source
== SRC_LINE
|| source
== SRC_AND_LOC
);
366 set_current_source_symtab_and_line (&sal
);
368 if (source_print
&& sal
.symtab
)
370 struct symtab_and_line cursal
;
372 int mid_statement
= (source
== SRC_LINE
) && (fi
->pc
!= sal
.pc
);
374 if (annotation_level
)
375 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
379 if (print_frame_info_listing_hook
)
380 print_frame_info_listing_hook (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
383 /* We used to do this earlier, but that is clearly
384 wrong. This function is used by many different
385 parts of gdb, including normal_stop in infrun.c,
386 which uses this to print out the current PC
387 when we stepi/nexti into the middle of a source
388 line. Only the command line really wants this
389 behavior. Other UIs probably would like the
390 ability to decide for themselves if it is desired. */
391 if (addressprint
&& mid_statement
)
393 ui_out_field_core_addr (uiout
, "addr", fi
->pc
);
394 ui_out_text (uiout
, "\t");
397 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
400 /* Make sure we have at least a default source file */
401 set_default_source_symtab_and_line ();
402 cursal
= get_current_source_symtab_and_line ();
403 cursal
.line
= max (sal
.line
- get_lines_to_list () / 2, 1);
404 set_current_source_symtab_and_line (&cursal
);
408 set_default_breakpoint (1, fi
->pc
, sal
.symtab
, sal
.line
);
410 annotate_frame_end ();
412 gdb_flush (gdb_stdout
);
416 print_frame (struct frame_info
*fi
,
420 struct symtab_and_line sal
)
423 register char *funname
= 0;
424 enum language funlang
= language_unknown
;
425 struct ui_stream
*stb
;
426 struct cleanup
*old_chain
;
427 struct cleanup
*list_chain
;
429 stb
= ui_out_stream_new (uiout
);
430 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
432 func
= find_pc_function (frame_address_in_block (fi
));
435 /* In certain pathological cases, the symtabs give the wrong
436 function (when we are in the first function in a file which
437 is compiled without debugging symbols, the previous function
438 is compiled with debugging symbols, and the "foo.o" symbol
439 that is supposed to tell us where the file with debugging symbols
440 ends has been truncated by ar because it is longer than 15
441 characters). This also occurs if the user uses asm() to create
442 a function but not stabs for it (in a file compiled -g).
444 So look in the minimal symbol tables as well, and if it comes
445 up with a larger address for the function use that instead.
446 I don't think this can ever cause any problems; there shouldn't
447 be any minimal symbols in the middle of a function; if this is
448 ever changed many parts of GDB will need to be changed (and we'll
449 create a find_pc_minimal_function or some such). */
451 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (frame_address_in_block (fi
));
453 && (SYMBOL_VALUE_ADDRESS (msymbol
)
454 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
457 /* There is no particular reason to think the line number
458 information is wrong. Someone might have just put in
459 a label with asm() but left the line numbers alone. */
460 /* In this case we have no way of knowing the source file
461 and line number, so don't print them. */
464 /* We also don't know anything about the function besides
465 its address and name. */
467 funname
= SYMBOL_NAME (msymbol
);
468 funlang
= SYMBOL_LANGUAGE (msymbol
);
472 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display the
473 demangled name that we already have stored in the symbol
474 table, but we stored a version with DMGL_PARAMS turned
475 on, and here we don't want to display parameters. So call
476 the demangler again, with DMGL_ANSI only. (Yes, I know
477 that printf_symbol_filtered() will again try to demangle
478 the name on the fly, but the issue is that if
479 cplus_demangle() fails here, it'll fail there too. So we
480 want to catch the failure ("demangled==NULL" case below)
481 here, while we still have our hands on the function
484 funname
= SYMBOL_NAME (func
);
485 funlang
= SYMBOL_LANGUAGE (func
);
486 if (funlang
== language_cplus
)
488 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
489 if (demangled
== NULL
)
490 /* If the demangler fails, try the demangled name from
491 the symbol table. This'll have parameters, but
492 that's preferable to diplaying a mangled name. */
493 funname
= SYMBOL_SOURCE_NAME (func
);
499 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (frame_address_in_block (fi
));
502 funname
= SYMBOL_NAME (msymbol
);
503 funlang
= SYMBOL_LANGUAGE (msymbol
);
507 annotate_frame_begin (level
== -1 ? 0 : level
, fi
->pc
);
509 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
513 ui_out_text (uiout
, "#");
514 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level", level
);
517 if (fi
->pc
!= sal
.pc
|| !sal
.symtab
|| source
== LOC_AND_ADDRESS
)
519 annotate_frame_address ();
520 ui_out_field_core_addr (uiout
, "addr", fi
->pc
);
521 annotate_frame_address_end ();
522 ui_out_text (uiout
, " in ");
524 annotate_frame_function_name ();
525 fprintf_symbol_filtered (stb
->stream
, funname
? funname
: "??", funlang
,
527 ui_out_field_stream (uiout
, "func", stb
);
528 ui_out_wrap_hint (uiout
, " ");
529 annotate_frame_args ();
531 ui_out_text (uiout
, " (");
534 struct print_args_args args
;
535 struct cleanup
*args_list_chain
;
538 args
.stream
= gdb_stdout
;
539 args_list_chain
= make_cleanup_ui_out_list_begin_end (uiout
, "args");
540 catch_errors (print_args_stub
, &args
, "", RETURN_MASK_ALL
);
541 /* FIXME: args must be a list. If one argument is a string it will
542 have " that will not be properly escaped. */
543 /* Invoke ui_out_tuple_end. */
544 do_cleanups (args_list_chain
);
547 ui_out_text (uiout
, ")");
548 if (sal
.symtab
&& sal
.symtab
->filename
)
550 annotate_frame_source_begin ();
551 ui_out_wrap_hint (uiout
, " ");
552 ui_out_text (uiout
, " at ");
553 annotate_frame_source_file ();
554 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
555 annotate_frame_source_file_end ();
556 ui_out_text (uiout
, ":");
557 annotate_frame_source_line ();
558 ui_out_field_int (uiout
, "line", sal
.line
);
559 annotate_frame_source_end ();
563 if (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
))
565 char *lib
= PC_SOLIB (fi
->pc
);
568 annotate_frame_where ();
569 ui_out_wrap_hint (uiout
, " ");
570 ui_out_text (uiout
, " from ");
571 ui_out_field_string (uiout
, "from", lib
);
574 #endif /* PC_SOLIB */
576 /* do_cleanups will call ui_out_tuple_end() for us. */
577 do_cleanups (list_chain
);
578 ui_out_text (uiout
, "\n");
579 do_cleanups (old_chain
);
583 /* Show or print the frame info. If this is the tui, it will be shown in
584 the source display */
586 print_frame_info (struct frame_info
*fi
, register int level
, int source
,
589 print_frame_info_base (fi
, level
, source
, args
);
592 /* Show the frame info. If this is the tui, it will be shown in
593 the source display otherwise, nothing is done */
595 show_stack_frame (struct frame_info
*fi
)
600 /* Read a frame specification in whatever the appropriate format is.
601 Call error() if the specification is in any way invalid (i.e.
602 this function never returns NULL). */
605 parse_frame_specification (char *frame_exp
)
609 CORE_ADDR args
[MAXARGS
];
614 char *addr_string
, *p
;
615 struct cleanup
*tmp_cleanup
;
617 while (*frame_exp
== ' ')
622 if (numargs
> MAXARGS
)
623 error ("Too many args in frame specification");
624 /* Parse an argument. */
625 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
627 addr_string
= savestring (frame_exp
, p
- frame_exp
);
632 tmp_cleanup
= make_cleanup (xfree
, addr_string
);
634 /* NOTE: we call parse_and_eval and then both
635 value_as_long and value_as_address rather than calling
636 parse_and_eval_long and parse_and_eval_address because
637 of the issue of potential side effects from evaluating
639 vp
= parse_and_eval (addr_string
);
641 level
= value_as_long (vp
);
643 args
[numargs
++] = value_as_address (vp
);
644 do_cleanups (tmp_cleanup
);
647 /* Skip spaces, move to possible next arg. */
657 if (deprecated_selected_frame
== NULL
)
658 error ("No selected frame.");
659 return deprecated_selected_frame
;
663 struct frame_info
*fid
=
664 find_relative_frame (get_current_frame (), &level
);
665 struct frame_info
*tfid
;
668 /* find_relative_frame was successful */
671 /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
672 take at least 2 addresses. It is important to detect this case
673 here so that "frame 100" does not give a confusing error message
674 like "frame specification requires two addresses". This of course
675 does not solve the "frame 100" problem for machines on which
676 a frame specification can be made with one address. To solve
677 that, we need a new syntax for a specifying a frame by address.
678 I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
679 two args, etc.), but people might think that is too much typing,
680 so I guess *0x23,0x45 would be a possible alternative (commas
681 really should be used instead of spaces to delimit; using spaces
682 normally works in an expression). */
683 #ifdef SETUP_ARBITRARY_FRAME
684 error ("No frame %s", paddr_d (args
[0]));
687 /* If (s)he specifies the frame with an address, he deserves what
688 (s)he gets. Still, give the highest one that matches. */
690 for (fid
= get_current_frame ();
691 fid
&& get_frame_base (fid
) != args
[0];
692 fid
= get_prev_frame (fid
))
696 while ((tfid
= get_prev_frame (fid
)) &&
697 (get_frame_base (tfid
) == args
[0]))
700 /* We couldn't identify the frame as an existing frame, but
701 perhaps we can create one with a single argument. */
705 #ifdef SETUP_ARBITRARY_FRAME
706 return SETUP_ARBITRARY_FRAME (numargs
, args
);
708 /* Usual case. Do it here rather than have everyone supply
709 a SETUP_ARBITRARY_FRAME that does this. */
711 return create_new_frame (args
[0], 0);
712 error ("Too many args in frame specification");
719 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
720 that if it is unsure about the answer, it returns 0
721 instead of guessing (this happens on the VAX and i960, for example).
723 On most machines, we never have to guess about the args address,
724 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
725 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
726 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
729 /* Print verbosely the selected frame or the frame at address ADDR.
730 This means absolutely all information in the frame is printed. */
733 frame_info (char *addr_exp
, int from_tty
)
735 struct frame_info
*fi
;
736 struct symtab_and_line sal
;
739 struct frame_info
*calling_frame_info
;
740 int i
, count
, numregs
;
742 enum language funlang
= language_unknown
;
744 if (!target_has_stack
)
747 fi
= parse_frame_specification (addr_exp
);
749 error ("Invalid frame specified.");
751 find_frame_sal (fi
, &sal
);
752 func
= get_frame_function (fi
);
753 /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain
755 s
= find_pc_symtab (fi
->pc
);
758 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display
759 * the demangled name that we already have stored in
760 * the symbol table, but we stored a version with
761 * DMGL_PARAMS turned on, and here we don't want
762 * to display parameters. So call the demangler again,
763 * with DMGL_ANSI only. RT
764 * (Yes, I know that printf_symbol_filtered() will
765 * again try to demangle the name on the fly, but
766 * the issue is that if cplus_demangle() fails here,
767 * it'll fail there too. So we want to catch the failure
768 * ("demangled==NULL" case below) here, while we still
769 * have our hands on the function symbol.)
772 funname
= SYMBOL_NAME (func
);
773 funlang
= SYMBOL_LANGUAGE (func
);
774 if (funlang
== language_cplus
)
776 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
777 /* If the demangler fails, try the demangled name
778 * from the symbol table. This'll have parameters,
779 * but that's preferable to diplaying a mangled name.
781 if (demangled
== NULL
)
782 funname
= SYMBOL_SOURCE_NAME (func
);
787 register struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (fi
->pc
);
790 funname
= SYMBOL_NAME (msymbol
);
791 funlang
= SYMBOL_LANGUAGE (msymbol
);
794 calling_frame_info
= get_prev_frame (fi
);
796 if (!addr_exp
&& frame_relative_level (deprecated_selected_frame
) >= 0)
798 printf_filtered ("Stack level %d, frame at ",
799 frame_relative_level (deprecated_selected_frame
));
800 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
801 printf_filtered (":\n");
805 printf_filtered ("Stack frame at ");
806 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
807 printf_filtered (":\n");
809 printf_filtered (" %s = ", REGISTER_NAME (PC_REGNUM
));
810 print_address_numeric (fi
->pc
, 1, gdb_stdout
);
815 printf_filtered (" in ");
816 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
817 DMGL_ANSI
| DMGL_PARAMS
);
821 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
822 puts_filtered ("; ");
824 printf_filtered ("saved %s ", REGISTER_NAME (PC_REGNUM
));
825 print_address_numeric (frame_pc_unwind (fi
), 1, gdb_stdout
);
826 printf_filtered ("\n");
830 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
832 printf_filtered (" (FRAMELESS),");
835 if (calling_frame_info
)
837 printf_filtered (" called by frame at ");
838 print_address_numeric (get_frame_base (calling_frame_info
),
841 if (get_next_frame (fi
) && calling_frame_info
)
844 if (get_next_frame (fi
))
846 printf_filtered (" caller of frame at ");
847 print_address_numeric (get_frame_base (get_next_frame (fi
)), 1,
850 if (get_next_frame (fi
) || calling_frame_info
)
851 puts_filtered ("\n");
853 printf_filtered (" source language %s.\n",
854 language_str (s
->language
));
856 #ifdef PRINT_EXTRA_FRAME_INFO
857 PRINT_EXTRA_FRAME_INFO (fi
);
861 /* Address of the argument list for this frame, or 0. */
862 CORE_ADDR arg_list
= FRAME_ARGS_ADDRESS_CORRECT (fi
);
863 /* Number of args for this frame, or -1 if unknown. */
867 printf_filtered (" Arglist at unknown address.\n");
870 printf_filtered (" Arglist at ");
871 print_address_numeric (arg_list
, 1, gdb_stdout
);
872 printf_filtered (",");
874 numargs
= FRAME_NUM_ARGS (fi
);
876 puts_filtered (" args: ");
877 else if (numargs
== 0)
878 puts_filtered (" no args.");
879 else if (numargs
== 1)
880 puts_filtered (" 1 arg: ");
882 printf_filtered (" %d args: ", numargs
);
883 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
884 puts_filtered ("\n");
888 /* Address of the local variables for this frame, or 0. */
889 CORE_ADDR arg_list
= FRAME_LOCALS_ADDRESS (fi
);
892 printf_filtered (" Locals at unknown address,");
895 printf_filtered (" Locals at ");
896 print_address_numeric (arg_list
, 1, gdb_stdout
);
897 printf_filtered (",");
901 if (fi
->saved_regs
== NULL
)
902 FRAME_INIT_SAVED_REGS (fi
);
903 /* Print as much information as possible on the location of all the
914 /* The sp is special; what's displayed isn't the save address, but
915 the value of the previous frame's sp. This is a legacy thing,
916 at one stage the frame cached the previous frame's SP instead
917 of its address, hence it was easiest to just display the cached
921 /* Find out the location of the saved stack pointer with out
922 actually evaluating it. */
923 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
925 if (!optimized
&& lval
== not_lval
)
927 void *value
= alloca (MAX_REGISTER_RAW_SIZE
);
929 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
931 sp
= extract_address (value
, REGISTER_RAW_SIZE (SP_REGNUM
));
932 printf_filtered (" Previous frame's sp is ");
933 print_address_numeric (sp
, 1, gdb_stdout
);
934 printf_filtered ("\n");
937 else if (!optimized
&& lval
== lval_memory
)
939 printf_filtered (" Previous frame's sp at ");
940 print_address_numeric (addr
, 1, gdb_stdout
);
941 printf_filtered ("\n");
944 else if (!optimized
&& lval
== lval_register
)
946 printf_filtered (" Previous frame's sp in %s\n",
947 REGISTER_NAME (realnum
));
950 /* else keep quiet. */
954 numregs
= NUM_REGS
+ NUM_PSEUDO_REGS
;
955 for (i
= 0; i
< numregs
; i
++)
958 /* Find out the location of the saved register without
959 fetching the corresponding value. */
960 frame_register_unwind (fi
, i
, &optimized
, &lval
, &addr
, &realnum
,
962 /* For moment, only display registers that were saved on the
964 if (!optimized
&& lval
== lval_memory
)
967 puts_filtered (" Saved registers:\n ");
971 printf_filtered (" %s at ", REGISTER_NAME (i
));
972 print_address_numeric (addr
, 1, gdb_stdout
);
976 if (count
|| need_nl
)
977 puts_filtered ("\n");
982 /* Set a limit on the number of frames printed by default in a
985 static int backtrace_limit
;
988 set_backtrace_limit_command (char *count_exp
, int from_tty
)
990 int count
= parse_and_eval_long (count_exp
);
993 error ("Negative argument not meaningful as backtrace limit.");
995 backtrace_limit
= count
;
999 backtrace_limit_info (char *arg
, int from_tty
)
1002 error ("\"Info backtrace-limit\" takes no arguments.");
1004 printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit
);
1008 /* Print briefly all stack frames or just the innermost COUNT frames. */
1010 static void backtrace_command_1 (char *count_exp
, int show_locals
,
1013 backtrace_command_1 (char *count_exp
, int show_locals
, int from_tty
)
1015 struct frame_info
*fi
;
1018 register struct frame_info
*trailing
;
1019 register int trailing_level
;
1021 if (!target_has_stack
)
1022 error ("No stack.");
1024 /* The following code must do two things. First, it must
1025 set the variable TRAILING to the frame from which we should start
1026 printing. Second, it must set the variable count to the number
1027 of frames which we should print, or -1 if all of them. */
1028 trailing
= get_current_frame ();
1030 /* The target can be in a state where there is no valid frames
1031 (e.g., just connected). */
1032 if (trailing
== NULL
)
1033 error ("No stack.");
1038 count
= parse_and_eval_long (count_exp
);
1041 struct frame_info
*current
;
1046 while (current
&& count
--)
1049 current
= get_prev_frame (current
);
1052 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1053 will be COUNT below it. */
1057 trailing
= get_prev_frame (trailing
);
1058 current
= get_prev_frame (current
);
1070 struct partial_symtab
*ps
;
1072 /* Read in symbols for all of the frames. Need to do this in
1073 a separate pass so that "Reading in symbols for xxx" messages
1074 don't screw up the appearance of the backtrace. Also
1075 if people have strong opinions against reading symbols for
1076 backtrace this may have to be an option. */
1080 fi
= get_prev_frame (fi
))
1083 ps
= find_pc_psymtab (frame_address_in_block (fi
));
1085 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
1089 for (i
= 0, fi
= trailing
;
1091 i
++, fi
= get_prev_frame (fi
))
1095 /* Don't use print_stack_frame; if an error() occurs it probably
1096 means further attempts to backtrace would fail (on the other
1097 hand, perhaps the code does or could be fixed to make sure
1098 the frame->prev field gets set to NULL in that case). */
1099 print_frame_info_base (fi
, trailing_level
+ i
, 0, 1);
1101 print_frame_local_vars (fi
, 1, gdb_stdout
);
1104 /* If we've stopped before the end, mention that. */
1106 printf_filtered ("(More stack frames follow...)\n");
1110 backtrace_command (char *arg
, int from_tty
)
1112 struct cleanup
*old_chain
= (struct cleanup
*) NULL
;
1113 char **argv
= (char **) NULL
;
1114 int argIndicatingFullTrace
= (-1), totArgLen
= 0, argc
= 0;
1117 if (arg
!= (char *) NULL
)
1121 argv
= buildargv (arg
);
1122 old_chain
= make_cleanup_freeargv (argv
);
1124 for (i
= 0; (argv
[i
] != (char *) NULL
); i
++)
1128 for (j
= 0; (j
< strlen (argv
[i
])); j
++)
1129 argv
[i
][j
] = tolower (argv
[i
][j
]);
1131 if (argIndicatingFullTrace
< 0 && subset_compare (argv
[i
], "full"))
1132 argIndicatingFullTrace
= argc
;
1136 totArgLen
+= strlen (argv
[i
]);
1140 if (argIndicatingFullTrace
>= 0)
1144 argPtr
= (char *) xmalloc (totArgLen
+ 1);
1149 memset (argPtr
, 0, totArgLen
+ 1);
1150 for (i
= 0; (i
< (argc
+ 1)); i
++)
1152 if (i
!= argIndicatingFullTrace
)
1154 strcat (argPtr
, argv
[i
]);
1155 strcat (argPtr
, " ");
1161 argPtr
= (char *) NULL
;
1165 backtrace_command_1 (argPtr
, (argIndicatingFullTrace
>= 0), from_tty
);
1167 if (argIndicatingFullTrace
>= 0 && totArgLen
> 0)
1171 do_cleanups (old_chain
);
1174 static void backtrace_full_command (char *arg
, int from_tty
);
1176 backtrace_full_command (char *arg
, int from_tty
)
1178 backtrace_command_1 (arg
, 1, from_tty
);
1182 /* Print the local variables of a block B active in FRAME.
1183 Return 1 if any variables were printed; 0 otherwise. */
1186 print_block_frame_locals (struct block
*b
, register struct frame_info
*fi
,
1187 int num_tabs
, register struct ui_file
*stream
)
1190 register struct symbol
*sym
;
1191 register int values_printed
= 0;
1193 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
1195 switch (SYMBOL_CLASS (sym
))
1202 for (j
= 0; j
< num_tabs
; j
++)
1203 fputs_filtered ("\t", stream
);
1204 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
1205 fputs_filtered (" = ", stream
);
1206 print_variable_value (sym
, fi
, stream
);
1207 fprintf_filtered (stream
, "\n");
1211 /* Ignore symbols which are not locals. */
1215 return values_printed
;
1218 /* Same, but print labels. */
1221 print_block_frame_labels (struct block
*b
, int *have_default
,
1222 register struct ui_file
*stream
)
1225 register struct symbol
*sym
;
1226 register int values_printed
= 0;
1228 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
1230 if (STREQ (SYMBOL_NAME (sym
), "default"))
1236 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1238 struct symtab_and_line sal
;
1239 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1241 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
1244 fprintf_filtered (stream
, " ");
1245 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, stream
);
1247 fprintf_filtered (stream
, " in file %s, line %d\n",
1248 sal
.symtab
->filename
, sal
.line
);
1251 return values_printed
;
1254 /* Print on STREAM all the local variables in frame FRAME,
1255 including all the blocks active in that frame
1258 Returns 1 if the job was done,
1259 or 0 if nothing was printed because we have no info
1260 on the function running in FRAME. */
1263 print_frame_local_vars (register struct frame_info
*fi
, register int num_tabs
,
1264 register struct ui_file
*stream
)
1266 register struct block
*block
= get_frame_block (fi
, 0);
1267 register int values_printed
= 0;
1271 fprintf_filtered (stream
, "No symbol table info available.\n");
1277 if (print_block_frame_locals (block
, fi
, num_tabs
, stream
))
1279 /* After handling the function's top-level block, stop.
1280 Don't continue to its superblock, the block of
1281 per-file symbols. */
1282 if (BLOCK_FUNCTION (block
))
1284 block
= BLOCK_SUPERBLOCK (block
);
1287 if (!values_printed
)
1289 fprintf_filtered (stream
, "No locals.\n");
1293 /* Same, but print labels. */
1296 print_frame_label_vars (register struct frame_info
*fi
, int this_level_only
,
1297 register struct ui_file
*stream
)
1299 register struct blockvector
*bl
;
1300 register struct block
*block
= get_frame_block (fi
, 0);
1301 register int values_printed
= 0;
1302 int index
, have_default
= 0;
1303 char *blocks_printed
;
1304 CORE_ADDR pc
= fi
->pc
;
1308 fprintf_filtered (stream
, "No symbol table info available.\n");
1312 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1313 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1314 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1318 CORE_ADDR end
= BLOCK_END (block
) - 4;
1321 if (bl
!= blockvector_for_pc (end
, &index
))
1322 error ("blockvector blotch");
1323 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1324 error ("blockvector botch");
1325 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1328 /* Don't print out blocks that have gone by. */
1329 while (index
< last_index
1330 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1333 while (index
< last_index
1334 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1336 if (blocks_printed
[index
] == 0)
1338 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
1340 blocks_printed
[index
] = 1;
1346 if (values_printed
&& this_level_only
)
1349 /* After handling the function's top-level block, stop.
1350 Don't continue to its superblock, the block of
1351 per-file symbols. */
1352 if (BLOCK_FUNCTION (block
))
1354 block
= BLOCK_SUPERBLOCK (block
);
1357 if (!values_printed
&& !this_level_only
)
1359 fprintf_filtered (stream
, "No catches.\n");
1365 locals_info (char *args
, int from_tty
)
1367 if (!deprecated_selected_frame
)
1368 error ("No frame selected.");
1369 print_frame_local_vars (deprecated_selected_frame
, 0, gdb_stdout
);
1373 catch_info (char *ignore
, int from_tty
)
1375 struct symtab_and_line
*sal
;
1377 /* Check for target support for exception handling */
1378 sal
= target_enable_exception_callback (EX_EVENT_CATCH
, 1);
1381 /* Currently not handling this */
1382 /* Ideally, here we should interact with the C++ runtime
1383 system to find the list of active handlers, etc. */
1384 fprintf_filtered (gdb_stdout
, "Info catch not supported with this target/compiler combination.\n");
1386 if (!deprecated_selected_frame
)
1387 error ("No frame selected.");
1392 /* Assume g++ compiled code -- old v 4.16 behaviour */
1393 if (!deprecated_selected_frame
)
1394 error ("No frame selected.");
1396 print_frame_label_vars (deprecated_selected_frame
, 0, gdb_stdout
);
1401 print_frame_arg_vars (register struct frame_info
*fi
,
1402 register struct ui_file
*stream
)
1404 struct symbol
*func
= get_frame_function (fi
);
1405 register struct block
*b
;
1407 register struct symbol
*sym
, *sym2
;
1408 register int values_printed
= 0;
1412 fprintf_filtered (stream
, "No symbol table info available.\n");
1416 b
= SYMBOL_BLOCK_VALUE (func
);
1417 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
1419 switch (SYMBOL_CLASS (sym
))
1425 case LOC_REGPARM_ADDR
:
1426 case LOC_BASEREG_ARG
:
1428 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), stream
);
1429 fputs_filtered (" = ", stream
);
1431 /* We have to look up the symbol because arguments can have
1432 two entries (one a parameter, one a local) and the one we
1433 want is the local, which lookup_symbol will find for us.
1434 This includes gcc1 (not gcc2) on the sparc when passing a
1435 small structure and gcc2 when the argument type is float
1436 and it is passed as a double and converted to float by
1437 the prologue (in the latter case the type of the LOC_ARG
1438 symbol is double and the type of the LOC_LOCAL symbol is
1439 float). There are also LOC_ARG/LOC_REGISTER pairs which
1440 are not combined in symbol-reading. */
1442 sym2
= lookup_symbol (SYMBOL_NAME (sym
),
1443 b
, VAR_NAMESPACE
, (int *) NULL
, (struct symtab
**) NULL
);
1444 print_variable_value (sym2
, fi
, stream
);
1445 fprintf_filtered (stream
, "\n");
1449 /* Don't worry about things which aren't arguments. */
1453 if (!values_printed
)
1455 fprintf_filtered (stream
, "No arguments.\n");
1460 args_info (char *ignore
, int from_tty
)
1462 if (!deprecated_selected_frame
)
1463 error ("No frame selected.");
1464 print_frame_arg_vars (deprecated_selected_frame
, gdb_stdout
);
1469 args_plus_locals_info (char *ignore
, int from_tty
)
1471 args_info (ignore
, from_tty
);
1472 locals_info (ignore
, from_tty
);
1476 /* Select frame FI. Also print the stack frame and show the source if
1477 this is the tui version. */
1479 select_and_print_frame (struct frame_info
*fi
)
1484 print_stack_frame (fi
, frame_relative_level (fi
), 1);
1488 /* Return the symbol-block in which the selected frame is executing.
1489 Can return zero under various legitimate circumstances.
1491 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1492 code address within the block returned. We use this to decide
1493 which macros are in scope. */
1496 get_selected_block (CORE_ADDR
*addr_in_block
)
1498 if (!target_has_stack
)
1501 /* NOTE: cagney/2002-11-28: Why go to all this effort to not create
1502 a selected/current frame? Perhaphs this function is called,
1503 indirectly, by WFI in "infrun.c" where avoiding the creation of
1504 an inner most frame is very important (it slows down single
1505 step). I suspect, though that this was true in the deep dark
1506 past but is no longer the case. A mindless look at all the
1507 callers tends to support this theory. I think we should be able
1508 to assume that there is always a selcted frame. */
1509 /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel
1511 if (!deprecated_selected_frame
)
1513 CORE_ADDR pc
= read_pc ();
1514 if (addr_in_block
!= NULL
)
1515 *addr_in_block
= pc
;
1516 return block_for_pc (pc
);
1518 return get_frame_block (deprecated_selected_frame
, addr_in_block
);
1521 /* Find a frame a certain number of levels away from FRAME.
1522 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1523 Positive means go to earlier frames (up); negative, the reverse.
1524 The int that contains the number of levels is counted toward
1525 zero as the frames for those levels are found.
1526 If the top or bottom frame is reached, that frame is returned,
1527 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1528 how much farther the original request asked to go. */
1531 find_relative_frame (register struct frame_info
*frame
,
1532 register int *level_offset_ptr
)
1534 register struct frame_info
*prev
;
1535 register struct frame_info
*frame1
;
1537 /* Going up is simple: just do get_prev_frame enough times
1538 or until initial frame is reached. */
1539 while (*level_offset_ptr
> 0)
1541 prev
= get_prev_frame (frame
);
1544 (*level_offset_ptr
)--;
1547 /* Going down is just as simple. */
1548 if (*level_offset_ptr
< 0)
1550 while (*level_offset_ptr
< 0)
1552 frame1
= get_next_frame (frame
);
1556 (*level_offset_ptr
)++;
1562 /* The "select_frame" command. With no arg, NOP.
1563 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1564 valid level. Otherwise, treat level_exp as an address expression
1565 and select it. See parse_frame_specification for more info on proper
1566 frame expressions. */
1570 select_frame_command_wrapper (char *level_exp
, int from_tty
)
1572 select_frame_command (level_exp
, from_tty
);
1576 select_frame_command (char *level_exp
, int from_tty
)
1578 struct frame_info
*frame
;
1579 int level
= frame_relative_level (deprecated_selected_frame
);
1581 if (!target_has_stack
)
1582 error ("No stack.");
1584 frame
= parse_frame_specification (level_exp
);
1586 select_frame (frame
);
1587 if (level
!= frame_relative_level (deprecated_selected_frame
))
1588 selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame
));
1591 /* The "frame" command. With no arg, print selected frame briefly.
1592 With arg, behaves like select_frame and then prints the selected
1596 frame_command (char *level_exp
, int from_tty
)
1598 select_frame_command (level_exp
, from_tty
);
1599 show_and_print_stack_frame (deprecated_selected_frame
,
1600 frame_relative_level (deprecated_selected_frame
), 1);
1603 /* The XDB Compatibility command to print the current frame. */
1606 current_frame_command (char *level_exp
, int from_tty
)
1608 if (target_has_stack
== 0 || deprecated_selected_frame
== 0)
1609 error ("No stack.");
1610 print_only_stack_frame (deprecated_selected_frame
,
1611 frame_relative_level (deprecated_selected_frame
), 1);
1614 /* Select the frame up one or COUNT stack levels
1615 from the previously selected frame, and print it briefly. */
1619 up_silently_base (char *count_exp
)
1621 register struct frame_info
*fi
;
1622 int count
= 1, count1
;
1624 count
= parse_and_eval_long (count_exp
);
1627 if (target_has_stack
== 0 || deprecated_selected_frame
== 0)
1628 error ("No stack.");
1630 fi
= find_relative_frame (deprecated_selected_frame
, &count1
);
1631 if (count1
!= 0 && count_exp
== 0)
1632 error ("Initial frame selected; you cannot go up.");
1634 selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame
));
1638 up_silently_command (char *count_exp
, int from_tty
)
1640 up_silently_base (count_exp
);
1644 up_command (char *count_exp
, int from_tty
)
1646 up_silently_base (count_exp
);
1647 show_and_print_stack_frame (deprecated_selected_frame
,
1648 frame_relative_level (deprecated_selected_frame
), 1);
1651 /* Select the frame down one or COUNT stack levels
1652 from the previously selected frame, and print it briefly. */
1656 down_silently_base (char *count_exp
)
1658 register struct frame_info
*frame
;
1659 int count
= -1, count1
;
1661 count
= -parse_and_eval_long (count_exp
);
1664 if (target_has_stack
== 0 || deprecated_selected_frame
== 0)
1665 error ("No stack.");
1667 frame
= find_relative_frame (deprecated_selected_frame
, &count1
);
1668 if (count1
!= 0 && count_exp
== 0)
1671 /* We only do this if count_exp is not specified. That way "down"
1672 means to really go down (and let me know if that is
1673 impossible), but "down 9999" can be used to mean go all the way
1674 down without getting an error. */
1676 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1679 select_frame (frame
);
1680 selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame
));
1685 down_silently_command (char *count_exp
, int from_tty
)
1687 down_silently_base (count_exp
);
1691 down_command (char *count_exp
, int from_tty
)
1693 down_silently_base (count_exp
);
1694 show_and_print_stack_frame (deprecated_selected_frame
,
1695 frame_relative_level (deprecated_selected_frame
), 1);
1699 return_command (char *retval_exp
, int from_tty
)
1701 struct symbol
*thisfun
;
1702 CORE_ADDR selected_frame_addr
;
1703 CORE_ADDR selected_frame_pc
;
1704 struct frame_info
*frame
;
1705 struct value
*return_value
= NULL
;
1707 if (deprecated_selected_frame
== NULL
)
1708 error ("No selected frame.");
1709 thisfun
= get_frame_function (deprecated_selected_frame
);
1710 selected_frame_addr
= get_frame_base (deprecated_selected_frame
);
1711 selected_frame_pc
= deprecated_selected_frame
->pc
;
1713 /* Compute the return value (if any -- possibly getting errors here). */
1717 struct type
*return_type
= NULL
;
1719 return_value
= parse_and_eval (retval_exp
);
1721 /* Cast return value to the return type of the function. */
1722 if (thisfun
!= NULL
)
1723 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
1724 if (return_type
== NULL
)
1725 return_type
= builtin_type_int
;
1726 return_value
= value_cast (return_type
, return_value
);
1728 /* Make sure we have fully evaluated it, since
1729 it might live in the stack frame we're about to pop. */
1730 if (VALUE_LAZY (return_value
))
1731 value_fetch_lazy (return_value
);
1734 /* If interactive, require confirmation. */
1740 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun
)))
1742 error ("Not confirmed.");
1746 else if (!query ("Make selected stack frame return now? "))
1747 error ("Not confirmed.");
1750 /* Do the real work. Pop until the specified frame is current. We
1751 use this method because the deprecated_selected_frame is not valid after
1752 a POP_FRAME. The pc comparison makes this work even if the
1753 selected frame shares its fp with another frame. */
1755 while (selected_frame_addr
!= get_frame_base (frame
= get_current_frame ())
1756 || selected_frame_pc
!= frame
->pc
)
1759 /* Then pop that frame. */
1763 /* Compute the return value (if any) and store in the place
1764 for return values. */
1767 set_return_value (return_value
);
1769 /* If we are at the end of a call dummy now, pop the dummy frame too. */
1771 if (CALL_DUMMY_HAS_COMPLETED (read_pc(), read_sp (),
1772 get_frame_base (get_current_frame ())))
1775 /* If interactive, print the frame that is now current. */
1778 frame_command ("0", 1);
1780 select_frame_command ("0", 0);
1783 /* Sets the scope to input function name, provided that the
1784 function is within the current stack frame */
1786 struct function_bounds
1788 CORE_ADDR low
, high
;
1791 static void func_command (char *arg
, int from_tty
);
1793 func_command (char *arg
, int from_tty
)
1795 struct frame_info
*fp
;
1797 struct symtabs_and_lines sals
;
1800 struct function_bounds
*func_bounds
= (struct function_bounds
*) NULL
;
1802 if (arg
!= (char *) NULL
)
1805 fp
= parse_frame_specification ("0");
1806 sals
= decode_line_spec (arg
, 1);
1807 func_bounds
= (struct function_bounds
*) xmalloc (
1808 sizeof (struct function_bounds
) * sals
.nelts
);
1809 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1811 if (sals
.sals
[i
].pc
== (CORE_ADDR
) 0 ||
1812 find_pc_partial_function (sals
.sals
[i
].pc
,
1814 &func_bounds
[i
].low
,
1815 &func_bounds
[i
].high
) == 0)
1817 func_bounds
[i
].low
=
1818 func_bounds
[i
].high
= (CORE_ADDR
) NULL
;
1824 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1825 found
= (fp
->pc
>= func_bounds
[i
].low
&&
1826 fp
->pc
< func_bounds
[i
].high
);
1830 fp
= find_relative_frame (fp
, &level
);
1833 while (!found
&& level
== 0);
1836 xfree (func_bounds
);
1839 printf_filtered ("'%s' not within current stack frame.\n", arg
);
1840 else if (fp
!= deprecated_selected_frame
)
1841 select_and_print_frame (fp
);
1844 /* Gets the language of the current frame. */
1847 get_frame_language (void)
1849 register struct symtab
*s
;
1850 enum language flang
; /* The language of the current frame */
1852 if (deprecated_selected_frame
)
1854 s
= find_pc_symtab (deprecated_selected_frame
->pc
);
1856 flang
= s
->language
;
1858 flang
= language_unknown
;
1861 flang
= language_unknown
;
1867 _initialize_stack (void)
1870 backtrace_limit
= 30;
1873 add_com ("return", class_stack
, return_command
,
1874 "Make selected stack frame return to its caller.\n\
1875 Control remains in the debugger, but when you continue\n\
1876 execution will resume in the frame above the one now selected.\n\
1877 If an argument is given, it is an expression for the value to return.");
1879 add_com ("up", class_stack
, up_command
,
1880 "Select and print stack frame that called this one.\n\
1881 An argument says how many frames up to go.");
1882 add_com ("up-silently", class_support
, up_silently_command
,
1883 "Same as the `up' command, but does not print anything.\n\
1884 This is useful in command scripts.");
1886 add_com ("down", class_stack
, down_command
,
1887 "Select and print stack frame called by this one.\n\
1888 An argument says how many frames down to go.");
1889 add_com_alias ("do", "down", class_stack
, 1);
1890 add_com_alias ("dow", "down", class_stack
, 1);
1891 add_com ("down-silently", class_support
, down_silently_command
,
1892 "Same as the `down' command, but does not print anything.\n\
1893 This is useful in command scripts.");
1895 add_com ("frame", class_stack
, frame_command
,
1896 "Select and print a stack frame.\n\
1897 With no argument, print the selected stack frame. (See also \"info frame\").\n\
1898 An argument specifies the frame to select.\n\
1899 It can be a stack frame number or the address of the frame.\n\
1900 With argument, nothing is printed if input is coming from\n\
1901 a command file or a user-defined command.");
1903 add_com_alias ("f", "frame", class_stack
, 1);
1907 add_com ("L", class_stack
, current_frame_command
,
1908 "Print the current stack frame.\n");
1909 add_com_alias ("V", "frame", class_stack
, 1);
1911 add_com ("select-frame", class_stack
, select_frame_command
,
1912 "Select a stack frame without printing anything.\n\
1913 An argument specifies the frame to select.\n\
1914 It can be a stack frame number or the address of the frame.\n");
1916 add_com ("backtrace", class_stack
, backtrace_command
,
1917 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
1918 With a negative argument, print outermost -COUNT frames.\n\
1919 Use of the 'full' qualifier also prints the values of the local variables.\n");
1920 add_com_alias ("bt", "backtrace", class_stack
, 0);
1923 add_com_alias ("t", "backtrace", class_stack
, 0);
1924 add_com ("T", class_stack
, backtrace_full_command
,
1925 "Print backtrace of all stack frames, or innermost COUNT frames \n\
1926 and the values of the local variables.\n\
1927 With a negative argument, print outermost -COUNT frames.\n\
1928 Usage: T <count>\n");
1931 add_com_alias ("where", "backtrace", class_alias
, 0);
1932 add_info ("stack", backtrace_command
,
1933 "Backtrace of the stack, or innermost COUNT frames.");
1934 add_info_alias ("s", "stack", 1);
1935 add_info ("frame", frame_info
,
1936 "All about selected stack frame, or frame at ADDR.");
1937 add_info_alias ("f", "frame", 1);
1938 add_info ("locals", locals_info
,
1939 "Local variables of current stack frame.");
1940 add_info ("args", args_info
,
1941 "Argument variables of current stack frame.");
1943 add_com ("l", class_info
, args_plus_locals_info
,
1944 "Argument and local variables of current stack frame.");
1947 add_com ("func", class_stack
, func_command
,
1948 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
1950 add_info ("catch", catch_info
,
1951 "Exceptions that can be caught in the current stack frame.");
1954 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
1955 "Specify maximum number of frames for \"backtrace\" to print by default.",
1957 add_info ("backtrace-limit", backtrace_limit_info
,
1958 "The maximum number of frames for \"backtrace\" to print by default.");