gdb/stack.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* Print and select stack frames for GDB, the GNU debugger.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "value.h"
  16. #include "symtab.h"
  17. #include "gdbtypes.h"
  18. #include "expression.h"
  19. #include "language.h"
  20. #include "frame.h"
  21. #include "gdbcmd.h"
  22. #include "gdbcore.h"
  23. #include "target.h"
  24. #include "source.h"
  25. #include "breakpoint.h"
  26. #include "demangle.h"
  27. #include "inferior.h"
  28. #include "annotate.h"
  29. #include "ui-out.h"
  30. #include "block.h"
  31. #include "stack.h"
  32. #include "dictionary.h"
  33. #include "reggroups.h"
  34. #include "regcache.h"
  35. #include "solib.h"
  36. #include "valprint.h"
  37. #include "gdbthread.h"
  38. #include "cp-support.h"
  39. #include "disasm.h"
  40. #include "inline-frame.h"
  41. #include "linespec.h"
  42. #include "cli/cli-utils.h"
  43. #include "objfiles.h"

  44. #include <ctype.h>
  45. #include "symfile.h"
  46. #include "extension.h"

  47. void (*deprecated_selected_frame_level_changed_hook) (int);

  48. /* The possible choices of "set print frame-arguments", and the value
  49.    of this setting.  */

  50. static const char *const print_frame_arguments_choices[] =
  51.   {"all", "scalars", "none", NULL};
  52. static const char *print_frame_arguments = "scalars";

  53. /* If non-zero, don't invoke pretty-printers for frame arguments.  */
  54. static int print_raw_frame_arguments;

  55. /* The possible choices of "set print entry-values", and the value
  56.    of this setting.  */

  57. const char print_entry_values_no[] = "no";
  58. const char print_entry_values_only[] = "only";
  59. const char print_entry_values_preferred[] = "preferred";
  60. const char print_entry_values_if_needed[] = "if-needed";
  61. const char print_entry_values_both[] = "both";
  62. const char print_entry_values_compact[] = "compact";
  63. const char print_entry_values_default[] = "default";
  64. static const char *const print_entry_values_choices[] =
  65. {
  66.   print_entry_values_no,
  67.   print_entry_values_only,
  68.   print_entry_values_preferred,
  69.   print_entry_values_if_needed,
  70.   print_entry_values_both,
  71.   print_entry_values_compact,
  72.   print_entry_values_default,
  73.   NULL
  74. };
  75. const char *print_entry_values = print_entry_values_default;

  76. /* Prototypes for local functions.  */

  77. static void print_frame_local_vars (struct frame_info *, int,
  78.                                     struct ui_file *);

  79. static void print_frame (struct frame_info *frame, int print_level,
  80.                          enum print_what print_whatint print_args,
  81.                          struct symtab_and_line sal);

  82. static void set_last_displayed_sal (int valid,
  83.                                     struct program_space *pspace,
  84.                                     CORE_ADDR addr,
  85.                                     struct symtab *symtab,
  86.                                     int line);

  87. /* Zero means do things normally; we are interacting directly with the
  88.    user.  One means print the full filename and linenumber when a
  89.    frame is printed, and do so in a format emacs18/emacs19.22 can
  90.    parseTwo means print similar annotations, but in many more
  91.    cases and in a slightly different syntax.  */

  92. int annotation_level = 0;

  93. /* These variables hold the last symtab and line we displayed to the user.
  94. * This is where we insert a breakpoint or a skiplist entry by default.  */
  95. static int last_displayed_sal_valid = 0;
  96. static struct program_space *last_displayed_pspace = 0;
  97. static CORE_ADDR last_displayed_addr = 0;
  98. static struct symtab *last_displayed_symtab = 0;
  99. static int last_displayed_line = 0;


  100. /* Return 1 if we should display the address in addition to the location,
  101.    because we are in the middle of a statement.  */

  102. static int
  103. frame_show_address (struct frame_info *frame,
  104.                     struct symtab_and_line sal)
  105. {
  106.   /* If there is a line number, but no PC, then there is no location
  107.      information associated with this sal.  The only way that should
  108.      happen is for the call sites of inlined functions (SAL comes from
  109.      find_frame_sal).  Otherwise, we would have some PC range if the
  110.      SAL came from a line table.  */
  111.   if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
  112.     {
  113.       if (get_next_frame (frame) == NULL)
  114.         gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
  115.       else
  116.         gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
  117.       return 0;
  118.     }

  119.   return get_frame_pc (frame) != sal.pc;
  120. }

  121. /* Show or print a stack frame FRAME briefly.  The output is format
  122.    according to PRINT_LEVEL and PRINT_WHAT printing the frame's
  123.    relative level, function name, argument list, and file name and
  124.    line number.  If the frame's PC is not at the beginning of the
  125.    source line, the actual PC is printed at the beginning.  */

  126. void
  127. print_stack_frame (struct frame_info *frame, int print_level,
  128.                    enum print_what print_what,
  129.                    int set_current_sal)
  130. {
  131.   volatile struct gdb_exception e;

  132.   /* For mi, alway print location and address.  */
  133.   if (ui_out_is_mi_like_p (current_uiout))
  134.     print_what = LOC_AND_ADDRESS;

  135.   TRY_CATCH (e, RETURN_MASK_ERROR)
  136.     {
  137.       print_frame_info (frame, print_level, print_what, 1 /* print_args */,
  138.                         set_current_sal);
  139.       if (set_current_sal)
  140.         set_current_sal_from_frame (frame);
  141.     }
  142. }

  143. /* Print nameless arguments of frame FRAME on STREAM, where START is
  144.    the offset of the first nameless argument, and NUM is the number of
  145.    nameless arguments to print.  FIRST is nonzero if this is the first
  146.    argument (not just the first nameless argument).  */

  147. static void
  148. print_frame_nameless_args (struct frame_info *frame, long start, int num,
  149.                            int first, struct ui_file *stream)
  150. {
  151.   struct gdbarch *gdbarch = get_frame_arch (frame);
  152.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  153.   int i;
  154.   CORE_ADDR argsaddr;
  155.   long arg_value;

  156.   for (i = 0; i < num; i++)
  157.     {
  158.       QUIT;
  159.       argsaddr = get_frame_args_address (frame);
  160.       if (!argsaddr)
  161.         return;
  162.       arg_value = read_memory_integer (argsaddr + start,
  163.                                        sizeof (int), byte_order);
  164.       if (!first)
  165.         fprintf_filtered (stream, ", ");
  166.       fprintf_filtered (stream, "%ld", arg_value);
  167.       first = 0;
  168.       start += sizeof (int);
  169.     }
  170. }

  171. /* Print single argument of inferior function.  ARG must be already
  172.    read in.

  173.    Errors are printed as if they would be the parameter value.  Use zeroed ARG
  174.    iff it should not be printed accoring to user settings.  */

  175. static void
  176. print_frame_arg (const struct frame_arg *arg)
  177. {
  178.   struct ui_out *uiout = current_uiout;
  179.   volatile struct gdb_exception except;
  180.   struct cleanup *old_chain;
  181.   struct ui_file *stb;

  182.   stb = mem_fileopen ();
  183.   old_chain = make_cleanup_ui_file_delete (stb);

  184.   gdb_assert (!arg->val || !arg->error);
  185.   gdb_assert (arg->entry_kind == print_entry_values_no
  186.               || arg->entry_kind == print_entry_values_only
  187.               || (!ui_out_is_mi_like_p (uiout)
  188.                   && arg->entry_kind == print_entry_values_compact));

  189.   annotate_arg_begin ();

  190.   make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
  191.   fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
  192.                            SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
  193.   if (arg->entry_kind == print_entry_values_compact)
  194.     {
  195.       /* It is OK to provide invalid MI-like stream as with
  196.          PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
  197.       fputs_filtered ("=", stb);

  198.       fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
  199.                                SYMBOL_LANGUAGE (arg->sym),
  200.                                DMGL_PARAMS | DMGL_ANSI);
  201.     }
  202.   if (arg->entry_kind == print_entry_values_only
  203.       || arg->entry_kind == print_entry_values_compact)
  204.     fputs_filtered ("@entry", stb);
  205.   ui_out_field_stream (uiout, "name", stb);
  206.   annotate_arg_name_end ();
  207.   ui_out_text (uiout, "=");

  208.   if (!arg->val && !arg->error)
  209.     ui_out_text (uiout, "...");
  210.   else
  211.     {
  212.       if (arg->error)
  213.         except.message = arg->error;
  214.       else
  215.         {
  216.           /* TRY_CATCH has two statements, wrap it in a block.  */

  217.           TRY_CATCH (except, RETURN_MASK_ERROR)
  218.             {
  219.               const struct language_defn *language;
  220.               struct value_print_options opts;

  221.               /* Avoid value_print because it will deref ref parameters.  We
  222.                  just want to print their addresses.  Print ??? for args whose
  223.                  address we do not know.  We pass 2 as "recurse" to val_print
  224.                  because our standard indentation here is 4 spaces, and
  225.                  val_print indents 2 for each recurse.  */

  226.               annotate_arg_value (value_type (arg->val));

  227.               /* Use the appropriate language to display our symbol, unless the
  228.                  user forced the language to a specific language.  */
  229.               if (language_mode == language_mode_auto)
  230.                 language = language_def (SYMBOL_LANGUAGE (arg->sym));
  231.               else
  232.                 language = current_language;

  233.               get_no_prettyformat_print_options (&opts);
  234.               opts.deref_ref = 1;
  235.               opts.raw = print_raw_frame_arguments;

  236.               /* True in "summary" mode, false otherwise.  */
  237.               opts.summary = !strcmp (print_frame_arguments, "scalars");

  238.               common_val_print (arg->val, stb, 2, &opts, language);
  239.             }
  240.         }
  241.       if (except.message)
  242.         fprintf_filtered (stb, _("<error reading variable: %s>"),
  243.                           except.message);
  244.     }

  245.   ui_out_field_stream (uiout, "value", stb);

  246.   /* Also invoke ui_out_tuple_end.  */
  247.   do_cleanups (old_chain);

  248.   annotate_arg_end ();
  249. }

  250. /* Read in inferior function local SYM at FRAME into ARGP.  Caller is
  251.    responsible for xfree of ARGP->ERROR.  This function never throws an
  252.    exception.  */

  253. void
  254. read_frame_local (struct symbol *sym, struct frame_info *frame,
  255.                   struct frame_arg *argp)
  256. {
  257.   volatile struct gdb_exception except;
  258.   struct value *val = NULL;

  259.   TRY_CATCH (except, RETURN_MASK_ERROR)
  260.     {
  261.       val = read_var_value (sym, frame);
  262.     }

  263.   argp->error = (val == NULL) ? xstrdup (except.message) : NULL;
  264.   argp->sym = sym;
  265.   argp->val = val;
  266. }

  267. /* Read in inferior function parameter SYM at FRAME into ARGP.  Caller is
  268.    responsible for xfree of ARGP->ERROR.  This function never throws an
  269.    exception.  */

  270. void
  271. read_frame_arg (struct symbol *sym, struct frame_info *frame,
  272.                 struct frame_arg *argp, struct frame_arg *entryargp)
  273. {
  274.   struct value *val = NULL, *entryval = NULL;
  275.   char *val_error = NULL, *entryval_error = NULL;
  276.   int val_equal = 0;
  277.   volatile struct gdb_exception except;

  278.   if (print_entry_values != print_entry_values_only
  279.       && print_entry_values != print_entry_values_preferred)
  280.     {
  281.       TRY_CATCH (except, RETURN_MASK_ERROR)
  282.         {
  283.           val = read_var_value (sym, frame);
  284.         }
  285.       if (!val)
  286.         {
  287.           val_error = alloca (strlen (except.message) + 1);
  288.           strcpy (val_error, except.message);
  289.         }
  290.     }

  291.   if (SYMBOL_COMPUTED_OPS (sym) != NULL
  292.       && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
  293.       && print_entry_values != print_entry_values_no
  294.       && (print_entry_values != print_entry_values_if_needed
  295.           || !val || value_optimized_out (val)))
  296.     {
  297.       TRY_CATCH (except, RETURN_MASK_ERROR)
  298.         {
  299.           const struct symbol_computed_ops *ops;

  300.           ops = SYMBOL_COMPUTED_OPS (sym);
  301.           entryval = ops->read_variable_at_entry (sym, frame);
  302.         }
  303.       if (!entryval)
  304.         {
  305.           entryval_error = alloca (strlen (except.message) + 1);
  306.           strcpy (entryval_error, except.message);
  307.         }

  308.       if (except.error == NO_ENTRY_VALUE_ERROR
  309.           || (entryval && value_optimized_out (entryval)))
  310.         {
  311.           entryval = NULL;
  312.           entryval_error = NULL;
  313.         }

  314.       if (print_entry_values == print_entry_values_compact
  315.           || print_entry_values == print_entry_values_default)
  316.         {
  317.           /* For MI do not try to use print_entry_values_compact for ARGP.  */

  318.           if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
  319.             {
  320.               struct type *type = value_type (val);

  321.               if (value_lazy (val))
  322.                 value_fetch_lazy (val);
  323.               if (value_lazy (entryval))
  324.                 value_fetch_lazy (entryval);

  325.               if (value_contents_eq (val, 0, entryval, 0, TYPE_LENGTH (type)))
  326.                 {
  327.                   /* Initialize it just to avoid a GCC false warning.  */
  328.                   struct value *val_deref = NULL, *entryval_deref;

  329.                   /* DW_AT_GNU_call_site_value does match with the current
  330.                      value.  If it is a reference still try to verify if
  331.                      dereferenced DW_AT_GNU_call_site_data_value does not
  332.                      differ.  */

  333.                   TRY_CATCH (except, RETURN_MASK_ERROR)
  334.                     {
  335.                       struct type *type_deref;

  336.                       val_deref = coerce_ref (val);
  337.                       if (value_lazy (val_deref))
  338.                         value_fetch_lazy (val_deref);
  339.                       type_deref = value_type (val_deref);

  340.                       entryval_deref = coerce_ref (entryval);
  341.                       if (value_lazy (entryval_deref))
  342.                         value_fetch_lazy (entryval_deref);

  343.                       /* If the reference addresses match but dereferenced
  344.                          content does not match print them.  */
  345.                       if (val != val_deref
  346.                           && value_contents_eq (val_deref, 0,
  347.                                                 entryval_deref, 0,
  348.                                                 TYPE_LENGTH (type_deref)))
  349.                         val_equal = 1;
  350.                     }

  351.                   /* Value was not a reference; and its content matches.  */
  352.                   if (val == val_deref)
  353.                     val_equal = 1;
  354.                   /* If the dereferenced content could not be fetched do not
  355.                      display anything.  */
  356.                   else if (except.error == NO_ENTRY_VALUE_ERROR)
  357.                     val_equal = 1;
  358.                   else if (except.message)
  359.                     {
  360.                       entryval_error = alloca (strlen (except.message) + 1);
  361.                       strcpy (entryval_error, except.message);
  362.                     }

  363.                   if (val_equal)
  364.                     entryval = NULL;
  365.                 }
  366.             }

  367.           /* Try to remove possibly duplicate error message for ENTRYARGP even
  368.              in MI mode.  */

  369.           if (val_error && entryval_error
  370.               && strcmp (val_error, entryval_error) == 0)
  371.             {
  372.               entryval_error = NULL;

  373.               /* Do not se VAL_EQUAL as the same error message may be shown for
  374.                  the entry value even if no entry values are present in the
  375.                  inferior.  */
  376.             }
  377.         }
  378.     }

  379.   if (entryval == NULL)
  380.     {
  381.       if (print_entry_values == print_entry_values_preferred)
  382.         {
  383.           TRY_CATCH (except, RETURN_MASK_ERROR)
  384.             {
  385.               val = read_var_value (sym, frame);
  386.             }
  387.           if (!val)
  388.             {
  389.               val_error = alloca (strlen (except.message) + 1);
  390.               strcpy (val_error, except.message);
  391.             }
  392.         }
  393.       if (print_entry_values == print_entry_values_only
  394.           || print_entry_values == print_entry_values_both
  395.           || (print_entry_values == print_entry_values_preferred
  396.               && (!val || value_optimized_out (val))))
  397.         {
  398.           entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
  399.           entryval_error = NULL;
  400.         }
  401.     }
  402.   if ((print_entry_values == print_entry_values_compact
  403.        || print_entry_values == print_entry_values_if_needed
  404.        || print_entry_values == print_entry_values_preferred)
  405.       && (!val || value_optimized_out (val)) && entryval != NULL)
  406.     {
  407.       val = NULL;
  408.       val_error = NULL;
  409.     }

  410.   argp->sym = sym;
  411.   argp->val = val;
  412.   argp->error = val_error ? xstrdup (val_error) : NULL;
  413.   if (!val && !val_error)
  414.     argp->entry_kind = print_entry_values_only;
  415.   else if ((print_entry_values == print_entry_values_compact
  416.            || print_entry_values == print_entry_values_default) && val_equal)
  417.     {
  418.       argp->entry_kind = print_entry_values_compact;
  419.       gdb_assert (!ui_out_is_mi_like_p (current_uiout));
  420.     }
  421.   else
  422.     argp->entry_kind = print_entry_values_no;

  423.   entryargp->sym = sym;
  424.   entryargp->val = entryval;
  425.   entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
  426.   if (!entryval && !entryval_error)
  427.     entryargp->entry_kind = print_entry_values_no;
  428.   else
  429.     entryargp->entry_kind = print_entry_values_only;
  430. }

  431. /* Print the arguments of frame FRAME on STREAM, given the function
  432.    FUNC running in that frame (as a symbol), where NUM is the number
  433.    of arguments according to the stack frame (or -1 if the number of
  434.    arguments is unknown).  */

  435. /* Note that currently the "number of arguments according to the
  436.    stack frame" is only known on VAX where i refers to the "number of
  437.    ints of arguments according to the stack frame".  */

  438. static void
  439. print_frame_args (struct symbol *func, struct frame_info *frame,
  440.                   int num, struct ui_file *stream)
  441. {
  442.   struct ui_out *uiout = current_uiout;
  443.   int first = 1;
  444.   /* Offset of next stack argument beyond the one we have seen that is
  445.      at the highest offset, or -1 if we haven't come to a stack
  446.      argument yet.  */
  447.   long highest_offset = -1;
  448.   /* Number of ints of arguments that we have printed so far.  */
  449.   int args_printed = 0;
  450.   struct cleanup *old_chain;
  451.   struct ui_file *stb;
  452.   /* True if we should print arguments, false otherwise.  */
  453.   int print_args = strcmp (print_frame_arguments, "none");

  454.   stb = mem_fileopen ();
  455.   old_chain = make_cleanup_ui_file_delete (stb);

  456.   if (func)
  457.     {
  458.       const struct block *b = SYMBOL_BLOCK_VALUE (func);
  459.       struct block_iterator iter;
  460.       struct symbol *sym;

  461.       ALL_BLOCK_SYMBOLS (b, iter, sym)
  462.         {
  463.           struct frame_arg arg, entryarg;

  464.           QUIT;

  465.           /* Keep track of the highest stack argument offset seen, and
  466.              skip over any kinds of symbols we don't care about.  */

  467.           if (!SYMBOL_IS_ARGUMENT (sym))
  468.             continue;

  469.           switch (SYMBOL_CLASS (sym))
  470.             {
  471.             case LOC_ARG:
  472.             case LOC_REF_ARG:
  473.               {
  474.                 long current_offset = SYMBOL_VALUE (sym);
  475.                 int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));

  476.                 /* Compute address of next argument by adding the size of
  477.                    this argument and rounding to an int boundary.  */
  478.                 current_offset =
  479.                   ((current_offset + arg_size + sizeof (int) - 1)
  480.                    & ~(sizeof (int) - 1));

  481.                 /* If this is the highest offset seen yet, set
  482.                    highest_offset.  */
  483.                 if (highest_offset == -1
  484.                     || (current_offset > highest_offset))
  485.                   highest_offset = current_offset;

  486.                 /* Add the number of ints we're about to print to
  487.                    args_printed.  */
  488.                 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
  489.               }

  490.               /* We care about types of symbols, but don't need to
  491.                  keep track of stack offsets in them.  */
  492.             case LOC_REGISTER:
  493.             case LOC_REGPARM_ADDR:
  494.             case LOC_COMPUTED:
  495.             case LOC_OPTIMIZED_OUT:
  496.             default:
  497.               break;
  498.             }

  499.           /* We have to look up the symbol because arguments can have
  500.              two entries (one a parameter, one a local) and the one we
  501.              want is the local, which lookup_symbol will find for us.
  502.              This includes gcc1 (not gcc2) on SPARC when passing a
  503.              small structure and gcc2 when the argument type is float
  504.              and it is passed as a double and converted to float by
  505.              the prologue (in the latter case the type of the LOC_ARG
  506.              symbol is double and the type of the LOC_LOCAL symbol is
  507.              float).  */
  508.           /* But if the parameter name is null, don't try it.  Null
  509.              parameter names occur on the RS/6000, for traceback
  510.              tables.  FIXME, should we even print them?  */

  511.           if (*SYMBOL_LINKAGE_NAME (sym))
  512.             {
  513.               struct symbol *nsym;

  514.               nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
  515.                                     b, VAR_DOMAIN, NULL);
  516.               gdb_assert (nsym != NULL);
  517.               if (SYMBOL_CLASS (nsym) == LOC_REGISTER
  518.                   && !SYMBOL_IS_ARGUMENT (nsym))
  519.                 {
  520.                   /* There is a LOC_ARG/LOC_REGISTER pair.  This means
  521.                      that it was passed on the stack and loaded into a
  522.                      register, or passed in a register and stored in a
  523.                      stack slot.  GDB 3.x used the LOC_ARG; GDB
  524.                      4.0-4.11 used the LOC_REGISTER.

  525.                      Reasons for using the LOC_ARG:

  526.                      (1) Because find_saved_registers may be slow for
  527.                          remote debugging.

  528.                      (2) Because registers are often re-used and stack
  529.                          slots rarely (never?) are.  Therefore using
  530.                          the stack slot is much less likely to print
  531.                          garbage.

  532.                      Reasons why we might want to use the LOC_REGISTER:

  533.                      (1) So that the backtrace prints the same value
  534.                          as "print foo".  I see no compelling reason
  535.                          why this needs to be the case; having the
  536.                          backtrace print the value which was passed
  537.                          in, and "print foo" print the value as
  538.                          modified within the called function, makes
  539.                          perfect sense to me.

  540.                      Additional note: It might be nice if "info args"
  541.                      displayed both values.

  542.                      One more note: There is a case with SPARC
  543.                      structure passing where we need to use the
  544.                      LOC_REGISTER, but this is dealt with by creating
  545.                      a single LOC_REGPARM in symbol reading.  */

  546.                   /* Leave sym (the LOC_ARG) alone.  */
  547.                   ;
  548.                 }
  549.               else
  550.                 sym = nsym;
  551.             }

  552.           /* Print the current arg.  */
  553.           if (!first)
  554.             ui_out_text (uiout, ", ");
  555.           ui_out_wrap_hint (uiout, "    ");

  556.           if (!print_args)
  557.             {
  558.               memset (&arg, 0, sizeof (arg));
  559.               arg.sym = sym;
  560.               arg.entry_kind = print_entry_values_no;
  561.               memset (&entryarg, 0, sizeof (entryarg));
  562.               entryarg.sym = sym;
  563.               entryarg.entry_kind = print_entry_values_no;
  564.             }
  565.           else
  566.             read_frame_arg (sym, frame, &arg, &entryarg);

  567.           if (arg.entry_kind != print_entry_values_only)
  568.             print_frame_arg (&arg);

  569.           if (entryarg.entry_kind != print_entry_values_no)
  570.             {
  571.               if (arg.entry_kind != print_entry_values_only)
  572.                 {
  573.                   ui_out_text (uiout, ", ");
  574.                   ui_out_wrap_hint (uiout, "    ");
  575.                 }

  576.               print_frame_arg (&entryarg);
  577.             }

  578.           xfree (arg.error);
  579.           xfree (entryarg.error);

  580.           first = 0;
  581.         }
  582.     }

  583.   /* Don't print nameless args in situations where we don't know
  584.      enough about the stack to find them.  */
  585.   if (num != -1)
  586.     {
  587.       long start;

  588.       if (highest_offset == -1)
  589.         start = gdbarch_frame_args_skip (get_frame_arch (frame));
  590.       else
  591.         start = highest_offset;

  592.       print_frame_nameless_args (frame, start, num - args_printed,
  593.                                  first, stream);
  594.     }

  595.   do_cleanups (old_chain);
  596. }

  597. /* Set the current source and line to the location given by frame
  598.    FRAME, if possible.  When CENTER is true, adjust so the relevant
  599.    line is in the center of the next 'list'.  */

  600. void
  601. set_current_sal_from_frame (struct frame_info *frame)
  602. {
  603.   struct symtab_and_line sal;

  604.   find_frame_sal (frame, &sal);
  605.   if (sal.symtab != NULL)
  606.     set_current_source_symtab_and_line (&sal);
  607. }

  608. /* If ON, GDB will display disassembly of the next source line when
  609.    execution of the program being debugged stops.
  610.    If AUTO (which is the default), or there's no line info to determine
  611.    the source line of the next instruction, display disassembly of next
  612.    instruction instead.  */

  613. static enum auto_boolean disassemble_next_line;

  614. static void
  615. show_disassemble_next_line (struct ui_file *file, int from_tty,
  616.                                  struct cmd_list_element *c,
  617.                                  const char *value)
  618. {
  619.   fprintf_filtered (file,
  620.                     _("Debugger's willingness to use "
  621.                       "disassemble-next-line is %s.\n"),
  622.                     value);
  623. }

  624. /* Use TRY_CATCH to catch the exception from the gdb_disassembly
  625.    because it will be broken by filter sometime.  */

  626. static void
  627. do_gdb_disassembly (struct gdbarch *gdbarch,
  628.                     int how_many, CORE_ADDR low, CORE_ADDR high)
  629. {
  630.   volatile struct gdb_exception exception;

  631.   TRY_CATCH (exception, RETURN_MASK_ERROR)
  632.     {
  633.       gdb_disassembly (gdbarch, current_uiout, 0,
  634.                        DISASSEMBLY_RAW_INSN, how_many,
  635.                        low, high);
  636.     }
  637.   if (exception.reason < 0)
  638.     {
  639.       /* If an exception was thrown while doing the disassembly, print
  640.          the error message, to give the user a clue of what happened.  */
  641.       exception_print (gdb_stderr, exception);
  642.     }
  643. }

  644. /* Print information about frame FRAME.  The output is format according
  645.    to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS.  The meaning of
  646.    PRINT_WHAT is:

  647.    SRC_LINE: Print only source line.
  648.    LOCATION: Print only location.
  649.    LOC_AND_SRC: Print location and source line.

  650.    Used in "where" output, and to emit breakpoint or step
  651.    messages.  */

  652. void
  653. print_frame_info (struct frame_info *frame, int print_level,
  654.                   enum print_what print_what, int print_args,
  655.                   int set_current_sal)
  656. {
  657.   struct gdbarch *gdbarch = get_frame_arch (frame);
  658.   struct symtab_and_line sal;
  659.   int source_print;
  660.   int location_print;
  661.   struct ui_out *uiout = current_uiout;

  662.   if (get_frame_type (frame) == DUMMY_FRAME
  663.       || get_frame_type (frame) == SIGTRAMP_FRAME
  664.       || get_frame_type (frame) == ARCH_FRAME)
  665.     {
  666.       struct cleanup *uiout_cleanup
  667.         = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");

  668.       annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
  669.                             gdbarch, get_frame_pc (frame));

  670.       /* Do this regardless of SOURCE because we don't have any source
  671.          to list for this frame.  */
  672.       if (print_level)
  673.         {
  674.           ui_out_text (uiout, "#");
  675.           ui_out_field_fmt_int (uiout, 2, ui_left, "level",
  676.                                 frame_relative_level (frame));
  677.         }
  678.       if (ui_out_is_mi_like_p (uiout))
  679.         {
  680.           annotate_frame_address ();
  681.           ui_out_field_core_addr (uiout, "addr",
  682.                                   gdbarch, get_frame_pc (frame));
  683.           annotate_frame_address_end ();
  684.         }

  685.       if (get_frame_type (frame) == DUMMY_FRAME)
  686.         {
  687.           annotate_function_call ();
  688.           ui_out_field_string (uiout, "func", "<function called from gdb>");
  689.         }
  690.       else if (get_frame_type (frame) == SIGTRAMP_FRAME)
  691.         {
  692.           annotate_signal_handler_caller ();
  693.           ui_out_field_string (uiout, "func", "<signal handler called>");
  694.         }
  695.       else if (get_frame_type (frame) == ARCH_FRAME)
  696.         {
  697.           ui_out_field_string (uiout, "func", "<cross-architecture call>");
  698.         }
  699.       ui_out_text (uiout, "\n");
  700.       annotate_frame_end ();

  701.       /* If disassemble-next-line is set to auto or on output the next
  702.          instruction.  */
  703.       if (disassemble_next_line == AUTO_BOOLEAN_AUTO
  704.           || disassemble_next_line == AUTO_BOOLEAN_TRUE)
  705.         do_gdb_disassembly (get_frame_arch (frame), 1,
  706.                             get_frame_pc (frame), get_frame_pc (frame) + 1);

  707.       do_cleanups (uiout_cleanup);
  708.       return;
  709.     }

  710.   /* If FRAME is not the innermost frame, that normally means that
  711.      FRAME->pc points to *after* the call instruction, and we want to
  712.      get the line containing the call, never the next line.  But if
  713.      the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
  714.      next frame was not entered as the result of a call, and we want
  715.      to get the line containing FRAME->pc.  */
  716.   find_frame_sal (frame, &sal);

  717.   location_print = (print_what == LOCATION
  718.                     || print_what == LOC_AND_ADDRESS
  719.                     || print_what == SRC_AND_LOC);

  720.   if (location_print || !sal.symtab)
  721.     print_frame (frame, print_level, print_what, print_args, sal);

  722.   source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);

  723.   /* If disassemble-next-line is set to auto or on and doesn't have
  724.      the line debug messages for $pc, output the next instruction.  */
  725.   if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
  726.        || disassemble_next_line == AUTO_BOOLEAN_TRUE)
  727.       && source_print && !sal.symtab)
  728.     do_gdb_disassembly (get_frame_arch (frame), 1,
  729.                         get_frame_pc (frame), get_frame_pc (frame) + 1);

  730.   if (source_print && sal.symtab)
  731.     {
  732.       int done = 0;
  733.       int mid_statement = ((print_what == SRC_LINE)
  734.                            && frame_show_address (frame, sal));

  735.       if (annotation_level)
  736.         done = identify_source_line (sal.symtab, sal.line, mid_statement,
  737.                                      get_frame_pc (frame));
  738.       if (!done)
  739.         {
  740.           if (deprecated_print_frame_info_listing_hook)
  741.             deprecated_print_frame_info_listing_hook (sal.symtab,
  742.                                                       sal.line,
  743.                                                       sal.line + 1, 0);
  744.           else
  745.             {
  746.               struct value_print_options opts;

  747.               get_user_print_options (&opts);
  748.               /* We used to do this earlier, but that is clearly
  749.                  wrong.  This function is used by many different
  750.                  parts of gdb, including normal_stop in infrun.c,
  751.                  which uses this to print out the current PC
  752.                  when we stepi/nexti into the middle of a source
  753.                  line.  Only the command line really wants this
  754.                  behavior.  Other UIs probably would like the
  755.                  ability to decide for themselves if it is desired.  */
  756.               if (opts.addressprint && mid_statement)
  757.                 {
  758.                   ui_out_field_core_addr (uiout, "addr",
  759.                                           gdbarch, get_frame_pc (frame));
  760.                   ui_out_text (uiout, "\t");
  761.                 }

  762.               print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
  763.             }
  764.         }

  765.       /* If disassemble-next-line is set to on and there is line debug
  766.          messages, output assembly codes for next line.  */
  767.       if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
  768.         do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
  769.     }

  770.   if (set_current_sal)
  771.     {
  772.       CORE_ADDR pc;

  773.       if (get_frame_pc_if_available (frame, &pc))
  774.         set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
  775.       else
  776.         set_last_displayed_sal (0, 0, 0, 0, 0);
  777.     }

  778.   annotate_frame_end ();

  779.   gdb_flush (gdb_stdout);
  780. }

  781. /* Remember the last symtab and line we displayed, which we use e.g.
  782. * as the place to put a breakpoint when the `break' command is
  783. * invoked with no arguments.  */

  784. static void
  785. set_last_displayed_sal (int valid, struct program_space *pspace,
  786.                         CORE_ADDR addr, struct symtab *symtab,
  787.                         int line)
  788. {
  789.   last_displayed_sal_valid = valid;
  790.   last_displayed_pspace = pspace;
  791.   last_displayed_addr = addr;
  792.   last_displayed_symtab = symtab;
  793.   last_displayed_line = line;
  794.   if (valid && pspace == NULL)
  795.     {
  796.       clear_last_displayed_sal ();
  797.       internal_error (__FILE__, __LINE__,
  798.                       _("Trying to set NULL pspace."));
  799.     }
  800. }

  801. /* Forget the last sal we displayed.  */

  802. void
  803. clear_last_displayed_sal (void)
  804. {
  805.   last_displayed_sal_valid = 0;
  806.   last_displayed_pspace = 0;
  807.   last_displayed_addr = 0;
  808.   last_displayed_symtab = 0;
  809.   last_displayed_line = 0;
  810. }

  811. /* Is our record of the last sal we displayed valid?  If not,
  812. * the get_last_displayed_* functions will return NULL or 0, as
  813. * appropriate.  */

  814. int
  815. last_displayed_sal_is_valid (void)
  816. {
  817.   return last_displayed_sal_valid;
  818. }

  819. /* Get the pspace of the last sal we displayed, if it's valid.  */

  820. struct program_space *
  821. get_last_displayed_pspace (void)
  822. {
  823.   if (last_displayed_sal_valid)
  824.     return last_displayed_pspace;
  825.   return 0;
  826. }

  827. /* Get the address of the last sal we displayed, if it's valid.  */

  828. CORE_ADDR
  829. get_last_displayed_addr (void)
  830. {
  831.   if (last_displayed_sal_valid)
  832.     return last_displayed_addr;
  833.   return 0;
  834. }

  835. /* Get the symtab of the last sal we displayed, if it's valid.  */

  836. struct symtab*
  837. get_last_displayed_symtab (void)
  838. {
  839.   if (last_displayed_sal_valid)
  840.     return last_displayed_symtab;
  841.   return 0;
  842. }

  843. /* Get the line of the last sal we displayed, if it's valid.  */

  844. int
  845. get_last_displayed_line (void)
  846. {
  847.   if (last_displayed_sal_valid)
  848.     return last_displayed_line;
  849.   return 0;
  850. }

  851. /* Get the last sal we displayed, if it's valid.  */

  852. void
  853. get_last_displayed_sal (struct symtab_and_line *sal)
  854. {
  855.   if (last_displayed_sal_valid)
  856.     {
  857.       sal->pspace = last_displayed_pspace;
  858.       sal->pc = last_displayed_addr;
  859.       sal->symtab = last_displayed_symtab;
  860.       sal->line = last_displayed_line;
  861.     }
  862.   else
  863.     {
  864.       sal->pspace = 0;
  865.       sal->pc = 0;
  866.       sal->symtab = 0;
  867.       sal->line = 0;
  868.     }
  869. }


  870. /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
  871.    corresponding to FRAME.  FUNNAME needs to be freed by the caller.  */

  872. void
  873. find_frame_funname (struct frame_info *frame, char **funname,
  874.                     enum language *funlang, struct symbol **funcp)
  875. {
  876.   struct symbol *func;

  877.   *funname = NULL;
  878.   *funlang = language_unknown;
  879.   if (funcp)
  880.     *funcp = NULL;

  881.   func = get_frame_function (frame);
  882.   if (func)
  883.     {
  884.       /* In certain pathological cases, the symtabs give the wrong
  885.          function (when we are in the first function in a file which
  886.          is compiled without debugging symbols, the previous function
  887.          is compiled with debugging symbols, and the "foo.o" symbol
  888.          that is supposed to tell us where the file with debugging
  889.          symbols ends has been truncated by ar because it is longer
  890.          than 15 characters).  This also occurs if the user uses asm()
  891.          to create a function but not stabs for it (in a file compiled
  892.          with -g).

  893.          So look in the minimal symbol tables as well, and if it comes
  894.          up with a larger address for the function use that instead.
  895.          I don't think this can ever cause any problems; there
  896.          shouldn't be any minimal symbols in the middle of a function;
  897.          if this is ever changed many parts of GDB will need to be
  898.          changed (and we'll create a find_pc_minimal_function or some
  899.          such).  */

  900.       struct bound_minimal_symbol msymbol;

  901.       /* Don't attempt to do this for inlined functions, which do not
  902.          have a corresponding minimal symbol.  */
  903.       if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
  904.         msymbol
  905.           = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
  906.       else
  907.         memset (&msymbol, 0, sizeof (msymbol));

  908.       if (msymbol.minsym != NULL
  909.           && (BMSYMBOL_VALUE_ADDRESS (msymbol)
  910.               > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
  911.         {
  912.           /* We also don't know anything about the function besides
  913.              its address and name.  */
  914.           func = 0;
  915.           *funname = xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym));
  916.           *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
  917.         }
  918.       else
  919.         {
  920.           *funname = xstrdup (SYMBOL_PRINT_NAME (func));
  921.           *funlang = SYMBOL_LANGUAGE (func);
  922.           if (funcp)
  923.             *funcp = func;
  924.           if (*funlang == language_cplus)
  925.             {
  926.               /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
  927.                  to display the demangled name that we already have
  928.                  stored in the symbol table, but we stored a version
  929.                  with DMGL_PARAMS turned on, and here we don't want to
  930.                  display parameters.  So remove the parameters.  */
  931.               char *func_only = cp_remove_params (*funname);

  932.               if (func_only)
  933.                 {
  934.                   xfree (*funname);
  935.                   *funname = func_only;
  936.                 }
  937.             }
  938.         }
  939.     }
  940.   else
  941.     {
  942.       struct bound_minimal_symbol msymbol;
  943.       CORE_ADDR pc;

  944.       if (!get_frame_address_in_block_if_available (frame, &pc))
  945.         return;

  946.       msymbol = lookup_minimal_symbol_by_pc (pc);
  947.       if (msymbol.minsym != NULL)
  948.         {
  949.           *funname = xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym));
  950.           *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
  951.         }
  952.     }
  953. }

  954. static void
  955. print_frame (struct frame_info *frame, int print_level,
  956.              enum print_what print_what, int print_args,
  957.              struct symtab_and_line sal)
  958. {
  959.   struct gdbarch *gdbarch = get_frame_arch (frame);
  960.   struct ui_out *uiout = current_uiout;
  961.   char *funname = NULL;
  962.   enum language funlang = language_unknown;
  963.   struct ui_file *stb;
  964.   struct cleanup *old_chain, *list_chain;
  965.   struct value_print_options opts;
  966.   struct symbol *func;
  967.   CORE_ADDR pc = 0;
  968.   int pc_p;

  969.   pc_p = get_frame_pc_if_available (frame, &pc);

  970.   stb = mem_fileopen ();
  971.   old_chain = make_cleanup_ui_file_delete (stb);

  972.   find_frame_funname (frame, &funname, &funlang, &func);
  973.   make_cleanup (xfree, funname);

  974.   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
  975.                         gdbarch, pc);

  976.   list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");

  977.   if (print_level)
  978.     {
  979.       ui_out_text (uiout, "#");
  980.       ui_out_field_fmt_int (uiout, 2, ui_left, "level",
  981.                             frame_relative_level (frame));
  982.     }
  983.   get_user_print_options (&opts);
  984.   if (opts.addressprint)
  985.     if (!sal.symtab
  986.         || frame_show_address (frame, sal)
  987.         || print_what == LOC_AND_ADDRESS)
  988.       {
  989.         annotate_frame_address ();
  990.         if (pc_p)
  991.           ui_out_field_core_addr (uiout, "addr", gdbarch, pc);
  992.         else
  993.           ui_out_field_string (uiout, "addr", "<unavailable>");
  994.         annotate_frame_address_end ();
  995.         ui_out_text (uiout, " in ");
  996.       }
  997.   annotate_frame_function_name ();
  998.   fprintf_symbol_filtered (stb, funname ? funname : "??",
  999.                            funlang, DMGL_ANSI);
  1000.   ui_out_field_stream (uiout, "func", stb);
  1001.   ui_out_wrap_hint (uiout, "   ");
  1002.   annotate_frame_args ();

  1003.   ui_out_text (uiout, " (");
  1004.   if (print_args)
  1005.     {
  1006.       struct gdbarch *gdbarch = get_frame_arch (frame);
  1007.       int numargs;
  1008.       struct cleanup *args_list_chain;
  1009.       volatile struct gdb_exception e;

  1010.       if (gdbarch_frame_num_args_p (gdbarch))
  1011.         {
  1012.           numargs = gdbarch_frame_num_args (gdbarch, frame);
  1013.           gdb_assert (numargs >= 0);
  1014.         }
  1015.       else
  1016.         numargs = -1;

  1017.       args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
  1018.       TRY_CATCH (e, RETURN_MASK_ERROR)
  1019.         {
  1020.           print_frame_args (func, frame, numargs, gdb_stdout);
  1021.         }
  1022.       /* FIXME: ARGS must be a list.  If one argument is a string it
  1023.           will have " that will not be properly escaped.  */
  1024.       /* Invoke ui_out_tuple_end.  */
  1025.       do_cleanups (args_list_chain);
  1026.       QUIT;
  1027.     }
  1028.   ui_out_text (uiout, ")");
  1029.   if (sal.symtab)
  1030.     {
  1031.       const char *filename_display;

  1032.       filename_display = symtab_to_filename_for_display (sal.symtab);
  1033.       annotate_frame_source_begin ();
  1034.       ui_out_wrap_hint (uiout, "   ");
  1035.       ui_out_text (uiout, " at ");
  1036.       annotate_frame_source_file ();
  1037.       ui_out_field_string (uiout, "file", filename_display);
  1038.       if (ui_out_is_mi_like_p (uiout))
  1039.         {
  1040.           const char *fullname = symtab_to_fullname (sal.symtab);

  1041.           ui_out_field_string (uiout, "fullname", fullname);
  1042.         }
  1043.       annotate_frame_source_file_end ();
  1044.       ui_out_text (uiout, ":");
  1045.       annotate_frame_source_line ();
  1046.       ui_out_field_int (uiout, "line", sal.line);
  1047.       annotate_frame_source_end ();
  1048.     }

  1049.   if (pc_p && (funname == NULL || sal.symtab == NULL))
  1050.     {
  1051.       char *lib = solib_name_from_address (get_frame_program_space (frame),
  1052.                                            get_frame_pc (frame));

  1053.       if (lib)
  1054.         {
  1055.           annotate_frame_where ();
  1056.           ui_out_wrap_hint (uiout, "  ");
  1057.           ui_out_text (uiout, " from ");
  1058.           ui_out_field_string (uiout, "from", lib);
  1059.         }
  1060.     }

  1061.   /* do_cleanups will call ui_out_tuple_end() for us.  */
  1062.   do_cleanups (list_chain);
  1063.   ui_out_text (uiout, "\n");
  1064.   do_cleanups (old_chain);
  1065. }


  1066. /* Read a frame specification in whatever the appropriate format is
  1067.    from FRAME_EXP.  Call error(), printing MESSAGE, if the
  1068.    specification is in any way invalid (so this function never returns
  1069.    NULL).  When SEPECTED_P is non-NULL set its target to indicate that
  1070.    the default selected frame was used.  */

  1071. static struct frame_info *
  1072. parse_frame_specification_1 (const char *frame_exp, const char *message,
  1073.                              int *selected_frame_p)
  1074. {
  1075.   int numargs;
  1076.   struct value *args[4];
  1077.   CORE_ADDR addrs[ARRAY_SIZE (args)];

  1078.   if (frame_exp == NULL)
  1079.     numargs = 0;
  1080.   else
  1081.     {
  1082.       numargs = 0;
  1083.       while (1)
  1084.         {
  1085.           char *addr_string;
  1086.           struct cleanup *cleanup;
  1087.           const char *p;

  1088.           /* Skip leading white space, bail of EOL.  */
  1089.           frame_exp = skip_spaces_const (frame_exp);
  1090.           if (!*frame_exp)
  1091.             break;

  1092.           /* Parse the argument, extract it, save it.  */
  1093.           for (p = frame_exp;
  1094.                *p && !isspace (*p);
  1095.                p++);
  1096.           addr_string = savestring (frame_exp, p - frame_exp);
  1097.           frame_exp = p;
  1098.           cleanup = make_cleanup (xfree, addr_string);

  1099.           /* NOTE: Parse and evaluate expression, but do not use
  1100.              functions such as parse_and_eval_long or
  1101.              parse_and_eval_address to also extract the value.
  1102.              Instead value_as_long and value_as_address are used.
  1103.              This avoids problems with expressions that contain
  1104.              side-effects.  */
  1105.           if (numargs >= ARRAY_SIZE (args))
  1106.             error (_("Too many args in frame specification"));
  1107.           args[numargs++] = parse_and_eval (addr_string);

  1108.           do_cleanups (cleanup);
  1109.         }
  1110.     }

  1111.   /* If no args, default to the selected frame.  */
  1112.   if (numargs == 0)
  1113.     {
  1114.       if (selected_frame_p != NULL)
  1115.         (*selected_frame_p) = 1;
  1116.       return get_selected_frame (message);
  1117.     }

  1118.   /* None of the remaining use the selected frame.  */
  1119.   if (selected_frame_p != NULL)
  1120.     (*selected_frame_p) = 0;

  1121.   /* Assume the single arg[0] is an integer, and try using that to
  1122.      select a frame relative to current.  */
  1123.   if (numargs == 1)
  1124.     {
  1125.       struct frame_info *fid;
  1126.       int level = value_as_long (args[0]);

  1127.       fid = find_relative_frame (get_current_frame (), &level);
  1128.       if (level == 0)
  1129.         /* find_relative_frame was successful.  */
  1130.         return fid;
  1131.     }

  1132.   /* Convert each value into a corresponding address.  */
  1133.   {
  1134.     int i;

  1135.     for (i = 0; i < numargs; i++)
  1136.       addrs[i] = value_as_address (args[i]);
  1137.   }

  1138.   /* Assume that the single arg[0] is an address, use that to identify
  1139.      a frame with a matching ID.  Should this also accept stack/pc or
  1140.      stack/pc/special.  */
  1141.   if (numargs == 1)
  1142.     {
  1143.       struct frame_id id = frame_id_build_wild (addrs[0]);
  1144.       struct frame_info *fid;

  1145.       /* If (s)he specifies the frame with an address, he deserves
  1146.          what (s)he gets.  Still, give the highest one that matches.
  1147.          (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
  1148.          know).  */
  1149.       for (fid = get_current_frame ();
  1150.            fid != NULL;
  1151.            fid = get_prev_frame (fid))
  1152.         {
  1153.           if (frame_id_eq (id, get_frame_id (fid)))
  1154.             {
  1155.               struct frame_info *prev_frame;

  1156.               while (1)
  1157.                 {
  1158.                   prev_frame = get_prev_frame (fid);
  1159.                   if (!prev_frame
  1160.                       || !frame_id_eq (id, get_frame_id (prev_frame)))
  1161.                     break;
  1162.                   fid = prev_frame;
  1163.                 }
  1164.               return fid;
  1165.             }
  1166.         }
  1167.       }

  1168.   /* We couldn't identify the frame as an existing frame, but
  1169.      perhaps we can create one with a single argument.  */
  1170.   if (numargs == 1)
  1171.     return create_new_frame (addrs[0], 0);
  1172.   else if (numargs == 2)
  1173.     return create_new_frame (addrs[0], addrs[1]);
  1174.   else
  1175.     error (_("Too many args in frame specification"));
  1176. }

  1177. static struct frame_info *
  1178. parse_frame_specification (char *frame_exp)
  1179. {
  1180.   return parse_frame_specification_1 (frame_exp, NULL, NULL);
  1181. }

  1182. /* Print verbosely the selected frame or the frame at address
  1183.    ADDR_EXP.  Absolutely all information in the frame is printed.  */

  1184. static void
  1185. frame_info (char *addr_exp, int from_tty)
  1186. {
  1187.   struct frame_info *fi;
  1188.   struct symtab_and_line sal;
  1189.   struct symbol *func;
  1190.   struct symtab *s;
  1191.   struct frame_info *calling_frame_info;
  1192.   int numregs;
  1193.   const char *funname = 0;
  1194.   enum language funlang = language_unknown;
  1195.   const char *pc_regname;
  1196.   int selected_frame_p;
  1197.   struct gdbarch *gdbarch;
  1198.   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
  1199.   CORE_ADDR frame_pc;
  1200.   int frame_pc_p;
  1201.   /* Initialize it to avoid "may be used uninitialized" warning.  */
  1202.   CORE_ADDR caller_pc = 0;
  1203.   volatile struct gdb_exception ex;

  1204.   fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
  1205.   gdbarch = get_frame_arch (fi);

  1206.   /* Name of the value returned by get_frame_pc().  Per comments, "pc"
  1207.      is not a good name.  */
  1208.   if (gdbarch_pc_regnum (gdbarch) >= 0)
  1209.     /* OK, this is weird.  The gdbarch_pc_regnum hardware register's value can
  1210.        easily not match that of the internal value returned by
  1211.        get_frame_pc().  */
  1212.     pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
  1213.   else
  1214.     /* But then, this is weird to.  Even without gdbarch_pc_regnum, an
  1215.        architectures will often have a hardware register called "pc",
  1216.        and that register's value, again, can easily not match
  1217.        get_frame_pc().  */
  1218.     pc_regname = "pc";

  1219.   frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
  1220.   find_frame_sal (fi, &sal);
  1221.   func = get_frame_function (fi);
  1222.   s = sal.symtab;
  1223.   if (func)
  1224.     {
  1225.       funname = SYMBOL_PRINT_NAME (func);
  1226.       funlang = SYMBOL_LANGUAGE (func);
  1227.       if (funlang == language_cplus)
  1228.         {
  1229.           /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
  1230.              to display the demangled name that we already have
  1231.              stored in the symbol table, but we stored a version
  1232.              with DMGL_PARAMS turned on, and here we don't want to
  1233.              display parameters.  So remove the parameters.  */
  1234.           char *func_only = cp_remove_params (funname);

  1235.           if (func_only)
  1236.             {
  1237.               funname = func_only;
  1238.               make_cleanup (xfree, func_only);
  1239.             }
  1240.         }
  1241.     }
  1242.   else if (frame_pc_p)
  1243.     {
  1244.       struct bound_minimal_symbol msymbol;

  1245.       msymbol = lookup_minimal_symbol_by_pc (frame_pc);
  1246.       if (msymbol.minsym != NULL)
  1247.         {
  1248.           funname = MSYMBOL_PRINT_NAME (msymbol.minsym);
  1249.           funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
  1250.         }
  1251.     }
  1252.   calling_frame_info = get_prev_frame (fi);

  1253.   if (selected_frame_p && frame_relative_level (fi) >= 0)
  1254.     {
  1255.       printf_filtered (_("Stack level %d, frame at "),
  1256.                        frame_relative_level (fi));
  1257.     }
  1258.   else
  1259.     {
  1260.       printf_filtered (_("Stack frame at "));
  1261.     }
  1262.   fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
  1263.   printf_filtered (":\n");
  1264.   printf_filtered (" %s = ", pc_regname);
  1265.   if (frame_pc_p)
  1266.     fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
  1267.   else
  1268.     fputs_filtered ("<unavailable>", gdb_stdout);

  1269.   wrap_here ("   ");
  1270.   if (funname)
  1271.     {
  1272.       printf_filtered (" in ");
  1273.       fprintf_symbol_filtered (gdb_stdout, funname, funlang,
  1274.                                DMGL_ANSI | DMGL_PARAMS);
  1275.     }
  1276.   wrap_here ("   ");
  1277.   if (sal.symtab)
  1278.     printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal.symtab),
  1279.                      sal.line);
  1280.   puts_filtered ("; ");
  1281.   wrap_here ("    ");
  1282.   printf_filtered ("saved %s = ", pc_regname);

  1283.   TRY_CATCH (ex, RETURN_MASK_ERROR)
  1284.     {
  1285.       caller_pc = frame_unwind_caller_pc (fi);
  1286.     }
  1287.   if (ex.reason < 0)
  1288.     {
  1289.       switch (ex.error)
  1290.         {
  1291.         case NOT_AVAILABLE_ERROR:
  1292.           val_print_unavailable (gdb_stdout);
  1293.           break;
  1294.         case OPTIMIZED_OUT_ERROR:
  1295.           val_print_not_saved (gdb_stdout);
  1296.           break;
  1297.         default:
  1298.           fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
  1299.           break;
  1300.         }
  1301.     }
  1302.   else
  1303.     fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
  1304.   printf_filtered ("\n");

  1305.   if (calling_frame_info == NULL)
  1306.     {
  1307.       enum unwind_stop_reason reason;

  1308.       reason = get_frame_unwind_stop_reason (fi);
  1309.       if (reason != UNWIND_NO_REASON)
  1310.         printf_filtered (_(" Outermost frame: %s\n"),
  1311.                          frame_stop_reason_string (fi));
  1312.     }
  1313.   else if (get_frame_type (fi) == TAILCALL_FRAME)
  1314.     puts_filtered (" tail call frame");
  1315.   else if (get_frame_type (fi) == INLINE_FRAME)
  1316.     printf_filtered (" inlined into frame %d",
  1317.                      frame_relative_level (get_prev_frame (fi)));
  1318.   else
  1319.     {
  1320.       printf_filtered (" called by frame at ");
  1321.       fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
  1322.                       gdb_stdout);
  1323.     }
  1324.   if (get_next_frame (fi) && calling_frame_info)
  1325.     puts_filtered (",");
  1326.   wrap_here ("   ");
  1327.   if (get_next_frame (fi))
  1328.     {
  1329.       printf_filtered (" caller of frame at ");
  1330.       fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
  1331.                       gdb_stdout);
  1332.     }
  1333.   if (get_next_frame (fi) || calling_frame_info)
  1334.     puts_filtered ("\n");

  1335.   if (s)
  1336.     printf_filtered (" source language %s.\n",
  1337.                      language_str (s->language));

  1338.   {
  1339.     /* Address of the argument list for this frame, or 0.  */
  1340.     CORE_ADDR arg_list = get_frame_args_address (fi);
  1341.     /* Number of args for this frame, or -1 if unknown.  */
  1342.     int numargs;

  1343.     if (arg_list == 0)
  1344.       printf_filtered (" Arglist at unknown address.\n");
  1345.     else
  1346.       {
  1347.         printf_filtered (" Arglist at ");
  1348.         fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
  1349.         printf_filtered (",");

  1350.         if (!gdbarch_frame_num_args_p (gdbarch))
  1351.           {
  1352.             numargs = -1;
  1353.             puts_filtered (" args: ");
  1354.           }
  1355.         else
  1356.           {
  1357.             numargs = gdbarch_frame_num_args (gdbarch, fi);
  1358.             gdb_assert (numargs >= 0);
  1359.             if (numargs == 0)
  1360.               puts_filtered (" no args.");
  1361.             else if (numargs == 1)
  1362.               puts_filtered (" 1 arg: ");
  1363.             else
  1364.               printf_filtered (" %d args: ", numargs);
  1365.           }
  1366.         print_frame_args (func, fi, numargs, gdb_stdout);
  1367.         puts_filtered ("\n");
  1368.       }
  1369.   }
  1370.   {
  1371.     /* Address of the local variables for this frame, or 0.  */
  1372.     CORE_ADDR arg_list = get_frame_locals_address (fi);

  1373.     if (arg_list == 0)
  1374.       printf_filtered (" Locals at unknown address,");
  1375.     else
  1376.       {
  1377.         printf_filtered (" Locals at ");
  1378.         fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
  1379.         printf_filtered (",");
  1380.       }
  1381.   }

  1382.   /* Print as much information as possible on the location of all the
  1383.      registers.  */
  1384.   {
  1385.     enum lval_type lval;
  1386.     int optimized;
  1387.     int unavailable;
  1388.     CORE_ADDR addr;
  1389.     int realnum;
  1390.     int count;
  1391.     int i;
  1392.     int need_nl = 1;

  1393.     /* The sp is special; what's displayed isn't the save address, but
  1394.        the value of the previous frame's sp.  This is a legacy thing,
  1395.        at one stage the frame cached the previous frame's SP instead
  1396.        of its address, hence it was easiest to just display the cached
  1397.        value.  */
  1398.     if (gdbarch_sp_regnum (gdbarch) >= 0)
  1399.       {
  1400.         /* Find out the location of the saved stack pointer with out
  1401.            actually evaluating it.  */
  1402.         frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
  1403.                                &optimized, &unavailable, &lval, &addr,
  1404.                                &realnum, NULL);
  1405.         if (!optimized && !unavailable && lval == not_lval)
  1406.           {
  1407.             enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1408.             int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
  1409.             gdb_byte value[MAX_REGISTER_SIZE];
  1410.             CORE_ADDR sp;

  1411.             frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
  1412.                                    &optimized, &unavailable, &lval, &addr,
  1413.                                    &realnum, value);
  1414.             /* NOTE: cagney/2003-05-22: This is assuming that the
  1415.                stack pointer was packed as an unsigned integer.  That
  1416.                may or may not be valid.  */
  1417.             sp = extract_unsigned_integer (value, sp_size, byte_order);
  1418.             printf_filtered (" Previous frame's sp is ");
  1419.             fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
  1420.             printf_filtered ("\n");
  1421.             need_nl = 0;
  1422.           }
  1423.         else if (!optimized && !unavailable && lval == lval_memory)
  1424.           {
  1425.             printf_filtered (" Previous frame's sp at ");
  1426.             fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
  1427.             printf_filtered ("\n");
  1428.             need_nl = 0;
  1429.           }
  1430.         else if (!optimized && !unavailable && lval == lval_register)
  1431.           {
  1432.             printf_filtered (" Previous frame's sp in %s\n",
  1433.                              gdbarch_register_name (gdbarch, realnum));
  1434.             need_nl = 0;
  1435.           }
  1436.         /* else keep quiet.  */
  1437.       }

  1438.     count = 0;
  1439.     numregs = gdbarch_num_regs (gdbarch)
  1440.               + gdbarch_num_pseudo_regs (gdbarch);
  1441.     for (i = 0; i < numregs; i++)
  1442.       if (i != gdbarch_sp_regnum (gdbarch)
  1443.           && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
  1444.         {
  1445.           /* Find out the location of the saved register without
  1446.              fetching the corresponding value.  */
  1447.           frame_register_unwind (fi, i, &optimized, &unavailable,
  1448.                                  &lval, &addr, &realnum, NULL);
  1449.           /* For moment, only display registers that were saved on the
  1450.              stack.  */
  1451.           if (!optimized && !unavailable && lval == lval_memory)
  1452.             {
  1453.               if (count == 0)
  1454.                 puts_filtered (" Saved registers:\n ");
  1455.               else
  1456.                 puts_filtered (",");
  1457.               wrap_here (" ");
  1458.               printf_filtered (" %s at ",
  1459.                                gdbarch_register_name (gdbarch, i));
  1460.               fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
  1461.               count++;
  1462.             }
  1463.         }
  1464.     if (count || need_nl)
  1465.       puts_filtered ("\n");
  1466.   }

  1467.   do_cleanups (back_to);
  1468. }

  1469. /* Print briefly all stack frames or just the innermost COUNT_EXP
  1470.    frames.  */

  1471. static void
  1472. backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
  1473.                      int from_tty)
  1474. {
  1475.   struct frame_info *fi;
  1476.   int count;
  1477.   int i;
  1478.   struct frame_info *trailing;
  1479.   int trailing_level, py_start = 0, py_end = 0;
  1480.   enum ext_lang_bt_status result = EXT_LANG_BT_ERROR;

  1481.   if (!target_has_stack)
  1482.     error (_("No stack."));

  1483.   /* The following code must do two things.  First, it must set the
  1484.      variable TRAILING to the frame from which we should start
  1485.      printing.  Second, it must set the variable count to the number
  1486.      of frames which we should print, or -1 if all of them.  */
  1487.   trailing = get_current_frame ();

  1488.   trailing_level = 0;
  1489.   if (count_exp)
  1490.     {
  1491.       count = parse_and_eval_long (count_exp);
  1492.       if (count < 0)
  1493.         {
  1494.           struct frame_info *current;

  1495.           py_start = count;
  1496.           count = -count;

  1497.           current = trailing;
  1498.           while (current && count--)
  1499.             {
  1500.               QUIT;
  1501.               current = get_prev_frame (current);
  1502.             }

  1503.           /* Will stop when CURRENT reaches the top of the stack.
  1504.              TRAILING will be COUNT below it.  */
  1505.           while (current)
  1506.             {
  1507.               QUIT;
  1508.               trailing = get_prev_frame (trailing);
  1509.               current = get_prev_frame (current);
  1510.               trailing_level++;
  1511.             }

  1512.           count = -1;
  1513.         }
  1514.       else
  1515.         {
  1516.           py_start = 0;
  1517.           py_end = count;
  1518.         }
  1519.     }
  1520.   else
  1521.     {
  1522.       py_end = -1;
  1523.       count = -1;
  1524.     }

  1525.   if (info_verbose)
  1526.     {
  1527.       /* Read in symbols for all of the frames.  Need to do this in a
  1528.          separate pass so that "Reading in symbols for xxx" messages
  1529.          don't screw up the appearance of the backtrace.  Also if
  1530.          people have strong opinions against reading symbols for
  1531.          backtrace this may have to be an option.  */
  1532.       i = count;
  1533.       for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
  1534.         {
  1535.           CORE_ADDR pc;

  1536.           QUIT;
  1537.           pc = get_frame_address_in_block (fi);
  1538.           expand_symtab_containing_pc (pc, find_pc_mapped_section (pc));
  1539.         }
  1540.     }

  1541.   if (! no_filters)
  1542.     {
  1543.       int flags = PRINT_LEVEL | PRINT_FRAME_INFO | PRINT_ARGS;
  1544.       enum ext_lang_frame_args arg_type;

  1545.       if (show_locals)
  1546.         flags |= PRINT_LOCALS;

  1547.       if (!strcmp (print_frame_arguments, "scalars"))
  1548.         arg_type = CLI_SCALAR_VALUES;
  1549.       else if (!strcmp (print_frame_arguments, "all"))
  1550.         arg_type = CLI_ALL_VALUES;
  1551.       else
  1552.         arg_type = NO_VALUES;

  1553.       result = apply_ext_lang_frame_filter (get_current_frame (), flags,
  1554.                                             arg_type, current_uiout,
  1555.                                             py_start, py_end);
  1556.     }

  1557.   /* Run the inbuilt backtrace if there are no filters registered, or
  1558.      "no-filters" has been specified from the command.  */
  1559.   if (no_filters ||  result == EXT_LANG_BT_NO_FILTERS)
  1560.     {
  1561.       for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
  1562.         {
  1563.           QUIT;

  1564.           /* Don't use print_stack_frame; if an error() occurs it probably
  1565.              means further attempts to backtrace would fail (on the other
  1566.              hand, perhaps the code does or could be fixed to make sure
  1567.              the frame->prev field gets set to NULL in that case).  */

  1568.           print_frame_info (fi, 1, LOCATION, 1, 0);
  1569.           if (show_locals)
  1570.             {
  1571.               struct frame_id frame_id = get_frame_id (fi);

  1572.               print_frame_local_vars (fi, 1, gdb_stdout);

  1573.               /* print_frame_local_vars invalidates FI.  */
  1574.               fi = frame_find_by_id (frame_id);
  1575.               if (fi == NULL)
  1576.                 {
  1577.                   trailing = NULL;
  1578.                   warning (_("Unable to restore previously selected frame."));
  1579.                   break;
  1580.                 }
  1581.             }

  1582.           /* Save the last frame to check for error conditions.  */
  1583.           trailing = fi;
  1584.         }

  1585.       /* If we've stopped before the end, mention that.  */
  1586.       if (fi && from_tty)
  1587.         printf_filtered (_("(More stack frames follow...)\n"));

  1588.       /* If we've run out of frames, and the reason appears to be an error
  1589.          condition, print it.  */
  1590.       if (fi == NULL && trailing != NULL)
  1591.         {
  1592.           enum unwind_stop_reason reason;

  1593.           reason = get_frame_unwind_stop_reason (trailing);
  1594.           if (reason >= UNWIND_FIRST_ERROR)
  1595.             printf_filtered (_("Backtrace stopped: %s\n"),
  1596.                              frame_stop_reason_string (trailing));
  1597.         }
  1598.     }
  1599. }

  1600. static void
  1601. backtrace_command (char *arg, int from_tty)
  1602. {
  1603.   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
  1604.   int fulltrace_arg = -1, arglen = 0, argc = 0, no_filters  = -1;
  1605.   int user_arg = 0;

  1606.   if (arg)
  1607.     {
  1608.       char **argv;
  1609.       int i;

  1610.       argv = gdb_buildargv (arg);
  1611.       make_cleanup_freeargv (argv);
  1612.       argc = 0;
  1613.       for (i = 0; argv[i]; i++)
  1614.         {
  1615.           unsigned int j;

  1616.           for (j = 0; j < strlen (argv[i]); j++)
  1617.             argv[i][j] = tolower (argv[i][j]);

  1618.           if (no_filters < 0 && subset_compare (argv[i], "no-filters"))
  1619.             no_filters = argc;
  1620.           else
  1621.             {
  1622.               if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
  1623.                 fulltrace_arg = argc;
  1624.               else
  1625.                 {
  1626.                   user_arg++;
  1627.                   arglen += strlen (argv[i]);
  1628.                 }
  1629.             }
  1630.           argc++;
  1631.         }
  1632.       arglen += user_arg;
  1633.       if (fulltrace_arg >= 0 || no_filters >= 0)
  1634.         {
  1635.           if (arglen > 0)
  1636.             {
  1637.               arg = xmalloc (arglen + 1);
  1638.               make_cleanup (xfree, arg);
  1639.               arg[0] = 0;
  1640.               for (i = 0; i < argc; i++)
  1641.                 {
  1642.                   if (i != fulltrace_arg && i != no_filters)
  1643.                     {
  1644.                       strcat (arg, argv[i]);
  1645.                       strcat (arg, " ");
  1646.                     }
  1647.                 }
  1648.             }
  1649.           else
  1650.             arg = NULL;
  1651.         }
  1652.     }

  1653.   backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */,
  1654.                        no_filters >= 0 /* no frame-filters */, from_tty);

  1655.   do_cleanups (old_chain);
  1656. }

  1657. static void
  1658. backtrace_full_command (char *arg, int from_tty)
  1659. {
  1660.   backtrace_command_1 (arg, 1 /* show_locals */, 0, from_tty);
  1661. }


  1662. /* Iterate over the local variables of a block B, calling CB with
  1663.    CB_DATA.  */

  1664. static void
  1665. iterate_over_block_locals (const struct block *b,
  1666.                            iterate_over_block_arg_local_vars_cb cb,
  1667.                            void *cb_data)
  1668. {
  1669.   struct block_iterator iter;
  1670.   struct symbol *sym;

  1671.   ALL_BLOCK_SYMBOLS (b, iter, sym)
  1672.     {
  1673.       switch (SYMBOL_CLASS (sym))
  1674.         {
  1675.         case LOC_LOCAL:
  1676.         case LOC_REGISTER:
  1677.         case LOC_STATIC:
  1678.         case LOC_COMPUTED:
  1679.           if (SYMBOL_IS_ARGUMENT (sym))
  1680.             break;
  1681.           if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
  1682.             break;
  1683.           (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
  1684.           break;

  1685.         default:
  1686.           /* Ignore symbols which are not locals.  */
  1687.           break;
  1688.         }
  1689.     }
  1690. }


  1691. /* Same, but print labels.  */

  1692. #if 0
  1693. /* Commented out, as the code using this function has also been
  1694.    commented out.  FIXME:brobecker/2009-01-13: Find out why the code
  1695.    was commented out in the first place.  The discussion introducing
  1696.    this change (2007-12-04: Support lexical blocks and function bodies
  1697.    that occupy non-contiguous address ranges) did not explain why
  1698.    this change was made.  */
  1699. static int
  1700. print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
  1701.                           int *have_default, struct ui_file *stream)
  1702. {
  1703.   struct block_iterator iter;
  1704.   struct symbol *sym;
  1705.   int values_printed = 0;

  1706.   ALL_BLOCK_SYMBOLS (b, iter, sym)
  1707.     {
  1708.       if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
  1709.         {
  1710.           if (*have_default)
  1711.             continue;
  1712.           *have_default = 1;
  1713.         }
  1714.       if (SYMBOL_CLASS (sym) == LOC_LABEL)
  1715.         {
  1716.           struct symtab_and_line sal;
  1717.           struct value_print_options opts;

  1718.           sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
  1719.           values_printed = 1;
  1720.           fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
  1721.           get_user_print_options (&opts);
  1722.           if (opts.addressprint)
  1723.             {
  1724.               fprintf_filtered (stream, " ");
  1725.               fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
  1726.                               stream);
  1727.             }
  1728.           fprintf_filtered (stream, " in file %s, line %d\n",
  1729.                             sal.symtab->filename, sal.line);
  1730.         }
  1731.     }

  1732.   return values_printed;
  1733. }
  1734. #endif

  1735. /* Iterate over all the local variables in block B, including all its
  1736.    superblocks, stopping when the top-level block is reached.  */

  1737. void
  1738. iterate_over_block_local_vars (const struct block *block,
  1739.                                iterate_over_block_arg_local_vars_cb cb,
  1740.                                void *cb_data)
  1741. {
  1742.   while (block)
  1743.     {
  1744.       iterate_over_block_locals (block, cb, cb_data);
  1745.       /* After handling the function's top-level block, stop.  Don't
  1746.          continue to its superblock, the block of per-file
  1747.          symbols.  */
  1748.       if (BLOCK_FUNCTION (block))
  1749.         break;
  1750.       block = BLOCK_SUPERBLOCK (block);
  1751.     }
  1752. }

  1753. /* Data to be passed around in the calls to the locals and args
  1754.    iterators.  */

  1755. struct print_variable_and_value_data
  1756. {
  1757.   struct frame_id frame_id;
  1758.   int num_tabs;
  1759.   struct ui_file *stream;
  1760.   int values_printed;
  1761. };

  1762. /* The callback for the locals and args iterators.  */

  1763. static void
  1764. do_print_variable_and_value (const char *print_name,
  1765.                              struct symbol *sym,
  1766.                              void *cb_data)
  1767. {
  1768.   struct print_variable_and_value_data *p = cb_data;
  1769.   struct frame_info *frame;

  1770.   frame = frame_find_by_id (p->frame_id);
  1771.   if (frame == NULL)
  1772.     {
  1773.       warning (_("Unable to restore previously selected frame."));
  1774.       return;
  1775.     }

  1776.   print_variable_and_value (print_name, sym, frame, p->stream, p->num_tabs);

  1777.   /* print_variable_and_value invalidates FRAME.  */
  1778.   frame = NULL;

  1779.   p->values_printed = 1;
  1780. }

  1781. /* Print all variables from the innermost up to the function block of FRAME.
  1782.    Print them with values to STREAM indented by NUM_TABS.

  1783.    This function will invalidate FRAME.  */

  1784. static void
  1785. print_frame_local_vars (struct frame_info *frame, int num_tabs,
  1786.                         struct ui_file *stream)
  1787. {
  1788.   struct print_variable_and_value_data cb_data;
  1789.   const struct block *block;
  1790.   CORE_ADDR pc;

  1791.   if (!get_frame_pc_if_available (frame, &pc))
  1792.     {
  1793.       fprintf_filtered (stream,
  1794.                         _("PC unavailable, cannot determine locals.\n"));
  1795.       return;
  1796.     }

  1797.   block = get_frame_block (frame, 0);
  1798.   if (block == 0)
  1799.     {
  1800.       fprintf_filtered (stream, "No symbol table info available.\n");
  1801.       return;
  1802.     }

  1803.   cb_data.frame_id = get_frame_id (frame);
  1804.   cb_data.num_tabs = 4 * num_tabs;
  1805.   cb_data.stream = stream;
  1806.   cb_data.values_printed = 0;

  1807.   iterate_over_block_local_vars (block,
  1808.                                  do_print_variable_and_value,
  1809.                                  &cb_data);

  1810.   /* do_print_variable_and_value invalidates FRAME.  */
  1811.   frame = NULL;

  1812.   if (!cb_data.values_printed)
  1813.     fprintf_filtered (stream, _("No locals.\n"));
  1814. }

  1815. void
  1816. locals_info (char *args, int from_tty)
  1817. {
  1818.   print_frame_local_vars (get_selected_frame (_("No frame selected.")),
  1819.                           0, gdb_stdout);
  1820. }

  1821. /* Iterate over all the argument variables in block B.

  1822.    Returns 1 if any argument was walked; 0 otherwise.  */

  1823. void
  1824. iterate_over_block_arg_vars (const struct block *b,
  1825.                              iterate_over_block_arg_local_vars_cb cb,
  1826.                              void *cb_data)
  1827. {
  1828.   struct block_iterator iter;
  1829.   struct symbol *sym, *sym2;

  1830.   ALL_BLOCK_SYMBOLS (b, iter, sym)
  1831.     {
  1832.       /* Don't worry about things which aren't arguments.  */
  1833.       if (SYMBOL_IS_ARGUMENT (sym))
  1834.         {
  1835.           /* We have to look up the symbol because arguments can have
  1836.              two entries (one a parameter, one a local) and the one we
  1837.              want is the local, which lookup_symbol will find for us.
  1838.              This includes gcc1 (not gcc2) on the sparc when passing a
  1839.              small structure and gcc2 when the argument type is float
  1840.              and it is passed as a double and converted to float by
  1841.              the prologue (in the latter case the type of the LOC_ARG
  1842.              symbol is double and the type of the LOC_LOCAL symbol is
  1843.              float).  There are also LOC_ARG/LOC_REGISTER pairs which
  1844.              are not combined in symbol-reading.  */

  1845.           sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
  1846.                                 b, VAR_DOMAIN, NULL);
  1847.           (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
  1848.         }
  1849.     }
  1850. }

  1851. /* Print all argument variables of the function of FRAME.
  1852.    Print them with values to STREAM.

  1853.    This function will invalidate FRAME.  */

  1854. static void
  1855. print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
  1856. {
  1857.   struct print_variable_and_value_data cb_data;
  1858.   struct symbol *func;
  1859.   CORE_ADDR pc;

  1860.   if (!get_frame_pc_if_available (frame, &pc))
  1861.     {
  1862.       fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
  1863.       return;
  1864.     }

  1865.   func = get_frame_function (frame);
  1866.   if (func == NULL)
  1867.     {
  1868.       fprintf_filtered (stream, _("No symbol table info available.\n"));
  1869.       return;
  1870.     }

  1871.   cb_data.frame_id = get_frame_id (frame);
  1872.   cb_data.num_tabs = 0;
  1873.   cb_data.stream = gdb_stdout;
  1874.   cb_data.values_printed = 0;

  1875.   iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
  1876.                                do_print_variable_and_value, &cb_data);

  1877.   /* do_print_variable_and_value invalidates FRAME.  */
  1878.   frame = NULL;

  1879.   if (!cb_data.values_printed)
  1880.     fprintf_filtered (stream, _("No arguments.\n"));
  1881. }

  1882. void
  1883. args_info (char *ignore, int from_tty)
  1884. {
  1885.   print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
  1886.                         gdb_stdout);
  1887. }


  1888. static void
  1889. args_plus_locals_info (char *ignore, int from_tty)
  1890. {
  1891.   args_info (ignore, from_tty);
  1892.   locals_info (ignore, from_tty);
  1893. }


  1894. /* Select frame FRAME.  Also print the stack frame and show the source
  1895.    if this is the tui version.  */
  1896. static void
  1897. select_and_print_frame (struct frame_info *frame)
  1898. {
  1899.   select_frame (frame);
  1900.   if (frame)
  1901.     print_stack_frame (frame, 1, SRC_AND_LOC, 1);
  1902. }

  1903. /* Return the symbol-block in which the selected frame is executing.
  1904.    Can return zero under various legitimate circumstances.

  1905.    If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
  1906.    code address within the block returned.  We use this to decide
  1907.    which macros are in scope.  */

  1908. const struct block *
  1909. get_selected_block (CORE_ADDR *addr_in_block)
  1910. {
  1911.   if (!has_stack_frames ())
  1912.     return 0;

  1913.   return get_frame_block (get_selected_frame (NULL), addr_in_block);
  1914. }

  1915. /* Find a frame a certain number of levels away from FRAME.
  1916.    LEVEL_OFFSET_PTR points to an int containing the number of levels.
  1917.    Positive means go to earlier frames (up); negative, the reverse.
  1918.    The int that contains the number of levels is counted toward
  1919.    zero as the frames for those levels are found.
  1920.    If the top or bottom frame is reached, that frame is returned,
  1921.    but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
  1922.    how much farther the original request asked to go.  */

  1923. struct frame_info *
  1924. find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
  1925. {
  1926.   /* Going up is simple: just call get_prev_frame enough times or
  1927.      until the initial frame is reached.  */
  1928.   while (*level_offset_ptr > 0)
  1929.     {
  1930.       struct frame_info *prev = get_prev_frame (frame);

  1931.       if (!prev)
  1932.         break;
  1933.       (*level_offset_ptr)--;
  1934.       frame = prev;
  1935.     }

  1936.   /* Going down is just as simple.  */
  1937.   while (*level_offset_ptr < 0)
  1938.     {
  1939.       struct frame_info *next = get_next_frame (frame);

  1940.       if (!next)
  1941.         break;
  1942.       (*level_offset_ptr)++;
  1943.       frame = next;
  1944.     }

  1945.   return frame;
  1946. }

  1947. /* The "select_frame" command.  With no argument this is a NOP.
  1948.    Select the frame at level LEVEL_EXP if it is a valid level.
  1949.    Otherwise, treat LEVEL_EXP as an address expression and select it.

  1950.    See parse_frame_specification for more info on proper frame
  1951.    expressions.  */

  1952. void
  1953. select_frame_command (char *level_exp, int from_tty)
  1954. {
  1955.   select_frame (parse_frame_specification_1 (level_exp, "No stack.", NULL));
  1956. }

  1957. /* The "frame" command.  With no argument, print the selected frame
  1958.    briefly.  With an argument, behave like select_frame and then print
  1959.    the selected frame.  */

  1960. static void
  1961. frame_command (char *level_exp, int from_tty)
  1962. {
  1963.   select_frame_command (level_exp, from_tty);
  1964.   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
  1965. }

  1966. /* The XDB Compatibility command to print the current frame.  */

  1967. static void
  1968. current_frame_command (char *level_exp, int from_tty)
  1969. {
  1970.   print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC, 1);
  1971. }

  1972. /* Select the frame up one or COUNT_EXP stack levels from the
  1973.    previously selected frame, and print it briefly.  */

  1974. static void
  1975. up_silently_base (const char *count_exp)
  1976. {
  1977.   struct frame_info *frame;
  1978.   int count = 1;

  1979.   if (count_exp)
  1980.     count = parse_and_eval_long (count_exp);

  1981.   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
  1982.   if (count != 0 && count_exp == NULL)
  1983.     error (_("Initial frame selected; you cannot go up."));
  1984.   select_frame (frame);
  1985. }

  1986. static void
  1987. up_silently_command (char *count_exp, int from_tty)
  1988. {
  1989.   up_silently_base (count_exp);
  1990. }

  1991. static void
  1992. up_command (char *count_exp, int from_tty)
  1993. {
  1994.   up_silently_base (count_exp);
  1995.   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
  1996. }

  1997. /* Select the frame down one or COUNT_EXP stack levels from the previously
  1998.    selected frame, and print it briefly.  */

  1999. static void
  2000. down_silently_base (const char *count_exp)
  2001. {
  2002.   struct frame_info *frame;
  2003.   int count = -1;

  2004.   if (count_exp)
  2005.     count = -parse_and_eval_long (count_exp);

  2006.   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
  2007.   if (count != 0 && count_exp == NULL)
  2008.     {
  2009.       /* We only do this if COUNT_EXP is not specified.  That way
  2010.          "down" means to really go down (and let me know if that is
  2011.          impossible), but "down 9999" can be used to mean go all the
  2012.          way down without getting an error.  */

  2013.       error (_("Bottom (innermost) frame selected; you cannot go down."));
  2014.     }

  2015.   select_frame (frame);
  2016. }

  2017. static void
  2018. down_silently_command (char *count_exp, int from_tty)
  2019. {
  2020.   down_silently_base (count_exp);
  2021. }

  2022. static void
  2023. down_command (char *count_exp, int from_tty)
  2024. {
  2025.   down_silently_base (count_exp);
  2026.   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
  2027. }


  2028. void
  2029. return_command (char *retval_exp, int from_tty)
  2030. {
  2031.   /* Initialize it just to avoid a GCC false warning.  */
  2032.   enum return_value_convention rv_conv = RETURN_VALUE_STRUCT_CONVENTION;
  2033.   struct frame_info *thisframe;
  2034.   struct gdbarch *gdbarch;
  2035.   struct symbol *thisfun;
  2036.   struct value *return_value = NULL;
  2037.   struct value *function = NULL;
  2038.   const char *query_prefix = "";

  2039.   thisframe = get_selected_frame ("No selected frame.");
  2040.   thisfun = get_frame_function (thisframe);
  2041.   gdbarch = get_frame_arch (thisframe);

  2042.   if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
  2043.     error (_("Can not force return from an inlined function."));

  2044.   /* Compute the return value.  If the computation triggers an error,
  2045.      let it bail.  If the return type can't be handled, set
  2046.      RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
  2047.      message.  */
  2048.   if (retval_exp)
  2049.     {
  2050.       struct expression *retval_expr = parse_expression (retval_exp);
  2051.       struct cleanup *old_chain = make_cleanup (xfree, retval_expr);
  2052.       struct type *return_type = NULL;

  2053.       /* Compute the return value.  Should the computation fail, this
  2054.          call throws an error.  */
  2055.       return_value = evaluate_expression (retval_expr);

  2056.       /* Cast return value to the return type of the function.  Should
  2057.          the cast fail, this call throws an error.  */
  2058.       if (thisfun != NULL)
  2059.         return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
  2060.       if (return_type == NULL)
  2061.               {
  2062.           if (retval_expr->elts[0].opcode != UNOP_CAST
  2063.               && retval_expr->elts[0].opcode != UNOP_CAST_TYPE)
  2064.             error (_("Return value type not available for selected "
  2065.                      "stack frame.\n"
  2066.                      "Please use an explicit cast of the value to return."));
  2067.           return_type = value_type (return_value);
  2068.         }
  2069.       do_cleanups (old_chain);
  2070.       CHECK_TYPEDEF (return_type);
  2071.       return_value = value_cast (return_type, return_value);

  2072.       /* Make sure the value is fully evaluated.  It may live in the
  2073.          stack frame we're about to pop.  */
  2074.       if (value_lazy (return_value))
  2075.         value_fetch_lazy (return_value);

  2076.       if (thisfun != NULL)
  2077.         function = read_var_value (thisfun, thisframe);

  2078.       rv_conv = RETURN_VALUE_REGISTER_CONVENTION;
  2079.       if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
  2080.         /* If the return-type is "void", don't try to find the
  2081.            return-value's location.  However, do still evaluate the
  2082.            return expression so that, even when the expression result
  2083.            is discarded, side effects such as "return i++" still
  2084.            occur.  */
  2085.         return_value = NULL;
  2086.       else if (thisfun != NULL)
  2087.         {
  2088.           rv_conv = struct_return_convention (gdbarch, function, return_type);
  2089.           if (rv_conv == RETURN_VALUE_STRUCT_CONVENTION
  2090.               || rv_conv == RETURN_VALUE_ABI_RETURNS_ADDRESS)
  2091.             {
  2092.               query_prefix = "The location at which to store the "
  2093.                 "function's return value is unknown.\n"
  2094.                 "If you continue, the return value "
  2095.                 "that you specified will be ignored.\n";
  2096.               return_value = NULL;
  2097.             }
  2098.         }
  2099.     }

  2100.   /* Does an interactive user really want to do this?  Include
  2101.      information, such as how well GDB can handle the return value, in
  2102.      the query message.  */
  2103.   if (from_tty)
  2104.     {
  2105.       int confirmed;

  2106.       if (thisfun == NULL)
  2107.         confirmed = query (_("%sMake selected stack frame return now? "),
  2108.                            query_prefix);
  2109.       else
  2110.         confirmed = query (_("%sMake %s return now? "), query_prefix,
  2111.                            SYMBOL_PRINT_NAME (thisfun));
  2112.       if (!confirmed)
  2113.         error (_("Not confirmed"));
  2114.     }

  2115.   /* Discard the selected frame and all frames inner-to it.  */
  2116.   frame_pop (get_selected_frame (NULL));

  2117.   /* Store RETURN_VALUE in the just-returned register set.  */
  2118.   if (return_value != NULL)
  2119.     {
  2120.       struct type *return_type = value_type (return_value);
  2121.       struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ());

  2122.       gdb_assert (rv_conv != RETURN_VALUE_STRUCT_CONVENTION
  2123.                   && rv_conv != RETURN_VALUE_ABI_RETURNS_ADDRESS);
  2124.       gdbarch_return_value (gdbarch, function, return_type,
  2125.                             get_current_regcache (), NULL /*read*/,
  2126.                             value_contents (return_value) /*write*/);
  2127.     }

  2128.   /* If we are at the end of a call dummy now, pop the dummy frame
  2129.      too.  */
  2130.   if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
  2131.     frame_pop (get_current_frame ());

  2132.   /* If interactive, print the frame that is now current.  */
  2133.   if (from_tty)
  2134.     frame_command ("0", 1);
  2135.   else
  2136.     select_frame_command ("0", 0);
  2137. }

  2138. /* Sets the scope to input function name, provided that the function
  2139.    is within the current stack frame.  */

  2140. struct function_bounds
  2141. {
  2142.   CORE_ADDR low, high;
  2143. };

  2144. static void
  2145. func_command (char *arg, int from_tty)
  2146. {
  2147.   struct frame_info *frame;
  2148.   int found = 0;
  2149.   struct symtabs_and_lines sals;
  2150.   int i;
  2151.   int level = 1;
  2152.   struct function_bounds *func_bounds = NULL;
  2153.   struct cleanup *cleanups;

  2154.   if (arg != NULL)
  2155.     return;

  2156.   frame = parse_frame_specification ("0");
  2157.   sals = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
  2158.   cleanups = make_cleanup (xfree, sals.sals);
  2159.   func_bounds = (struct function_bounds *) xmalloc (
  2160.                               sizeof (struct function_bounds) * sals.nelts);
  2161.   make_cleanup (xfree, func_bounds);
  2162.   for (i = 0; (i < sals.nelts && !found); i++)
  2163.     {
  2164.       if (sals.sals[i].pspace != current_program_space)
  2165.         func_bounds[i].low = func_bounds[i].high = 0;
  2166.       else if (sals.sals[i].pc == 0
  2167.                || find_pc_partial_function (sals.sals[i].pc, NULL,
  2168.                                             &func_bounds[i].low,
  2169.                                             &func_bounds[i].high) == 0)
  2170.         {
  2171.           func_bounds[i].low = func_bounds[i].high = 0;
  2172.         }
  2173.     }

  2174.   do
  2175.     {
  2176.       for (i = 0; (i < sals.nelts && !found); i++)
  2177.         found = (get_frame_pc (frame) >= func_bounds[i].low
  2178.                  && get_frame_pc (frame) < func_bounds[i].high);
  2179.       if (!found)
  2180.         {
  2181.           level = 1;
  2182.           frame = find_relative_frame (frame, &level);
  2183.         }
  2184.     }
  2185.   while (!found && level == 0);

  2186.   do_cleanups (cleanups);

  2187.   if (!found)
  2188.     printf_filtered (_("'%s' not within current stack frame.\n"), arg);
  2189.   else if (frame != get_selected_frame (NULL))
  2190.     select_and_print_frame (frame);
  2191. }

  2192. /* Gets the language of the current frame.  */

  2193. enum language
  2194. get_frame_language (void)
  2195. {
  2196.   struct frame_info *frame = deprecated_safe_get_selected_frame ();

  2197.   if (frame)
  2198.     {
  2199.       volatile struct gdb_exception ex;
  2200.       CORE_ADDR pc = 0;

  2201.       /* We determine the current frame language by looking up its
  2202.          associated symtab.  To retrieve this symtab, we use the frame
  2203.          PC.  However we cannot use the frame PC as is, because it
  2204.          usually points to the instruction following the "call", which
  2205.          is sometimes the first instruction of another function.  So
  2206.          we rely on get_frame_address_in_block(), it provides us with
  2207.          a PC that is guaranteed to be inside the frame's code
  2208.          block.  */

  2209.       TRY_CATCH (ex, RETURN_MASK_ERROR)
  2210.         {
  2211.           pc = get_frame_address_in_block (frame);
  2212.         }
  2213.       if (ex.reason < 0)
  2214.         {
  2215.           if (ex.error != NOT_AVAILABLE_ERROR)
  2216.             throw_exception (ex);
  2217.         }
  2218.       else
  2219.         {
  2220.           struct compunit_symtab *cust = find_pc_compunit_symtab (pc);

  2221.           if (cust != NULL)
  2222.             return compunit_language (cust);
  2223.         }
  2224.     }

  2225.   return language_unknown;
  2226. }


  2227. /* Provide a prototype to silence -Wmissing-prototypes.  */
  2228. void _initialize_stack (void);

  2229. void
  2230. _initialize_stack (void)
  2231. {
  2232.   add_com ("return", class_stack, return_command, _("\
  2233. Make selected stack frame return to its caller.\n\
  2234. Control remains in the debugger, but when you continue\n\
  2235. execution will resume in the frame above the one now selected.\n\
  2236. If an argument is given, it is an expression for the value to return."));

  2237.   add_com ("up", class_stack, up_command, _("\
  2238. Select and print stack frame that called this one.\n\
  2239. An argument says how many frames up to go."));
  2240.   add_com ("up-silently", class_support, up_silently_command, _("\
  2241. Same as the `up' command, but does not print anything.\n\
  2242. This is useful in command scripts."));

  2243.   add_com ("down", class_stack, down_command, _("\
  2244. Select and print stack frame called by this one.\n\
  2245. An argument says how many frames down to go."));
  2246.   add_com_alias ("do", "down", class_stack, 1);
  2247.   add_com_alias ("dow", "down", class_stack, 1);
  2248.   add_com ("down-silently", class_support, down_silently_command, _("\
  2249. Same as the `down' command, but does not print anything.\n\
  2250. This is useful in command scripts."));

  2251.   add_com ("frame", class_stack, frame_command, _("\
  2252. Select and print a stack frame.\nWith no argument, \
  2253. print the selected stack frame.  (See also \"info frame\").\n\
  2254. An argument specifies the frame to select.\n\
  2255. It can be a stack frame number or the address of the frame.\n\
  2256. With argument, nothing is printed if input is coming from\n\
  2257. a command file or a user-defined command."));

  2258.   add_com_alias ("f", "frame", class_stack, 1);

  2259.   if (xdb_commands)
  2260.     {
  2261.       add_com ("L", class_stack, current_frame_command,
  2262.                _("Print the current stack frame.\n"));
  2263.       add_com_alias ("V", "frame", class_stack, 1);
  2264.     }
  2265.   add_com ("select-frame", class_stack, select_frame_command, _("\
  2266. Select a stack frame without printing anything.\n\
  2267. An argument specifies the frame to select.\n\
  2268. It can be a stack frame number or the address of the frame.\n"));

  2269.   add_com ("backtrace", class_stack, backtrace_command, _("\
  2270. Print backtrace of all stack frames, or innermost COUNT frames.\n\
  2271. With a negative argument, print outermost -COUNT frames.\nUse of the \
  2272. 'full' qualifier also prints the values of the local variables.\n\
  2273. Use of the 'no-filters' qualifier prohibits frame filters from executing\n\
  2274. on this backtrace.\n"));
  2275.   add_com_alias ("bt", "backtrace", class_stack, 0);
  2276.   if (xdb_commands)
  2277.     {
  2278.       add_com_alias ("t", "backtrace", class_stack, 0);
  2279.       add_com ("T", class_stack, backtrace_full_command, _("\
  2280. Print backtrace of all stack frames, or innermost COUNT frames\n\
  2281. and the values of the local variables.\n\
  2282. With a negative argument, print outermost -COUNT frames.\n\
  2283. Usage: T <count>\n"));
  2284.     }

  2285.   add_com_alias ("where", "backtrace", class_alias, 0);
  2286.   add_info ("stack", backtrace_command,
  2287.             _("Backtrace of the stack, or innermost COUNT frames."));
  2288.   add_info_alias ("s", "stack", 1);
  2289.   add_info ("frame", frame_info,
  2290.             _("All about selected stack frame, or frame at ADDR."));
  2291.   add_info_alias ("f", "frame", 1);
  2292.   add_info ("locals", locals_info,
  2293.             _("Local variables of current stack frame."));
  2294.   add_info ("args", args_info,
  2295.             _("Argument variables of current stack frame."));
  2296.   if (xdb_commands)
  2297.     add_com ("l", class_info, args_plus_locals_info,
  2298.              _("Argument and local variables of current stack frame."));

  2299.   if (dbx_commands)
  2300.     add_com ("func", class_stack, func_command, _("\
  2301. Select the stack frame that contains <func>.\n\
  2302. Usage: func <name>\n"));

  2303.   add_setshow_enum_cmd ("frame-arguments", class_stack,
  2304.                         print_frame_arguments_choices, &print_frame_arguments,
  2305.                         _("Set printing of non-scalar frame arguments"),
  2306.                         _("Show printing of non-scalar frame arguments"),
  2307.                         NULL, NULL, NULL, &setprintlist, &showprintlist);

  2308.   add_setshow_boolean_cmd ("frame-arguments", no_class,
  2309.                            &print_raw_frame_arguments, _("\
  2310. Set whether to print frame arguments in raw form."), _("\
  2311. Show whether to print frame arguments in raw form."), _("\
  2312. If set, frame arguments are printed in raw form, bypassing any\n\
  2313. pretty-printers for that value."),
  2314.                            NULL, NULL,
  2315.                            &setprintrawlist, &showprintrawlist);

  2316.   add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
  2317.                                 &disassemble_next_line, _("\
  2318. Set whether to disassemble next source line or insn when execution stops."),
  2319.                                 _("\
  2320. Show whether to disassemble next source line or insn when execution stops."),
  2321.                                 _("\
  2322. If ON, GDB will display disassembly of the next source line, in addition\n\
  2323. to displaying the source line itself.  If the next source line cannot\n\
  2324. be displayed (e.g., source is unavailable or there's no line info), GDB\n\
  2325. will display disassembly of next instruction instead of showing the\n\
  2326. source line.\n\
  2327. If AUTO, display disassembly of next instruction only if the source line\n\
  2328. cannot be displayed.\n\
  2329. If OFF (which is the default), never display the disassembly of the next\n\
  2330. source line."),
  2331.                                 NULL,
  2332.                                 show_disassemble_next_line,
  2333.                                 &setlist, &showlist);
  2334.   disassemble_next_line = AUTO_BOOLEAN_FALSE;

  2335.   add_setshow_enum_cmd ("entry-values", class_stack,
  2336.                         print_entry_values_choices, &print_entry_values,
  2337.                         _("Set printing of function arguments at function "
  2338.                           "entry"),
  2339.                         _("Show printing of function arguments at function "
  2340.                           "entry"),
  2341.                         _("\
  2342. GDB can sometimes determine the values of function arguments at entry,\n\
  2343. in addition to their current values.  This option tells GDB whether\n\
  2344. to print the current value, the value at entry (marked as val@entry),\n\
  2345. or both.  Note that one or both of these values may be <optimized out>."),
  2346.                         NULL, NULL, &setprintlist, &showprintlist);
  2347. }