1 /* Print and select stack frames for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007
5 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
26 #include "expression.h"
33 #include "breakpoint.h"
40 #include "dictionary.h"
41 #include "exceptions.h"
42 #include "reggroups.h"
47 #include "gdb_assert.h"
49 #include "gdb_string.h"
51 void (*deprecated_selected_frame_level_changed_hook
) (int);
53 /* The possible choices of "set print frame-arguments, and the value
56 static const char *print_frame_arguments_choices
[] =
57 {"all", "scalars", "none", NULL
};
58 static const char *print_frame_arguments
= "all";
60 /* Prototypes for local functions. */
62 static void print_frame_local_vars (struct frame_info
*, int,
65 static void print_frame (struct frame_info
*frame
, int print_level
,
66 enum print_what print_what
, int print_args
,
67 struct symtab_and_line sal
);
69 /* Zero means do things normally; we are interacting directly with the
70 user. One means print the full filename and linenumber when a
71 frame is printed, and do so in a format emacs18/emacs19.22 can
72 parse. Two means print similar annotations, but in many more
73 cases and in a slightly different syntax. */
75 int annotation_level
= 0;
78 struct print_stack_frame_args
80 struct frame_info
*frame
;
82 enum print_what print_what
;
86 /* Show or print the frame arguments; stub for catch_errors. */
89 print_stack_frame_stub (void *args
)
91 struct print_stack_frame_args
*p
= args
;
92 int center
= (p
->print_what
== SRC_LINE
|| p
->print_what
== SRC_AND_LOC
);
94 print_frame_info (p
->frame
, p
->print_level
, p
->print_what
, p
->print_args
);
95 set_current_sal_from_frame (p
->frame
, center
);
99 /* Show or print a stack frame FRAME briefly. The output is format
100 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
101 relative level, function name, argument list, and file name and
102 line number. If the frame's PC is not at the beginning of the
103 source line, the actual PC is printed at the beginning. */
106 print_stack_frame (struct frame_info
*frame
, int print_level
,
107 enum print_what print_what
)
109 struct print_stack_frame_args args
;
112 args
.print_level
= print_level
;
113 args
.print_what
= print_what
;
114 /* For mi, alway print location and address. */
115 args
.print_what
= ui_out_is_mi_like_p (uiout
) ? LOC_AND_ADDRESS
: print_what
;
118 catch_errors (print_stack_frame_stub
, &args
, "", RETURN_MASK_ALL
);
121 struct print_args_args
124 struct frame_info
*frame
;
125 struct ui_file
*stream
;
128 static int print_args_stub (void *args
);
130 /* Print nameless arguments of frame FRAME on STREAM, where START is
131 the offset of the first nameless argument, and NUM is the number of
132 nameless arguments to print. FIRST is nonzero if this is the first
133 argument (not just the first nameless argument). */
136 print_frame_nameless_args (struct frame_info
*frame
, long start
, int num
,
137 int first
, struct ui_file
*stream
)
143 for (i
= 0; i
< num
; i
++)
146 argsaddr
= get_frame_args_address (frame
);
149 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
151 fprintf_filtered (stream
, ", ");
152 fprintf_filtered (stream
, "%ld", arg_value
);
154 start
+= sizeof (int);
158 /* Return non-zero if the debugger should print the value of the provided
159 symbol parameter (SYM). */
162 print_this_frame_argument_p (struct symbol
*sym
)
166 /* If the user asked to print no argument at all, then obviously
167 do not print this argument. */
169 if (strcmp (print_frame_arguments
, "none") == 0)
172 /* If the user asked to print all arguments, then we should print
175 if (strcmp (print_frame_arguments
, "all") == 0)
178 /* The user asked to print only the scalar arguments, so do not
179 print the non-scalar ones. */
181 type
= CHECK_TYPEDEF (SYMBOL_TYPE (sym
));
182 switch (TYPE_CODE (type
))
184 case TYPE_CODE_ARRAY
:
185 case TYPE_CODE_STRUCT
:
186 case TYPE_CODE_UNION
:
188 case TYPE_CODE_STRING
:
189 case TYPE_CODE_BITSTRING
:
196 /* Print the arguments of frame FRAME on STREAM, given the function
197 FUNC running in that frame (as a symbol), where NUM is the number
198 of arguments according to the stack frame (or -1 if the number of
199 arguments is unknown). */
201 /* Note that currently the "number of argumentss according to the
202 stack frame" is only known on VAX where i refers to the "number of
203 ints of argumentss according to the stack frame". */
206 print_frame_args (struct symbol
*func
, struct frame_info
*frame
,
207 int num
, struct ui_file
*stream
)
210 /* Offset of next stack argument beyond the one we have seen that is
211 at the highest offset, or -1 if we haven't come to a stack
213 long highest_offset
= -1;
214 /* Number of ints of arguments that we have printed so far. */
215 int args_printed
= 0;
216 struct cleanup
*old_chain
, *list_chain
;
217 struct ui_stream
*stb
;
219 stb
= ui_out_stream_new (uiout
);
220 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
224 struct block
*b
= SYMBOL_BLOCK_VALUE (func
);
225 struct dict_iterator iter
;
229 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
233 /* Keep track of the highest stack argument offset seen, and
234 skip over any kinds of symbols we don't care about. */
236 switch (SYMBOL_CLASS (sym
))
241 long current_offset
= SYMBOL_VALUE (sym
);
242 int arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
244 /* Compute address of next argument by adding the size of
245 this argument and rounding to an int boundary. */
247 ((current_offset
+ arg_size
+ sizeof (int) - 1)
248 & ~(sizeof (int) - 1));
250 /* If this is the highest offset seen yet, set
252 if (highest_offset
== -1
253 || (current_offset
> highest_offset
))
254 highest_offset
= current_offset
;
256 /* Add the number of ints we're about to print to
258 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
261 /* We care about types of symbols, but don't need to
262 keep track of stack offsets in them. */
264 case LOC_REGPARM_ADDR
:
266 case LOC_BASEREG_ARG
:
267 case LOC_COMPUTED_ARG
:
270 /* Other types of symbols we just skip over. */
275 /* We have to look up the symbol because arguments can have
276 two entries (one a parameter, one a local) and the one we
277 want is the local, which lookup_symbol will find for us.
278 This includes gcc1 (not gcc2) on SPARC when passing a
279 small structure and gcc2 when the argument type is float
280 and it is passed as a double and converted to float by
281 the prologue (in the latter case the type of the LOC_ARG
282 symbol is double and the type of the LOC_LOCAL symbol is
284 /* But if the parameter name is null, don't try it. Null
285 parameter names occur on the RS/6000, for traceback
286 tables. FIXME, should we even print them? */
288 if (*DEPRECATED_SYMBOL_NAME (sym
))
291 nsym
= lookup_symbol (DEPRECATED_SYMBOL_NAME (sym
),
292 b
, VAR_DOMAIN
, NULL
, NULL
);
293 gdb_assert (nsym
!= NULL
);
294 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
296 /* There is a LOC_ARG/LOC_REGISTER pair. This means
297 that it was passed on the stack and loaded into a
298 register, or passed in a register and stored in a
299 stack slot. GDB 3.x used the LOC_ARG; GDB
300 4.0-4.11 used the LOC_REGISTER.
302 Reasons for using the LOC_ARG:
304 (1) Because find_saved_registers may be slow for
307 (2) Because registers are often re-used and stack
308 slots rarely (never?) are. Therefore using
309 the stack slot is much less likely to print
312 Reasons why we might want to use the LOC_REGISTER:
314 (1) So that the backtrace prints the same value
315 as "print foo". I see no compelling reason
316 why this needs to be the case; having the
317 backtrace print the value which was passed
318 in, and "print foo" print the value as
319 modified within the called function, makes
322 Additional note: It might be nice if "info args"
323 displayed both values.
325 One more note: There is a case with SPARC
326 structure passing where we need to use the
327 LOC_REGISTER, but this is dealt with by creating
328 a single LOC_REGPARM in symbol reading. */
330 /* Leave sym (the LOC_ARG) alone. */
337 /* Print the current arg. */
339 ui_out_text (uiout
, ", ");
340 ui_out_wrap_hint (uiout
, " ");
342 annotate_arg_begin ();
344 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
345 fprintf_symbol_filtered (stb
->stream
, SYMBOL_PRINT_NAME (sym
),
346 SYMBOL_LANGUAGE (sym
),
347 DMGL_PARAMS
| DMGL_ANSI
);
348 ui_out_field_stream (uiout
, "name", stb
);
349 annotate_arg_name_end ();
350 ui_out_text (uiout
, "=");
352 if (print_this_frame_argument_p (sym
))
354 /* Avoid value_print because it will deref ref parameters.
355 We just want to print their addresses. Print ??? for
356 args whose address we do not know. We pass 2 as
357 "recurse" to val_print because our standard indentation
358 here is 4 spaces, and val_print indents 2 for each
360 val
= read_var_value (sym
, frame
);
362 annotate_arg_value (val
== NULL
? NULL
: value_type (val
));
366 common_val_print (val
, stb
->stream
, 0, 0, 2,
368 ui_out_field_stream (uiout
, "value", stb
);
371 ui_out_text (uiout
, "???");
374 ui_out_text (uiout
, "...");
377 /* Invoke ui_out_tuple_end. */
378 do_cleanups (list_chain
);
386 /* Don't print nameless args in situations where we don't know
387 enough about the stack to find them. */
392 if (highest_offset
== -1)
393 start
= gdbarch_frame_args_skip (get_frame_arch (frame
));
395 start
= highest_offset
;
397 print_frame_nameless_args (frame
, start
, num
- args_printed
,
401 do_cleanups (old_chain
);
404 /* Stub for catch_errors. */
407 print_args_stub (void *args
)
409 struct print_args_args
*p
= args
;
412 if (gdbarch_frame_num_args_p (current_gdbarch
))
414 numargs
= gdbarch_frame_num_args (current_gdbarch
, p
->frame
);
415 gdb_assert (numargs
>= 0);
419 print_frame_args (p
->func
, p
->frame
, numargs
, p
->stream
);
423 /* Set the current source and line to the location given by frame
424 FRAME, if possible. When CENTER is true, adjust so the relevant
425 line is in the center of the next 'list'. */
428 set_current_sal_from_frame (struct frame_info
*frame
, int center
)
430 struct symtab_and_line sal
;
432 find_frame_sal (frame
, &sal
);
436 sal
.line
= max (sal
.line
- get_lines_to_list () / 2, 1);
437 set_current_source_symtab_and_line (&sal
);
441 /* Print information about frame FRAME. The output is format according
442 to PRINT_LEVEL and PRINT_WHAT and PRINT ARGS. The meaning of
445 SRC_LINE: Print only source line.
446 LOCATION: Print only location.
447 LOC_AND_SRC: Print location and source line.
449 Used in "where" output, and to emit breakpoint or step
453 print_frame_info (struct frame_info
*frame
, int print_level
,
454 enum print_what print_what
, int print_args
)
456 struct symtab_and_line sal
;
460 if (get_frame_type (frame
) == DUMMY_FRAME
461 || get_frame_type (frame
) == SIGTRAMP_FRAME
)
463 struct cleanup
*uiout_cleanup
464 = make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
466 annotate_frame_begin (print_level
? frame_relative_level (frame
) : 0,
467 get_frame_pc (frame
));
469 /* Do this regardless of SOURCE because we don't have any source
470 to list for this frame. */
473 ui_out_text (uiout
, "#");
474 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
475 frame_relative_level (frame
));
477 if (ui_out_is_mi_like_p (uiout
))
479 annotate_frame_address ();
480 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (frame
));
481 annotate_frame_address_end ();
484 if (get_frame_type (frame
) == DUMMY_FRAME
)
486 annotate_function_call ();
487 ui_out_field_string (uiout
, "func", "<function called from gdb>");
489 else if (get_frame_type (frame
) == SIGTRAMP_FRAME
)
491 annotate_signal_handler_caller ();
492 ui_out_field_string (uiout
, "func", "<signal handler called>");
494 ui_out_text (uiout
, "\n");
495 annotate_frame_end ();
497 do_cleanups (uiout_cleanup
);
501 /* If FRAME is not the innermost frame, that normally means that
502 FRAME->pc points to *after* the call instruction, and we want to
503 get the line containing the call, never the next line. But if
504 the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
505 next frame was not entered as the result of a call, and we want
506 to get the line containing FRAME->pc. */
507 find_frame_sal (frame
, &sal
);
509 location_print
= (print_what
== LOCATION
510 || print_what
== LOC_AND_ADDRESS
511 || print_what
== SRC_AND_LOC
);
513 if (location_print
|| !sal
.symtab
)
514 print_frame (frame
, print_level
, print_what
, print_args
, sal
);
516 source_print
= (print_what
== SRC_LINE
|| print_what
== SRC_AND_LOC
);
518 if (source_print
&& sal
.symtab
)
521 int mid_statement
= ((print_what
== SRC_LINE
)
522 && (get_frame_pc (frame
) != sal
.pc
));
524 if (annotation_level
)
525 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
526 get_frame_pc (frame
));
529 if (deprecated_print_frame_info_listing_hook
)
530 deprecated_print_frame_info_listing_hook (sal
.symtab
,
535 /* We used to do this earlier, but that is clearly
536 wrong. This function is used by many different
537 parts of gdb, including normal_stop in infrun.c,
538 which uses this to print out the current PC
539 when we stepi/nexti into the middle of a source
540 line. Only the command line really wants this
541 behavior. Other UIs probably would like the
542 ability to decide for themselves if it is desired. */
543 if (addressprint
&& mid_statement
)
545 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (frame
));
546 ui_out_text (uiout
, "\t");
549 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
554 if (print_what
!= LOCATION
)
555 set_default_breakpoint (1, get_frame_pc (frame
), sal
.symtab
, sal
.line
);
557 annotate_frame_end ();
559 gdb_flush (gdb_stdout
);
563 print_frame (struct frame_info
*frame
, int print_level
,
564 enum print_what print_what
, int print_args
,
565 struct symtab_and_line sal
)
568 char *funname
= NULL
;
569 enum language funlang
= language_unknown
;
570 struct ui_stream
*stb
;
571 struct cleanup
*old_chain
, *list_chain
;
573 stb
= ui_out_stream_new (uiout
);
574 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
576 func
= find_pc_function (get_frame_address_in_block (frame
));
579 /* In certain pathological cases, the symtabs give the wrong
580 function (when we are in the first function in a file which
581 is compiled without debugging symbols, the previous function
582 is compiled with debugging symbols, and the "foo.o" symbol
583 that is supposed to tell us where the file with debugging
584 symbols ends has been truncated by ar because it is longer
585 than 15 characters). This also occurs if the user uses asm()
586 to create a function but not stabs for it (in a file compiled
589 So look in the minimal symbol tables as well, and if it comes
590 up with a larger address for the function use that instead.
591 I don't think this can ever cause any problems; there
592 shouldn't be any minimal symbols in the middle of a function;
593 if this is ever changed many parts of GDB will need to be
594 changed (and we'll create a find_pc_minimal_function or some
597 struct minimal_symbol
*msymbol
=
598 lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame
));
601 && (SYMBOL_VALUE_ADDRESS (msymbol
)
602 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
604 /* We also don't know anything about the function besides
605 its address and name. */
607 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
608 funlang
= SYMBOL_LANGUAGE (msymbol
);
612 funname
= DEPRECATED_SYMBOL_NAME (func
);
613 funlang
= SYMBOL_LANGUAGE (func
);
614 if (funlang
== language_cplus
)
616 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
617 to display the demangled name that we already have
618 stored in the symbol table, but we stored a version
619 with DMGL_PARAMS turned on, and here we don't want to
620 display parameters. So call the demangler again, with
623 Yes, printf_symbol_filtered() will again try to
624 demangle the name on the fly, but the issue is that
625 if cplus_demangle() fails here, it will fail there
626 too. So we want to catch the failure (where DEMANGLED
627 is NULL below) here, while we still have our hands on
628 the function symbol.) */
629 char *demangled
= cplus_demangle (funname
, DMGL_ANSI
);
630 if (demangled
== NULL
)
631 /* If the demangler fails, try the demangled name from
632 the symbol table. That'll have parameters, but
633 that's preferable to displaying a mangled name. */
634 funname
= SYMBOL_PRINT_NAME (func
);
642 struct minimal_symbol
*msymbol
=
643 lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame
));
647 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
648 funlang
= SYMBOL_LANGUAGE (msymbol
);
652 annotate_frame_begin (print_level
? frame_relative_level (frame
) : 0,
653 get_frame_pc (frame
));
655 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
659 ui_out_text (uiout
, "#");
660 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
661 frame_relative_level (frame
));
664 if (get_frame_pc (frame
) != sal
.pc
|| !sal
.symtab
665 || print_what
== LOC_AND_ADDRESS
)
667 annotate_frame_address ();
668 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (frame
));
669 annotate_frame_address_end ();
670 ui_out_text (uiout
, " in ");
672 annotate_frame_function_name ();
673 fprintf_symbol_filtered (stb
->stream
, funname
? funname
: "??",
675 ui_out_field_stream (uiout
, "func", stb
);
676 ui_out_wrap_hint (uiout
, " ");
677 annotate_frame_args ();
679 ui_out_text (uiout
, " (");
682 struct print_args_args args
;
683 struct cleanup
*args_list_chain
;
686 args
.stream
= gdb_stdout
;
687 args_list_chain
= make_cleanup_ui_out_list_begin_end (uiout
, "args");
688 catch_errors (print_args_stub
, &args
, "", RETURN_MASK_ALL
);
689 /* FIXME: ARGS must be a list. If one argument is a string it
690 will have " that will not be properly escaped. */
691 /* Invoke ui_out_tuple_end. */
692 do_cleanups (args_list_chain
);
695 ui_out_text (uiout
, ")");
696 if (sal
.symtab
&& sal
.symtab
->filename
)
698 annotate_frame_source_begin ();
699 ui_out_wrap_hint (uiout
, " ");
700 ui_out_text (uiout
, " at ");
701 annotate_frame_source_file ();
702 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
703 if (ui_out_is_mi_like_p (uiout
))
705 const char *fullname
= symtab_to_fullname (sal
.symtab
);
706 if (fullname
!= NULL
)
707 ui_out_field_string (uiout
, "fullname", fullname
);
709 annotate_frame_source_file_end ();
710 ui_out_text (uiout
, ":");
711 annotate_frame_source_line ();
712 ui_out_field_int (uiout
, "line", sal
.line
);
713 annotate_frame_source_end ();
716 if (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
))
719 char *lib
= PC_SOLIB (get_frame_pc (frame
));
721 char *lib
= solib_address (get_frame_pc (frame
));
725 annotate_frame_where ();
726 ui_out_wrap_hint (uiout
, " ");
727 ui_out_text (uiout
, " from ");
728 ui_out_field_string (uiout
, "from", lib
);
732 /* do_cleanups will call ui_out_tuple_end() for us. */
733 do_cleanups (list_chain
);
734 ui_out_text (uiout
, "\n");
735 do_cleanups (old_chain
);
738 /* Show the frame info. If this is the tui, it will be shown in the
739 source display otherwise, nothing is done. */
742 show_stack_frame (struct frame_info
*frame
)
747 /* Read a frame specification in whatever the appropriate format is
748 from FRAME_EXP. Call error(), printing MESSAGE, if the
749 specification is in any way invalid (so this function never returns
750 NULL). When SEPECTED_P is non-NULL set its target to indicate that
751 the default selected frame was used. */
753 static struct frame_info
*
754 parse_frame_specification_1 (const char *frame_exp
, const char *message
,
755 int *selected_frame_p
)
758 struct value
*args
[4];
759 CORE_ADDR addrs
[ARRAY_SIZE (args
)];
761 if (frame_exp
== NULL
)
766 struct cleanup
*tmp_cleanup
;
772 struct cleanup
*cleanup
;
775 /* Skip leading white space, bail of EOL. */
776 while (isspace (*frame_exp
))
781 /* Parse the argument, extract it, save it. */
785 addr_string
= savestring (frame_exp
, p
- frame_exp
);
787 cleanup
= make_cleanup (xfree
, addr_string
);
789 /* NOTE: Parse and evaluate expression, but do not use
790 functions such as parse_and_eval_long or
791 parse_and_eval_address to also extract the value.
792 Instead value_as_long and value_as_address are used.
793 This avoids problems with expressions that contain
795 if (numargs
>= ARRAY_SIZE (args
))
796 error (_("Too many args in frame specification"));
797 args
[numargs
++] = parse_and_eval (addr_string
);
799 do_cleanups (cleanup
);
803 /* If no args, default to the selected frame. */
806 if (selected_frame_p
!= NULL
)
807 (*selected_frame_p
) = 1;
808 return get_selected_frame (message
);
811 /* None of the remaining use the selected frame. */
812 if (selected_frame_p
!= NULL
)
813 (*selected_frame_p
) = 0;
815 /* Assume the single arg[0] is an integer, and try using that to
816 select a frame relative to current. */
819 struct frame_info
*fid
;
820 int level
= value_as_long (args
[0]);
821 fid
= find_relative_frame (get_current_frame (), &level
);
823 /* find_relative_frame was successful */
827 /* Convert each value into a corresponding address. */
830 for (i
= 0; i
< numargs
; i
++)
831 addrs
[i
] = value_as_address (args
[0]);
834 /* Assume that the single arg[0] is an address, use that to identify
835 a frame with a matching ID. Should this also accept stack/pc or
839 struct frame_id id
= frame_id_build_wild (addrs
[0]);
840 struct frame_info
*fid
;
842 /* If (s)he specifies the frame with an address, he deserves
843 what (s)he gets. Still, give the highest one that matches.
844 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
846 for (fid
= get_current_frame ();
848 fid
= get_prev_frame (fid
))
850 if (frame_id_eq (id
, get_frame_id (fid
)))
852 while (frame_id_eq (id
, frame_unwind_id (fid
)))
853 fid
= get_prev_frame (fid
);
859 /* We couldn't identify the frame as an existing frame, but
860 perhaps we can create one with a single argument. */
862 return create_new_frame (addrs
[0], 0);
863 else if (numargs
== 2)
864 return create_new_frame (addrs
[0], addrs
[1]);
866 error (_("Too many args in frame specification"));
869 static struct frame_info
*
870 parse_frame_specification (char *frame_exp
)
872 return parse_frame_specification_1 (frame_exp
, NULL
, NULL
);
875 /* Print verbosely the selected frame or the frame at address
876 ADDR_EXP. Absolutely all information in the frame is printed. */
879 frame_info (char *addr_exp
, int from_tty
)
881 struct frame_info
*fi
;
882 struct symtab_and_line sal
;
885 struct frame_info
*calling_frame_info
;
886 int i
, count
, numregs
;
888 enum language funlang
= language_unknown
;
889 const char *pc_regname
;
890 int selected_frame_p
;
891 struct gdbarch
*gdbarch
;
893 fi
= parse_frame_specification_1 (addr_exp
, "No stack.", &selected_frame_p
);
895 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
896 is not a good name. */
897 if (gdbarch_pc_regnum (current_gdbarch
) >= 0)
898 /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can
899 easily not match that of the internal value returned by
901 pc_regname
= gdbarch_register_name (current_gdbarch
,
902 gdbarch_pc_regnum (current_gdbarch
));
904 /* But then, this is weird to. Even without gdbarch_pc_regnum, an
905 architectures will often have a hardware register called "pc",
906 and that register's value, again, can easily not match
910 find_frame_sal (fi
, &sal
);
911 gdbarch
= get_frame_arch (fi
);
912 func
= get_frame_function (fi
);
913 /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain
915 s
= find_pc_symtab (get_frame_pc (fi
));
918 /* It seems appropriate to use SYMBOL_PRINT_NAME() here, to
919 display the demangled name that we already have stored in the
920 symbol table, but we stored a version with DMGL_PARAMS turned
921 on, and here we don't want to display parameters. So call the
922 demangler again, with DMGL_ANSI only.
924 Yes, printf_symbol_filtered() will again try to demangle the
925 name on the fly, but the issue is that if cplus_demangle()
926 fails here, it will fail there too. So we want to catch the
927 failure (where DEMANGLED is NULL below) here, while we still
928 have our hands on the function symbol.) */
929 funname
= DEPRECATED_SYMBOL_NAME (func
);
930 funlang
= SYMBOL_LANGUAGE (func
);
931 if (funlang
== language_cplus
)
933 char *demangled
= cplus_demangle (funname
, DMGL_ANSI
);
934 /* If the demangler fails, try the demangled name from the
935 symbol table. That'll have parameters, but that's
936 preferable to displaying a mangled name. */
937 if (demangled
== NULL
)
938 funname
= SYMBOL_PRINT_NAME (func
);
945 struct minimal_symbol
*msymbol
;
947 msymbol
= lookup_minimal_symbol_by_pc (get_frame_pc (fi
));
950 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
951 funlang
= SYMBOL_LANGUAGE (msymbol
);
954 calling_frame_info
= get_prev_frame (fi
);
956 if (selected_frame_p
&& frame_relative_level (fi
) >= 0)
958 printf_filtered (_("Stack level %d, frame at "),
959 frame_relative_level (fi
));
963 printf_filtered (_("Stack frame at "));
965 deprecated_print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
966 printf_filtered (":\n");
967 printf_filtered (" %s = ", pc_regname
);
968 deprecated_print_address_numeric (get_frame_pc (fi
), 1, gdb_stdout
);
973 printf_filtered (" in ");
974 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
975 DMGL_ANSI
| DMGL_PARAMS
);
979 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
980 puts_filtered ("; ");
982 printf_filtered ("saved %s ", pc_regname
);
983 deprecated_print_address_numeric (frame_pc_unwind (fi
), 1, gdb_stdout
);
984 printf_filtered ("\n");
986 if (calling_frame_info
== NULL
)
988 enum unwind_stop_reason reason
;
990 reason
= get_frame_unwind_stop_reason (fi
);
991 if (reason
!= UNWIND_NO_REASON
)
992 printf_filtered (_(" Outermost frame: %s\n"),
993 frame_stop_reason_string (reason
));
996 if (calling_frame_info
)
998 printf_filtered (" called by frame at ");
999 deprecated_print_address_numeric (get_frame_base (calling_frame_info
),
1002 if (get_next_frame (fi
) && calling_frame_info
)
1003 puts_filtered (",");
1005 if (get_next_frame (fi
))
1007 printf_filtered (" caller of frame at ");
1008 deprecated_print_address_numeric (get_frame_base (get_next_frame (fi
)), 1,
1011 if (get_next_frame (fi
) || calling_frame_info
)
1012 puts_filtered ("\n");
1015 printf_filtered (" source language %s.\n",
1016 language_str (s
->language
));
1019 /* Address of the argument list for this frame, or 0. */
1020 CORE_ADDR arg_list
= get_frame_args_address (fi
);
1021 /* Number of args for this frame, or -1 if unknown. */
1025 printf_filtered (" Arglist at unknown address.\n");
1028 printf_filtered (" Arglist at ");
1029 deprecated_print_address_numeric (arg_list
, 1, gdb_stdout
);
1030 printf_filtered (",");
1032 if (!gdbarch_frame_num_args_p (gdbarch
))
1035 puts_filtered (" args: ");
1039 numargs
= gdbarch_frame_num_args (gdbarch
, fi
);
1040 gdb_assert (numargs
>= 0);
1042 puts_filtered (" no args.");
1043 else if (numargs
== 1)
1044 puts_filtered (" 1 arg: ");
1046 printf_filtered (" %d args: ", numargs
);
1048 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
1049 puts_filtered ("\n");
1053 /* Address of the local variables for this frame, or 0. */
1054 CORE_ADDR arg_list
= get_frame_locals_address (fi
);
1057 printf_filtered (" Locals at unknown address,");
1060 printf_filtered (" Locals at ");
1061 deprecated_print_address_numeric (arg_list
, 1, gdb_stdout
);
1062 printf_filtered (",");
1066 /* Print as much information as possible on the location of all the
1069 enum lval_type lval
;
1077 /* The sp is special; what's displayed isn't the save address, but
1078 the value of the previous frame's sp. This is a legacy thing,
1079 at one stage the frame cached the previous frame's SP instead
1080 of its address, hence it was easiest to just display the cached
1082 if (gdbarch_sp_regnum (gdbarch
) >= 0)
1084 /* Find out the location of the saved stack pointer with out
1085 actually evaluating it. */
1086 frame_register_unwind (fi
, gdbarch_sp_regnum (gdbarch
),
1087 &optimized
, &lval
, &addr
,
1089 if (!optimized
&& lval
== not_lval
)
1091 gdb_byte value
[MAX_REGISTER_SIZE
];
1093 frame_register_unwind (fi
, gdbarch_sp_regnum (gdbarch
),
1094 &optimized
, &lval
, &addr
,
1096 /* NOTE: cagney/2003-05-22: This is assuming that the
1097 stack pointer was packed as an unsigned integer. That
1098 may or may not be valid. */
1099 sp
= extract_unsigned_integer (value
,
1100 register_size (gdbarch
,
1101 gdbarch_sp_regnum (gdbarch
)));
1102 printf_filtered (" Previous frame's sp is ");
1103 deprecated_print_address_numeric (sp
, 1, gdb_stdout
);
1104 printf_filtered ("\n");
1107 else if (!optimized
&& lval
== lval_memory
)
1109 printf_filtered (" Previous frame's sp at ");
1110 deprecated_print_address_numeric (addr
, 1, gdb_stdout
);
1111 printf_filtered ("\n");
1114 else if (!optimized
&& lval
== lval_register
)
1116 printf_filtered (" Previous frame's sp in %s\n",
1117 gdbarch_register_name (gdbarch
, realnum
));
1120 /* else keep quiet. */
1124 numregs
= gdbarch_num_regs (gdbarch
)
1125 + gdbarch_num_pseudo_regs (gdbarch
);
1126 for (i
= 0; i
< numregs
; i
++)
1127 if (i
!= gdbarch_sp_regnum (gdbarch
)
1128 && gdbarch_register_reggroup_p (gdbarch
, i
, all_reggroup
))
1130 /* Find out the location of the saved register without
1131 fetching the corresponding value. */
1132 frame_register_unwind (fi
, i
, &optimized
, &lval
, &addr
, &realnum
,
1134 /* For moment, only display registers that were saved on the
1136 if (!optimized
&& lval
== lval_memory
)
1139 puts_filtered (" Saved registers:\n ");
1141 puts_filtered (",");
1143 printf_filtered (" %s at ",
1144 gdbarch_register_name (gdbarch
, i
));
1145 deprecated_print_address_numeric (addr
, 1, gdb_stdout
);
1149 if (count
|| need_nl
)
1150 puts_filtered ("\n");
1154 /* Print briefly all stack frames or just the innermost COUNT_EXP
1158 backtrace_command_1 (char *count_exp
, int show_locals
, int from_tty
)
1160 struct frame_info
*fi
;
1163 struct frame_info
*trailing
;
1166 if (!target_has_stack
)
1167 error (_("No stack."));
1169 /* The following code must do two things. First, it must set the
1170 variable TRAILING to the frame from which we should start
1171 printing. Second, it must set the variable count to the number
1172 of frames which we should print, or -1 if all of them. */
1173 trailing
= get_current_frame ();
1175 /* The target can be in a state where there is no valid frames
1176 (e.g., just connected). */
1177 if (trailing
== NULL
)
1178 error (_("No stack."));
1183 count
= parse_and_eval_long (count_exp
);
1186 struct frame_info
*current
;
1191 while (current
&& count
--)
1194 current
= get_prev_frame (current
);
1197 /* Will stop when CURRENT reaches the top of the stack.
1198 TRAILING will be COUNT below it. */
1202 trailing
= get_prev_frame (trailing
);
1203 current
= get_prev_frame (current
);
1215 struct partial_symtab
*ps
;
1217 /* Read in symbols for all of the frames. Need to do this in a
1218 separate pass so that "Reading in symbols for xxx" messages
1219 don't screw up the appearance of the backtrace. Also if
1220 people have strong opinions against reading symbols for
1221 backtrace this may have to be an option. */
1223 for (fi
= trailing
; fi
!= NULL
&& i
--; fi
= get_prev_frame (fi
))
1226 ps
= find_pc_psymtab (get_frame_address_in_block (fi
));
1228 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in. */
1232 for (i
= 0, fi
= trailing
; fi
&& count
--; i
++, fi
= get_prev_frame (fi
))
1236 /* Don't use print_stack_frame; if an error() occurs it probably
1237 means further attempts to backtrace would fail (on the other
1238 hand, perhaps the code does or could be fixed to make sure
1239 the frame->prev field gets set to NULL in that case). */
1240 print_frame_info (fi
, 1, LOCATION
, 1);
1242 print_frame_local_vars (fi
, 1, gdb_stdout
);
1244 /* Save the last frame to check for error conditions. */
1248 /* If we've stopped before the end, mention that. */
1250 printf_filtered (_("(More stack frames follow...)\n"));
1252 /* If we've run out of frames, and the reason appears to be an error
1253 condition, print it. */
1254 if (fi
== NULL
&& trailing
!= NULL
)
1256 enum unwind_stop_reason reason
;
1258 reason
= get_frame_unwind_stop_reason (trailing
);
1259 if (reason
> UNWIND_FIRST_ERROR
)
1260 printf_filtered (_("Backtrace stopped: %s\n"),
1261 frame_stop_reason_string (reason
));
1265 struct backtrace_command_args
1272 /* Stub for catch_errors. */
1275 backtrace_command_stub (void *data
)
1277 struct backtrace_command_args
*args
= data
;
1278 backtrace_command_1 (args
->count_exp
, args
->show_locals
, args
->from_tty
);
1283 backtrace_command (char *arg
, int from_tty
)
1285 struct cleanup
*old_chain
= NULL
;
1286 int fulltrace_arg
= -1, arglen
= 0, argc
= 0;
1287 struct backtrace_command_args btargs
;
1294 argv
= buildargv (arg
);
1295 old_chain
= make_cleanup_freeargv (argv
);
1297 for (i
= 0; argv
[i
]; i
++)
1301 for (j
= 0; j
< strlen (argv
[i
]); j
++)
1302 argv
[i
][j
] = tolower (argv
[i
][j
]);
1304 if (fulltrace_arg
< 0 && subset_compare (argv
[i
], "full"))
1305 fulltrace_arg
= argc
;
1308 arglen
+= strlen (argv
[i
]);
1313 if (fulltrace_arg
>= 0)
1317 arg
= xmalloc (arglen
+ 1);
1318 memset (arg
, 0, arglen
+ 1);
1319 for (i
= 0; i
< (argc
+ 1); i
++)
1321 if (i
!= fulltrace_arg
)
1323 strcat (arg
, argv
[i
]);
1333 btargs
.count_exp
= arg
;
1334 btargs
.show_locals
= (fulltrace_arg
>= 0);
1335 btargs
.from_tty
= from_tty
;
1336 catch_errors (backtrace_command_stub
, &btargs
, "", RETURN_MASK_ERROR
);
1338 if (fulltrace_arg
>= 0 && arglen
> 0)
1342 do_cleanups (old_chain
);
1346 backtrace_full_command (char *arg
, int from_tty
)
1348 struct backtrace_command_args btargs
;
1349 btargs
.count_exp
= arg
;
1350 btargs
.show_locals
= 1;
1351 btargs
.from_tty
= from_tty
;
1352 catch_errors (backtrace_command_stub
, &btargs
, "", RETURN_MASK_ERROR
);
1356 /* Print the local variables of a block B active in FRAME on STREAM.
1357 Return 1 if any variables were printed; 0 otherwise. */
1360 print_block_frame_locals (struct block
*b
, struct frame_info
*frame
,
1361 int num_tabs
, struct ui_file
*stream
)
1363 struct dict_iterator iter
;
1365 int values_printed
= 0;
1368 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1370 switch (SYMBOL_CLASS (sym
))
1378 for (j
= 0; j
< num_tabs
; j
++)
1379 fputs_filtered ("\t", stream
);
1380 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1381 fputs_filtered (" = ", stream
);
1382 print_variable_value (sym
, frame
, stream
);
1383 fprintf_filtered (stream
, "\n");
1387 /* Ignore symbols which are not locals. */
1392 return values_printed
;
1395 /* Same, but print labels. */
1398 print_block_frame_labels (struct block
*b
, int *have_default
,
1399 struct ui_file
*stream
)
1401 struct dict_iterator iter
;
1403 int values_printed
= 0;
1405 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1407 if (strcmp (DEPRECATED_SYMBOL_NAME (sym
), "default") == 0)
1413 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1415 struct symtab_and_line sal
;
1416 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1418 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1421 fprintf_filtered (stream
, " ");
1422 deprecated_print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, stream
);
1424 fprintf_filtered (stream
, " in file %s, line %d\n",
1425 sal
.symtab
->filename
, sal
.line
);
1429 return values_printed
;
1432 /* Print on STREAM all the local variables in frame FRAME, including
1433 all the blocks active in that frame at its current PC.
1435 Returns 1 if the job was done, or 0 if nothing was printed because
1436 we have no info on the function running in FRAME. */
1439 print_frame_local_vars (struct frame_info
*frame
, int num_tabs
,
1440 struct ui_file
*stream
)
1442 struct block
*block
= get_frame_block (frame
, 0);
1443 int values_printed
= 0;
1447 fprintf_filtered (stream
, "No symbol table info available.\n");
1453 if (print_block_frame_locals (block
, frame
, num_tabs
, stream
))
1455 /* After handling the function's top-level block, stop. Don't
1456 continue to its superblock, the block of per-file symbols. */
1457 if (BLOCK_FUNCTION (block
))
1459 block
= BLOCK_SUPERBLOCK (block
);
1462 if (!values_printed
)
1463 fprintf_filtered (stream
, _("No locals.\n"));
1466 /* Same, but print labels. */
1469 print_frame_label_vars (struct frame_info
*frame
, int this_level_only
,
1470 struct ui_file
*stream
)
1472 struct blockvector
*bl
;
1473 struct block
*block
= get_frame_block (frame
, 0);
1474 int values_printed
= 0;
1475 int index
, have_default
= 0;
1476 char *blocks_printed
;
1477 CORE_ADDR pc
= get_frame_pc (frame
);
1481 fprintf_filtered (stream
, "No symbol table info available.\n");
1485 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1486 blocks_printed
= alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1487 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1491 CORE_ADDR end
= BLOCK_END (block
) - 4;
1494 if (bl
!= blockvector_for_pc (end
, &index
))
1495 error (_("blockvector blotch"));
1496 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1497 error (_("blockvector botch"));
1498 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1501 /* Don't print out blocks that have gone by. */
1502 while (index
< last_index
1503 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1506 while (index
< last_index
1507 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1509 if (blocks_printed
[index
] == 0)
1511 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
),
1512 &have_default
, stream
))
1514 blocks_printed
[index
] = 1;
1520 if (values_printed
&& this_level_only
)
1523 /* After handling the function's top-level block, stop. Don't
1524 continue to its superblock, the block of per-file symbols. */
1525 if (BLOCK_FUNCTION (block
))
1527 block
= BLOCK_SUPERBLOCK (block
);
1530 if (!values_printed
&& !this_level_only
)
1531 fprintf_filtered (stream
, _("No catches.\n"));
1535 locals_info (char *args
, int from_tty
)
1537 print_frame_local_vars (get_selected_frame (_("No frame selected.")),
1542 catch_info (char *ignore
, int from_tty
)
1544 struct symtab_and_line
*sal
;
1546 /* Check for target support for exception handling */
1547 sal
= target_enable_exception_callback (EX_EVENT_CATCH
, 1);
1550 /* Currently not handling this. Ideally, here we should
1551 interact with the C++ runtime system to find the list of
1552 active handlers, etc. */
1553 fprintf_filtered (gdb_stdout
, _("\
1554 Info catch not supported with this target/compiler combination.\n"));
1558 /* Assume g++ compiled code; old GDB 4.16 behaviour. */
1559 print_frame_label_vars (get_selected_frame (_("No frame selected.")),
1565 print_frame_arg_vars (struct frame_info
*frame
, struct ui_file
*stream
)
1567 struct symbol
*func
= get_frame_function (frame
);
1569 struct dict_iterator iter
;
1570 struct symbol
*sym
, *sym2
;
1571 int values_printed
= 0;
1575 fprintf_filtered (stream
, _("No symbol table info available.\n"));
1579 b
= SYMBOL_BLOCK_VALUE (func
);
1580 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1582 switch (SYMBOL_CLASS (sym
))
1588 case LOC_REGPARM_ADDR
:
1589 case LOC_BASEREG_ARG
:
1590 case LOC_COMPUTED_ARG
:
1592 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1593 fputs_filtered (" = ", stream
);
1595 /* We have to look up the symbol because arguments can have
1596 two entries (one a parameter, one a local) and the one we
1597 want is the local, which lookup_symbol will find for us.
1598 This includes gcc1 (not gcc2) on the sparc when passing a
1599 small structure and gcc2 when the argument type is float
1600 and it is passed as a double and converted to float by
1601 the prologue (in the latter case the type of the LOC_ARG
1602 symbol is double and the type of the LOC_LOCAL symbol is
1603 float). There are also LOC_ARG/LOC_REGISTER pairs which
1604 are not combined in symbol-reading. */
1606 sym2
= lookup_symbol (DEPRECATED_SYMBOL_NAME (sym
),
1607 b
, VAR_DOMAIN
, NULL
, NULL
);
1608 print_variable_value (sym2
, frame
, stream
);
1609 fprintf_filtered (stream
, "\n");
1613 /* Don't worry about things which aren't arguments. */
1618 if (!values_printed
)
1619 fprintf_filtered (stream
, _("No arguments.\n"));
1623 args_info (char *ignore
, int from_tty
)
1625 print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
1631 args_plus_locals_info (char *ignore
, int from_tty
)
1633 args_info (ignore
, from_tty
);
1634 locals_info (ignore
, from_tty
);
1638 /* Select frame FRAME. Also print the stack frame and show the source
1639 if this is the tui version. */
1641 select_and_print_frame (struct frame_info
*frame
)
1643 select_frame (frame
);
1645 print_stack_frame (frame
, 1, SRC_AND_LOC
);
1648 /* Return the symbol-block in which the selected frame is executing.
1649 Can return zero under various legitimate circumstances.
1651 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1652 code address within the block returned. We use this to decide
1653 which macros are in scope. */
1656 get_selected_block (CORE_ADDR
*addr_in_block
)
1658 if (!target_has_stack
)
1661 return get_frame_block (get_selected_frame (NULL
), addr_in_block
);
1664 /* Find a frame a certain number of levels away from FRAME.
1665 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1666 Positive means go to earlier frames (up); negative, the reverse.
1667 The int that contains the number of levels is counted toward
1668 zero as the frames for those levels are found.
1669 If the top or bottom frame is reached, that frame is returned,
1670 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1671 how much farther the original request asked to go. */
1674 find_relative_frame (struct frame_info
*frame
, int *level_offset_ptr
)
1676 /* Going up is simple: just call get_prev_frame enough times or
1677 until the initial frame is reached. */
1678 while (*level_offset_ptr
> 0)
1680 struct frame_info
*prev
= get_prev_frame (frame
);
1683 (*level_offset_ptr
)--;
1687 /* Going down is just as simple. */
1688 while (*level_offset_ptr
< 0)
1690 struct frame_info
*next
= get_next_frame (frame
);
1693 (*level_offset_ptr
)++;
1700 /* The "select_frame" command. With no argument this is a NOP.
1701 Select the frame at level LEVEL_EXP if it is a valid level.
1702 Otherwise, treat LEVEL_EXP as an address expression and select it.
1704 See parse_frame_specification for more info on proper frame
1708 select_frame_command (char *level_exp
, int from_tty
)
1710 select_frame (parse_frame_specification_1 (level_exp
, "No stack.", NULL
));
1713 /* The "frame" command. With no argument, print the selected frame
1714 briefly. With an argument, behave like select_frame and then print
1715 the selected frame. */
1718 frame_command (char *level_exp
, int from_tty
)
1720 select_frame_command (level_exp
, from_tty
);
1721 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1724 /* The XDB Compatibility command to print the current frame. */
1727 current_frame_command (char *level_exp
, int from_tty
)
1729 print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC
);
1732 /* Select the frame up one or COUNT_EXP stack levels from the
1733 previously selected frame, and print it briefly. */
1736 up_silently_base (char *count_exp
)
1738 struct frame_info
*frame
;
1742 count
= parse_and_eval_long (count_exp
);
1744 frame
= find_relative_frame (get_selected_frame ("No stack."), &count
);
1745 if (count
!= 0 && count_exp
== NULL
)
1746 error (_("Initial frame selected; you cannot go up."));
1747 select_frame (frame
);
1751 up_silently_command (char *count_exp
, int from_tty
)
1753 up_silently_base (count_exp
);
1757 up_command (char *count_exp
, int from_tty
)
1759 up_silently_base (count_exp
);
1760 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1763 /* Select the frame down one or COUNT_EXP stack levels from the previously
1764 selected frame, and print it briefly. */
1767 down_silently_base (char *count_exp
)
1769 struct frame_info
*frame
;
1772 count
= -parse_and_eval_long (count_exp
);
1774 frame
= find_relative_frame (get_selected_frame ("No stack."), &count
);
1775 if (count
!= 0 && count_exp
== NULL
)
1777 /* We only do this if COUNT_EXP is not specified. That way
1778 "down" means to really go down (and let me know if that is
1779 impossible), but "down 9999" can be used to mean go all the
1780 way down without getting an error. */
1782 error (_("Bottom (innermost) frame selected; you cannot go down."));
1785 select_frame (frame
);
1789 down_silently_command (char *count_exp
, int from_tty
)
1791 down_silently_base (count_exp
);
1795 down_command (char *count_exp
, int from_tty
)
1797 down_silently_base (count_exp
);
1798 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1803 return_command (char *retval_exp
, int from_tty
)
1805 struct symbol
*thisfun
;
1806 struct value
*return_value
= NULL
;
1807 const char *query_prefix
= "";
1809 thisfun
= get_frame_function (get_selected_frame ("No selected frame."));
1811 /* Compute the return value. If the computation triggers an error,
1812 let it bail. If the return type can't be handled, set
1813 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
1817 struct type
*return_type
= NULL
;
1819 /* Compute the return value. Should the computation fail, this
1820 call throws an error. */
1821 return_value
= parse_and_eval (retval_exp
);
1823 /* Cast return value to the return type of the function. Should
1824 the cast fail, this call throws an error. */
1825 if (thisfun
!= NULL
)
1826 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
1827 if (return_type
== NULL
)
1828 return_type
= builtin_type_int
;
1829 CHECK_TYPEDEF (return_type
);
1830 return_value
= value_cast (return_type
, return_value
);
1832 /* Make sure the value is fully evaluated. It may live in the
1833 stack frame we're about to pop. */
1834 if (value_lazy (return_value
))
1835 value_fetch_lazy (return_value
);
1837 if (TYPE_CODE (return_type
) == TYPE_CODE_VOID
)
1838 /* If the return-type is "void", don't try to find the
1839 return-value's location. However, do still evaluate the
1840 return expression so that, even when the expression result
1841 is discarded, side effects such as "return i++" still
1843 return_value
= NULL
;
1844 else if (using_struct_return (return_type
))
1847 The location at which to store the function's return value is unknown.\n\
1848 If you continue, the return value that you specified will be ignored.\n";
1849 return_value
= NULL
;
1853 /* Does an interactive user really want to do this? Include
1854 information, such as how well GDB can handle the return value, in
1855 the query message. */
1859 if (thisfun
== NULL
)
1860 confirmed
= query (_("%sMake selected stack frame return now? "),
1863 confirmed
= query (_("%sMake %s return now? "), query_prefix
,
1864 SYMBOL_PRINT_NAME (thisfun
));
1866 error (_("Not confirmed"));
1869 /* NOTE: cagney/2003-01-18: Is this silly? Rather than pop each
1870 frame in turn, should this code just go straight to the relevant
1871 frame and pop that? */
1873 /* First discard all frames inner-to the selected frame (making the
1874 selected frame current). */
1876 struct frame_id selected_id
= get_frame_id (get_selected_frame (NULL
));
1877 while (!frame_id_eq (selected_id
, get_frame_id (get_current_frame ())))
1879 struct frame_info
*frame
= get_current_frame ();
1880 if (frame_id_inner (get_frame_arch (frame
), selected_id
,
1881 get_frame_id (frame
)))
1882 /* Caught in the safety net, oops! We've gone way past the
1884 error (_("Problem while popping stack frames (corrupt stack?)"));
1885 frame_pop (get_current_frame ());
1889 /* Second discard the selected frame (which is now also the current
1891 frame_pop (get_current_frame ());
1893 /* Store RETURN_VALUE in the just-returned register set. */
1894 if (return_value
!= NULL
)
1896 struct type
*return_type
= value_type (return_value
);
1897 struct gdbarch
*gdbarch
= get_regcache_arch (get_current_regcache ());
1898 gdb_assert (gdbarch_return_value (gdbarch
, return_type
, NULL
, NULL
, NULL
)
1899 == RETURN_VALUE_REGISTER_CONVENTION
);
1900 gdbarch_return_value (gdbarch
, return_type
,
1901 get_current_regcache (), NULL
/*read*/,
1902 value_contents (return_value
) /*write*/);
1905 /* If we are at the end of a call dummy now, pop the dummy frame
1907 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME
)
1908 frame_pop (get_current_frame ());
1910 /* If interactive, print the frame that is now current. */
1912 frame_command ("0", 1);
1914 select_frame_command ("0", 0);
1917 /* Sets the scope to input function name, provided that the function
1918 is within the current stack frame */
1920 struct function_bounds
1922 CORE_ADDR low
, high
;
1926 func_command (char *arg
, int from_tty
)
1928 struct frame_info
*frame
;
1930 struct symtabs_and_lines sals
;
1933 struct function_bounds
*func_bounds
= NULL
;
1938 frame
= parse_frame_specification ("0");
1939 sals
= decode_line_spec (arg
, 1);
1940 func_bounds
= (struct function_bounds
*) xmalloc (
1941 sizeof (struct function_bounds
) * sals
.nelts
);
1942 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1944 if (sals
.sals
[i
].pc
== 0
1945 || find_pc_partial_function (sals
.sals
[i
].pc
, NULL
,
1946 &func_bounds
[i
].low
,
1947 &func_bounds
[i
].high
) == 0)
1949 func_bounds
[i
].low
= func_bounds
[i
].high
= 0;
1955 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1956 found
= (get_frame_pc (frame
) >= func_bounds
[i
].low
1957 && get_frame_pc (frame
) < func_bounds
[i
].high
);
1961 frame
= find_relative_frame (frame
, &level
);
1964 while (!found
&& level
== 0);
1967 xfree (func_bounds
);
1970 printf_filtered (_("'%s' not within current stack frame.\n"), arg
);
1971 else if (frame
!= get_selected_frame (NULL
))
1972 select_and_print_frame (frame
);
1975 /* Gets the language of the current frame. */
1978 get_frame_language (void)
1980 struct frame_info
*frame
= deprecated_safe_get_selected_frame ();
1984 /* We determine the current frame language by looking up its
1985 associated symtab. To retrieve this symtab, we use the frame
1986 PC. However we cannot use the frame PC as is, because it
1987 usually points to the instruction following the "call", which
1988 is sometimes the first instruction of another function. So
1989 we rely on get_frame_address_in_block(), it provides us with
1990 a PC that is guaranteed to be inside the frame's code
1992 CORE_ADDR pc
= get_frame_address_in_block (frame
);
1993 struct symtab
*s
= find_pc_symtab (pc
);
1999 return language_unknown
;
2003 /* Provide a prototype to silence -Wmissing-prototypes. */
2004 void _initialize_stack (void);
2007 _initialize_stack (void)
2010 backtrace_limit
= 30;
2013 add_com ("return", class_stack
, return_command
, _("\
2014 Make selected stack frame return to its caller.\n\
2015 Control remains in the debugger, but when you continue\n\
2016 execution will resume in the frame above the one now selected.\n\
2017 If an argument is given, it is an expression for the value to return."));
2019 add_com ("up", class_stack
, up_command
, _("\
2020 Select and print stack frame that called this one.\n\
2021 An argument says how many frames up to go."));
2022 add_com ("up-silently", class_support
, up_silently_command
, _("\
2023 Same as the `up' command, but does not print anything.\n\
2024 This is useful in command scripts."));
2026 add_com ("down", class_stack
, down_command
, _("\
2027 Select and print stack frame called by this one.\n\
2028 An argument says how many frames down to go."));
2029 add_com_alias ("do", "down", class_stack
, 1);
2030 add_com_alias ("dow", "down", class_stack
, 1);
2031 add_com ("down-silently", class_support
, down_silently_command
, _("\
2032 Same as the `down' command, but does not print anything.\n\
2033 This is useful in command scripts."));
2035 add_com ("frame", class_stack
, frame_command
, _("\
2036 Select and print a stack frame.\n\
2037 With no argument, print the selected stack frame. (See also \"info frame\").\n\
2038 An argument specifies the frame to select.\n\
2039 It can be a stack frame number or the address of the frame.\n\
2040 With argument, nothing is printed if input is coming from\n\
2041 a command file or a user-defined command."));
2043 add_com_alias ("f", "frame", class_stack
, 1);
2047 add_com ("L", class_stack
, current_frame_command
,
2048 _("Print the current stack frame.\n"));
2049 add_com_alias ("V", "frame", class_stack
, 1);
2051 add_com ("select-frame", class_stack
, select_frame_command
, _("\
2052 Select a stack frame without printing anything.\n\
2053 An argument specifies the frame to select.\n\
2054 It can be a stack frame number or the address of the frame.\n"));
2056 add_com ("backtrace", class_stack
, backtrace_command
, _("\
2057 Print backtrace of all stack frames, or innermost COUNT frames.\n\
2058 With a negative argument, print outermost -COUNT frames.\n\
2059 Use of the 'full' qualifier also prints the values of the local variables.\n"));
2060 add_com_alias ("bt", "backtrace", class_stack
, 0);
2063 add_com_alias ("t", "backtrace", class_stack
, 0);
2064 add_com ("T", class_stack
, backtrace_full_command
, _("\
2065 Print backtrace of all stack frames, or innermost COUNT frames \n\
2066 and the values of the local variables.\n\
2067 With a negative argument, print outermost -COUNT frames.\n\
2068 Usage: T <count>\n"));
2071 add_com_alias ("where", "backtrace", class_alias
, 0);
2072 add_info ("stack", backtrace_command
,
2073 _("Backtrace of the stack, or innermost COUNT frames."));
2074 add_info_alias ("s", "stack", 1);
2075 add_info ("frame", frame_info
,
2076 _("All about selected stack frame, or frame at ADDR."));
2077 add_info_alias ("f", "frame", 1);
2078 add_info ("locals", locals_info
,
2079 _("Local variables of current stack frame."));
2080 add_info ("args", args_info
,
2081 _("Argument variables of current stack frame."));
2083 add_com ("l", class_info
, args_plus_locals_info
,
2084 _("Argument and local variables of current stack frame."));
2087 add_com ("func", class_stack
, func_command
, _("\
2088 Select the stack frame that contains <func>.\n\
2089 Usage: func <name>\n"));
2091 add_info ("catch", catch_info
,
2092 _("Exceptions that can be caught in the current stack frame."));
2094 add_setshow_enum_cmd ("frame-arguments", class_stack
,
2095 print_frame_arguments_choices
, &print_frame_arguments
,
2096 _("Set printing of non-scalar frame arguments"),
2097 _("Show printing of non-scalar frame arguments"),
2098 NULL
, NULL
, NULL
, &setprintlist
, &showprintlist
);
2101 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
, _(\
2102 "Specify maximum number of frames for \"backtrace\" to print by default."),
2104 add_info ("backtrace-limit", backtrace_limit_info
, _("\
2105 The maximum number of frames for \"backtrace\" to print by default."));