Home | History | Annotate | Line # | Download | only in gdb
stack.c revision 1.1.1.6
      1 /* Print and select stack frames for GDB, the GNU debugger.
      2 
      3    Copyright (C) 1986-2019 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #include "defs.h"
     21 #include "value.h"
     22 #include "symtab.h"
     23 #include "gdbtypes.h"
     24 #include "expression.h"
     25 #include "language.h"
     26 #include "frame.h"
     27 #include "gdbcmd.h"
     28 #include "gdbcore.h"
     29 #include "target.h"
     30 #include "source.h"
     31 #include "breakpoint.h"
     32 #include "demangle.h"
     33 #include "inferior.h"
     34 #include "annotate.h"
     35 #include "ui-out.h"
     36 #include "block.h"
     37 #include "stack.h"
     38 #include "dictionary.h"
     39 #include "reggroups.h"
     40 #include "regcache.h"
     41 #include "solib.h"
     42 #include "valprint.h"
     43 #include "gdbthread.h"
     44 #include "cp-support.h"
     45 #include "disasm.h"
     46 #include "inline-frame.h"
     47 #include "linespec.h"
     48 #include "cli/cli-utils.h"
     49 #include "objfiles.h"
     50 
     51 #include "symfile.h"
     52 #include "extension.h"
     53 #include "observable.h"
     54 #include "common/def-vector.h"
     55 
     56 /* The possible choices of "set print frame-arguments", and the value
     57    of this setting.  */
     58 
     59 static const char *const print_frame_arguments_choices[] =
     60   {"all", "scalars", "none", NULL};
     61 static const char *print_frame_arguments = "scalars";
     62 
     63 /* If non-zero, don't invoke pretty-printers for frame arguments.  */
     64 static int print_raw_frame_arguments;
     65 
     66 /* The possible choices of "set print entry-values", and the value
     67    of this setting.  */
     68 
     69 const char print_entry_values_no[] = "no";
     70 const char print_entry_values_only[] = "only";
     71 const char print_entry_values_preferred[] = "preferred";
     72 const char print_entry_values_if_needed[] = "if-needed";
     73 const char print_entry_values_both[] = "both";
     74 const char print_entry_values_compact[] = "compact";
     75 const char print_entry_values_default[] = "default";
     76 static const char *const print_entry_values_choices[] =
     77 {
     78   print_entry_values_no,
     79   print_entry_values_only,
     80   print_entry_values_preferred,
     81   print_entry_values_if_needed,
     82   print_entry_values_both,
     83   print_entry_values_compact,
     84   print_entry_values_default,
     85   NULL
     86 };
     87 const char *print_entry_values = print_entry_values_default;
     88 
     89 /* Prototypes for local functions.  */
     90 
     91 static void print_frame_local_vars (struct frame_info *frame,
     92 				    bool quiet,
     93 				    const char *regexp, const char *t_regexp,
     94 				    int num_tabs, struct ui_file *stream);
     95 
     96 static void print_frame (struct frame_info *frame, int print_level,
     97 			 enum print_what print_what,  int print_args,
     98 			 struct symtab_and_line sal);
     99 
    100 static void set_last_displayed_sal (int valid,
    101 				    struct program_space *pspace,
    102 				    CORE_ADDR addr,
    103 				    struct symtab *symtab,
    104 				    int line);
    105 
    106 static struct frame_info *find_frame_for_function (const char *);
    107 static struct frame_info *find_frame_for_address (CORE_ADDR);
    108 
    109 /* Zero means do things normally; we are interacting directly with the
    110    user.  One means print the full filename and linenumber when a
    111    frame is printed, and do so in a format emacs18/emacs19.22 can
    112    parse.  Two means print similar annotations, but in many more
    113    cases and in a slightly different syntax.  */
    114 
    115 int annotation_level = 0;
    116 
    117 /* These variables hold the last symtab and line we displayed to the user.
    118  * This is where we insert a breakpoint or a skiplist entry by default.  */
    119 static int last_displayed_sal_valid = 0;
    120 static struct program_space *last_displayed_pspace = 0;
    121 static CORE_ADDR last_displayed_addr = 0;
    122 static struct symtab *last_displayed_symtab = 0;
    123 static int last_displayed_line = 0;
    124 
    125 
    127 /* Return 1 if we should display the address in addition to the location,
    128    because we are in the middle of a statement.  */
    129 
    130 static int
    131 frame_show_address (struct frame_info *frame,
    132 		    struct symtab_and_line sal)
    133 {
    134   /* If there is a line number, but no PC, then there is no location
    135      information associated with this sal.  The only way that should
    136      happen is for the call sites of inlined functions (SAL comes from
    137      find_frame_sal).  Otherwise, we would have some PC range if the
    138      SAL came from a line table.  */
    139   if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
    140     {
    141       if (get_next_frame (frame) == NULL)
    142 	gdb_assert (inline_skipped_frames (inferior_thread ()) > 0);
    143       else
    144 	gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
    145       return 0;
    146     }
    147 
    148   return get_frame_pc (frame) != sal.pc;
    149 }
    150 
    151 /* See frame.h.  */
    152 
    153 void
    154 print_stack_frame_to_uiout (struct ui_out *uiout, struct frame_info *frame,
    155 			    int print_level, enum print_what print_what,
    156 			    int set_current_sal)
    157 {
    158   scoped_restore save_uiout = make_scoped_restore (&current_uiout, uiout);
    159 
    160   print_stack_frame (frame, print_level, print_what, set_current_sal);
    161 }
    162 
    163 /* Show or print a stack frame FRAME briefly.  The output is formatted
    164    according to PRINT_LEVEL and PRINT_WHAT printing the frame's
    165    relative level, function name, argument list, and file name and
    166    line number.  If the frame's PC is not at the beginning of the
    167    source line, the actual PC is printed at the beginning.  */
    168 
    169 void
    170 print_stack_frame (struct frame_info *frame, int print_level,
    171 		   enum print_what print_what,
    172 		   int set_current_sal)
    173 {
    174 
    175   /* For mi, alway print location and address.  */
    176   if (current_uiout->is_mi_like_p ())
    177     print_what = LOC_AND_ADDRESS;
    178 
    179   TRY
    180     {
    181       print_frame_info (frame, print_level, print_what, 1 /* print_args */,
    182 			set_current_sal);
    183       if (set_current_sal)
    184 	set_current_sal_from_frame (frame);
    185     }
    186   CATCH (e, RETURN_MASK_ERROR)
    187     {
    188     }
    189   END_CATCH
    190 }
    191 
    192 /* Print nameless arguments of frame FRAME on STREAM, where START is
    193    the offset of the first nameless argument, and NUM is the number of
    194    nameless arguments to print.  FIRST is nonzero if this is the first
    195    argument (not just the first nameless argument).  */
    196 
    197 static void
    198 print_frame_nameless_args (struct frame_info *frame, long start, int num,
    199 			   int first, struct ui_file *stream)
    200 {
    201   struct gdbarch *gdbarch = get_frame_arch (frame);
    202   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    203   int i;
    204   CORE_ADDR argsaddr;
    205   long arg_value;
    206 
    207   for (i = 0; i < num; i++)
    208     {
    209       QUIT;
    210       argsaddr = get_frame_args_address (frame);
    211       if (!argsaddr)
    212 	return;
    213       arg_value = read_memory_integer (argsaddr + start,
    214 				       sizeof (int), byte_order);
    215       if (!first)
    216 	fprintf_filtered (stream, ", ");
    217       fprintf_filtered (stream, "%ld", arg_value);
    218       first = 0;
    219       start += sizeof (int);
    220     }
    221 }
    222 
    223 /* Print single argument of inferior function.  ARG must be already
    224    read in.
    225 
    226    Errors are printed as if they would be the parameter value.  Use zeroed ARG
    227    iff it should not be printed accoring to user settings.  */
    228 
    229 static void
    230 print_frame_arg (const struct frame_arg *arg)
    231 {
    232   struct ui_out *uiout = current_uiout;
    233   const char *error_message = NULL;
    234 
    235   string_file stb;
    236 
    237   gdb_assert (!arg->val || !arg->error);
    238   gdb_assert (arg->entry_kind == print_entry_values_no
    239 	      || arg->entry_kind == print_entry_values_only
    240 	      || (!uiout->is_mi_like_p ()
    241 		  && arg->entry_kind == print_entry_values_compact));
    242 
    243   annotate_arg_emitter arg_emitter;
    244   ui_out_emit_tuple tuple_emitter (uiout, NULL);
    245   fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
    246 			   SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
    247   if (arg->entry_kind == print_entry_values_compact)
    248     {
    249       /* It is OK to provide invalid MI-like stream as with
    250 	 PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
    251       stb.puts ("=");
    252 
    253       fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (arg->sym),
    254 			       SYMBOL_LANGUAGE (arg->sym),
    255 			       DMGL_PARAMS | DMGL_ANSI);
    256     }
    257   if (arg->entry_kind == print_entry_values_only
    258       || arg->entry_kind == print_entry_values_compact)
    259     stb.puts ("@entry");
    260   uiout->field_stream ("name", stb, ui_out_style_kind::VARIABLE);
    261   annotate_arg_name_end ();
    262   uiout->text ("=");
    263 
    264   if (!arg->val && !arg->error)
    265     uiout->text ("...");
    266   else
    267     {
    268       if (arg->error)
    269 	error_message = arg->error;
    270       else
    271 	{
    272 	  TRY
    273 	    {
    274 	      const struct language_defn *language;
    275 	      struct value_print_options opts;
    276 
    277 	      /* Avoid value_print because it will deref ref parameters.  We
    278 		 just want to print their addresses.  Print ??? for args whose
    279 		 address we do not know.  We pass 2 as "recurse" to val_print
    280 		 because our standard indentation here is 4 spaces, and
    281 		 val_print indents 2 for each recurse.  */
    282 
    283 	      annotate_arg_value (value_type (arg->val));
    284 
    285 	      /* Use the appropriate language to display our symbol, unless the
    286 		 user forced the language to a specific language.  */
    287 	      if (language_mode == language_mode_auto)
    288 		language = language_def (SYMBOL_LANGUAGE (arg->sym));
    289 	      else
    290 		language = current_language;
    291 
    292 	      get_no_prettyformat_print_options (&opts);
    293 	      opts.deref_ref = 1;
    294 	      opts.raw = print_raw_frame_arguments;
    295 
    296 	      /* True in "summary" mode, false otherwise.  */
    297 	      opts.summary = !strcmp (print_frame_arguments, "scalars");
    298 
    299 	      common_val_print (arg->val, &stb, 2, &opts, language);
    300 	    }
    301 	  CATCH (except, RETURN_MASK_ERROR)
    302 	    {
    303 	      error_message = except.message;
    304 	    }
    305 	  END_CATCH
    306 	}
    307       if (error_message != NULL)
    308 	stb.printf (_("<error reading variable: %s>"), error_message);
    309     }
    310 
    311   uiout->field_stream ("value", stb);
    312 }
    313 
    314 /* Read in inferior function local SYM at FRAME into ARGP.  Caller is
    315    responsible for xfree of ARGP->ERROR.  This function never throws an
    316    exception.  */
    317 
    318 void
    319 read_frame_local (struct symbol *sym, struct frame_info *frame,
    320 		  struct frame_arg *argp)
    321 {
    322   argp->sym = sym;
    323   argp->val = NULL;
    324   argp->error = NULL;
    325 
    326   TRY
    327     {
    328       argp->val = read_var_value (sym, NULL, frame);
    329     }
    330   CATCH (except, RETURN_MASK_ERROR)
    331     {
    332       argp->error = xstrdup (except.message);
    333     }
    334   END_CATCH
    335 }
    336 
    337 /* Read in inferior function parameter SYM at FRAME into ARGP.  Caller is
    338    responsible for xfree of ARGP->ERROR.  This function never throws an
    339    exception.  */
    340 
    341 void
    342 read_frame_arg (struct symbol *sym, struct frame_info *frame,
    343 	        struct frame_arg *argp, struct frame_arg *entryargp)
    344 {
    345   struct value *val = NULL, *entryval = NULL;
    346   char *val_error = NULL, *entryval_error = NULL;
    347   int val_equal = 0;
    348 
    349   if (print_entry_values != print_entry_values_only
    350       && print_entry_values != print_entry_values_preferred)
    351     {
    352       TRY
    353 	{
    354 	  val = read_var_value (sym, NULL, frame);
    355 	}
    356       CATCH (except, RETURN_MASK_ERROR)
    357 	{
    358 	  val_error = (char *) alloca (strlen (except.message) + 1);
    359 	  strcpy (val_error, except.message);
    360 	}
    361       END_CATCH
    362     }
    363 
    364   if (SYMBOL_COMPUTED_OPS (sym) != NULL
    365       && SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry != NULL
    366       && print_entry_values != print_entry_values_no
    367       && (print_entry_values != print_entry_values_if_needed
    368 	  || !val || value_optimized_out (val)))
    369     {
    370       TRY
    371 	{
    372 	  const struct symbol_computed_ops *ops;
    373 
    374 	  ops = SYMBOL_COMPUTED_OPS (sym);
    375 	  entryval = ops->read_variable_at_entry (sym, frame);
    376 	}
    377       CATCH (except, RETURN_MASK_ERROR)
    378 	{
    379 	  if (except.error != NO_ENTRY_VALUE_ERROR)
    380 	    {
    381 	      entryval_error = (char *) alloca (strlen (except.message) + 1);
    382 	      strcpy (entryval_error, except.message);
    383 	    }
    384 	}
    385       END_CATCH
    386 
    387       if (entryval != NULL && value_optimized_out (entryval))
    388 	entryval = NULL;
    389 
    390       if (print_entry_values == print_entry_values_compact
    391 	  || print_entry_values == print_entry_values_default)
    392 	{
    393 	  /* For MI do not try to use print_entry_values_compact for ARGP.  */
    394 
    395 	  if (val && entryval && !current_uiout->is_mi_like_p ())
    396 	    {
    397 	      struct type *type = value_type (val);
    398 
    399 	      if (value_lazy (val))
    400 		value_fetch_lazy (val);
    401 	      if (value_lazy (entryval))
    402 		value_fetch_lazy (entryval);
    403 
    404 	      if (value_contents_eq (val, 0, entryval, 0, TYPE_LENGTH (type)))
    405 		{
    406 		  /* Initialize it just to avoid a GCC false warning.  */
    407 		  struct value *val_deref = NULL, *entryval_deref;
    408 
    409 		  /* DW_AT_call_value does match with the current
    410 		     value.  If it is a reference still try to verify if
    411 		     dereferenced DW_AT_call_data_value does not differ.  */
    412 
    413 		  TRY
    414 		    {
    415 		      struct type *type_deref;
    416 
    417 		      val_deref = coerce_ref (val);
    418 		      if (value_lazy (val_deref))
    419 			value_fetch_lazy (val_deref);
    420 		      type_deref = value_type (val_deref);
    421 
    422 		      entryval_deref = coerce_ref (entryval);
    423 		      if (value_lazy (entryval_deref))
    424 			value_fetch_lazy (entryval_deref);
    425 
    426 		      /* If the reference addresses match but dereferenced
    427 			 content does not match print them.  */
    428 		      if (val != val_deref
    429 			  && value_contents_eq (val_deref, 0,
    430 						entryval_deref, 0,
    431 						TYPE_LENGTH (type_deref)))
    432 			val_equal = 1;
    433 		    }
    434 		  CATCH (except, RETURN_MASK_ERROR)
    435 		    {
    436 		      /* If the dereferenced content could not be
    437 			 fetched do not display anything.  */
    438 		      if (except.error == NO_ENTRY_VALUE_ERROR)
    439 			val_equal = 1;
    440 		      else if (except.message != NULL)
    441 			{
    442 			  entryval_error = (char *) alloca (strlen (except.message) + 1);
    443 			  strcpy (entryval_error, except.message);
    444 			}
    445 		    }
    446 		  END_CATCH
    447 
    448 		  /* Value was not a reference; and its content matches.  */
    449 		  if (val == val_deref)
    450 		    val_equal = 1;
    451 
    452 		  if (val_equal)
    453 		    entryval = NULL;
    454 		}
    455 	    }
    456 
    457 	  /* Try to remove possibly duplicate error message for ENTRYARGP even
    458 	     in MI mode.  */
    459 
    460 	  if (val_error && entryval_error
    461 	      && strcmp (val_error, entryval_error) == 0)
    462 	    {
    463 	      entryval_error = NULL;
    464 
    465 	      /* Do not se VAL_EQUAL as the same error message may be shown for
    466 		 the entry value even if no entry values are present in the
    467 		 inferior.  */
    468 	    }
    469 	}
    470     }
    471 
    472   if (entryval == NULL)
    473     {
    474       if (print_entry_values == print_entry_values_preferred)
    475 	{
    476 	  gdb_assert (val == NULL);
    477 
    478 	  TRY
    479 	    {
    480 	      val = read_var_value (sym, NULL, frame);
    481 	    }
    482 	  CATCH (except, RETURN_MASK_ERROR)
    483 	    {
    484 	      val_error = (char *) alloca (strlen (except.message) + 1);
    485 	      strcpy (val_error, except.message);
    486 	    }
    487 	  END_CATCH
    488 	}
    489       if (print_entry_values == print_entry_values_only
    490 	  || print_entry_values == print_entry_values_both
    491 	  || (print_entry_values == print_entry_values_preferred
    492 	      && (!val || value_optimized_out (val))))
    493 	{
    494 	  entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
    495 	  entryval_error = NULL;
    496 	}
    497     }
    498   if ((print_entry_values == print_entry_values_compact
    499        || print_entry_values == print_entry_values_if_needed
    500        || print_entry_values == print_entry_values_preferred)
    501       && (!val || value_optimized_out (val)) && entryval != NULL)
    502     {
    503       val = NULL;
    504       val_error = NULL;
    505     }
    506 
    507   argp->sym = sym;
    508   argp->val = val;
    509   argp->error = val_error ? xstrdup (val_error) : NULL;
    510   if (!val && !val_error)
    511     argp->entry_kind = print_entry_values_only;
    512   else if ((print_entry_values == print_entry_values_compact
    513 	   || print_entry_values == print_entry_values_default) && val_equal)
    514     {
    515       argp->entry_kind = print_entry_values_compact;
    516       gdb_assert (!current_uiout->is_mi_like_p ());
    517     }
    518   else
    519     argp->entry_kind = print_entry_values_no;
    520 
    521   entryargp->sym = sym;
    522   entryargp->val = entryval;
    523   entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
    524   if (!entryval && !entryval_error)
    525     entryargp->entry_kind = print_entry_values_no;
    526   else
    527     entryargp->entry_kind = print_entry_values_only;
    528 }
    529 
    530 /* Print the arguments of frame FRAME on STREAM, given the function
    531    FUNC running in that frame (as a symbol), where NUM is the number
    532    of arguments according to the stack frame (or -1 if the number of
    533    arguments is unknown).  */
    534 
    535 /* Note that currently the "number of arguments according to the
    536    stack frame" is only known on VAX where i refers to the "number of
    537    ints of arguments according to the stack frame".  */
    538 
    539 static void
    540 print_frame_args (struct symbol *func, struct frame_info *frame,
    541 		  int num, struct ui_file *stream)
    542 {
    543   struct ui_out *uiout = current_uiout;
    544   int first = 1;
    545   /* Offset of next stack argument beyond the one we have seen that is
    546      at the highest offset, or -1 if we haven't come to a stack
    547      argument yet.  */
    548   long highest_offset = -1;
    549   /* Number of ints of arguments that we have printed so far.  */
    550   int args_printed = 0;
    551   /* True if we should print arguments, false otherwise.  */
    552   int print_args = strcmp (print_frame_arguments, "none");
    553 
    554   if (func)
    555     {
    556       const struct block *b = SYMBOL_BLOCK_VALUE (func);
    557       struct block_iterator iter;
    558       struct symbol *sym;
    559 
    560       ALL_BLOCK_SYMBOLS (b, iter, sym)
    561         {
    562 	  struct frame_arg arg, entryarg;
    563 
    564 	  QUIT;
    565 
    566 	  /* Keep track of the highest stack argument offset seen, and
    567 	     skip over any kinds of symbols we don't care about.  */
    568 
    569 	  if (!SYMBOL_IS_ARGUMENT (sym))
    570 	    continue;
    571 
    572 	  switch (SYMBOL_CLASS (sym))
    573 	    {
    574 	    case LOC_ARG:
    575 	    case LOC_REF_ARG:
    576 	      {
    577 		long current_offset = SYMBOL_VALUE (sym);
    578 		int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
    579 
    580 		/* Compute address of next argument by adding the size of
    581 		   this argument and rounding to an int boundary.  */
    582 		current_offset =
    583 		  ((current_offset + arg_size + sizeof (int) - 1)
    584 		   & ~(sizeof (int) - 1));
    585 
    586 		/* If this is the highest offset seen yet, set
    587 		   highest_offset.  */
    588 		if (highest_offset == -1
    589 		    || (current_offset > highest_offset))
    590 		  highest_offset = current_offset;
    591 
    592 		/* Add the number of ints we're about to print to
    593 		   args_printed.  */
    594 		args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
    595 	      }
    596 
    597 	      /* We care about types of symbols, but don't need to
    598 		 keep track of stack offsets in them.  */
    599 	    case LOC_REGISTER:
    600 	    case LOC_REGPARM_ADDR:
    601 	    case LOC_COMPUTED:
    602 	    case LOC_OPTIMIZED_OUT:
    603 	    default:
    604 	      break;
    605 	    }
    606 
    607 	  /* We have to look up the symbol because arguments can have
    608 	     two entries (one a parameter, one a local) and the one we
    609 	     want is the local, which lookup_symbol will find for us.
    610 	     This includes gcc1 (not gcc2) on SPARC when passing a
    611 	     small structure and gcc2 when the argument type is float
    612 	     and it is passed as a double and converted to float by
    613 	     the prologue (in the latter case the type of the LOC_ARG
    614 	     symbol is double and the type of the LOC_LOCAL symbol is
    615 	     float).  */
    616 	  /* But if the parameter name is null, don't try it.  Null
    617 	     parameter names occur on the RS/6000, for traceback
    618 	     tables.  FIXME, should we even print them?  */
    619 
    620 	  if (*SYMBOL_LINKAGE_NAME (sym))
    621 	    {
    622 	      struct symbol *nsym;
    623 
    624 	      nsym = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
    625 						b, VAR_DOMAIN).symbol;
    626 	      gdb_assert (nsym != NULL);
    627 	      if (SYMBOL_CLASS (nsym) == LOC_REGISTER
    628 		  && !SYMBOL_IS_ARGUMENT (nsym))
    629 		{
    630 		  /* There is a LOC_ARG/LOC_REGISTER pair.  This means
    631 		     that it was passed on the stack and loaded into a
    632 		     register, or passed in a register and stored in a
    633 		     stack slot.  GDB 3.x used the LOC_ARG; GDB
    634 		     4.0-4.11 used the LOC_REGISTER.
    635 
    636 		     Reasons for using the LOC_ARG:
    637 
    638 		     (1) Because find_saved_registers may be slow for
    639 		         remote debugging.
    640 
    641 		     (2) Because registers are often re-used and stack
    642 		         slots rarely (never?) are.  Therefore using
    643 		         the stack slot is much less likely to print
    644 		         garbage.
    645 
    646 		     Reasons why we might want to use the LOC_REGISTER:
    647 
    648 		     (1) So that the backtrace prints the same value
    649 		         as "print foo".  I see no compelling reason
    650 		         why this needs to be the case; having the
    651 		         backtrace print the value which was passed
    652 		         in, and "print foo" print the value as
    653 		         modified within the called function, makes
    654 		         perfect sense to me.
    655 
    656 		     Additional note: It might be nice if "info args"
    657 		     displayed both values.
    658 
    659 		     One more note: There is a case with SPARC
    660 		     structure passing where we need to use the
    661 		     LOC_REGISTER, but this is dealt with by creating
    662 		     a single LOC_REGPARM in symbol reading.  */
    663 
    664 		  /* Leave sym (the LOC_ARG) alone.  */
    665 		  ;
    666 		}
    667 	      else
    668 		sym = nsym;
    669 	    }
    670 
    671 	  /* Print the current arg.  */
    672 	  if (!first)
    673 	    uiout->text (", ");
    674 	  uiout->wrap_hint ("    ");
    675 
    676 	  if (!print_args)
    677 	    {
    678 	      memset (&arg, 0, sizeof (arg));
    679 	      arg.sym = sym;
    680 	      arg.entry_kind = print_entry_values_no;
    681 	      memset (&entryarg, 0, sizeof (entryarg));
    682 	      entryarg.sym = sym;
    683 	      entryarg.entry_kind = print_entry_values_no;
    684 	    }
    685 	  else
    686 	    read_frame_arg (sym, frame, &arg, &entryarg);
    687 
    688 	  if (arg.entry_kind != print_entry_values_only)
    689 	    print_frame_arg (&arg);
    690 
    691 	  if (entryarg.entry_kind != print_entry_values_no)
    692 	    {
    693 	      if (arg.entry_kind != print_entry_values_only)
    694 		{
    695 		  uiout->text (", ");
    696 		  uiout->wrap_hint ("    ");
    697 		}
    698 
    699 	      print_frame_arg (&entryarg);
    700 	    }
    701 
    702 	  xfree (arg.error);
    703 	  xfree (entryarg.error);
    704 
    705 	  first = 0;
    706 	}
    707     }
    708 
    709   /* Don't print nameless args in situations where we don't know
    710      enough about the stack to find them.  */
    711   if (num != -1)
    712     {
    713       long start;
    714 
    715       if (highest_offset == -1)
    716 	start = gdbarch_frame_args_skip (get_frame_arch (frame));
    717       else
    718 	start = highest_offset;
    719 
    720       print_frame_nameless_args (frame, start, num - args_printed,
    721 				 first, stream);
    722     }
    723 }
    724 
    725 /* Set the current source and line to the location given by frame
    726    FRAME, if possible.  When CENTER is true, adjust so the relevant
    727    line is in the center of the next 'list'.  */
    728 
    729 void
    730 set_current_sal_from_frame (struct frame_info *frame)
    731 {
    732   symtab_and_line sal = find_frame_sal (frame);
    733   if (sal.symtab != NULL)
    734     set_current_source_symtab_and_line (sal);
    735 }
    736 
    737 /* If ON, GDB will display disassembly of the next source line when
    738    execution of the program being debugged stops.
    739    If AUTO (which is the default), or there's no line info to determine
    740    the source line of the next instruction, display disassembly of next
    741    instruction instead.  */
    742 
    743 static enum auto_boolean disassemble_next_line;
    744 
    745 static void
    746 show_disassemble_next_line (struct ui_file *file, int from_tty,
    747 				 struct cmd_list_element *c,
    748 				 const char *value)
    749 {
    750   fprintf_filtered (file,
    751 		    _("Debugger's willingness to use "
    752 		      "disassemble-next-line is %s.\n"),
    753                     value);
    754 }
    755 
    756 /* Use TRY_CATCH to catch the exception from the gdb_disassembly
    757    because it will be broken by filter sometime.  */
    758 
    759 static void
    760 do_gdb_disassembly (struct gdbarch *gdbarch,
    761 		    int how_many, CORE_ADDR low, CORE_ADDR high)
    762 {
    763 
    764   TRY
    765     {
    766       gdb_disassembly (gdbarch, current_uiout,
    767 		       DISASSEMBLY_RAW_INSN, how_many,
    768 		       low, high);
    769     }
    770   CATCH (exception, RETURN_MASK_ERROR)
    771     {
    772       /* If an exception was thrown while doing the disassembly, print
    773 	 the error message, to give the user a clue of what happened.  */
    774       exception_print (gdb_stderr, exception);
    775     }
    776   END_CATCH
    777 }
    778 
    779 /* Print information about frame FRAME.  The output is format according
    780    to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS.  The meaning of
    781    PRINT_WHAT is:
    782 
    783    SRC_LINE: Print only source line.
    784    LOCATION: Print only location.
    785    SRC_AND_LOC: Print location and source line.
    786 
    787    Used in "where" output, and to emit breakpoint or step
    788    messages.  */
    789 
    790 void
    791 print_frame_info (struct frame_info *frame, int print_level,
    792 		  enum print_what print_what, int print_args,
    793 		  int set_current_sal)
    794 {
    795   struct gdbarch *gdbarch = get_frame_arch (frame);
    796   int source_print;
    797   int location_print;
    798   struct ui_out *uiout = current_uiout;
    799 
    800   if (get_frame_type (frame) == DUMMY_FRAME
    801       || get_frame_type (frame) == SIGTRAMP_FRAME
    802       || get_frame_type (frame) == ARCH_FRAME)
    803     {
    804       ui_out_emit_tuple tuple_emitter (uiout, "frame");
    805 
    806       annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
    807 			    gdbarch, get_frame_pc (frame));
    808 
    809       /* Do this regardless of SOURCE because we don't have any source
    810          to list for this frame.  */
    811       if (print_level)
    812         {
    813           uiout->text ("#");
    814           uiout->field_fmt_int (2, ui_left, "level",
    815 				frame_relative_level (frame));
    816         }
    817       if (uiout->is_mi_like_p ())
    818         {
    819           annotate_frame_address ();
    820           uiout->field_core_addr ("addr",
    821 				  gdbarch, get_frame_pc (frame));
    822           annotate_frame_address_end ();
    823         }
    824 
    825       if (get_frame_type (frame) == DUMMY_FRAME)
    826         {
    827           annotate_function_call ();
    828           uiout->field_string ("func", "<function called from gdb>",
    829 			       ui_out_style_kind::FUNCTION);
    830 	}
    831       else if (get_frame_type (frame) == SIGTRAMP_FRAME)
    832         {
    833 	  annotate_signal_handler_caller ();
    834           uiout->field_string ("func", "<signal handler called>",
    835 			       ui_out_style_kind::FUNCTION);
    836         }
    837       else if (get_frame_type (frame) == ARCH_FRAME)
    838         {
    839           uiout->field_string ("func", "<cross-architecture call>",
    840 			       ui_out_style_kind::FUNCTION);
    841 	}
    842       uiout->text ("\n");
    843       annotate_frame_end ();
    844 
    845       /* If disassemble-next-line is set to auto or on output the next
    846 	 instruction.  */
    847       if (disassemble_next_line == AUTO_BOOLEAN_AUTO
    848 	  || disassemble_next_line == AUTO_BOOLEAN_TRUE)
    849 	do_gdb_disassembly (get_frame_arch (frame), 1,
    850 			    get_frame_pc (frame), get_frame_pc (frame) + 1);
    851 
    852       return;
    853     }
    854 
    855   /* If FRAME is not the innermost frame, that normally means that
    856      FRAME->pc points to *after* the call instruction, and we want to
    857      get the line containing the call, never the next line.  But if
    858      the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
    859      next frame was not entered as the result of a call, and we want
    860      to get the line containing FRAME->pc.  */
    861   symtab_and_line sal = find_frame_sal (frame);
    862 
    863   location_print = (print_what == LOCATION
    864 		    || print_what == LOC_AND_ADDRESS
    865 		    || print_what == SRC_AND_LOC);
    866 
    867   if (location_print || !sal.symtab)
    868     print_frame (frame, print_level, print_what, print_args, sal);
    869 
    870   source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
    871 
    872   /* If disassemble-next-line is set to auto or on and doesn't have
    873      the line debug messages for $pc, output the next instruction.  */
    874   if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
    875        || disassemble_next_line == AUTO_BOOLEAN_TRUE)
    876       && source_print && !sal.symtab)
    877     do_gdb_disassembly (get_frame_arch (frame), 1,
    878 			get_frame_pc (frame), get_frame_pc (frame) + 1);
    879 
    880   if (source_print && sal.symtab)
    881     {
    882       int done = 0;
    883       int mid_statement = ((print_what == SRC_LINE)
    884 			   && frame_show_address (frame, sal));
    885 
    886       if (annotation_level)
    887 	done = identify_source_line (sal.symtab, sal.line, mid_statement,
    888 				     get_frame_pc (frame));
    889       if (!done)
    890 	{
    891 	  if (deprecated_print_frame_info_listing_hook)
    892 	    deprecated_print_frame_info_listing_hook (sal.symtab,
    893 						      sal.line,
    894 						      sal.line + 1, 0);
    895 	  else
    896 	    {
    897 	      struct value_print_options opts;
    898 
    899 	      get_user_print_options (&opts);
    900 	      /* We used to do this earlier, but that is clearly
    901 		 wrong.  This function is used by many different
    902 		 parts of gdb, including normal_stop in infrun.c,
    903 		 which uses this to print out the current PC
    904 		 when we stepi/nexti into the middle of a source
    905 		 line.  Only the command line really wants this
    906 		 behavior.  Other UIs probably would like the
    907 		 ability to decide for themselves if it is desired.  */
    908 	      if (opts.addressprint && mid_statement)
    909 		{
    910 		  uiout->field_core_addr ("addr",
    911 					  gdbarch, get_frame_pc (frame));
    912 		  uiout->text ("\t");
    913 		}
    914 
    915 	      print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
    916 	    }
    917 	}
    918 
    919       /* If disassemble-next-line is set to on and there is line debug
    920          messages, output assembly codes for next line.  */
    921       if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
    922 	do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
    923     }
    924 
    925   if (set_current_sal)
    926     {
    927       CORE_ADDR pc;
    928 
    929       if (get_frame_pc_if_available (frame, &pc))
    930 	set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
    931       else
    932 	set_last_displayed_sal (0, 0, 0, 0, 0);
    933     }
    934 
    935   annotate_frame_end ();
    936 
    937   gdb_flush (gdb_stdout);
    938 }
    939 
    940 /* Remember the last symtab and line we displayed, which we use e.g.
    941  * as the place to put a breakpoint when the `break' command is
    942  * invoked with no arguments.  */
    943 
    944 static void
    945 set_last_displayed_sal (int valid, struct program_space *pspace,
    946 			CORE_ADDR addr, struct symtab *symtab,
    947 			int line)
    948 {
    949   last_displayed_sal_valid = valid;
    950   last_displayed_pspace = pspace;
    951   last_displayed_addr = addr;
    952   last_displayed_symtab = symtab;
    953   last_displayed_line = line;
    954   if (valid && pspace == NULL)
    955     {
    956       clear_last_displayed_sal ();
    957       internal_error (__FILE__, __LINE__,
    958 		      _("Trying to set NULL pspace."));
    959     }
    960 }
    961 
    962 /* Forget the last sal we displayed.  */
    963 
    964 void
    965 clear_last_displayed_sal (void)
    966 {
    967   last_displayed_sal_valid = 0;
    968   last_displayed_pspace = 0;
    969   last_displayed_addr = 0;
    970   last_displayed_symtab = 0;
    971   last_displayed_line = 0;
    972 }
    973 
    974 /* Is our record of the last sal we displayed valid?  If not,
    975  * the get_last_displayed_* functions will return NULL or 0, as
    976  * appropriate.  */
    977 
    978 int
    979 last_displayed_sal_is_valid (void)
    980 {
    981   return last_displayed_sal_valid;
    982 }
    983 
    984 /* Get the pspace of the last sal we displayed, if it's valid.  */
    985 
    986 struct program_space *
    987 get_last_displayed_pspace (void)
    988 {
    989   if (last_displayed_sal_valid)
    990     return last_displayed_pspace;
    991   return 0;
    992 }
    993 
    994 /* Get the address of the last sal we displayed, if it's valid.  */
    995 
    996 CORE_ADDR
    997 get_last_displayed_addr (void)
    998 {
    999   if (last_displayed_sal_valid)
   1000     return last_displayed_addr;
   1001   return 0;
   1002 }
   1003 
   1004 /* Get the symtab of the last sal we displayed, if it's valid.  */
   1005 
   1006 struct symtab*
   1007 get_last_displayed_symtab (void)
   1008 {
   1009   if (last_displayed_sal_valid)
   1010     return last_displayed_symtab;
   1011   return 0;
   1012 }
   1013 
   1014 /* Get the line of the last sal we displayed, if it's valid.  */
   1015 
   1016 int
   1017 get_last_displayed_line (void)
   1018 {
   1019   if (last_displayed_sal_valid)
   1020     return last_displayed_line;
   1021   return 0;
   1022 }
   1023 
   1024 /* Get the last sal we displayed, if it's valid.  */
   1025 
   1026 symtab_and_line
   1027 get_last_displayed_sal ()
   1028 {
   1029   symtab_and_line sal;
   1030 
   1031   if (last_displayed_sal_valid)
   1032     {
   1033       sal.pspace = last_displayed_pspace;
   1034       sal.pc = last_displayed_addr;
   1035       sal.symtab = last_displayed_symtab;
   1036       sal.line = last_displayed_line;
   1037     }
   1038 
   1039   return sal;
   1040 }
   1041 
   1042 
   1043 /* Attempt to obtain the name, FUNLANG and optionally FUNCP of the function
   1044    corresponding to FRAME.  */
   1045 
   1046 gdb::unique_xmalloc_ptr<char>
   1047 find_frame_funname (struct frame_info *frame, enum language *funlang,
   1048 		    struct symbol **funcp)
   1049 {
   1050   struct symbol *func;
   1051   gdb::unique_xmalloc_ptr<char> funname;
   1052 
   1053   *funlang = language_unknown;
   1054   if (funcp)
   1055     *funcp = NULL;
   1056 
   1057   func = get_frame_function (frame);
   1058   if (func)
   1059     {
   1060       /* In certain pathological cases, the symtabs give the wrong
   1061          function (when we are in the first function in a file which
   1062          is compiled without debugging symbols, the previous function
   1063          is compiled with debugging symbols, and the "foo.o" symbol
   1064          that is supposed to tell us where the file with debugging
   1065          symbols ends has been truncated by ar because it is longer
   1066          than 15 characters).  This also occurs if the user uses asm()
   1067          to create a function but not stabs for it (in a file compiled
   1068          with -g).
   1069 
   1070          So look in the minimal symbol tables as well, and if it comes
   1071          up with a larger address for the function use that instead.
   1072          I don't think this can ever cause any problems; there
   1073          shouldn't be any minimal symbols in the middle of a function;
   1074          if this is ever changed many parts of GDB will need to be
   1075          changed (and we'll create a find_pc_minimal_function or some
   1076          such).  */
   1077 
   1078       struct bound_minimal_symbol msymbol;
   1079 
   1080       /* Don't attempt to do this for inlined functions, which do not
   1081 	 have a corresponding minimal symbol.  */
   1082       if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
   1083 	msymbol
   1084 	  = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
   1085       else
   1086 	memset (&msymbol, 0, sizeof (msymbol));
   1087 
   1088       if (msymbol.minsym != NULL
   1089 	  && (BMSYMBOL_VALUE_ADDRESS (msymbol)
   1090 	      > BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (func))))
   1091 	{
   1092 	  /* We also don't know anything about the function besides
   1093 	     its address and name.  */
   1094 	  func = 0;
   1095 	  funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)));
   1096 	  *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
   1097 	}
   1098       else
   1099 	{
   1100 	  const char *print_name = SYMBOL_PRINT_NAME (func);
   1101 
   1102 	  *funlang = SYMBOL_LANGUAGE (func);
   1103 	  if (funcp)
   1104 	    *funcp = func;
   1105 	  if (*funlang == language_cplus)
   1106 	    {
   1107 	      /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
   1108 		 to display the demangled name that we already have
   1109 		 stored in the symbol table, but we stored a version
   1110 		 with DMGL_PARAMS turned on, and here we don't want to
   1111 		 display parameters.  So remove the parameters.  */
   1112 	      funname = cp_remove_params (print_name);
   1113 	    }
   1114 
   1115 	  /* If we didn't hit the C++ case above, set *funname
   1116 	     here.  */
   1117 	  if (funname == NULL)
   1118 	    funname.reset (xstrdup (print_name));
   1119 	}
   1120     }
   1121   else
   1122     {
   1123       struct bound_minimal_symbol msymbol;
   1124       CORE_ADDR pc;
   1125 
   1126       if (!get_frame_address_in_block_if_available (frame, &pc))
   1127 	return funname;
   1128 
   1129       msymbol = lookup_minimal_symbol_by_pc (pc);
   1130       if (msymbol.minsym != NULL)
   1131 	{
   1132 	  funname.reset (xstrdup (MSYMBOL_PRINT_NAME (msymbol.minsym)));
   1133 	  *funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
   1134 	}
   1135     }
   1136 
   1137   return funname;
   1138 }
   1139 
   1140 static void
   1141 print_frame (struct frame_info *frame, int print_level,
   1142 	     enum print_what print_what, int print_args,
   1143 	     struct symtab_and_line sal)
   1144 {
   1145   struct gdbarch *gdbarch = get_frame_arch (frame);
   1146   struct ui_out *uiout = current_uiout;
   1147   enum language funlang = language_unknown;
   1148   struct value_print_options opts;
   1149   struct symbol *func;
   1150   CORE_ADDR pc = 0;
   1151   int pc_p;
   1152 
   1153   pc_p = get_frame_pc_if_available (frame, &pc);
   1154 
   1155   gdb::unique_xmalloc_ptr<char> funname
   1156     = find_frame_funname (frame, &funlang, &func);
   1157 
   1158   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
   1159 			gdbarch, pc);
   1160 
   1161   {
   1162     ui_out_emit_tuple tuple_emitter (uiout, "frame");
   1163 
   1164     if (print_level)
   1165       {
   1166 	uiout->text ("#");
   1167 	uiout->field_fmt_int (2, ui_left, "level",
   1168 			      frame_relative_level (frame));
   1169       }
   1170     get_user_print_options (&opts);
   1171     if (opts.addressprint)
   1172       if (!sal.symtab
   1173 	  || frame_show_address (frame, sal)
   1174 	  || print_what == LOC_AND_ADDRESS)
   1175 	{
   1176 	  annotate_frame_address ();
   1177 	  if (pc_p)
   1178 	    uiout->field_core_addr ("addr", gdbarch, pc);
   1179 	  else
   1180 	    uiout->field_string ("addr", "<unavailable>",
   1181 				 ui_out_style_kind::ADDRESS);
   1182 	  annotate_frame_address_end ();
   1183 	  uiout->text (" in ");
   1184 	}
   1185     annotate_frame_function_name ();
   1186 
   1187     string_file stb;
   1188     fprintf_symbol_filtered (&stb, funname ? funname.get () : "??",
   1189 			     funlang, DMGL_ANSI);
   1190     uiout->field_stream ("func", stb, ui_out_style_kind::FUNCTION);
   1191     uiout->wrap_hint ("   ");
   1192     annotate_frame_args ();
   1193 
   1194     uiout->text (" (");
   1195     if (print_args)
   1196       {
   1197 	int numargs;
   1198 
   1199 	if (gdbarch_frame_num_args_p (gdbarch))
   1200 	  {
   1201 	    numargs = gdbarch_frame_num_args (gdbarch, frame);
   1202 	    gdb_assert (numargs >= 0);
   1203 	  }
   1204 	else
   1205 	  numargs = -1;
   1206 
   1207 	{
   1208 	  ui_out_emit_list list_emitter (uiout, "args");
   1209 	  TRY
   1210 	    {
   1211 	      print_frame_args (func, frame, numargs, gdb_stdout);
   1212 	    }
   1213 	  CATCH (e, RETURN_MASK_ERROR)
   1214 	    {
   1215 	    }
   1216 	  END_CATCH
   1217 
   1218 	    /* FIXME: ARGS must be a list.  If one argument is a string it
   1219 	       will have " that will not be properly escaped.  */
   1220 	    }
   1221 	QUIT;
   1222       }
   1223     uiout->text (")");
   1224     if (sal.symtab)
   1225       {
   1226 	const char *filename_display;
   1227 
   1228 	filename_display = symtab_to_filename_for_display (sal.symtab);
   1229 	annotate_frame_source_begin ();
   1230 	uiout->wrap_hint ("   ");
   1231 	uiout->text (" at ");
   1232 	annotate_frame_source_file ();
   1233 	uiout->field_string ("file", filename_display, ui_out_style_kind::FILE);
   1234 	if (uiout->is_mi_like_p ())
   1235 	  {
   1236 	    const char *fullname = symtab_to_fullname (sal.symtab);
   1237 
   1238 	    uiout->field_string ("fullname", fullname);
   1239 	  }
   1240 	annotate_frame_source_file_end ();
   1241 	uiout->text (":");
   1242 	annotate_frame_source_line ();
   1243 	uiout->field_int ("line", sal.line);
   1244 	annotate_frame_source_end ();
   1245       }
   1246 
   1247     if (pc_p && (funname == NULL || sal.symtab == NULL))
   1248       {
   1249 	char *lib = solib_name_from_address (get_frame_program_space (frame),
   1250 					     get_frame_pc (frame));
   1251 
   1252 	if (lib)
   1253 	  {
   1254 	    annotate_frame_where ();
   1255 	    uiout->wrap_hint ("  ");
   1256 	    uiout->text (" from ");
   1257 	    uiout->field_string ("from", lib);
   1258 	  }
   1259       }
   1260     if (uiout->is_mi_like_p ())
   1261       uiout->field_string ("arch",
   1262 			   (gdbarch_bfd_arch_info (gdbarch))->printable_name);
   1263   }
   1264 
   1265   uiout->text ("\n");
   1266 }
   1267 
   1268 
   1270 /* Completion function for "frame function", "info frame function", and
   1271    "select-frame function" commands.  */
   1272 
   1273 void
   1274 frame_selection_by_function_completer (struct cmd_list_element *ignore,
   1275 				       completion_tracker &tracker,
   1276 				       const char *text, const char *word)
   1277 {
   1278   /* This is used to complete function names within a stack.  It would be
   1279      nice if we only offered functions that were actually in the stack.
   1280      However, this would mean unwinding the stack to completion, which
   1281      could take too long, or on a corrupted stack, possibly not end.
   1282      Instead, we offer all symbol names as a safer choice.  */
   1283   collect_symbol_completion_matches (tracker,
   1284 				     complete_symbol_mode::EXPRESSION,
   1285 				     symbol_name_match_type::EXPRESSION,
   1286 				     text, word);
   1287 }
   1288 
   1289 /* Core of all the "info frame" sub-commands.  Print information about a
   1290    frame FI.  If SELECTED_FRAME_P is true then the user didn't provide a
   1291    frame specification, they just entered 'info frame'.  If the user did
   1292    provide a frame specification (for example 'info frame 0', 'info frame
   1293    level 1') then SELECTED_FRAME_P will be false.  */
   1294 
   1295 static void
   1296 info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
   1297 {
   1298   struct symbol *func;
   1299   struct symtab *s;
   1300   struct frame_info *calling_frame_info;
   1301   int numregs;
   1302   const char *funname = 0;
   1303   enum language funlang = language_unknown;
   1304   const char *pc_regname;
   1305   struct gdbarch *gdbarch;
   1306   CORE_ADDR frame_pc;
   1307   int frame_pc_p;
   1308   /* Initialize it to avoid "may be used uninitialized" warning.  */
   1309   CORE_ADDR caller_pc = 0;
   1310   int caller_pc_p = 0;
   1311 
   1312   gdbarch = get_frame_arch (fi);
   1313 
   1314   /* Name of the value returned by get_frame_pc().  Per comments, "pc"
   1315      is not a good name.  */
   1316   if (gdbarch_pc_regnum (gdbarch) >= 0)
   1317     /* OK, this is weird.  The gdbarch_pc_regnum hardware register's value can
   1318        easily not match that of the internal value returned by
   1319        get_frame_pc().  */
   1320     pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
   1321   else
   1322     /* But then, this is weird to.  Even without gdbarch_pc_regnum, an
   1323        architectures will often have a hardware register called "pc",
   1324        and that register's value, again, can easily not match
   1325        get_frame_pc().  */
   1326     pc_regname = "pc";
   1327 
   1328   frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
   1329   func = get_frame_function (fi);
   1330   symtab_and_line sal = find_frame_sal (fi);
   1331   s = sal.symtab;
   1332   gdb::unique_xmalloc_ptr<char> func_only;
   1333   if (func)
   1334     {
   1335       funname = SYMBOL_PRINT_NAME (func);
   1336       funlang = SYMBOL_LANGUAGE (func);
   1337       if (funlang == language_cplus)
   1338 	{
   1339 	  /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
   1340 	     to display the demangled name that we already have
   1341 	     stored in the symbol table, but we stored a version
   1342 	     with DMGL_PARAMS turned on, and here we don't want to
   1343 	     display parameters.  So remove the parameters.  */
   1344 	  func_only = cp_remove_params (funname);
   1345 
   1346 	  if (func_only)
   1347 	    funname = func_only.get ();
   1348 	}
   1349     }
   1350   else if (frame_pc_p)
   1351     {
   1352       struct bound_minimal_symbol msymbol;
   1353 
   1354       msymbol = lookup_minimal_symbol_by_pc (frame_pc);
   1355       if (msymbol.minsym != NULL)
   1356 	{
   1357 	  funname = MSYMBOL_PRINT_NAME (msymbol.minsym);
   1358 	  funlang = MSYMBOL_LANGUAGE (msymbol.minsym);
   1359 	}
   1360     }
   1361   calling_frame_info = get_prev_frame (fi);
   1362 
   1363   if (selected_frame_p && frame_relative_level (fi) >= 0)
   1364     {
   1365       printf_filtered (_("Stack level %d, frame at "),
   1366 		       frame_relative_level (fi));
   1367     }
   1368   else
   1369     {
   1370       printf_filtered (_("Stack frame at "));
   1371     }
   1372   fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
   1373   printf_filtered (":\n");
   1374   printf_filtered (" %s = ", pc_regname);
   1375   if (frame_pc_p)
   1376     fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
   1377   else
   1378     fputs_filtered ("<unavailable>", gdb_stdout);
   1379 
   1380   wrap_here ("   ");
   1381   if (funname)
   1382     {
   1383       printf_filtered (" in ");
   1384       fprintf_symbol_filtered (gdb_stdout, funname, funlang,
   1385 			       DMGL_ANSI | DMGL_PARAMS);
   1386     }
   1387   wrap_here ("   ");
   1388   if (sal.symtab)
   1389     printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal.symtab),
   1390 		     sal.line);
   1391   puts_filtered ("; ");
   1392   wrap_here ("    ");
   1393   printf_filtered ("saved %s = ", pc_regname);
   1394 
   1395   if (!frame_id_p (frame_unwind_caller_id (fi)))
   1396     val_print_not_saved (gdb_stdout);
   1397   else
   1398     {
   1399       TRY
   1400 	{
   1401 	  caller_pc = frame_unwind_caller_pc (fi);
   1402 	  caller_pc_p = 1;
   1403 	}
   1404       CATCH (ex, RETURN_MASK_ERROR)
   1405 	{
   1406 	  switch (ex.error)
   1407 	    {
   1408 	    case NOT_AVAILABLE_ERROR:
   1409 	      val_print_unavailable (gdb_stdout);
   1410 	      break;
   1411 	    case OPTIMIZED_OUT_ERROR:
   1412 	      val_print_not_saved (gdb_stdout);
   1413 	      break;
   1414 	    default:
   1415 	      fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
   1416 	      break;
   1417 	    }
   1418 	}
   1419       END_CATCH
   1420     }
   1421 
   1422   if (caller_pc_p)
   1423     fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
   1424   printf_filtered ("\n");
   1425 
   1426   if (calling_frame_info == NULL)
   1427     {
   1428       enum unwind_stop_reason reason;
   1429 
   1430       reason = get_frame_unwind_stop_reason (fi);
   1431       if (reason != UNWIND_NO_REASON)
   1432 	printf_filtered (_(" Outermost frame: %s\n"),
   1433 			 frame_stop_reason_string (fi));
   1434     }
   1435   else if (get_frame_type (fi) == TAILCALL_FRAME)
   1436     puts_filtered (" tail call frame");
   1437   else if (get_frame_type (fi) == INLINE_FRAME)
   1438     printf_filtered (" inlined into frame %d",
   1439 		     frame_relative_level (get_prev_frame (fi)));
   1440   else
   1441     {
   1442       printf_filtered (" called by frame at ");
   1443       fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
   1444 		      gdb_stdout);
   1445     }
   1446   if (get_next_frame (fi) && calling_frame_info)
   1447     puts_filtered (",");
   1448   wrap_here ("   ");
   1449   if (get_next_frame (fi))
   1450     {
   1451       printf_filtered (" caller of frame at ");
   1452       fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
   1453 		      gdb_stdout);
   1454     }
   1455   if (get_next_frame (fi) || calling_frame_info)
   1456     puts_filtered ("\n");
   1457 
   1458   if (s)
   1459     printf_filtered (" source language %s.\n",
   1460 		     language_str (s->language));
   1461 
   1462   {
   1463     /* Address of the argument list for this frame, or 0.  */
   1464     CORE_ADDR arg_list = get_frame_args_address (fi);
   1465     /* Number of args for this frame, or -1 if unknown.  */
   1466     int numargs;
   1467 
   1468     if (arg_list == 0)
   1469       printf_filtered (" Arglist at unknown address.\n");
   1470     else
   1471       {
   1472 	printf_filtered (" Arglist at ");
   1473 	fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
   1474 	printf_filtered (",");
   1475 
   1476 	if (!gdbarch_frame_num_args_p (gdbarch))
   1477 	  {
   1478 	    numargs = -1;
   1479 	    puts_filtered (" args: ");
   1480 	  }
   1481 	else
   1482 	  {
   1483 	    numargs = gdbarch_frame_num_args (gdbarch, fi);
   1484 	    gdb_assert (numargs >= 0);
   1485 	    if (numargs == 0)
   1486 	      puts_filtered (" no args.");
   1487 	    else if (numargs == 1)
   1488 	      puts_filtered (" 1 arg: ");
   1489 	    else
   1490 	      printf_filtered (" %d args: ", numargs);
   1491 	  }
   1492 	print_frame_args (func, fi, numargs, gdb_stdout);
   1493 	puts_filtered ("\n");
   1494       }
   1495   }
   1496   {
   1497     /* Address of the local variables for this frame, or 0.  */
   1498     CORE_ADDR arg_list = get_frame_locals_address (fi);
   1499 
   1500     if (arg_list == 0)
   1501       printf_filtered (" Locals at unknown address,");
   1502     else
   1503       {
   1504 	printf_filtered (" Locals at ");
   1505 	fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
   1506 	printf_filtered (",");
   1507       }
   1508   }
   1509 
   1510   /* Print as much information as possible on the location of all the
   1511      registers.  */
   1512   {
   1513     int count;
   1514     int i;
   1515     int need_nl = 1;
   1516     int sp_regnum = gdbarch_sp_regnum (gdbarch);
   1517 
   1518     /* The sp is special; what's displayed isn't the save address, but
   1519        the value of the previous frame's sp.  This is a legacy thing,
   1520        at one stage the frame cached the previous frame's SP instead
   1521        of its address, hence it was easiest to just display the cached
   1522        value.  */
   1523     if (sp_regnum >= 0)
   1524       {
   1525 	struct value *value = frame_unwind_register_value (fi, sp_regnum);
   1526 	gdb_assert (value != NULL);
   1527 
   1528 	if (!value_optimized_out (value) && value_entirely_available (value))
   1529 	  {
   1530 	    if (VALUE_LVAL (value) == not_lval)
   1531 	      {
   1532 		CORE_ADDR sp;
   1533 		enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   1534 		int sp_size = register_size (gdbarch, sp_regnum);
   1535 
   1536 		sp = extract_unsigned_integer (value_contents_all (value),
   1537 					       sp_size, byte_order);
   1538 
   1539 		printf_filtered (" Previous frame's sp is ");
   1540 		fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
   1541 		printf_filtered ("\n");
   1542 	      }
   1543 	    else if (VALUE_LVAL (value) == lval_memory)
   1544 	      {
   1545 		printf_filtered (" Previous frame's sp at ");
   1546 		fputs_filtered (paddress (gdbarch, value_address (value)),
   1547 				gdb_stdout);
   1548 		printf_filtered ("\n");
   1549 	      }
   1550 	    else if (VALUE_LVAL (value) == lval_register)
   1551 	      {
   1552 		printf_filtered (" Previous frame's sp in %s\n",
   1553 				 gdbarch_register_name (gdbarch,
   1554 							VALUE_REGNUM (value)));
   1555 	      }
   1556 
   1557 	    release_value (value);
   1558 	    need_nl = 0;
   1559 	  }
   1560 	/* else keep quiet.  */
   1561       }
   1562 
   1563     count = 0;
   1564     numregs = gdbarch_num_cooked_regs (gdbarch);
   1565     for (i = 0; i < numregs; i++)
   1566       if (i != sp_regnum
   1567 	  && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
   1568 	{
   1569 	  enum lval_type lval;
   1570 	  int optimized;
   1571 	  int unavailable;
   1572 	  CORE_ADDR addr;
   1573 	  int realnum;
   1574 
   1575 	  /* Find out the location of the saved register without
   1576              fetching the corresponding value.  */
   1577 	  frame_register_unwind (fi, i, &optimized, &unavailable,
   1578 				 &lval, &addr, &realnum, NULL);
   1579 	  /* For moment, only display registers that were saved on the
   1580 	     stack.  */
   1581 	  if (!optimized && !unavailable && lval == lval_memory)
   1582 	    {
   1583 	      if (count == 0)
   1584 		puts_filtered (" Saved registers:\n ");
   1585 	      else
   1586 		puts_filtered (",");
   1587 	      wrap_here (" ");
   1588 	      printf_filtered (" %s at ",
   1589 			       gdbarch_register_name (gdbarch, i));
   1590 	      fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
   1591 	      count++;
   1592 	    }
   1593 	}
   1594     if (count || need_nl)
   1595       puts_filtered ("\n");
   1596   }
   1597 }
   1598 
   1599 /* Return the innermost frame at level LEVEL.  */
   1600 
   1601 static struct frame_info *
   1602 leading_innermost_frame (int level)
   1603 {
   1604   struct frame_info *leading;
   1605 
   1606   leading = get_current_frame ();
   1607 
   1608   gdb_assert (level >= 0);
   1609 
   1610   while (leading != nullptr && level)
   1611     {
   1612       QUIT;
   1613       leading = get_prev_frame (leading);
   1614       level--;
   1615     }
   1616 
   1617   return leading;
   1618 }
   1619 
   1620 /* Return the starting frame needed to handle COUNT outermost frames.  */
   1621 
   1622 static struct frame_info *
   1623 trailing_outermost_frame (int count)
   1624 {
   1625   struct frame_info *current;
   1626   struct frame_info *trailing;
   1627 
   1628   trailing = get_current_frame ();
   1629 
   1630   gdb_assert (count > 0);
   1631 
   1632   current = trailing;
   1633   while (current != nullptr && count--)
   1634     {
   1635       QUIT;
   1636       current = get_prev_frame (current);
   1637     }
   1638 
   1639   /* Will stop when CURRENT reaches the top of the stack.
   1640      TRAILING will be COUNT below it.  */
   1641   while (current != nullptr)
   1642     {
   1643       QUIT;
   1644       trailing = get_prev_frame (trailing);
   1645       current = get_prev_frame (current);
   1646     }
   1647 
   1648   return trailing;
   1649 }
   1650 
   1651 /* The core of all the "select-frame" sub-commands.  Just wraps a call to
   1652    SELECT_FRAME.  */
   1653 
   1654 static void
   1655 select_frame_command_core (struct frame_info *fi, bool ignored)
   1656 {
   1657   struct frame_info *prev_frame = get_selected_frame_if_set ();
   1658   select_frame (fi);
   1659   if (get_selected_frame_if_set () != prev_frame)
   1660     gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
   1661 }
   1662 
   1663 /* See stack.h.  */
   1664 
   1665 void
   1666 select_frame_for_mi (struct frame_info *fi)
   1667 {
   1668   select_frame_command_core (fi, FALSE /* Ignored.  */);
   1669 }
   1670 
   1671 /* The core of all the "frame" sub-commands.  Select frame FI, and if this
   1672    means we change frame send out a change notification (otherwise, just
   1673    reprint the current frame summary).   */
   1674 
   1675 static void
   1676 frame_command_core (struct frame_info *fi, bool ignored)
   1677 {
   1678   struct frame_info *prev_frame = get_selected_frame_if_set ();
   1679 
   1680   select_frame (fi);
   1681   if (get_selected_frame_if_set () != prev_frame)
   1682     gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
   1683   else
   1684     print_selected_thread_frame (current_uiout, USER_SELECTED_FRAME);
   1685 }
   1686 
   1687 /* The three commands 'frame', 'select-frame', and 'info frame' all have a
   1688    common set of sub-commands that allow a specific frame to be selected.
   1689    All of the sub-command functions are static methods within this class
   1690    template which is then instantiated below.  The template parameter is a
   1691    callback used to implement the functionality of the base command
   1692    ('frame', 'select-frame', or 'info frame').
   1693 
   1694    In the template parameter FI is the frame being selected.  The
   1695    SELECTED_FRAME_P flag is true if the frame being selected was done by
   1696    default, which happens when the user uses the base command with no
   1697    arguments.  For example the commands 'info frame', 'select-frame',
   1698    'frame' will all cause SELECTED_FRAME_P to be true.  In all other cases
   1699    SELECTED_FRAME_P is false.  */
   1700 
   1701 template <void (*FPTR) (struct frame_info *fi, bool selected_frame_p)>
   1702 class frame_command_helper
   1703 {
   1704 public:
   1705 
   1706   /* The "frame level" family of commands.  The ARG is an integer that is
   1707      the frame's level in the stack.  */
   1708   static void
   1709   level (const char *arg, int from_tty)
   1710   {
   1711     int level = value_as_long (parse_and_eval (arg));
   1712     struct frame_info *fid
   1713       = find_relative_frame (get_current_frame (), &level);
   1714     if (level != 0)
   1715       error (_("No frame at level %s."), arg);
   1716     FPTR (fid, false);
   1717   }
   1718 
   1719   /* The "frame address" family of commands.  ARG is a stack-pointer
   1720      address for an existing frame.  This command does not allow new
   1721      frames to be created.  */
   1722 
   1723   static void
   1724   address (const char *arg, int from_tty)
   1725   {
   1726     CORE_ADDR addr = value_as_address (parse_and_eval (arg));
   1727     struct frame_info *fid = find_frame_for_address (addr);
   1728     if (fid == NULL)
   1729       error (_("No frame at address %s."), arg);
   1730     FPTR (fid, false);
   1731   }
   1732 
   1733   /* The "frame view" family of commands.  ARG is one or two addresses and
   1734      is used to view a frame that might be outside the current backtrace.
   1735      The addresses are stack-pointer address, and (optional) pc-address.  */
   1736 
   1737   static void
   1738   view (const char *args, int from_tty)
   1739   {
   1740     struct frame_info *fid;
   1741 
   1742     if (args == NULL)
   1743     error (_("Missing address argument to view a frame"));
   1744 
   1745     gdb_argv argv (args);
   1746 
   1747     if (argv.count () == 2)
   1748       {
   1749 	CORE_ADDR addr[2];
   1750 
   1751 	addr [0] = value_as_address (parse_and_eval (argv[0]));
   1752 	addr [1] = value_as_address (parse_and_eval (argv[1]));
   1753 	fid = create_new_frame (addr[0], addr[1]);
   1754       }
   1755     else
   1756       {
   1757 	CORE_ADDR addr = value_as_address (parse_and_eval (argv[0]));
   1758 	fid = create_new_frame (addr, false);
   1759       }
   1760     FPTR (fid, false);
   1761   }
   1762 
   1763   /* The "frame function" family of commands.  ARG is the name of a
   1764      function within the stack, the first function (searching from frame
   1765      0) with that name will be selected.  */
   1766 
   1767   static void
   1768   function (const char *arg, int from_tty)
   1769   {
   1770     if (arg == NULL)
   1771       error (_("Missing function name argument"));
   1772     struct frame_info *fid = find_frame_for_function (arg);
   1773     if (fid == NULL)
   1774       error (_("No frame for function \"%s\"."), arg);
   1775     FPTR (fid, false);
   1776   }
   1777 
   1778   /* The "frame" base command, that is, when no sub-command is specified.
   1779      If one argument is provided then we assume that this is a frame's
   1780      level as historically, this was the supported command syntax that was
   1781      used most often.
   1782 
   1783      If no argument is provided, then the current frame is selected.  */
   1784 
   1785   static void
   1786   base_command (const char *arg, int from_tty)
   1787   {
   1788     if (arg == NULL)
   1789       FPTR (get_selected_frame (_("No stack.")), true);
   1790     else
   1791       level (arg, from_tty);
   1792   }
   1793 };
   1794 
   1795 /* Instantiate three FRAME_COMMAND_HELPER instances to implement the
   1796    sub-commands for 'info frame', 'frame', and 'select-frame' commands.  */
   1797 
   1798 static frame_command_helper <info_frame_command_core> info_frame_cmd;
   1799 static frame_command_helper <frame_command_core> frame_cmd;
   1800 static frame_command_helper <select_frame_command_core> select_frame_cmd;
   1801 
   1802 /* Print briefly all stack frames or just the innermost COUNT_EXP
   1803    frames.  */
   1804 
   1805 static void
   1806 backtrace_command_1 (const char *count_exp, frame_filter_flags flags,
   1807 		     int no_filters, int from_tty)
   1808 {
   1809   struct frame_info *fi;
   1810   int count;
   1811   int py_start = 0, py_end = 0;
   1812   enum ext_lang_bt_status result = EXT_LANG_BT_ERROR;
   1813 
   1814   if (!target_has_stack)
   1815     error (_("No stack."));
   1816 
   1817   if (count_exp)
   1818     {
   1819       count = parse_and_eval_long (count_exp);
   1820       if (count < 0)
   1821 	py_start = count;
   1822       else
   1823 	{
   1824 	  py_start = 0;
   1825 	  /* The argument to apply_ext_lang_frame_filter is the number
   1826 	     of the final frame to print, and frames start at 0.  */
   1827 	  py_end = count - 1;
   1828 	}
   1829     }
   1830   else
   1831     {
   1832       py_end = -1;
   1833       count = -1;
   1834     }
   1835 
   1836   if (! no_filters)
   1837     {
   1838       enum ext_lang_frame_args arg_type;
   1839 
   1840       flags |= PRINT_LEVEL | PRINT_FRAME_INFO | PRINT_ARGS;
   1841       if (from_tty)
   1842 	flags |= PRINT_MORE_FRAMES;
   1843 
   1844       if (!strcmp (print_frame_arguments, "scalars"))
   1845 	arg_type = CLI_SCALAR_VALUES;
   1846       else if (!strcmp (print_frame_arguments, "all"))
   1847 	arg_type = CLI_ALL_VALUES;
   1848       else
   1849 	arg_type = NO_VALUES;
   1850 
   1851       result = apply_ext_lang_frame_filter (get_current_frame (), flags,
   1852 					    arg_type, current_uiout,
   1853 					    py_start, py_end);
   1854     }
   1855 
   1856   /* Run the inbuilt backtrace if there are no filters registered, or
   1857      "no-filters" has been specified from the command.  */
   1858   if (no_filters ||  result == EXT_LANG_BT_NO_FILTERS)
   1859     {
   1860       struct frame_info *trailing;
   1861 
   1862       /* The following code must do two things.  First, it must set the
   1863 	 variable TRAILING to the frame from which we should start
   1864 	 printing.  Second, it must set the variable count to the number
   1865 	 of frames which we should print, or -1 if all of them.  */
   1866 
   1867       if (count_exp != NULL && count < 0)
   1868 	{
   1869 	  trailing = trailing_outermost_frame (-count);
   1870 	  count = -1;
   1871 	}
   1872       else
   1873 	trailing = get_current_frame ();
   1874 
   1875       for (fi = trailing; fi && count--; fi = get_prev_frame (fi))
   1876 	{
   1877 	  QUIT;
   1878 
   1879 	  /* Don't use print_stack_frame; if an error() occurs it probably
   1880 	     means further attempts to backtrace would fail (on the other
   1881 	     hand, perhaps the code does or could be fixed to make sure
   1882 	     the frame->prev field gets set to NULL in that case).  */
   1883 
   1884 	  print_frame_info (fi, 1, LOCATION, 1, 0);
   1885 	  if ((flags & PRINT_LOCALS) != 0)
   1886 	    {
   1887 	      struct frame_id frame_id = get_frame_id (fi);
   1888 
   1889 	      print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout);
   1890 
   1891 	      /* print_frame_local_vars invalidates FI.  */
   1892 	      fi = frame_find_by_id (frame_id);
   1893 	      if (fi == NULL)
   1894 		{
   1895 		  trailing = NULL;
   1896 		  warning (_("Unable to restore previously selected frame."));
   1897 		  break;
   1898 		}
   1899 	    }
   1900 
   1901 	  /* Save the last frame to check for error conditions.  */
   1902 	  trailing = fi;
   1903 	}
   1904 
   1905       /* If we've stopped before the end, mention that.  */
   1906       if (fi && from_tty)
   1907 	printf_filtered (_("(More stack frames follow...)\n"));
   1908 
   1909       /* If we've run out of frames, and the reason appears to be an error
   1910 	 condition, print it.  */
   1911       if (fi == NULL && trailing != NULL)
   1912 	{
   1913 	  enum unwind_stop_reason reason;
   1914 
   1915 	  reason = get_frame_unwind_stop_reason (trailing);
   1916 	  if (reason >= UNWIND_FIRST_ERROR)
   1917 	    printf_filtered (_("Backtrace stopped: %s\n"),
   1918 			     frame_stop_reason_string (trailing));
   1919 	}
   1920     }
   1921 }
   1922 
   1923 static void
   1924 backtrace_command (const char *arg, int from_tty)
   1925 {
   1926   bool filters = true;
   1927   frame_filter_flags flags = 0;
   1928 
   1929   if (arg)
   1930     {
   1931       bool done = false;
   1932 
   1933       while (!done)
   1934 	{
   1935 	  const char *save_arg = arg;
   1936 	  std::string this_arg = extract_arg (&arg);
   1937 
   1938 	  if (this_arg.empty ())
   1939 	    break;
   1940 
   1941 	  if (subset_compare (this_arg.c_str (), "no-filters"))
   1942 	    filters = false;
   1943 	  else if (subset_compare (this_arg.c_str (), "full"))
   1944 	    flags |= PRINT_LOCALS;
   1945 	  else if (subset_compare (this_arg.c_str (), "hide"))
   1946 	    flags |= PRINT_HIDE;
   1947 	  else
   1948 	    {
   1949 	      /* Not a recognized argument, so stop.  */
   1950 	      arg = save_arg;
   1951 	      done = true;
   1952 	    }
   1953 	}
   1954 
   1955       if (*arg == '\0')
   1956 	arg = NULL;
   1957     }
   1958 
   1959   backtrace_command_1 (arg, flags, !filters /* no frame-filters */, from_tty);
   1960 }
   1961 
   1962 /* Iterate over the local variables of a block B, calling CB with
   1963    CB_DATA.  */
   1964 
   1965 static void
   1966 iterate_over_block_locals (const struct block *b,
   1967 			   iterate_over_block_arg_local_vars_cb cb,
   1968 			   void *cb_data)
   1969 {
   1970   struct block_iterator iter;
   1971   struct symbol *sym;
   1972 
   1973   ALL_BLOCK_SYMBOLS (b, iter, sym)
   1974     {
   1975       switch (SYMBOL_CLASS (sym))
   1976 	{
   1977 	case LOC_LOCAL:
   1978 	case LOC_REGISTER:
   1979 	case LOC_STATIC:
   1980 	case LOC_COMPUTED:
   1981 	case LOC_OPTIMIZED_OUT:
   1982 	  if (SYMBOL_IS_ARGUMENT (sym))
   1983 	    break;
   1984 	  if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
   1985 	    break;
   1986 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
   1987 	  break;
   1988 
   1989 	default:
   1990 	  /* Ignore symbols which are not locals.  */
   1991 	  break;
   1992 	}
   1993     }
   1994 }
   1995 
   1996 
   1997 /* Same, but print labels.  */
   1998 
   1999 #if 0
   2000 /* Commented out, as the code using this function has also been
   2001    commented out.  FIXME:brobecker/2009-01-13: Find out why the code
   2002    was commented out in the first place.  The discussion introducing
   2003    this change (2007-12-04: Support lexical blocks and function bodies
   2004    that occupy non-contiguous address ranges) did not explain why
   2005    this change was made.  */
   2006 static int
   2007 print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
   2008 			  int *have_default, struct ui_file *stream)
   2009 {
   2010   struct block_iterator iter;
   2011   struct symbol *sym;
   2012   int values_printed = 0;
   2013 
   2014   ALL_BLOCK_SYMBOLS (b, iter, sym)
   2015     {
   2016       if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
   2017 	{
   2018 	  if (*have_default)
   2019 	    continue;
   2020 	  *have_default = 1;
   2021 	}
   2022       if (SYMBOL_CLASS (sym) == LOC_LABEL)
   2023 	{
   2024 	  struct symtab_and_line sal;
   2025 	  struct value_print_options opts;
   2026 
   2027 	  sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
   2028 	  values_printed = 1;
   2029 	  fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
   2030 	  get_user_print_options (&opts);
   2031 	  if (opts.addressprint)
   2032 	    {
   2033 	      fprintf_filtered (stream, " ");
   2034 	      fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
   2035 			      stream);
   2036 	    }
   2037 	  fprintf_filtered (stream, " in file %s, line %d\n",
   2038 			    sal.symtab->filename, sal.line);
   2039 	}
   2040     }
   2041 
   2042   return values_printed;
   2043 }
   2044 #endif
   2045 
   2046 /* Iterate over all the local variables in block B, including all its
   2047    superblocks, stopping when the top-level block is reached.  */
   2048 
   2049 void
   2050 iterate_over_block_local_vars (const struct block *block,
   2051 			       iterate_over_block_arg_local_vars_cb cb,
   2052 			       void *cb_data)
   2053 {
   2054   while (block)
   2055     {
   2056       iterate_over_block_locals (block, cb, cb_data);
   2057       /* After handling the function's top-level block, stop.  Don't
   2058 	 continue to its superblock, the block of per-file
   2059 	 symbols.  */
   2060       if (BLOCK_FUNCTION (block))
   2061 	break;
   2062       block = BLOCK_SUPERBLOCK (block);
   2063     }
   2064 }
   2065 
   2066 /* Data to be passed around in the calls to the locals and args
   2067    iterators.  */
   2068 
   2069 struct print_variable_and_value_data
   2070 {
   2071   gdb::optional<compiled_regex> preg;
   2072   gdb::optional<compiled_regex> treg;
   2073   struct frame_id frame_id;
   2074   int num_tabs;
   2075   struct ui_file *stream;
   2076   int values_printed;
   2077 };
   2078 
   2079 /* The callback for the locals and args iterators.  */
   2080 
   2081 static void
   2082 do_print_variable_and_value (const char *print_name,
   2083 			     struct symbol *sym,
   2084 			     void *cb_data)
   2085 {
   2086   struct print_variable_and_value_data *p
   2087     = (struct print_variable_and_value_data *) cb_data;
   2088   struct frame_info *frame;
   2089 
   2090   if (p->preg.has_value ()
   2091       && p->preg->exec (SYMBOL_NATURAL_NAME (sym), 0,
   2092 			NULL, 0) != 0)
   2093     return;
   2094   if (p->treg.has_value ()
   2095       && !treg_matches_sym_type_name (*p->treg, sym))
   2096     return;
   2097 
   2098   frame = frame_find_by_id (p->frame_id);
   2099   if (frame == NULL)
   2100     {
   2101       warning (_("Unable to restore previously selected frame."));
   2102       return;
   2103     }
   2104 
   2105   print_variable_and_value (print_name, sym, frame, p->stream, p->num_tabs);
   2106 
   2107   /* print_variable_and_value invalidates FRAME.  */
   2108   frame = NULL;
   2109 
   2110   p->values_printed = 1;
   2111 }
   2112 
   2113 /* Prepares the regular expression REG from REGEXP.
   2114    If REGEXP is NULL, it results in an empty regular expression.  */
   2115 
   2116 static void
   2117 prepare_reg (const char *regexp, gdb::optional<compiled_regex> *reg)
   2118 {
   2119   if (regexp != NULL)
   2120     {
   2121       int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off
   2122 				? REG_ICASE : 0);
   2123       reg->emplace (regexp, cflags, _("Invalid regexp"));
   2124     }
   2125   else
   2126     reg->reset ();
   2127 }
   2128 
   2129 /* Print all variables from the innermost up to the function block of FRAME.
   2130    Print them with values to STREAM indented by NUM_TABS.
   2131    If REGEXP is not NULL, only print local variables whose name
   2132    matches REGEXP.
   2133    If T_REGEXP is not NULL, only print local variables whose type
   2134    matches T_REGEXP.
   2135    If no local variables have been printed and !QUIET, prints a message
   2136    explaining why no local variables could be printed.
   2137 
   2138    This function will invalidate FRAME.  */
   2139 
   2140 static void
   2141 print_frame_local_vars (struct frame_info *frame,
   2142 			bool quiet,
   2143 			const char *regexp, const char *t_regexp,
   2144 			int num_tabs, struct ui_file *stream)
   2145 {
   2146   struct print_variable_and_value_data cb_data;
   2147   const struct block *block;
   2148   CORE_ADDR pc;
   2149 
   2150   if (!get_frame_pc_if_available (frame, &pc))
   2151     {
   2152       if (!quiet)
   2153 	fprintf_filtered (stream,
   2154 			  _("PC unavailable, cannot determine locals.\n"));
   2155       return;
   2156     }
   2157 
   2158   block = get_frame_block (frame, 0);
   2159   if (block == 0)
   2160     {
   2161       if (!quiet)
   2162 	fprintf_filtered (stream, "No symbol table info available.\n");
   2163       return;
   2164     }
   2165 
   2166   prepare_reg (regexp, &cb_data.preg);
   2167   prepare_reg (t_regexp, &cb_data.treg);
   2168   cb_data.frame_id = get_frame_id (frame);
   2169   cb_data.num_tabs = 4 * num_tabs;
   2170   cb_data.stream = stream;
   2171   cb_data.values_printed = 0;
   2172 
   2173   /* Temporarily change the selected frame to the given FRAME.
   2174      This allows routines that rely on the selected frame instead
   2175      of being given a frame as parameter to use the correct frame.  */
   2176   scoped_restore_selected_frame restore_selected_frame;
   2177   select_frame (frame);
   2178 
   2179   iterate_over_block_local_vars (block,
   2180 				 do_print_variable_and_value,
   2181 				 &cb_data);
   2182 
   2183   if (!cb_data.values_printed && !quiet)
   2184     {
   2185       if (regexp == NULL && t_regexp == NULL)
   2186 	fprintf_filtered (stream, _("No locals.\n"));
   2187       else
   2188 	fprintf_filtered (stream, _("No matching locals.\n"));
   2189     }
   2190 }
   2191 
   2192 void
   2193 info_locals_command (const char *args, int from_tty)
   2194 {
   2195   std::string regexp;
   2196   std::string t_regexp;
   2197   bool quiet = false;
   2198 
   2199   while (args != NULL
   2200 	 && extract_info_print_args (&args, &quiet, &regexp, &t_regexp))
   2201     ;
   2202 
   2203   if (args != NULL)
   2204     report_unrecognized_option_error ("info locals", args);
   2205 
   2206   print_frame_local_vars (get_selected_frame (_("No frame selected.")),
   2207 			  quiet,
   2208 			  regexp.empty () ? NULL : regexp.c_str (),
   2209 			  t_regexp.empty () ? NULL : t_regexp.c_str (),
   2210 			  0, gdb_stdout);
   2211 }
   2212 
   2213 /* Iterate over all the argument variables in block B.  */
   2214 
   2215 void
   2216 iterate_over_block_arg_vars (const struct block *b,
   2217 			     iterate_over_block_arg_local_vars_cb cb,
   2218 			     void *cb_data)
   2219 {
   2220   struct block_iterator iter;
   2221   struct symbol *sym, *sym2;
   2222 
   2223   ALL_BLOCK_SYMBOLS (b, iter, sym)
   2224     {
   2225       /* Don't worry about things which aren't arguments.  */
   2226       if (SYMBOL_IS_ARGUMENT (sym))
   2227 	{
   2228 	  /* We have to look up the symbol because arguments can have
   2229 	     two entries (one a parameter, one a local) and the one we
   2230 	     want is the local, which lookup_symbol will find for us.
   2231 	     This includes gcc1 (not gcc2) on the sparc when passing a
   2232 	     small structure and gcc2 when the argument type is float
   2233 	     and it is passed as a double and converted to float by
   2234 	     the prologue (in the latter case the type of the LOC_ARG
   2235 	     symbol is double and the type of the LOC_LOCAL symbol is
   2236 	     float).  There are also LOC_ARG/LOC_REGISTER pairs which
   2237 	     are not combined in symbol-reading.  */
   2238 
   2239 	  sym2 = lookup_symbol_search_name (SYMBOL_SEARCH_NAME (sym),
   2240 					    b, VAR_DOMAIN).symbol;
   2241 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
   2242 	}
   2243     }
   2244 }
   2245 
   2246 /* Print all argument variables of the function of FRAME.
   2247    Print them with values to STREAM.
   2248    If REGEXP is not NULL, only print argument variables whose name
   2249    matches REGEXP.
   2250    If T_REGEXP is not NULL, only print argument variables whose type
   2251    matches T_REGEXP.
   2252    If no argument variables have been printed and !QUIET, prints a message
   2253    explaining why no argument variables could be printed.
   2254 
   2255    This function will invalidate FRAME.  */
   2256 
   2257 static void
   2258 print_frame_arg_vars (struct frame_info *frame,
   2259 		      bool quiet,
   2260 		      const char *regexp, const char *t_regexp,
   2261 		      struct ui_file *stream)
   2262 {
   2263   struct print_variable_and_value_data cb_data;
   2264   struct symbol *func;
   2265   CORE_ADDR pc;
   2266   gdb::optional<compiled_regex> preg;
   2267   gdb::optional<compiled_regex> treg;
   2268 
   2269   if (!get_frame_pc_if_available (frame, &pc))
   2270     {
   2271       if (!quiet)
   2272 	fprintf_filtered (stream,
   2273 			  _("PC unavailable, cannot determine args.\n"));
   2274       return;
   2275     }
   2276 
   2277   func = get_frame_function (frame);
   2278   if (func == NULL)
   2279     {
   2280       if (!quiet)
   2281 	fprintf_filtered (stream, _("No symbol table info available.\n"));
   2282       return;
   2283     }
   2284 
   2285   prepare_reg (regexp, &cb_data.preg);
   2286   prepare_reg (t_regexp, &cb_data.treg);
   2287   cb_data.frame_id = get_frame_id (frame);
   2288   cb_data.num_tabs = 0;
   2289   cb_data.stream = stream;
   2290   cb_data.values_printed = 0;
   2291 
   2292   iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
   2293 			       do_print_variable_and_value, &cb_data);
   2294 
   2295   /* do_print_variable_and_value invalidates FRAME.  */
   2296   frame = NULL;
   2297 
   2298   if (!cb_data.values_printed && !quiet)
   2299     {
   2300       if (regexp == NULL && t_regexp == NULL)
   2301 	fprintf_filtered (stream, _("No arguments.\n"));
   2302       else
   2303 	fprintf_filtered (stream, _("No matching arguments.\n"));
   2304     }
   2305 }
   2306 
   2307 void
   2308 info_args_command (const char *args, int from_tty)
   2309 {
   2310   std::string regexp;
   2311   std::string t_regexp;
   2312   bool quiet = false;
   2313 
   2314   while (args != NULL
   2315 	 && extract_info_print_args (&args, &quiet, &regexp, &t_regexp))
   2316     ;
   2317 
   2318   if (args != NULL)
   2319     report_unrecognized_option_error ("info args", args);
   2320 
   2321 
   2322   print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
   2323 			quiet,
   2324 			regexp.empty () ? NULL : regexp.c_str (),
   2325 			t_regexp.empty () ? NULL : t_regexp.c_str (),
   2326 			gdb_stdout);
   2327 }
   2328 
   2329 /* Return the symbol-block in which the selected frame is executing.
   2331    Can return zero under various legitimate circumstances.
   2332 
   2333    If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
   2334    code address within the block returned.  We use this to decide
   2335    which macros are in scope.  */
   2336 
   2337 const struct block *
   2338 get_selected_block (CORE_ADDR *addr_in_block)
   2339 {
   2340   if (!has_stack_frames ())
   2341     return 0;
   2342 
   2343   return get_frame_block (get_selected_frame (NULL), addr_in_block);
   2344 }
   2345 
   2346 /* Find a frame a certain number of levels away from FRAME.
   2347    LEVEL_OFFSET_PTR points to an int containing the number of levels.
   2348    Positive means go to earlier frames (up); negative, the reverse.
   2349    The int that contains the number of levels is counted toward
   2350    zero as the frames for those levels are found.
   2351    If the top or bottom frame is reached, that frame is returned,
   2352    but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
   2353    how much farther the original request asked to go.  */
   2354 
   2355 struct frame_info *
   2356 find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
   2357 {
   2358   /* Going up is simple: just call get_prev_frame enough times or
   2359      until the initial frame is reached.  */
   2360   while (*level_offset_ptr > 0)
   2361     {
   2362       struct frame_info *prev = get_prev_frame (frame);
   2363 
   2364       if (!prev)
   2365 	break;
   2366       (*level_offset_ptr)--;
   2367       frame = prev;
   2368     }
   2369 
   2370   /* Going down is just as simple.  */
   2371   while (*level_offset_ptr < 0)
   2372     {
   2373       struct frame_info *next = get_next_frame (frame);
   2374 
   2375       if (!next)
   2376 	break;
   2377       (*level_offset_ptr)++;
   2378       frame = next;
   2379     }
   2380 
   2381   return frame;
   2382 }
   2383 
   2384 /* Select the frame up one or COUNT_EXP stack levels from the
   2385    previously selected frame, and print it briefly.  */
   2386 
   2387 static void
   2388 up_silently_base (const char *count_exp)
   2389 {
   2390   struct frame_info *frame;
   2391   int count = 1;
   2392 
   2393   if (count_exp)
   2394     count = parse_and_eval_long (count_exp);
   2395 
   2396   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
   2397   if (count != 0 && count_exp == NULL)
   2398     error (_("Initial frame selected; you cannot go up."));
   2399   select_frame (frame);
   2400 }
   2401 
   2402 static void
   2403 up_silently_command (const char *count_exp, int from_tty)
   2404 {
   2405   up_silently_base (count_exp);
   2406 }
   2407 
   2408 static void
   2409 up_command (const char *count_exp, int from_tty)
   2410 {
   2411   up_silently_base (count_exp);
   2412   gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
   2413 }
   2414 
   2415 /* Select the frame down one or COUNT_EXP stack levels from the previously
   2416    selected frame, and print it briefly.  */
   2417 
   2418 static void
   2419 down_silently_base (const char *count_exp)
   2420 {
   2421   struct frame_info *frame;
   2422   int count = -1;
   2423 
   2424   if (count_exp)
   2425     count = -parse_and_eval_long (count_exp);
   2426 
   2427   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
   2428   if (count != 0 && count_exp == NULL)
   2429     {
   2430       /* We only do this if COUNT_EXP is not specified.  That way
   2431          "down" means to really go down (and let me know if that is
   2432          impossible), but "down 9999" can be used to mean go all the
   2433          way down without getting an error.  */
   2434 
   2435       error (_("Bottom (innermost) frame selected; you cannot go down."));
   2436     }
   2437 
   2438   select_frame (frame);
   2439 }
   2440 
   2441 static void
   2442 down_silently_command (const char *count_exp, int from_tty)
   2443 {
   2444   down_silently_base (count_exp);
   2445 }
   2446 
   2447 static void
   2448 down_command (const char *count_exp, int from_tty)
   2449 {
   2450   down_silently_base (count_exp);
   2451   gdb::observers::user_selected_context_changed.notify (USER_SELECTED_FRAME);
   2452 }
   2453 
   2454 void
   2455 return_command (const char *retval_exp, int from_tty)
   2456 {
   2457   /* Initialize it just to avoid a GCC false warning.  */
   2458   enum return_value_convention rv_conv = RETURN_VALUE_STRUCT_CONVENTION;
   2459   struct frame_info *thisframe;
   2460   struct gdbarch *gdbarch;
   2461   struct symbol *thisfun;
   2462   struct value *return_value = NULL;
   2463   struct value *function = NULL;
   2464   const char *query_prefix = "";
   2465 
   2466   thisframe = get_selected_frame ("No selected frame.");
   2467   thisfun = get_frame_function (thisframe);
   2468   gdbarch = get_frame_arch (thisframe);
   2469 
   2470   if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
   2471     error (_("Can not force return from an inlined function."));
   2472 
   2473   /* Compute the return value.  If the computation triggers an error,
   2474      let it bail.  If the return type can't be handled, set
   2475      RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
   2476      message.  */
   2477   if (retval_exp)
   2478     {
   2479       expression_up retval_expr = parse_expression (retval_exp);
   2480       struct type *return_type = NULL;
   2481 
   2482       /* Compute the return value.  Should the computation fail, this
   2483          call throws an error.  */
   2484       return_value = evaluate_expression (retval_expr.get ());
   2485 
   2486       /* Cast return value to the return type of the function.  Should
   2487          the cast fail, this call throws an error.  */
   2488       if (thisfun != NULL)
   2489 	return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
   2490       if (return_type == NULL)
   2491       	{
   2492 	  if (retval_expr->elts[0].opcode != UNOP_CAST
   2493 	      && retval_expr->elts[0].opcode != UNOP_CAST_TYPE)
   2494 	    error (_("Return value type not available for selected "
   2495 		     "stack frame.\n"
   2496 		     "Please use an explicit cast of the value to return."));
   2497 	  return_type = value_type (return_value);
   2498 	}
   2499       return_type = check_typedef (return_type);
   2500       return_value = value_cast (return_type, return_value);
   2501 
   2502       /* Make sure the value is fully evaluated.  It may live in the
   2503          stack frame we're about to pop.  */
   2504       if (value_lazy (return_value))
   2505 	value_fetch_lazy (return_value);
   2506 
   2507       if (thisfun != NULL)
   2508 	function = read_var_value (thisfun, NULL, thisframe);
   2509 
   2510       rv_conv = RETURN_VALUE_REGISTER_CONVENTION;
   2511       if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
   2512 	/* If the return-type is "void", don't try to find the
   2513            return-value's location.  However, do still evaluate the
   2514            return expression so that, even when the expression result
   2515            is discarded, side effects such as "return i++" still
   2516            occur.  */
   2517 	return_value = NULL;
   2518       else if (thisfun != NULL)
   2519 	{
   2520 	  rv_conv = struct_return_convention (gdbarch, function, return_type);
   2521 	  if (rv_conv == RETURN_VALUE_STRUCT_CONVENTION
   2522 	      || rv_conv == RETURN_VALUE_ABI_RETURNS_ADDRESS)
   2523 	    {
   2524 	      query_prefix = "The location at which to store the "
   2525 		"function's return value is unknown.\n"
   2526 		"If you continue, the return value "
   2527 		"that you specified will be ignored.\n";
   2528 	      return_value = NULL;
   2529 	    }
   2530 	}
   2531     }
   2532 
   2533   /* Does an interactive user really want to do this?  Include
   2534      information, such as how well GDB can handle the return value, in
   2535      the query message.  */
   2536   if (from_tty)
   2537     {
   2538       int confirmed;
   2539 
   2540       if (thisfun == NULL)
   2541 	confirmed = query (_("%sMake selected stack frame return now? "),
   2542 			   query_prefix);
   2543       else
   2544 	{
   2545 	  if (TYPE_NO_RETURN (thisfun->type))
   2546 	    warning (_("Function does not return normally to caller."));
   2547 	  confirmed = query (_("%sMake %s return now? "), query_prefix,
   2548 			     SYMBOL_PRINT_NAME (thisfun));
   2549 	}
   2550       if (!confirmed)
   2551 	error (_("Not confirmed"));
   2552     }
   2553 
   2554   /* Discard the selected frame and all frames inner-to it.  */
   2555   frame_pop (get_selected_frame (NULL));
   2556 
   2557   /* Store RETURN_VALUE in the just-returned register set.  */
   2558   if (return_value != NULL)
   2559     {
   2560       struct type *return_type = value_type (return_value);
   2561       struct gdbarch *cache_arch = get_current_regcache ()->arch ();
   2562 
   2563       gdb_assert (rv_conv != RETURN_VALUE_STRUCT_CONVENTION
   2564 		  && rv_conv != RETURN_VALUE_ABI_RETURNS_ADDRESS);
   2565       gdbarch_return_value (cache_arch, function, return_type,
   2566 			    get_current_regcache (), NULL /*read*/,
   2567 			    value_contents (return_value) /*write*/);
   2568     }
   2569 
   2570   /* If we are at the end of a call dummy now, pop the dummy frame
   2571      too.  */
   2572   if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
   2573     frame_pop (get_current_frame ());
   2574 
   2575   select_frame (get_current_frame ());
   2576   /* If interactive, print the frame that is now current.  */
   2577   if (from_tty)
   2578     print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
   2579 }
   2580 
   2581 /* Find the most inner frame in the current stack for a function called
   2582    FUNCTION_NAME.  If no matching frame is found return NULL.  */
   2583 
   2584 static struct frame_info *
   2585 find_frame_for_function (const char *function_name)
   2586 {
   2587   /* Used to hold the lower and upper addresses for each of the
   2588      SYMTAB_AND_LINEs found for functions matching FUNCTION_NAME.  */
   2589   struct function_bounds
   2590   {
   2591     CORE_ADDR low, high;
   2592   };
   2593   struct frame_info *frame;
   2594   bool found = false;
   2595   int level = 1;
   2596 
   2597   gdb_assert (function_name != NULL);
   2598 
   2599   frame = get_current_frame ();
   2600   std::vector<symtab_and_line> sals
   2601     = decode_line_with_current_source (function_name,
   2602 				       DECODE_LINE_FUNFIRSTLINE);
   2603   gdb::def_vector<function_bounds> func_bounds (sals.size ());
   2604   for (size_t i = 0; i < sals.size (); i++)
   2605     {
   2606       if (sals[i].pspace != current_program_space)
   2607 	func_bounds[i].low = func_bounds[i].high = 0;
   2608       else if (sals[i].pc == 0
   2609 	       || find_pc_partial_function (sals[i].pc, NULL,
   2610 					    &func_bounds[i].low,
   2611 					    &func_bounds[i].high) == 0)
   2612 	func_bounds[i].low = func_bounds[i].high = 0;
   2613     }
   2614 
   2615   do
   2616     {
   2617       for (size_t i = 0; (i < sals.size () && !found); i++)
   2618 	found = (get_frame_pc (frame) >= func_bounds[i].low
   2619 		 && get_frame_pc (frame) < func_bounds[i].high);
   2620       if (!found)
   2621 	{
   2622 	  level = 1;
   2623 	  frame = find_relative_frame (frame, &level);
   2624 	}
   2625     }
   2626   while (!found && level == 0);
   2627 
   2628   if (!found)
   2629     frame = NULL;
   2630 
   2631   return frame;
   2632 }
   2633 
   2634 /* Implements the dbx 'func' command.  */
   2635 
   2636 static void
   2637 func_command (const char *arg, int from_tty)
   2638 {
   2639   if (arg == NULL)
   2640     return;
   2641 
   2642   struct frame_info *frame = find_frame_for_function (arg);
   2643   if (frame == NULL)
   2644     error (_("'%s' not within current stack frame."), arg);
   2645   if (frame != get_selected_frame (NULL))
   2646     {
   2647       select_frame (frame);
   2648       print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
   2649     }
   2650 }
   2651 
   2652 /* Apply a GDB command to all stack frames, or a set of identified frames,
   2653    or innermost COUNT frames.
   2654    With a negative COUNT, apply command on outermost -COUNT frames.
   2655 
   2656    frame apply 3 info frame     Apply 'info frame' to frames 0, 1, 2
   2657    frame apply -3 info frame    Apply 'info frame' to outermost 3 frames.
   2658    frame apply all x/i $pc      Apply 'x/i $pc' cmd to all frames.
   2659    frame apply all -s p local_var_no_idea_in_which_frame
   2660                 If a frame has a local variable called
   2661                 local_var_no_idea_in_which_frame, print frame
   2662                 and value of local_var_no_idea_in_which_frame.
   2663    frame apply all -s -q p local_var_no_idea_in_which_frame
   2664                 Same as before, but only print the variable value.
   2665    frame apply level 2-5 0 4-7 -s p i = i + 1
   2666                 Adds 1 to the variable i in the specified frames.
   2667                 Note that i will be incremented twice in
   2668                 frames 4 and 5.  */
   2669 
   2670 /* Apply a GDB command to COUNT stack frames, starting at TRAILING.
   2671    CMD starts with 0 or more qcs flags followed by the GDB command to apply.
   2672    COUNT -1 means all frames starting at TRAILING.  WHICH_COMMAND is used
   2673    for error messages.  */
   2674 
   2675 static void
   2676 frame_apply_command_count (const char *which_command,
   2677 			   const char *cmd, int from_tty,
   2678 			   struct frame_info *trailing, int count)
   2679 {
   2680   qcs_flags flags;
   2681   struct frame_info *fi;
   2682 
   2683   while (cmd != NULL && parse_flags_qcs (which_command, &cmd, &flags))
   2684     ;
   2685 
   2686   if (cmd == NULL || *cmd == '\0')
   2687     error (_("Please specify a command to apply on the selected frames"));
   2688 
   2689   /* The below will restore the current inferior/thread/frame.
   2690      Usually, only the frame is effectively to be restored.
   2691      But in case CMD switches of inferior/thread, better restore
   2692      these also.  */
   2693   scoped_restore_current_thread restore_thread;
   2694 
   2695   for (fi = trailing; fi && count--; fi = get_prev_frame (fi))
   2696     {
   2697       QUIT;
   2698 
   2699       select_frame (fi);
   2700       TRY
   2701 	{
   2702 	  std::string cmd_result;
   2703 	  {
   2704 	    /* In case CMD switches of inferior/thread/frame, the below
   2705 	       restores the inferior/thread/frame.  FI can then be
   2706 	       set to the selected frame.  */
   2707 	    scoped_restore_current_thread restore_fi_current_frame;
   2708 
   2709 	    cmd_result = execute_command_to_string (cmd, from_tty);
   2710 	  }
   2711 	  fi = get_selected_frame (_("frame apply "
   2712 				     "unable to get selected frame."));
   2713 	  if (!flags.silent || cmd_result.length () > 0)
   2714 	    {
   2715 	      if (!flags.quiet)
   2716 		print_stack_frame (fi, 1, LOCATION, 0);
   2717 	      printf_filtered ("%s", cmd_result.c_str ());
   2718 	    }
   2719 	}
   2720       CATCH (ex, RETURN_MASK_ERROR)
   2721 	{
   2722 	  fi = get_selected_frame (_("frame apply "
   2723 				     "unable to get selected frame."));
   2724 	  if (!flags.silent)
   2725 	    {
   2726 	      if (!flags.quiet)
   2727 		print_stack_frame (fi, 1, LOCATION, 0);
   2728 	      if (flags.cont)
   2729 		printf_filtered ("%s\n", ex.message);
   2730 	      else
   2731 		throw_exception (ex);
   2732 	    }
   2733 	}
   2734       END_CATCH;
   2735     }
   2736 }
   2737 
   2738 /* Implementation of the "frame apply level" command.  */
   2739 
   2740 static void
   2741 frame_apply_level_command (const char *cmd, int from_tty)
   2742 {
   2743   if (!target_has_stack)
   2744     error (_("No stack."));
   2745 
   2746   bool level_found = false;
   2747   const char *levels_str = cmd;
   2748   number_or_range_parser levels (levels_str);
   2749 
   2750   /* Skip the LEVEL list to find the flags and command args.  */
   2751   while (!levels.finished ())
   2752     {
   2753       /* Call for effect.  */
   2754       levels.get_number ();
   2755 
   2756       level_found = true;
   2757       if (levels.in_range ())
   2758 	levels.skip_range ();
   2759     }
   2760 
   2761   if (!level_found)
   2762     error (_("Missing or invalid LEVEL... argument"));
   2763 
   2764   cmd = levels.cur_tok ();
   2765 
   2766   /* Redo the LEVELS parsing, but applying COMMAND.  */
   2767   levels.init (levels_str);
   2768   while (!levels.finished ())
   2769     {
   2770       const int level_beg = levels.get_number ();
   2771       int n_frames;
   2772 
   2773       if (levels.in_range ())
   2774 	{
   2775 	  n_frames = levels.end_value () - level_beg + 1;
   2776 	  levels.skip_range ();
   2777 	}
   2778       else
   2779 	n_frames = 1;
   2780 
   2781       frame_apply_command_count ("frame apply level", cmd, from_tty,
   2782 				 leading_innermost_frame (level_beg), n_frames);
   2783     }
   2784 }
   2785 
   2786 /* Implementation of the "frame apply all" command.  */
   2787 
   2788 static void
   2789 frame_apply_all_command (const char *cmd, int from_tty)
   2790 {
   2791   if (!target_has_stack)
   2792     error (_("No stack."));
   2793 
   2794   frame_apply_command_count ("frame apply all", cmd, from_tty,
   2795 			     get_current_frame (), INT_MAX);
   2796 }
   2797 
   2798 /* Implementation of the "frame apply" command.  */
   2799 
   2800 static void
   2801 frame_apply_command (const char* cmd, int from_tty)
   2802 {
   2803   int count;
   2804   struct frame_info *trailing;
   2805 
   2806   if (!target_has_stack)
   2807     error (_("No stack."));
   2808 
   2809   if (cmd == NULL)
   2810     error (_("Missing COUNT argument."));
   2811   count = get_number_trailer (&cmd, 0);
   2812   if (count == 0)
   2813     error (_("Invalid COUNT argument."));
   2814 
   2815   if (count < 0)
   2816     {
   2817       trailing = trailing_outermost_frame (-count);
   2818       count = -1;
   2819     }
   2820   else
   2821     trailing = get_current_frame ();
   2822 
   2823   frame_apply_command_count ("frame apply", cmd, from_tty,
   2824 			     trailing, count);
   2825 }
   2826 
   2827 /* Implementation of the "faas" command.  */
   2828 
   2829 static void
   2830 faas_command (const char *cmd, int from_tty)
   2831 {
   2832   std::string expanded = std::string ("frame apply all -s ") + cmd;
   2833   execute_command (expanded.c_str (), from_tty);
   2834 }
   2835 
   2836 
   2837 /* Find inner-mode frame with frame address ADDRESS.  Return NULL if no
   2838    matching frame can be found.  */
   2839 
   2840 static struct frame_info *
   2841 find_frame_for_address (CORE_ADDR address)
   2842 {
   2843   struct frame_id id;
   2844   struct frame_info *fid;
   2845 
   2846   id = frame_id_build_wild (address);
   2847 
   2848   /* If (s)he specifies the frame with an address, he deserves
   2849      what (s)he gets.  Still, give the highest one that matches.
   2850      (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
   2851      know).  */
   2852   for (fid = get_current_frame ();
   2853        fid != NULL;
   2854        fid = get_prev_frame (fid))
   2855     {
   2856       if (frame_id_eq (id, get_frame_id (fid)))
   2857 	{
   2858 	  struct frame_info *prev_frame;
   2859 
   2860 	  while (1)
   2861 	    {
   2862 	      prev_frame = get_prev_frame (fid);
   2863 	      if (!prev_frame
   2864 		  || !frame_id_eq (id, get_frame_id (prev_frame)))
   2865 		break;
   2866 	      fid = prev_frame;
   2867 	    }
   2868 	  return fid;
   2869 	}
   2870     }
   2871   return NULL;
   2872 }
   2873 
   2874 
   2875 
   2877 /* Commands with a prefix of `frame apply'.  */
   2878 static struct cmd_list_element *frame_apply_cmd_list = NULL;
   2879 
   2880 /* Commands with a prefix of `frame'.  */
   2881 static struct cmd_list_element *frame_cmd_list = NULL;
   2882 
   2883 /* Commands with a prefix of `select frame'.  */
   2884 static struct cmd_list_element *select_frame_cmd_list = NULL;
   2885 
   2886 /* Commands with a prefix of `info frame'.  */
   2887 static struct cmd_list_element *info_frame_cmd_list = NULL;
   2888 
   2889 void
   2890 _initialize_stack (void)
   2891 {
   2892   struct cmd_list_element *cmd;
   2893 
   2894   add_com ("return", class_stack, return_command, _("\
   2895 Make selected stack frame return to its caller.\n\
   2896 Control remains in the debugger, but when you continue\n\
   2897 execution will resume in the frame above the one now selected.\n\
   2898 If an argument is given, it is an expression for the value to return."));
   2899 
   2900   add_com ("up", class_stack, up_command, _("\
   2901 Select and print stack frame that called this one.\n\
   2902 An argument says how many frames up to go."));
   2903   add_com ("up-silently", class_support, up_silently_command, _("\
   2904 Same as the `up' command, but does not print anything.\n\
   2905 This is useful in command scripts."));
   2906 
   2907   add_com ("down", class_stack, down_command, _("\
   2908 Select and print stack frame called by this one.\n\
   2909 An argument says how many frames down to go."));
   2910   add_com_alias ("do", "down", class_stack, 1);
   2911   add_com_alias ("dow", "down", class_stack, 1);
   2912   add_com ("down-silently", class_support, down_silently_command, _("\
   2913 Same as the `down' command, but does not print anything.\n\
   2914 This is useful in command scripts."));
   2915 
   2916   add_prefix_cmd ("frame", class_stack,
   2917                   &frame_cmd.base_command, _("\
   2918 Select and print a stack frame.\n\
   2919 With no argument, print the selected stack frame.  (See also \"info frame\").\n\
   2920 A single numerical argument specifies the frame to select."),
   2921                   &frame_cmd_list, "frame ", 1, &cmdlist);
   2922 
   2923   add_com_alias ("f", "frame", class_stack, 1);
   2924 
   2925 #define FRAME_APPLY_FLAGS_HELP "\
   2926 Prints the frame location information followed by COMMAND output.\n\
   2927 FLAG arguments are -q (quiet), -c (continue), -s (silent).\n\
   2928 Flag -q disables printing the frame location information.\n\
   2929 By default, if a COMMAND raises an error, frame apply is aborted.\n\
   2930 Flag -c indicates to print the error and continue.\n\
   2931 Flag -s indicates to silently ignore a COMMAND that raises an error\n\
   2932 or produces no output."
   2933 
   2934   add_prefix_cmd ("apply", class_stack, frame_apply_command,
   2935 		  _("Apply a command to a number of frames.\n\
   2936 Usage: frame apply COUNT [FLAG]... COMMAND\n\
   2937 With a negative COUNT argument, applies the command on outermost -COUNT frames.\n"
   2938 FRAME_APPLY_FLAGS_HELP),
   2939 		  &frame_apply_cmd_list, "frame apply ", 1, &frame_cmd_list);
   2940 
   2941   add_cmd ("all", class_stack, frame_apply_all_command,
   2942 	   _("\
   2943 Apply a command to all frames.\n\
   2944 \n\
   2945 Usage: frame apply all [FLAG]... COMMAND\n"
   2946 FRAME_APPLY_FLAGS_HELP),
   2947 	   &frame_apply_cmd_list);
   2948 
   2949   add_cmd ("level", class_stack, frame_apply_level_command,
   2950 	   _("\
   2951 Apply a command to a list of frames.\n\
   2952 \n\
   2953 Usage: frame apply level LEVEL... [FLAG]... COMMAND\n\
   2954 ID is a space-separated list of LEVELs of frames to apply COMMAND on.\n"
   2955 FRAME_APPLY_FLAGS_HELP),
   2956 	   &frame_apply_cmd_list);
   2957 
   2958   add_com ("faas", class_stack, faas_command, _("\
   2959 Apply a command to all frames (ignoring errors and empty output).\n\
   2960 Usage: faas COMMAND\n\
   2961 shortcut for 'frame apply all -s COMMAND'"));
   2962 
   2963 
   2964   add_prefix_cmd ("frame", class_stack,
   2965 		  &frame_cmd.base_command, _("\
   2966 Select and print a stack frame.\n\
   2967 With no argument, print the selected stack frame.  (See also \"info frame\").\n\
   2968 A single numerical argument specifies the frame to select."),
   2969 		  &frame_cmd_list, "frame ", 1, &cmdlist);
   2970   add_com_alias ("f", "frame", class_stack, 1);
   2971 
   2972   add_cmd ("address", class_stack, &frame_cmd.address,
   2973 	   _("\
   2974 Select and print a stack frame by stack address\n\
   2975 \n\
   2976 Usage: frame address STACK-ADDRESS"),
   2977 	   &frame_cmd_list);
   2978 
   2979   add_cmd ("view", class_stack, &frame_cmd.view,
   2980 	   _("\
   2981 View a stack frame that might be outside the current backtrace.\n\
   2982 \n\
   2983 Usage: frame view STACK-ADDRESS\n\
   2984        frame view STACK-ADDRESS PC-ADDRESS"),
   2985 	   &frame_cmd_list);
   2986 
   2987   cmd = add_cmd ("function", class_stack, &frame_cmd.function,
   2988 	   _("\
   2989 Select and print a stack frame by function name.\n\
   2990 \n\
   2991 Usage: frame function NAME\n\
   2992 \n\
   2993 The innermost frame that visited function NAME is selected."),
   2994 	   &frame_cmd_list);
   2995   set_cmd_completer (cmd, frame_selection_by_function_completer);
   2996 
   2997 
   2998   add_cmd ("level", class_stack, &frame_cmd.level,
   2999 	   _("\
   3000 Select and print a stack frame by level.\n\
   3001 \n\
   3002 Usage: frame level LEVEL"),
   3003 	   &frame_cmd_list);
   3004 
   3005   cmd = add_prefix_cmd_suppress_notification ("select-frame", class_stack,
   3006 		      &select_frame_cmd.base_command, _("\
   3007 Select a stack frame without printing anything.\n\
   3008 A single numerical argument specifies the frame to select."),
   3009 		      &select_frame_cmd_list, "select-frame ", 1, &cmdlist,
   3010 		      &cli_suppress_notification.user_selected_context);
   3011 
   3012   add_cmd_suppress_notification ("address", class_stack,
   3013 			 &select_frame_cmd.address, _("\
   3014 Select a stack frame by stack address.\n\
   3015 \n\
   3016 Usage: select-frame address STACK-ADDRESS"),
   3017 			 &select_frame_cmd_list,
   3018 			 &cli_suppress_notification.user_selected_context);
   3019 
   3020 
   3021   add_cmd_suppress_notification ("view", class_stack,
   3022 		 &select_frame_cmd.view, _("\
   3023 Select a stack frame that might be outside the current backtrace.\n\
   3024 \n\
   3025 Usage: select-frame view STACK-ADDRESS\n\
   3026        select-frame view STACK-ADDRESS PC-ADDRESS"),
   3027 		 &select_frame_cmd_list,
   3028 		 &cli_suppress_notification.user_selected_context);
   3029 
   3030   cmd = add_cmd_suppress_notification ("function", class_stack,
   3031 	       &select_frame_cmd.function, _("\
   3032 Select a stack frame by function name.\n\
   3033 \n\
   3034 Usage: select-frame function NAME"),
   3035 	       &select_frame_cmd_list,
   3036 	       &cli_suppress_notification.user_selected_context);
   3037   set_cmd_completer (cmd, frame_selection_by_function_completer);
   3038 
   3039   add_cmd_suppress_notification ("level", class_stack,
   3040 			 &select_frame_cmd.level, _("\
   3041 Select a stack frame by level.\n\
   3042 \n\
   3043 Usage: select-frame level LEVEL"),
   3044 			 &select_frame_cmd_list,
   3045 			 &cli_suppress_notification.user_selected_context);
   3046 
   3047   add_com ("backtrace", class_stack, backtrace_command, _("\
   3048 Print backtrace of all stack frames, or innermost COUNT frames.\n\
   3049 Usage: backtrace [QUALIFIERS]... [COUNT]\n\
   3050 With a negative argument, print outermost -COUNT frames.\n\
   3051 Use of the 'full' qualifier also prints the values of the local variables.\n\
   3052 Use of the 'no-filters' qualifier prohibits frame filters from executing\n\
   3053 on this backtrace."));
   3054   add_com_alias ("bt", "backtrace", class_stack, 0);
   3055 
   3056   add_com_alias ("where", "backtrace", class_alias, 0);
   3057   add_info ("stack", backtrace_command,
   3058 	    _("Backtrace of the stack, or innermost COUNT frames."));
   3059   add_info_alias ("s", "stack", 1);
   3060 
   3061   add_prefix_cmd ("frame", class_info, &info_frame_cmd.base_command,
   3062 		  _("All about the selected stack frame.\n\
   3063 With no arguments, displays information about the currently selected stack\n\
   3064 frame.  Alternatively a frame specification may be provided (See \"frame\")\n\
   3065 the information is then printed about the specified frame."),
   3066 		  &info_frame_cmd_list, "info frame ", 1, &infolist);
   3067   add_info_alias ("f", "frame", 1);
   3068 
   3069   add_cmd ("address", class_stack, &info_frame_cmd.address,
   3070 	   _("\
   3071 Print information about a stack frame selected by stack address.\n\
   3072 \n\
   3073 Usage: info frame address STACK-ADDRESS"),
   3074 	   &info_frame_cmd_list);
   3075 
   3076   add_cmd ("view", class_stack, &info_frame_cmd.view,
   3077 	   _("\
   3078 Print information about a stack frame outside the current backtrace.\n\
   3079 \n\
   3080 Usage: info frame view STACK-ADDRESS\n\
   3081        info frame view STACK-ADDRESS PC-ADDRESS"),
   3082 	   &info_frame_cmd_list);
   3083 
   3084   cmd = add_cmd ("function", class_stack, &info_frame_cmd.function,
   3085 	   _("\
   3086 Print information about a stack frame selected by function name.\n\
   3087 \n\
   3088 Usage: info frame function NAME"),
   3089 	   &info_frame_cmd_list);
   3090   set_cmd_completer (cmd, frame_selection_by_function_completer);
   3091 
   3092   add_cmd ("level", class_stack, &info_frame_cmd.level,
   3093 	   _("\
   3094 Print information about a stack frame selected by level.\n\
   3095 \n\
   3096 Usage: info frame level LEVEL"),
   3097 	   &info_frame_cmd_list);
   3098 
   3099   add_info ("locals", info_locals_command,
   3100 	    info_print_args_help (_("\
   3101 All local variables of current stack frame or those matching REGEXPs.\n\
   3102 Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
   3103 Prints the local variables of the current stack frame.\n"),
   3104 				  _("local variables")));
   3105   add_info ("args", info_args_command,
   3106 	    info_print_args_help (_("\
   3107 All argument variables of current stack frame or those matching REGEXPs.\n\
   3108 Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
   3109 Prints the argument variables of the current stack frame.\n"),
   3110 				  _("argument variables")));
   3111 
   3112   if (dbx_commands)
   3113     add_com ("func", class_stack, func_command, _("\
   3114 Select the stack frame that contains NAME.\n\
   3115 Usage: func NAME"));
   3116 
   3117   add_setshow_enum_cmd ("frame-arguments", class_stack,
   3118 			print_frame_arguments_choices, &print_frame_arguments,
   3119 			_("Set printing of non-scalar frame arguments"),
   3120 			_("Show printing of non-scalar frame arguments"),
   3121 			NULL, NULL, NULL, &setprintlist, &showprintlist);
   3122 
   3123   add_setshow_boolean_cmd ("frame-arguments", no_class,
   3124 			   &print_raw_frame_arguments, _("\
   3125 Set whether to print frame arguments in raw form."), _("\
   3126 Show whether to print frame arguments in raw form."), _("\
   3127 If set, frame arguments are printed in raw form, bypassing any\n\
   3128 pretty-printers for that value."),
   3129 			   NULL, NULL,
   3130 			   &setprintrawlist, &showprintrawlist);
   3131 
   3132   add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
   3133 			        &disassemble_next_line, _("\
   3134 Set whether to disassemble next source line or insn when execution stops."),
   3135 				_("\
   3136 Show whether to disassemble next source line or insn when execution stops."),
   3137 				_("\
   3138 If ON, GDB will display disassembly of the next source line, in addition\n\
   3139 to displaying the source line itself.  If the next source line cannot\n\
   3140 be displayed (e.g., source is unavailable or there's no line info), GDB\n\
   3141 will display disassembly of next instruction instead of showing the\n\
   3142 source line.\n\
   3143 If AUTO, display disassembly of next instruction only if the source line\n\
   3144 cannot be displayed.\n\
   3145 If OFF (which is the default), never display the disassembly of the next\n\
   3146 source line."),
   3147 			        NULL,
   3148 			        show_disassemble_next_line,
   3149 			        &setlist, &showlist);
   3150   disassemble_next_line = AUTO_BOOLEAN_FALSE;
   3151 
   3152   add_setshow_enum_cmd ("entry-values", class_stack,
   3153 			print_entry_values_choices, &print_entry_values,
   3154 			_("Set printing of function arguments at function "
   3155 			  "entry"),
   3156 			_("Show printing of function arguments at function "
   3157 			  "entry"),
   3158 			_("\
   3159 GDB can sometimes determine the values of function arguments at entry,\n\
   3160 in addition to their current values.  This option tells GDB whether\n\
   3161 to print the current value, the value at entry (marked as val@entry),\n\
   3162 or both.  Note that one or both of these values may be <optimized out>."),
   3163 			NULL, NULL, &setprintlist, &showprintlist);
   3164 }
   3165