xref: /dflybsd-src/contrib/gdb-7/gdb/stack.c (revision a45ae5f869d9cfcb3e41dbab486e10bfa9e336bf)
15796c8dcSSimon Schubert /* Print and select stack frames for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*a45ae5f8SJohn Marino    Copyright (C) 1986-2005, 2007-2012 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "value.h"
225796c8dcSSimon Schubert #include "symtab.h"
235796c8dcSSimon Schubert #include "gdbtypes.h"
245796c8dcSSimon Schubert #include "expression.h"
255796c8dcSSimon Schubert #include "language.h"
265796c8dcSSimon Schubert #include "frame.h"
275796c8dcSSimon Schubert #include "gdbcmd.h"
285796c8dcSSimon Schubert #include "gdbcore.h"
295796c8dcSSimon Schubert #include "target.h"
305796c8dcSSimon Schubert #include "source.h"
315796c8dcSSimon Schubert #include "breakpoint.h"
325796c8dcSSimon Schubert #include "demangle.h"
335796c8dcSSimon Schubert #include "inferior.h"
345796c8dcSSimon Schubert #include "annotate.h"
355796c8dcSSimon Schubert #include "ui-out.h"
365796c8dcSSimon Schubert #include "block.h"
375796c8dcSSimon Schubert #include "stack.h"
385796c8dcSSimon Schubert #include "dictionary.h"
395796c8dcSSimon Schubert #include "exceptions.h"
405796c8dcSSimon Schubert #include "reggroups.h"
415796c8dcSSimon Schubert #include "regcache.h"
425796c8dcSSimon Schubert #include "solib.h"
435796c8dcSSimon Schubert #include "valprint.h"
445796c8dcSSimon Schubert #include "gdbthread.h"
455796c8dcSSimon Schubert #include "cp-support.h"
465796c8dcSSimon Schubert #include "disasm.h"
475796c8dcSSimon Schubert #include "inline-frame.h"
48*a45ae5f8SJohn Marino #include "linespec.h"
495796c8dcSSimon Schubert 
505796c8dcSSimon Schubert #include "gdb_assert.h"
515796c8dcSSimon Schubert #include <ctype.h>
525796c8dcSSimon Schubert #include "gdb_string.h"
535796c8dcSSimon Schubert 
54cf7f2e2dSJohn Marino #include "psymtab.h"
55cf7f2e2dSJohn Marino #include "symfile.h"
56cf7f2e2dSJohn Marino 
575796c8dcSSimon Schubert void (*deprecated_selected_frame_level_changed_hook) (int);
585796c8dcSSimon Schubert 
59*a45ae5f8SJohn Marino /* The possible choices of "set print frame-arguments", and the value
605796c8dcSSimon Schubert    of this setting.  */
615796c8dcSSimon Schubert 
625796c8dcSSimon Schubert static const char *print_frame_arguments_choices[] =
635796c8dcSSimon Schubert   {"all", "scalars", "none", NULL};
645796c8dcSSimon Schubert static const char *print_frame_arguments = "scalars";
655796c8dcSSimon Schubert 
66*a45ae5f8SJohn Marino /* The possible choices of "set print entry-values", and the value
67*a45ae5f8SJohn Marino    of this setting.  */
68*a45ae5f8SJohn Marino 
69*a45ae5f8SJohn Marino const char print_entry_values_no[] = "no";
70*a45ae5f8SJohn Marino const char print_entry_values_only[] = "only";
71*a45ae5f8SJohn Marino const char print_entry_values_preferred[] = "preferred";
72*a45ae5f8SJohn Marino const char print_entry_values_if_needed[] = "if-needed";
73*a45ae5f8SJohn Marino const char print_entry_values_both[] = "both";
74*a45ae5f8SJohn Marino const char print_entry_values_compact[] = "compact";
75*a45ae5f8SJohn Marino const char print_entry_values_default[] = "default";
76*a45ae5f8SJohn Marino static const char *print_entry_values_choices[] =
77*a45ae5f8SJohn Marino {
78*a45ae5f8SJohn Marino   print_entry_values_no,
79*a45ae5f8SJohn Marino   print_entry_values_only,
80*a45ae5f8SJohn Marino   print_entry_values_preferred,
81*a45ae5f8SJohn Marino   print_entry_values_if_needed,
82*a45ae5f8SJohn Marino   print_entry_values_both,
83*a45ae5f8SJohn Marino   print_entry_values_compact,
84*a45ae5f8SJohn Marino   print_entry_values_default,
85*a45ae5f8SJohn Marino   NULL
86*a45ae5f8SJohn Marino };
87*a45ae5f8SJohn Marino const char *print_entry_values = print_entry_values_default;
88*a45ae5f8SJohn Marino 
895796c8dcSSimon Schubert /* Prototypes for local functions.  */
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert static void print_frame_local_vars (struct frame_info *, int,
925796c8dcSSimon Schubert 				    struct ui_file *);
935796c8dcSSimon Schubert 
945796c8dcSSimon Schubert static void print_frame (struct frame_info *frame, int print_level,
955796c8dcSSimon Schubert 			 enum print_what print_what,  int print_args,
965796c8dcSSimon Schubert 			 struct symtab_and_line sal);
975796c8dcSSimon Schubert 
98*a45ae5f8SJohn Marino static void set_last_displayed_sal (int valid,
99*a45ae5f8SJohn Marino 				    struct program_space *pspace,
100*a45ae5f8SJohn Marino 				    CORE_ADDR addr,
101*a45ae5f8SJohn Marino 				    struct symtab *symtab,
102*a45ae5f8SJohn Marino 				    int line);
103*a45ae5f8SJohn Marino 
1045796c8dcSSimon Schubert /* Zero means do things normally; we are interacting directly with the
1055796c8dcSSimon Schubert    user.  One means print the full filename and linenumber when a
1065796c8dcSSimon Schubert    frame is printed, and do so in a format emacs18/emacs19.22 can
1075796c8dcSSimon Schubert    parse.  Two means print similar annotations, but in many more
1085796c8dcSSimon Schubert    cases and in a slightly different syntax.  */
1095796c8dcSSimon Schubert 
1105796c8dcSSimon Schubert int annotation_level = 0;
111*a45ae5f8SJohn Marino 
112*a45ae5f8SJohn Marino /* These variables hold the last symtab and line we displayed to the user.
113*a45ae5f8SJohn Marino  * This is where we insert a breakpoint or a skiplist entry by default.  */
114*a45ae5f8SJohn Marino static int last_displayed_sal_valid = 0;
115*a45ae5f8SJohn Marino static struct program_space *last_displayed_pspace = 0;
116*a45ae5f8SJohn Marino static CORE_ADDR last_displayed_addr = 0;
117*a45ae5f8SJohn Marino static struct symtab *last_displayed_symtab = 0;
118*a45ae5f8SJohn Marino static int last_displayed_line = 0;
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert 
1215796c8dcSSimon Schubert /* Return 1 if we should display the address in addition to the location,
1225796c8dcSSimon Schubert    because we are in the middle of a statement.  */
1235796c8dcSSimon Schubert 
1245796c8dcSSimon Schubert static int
1255796c8dcSSimon Schubert frame_show_address (struct frame_info *frame,
1265796c8dcSSimon Schubert 		    struct symtab_and_line sal)
1275796c8dcSSimon Schubert {
1285796c8dcSSimon Schubert   /* If there is a line number, but no PC, then there is no location
1295796c8dcSSimon Schubert      information associated with this sal.  The only way that should
1305796c8dcSSimon Schubert      happen is for the call sites of inlined functions (SAL comes from
1315796c8dcSSimon Schubert      find_frame_sal).  Otherwise, we would have some PC range if the
1325796c8dcSSimon Schubert      SAL came from a line table.  */
1335796c8dcSSimon Schubert   if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
1345796c8dcSSimon Schubert     {
1355796c8dcSSimon Schubert       if (get_next_frame (frame) == NULL)
1365796c8dcSSimon Schubert 	gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
1375796c8dcSSimon Schubert       else
1385796c8dcSSimon Schubert 	gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
1395796c8dcSSimon Schubert       return 0;
1405796c8dcSSimon Schubert     }
1415796c8dcSSimon Schubert 
1425796c8dcSSimon Schubert   return get_frame_pc (frame) != sal.pc;
1435796c8dcSSimon Schubert }
1445796c8dcSSimon Schubert 
1455796c8dcSSimon Schubert /* Show or print a stack frame FRAME briefly.  The output is format
1465796c8dcSSimon Schubert    according to PRINT_LEVEL and PRINT_WHAT printing the frame's
1475796c8dcSSimon Schubert    relative level, function name, argument list, and file name and
1485796c8dcSSimon Schubert    line number.  If the frame's PC is not at the beginning of the
1495796c8dcSSimon Schubert    source line, the actual PC is printed at the beginning.  */
1505796c8dcSSimon Schubert 
1515796c8dcSSimon Schubert void
1525796c8dcSSimon Schubert print_stack_frame (struct frame_info *frame, int print_level,
1535796c8dcSSimon Schubert 		   enum print_what print_what)
1545796c8dcSSimon Schubert {
155*a45ae5f8SJohn Marino   volatile struct gdb_exception e;
1565796c8dcSSimon Schubert 
1575796c8dcSSimon Schubert   /* For mi, alway print location and address.  */
158*a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (current_uiout))
159*a45ae5f8SJohn Marino     print_what = LOC_AND_ADDRESS;
1605796c8dcSSimon Schubert 
161*a45ae5f8SJohn Marino   TRY_CATCH (e, RETURN_MASK_ERROR)
1625796c8dcSSimon Schubert     {
163*a45ae5f8SJohn Marino       int center = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
1645796c8dcSSimon Schubert 
165*a45ae5f8SJohn Marino       print_frame_info (frame, print_level, print_what, 1 /* print_args */);
166*a45ae5f8SJohn Marino       set_current_sal_from_frame (frame, center);
167*a45ae5f8SJohn Marino     }
168*a45ae5f8SJohn Marino }
1695796c8dcSSimon Schubert 
1705796c8dcSSimon Schubert /* Print nameless arguments of frame FRAME on STREAM, where START is
1715796c8dcSSimon Schubert    the offset of the first nameless argument, and NUM is the number of
1725796c8dcSSimon Schubert    nameless arguments to print.  FIRST is nonzero if this is the first
1735796c8dcSSimon Schubert    argument (not just the first nameless argument).  */
1745796c8dcSSimon Schubert 
1755796c8dcSSimon Schubert static void
1765796c8dcSSimon Schubert print_frame_nameless_args (struct frame_info *frame, long start, int num,
1775796c8dcSSimon Schubert 			   int first, struct ui_file *stream)
1785796c8dcSSimon Schubert {
1795796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
1805796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1815796c8dcSSimon Schubert   int i;
1825796c8dcSSimon Schubert   CORE_ADDR argsaddr;
1835796c8dcSSimon Schubert   long arg_value;
1845796c8dcSSimon Schubert 
1855796c8dcSSimon Schubert   for (i = 0; i < num; i++)
1865796c8dcSSimon Schubert     {
1875796c8dcSSimon Schubert       QUIT;
1885796c8dcSSimon Schubert       argsaddr = get_frame_args_address (frame);
1895796c8dcSSimon Schubert       if (!argsaddr)
1905796c8dcSSimon Schubert 	return;
1915796c8dcSSimon Schubert       arg_value = read_memory_integer (argsaddr + start,
1925796c8dcSSimon Schubert 				       sizeof (int), byte_order);
1935796c8dcSSimon Schubert       if (!first)
1945796c8dcSSimon Schubert 	fprintf_filtered (stream, ", ");
1955796c8dcSSimon Schubert       fprintf_filtered (stream, "%ld", arg_value);
1965796c8dcSSimon Schubert       first = 0;
1975796c8dcSSimon Schubert       start += sizeof (int);
1985796c8dcSSimon Schubert     }
1995796c8dcSSimon Schubert }
2005796c8dcSSimon Schubert 
201*a45ae5f8SJohn Marino /* Print single argument of inferior function.  ARG must be already
202*a45ae5f8SJohn Marino    read in.
203*a45ae5f8SJohn Marino 
204*a45ae5f8SJohn Marino    Errors are printed as if they would be the parameter value.  Use zeroed ARG
205*a45ae5f8SJohn Marino    iff it should not be printed accoring to user settings.  */
206*a45ae5f8SJohn Marino 
207*a45ae5f8SJohn Marino static void
208*a45ae5f8SJohn Marino print_frame_arg (const struct frame_arg *arg)
209*a45ae5f8SJohn Marino {
210*a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
211*a45ae5f8SJohn Marino   volatile struct gdb_exception except;
212*a45ae5f8SJohn Marino   struct cleanup *old_chain;
213*a45ae5f8SJohn Marino   struct ui_stream *stb;
214*a45ae5f8SJohn Marino 
215*a45ae5f8SJohn Marino   stb = ui_out_stream_new (uiout);
216*a45ae5f8SJohn Marino   old_chain = make_cleanup_ui_out_stream_delete (stb);
217*a45ae5f8SJohn Marino 
218*a45ae5f8SJohn Marino   gdb_assert (!arg->val || !arg->error);
219*a45ae5f8SJohn Marino   gdb_assert (arg->entry_kind == print_entry_values_no
220*a45ae5f8SJohn Marino 	      || arg->entry_kind == print_entry_values_only
221*a45ae5f8SJohn Marino 	      || (!ui_out_is_mi_like_p (uiout)
222*a45ae5f8SJohn Marino 		  && arg->entry_kind == print_entry_values_compact));
223*a45ae5f8SJohn Marino 
224*a45ae5f8SJohn Marino   annotate_arg_begin ();
225*a45ae5f8SJohn Marino 
226*a45ae5f8SJohn Marino   make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
227*a45ae5f8SJohn Marino   fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
228*a45ae5f8SJohn Marino 			   SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
229*a45ae5f8SJohn Marino   if (arg->entry_kind == print_entry_values_compact)
230*a45ae5f8SJohn Marino     {
231*a45ae5f8SJohn Marino       /* It is OK to provide invalid MI-like stream as with
232*a45ae5f8SJohn Marino 	 PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
233*a45ae5f8SJohn Marino       fputs_filtered ("=", stb->stream);
234*a45ae5f8SJohn Marino 
235*a45ae5f8SJohn Marino       fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
236*a45ae5f8SJohn Marino 			       SYMBOL_LANGUAGE (arg->sym),
237*a45ae5f8SJohn Marino 			       DMGL_PARAMS | DMGL_ANSI);
238*a45ae5f8SJohn Marino     }
239*a45ae5f8SJohn Marino   if (arg->entry_kind == print_entry_values_only
240*a45ae5f8SJohn Marino       || arg->entry_kind == print_entry_values_compact)
241*a45ae5f8SJohn Marino     fputs_filtered ("@entry", stb->stream);
242*a45ae5f8SJohn Marino   ui_out_field_stream (uiout, "name", stb);
243*a45ae5f8SJohn Marino   annotate_arg_name_end ();
244*a45ae5f8SJohn Marino   ui_out_text (uiout, "=");
245*a45ae5f8SJohn Marino 
246*a45ae5f8SJohn Marino   if (!arg->val && !arg->error)
247*a45ae5f8SJohn Marino     ui_out_text (uiout, "...");
248*a45ae5f8SJohn Marino   else
249*a45ae5f8SJohn Marino     {
250*a45ae5f8SJohn Marino       if (arg->error)
251*a45ae5f8SJohn Marino 	except.message = arg->error;
252*a45ae5f8SJohn Marino       else
253*a45ae5f8SJohn Marino 	{
254*a45ae5f8SJohn Marino 	  /* TRY_CATCH has two statements, wrap it in a block.  */
255*a45ae5f8SJohn Marino 
256*a45ae5f8SJohn Marino 	  TRY_CATCH (except, RETURN_MASK_ERROR)
257*a45ae5f8SJohn Marino 	    {
258*a45ae5f8SJohn Marino 	      const struct language_defn *language;
259*a45ae5f8SJohn Marino 	      struct value_print_options opts;
260*a45ae5f8SJohn Marino 
261*a45ae5f8SJohn Marino 	      /* Avoid value_print because it will deref ref parameters.  We
262*a45ae5f8SJohn Marino 		 just want to print their addresses.  Print ??? for args whose
263*a45ae5f8SJohn Marino 		 address we do not know.  We pass 2 as "recurse" to val_print
264*a45ae5f8SJohn Marino 		 because our standard indentation here is 4 spaces, and
265*a45ae5f8SJohn Marino 		 val_print indents 2 for each recurse.  */
266*a45ae5f8SJohn Marino 
267*a45ae5f8SJohn Marino 	      annotate_arg_value (value_type (arg->val));
268*a45ae5f8SJohn Marino 
269*a45ae5f8SJohn Marino 	      /* Use the appropriate language to display our symbol, unless the
270*a45ae5f8SJohn Marino 		 user forced the language to a specific language.  */
271*a45ae5f8SJohn Marino 	      if (language_mode == language_mode_auto)
272*a45ae5f8SJohn Marino 		language = language_def (SYMBOL_LANGUAGE (arg->sym));
273*a45ae5f8SJohn Marino 	      else
274*a45ae5f8SJohn Marino 		language = current_language;
275*a45ae5f8SJohn Marino 
276*a45ae5f8SJohn Marino 	      get_raw_print_options (&opts);
277*a45ae5f8SJohn Marino 	      opts.deref_ref = 1;
278*a45ae5f8SJohn Marino 
279*a45ae5f8SJohn Marino 	      /* True in "summary" mode, false otherwise.  */
280*a45ae5f8SJohn Marino 	      opts.summary = !strcmp (print_frame_arguments, "scalars");
281*a45ae5f8SJohn Marino 
282*a45ae5f8SJohn Marino 	      common_val_print (arg->val, stb->stream, 2, &opts, language);
283*a45ae5f8SJohn Marino 	    }
284*a45ae5f8SJohn Marino 	}
285*a45ae5f8SJohn Marino       if (except.message)
286*a45ae5f8SJohn Marino 	fprintf_filtered (stb->stream, _("<error reading variable: %s>"),
287*a45ae5f8SJohn Marino 			  except.message);
288*a45ae5f8SJohn Marino     }
289*a45ae5f8SJohn Marino 
290*a45ae5f8SJohn Marino   ui_out_field_stream (uiout, "value", stb);
291*a45ae5f8SJohn Marino 
292*a45ae5f8SJohn Marino   /* Aleo invoke ui_out_tuple_end.  */
293*a45ae5f8SJohn Marino   do_cleanups (old_chain);
294*a45ae5f8SJohn Marino 
295*a45ae5f8SJohn Marino   annotate_arg_end ();
296*a45ae5f8SJohn Marino }
297*a45ae5f8SJohn Marino 
298*a45ae5f8SJohn Marino /* Read in inferior function parameter SYM at FRAME into ARGP.  Caller is
299*a45ae5f8SJohn Marino    responsible for xfree of ARGP->ERROR.  This function never throws an
300*a45ae5f8SJohn Marino    exception.  */
301*a45ae5f8SJohn Marino 
302*a45ae5f8SJohn Marino void
303*a45ae5f8SJohn Marino read_frame_arg (struct symbol *sym, struct frame_info *frame,
304*a45ae5f8SJohn Marino 	        struct frame_arg *argp, struct frame_arg *entryargp)
305*a45ae5f8SJohn Marino {
306*a45ae5f8SJohn Marino   struct value *val = NULL, *entryval = NULL;
307*a45ae5f8SJohn Marino   char *val_error = NULL, *entryval_error = NULL;
308*a45ae5f8SJohn Marino   int val_equal = 0;
309*a45ae5f8SJohn Marino   volatile struct gdb_exception except;
310*a45ae5f8SJohn Marino 
311*a45ae5f8SJohn Marino   if (print_entry_values != print_entry_values_only
312*a45ae5f8SJohn Marino       && print_entry_values != print_entry_values_preferred)
313*a45ae5f8SJohn Marino     {
314*a45ae5f8SJohn Marino       TRY_CATCH (except, RETURN_MASK_ERROR)
315*a45ae5f8SJohn Marino 	{
316*a45ae5f8SJohn Marino 	  val = read_var_value (sym, frame);
317*a45ae5f8SJohn Marino 	}
318*a45ae5f8SJohn Marino       if (!val)
319*a45ae5f8SJohn Marino 	{
320*a45ae5f8SJohn Marino 	  val_error = alloca (strlen (except.message) + 1);
321*a45ae5f8SJohn Marino 	  strcpy (val_error, except.message);
322*a45ae5f8SJohn Marino 	}
323*a45ae5f8SJohn Marino     }
324*a45ae5f8SJohn Marino 
325*a45ae5f8SJohn Marino   if (SYMBOL_CLASS (sym) == LOC_COMPUTED
326*a45ae5f8SJohn Marino       && print_entry_values != print_entry_values_no
327*a45ae5f8SJohn Marino       && (print_entry_values != print_entry_values_if_needed
328*a45ae5f8SJohn Marino 	  || !val || value_optimized_out (val)))
329*a45ae5f8SJohn Marino     {
330*a45ae5f8SJohn Marino       TRY_CATCH (except, RETURN_MASK_ERROR)
331*a45ae5f8SJohn Marino 	{
332*a45ae5f8SJohn Marino 	  const struct symbol_computed_ops *ops;
333*a45ae5f8SJohn Marino 
334*a45ae5f8SJohn Marino 	  ops = SYMBOL_COMPUTED_OPS (sym);
335*a45ae5f8SJohn Marino 	  entryval = ops->read_variable_at_entry (sym, frame);
336*a45ae5f8SJohn Marino 	}
337*a45ae5f8SJohn Marino       if (!entryval)
338*a45ae5f8SJohn Marino 	{
339*a45ae5f8SJohn Marino 	  entryval_error = alloca (strlen (except.message) + 1);
340*a45ae5f8SJohn Marino 	  strcpy (entryval_error, except.message);
341*a45ae5f8SJohn Marino 	}
342*a45ae5f8SJohn Marino 
343*a45ae5f8SJohn Marino       if (except.error == NO_ENTRY_VALUE_ERROR
344*a45ae5f8SJohn Marino 	  || (entryval && value_optimized_out (entryval)))
345*a45ae5f8SJohn Marino 	{
346*a45ae5f8SJohn Marino 	  entryval = NULL;
347*a45ae5f8SJohn Marino 	  entryval_error = NULL;
348*a45ae5f8SJohn Marino 	}
349*a45ae5f8SJohn Marino 
350*a45ae5f8SJohn Marino       if (print_entry_values == print_entry_values_compact
351*a45ae5f8SJohn Marino 	  || print_entry_values == print_entry_values_default)
352*a45ae5f8SJohn Marino 	{
353*a45ae5f8SJohn Marino 	  /* For MI do not try to use print_entry_values_compact for ARGP.  */
354*a45ae5f8SJohn Marino 
355*a45ae5f8SJohn Marino 	  if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
356*a45ae5f8SJohn Marino 	    {
357*a45ae5f8SJohn Marino 	      unsigned len = TYPE_LENGTH (value_type (val));
358*a45ae5f8SJohn Marino 
359*a45ae5f8SJohn Marino 	      if (!value_optimized_out (val) && value_lazy (val))
360*a45ae5f8SJohn Marino 		value_fetch_lazy (val);
361*a45ae5f8SJohn Marino 	      if (!value_optimized_out (val) && value_lazy (entryval))
362*a45ae5f8SJohn Marino 		value_fetch_lazy (entryval);
363*a45ae5f8SJohn Marino 	      if (!value_optimized_out (val)
364*a45ae5f8SJohn Marino 		  && value_available_contents_eq (val, 0, entryval, 0, len))
365*a45ae5f8SJohn Marino 		{
366*a45ae5f8SJohn Marino 		  /* Initialize it just to avoid a GCC false warning.  */
367*a45ae5f8SJohn Marino 		  struct value *val_deref = NULL, *entryval_deref;
368*a45ae5f8SJohn Marino 
369*a45ae5f8SJohn Marino 		  /* DW_AT_GNU_call_site_value does match with the current
370*a45ae5f8SJohn Marino 		     value.  If it is a reference still try to verify if
371*a45ae5f8SJohn Marino 		     dereferenced DW_AT_GNU_call_site_data_value does not
372*a45ae5f8SJohn Marino 		     differ.  */
373*a45ae5f8SJohn Marino 
374*a45ae5f8SJohn Marino 		  TRY_CATCH (except, RETURN_MASK_ERROR)
375*a45ae5f8SJohn Marino 		    {
376*a45ae5f8SJohn Marino 		      unsigned len_deref;
377*a45ae5f8SJohn Marino 
378*a45ae5f8SJohn Marino 		      val_deref = coerce_ref (val);
379*a45ae5f8SJohn Marino 		      if (value_lazy (val_deref))
380*a45ae5f8SJohn Marino 			value_fetch_lazy (val_deref);
381*a45ae5f8SJohn Marino 		      len_deref = TYPE_LENGTH (value_type (val_deref));
382*a45ae5f8SJohn Marino 
383*a45ae5f8SJohn Marino 		      entryval_deref = coerce_ref (entryval);
384*a45ae5f8SJohn Marino 		      if (value_lazy (entryval_deref))
385*a45ae5f8SJohn Marino 			value_fetch_lazy (entryval_deref);
386*a45ae5f8SJohn Marino 
387*a45ae5f8SJohn Marino 		      /* If the reference addresses match but dereferenced
388*a45ae5f8SJohn Marino 			 content does not match print them.  */
389*a45ae5f8SJohn Marino 		      if (val != val_deref
390*a45ae5f8SJohn Marino 			  && value_available_contents_eq (val_deref, 0,
391*a45ae5f8SJohn Marino 							  entryval_deref, 0,
392*a45ae5f8SJohn Marino 							  len_deref))
393*a45ae5f8SJohn Marino 			val_equal = 1;
394*a45ae5f8SJohn Marino 		    }
395*a45ae5f8SJohn Marino 
396*a45ae5f8SJohn Marino 		  /* Value was not a reference; and its content matches.  */
397*a45ae5f8SJohn Marino 		  if (val == val_deref)
398*a45ae5f8SJohn Marino 		    val_equal = 1;
399*a45ae5f8SJohn Marino 		  /* If the dereferenced content could not be fetched do not
400*a45ae5f8SJohn Marino 		     display anything.  */
401*a45ae5f8SJohn Marino 		  else if (except.error == NO_ENTRY_VALUE_ERROR)
402*a45ae5f8SJohn Marino 		    val_equal = 1;
403*a45ae5f8SJohn Marino 		  else if (except.message)
404*a45ae5f8SJohn Marino 		    {
405*a45ae5f8SJohn Marino 		      entryval_error = alloca (strlen (except.message) + 1);
406*a45ae5f8SJohn Marino 		      strcpy (entryval_error, except.message);
407*a45ae5f8SJohn Marino 		    }
408*a45ae5f8SJohn Marino 
409*a45ae5f8SJohn Marino 		  if (val_equal)
410*a45ae5f8SJohn Marino 		    entryval = NULL;
411*a45ae5f8SJohn Marino 		}
412*a45ae5f8SJohn Marino 	    }
413*a45ae5f8SJohn Marino 
414*a45ae5f8SJohn Marino 	  /* Try to remove possibly duplicate error message for ENTRYARGP even
415*a45ae5f8SJohn Marino 	     in MI mode.  */
416*a45ae5f8SJohn Marino 
417*a45ae5f8SJohn Marino 	  if (val_error && entryval_error
418*a45ae5f8SJohn Marino 	      && strcmp (val_error, entryval_error) == 0)
419*a45ae5f8SJohn Marino 	    {
420*a45ae5f8SJohn Marino 	      entryval_error = NULL;
421*a45ae5f8SJohn Marino 
422*a45ae5f8SJohn Marino 	      /* Do not se VAL_EQUAL as the same error message may be shown for
423*a45ae5f8SJohn Marino 		 the entry value even if no entry values are present in the
424*a45ae5f8SJohn Marino 		 inferior.  */
425*a45ae5f8SJohn Marino 	    }
426*a45ae5f8SJohn Marino 	}
427*a45ae5f8SJohn Marino     }
428*a45ae5f8SJohn Marino 
429*a45ae5f8SJohn Marino   if (entryval == NULL)
430*a45ae5f8SJohn Marino     {
431*a45ae5f8SJohn Marino       if (print_entry_values == print_entry_values_preferred)
432*a45ae5f8SJohn Marino 	{
433*a45ae5f8SJohn Marino 	  TRY_CATCH (except, RETURN_MASK_ERROR)
434*a45ae5f8SJohn Marino 	    {
435*a45ae5f8SJohn Marino 	      val = read_var_value (sym, frame);
436*a45ae5f8SJohn Marino 	    }
437*a45ae5f8SJohn Marino 	  if (!val)
438*a45ae5f8SJohn Marino 	    {
439*a45ae5f8SJohn Marino 	      val_error = alloca (strlen (except.message) + 1);
440*a45ae5f8SJohn Marino 	      strcpy (val_error, except.message);
441*a45ae5f8SJohn Marino 	    }
442*a45ae5f8SJohn Marino 	}
443*a45ae5f8SJohn Marino       if (print_entry_values == print_entry_values_only
444*a45ae5f8SJohn Marino 	  || print_entry_values == print_entry_values_both
445*a45ae5f8SJohn Marino 	  || (print_entry_values == print_entry_values_preferred
446*a45ae5f8SJohn Marino 	      && (!val || value_optimized_out (val))))
447*a45ae5f8SJohn Marino 	entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
448*a45ae5f8SJohn Marino     }
449*a45ae5f8SJohn Marino   if ((print_entry_values == print_entry_values_compact
450*a45ae5f8SJohn Marino        || print_entry_values == print_entry_values_if_needed
451*a45ae5f8SJohn Marino        || print_entry_values == print_entry_values_preferred)
452*a45ae5f8SJohn Marino       && (!val || value_optimized_out (val)) && entryval != NULL)
453*a45ae5f8SJohn Marino     {
454*a45ae5f8SJohn Marino       val = NULL;
455*a45ae5f8SJohn Marino       val_error = NULL;
456*a45ae5f8SJohn Marino     }
457*a45ae5f8SJohn Marino 
458*a45ae5f8SJohn Marino   argp->sym = sym;
459*a45ae5f8SJohn Marino   argp->val = val;
460*a45ae5f8SJohn Marino   argp->error = val_error ? xstrdup (val_error) : NULL;
461*a45ae5f8SJohn Marino   if (!val && !val_error)
462*a45ae5f8SJohn Marino     argp->entry_kind = print_entry_values_only;
463*a45ae5f8SJohn Marino   else if ((print_entry_values == print_entry_values_compact
464*a45ae5f8SJohn Marino 	   || print_entry_values == print_entry_values_default) && val_equal)
465*a45ae5f8SJohn Marino     {
466*a45ae5f8SJohn Marino       argp->entry_kind = print_entry_values_compact;
467*a45ae5f8SJohn Marino       gdb_assert (!ui_out_is_mi_like_p (current_uiout));
468*a45ae5f8SJohn Marino     }
469*a45ae5f8SJohn Marino   else
470*a45ae5f8SJohn Marino     argp->entry_kind = print_entry_values_no;
471*a45ae5f8SJohn Marino 
472*a45ae5f8SJohn Marino   entryargp->sym = sym;
473*a45ae5f8SJohn Marino   entryargp->val = entryval;
474*a45ae5f8SJohn Marino   entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
475*a45ae5f8SJohn Marino   if (!entryval && !entryval_error)
476*a45ae5f8SJohn Marino     entryargp->entry_kind = print_entry_values_no;
477*a45ae5f8SJohn Marino   else
478*a45ae5f8SJohn Marino     entryargp->entry_kind = print_entry_values_only;
479*a45ae5f8SJohn Marino }
480*a45ae5f8SJohn Marino 
4815796c8dcSSimon Schubert /* Print the arguments of frame FRAME on STREAM, given the function
4825796c8dcSSimon Schubert    FUNC running in that frame (as a symbol), where NUM is the number
4835796c8dcSSimon Schubert    of arguments according to the stack frame (or -1 if the number of
4845796c8dcSSimon Schubert    arguments is unknown).  */
4855796c8dcSSimon Schubert 
4865796c8dcSSimon Schubert /* Note that currently the "number of arguments according to the
4875796c8dcSSimon Schubert    stack frame" is only known on VAX where i refers to the "number of
4885796c8dcSSimon Schubert    ints of arguments according to the stack frame".  */
4895796c8dcSSimon Schubert 
4905796c8dcSSimon Schubert static void
4915796c8dcSSimon Schubert print_frame_args (struct symbol *func, struct frame_info *frame,
4925796c8dcSSimon Schubert 		  int num, struct ui_file *stream)
4935796c8dcSSimon Schubert {
494*a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
4955796c8dcSSimon Schubert   int first = 1;
4965796c8dcSSimon Schubert   /* Offset of next stack argument beyond the one we have seen that is
4975796c8dcSSimon Schubert      at the highest offset, or -1 if we haven't come to a stack
4985796c8dcSSimon Schubert      argument yet.  */
4995796c8dcSSimon Schubert   long highest_offset = -1;
5005796c8dcSSimon Schubert   /* Number of ints of arguments that we have printed so far.  */
5015796c8dcSSimon Schubert   int args_printed = 0;
5025796c8dcSSimon Schubert   struct cleanup *old_chain, *list_chain;
5035796c8dcSSimon Schubert   struct ui_stream *stb;
5045796c8dcSSimon Schubert   /* True if we should print arguments, false otherwise.  */
5055796c8dcSSimon Schubert   int print_args = strcmp (print_frame_arguments, "none");
5065796c8dcSSimon Schubert   /* True in "summary" mode, false otherwise.  */
5075796c8dcSSimon Schubert   int summary = !strcmp (print_frame_arguments, "scalars");
5085796c8dcSSimon Schubert 
5095796c8dcSSimon Schubert   stb = ui_out_stream_new (uiout);
5105796c8dcSSimon Schubert   old_chain = make_cleanup_ui_out_stream_delete (stb);
5115796c8dcSSimon Schubert 
5125796c8dcSSimon Schubert   if (func)
5135796c8dcSSimon Schubert     {
5145796c8dcSSimon Schubert       struct block *b = SYMBOL_BLOCK_VALUE (func);
5155796c8dcSSimon Schubert       struct dict_iterator iter;
5165796c8dcSSimon Schubert       struct symbol *sym;
5175796c8dcSSimon Schubert 
5185796c8dcSSimon Schubert       ALL_BLOCK_SYMBOLS (b, iter, sym)
5195796c8dcSSimon Schubert         {
520*a45ae5f8SJohn Marino 	  struct frame_arg arg, entryarg;
521*a45ae5f8SJohn Marino 
5225796c8dcSSimon Schubert 	  QUIT;
5235796c8dcSSimon Schubert 
5245796c8dcSSimon Schubert 	  /* Keep track of the highest stack argument offset seen, and
5255796c8dcSSimon Schubert 	     skip over any kinds of symbols we don't care about.  */
5265796c8dcSSimon Schubert 
5275796c8dcSSimon Schubert 	  if (!SYMBOL_IS_ARGUMENT (sym))
5285796c8dcSSimon Schubert 	    continue;
5295796c8dcSSimon Schubert 
5305796c8dcSSimon Schubert 	  switch (SYMBOL_CLASS (sym))
5315796c8dcSSimon Schubert 	    {
5325796c8dcSSimon Schubert 	    case LOC_ARG:
5335796c8dcSSimon Schubert 	    case LOC_REF_ARG:
5345796c8dcSSimon Schubert 	      {
5355796c8dcSSimon Schubert 		long current_offset = SYMBOL_VALUE (sym);
5365796c8dcSSimon Schubert 		int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
5375796c8dcSSimon Schubert 
5385796c8dcSSimon Schubert 		/* Compute address of next argument by adding the size of
5395796c8dcSSimon Schubert 		   this argument and rounding to an int boundary.  */
5405796c8dcSSimon Schubert 		current_offset =
5415796c8dcSSimon Schubert 		  ((current_offset + arg_size + sizeof (int) - 1)
5425796c8dcSSimon Schubert 		   & ~(sizeof (int) - 1));
5435796c8dcSSimon Schubert 
5445796c8dcSSimon Schubert 		/* If this is the highest offset seen yet, set
5455796c8dcSSimon Schubert 		   highest_offset.  */
5465796c8dcSSimon Schubert 		if (highest_offset == -1
5475796c8dcSSimon Schubert 		    || (current_offset > highest_offset))
5485796c8dcSSimon Schubert 		  highest_offset = current_offset;
5495796c8dcSSimon Schubert 
5505796c8dcSSimon Schubert 		/* Add the number of ints we're about to print to
5515796c8dcSSimon Schubert 		   args_printed.  */
5525796c8dcSSimon Schubert 		args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
5535796c8dcSSimon Schubert 	      }
5545796c8dcSSimon Schubert 
5555796c8dcSSimon Schubert 	      /* We care about types of symbols, but don't need to
5565796c8dcSSimon Schubert 		 keep track of stack offsets in them.  */
5575796c8dcSSimon Schubert 	    case LOC_REGISTER:
5585796c8dcSSimon Schubert 	    case LOC_REGPARM_ADDR:
5595796c8dcSSimon Schubert 	    case LOC_COMPUTED:
5605796c8dcSSimon Schubert 	    case LOC_OPTIMIZED_OUT:
5615796c8dcSSimon Schubert 	    default:
5625796c8dcSSimon Schubert 	      break;
5635796c8dcSSimon Schubert 	    }
5645796c8dcSSimon Schubert 
5655796c8dcSSimon Schubert 	  /* We have to look up the symbol because arguments can have
5665796c8dcSSimon Schubert 	     two entries (one a parameter, one a local) and the one we
5675796c8dcSSimon Schubert 	     want is the local, which lookup_symbol will find for us.
5685796c8dcSSimon Schubert 	     This includes gcc1 (not gcc2) on SPARC when passing a
5695796c8dcSSimon Schubert 	     small structure and gcc2 when the argument type is float
5705796c8dcSSimon Schubert 	     and it is passed as a double and converted to float by
5715796c8dcSSimon Schubert 	     the prologue (in the latter case the type of the LOC_ARG
5725796c8dcSSimon Schubert 	     symbol is double and the type of the LOC_LOCAL symbol is
5735796c8dcSSimon Schubert 	     float).  */
5745796c8dcSSimon Schubert 	  /* But if the parameter name is null, don't try it.  Null
5755796c8dcSSimon Schubert 	     parameter names occur on the RS/6000, for traceback
5765796c8dcSSimon Schubert 	     tables.  FIXME, should we even print them?  */
5775796c8dcSSimon Schubert 
5785796c8dcSSimon Schubert 	  if (*SYMBOL_LINKAGE_NAME (sym))
5795796c8dcSSimon Schubert 	    {
5805796c8dcSSimon Schubert 	      struct symbol *nsym;
581cf7f2e2dSJohn Marino 
5825796c8dcSSimon Schubert 	      nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
5835796c8dcSSimon Schubert 				    b, VAR_DOMAIN, NULL);
5845796c8dcSSimon Schubert 	      gdb_assert (nsym != NULL);
5855796c8dcSSimon Schubert 	      if (SYMBOL_CLASS (nsym) == LOC_REGISTER
5865796c8dcSSimon Schubert 		  && !SYMBOL_IS_ARGUMENT (nsym))
5875796c8dcSSimon Schubert 		{
5885796c8dcSSimon Schubert 		  /* There is a LOC_ARG/LOC_REGISTER pair.  This means
5895796c8dcSSimon Schubert 		     that it was passed on the stack and loaded into a
5905796c8dcSSimon Schubert 		     register, or passed in a register and stored in a
5915796c8dcSSimon Schubert 		     stack slot.  GDB 3.x used the LOC_ARG; GDB
5925796c8dcSSimon Schubert 		     4.0-4.11 used the LOC_REGISTER.
5935796c8dcSSimon Schubert 
5945796c8dcSSimon Schubert 		     Reasons for using the LOC_ARG:
5955796c8dcSSimon Schubert 
5965796c8dcSSimon Schubert 		     (1) Because find_saved_registers may be slow for
5975796c8dcSSimon Schubert 		         remote debugging.
5985796c8dcSSimon Schubert 
5995796c8dcSSimon Schubert 		     (2) Because registers are often re-used and stack
6005796c8dcSSimon Schubert 		         slots rarely (never?) are.  Therefore using
6015796c8dcSSimon Schubert 		         the stack slot is much less likely to print
6025796c8dcSSimon Schubert 		         garbage.
6035796c8dcSSimon Schubert 
6045796c8dcSSimon Schubert 		     Reasons why we might want to use the LOC_REGISTER:
6055796c8dcSSimon Schubert 
6065796c8dcSSimon Schubert 		     (1) So that the backtrace prints the same value
6075796c8dcSSimon Schubert 		         as "print foo".  I see no compelling reason
6085796c8dcSSimon Schubert 		         why this needs to be the case; having the
6095796c8dcSSimon Schubert 		         backtrace print the value which was passed
6105796c8dcSSimon Schubert 		         in, and "print foo" print the value as
6115796c8dcSSimon Schubert 		         modified within the called function, makes
6125796c8dcSSimon Schubert 		         perfect sense to me.
6135796c8dcSSimon Schubert 
6145796c8dcSSimon Schubert 		     Additional note: It might be nice if "info args"
6155796c8dcSSimon Schubert 		     displayed both values.
6165796c8dcSSimon Schubert 
6175796c8dcSSimon Schubert 		     One more note: There is a case with SPARC
6185796c8dcSSimon Schubert 		     structure passing where we need to use the
6195796c8dcSSimon Schubert 		     LOC_REGISTER, but this is dealt with by creating
6205796c8dcSSimon Schubert 		     a single LOC_REGPARM in symbol reading.  */
6215796c8dcSSimon Schubert 
6225796c8dcSSimon Schubert 		  /* Leave sym (the LOC_ARG) alone.  */
6235796c8dcSSimon Schubert 		  ;
6245796c8dcSSimon Schubert 		}
6255796c8dcSSimon Schubert 	      else
6265796c8dcSSimon Schubert 		sym = nsym;
6275796c8dcSSimon Schubert 	    }
6285796c8dcSSimon Schubert 
6295796c8dcSSimon Schubert 	  /* Print the current arg.  */
6305796c8dcSSimon Schubert 	  if (!first)
6315796c8dcSSimon Schubert 	    ui_out_text (uiout, ", ");
6325796c8dcSSimon Schubert 	  ui_out_wrap_hint (uiout, "    ");
6335796c8dcSSimon Schubert 
634*a45ae5f8SJohn Marino 	  if (!print_args)
6355796c8dcSSimon Schubert 	    {
636*a45ae5f8SJohn Marino 	      memset (&arg, 0, sizeof (arg));
637*a45ae5f8SJohn Marino 	      arg.sym = sym;
638*a45ae5f8SJohn Marino 	      arg.entry_kind = print_entry_values_no;
639*a45ae5f8SJohn Marino 	      memset (&entryarg, 0, sizeof (entryarg));
640*a45ae5f8SJohn Marino 	      entryarg.sym = sym;
641*a45ae5f8SJohn Marino 	      entryarg.entry_kind = print_entry_values_no;
6425796c8dcSSimon Schubert 	    }
6435796c8dcSSimon Schubert 	  else
644*a45ae5f8SJohn Marino 	    read_frame_arg (sym, frame, &arg, &entryarg);
645*a45ae5f8SJohn Marino 
646*a45ae5f8SJohn Marino 	  if (arg.entry_kind != print_entry_values_only)
647*a45ae5f8SJohn Marino 	    print_frame_arg (&arg);
648*a45ae5f8SJohn Marino 
649*a45ae5f8SJohn Marino 	  if (entryarg.entry_kind != print_entry_values_no)
650*a45ae5f8SJohn Marino 	    {
651*a45ae5f8SJohn Marino 	      if (arg.entry_kind != print_entry_values_only)
652*a45ae5f8SJohn Marino 		{
653*a45ae5f8SJohn Marino 		  ui_out_text (uiout, ", ");
654*a45ae5f8SJohn Marino 		  ui_out_wrap_hint (uiout, "    ");
6555796c8dcSSimon Schubert 		}
6565796c8dcSSimon Schubert 
657*a45ae5f8SJohn Marino 	      print_frame_arg (&entryarg);
658*a45ae5f8SJohn Marino 	    }
6595796c8dcSSimon Schubert 
660*a45ae5f8SJohn Marino 	  xfree (arg.error);
661*a45ae5f8SJohn Marino 	  xfree (entryarg.error);
6625796c8dcSSimon Schubert 
6635796c8dcSSimon Schubert 	  first = 0;
6645796c8dcSSimon Schubert 	}
6655796c8dcSSimon Schubert     }
6665796c8dcSSimon Schubert 
6675796c8dcSSimon Schubert   /* Don't print nameless args in situations where we don't know
6685796c8dcSSimon Schubert      enough about the stack to find them.  */
6695796c8dcSSimon Schubert   if (num != -1)
6705796c8dcSSimon Schubert     {
6715796c8dcSSimon Schubert       long start;
6725796c8dcSSimon Schubert 
6735796c8dcSSimon Schubert       if (highest_offset == -1)
6745796c8dcSSimon Schubert 	start = gdbarch_frame_args_skip (get_frame_arch (frame));
6755796c8dcSSimon Schubert       else
6765796c8dcSSimon Schubert 	start = highest_offset;
6775796c8dcSSimon Schubert 
6785796c8dcSSimon Schubert       print_frame_nameless_args (frame, start, num - args_printed,
6795796c8dcSSimon Schubert 				 first, stream);
6805796c8dcSSimon Schubert     }
6815796c8dcSSimon Schubert 
6825796c8dcSSimon Schubert   do_cleanups (old_chain);
6835796c8dcSSimon Schubert }
6845796c8dcSSimon Schubert 
6855796c8dcSSimon Schubert /* Set the current source and line to the location given by frame
6865796c8dcSSimon Schubert    FRAME, if possible.  When CENTER is true, adjust so the relevant
6875796c8dcSSimon Schubert    line is in the center of the next 'list'.  */
6885796c8dcSSimon Schubert 
6895796c8dcSSimon Schubert void
6905796c8dcSSimon Schubert set_current_sal_from_frame (struct frame_info *frame, int center)
6915796c8dcSSimon Schubert {
6925796c8dcSSimon Schubert   struct symtab_and_line sal;
6935796c8dcSSimon Schubert 
6945796c8dcSSimon Schubert   find_frame_sal (frame, &sal);
6955796c8dcSSimon Schubert   if (sal.symtab)
6965796c8dcSSimon Schubert     {
6975796c8dcSSimon Schubert       if (center)
6985796c8dcSSimon Schubert         sal.line = max (sal.line - get_lines_to_list () / 2, 1);
6995796c8dcSSimon Schubert       set_current_source_symtab_and_line (&sal);
7005796c8dcSSimon Schubert     }
7015796c8dcSSimon Schubert }
7025796c8dcSSimon Schubert 
7035796c8dcSSimon Schubert /* If ON, GDB will display disassembly of the next source line when
7045796c8dcSSimon Schubert    execution of the program being debugged stops.
7055796c8dcSSimon Schubert    If AUTO (which is the default), or there's no line info to determine
7065796c8dcSSimon Schubert    the source line of the next instruction, display disassembly of next
7075796c8dcSSimon Schubert    instruction instead.  */
7085796c8dcSSimon Schubert 
7095796c8dcSSimon Schubert static enum auto_boolean disassemble_next_line;
7105796c8dcSSimon Schubert 
7115796c8dcSSimon Schubert static void
7125796c8dcSSimon Schubert show_disassemble_next_line (struct ui_file *file, int from_tty,
7135796c8dcSSimon Schubert 				 struct cmd_list_element *c,
7145796c8dcSSimon Schubert 				 const char *value)
7155796c8dcSSimon Schubert {
716c50c785cSJohn Marino   fprintf_filtered (file,
717c50c785cSJohn Marino 		    _("Debugger's willingness to use "
718c50c785cSJohn Marino 		      "disassemble-next-line is %s.\n"),
7195796c8dcSSimon Schubert                     value);
7205796c8dcSSimon Schubert }
7215796c8dcSSimon Schubert 
7225796c8dcSSimon Schubert /* Use TRY_CATCH to catch the exception from the gdb_disassembly
7235796c8dcSSimon Schubert    because it will be broken by filter sometime.  */
7245796c8dcSSimon Schubert 
7255796c8dcSSimon Schubert static void
7265796c8dcSSimon Schubert do_gdb_disassembly (struct gdbarch *gdbarch,
7275796c8dcSSimon Schubert 		    int how_many, CORE_ADDR low, CORE_ADDR high)
7285796c8dcSSimon Schubert {
7295796c8dcSSimon Schubert   volatile struct gdb_exception exception;
7305796c8dcSSimon Schubert 
731*a45ae5f8SJohn Marino   TRY_CATCH (exception, RETURN_MASK_ERROR)
7325796c8dcSSimon Schubert     {
733*a45ae5f8SJohn Marino       gdb_disassembly (gdbarch, current_uiout, 0,
734*a45ae5f8SJohn Marino 		       DISASSEMBLY_RAW_INSN, how_many,
735*a45ae5f8SJohn Marino 		       low, high);
7365796c8dcSSimon Schubert     }
737*a45ae5f8SJohn Marino   if (exception.reason < 0)
738*a45ae5f8SJohn Marino     {
7395796c8dcSSimon Schubert       /* If an exception was thrown while doing the disassembly, print
7405796c8dcSSimon Schubert 	 the error message, to give the user a clue of what happened.  */
7415796c8dcSSimon Schubert       exception_print (gdb_stderr, exception);
7425796c8dcSSimon Schubert     }
743*a45ae5f8SJohn Marino }
7445796c8dcSSimon Schubert 
7455796c8dcSSimon Schubert /* Print information about frame FRAME.  The output is format according
746*a45ae5f8SJohn Marino    to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS.  The meaning of
7475796c8dcSSimon Schubert    PRINT_WHAT is:
7485796c8dcSSimon Schubert 
7495796c8dcSSimon Schubert    SRC_LINE: Print only source line.
7505796c8dcSSimon Schubert    LOCATION: Print only location.
7515796c8dcSSimon Schubert    LOC_AND_SRC: Print location and source line.
7525796c8dcSSimon Schubert 
7535796c8dcSSimon Schubert    Used in "where" output, and to emit breakpoint or step
7545796c8dcSSimon Schubert    messages.  */
7555796c8dcSSimon Schubert 
7565796c8dcSSimon Schubert void
7575796c8dcSSimon Schubert print_frame_info (struct frame_info *frame, int print_level,
7585796c8dcSSimon Schubert 		  enum print_what print_what, int print_args)
7595796c8dcSSimon Schubert {
7605796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
7615796c8dcSSimon Schubert   struct symtab_and_line sal;
7625796c8dcSSimon Schubert   int source_print;
7635796c8dcSSimon Schubert   int location_print;
764*a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
7655796c8dcSSimon Schubert 
7665796c8dcSSimon Schubert   if (get_frame_type (frame) == DUMMY_FRAME
7675796c8dcSSimon Schubert       || get_frame_type (frame) == SIGTRAMP_FRAME
7685796c8dcSSimon Schubert       || get_frame_type (frame) == ARCH_FRAME)
7695796c8dcSSimon Schubert     {
7705796c8dcSSimon Schubert       struct cleanup *uiout_cleanup
7715796c8dcSSimon Schubert 	= make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
7725796c8dcSSimon Schubert 
7735796c8dcSSimon Schubert       annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
7745796c8dcSSimon Schubert 			    gdbarch, get_frame_pc (frame));
7755796c8dcSSimon Schubert 
7765796c8dcSSimon Schubert       /* Do this regardless of SOURCE because we don't have any source
7775796c8dcSSimon Schubert          to list for this frame.  */
7785796c8dcSSimon Schubert       if (print_level)
7795796c8dcSSimon Schubert         {
7805796c8dcSSimon Schubert           ui_out_text (uiout, "#");
7815796c8dcSSimon Schubert           ui_out_field_fmt_int (uiout, 2, ui_left, "level",
7825796c8dcSSimon Schubert 				frame_relative_level (frame));
7835796c8dcSSimon Schubert         }
7845796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
7855796c8dcSSimon Schubert         {
7865796c8dcSSimon Schubert           annotate_frame_address ();
7875796c8dcSSimon Schubert           ui_out_field_core_addr (uiout, "addr",
7885796c8dcSSimon Schubert 				  gdbarch, get_frame_pc (frame));
7895796c8dcSSimon Schubert           annotate_frame_address_end ();
7905796c8dcSSimon Schubert         }
7915796c8dcSSimon Schubert 
7925796c8dcSSimon Schubert       if (get_frame_type (frame) == DUMMY_FRAME)
7935796c8dcSSimon Schubert         {
7945796c8dcSSimon Schubert           annotate_function_call ();
7955796c8dcSSimon Schubert           ui_out_field_string (uiout, "func", "<function called from gdb>");
7965796c8dcSSimon Schubert 	}
7975796c8dcSSimon Schubert       else if (get_frame_type (frame) == SIGTRAMP_FRAME)
7985796c8dcSSimon Schubert         {
7995796c8dcSSimon Schubert 	  annotate_signal_handler_caller ();
8005796c8dcSSimon Schubert           ui_out_field_string (uiout, "func", "<signal handler called>");
8015796c8dcSSimon Schubert         }
8025796c8dcSSimon Schubert       else if (get_frame_type (frame) == ARCH_FRAME)
8035796c8dcSSimon Schubert         {
8045796c8dcSSimon Schubert           ui_out_field_string (uiout, "func", "<cross-architecture call>");
8055796c8dcSSimon Schubert 	}
8065796c8dcSSimon Schubert       ui_out_text (uiout, "\n");
8075796c8dcSSimon Schubert       annotate_frame_end ();
8085796c8dcSSimon Schubert 
8095796c8dcSSimon Schubert       do_cleanups (uiout_cleanup);
8105796c8dcSSimon Schubert       return;
8115796c8dcSSimon Schubert     }
8125796c8dcSSimon Schubert 
8135796c8dcSSimon Schubert   /* If FRAME is not the innermost frame, that normally means that
8145796c8dcSSimon Schubert      FRAME->pc points to *after* the call instruction, and we want to
8155796c8dcSSimon Schubert      get the line containing the call, never the next line.  But if
8165796c8dcSSimon Schubert      the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
8175796c8dcSSimon Schubert      next frame was not entered as the result of a call, and we want
8185796c8dcSSimon Schubert      to get the line containing FRAME->pc.  */
8195796c8dcSSimon Schubert   find_frame_sal (frame, &sal);
8205796c8dcSSimon Schubert 
8215796c8dcSSimon Schubert   location_print = (print_what == LOCATION
8225796c8dcSSimon Schubert 		    || print_what == LOC_AND_ADDRESS
8235796c8dcSSimon Schubert 		    || print_what == SRC_AND_LOC);
8245796c8dcSSimon Schubert 
8255796c8dcSSimon Schubert   if (location_print || !sal.symtab)
8265796c8dcSSimon Schubert     print_frame (frame, print_level, print_what, print_args, sal);
8275796c8dcSSimon Schubert 
8285796c8dcSSimon Schubert   source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
8295796c8dcSSimon Schubert 
8305796c8dcSSimon Schubert   /* If disassemble-next-line is set to auto or on and doesn't have
8315796c8dcSSimon Schubert      the line debug messages for $pc, output the next instruction.  */
8325796c8dcSSimon Schubert   if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
8335796c8dcSSimon Schubert        || disassemble_next_line == AUTO_BOOLEAN_TRUE)
8345796c8dcSSimon Schubert       && source_print && !sal.symtab)
8355796c8dcSSimon Schubert     do_gdb_disassembly (get_frame_arch (frame), 1,
8365796c8dcSSimon Schubert 			get_frame_pc (frame), get_frame_pc (frame) + 1);
8375796c8dcSSimon Schubert 
8385796c8dcSSimon Schubert   if (source_print && sal.symtab)
8395796c8dcSSimon Schubert     {
8405796c8dcSSimon Schubert       int done = 0;
8415796c8dcSSimon Schubert       int mid_statement = ((print_what == SRC_LINE)
8425796c8dcSSimon Schubert 			   && frame_show_address (frame, sal));
8435796c8dcSSimon Schubert 
8445796c8dcSSimon Schubert       if (annotation_level)
8455796c8dcSSimon Schubert 	done = identify_source_line (sal.symtab, sal.line, mid_statement,
8465796c8dcSSimon Schubert 				     get_frame_pc (frame));
8475796c8dcSSimon Schubert       if (!done)
8485796c8dcSSimon Schubert 	{
8495796c8dcSSimon Schubert 	  if (deprecated_print_frame_info_listing_hook)
8505796c8dcSSimon Schubert 	    deprecated_print_frame_info_listing_hook (sal.symtab,
8515796c8dcSSimon Schubert 						      sal.line,
8525796c8dcSSimon Schubert 						      sal.line + 1, 0);
8535796c8dcSSimon Schubert 	  else
8545796c8dcSSimon Schubert 	    {
8555796c8dcSSimon Schubert 	      struct value_print_options opts;
856cf7f2e2dSJohn Marino 
8575796c8dcSSimon Schubert 	      get_user_print_options (&opts);
8585796c8dcSSimon Schubert 	      /* We used to do this earlier, but that is clearly
8595796c8dcSSimon Schubert 		 wrong.  This function is used by many different
8605796c8dcSSimon Schubert 		 parts of gdb, including normal_stop in infrun.c,
8615796c8dcSSimon Schubert 		 which uses this to print out the current PC
8625796c8dcSSimon Schubert 		 when we stepi/nexti into the middle of a source
8635796c8dcSSimon Schubert 		 line.  Only the command line really wants this
8645796c8dcSSimon Schubert 		 behavior.  Other UIs probably would like the
8655796c8dcSSimon Schubert 		 ability to decide for themselves if it is desired.  */
8665796c8dcSSimon Schubert 	      if (opts.addressprint && mid_statement)
8675796c8dcSSimon Schubert 		{
8685796c8dcSSimon Schubert 		  ui_out_field_core_addr (uiout, "addr",
8695796c8dcSSimon Schubert 					  gdbarch, get_frame_pc (frame));
8705796c8dcSSimon Schubert 		  ui_out_text (uiout, "\t");
8715796c8dcSSimon Schubert 		}
8725796c8dcSSimon Schubert 
8735796c8dcSSimon Schubert 	      print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
8745796c8dcSSimon Schubert 	    }
8755796c8dcSSimon Schubert 	}
8765796c8dcSSimon Schubert 
8775796c8dcSSimon Schubert       /* If disassemble-next-line is set to on and there is line debug
8785796c8dcSSimon Schubert          messages, output assembly codes for next line.  */
8795796c8dcSSimon Schubert       if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
880cf7f2e2dSJohn Marino 	do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
8815796c8dcSSimon Schubert     }
8825796c8dcSSimon Schubert 
8835796c8dcSSimon Schubert   if (print_what != LOCATION)
884c50c785cSJohn Marino     {
885c50c785cSJohn Marino       CORE_ADDR pc;
886c50c785cSJohn Marino 
887c50c785cSJohn Marino       if (get_frame_pc_if_available (frame, &pc))
888*a45ae5f8SJohn Marino 	set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
889c50c785cSJohn Marino       else
890*a45ae5f8SJohn Marino 	set_last_displayed_sal (0, 0, 0, 0, 0);
891c50c785cSJohn Marino     }
8925796c8dcSSimon Schubert 
8935796c8dcSSimon Schubert   annotate_frame_end ();
8945796c8dcSSimon Schubert 
8955796c8dcSSimon Schubert   gdb_flush (gdb_stdout);
8965796c8dcSSimon Schubert }
8975796c8dcSSimon Schubert 
898*a45ae5f8SJohn Marino /* Remember the last symtab and line we displayed, which we use e.g.
899*a45ae5f8SJohn Marino  * as the place to put a breakpoint when the `break' command is
900*a45ae5f8SJohn Marino  * invoked with no arguments.  */
901*a45ae5f8SJohn Marino 
902*a45ae5f8SJohn Marino static void
903*a45ae5f8SJohn Marino set_last_displayed_sal (int valid, struct program_space *pspace,
904*a45ae5f8SJohn Marino 			CORE_ADDR addr, struct symtab *symtab,
905*a45ae5f8SJohn Marino 			int line)
906*a45ae5f8SJohn Marino {
907*a45ae5f8SJohn Marino   last_displayed_sal_valid = valid;
908*a45ae5f8SJohn Marino   last_displayed_pspace = pspace;
909*a45ae5f8SJohn Marino   last_displayed_addr = addr;
910*a45ae5f8SJohn Marino   last_displayed_symtab = symtab;
911*a45ae5f8SJohn Marino   last_displayed_line = line;
912*a45ae5f8SJohn Marino }
913*a45ae5f8SJohn Marino 
914*a45ae5f8SJohn Marino /* Forget the last sal we displayed.  */
915*a45ae5f8SJohn Marino 
916*a45ae5f8SJohn Marino void
917*a45ae5f8SJohn Marino clear_last_displayed_sal (void)
918*a45ae5f8SJohn Marino {
919*a45ae5f8SJohn Marino   last_displayed_sal_valid = 0;
920*a45ae5f8SJohn Marino   last_displayed_pspace = 0;
921*a45ae5f8SJohn Marino   last_displayed_addr = 0;
922*a45ae5f8SJohn Marino   last_displayed_symtab = 0;
923*a45ae5f8SJohn Marino   last_displayed_line = 0;
924*a45ae5f8SJohn Marino }
925*a45ae5f8SJohn Marino 
926*a45ae5f8SJohn Marino /* Is our record of the last sal we displayed valid?  If not,
927*a45ae5f8SJohn Marino  * the get_last_displayed_* functions will return NULL or 0, as
928*a45ae5f8SJohn Marino  * appropriate.  */
929*a45ae5f8SJohn Marino 
930*a45ae5f8SJohn Marino int
931*a45ae5f8SJohn Marino last_displayed_sal_is_valid (void)
932*a45ae5f8SJohn Marino {
933*a45ae5f8SJohn Marino   return last_displayed_sal_valid;
934*a45ae5f8SJohn Marino }
935*a45ae5f8SJohn Marino 
936*a45ae5f8SJohn Marino /* Get the pspace of the last sal we displayed, if it's valid.  */
937*a45ae5f8SJohn Marino 
938*a45ae5f8SJohn Marino struct program_space *
939*a45ae5f8SJohn Marino get_last_displayed_pspace (void)
940*a45ae5f8SJohn Marino {
941*a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
942*a45ae5f8SJohn Marino     return last_displayed_pspace;
943*a45ae5f8SJohn Marino   return 0;
944*a45ae5f8SJohn Marino }
945*a45ae5f8SJohn Marino 
946*a45ae5f8SJohn Marino /* Get the address of the last sal we displayed, if it's valid.  */
947*a45ae5f8SJohn Marino 
948*a45ae5f8SJohn Marino CORE_ADDR
949*a45ae5f8SJohn Marino get_last_displayed_addr (void)
950*a45ae5f8SJohn Marino {
951*a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
952*a45ae5f8SJohn Marino     return last_displayed_addr;
953*a45ae5f8SJohn Marino   return 0;
954*a45ae5f8SJohn Marino }
955*a45ae5f8SJohn Marino 
956*a45ae5f8SJohn Marino /* Get the symtab of the last sal we displayed, if it's valid.  */
957*a45ae5f8SJohn Marino 
958*a45ae5f8SJohn Marino struct symtab*
959*a45ae5f8SJohn Marino get_last_displayed_symtab (void)
960*a45ae5f8SJohn Marino {
961*a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
962*a45ae5f8SJohn Marino     return last_displayed_symtab;
963*a45ae5f8SJohn Marino   return 0;
964*a45ae5f8SJohn Marino }
965*a45ae5f8SJohn Marino 
966*a45ae5f8SJohn Marino /* Get the line of the last sal we displayed, if it's valid.  */
967*a45ae5f8SJohn Marino 
968*a45ae5f8SJohn Marino int
969*a45ae5f8SJohn Marino get_last_displayed_line (void)
970*a45ae5f8SJohn Marino {
971*a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
972*a45ae5f8SJohn Marino     return last_displayed_line;
973*a45ae5f8SJohn Marino   return 0;
974*a45ae5f8SJohn Marino }
975*a45ae5f8SJohn Marino 
976*a45ae5f8SJohn Marino /* Get the last sal we displayed, if it's valid.  */
977*a45ae5f8SJohn Marino 
978*a45ae5f8SJohn Marino void
979*a45ae5f8SJohn Marino get_last_displayed_sal (struct symtab_and_line *sal)
980*a45ae5f8SJohn Marino {
981*a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
982*a45ae5f8SJohn Marino     {
983*a45ae5f8SJohn Marino       sal->pspace = last_displayed_pspace;
984*a45ae5f8SJohn Marino       sal->pc = last_displayed_addr;
985*a45ae5f8SJohn Marino       sal->symtab = last_displayed_symtab;
986*a45ae5f8SJohn Marino       sal->line = last_displayed_line;
987*a45ae5f8SJohn Marino     }
988*a45ae5f8SJohn Marino   else
989*a45ae5f8SJohn Marino     {
990*a45ae5f8SJohn Marino       sal->pspace = 0;
991*a45ae5f8SJohn Marino       sal->pc = 0;
992*a45ae5f8SJohn Marino       sal->symtab = 0;
993*a45ae5f8SJohn Marino       sal->line = 0;
994*a45ae5f8SJohn Marino     }
995*a45ae5f8SJohn Marino }
996*a45ae5f8SJohn Marino 
997*a45ae5f8SJohn Marino 
998c50c785cSJohn Marino /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
999c50c785cSJohn Marino    corresponding to FRAME.  */
1000c50c785cSJohn Marino 
10015796c8dcSSimon Schubert void
10025796c8dcSSimon Schubert find_frame_funname (struct frame_info *frame, char **funname,
1003c50c785cSJohn Marino 		    enum language *funlang, struct symbol **funcp)
10045796c8dcSSimon Schubert {
10055796c8dcSSimon Schubert   struct symbol *func;
10065796c8dcSSimon Schubert 
10075796c8dcSSimon Schubert   *funname = NULL;
10085796c8dcSSimon Schubert   *funlang = language_unknown;
1009c50c785cSJohn Marino   if (funcp)
1010c50c785cSJohn Marino     *funcp = NULL;
10115796c8dcSSimon Schubert 
10125796c8dcSSimon Schubert   func = get_frame_function (frame);
10135796c8dcSSimon Schubert   if (func)
10145796c8dcSSimon Schubert     {
10155796c8dcSSimon Schubert       /* In certain pathological cases, the symtabs give the wrong
10165796c8dcSSimon Schubert          function (when we are in the first function in a file which
10175796c8dcSSimon Schubert          is compiled without debugging symbols, the previous function
10185796c8dcSSimon Schubert          is compiled with debugging symbols, and the "foo.o" symbol
10195796c8dcSSimon Schubert          that is supposed to tell us where the file with debugging
10205796c8dcSSimon Schubert          symbols ends has been truncated by ar because it is longer
10215796c8dcSSimon Schubert          than 15 characters).  This also occurs if the user uses asm()
10225796c8dcSSimon Schubert          to create a function but not stabs for it (in a file compiled
10235796c8dcSSimon Schubert          with -g).
10245796c8dcSSimon Schubert 
10255796c8dcSSimon Schubert          So look in the minimal symbol tables as well, and if it comes
10265796c8dcSSimon Schubert          up with a larger address for the function use that instead.
10275796c8dcSSimon Schubert          I don't think this can ever cause any problems; there
10285796c8dcSSimon Schubert          shouldn't be any minimal symbols in the middle of a function;
10295796c8dcSSimon Schubert          if this is ever changed many parts of GDB will need to be
10305796c8dcSSimon Schubert          changed (and we'll create a find_pc_minimal_function or some
10315796c8dcSSimon Schubert          such).  */
10325796c8dcSSimon Schubert 
10335796c8dcSSimon Schubert       struct minimal_symbol *msymbol = NULL;
10345796c8dcSSimon Schubert 
10355796c8dcSSimon Schubert       /* Don't attempt to do this for inlined functions, which do not
10365796c8dcSSimon Schubert 	 have a corresponding minimal symbol.  */
10375796c8dcSSimon Schubert       if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
10385796c8dcSSimon Schubert 	msymbol
10395796c8dcSSimon Schubert 	  = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
10405796c8dcSSimon Schubert 
10415796c8dcSSimon Schubert       if (msymbol != NULL
10425796c8dcSSimon Schubert 	  && (SYMBOL_VALUE_ADDRESS (msymbol)
10435796c8dcSSimon Schubert 	      > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
10445796c8dcSSimon Schubert 	{
10455796c8dcSSimon Schubert 	  /* We also don't know anything about the function besides
10465796c8dcSSimon Schubert 	     its address and name.  */
10475796c8dcSSimon Schubert 	  func = 0;
10485796c8dcSSimon Schubert 	  *funname = SYMBOL_PRINT_NAME (msymbol);
10495796c8dcSSimon Schubert 	  *funlang = SYMBOL_LANGUAGE (msymbol);
10505796c8dcSSimon Schubert 	}
10515796c8dcSSimon Schubert       else
10525796c8dcSSimon Schubert 	{
10535796c8dcSSimon Schubert 	  *funname = SYMBOL_PRINT_NAME (func);
10545796c8dcSSimon Schubert 	  *funlang = SYMBOL_LANGUAGE (func);
1055c50c785cSJohn Marino 	  if (funcp)
1056c50c785cSJohn Marino 	    *funcp = func;
10575796c8dcSSimon Schubert 	  if (*funlang == language_cplus)
10585796c8dcSSimon Schubert 	    {
10595796c8dcSSimon Schubert 	      /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
10605796c8dcSSimon Schubert 		 to display the demangled name that we already have
10615796c8dcSSimon Schubert 		 stored in the symbol table, but we stored a version
10625796c8dcSSimon Schubert 		 with DMGL_PARAMS turned on, and here we don't want to
10635796c8dcSSimon Schubert 		 display parameters.  So remove the parameters.  */
10645796c8dcSSimon Schubert 	      char *func_only = cp_remove_params (*funname);
1065cf7f2e2dSJohn Marino 
10665796c8dcSSimon Schubert 	      if (func_only)
10675796c8dcSSimon Schubert 		{
10685796c8dcSSimon Schubert 		  *funname = func_only;
10695796c8dcSSimon Schubert 		  make_cleanup (xfree, func_only);
10705796c8dcSSimon Schubert 		}
10715796c8dcSSimon Schubert 	    }
10725796c8dcSSimon Schubert 	}
10735796c8dcSSimon Schubert     }
10745796c8dcSSimon Schubert   else
10755796c8dcSSimon Schubert     {
1076c50c785cSJohn Marino       struct minimal_symbol *msymbol;
1077c50c785cSJohn Marino       CORE_ADDR pc;
10785796c8dcSSimon Schubert 
1079c50c785cSJohn Marino       if (!get_frame_address_in_block_if_available (frame, &pc))
1080c50c785cSJohn Marino 	return;
1081c50c785cSJohn Marino 
1082c50c785cSJohn Marino       msymbol = lookup_minimal_symbol_by_pc (pc);
10835796c8dcSSimon Schubert       if (msymbol != NULL)
10845796c8dcSSimon Schubert 	{
10855796c8dcSSimon Schubert 	  *funname = SYMBOL_PRINT_NAME (msymbol);
10865796c8dcSSimon Schubert 	  *funlang = SYMBOL_LANGUAGE (msymbol);
10875796c8dcSSimon Schubert 	}
10885796c8dcSSimon Schubert     }
10895796c8dcSSimon Schubert }
10905796c8dcSSimon Schubert 
10915796c8dcSSimon Schubert static void
10925796c8dcSSimon Schubert print_frame (struct frame_info *frame, int print_level,
10935796c8dcSSimon Schubert 	     enum print_what print_what, int print_args,
10945796c8dcSSimon Schubert 	     struct symtab_and_line sal)
10955796c8dcSSimon Schubert {
10965796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
1097*a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
10985796c8dcSSimon Schubert   char *funname = NULL;
10995796c8dcSSimon Schubert   enum language funlang = language_unknown;
11005796c8dcSSimon Schubert   struct ui_stream *stb;
11015796c8dcSSimon Schubert   struct cleanup *old_chain, *list_chain;
11025796c8dcSSimon Schubert   struct value_print_options opts;
1103c50c785cSJohn Marino   struct symbol *func;
1104c50c785cSJohn Marino   CORE_ADDR pc = 0;
1105c50c785cSJohn Marino   int pc_p;
1106c50c785cSJohn Marino 
1107c50c785cSJohn Marino   pc_p = get_frame_pc_if_available (frame, &pc);
11085796c8dcSSimon Schubert 
11095796c8dcSSimon Schubert   stb = ui_out_stream_new (uiout);
11105796c8dcSSimon Schubert   old_chain = make_cleanup_ui_out_stream_delete (stb);
11115796c8dcSSimon Schubert 
1112c50c785cSJohn Marino   find_frame_funname (frame, &funname, &funlang, &func);
11135796c8dcSSimon Schubert 
11145796c8dcSSimon Schubert   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
1115c50c785cSJohn Marino 			gdbarch, pc);
11165796c8dcSSimon Schubert 
11175796c8dcSSimon Schubert   list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
11185796c8dcSSimon Schubert 
11195796c8dcSSimon Schubert   if (print_level)
11205796c8dcSSimon Schubert     {
11215796c8dcSSimon Schubert       ui_out_text (uiout, "#");
11225796c8dcSSimon Schubert       ui_out_field_fmt_int (uiout, 2, ui_left, "level",
11235796c8dcSSimon Schubert 			    frame_relative_level (frame));
11245796c8dcSSimon Schubert     }
11255796c8dcSSimon Schubert   get_user_print_options (&opts);
11265796c8dcSSimon Schubert   if (opts.addressprint)
1127c50c785cSJohn Marino     if (!sal.symtab
1128c50c785cSJohn Marino 	|| frame_show_address (frame, sal)
11295796c8dcSSimon Schubert 	|| print_what == LOC_AND_ADDRESS)
11305796c8dcSSimon Schubert       {
11315796c8dcSSimon Schubert 	annotate_frame_address ();
1132c50c785cSJohn Marino 	if (pc_p)
1133c50c785cSJohn Marino 	  ui_out_field_core_addr (uiout, "addr", gdbarch, pc);
1134c50c785cSJohn Marino 	else
1135c50c785cSJohn Marino 	  ui_out_field_string (uiout, "addr", "<unavailable>");
11365796c8dcSSimon Schubert 	annotate_frame_address_end ();
11375796c8dcSSimon Schubert 	ui_out_text (uiout, " in ");
11385796c8dcSSimon Schubert       }
11395796c8dcSSimon Schubert   annotate_frame_function_name ();
11405796c8dcSSimon Schubert   fprintf_symbol_filtered (stb->stream, funname ? funname : "??",
11415796c8dcSSimon Schubert 			   funlang, DMGL_ANSI);
11425796c8dcSSimon Schubert   ui_out_field_stream (uiout, "func", stb);
11435796c8dcSSimon Schubert   ui_out_wrap_hint (uiout, "   ");
11445796c8dcSSimon Schubert   annotate_frame_args ();
11455796c8dcSSimon Schubert 
11465796c8dcSSimon Schubert   ui_out_text (uiout, " (");
11475796c8dcSSimon Schubert   if (print_args)
11485796c8dcSSimon Schubert     {
1149*a45ae5f8SJohn Marino       struct gdbarch *gdbarch = get_frame_arch (frame);
1150*a45ae5f8SJohn Marino       int numargs;
11515796c8dcSSimon Schubert       struct cleanup *args_list_chain;
1152*a45ae5f8SJohn Marino       volatile struct gdb_exception e;
1153cf7f2e2dSJohn Marino 
1154*a45ae5f8SJohn Marino       if (gdbarch_frame_num_args_p (gdbarch))
1155*a45ae5f8SJohn Marino 	{
1156*a45ae5f8SJohn Marino 	  numargs = gdbarch_frame_num_args (gdbarch, frame);
1157*a45ae5f8SJohn Marino 	  gdb_assert (numargs >= 0);
1158*a45ae5f8SJohn Marino 	}
1159*a45ae5f8SJohn Marino       else
1160*a45ae5f8SJohn Marino 	numargs = -1;
1161*a45ae5f8SJohn Marino 
11625796c8dcSSimon Schubert       args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
1163*a45ae5f8SJohn Marino       TRY_CATCH (e, RETURN_MASK_ERROR)
1164*a45ae5f8SJohn Marino 	{
1165*a45ae5f8SJohn Marino 	  print_frame_args (func, frame, numargs, gdb_stdout);
1166*a45ae5f8SJohn Marino 	}
11675796c8dcSSimon Schubert       /* FIXME: ARGS must be a list.  If one argument is a string it
11685796c8dcSSimon Schubert 	  will have " that will not be properly escaped.  */
11695796c8dcSSimon Schubert       /* Invoke ui_out_tuple_end.  */
11705796c8dcSSimon Schubert       do_cleanups (args_list_chain);
11715796c8dcSSimon Schubert       QUIT;
11725796c8dcSSimon Schubert     }
11735796c8dcSSimon Schubert   ui_out_text (uiout, ")");
11745796c8dcSSimon Schubert   if (sal.symtab && sal.symtab->filename)
11755796c8dcSSimon Schubert     {
11765796c8dcSSimon Schubert       annotate_frame_source_begin ();
11775796c8dcSSimon Schubert       ui_out_wrap_hint (uiout, "   ");
11785796c8dcSSimon Schubert       ui_out_text (uiout, " at ");
11795796c8dcSSimon Schubert       annotate_frame_source_file ();
11805796c8dcSSimon Schubert       ui_out_field_string (uiout, "file", sal.symtab->filename);
11815796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
11825796c8dcSSimon Schubert 	{
11835796c8dcSSimon Schubert 	  const char *fullname = symtab_to_fullname (sal.symtab);
1184cf7f2e2dSJohn Marino 
11855796c8dcSSimon Schubert 	  if (fullname != NULL)
11865796c8dcSSimon Schubert 	    ui_out_field_string (uiout, "fullname", fullname);
11875796c8dcSSimon Schubert 	}
11885796c8dcSSimon Schubert       annotate_frame_source_file_end ();
11895796c8dcSSimon Schubert       ui_out_text (uiout, ":");
11905796c8dcSSimon Schubert       annotate_frame_source_line ();
11915796c8dcSSimon Schubert       ui_out_field_int (uiout, "line", sal.line);
11925796c8dcSSimon Schubert       annotate_frame_source_end ();
11935796c8dcSSimon Schubert     }
11945796c8dcSSimon Schubert 
1195c50c785cSJohn Marino   if (pc_p && (!funname || (!sal.symtab || !sal.symtab->filename)))
11965796c8dcSSimon Schubert     {
11975796c8dcSSimon Schubert #ifdef PC_SOLIB
11985796c8dcSSimon Schubert       char *lib = PC_SOLIB (get_frame_pc (frame));
11995796c8dcSSimon Schubert #else
1200cf7f2e2dSJohn Marino       char *lib = solib_name_from_address (get_frame_program_space (frame),
1201cf7f2e2dSJohn Marino 					   get_frame_pc (frame));
12025796c8dcSSimon Schubert #endif
12035796c8dcSSimon Schubert       if (lib)
12045796c8dcSSimon Schubert 	{
12055796c8dcSSimon Schubert 	  annotate_frame_where ();
12065796c8dcSSimon Schubert 	  ui_out_wrap_hint (uiout, "  ");
12075796c8dcSSimon Schubert 	  ui_out_text (uiout, " from ");
12085796c8dcSSimon Schubert 	  ui_out_field_string (uiout, "from", lib);
12095796c8dcSSimon Schubert 	}
12105796c8dcSSimon Schubert     }
12115796c8dcSSimon Schubert 
12125796c8dcSSimon Schubert   /* do_cleanups will call ui_out_tuple_end() for us.  */
12135796c8dcSSimon Schubert   do_cleanups (list_chain);
12145796c8dcSSimon Schubert   ui_out_text (uiout, "\n");
12155796c8dcSSimon Schubert   do_cleanups (old_chain);
12165796c8dcSSimon Schubert }
12175796c8dcSSimon Schubert 
12185796c8dcSSimon Schubert 
12195796c8dcSSimon Schubert /* Read a frame specification in whatever the appropriate format is
12205796c8dcSSimon Schubert    from FRAME_EXP.  Call error(), printing MESSAGE, if the
12215796c8dcSSimon Schubert    specification is in any way invalid (so this function never returns
12225796c8dcSSimon Schubert    NULL).  When SEPECTED_P is non-NULL set its target to indicate that
12235796c8dcSSimon Schubert    the default selected frame was used.  */
12245796c8dcSSimon Schubert 
12255796c8dcSSimon Schubert static struct frame_info *
12265796c8dcSSimon Schubert parse_frame_specification_1 (const char *frame_exp, const char *message,
12275796c8dcSSimon Schubert 			     int *selected_frame_p)
12285796c8dcSSimon Schubert {
12295796c8dcSSimon Schubert   int numargs;
12305796c8dcSSimon Schubert   struct value *args[4];
12315796c8dcSSimon Schubert   CORE_ADDR addrs[ARRAY_SIZE (args)];
12325796c8dcSSimon Schubert 
12335796c8dcSSimon Schubert   if (frame_exp == NULL)
12345796c8dcSSimon Schubert     numargs = 0;
12355796c8dcSSimon Schubert   else
12365796c8dcSSimon Schubert     {
12375796c8dcSSimon Schubert       numargs = 0;
12385796c8dcSSimon Schubert       while (1)
12395796c8dcSSimon Schubert 	{
12405796c8dcSSimon Schubert 	  char *addr_string;
12415796c8dcSSimon Schubert 	  struct cleanup *cleanup;
12425796c8dcSSimon Schubert 	  const char *p;
12435796c8dcSSimon Schubert 
12445796c8dcSSimon Schubert 	  /* Skip leading white space, bail of EOL.  */
12455796c8dcSSimon Schubert 	  while (isspace (*frame_exp))
12465796c8dcSSimon Schubert 	    frame_exp++;
12475796c8dcSSimon Schubert 	  if (!*frame_exp)
12485796c8dcSSimon Schubert 	    break;
12495796c8dcSSimon Schubert 
12505796c8dcSSimon Schubert 	  /* Parse the argument, extract it, save it.  */
12515796c8dcSSimon Schubert 	  for (p = frame_exp;
12525796c8dcSSimon Schubert 	       *p && !isspace (*p);
12535796c8dcSSimon Schubert 	       p++);
12545796c8dcSSimon Schubert 	  addr_string = savestring (frame_exp, p - frame_exp);
12555796c8dcSSimon Schubert 	  frame_exp = p;
12565796c8dcSSimon Schubert 	  cleanup = make_cleanup (xfree, addr_string);
12575796c8dcSSimon Schubert 
12585796c8dcSSimon Schubert 	  /* NOTE: Parse and evaluate expression, but do not use
12595796c8dcSSimon Schubert 	     functions such as parse_and_eval_long or
12605796c8dcSSimon Schubert 	     parse_and_eval_address to also extract the value.
12615796c8dcSSimon Schubert 	     Instead value_as_long and value_as_address are used.
12625796c8dcSSimon Schubert 	     This avoids problems with expressions that contain
12635796c8dcSSimon Schubert 	     side-effects.  */
12645796c8dcSSimon Schubert 	  if (numargs >= ARRAY_SIZE (args))
12655796c8dcSSimon Schubert 	    error (_("Too many args in frame specification"));
12665796c8dcSSimon Schubert 	  args[numargs++] = parse_and_eval (addr_string);
12675796c8dcSSimon Schubert 
12685796c8dcSSimon Schubert 	  do_cleanups (cleanup);
12695796c8dcSSimon Schubert 	}
12705796c8dcSSimon Schubert     }
12715796c8dcSSimon Schubert 
12725796c8dcSSimon Schubert   /* If no args, default to the selected frame.  */
12735796c8dcSSimon Schubert   if (numargs == 0)
12745796c8dcSSimon Schubert     {
12755796c8dcSSimon Schubert       if (selected_frame_p != NULL)
12765796c8dcSSimon Schubert 	(*selected_frame_p) = 1;
12775796c8dcSSimon Schubert       return get_selected_frame (message);
12785796c8dcSSimon Schubert     }
12795796c8dcSSimon Schubert 
12805796c8dcSSimon Schubert   /* None of the remaining use the selected frame.  */
12815796c8dcSSimon Schubert   if (selected_frame_p != NULL)
12825796c8dcSSimon Schubert     (*selected_frame_p) = 0;
12835796c8dcSSimon Schubert 
12845796c8dcSSimon Schubert   /* Assume the single arg[0] is an integer, and try using that to
12855796c8dcSSimon Schubert      select a frame relative to current.  */
12865796c8dcSSimon Schubert   if (numargs == 1)
12875796c8dcSSimon Schubert     {
12885796c8dcSSimon Schubert       struct frame_info *fid;
12895796c8dcSSimon Schubert       int level = value_as_long (args[0]);
1290cf7f2e2dSJohn Marino 
12915796c8dcSSimon Schubert       fid = find_relative_frame (get_current_frame (), &level);
12925796c8dcSSimon Schubert       if (level == 0)
1293c50c785cSJohn Marino 	/* find_relative_frame was successful.  */
12945796c8dcSSimon Schubert 	return fid;
12955796c8dcSSimon Schubert     }
12965796c8dcSSimon Schubert 
12975796c8dcSSimon Schubert   /* Convert each value into a corresponding address.  */
12985796c8dcSSimon Schubert   {
12995796c8dcSSimon Schubert     int i;
1300cf7f2e2dSJohn Marino 
13015796c8dcSSimon Schubert     for (i = 0; i < numargs; i++)
13025796c8dcSSimon Schubert       addrs[i] = value_as_address (args[i]);
13035796c8dcSSimon Schubert   }
13045796c8dcSSimon Schubert 
13055796c8dcSSimon Schubert   /* Assume that the single arg[0] is an address, use that to identify
13065796c8dcSSimon Schubert      a frame with a matching ID.  Should this also accept stack/pc or
13075796c8dcSSimon Schubert      stack/pc/special.  */
13085796c8dcSSimon Schubert   if (numargs == 1)
13095796c8dcSSimon Schubert     {
13105796c8dcSSimon Schubert       struct frame_id id = frame_id_build_wild (addrs[0]);
13115796c8dcSSimon Schubert       struct frame_info *fid;
13125796c8dcSSimon Schubert 
13135796c8dcSSimon Schubert       /* If (s)he specifies the frame with an address, he deserves
13145796c8dcSSimon Schubert 	 what (s)he gets.  Still, give the highest one that matches.
13155796c8dcSSimon Schubert 	 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
13165796c8dcSSimon Schubert 	 know).  */
13175796c8dcSSimon Schubert       for (fid = get_current_frame ();
13185796c8dcSSimon Schubert 	   fid != NULL;
13195796c8dcSSimon Schubert 	   fid = get_prev_frame (fid))
13205796c8dcSSimon Schubert 	{
13215796c8dcSSimon Schubert 	  if (frame_id_eq (id, get_frame_id (fid)))
13225796c8dcSSimon Schubert 	    {
13235796c8dcSSimon Schubert 	      struct frame_info *prev_frame;
13245796c8dcSSimon Schubert 
13255796c8dcSSimon Schubert 	      while (1)
13265796c8dcSSimon Schubert 		{
13275796c8dcSSimon Schubert 		  prev_frame = get_prev_frame (fid);
13285796c8dcSSimon Schubert 		  if (!prev_frame
13295796c8dcSSimon Schubert 		      || !frame_id_eq (id, get_frame_id (prev_frame)))
13305796c8dcSSimon Schubert 		    break;
13315796c8dcSSimon Schubert 		  fid = prev_frame;
13325796c8dcSSimon Schubert 		}
13335796c8dcSSimon Schubert 	      return fid;
13345796c8dcSSimon Schubert 	    }
13355796c8dcSSimon Schubert 	}
13365796c8dcSSimon Schubert       }
13375796c8dcSSimon Schubert 
13385796c8dcSSimon Schubert   /* We couldn't identify the frame as an existing frame, but
13395796c8dcSSimon Schubert      perhaps we can create one with a single argument.  */
13405796c8dcSSimon Schubert   if (numargs == 1)
13415796c8dcSSimon Schubert     return create_new_frame (addrs[0], 0);
13425796c8dcSSimon Schubert   else if (numargs == 2)
13435796c8dcSSimon Schubert     return create_new_frame (addrs[0], addrs[1]);
13445796c8dcSSimon Schubert   else
13455796c8dcSSimon Schubert     error (_("Too many args in frame specification"));
13465796c8dcSSimon Schubert }
13475796c8dcSSimon Schubert 
13485796c8dcSSimon Schubert static struct frame_info *
13495796c8dcSSimon Schubert parse_frame_specification (char *frame_exp)
13505796c8dcSSimon Schubert {
13515796c8dcSSimon Schubert   return parse_frame_specification_1 (frame_exp, NULL, NULL);
13525796c8dcSSimon Schubert }
13535796c8dcSSimon Schubert 
13545796c8dcSSimon Schubert /* Print verbosely the selected frame or the frame at address
13555796c8dcSSimon Schubert    ADDR_EXP.  Absolutely all information in the frame is printed.  */
13565796c8dcSSimon Schubert 
13575796c8dcSSimon Schubert static void
13585796c8dcSSimon Schubert frame_info (char *addr_exp, int from_tty)
13595796c8dcSSimon Schubert {
13605796c8dcSSimon Schubert   struct frame_info *fi;
13615796c8dcSSimon Schubert   struct symtab_and_line sal;
13625796c8dcSSimon Schubert   struct symbol *func;
13635796c8dcSSimon Schubert   struct symtab *s;
13645796c8dcSSimon Schubert   struct frame_info *calling_frame_info;
1365cf7f2e2dSJohn Marino   int numregs;
13665796c8dcSSimon Schubert   char *funname = 0;
13675796c8dcSSimon Schubert   enum language funlang = language_unknown;
13685796c8dcSSimon Schubert   const char *pc_regname;
13695796c8dcSSimon Schubert   int selected_frame_p;
13705796c8dcSSimon Schubert   struct gdbarch *gdbarch;
13715796c8dcSSimon Schubert   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
1372c50c785cSJohn Marino   CORE_ADDR frame_pc;
1373c50c785cSJohn Marino   int frame_pc_p;
1374c50c785cSJohn Marino   CORE_ADDR caller_pc;
13755796c8dcSSimon Schubert 
13765796c8dcSSimon Schubert   fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
13775796c8dcSSimon Schubert   gdbarch = get_frame_arch (fi);
13785796c8dcSSimon Schubert 
13795796c8dcSSimon Schubert   /* Name of the value returned by get_frame_pc().  Per comments, "pc"
13805796c8dcSSimon Schubert      is not a good name.  */
13815796c8dcSSimon Schubert   if (gdbarch_pc_regnum (gdbarch) >= 0)
13825796c8dcSSimon Schubert     /* OK, this is weird.  The gdbarch_pc_regnum hardware register's value can
13835796c8dcSSimon Schubert        easily not match that of the internal value returned by
13845796c8dcSSimon Schubert        get_frame_pc().  */
13855796c8dcSSimon Schubert     pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
13865796c8dcSSimon Schubert   else
13875796c8dcSSimon Schubert     /* But then, this is weird to.  Even without gdbarch_pc_regnum, an
13885796c8dcSSimon Schubert        architectures will often have a hardware register called "pc",
13895796c8dcSSimon Schubert        and that register's value, again, can easily not match
13905796c8dcSSimon Schubert        get_frame_pc().  */
13915796c8dcSSimon Schubert     pc_regname = "pc";
13925796c8dcSSimon Schubert 
1393c50c785cSJohn Marino   frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
13945796c8dcSSimon Schubert   find_frame_sal (fi, &sal);
13955796c8dcSSimon Schubert   func = get_frame_function (fi);
1396c50c785cSJohn Marino   s = sal.symtab;
13975796c8dcSSimon Schubert   if (func)
13985796c8dcSSimon Schubert     {
13995796c8dcSSimon Schubert       funname = SYMBOL_PRINT_NAME (func);
14005796c8dcSSimon Schubert       funlang = SYMBOL_LANGUAGE (func);
14015796c8dcSSimon Schubert       if (funlang == language_cplus)
14025796c8dcSSimon Schubert 	{
14035796c8dcSSimon Schubert 	  /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
14045796c8dcSSimon Schubert 	     to display the demangled name that we already have
14055796c8dcSSimon Schubert 	     stored in the symbol table, but we stored a version
14065796c8dcSSimon Schubert 	     with DMGL_PARAMS turned on, and here we don't want to
14075796c8dcSSimon Schubert 	     display parameters.  So remove the parameters.  */
14085796c8dcSSimon Schubert 	  char *func_only = cp_remove_params (funname);
1409cf7f2e2dSJohn Marino 
14105796c8dcSSimon Schubert 	  if (func_only)
14115796c8dcSSimon Schubert 	    {
14125796c8dcSSimon Schubert 	      funname = func_only;
14135796c8dcSSimon Schubert 	      make_cleanup (xfree, func_only);
14145796c8dcSSimon Schubert 	    }
14155796c8dcSSimon Schubert 	}
14165796c8dcSSimon Schubert     }
1417c50c785cSJohn Marino   else if (frame_pc_p)
14185796c8dcSSimon Schubert     {
14195796c8dcSSimon Schubert       struct minimal_symbol *msymbol;
14205796c8dcSSimon Schubert 
1421c50c785cSJohn Marino       msymbol = lookup_minimal_symbol_by_pc (frame_pc);
14225796c8dcSSimon Schubert       if (msymbol != NULL)
14235796c8dcSSimon Schubert 	{
14245796c8dcSSimon Schubert 	  funname = SYMBOL_PRINT_NAME (msymbol);
14255796c8dcSSimon Schubert 	  funlang = SYMBOL_LANGUAGE (msymbol);
14265796c8dcSSimon Schubert 	}
14275796c8dcSSimon Schubert     }
14285796c8dcSSimon Schubert   calling_frame_info = get_prev_frame (fi);
14295796c8dcSSimon Schubert 
14305796c8dcSSimon Schubert   if (selected_frame_p && frame_relative_level (fi) >= 0)
14315796c8dcSSimon Schubert     {
14325796c8dcSSimon Schubert       printf_filtered (_("Stack level %d, frame at "),
14335796c8dcSSimon Schubert 		       frame_relative_level (fi));
14345796c8dcSSimon Schubert     }
14355796c8dcSSimon Schubert   else
14365796c8dcSSimon Schubert     {
14375796c8dcSSimon Schubert       printf_filtered (_("Stack frame at "));
14385796c8dcSSimon Schubert     }
14395796c8dcSSimon Schubert   fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
14405796c8dcSSimon Schubert   printf_filtered (":\n");
14415796c8dcSSimon Schubert   printf_filtered (" %s = ", pc_regname);
1442c50c785cSJohn Marino   if (frame_pc_p)
14435796c8dcSSimon Schubert     fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
1444c50c785cSJohn Marino   else
1445c50c785cSJohn Marino     fputs_filtered ("<unavailable>", gdb_stdout);
14465796c8dcSSimon Schubert 
14475796c8dcSSimon Schubert   wrap_here ("   ");
14485796c8dcSSimon Schubert   if (funname)
14495796c8dcSSimon Schubert     {
14505796c8dcSSimon Schubert       printf_filtered (" in ");
14515796c8dcSSimon Schubert       fprintf_symbol_filtered (gdb_stdout, funname, funlang,
14525796c8dcSSimon Schubert 			       DMGL_ANSI | DMGL_PARAMS);
14535796c8dcSSimon Schubert     }
14545796c8dcSSimon Schubert   wrap_here ("   ");
14555796c8dcSSimon Schubert   if (sal.symtab)
14565796c8dcSSimon Schubert     printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
14575796c8dcSSimon Schubert   puts_filtered ("; ");
14585796c8dcSSimon Schubert   wrap_here ("    ");
14595796c8dcSSimon Schubert   printf_filtered ("saved %s ", pc_regname);
1460c50c785cSJohn Marino   if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
1461c50c785cSJohn Marino     fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
1462c50c785cSJohn Marino   else
1463c50c785cSJohn Marino     fputs_filtered ("<unavailable>", gdb_stdout);
14645796c8dcSSimon Schubert   printf_filtered ("\n");
14655796c8dcSSimon Schubert 
14665796c8dcSSimon Schubert   if (calling_frame_info == NULL)
14675796c8dcSSimon Schubert     {
14685796c8dcSSimon Schubert       enum unwind_stop_reason reason;
14695796c8dcSSimon Schubert 
14705796c8dcSSimon Schubert       reason = get_frame_unwind_stop_reason (fi);
14715796c8dcSSimon Schubert       if (reason != UNWIND_NO_REASON)
14725796c8dcSSimon Schubert 	printf_filtered (_(" Outermost frame: %s\n"),
14735796c8dcSSimon Schubert 			 frame_stop_reason_string (reason));
14745796c8dcSSimon Schubert     }
1475*a45ae5f8SJohn Marino   else if (get_frame_type (fi) == TAILCALL_FRAME)
1476*a45ae5f8SJohn Marino     puts_filtered (" tail call frame");
14775796c8dcSSimon Schubert   else if (get_frame_type (fi) == INLINE_FRAME)
14785796c8dcSSimon Schubert     printf_filtered (" inlined into frame %d",
14795796c8dcSSimon Schubert 		     frame_relative_level (get_prev_frame (fi)));
14805796c8dcSSimon Schubert   else
14815796c8dcSSimon Schubert     {
14825796c8dcSSimon Schubert       printf_filtered (" called by frame at ");
14835796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
14845796c8dcSSimon Schubert 		      gdb_stdout);
14855796c8dcSSimon Schubert     }
14865796c8dcSSimon Schubert   if (get_next_frame (fi) && calling_frame_info)
14875796c8dcSSimon Schubert     puts_filtered (",");
14885796c8dcSSimon Schubert   wrap_here ("   ");
14895796c8dcSSimon Schubert   if (get_next_frame (fi))
14905796c8dcSSimon Schubert     {
14915796c8dcSSimon Schubert       printf_filtered (" caller of frame at ");
14925796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
14935796c8dcSSimon Schubert 		      gdb_stdout);
14945796c8dcSSimon Schubert     }
14955796c8dcSSimon Schubert   if (get_next_frame (fi) || calling_frame_info)
14965796c8dcSSimon Schubert     puts_filtered ("\n");
14975796c8dcSSimon Schubert 
14985796c8dcSSimon Schubert   if (s)
14995796c8dcSSimon Schubert     printf_filtered (" source language %s.\n",
15005796c8dcSSimon Schubert 		     language_str (s->language));
15015796c8dcSSimon Schubert 
15025796c8dcSSimon Schubert   {
15035796c8dcSSimon Schubert     /* Address of the argument list for this frame, or 0.  */
15045796c8dcSSimon Schubert     CORE_ADDR arg_list = get_frame_args_address (fi);
15055796c8dcSSimon Schubert     /* Number of args for this frame, or -1 if unknown.  */
15065796c8dcSSimon Schubert     int numargs;
15075796c8dcSSimon Schubert 
15085796c8dcSSimon Schubert     if (arg_list == 0)
15095796c8dcSSimon Schubert       printf_filtered (" Arglist at unknown address.\n");
15105796c8dcSSimon Schubert     else
15115796c8dcSSimon Schubert       {
15125796c8dcSSimon Schubert 	printf_filtered (" Arglist at ");
15135796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
15145796c8dcSSimon Schubert 	printf_filtered (",");
15155796c8dcSSimon Schubert 
15165796c8dcSSimon Schubert 	if (!gdbarch_frame_num_args_p (gdbarch))
15175796c8dcSSimon Schubert 	  {
15185796c8dcSSimon Schubert 	    numargs = -1;
15195796c8dcSSimon Schubert 	    puts_filtered (" args: ");
15205796c8dcSSimon Schubert 	  }
15215796c8dcSSimon Schubert 	else
15225796c8dcSSimon Schubert 	  {
15235796c8dcSSimon Schubert 	    numargs = gdbarch_frame_num_args (gdbarch, fi);
15245796c8dcSSimon Schubert 	    gdb_assert (numargs >= 0);
15255796c8dcSSimon Schubert 	    if (numargs == 0)
15265796c8dcSSimon Schubert 	      puts_filtered (" no args.");
15275796c8dcSSimon Schubert 	    else if (numargs == 1)
15285796c8dcSSimon Schubert 	      puts_filtered (" 1 arg: ");
15295796c8dcSSimon Schubert 	    else
15305796c8dcSSimon Schubert 	      printf_filtered (" %d args: ", numargs);
15315796c8dcSSimon Schubert 	  }
15325796c8dcSSimon Schubert 	print_frame_args (func, fi, numargs, gdb_stdout);
15335796c8dcSSimon Schubert 	puts_filtered ("\n");
15345796c8dcSSimon Schubert       }
15355796c8dcSSimon Schubert   }
15365796c8dcSSimon Schubert   {
15375796c8dcSSimon Schubert     /* Address of the local variables for this frame, or 0.  */
15385796c8dcSSimon Schubert     CORE_ADDR arg_list = get_frame_locals_address (fi);
15395796c8dcSSimon Schubert 
15405796c8dcSSimon Schubert     if (arg_list == 0)
15415796c8dcSSimon Schubert       printf_filtered (" Locals at unknown address,");
15425796c8dcSSimon Schubert     else
15435796c8dcSSimon Schubert       {
15445796c8dcSSimon Schubert 	printf_filtered (" Locals at ");
15455796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
15465796c8dcSSimon Schubert 	printf_filtered (",");
15475796c8dcSSimon Schubert       }
15485796c8dcSSimon Schubert   }
15495796c8dcSSimon Schubert 
15505796c8dcSSimon Schubert   /* Print as much information as possible on the location of all the
15515796c8dcSSimon Schubert      registers.  */
15525796c8dcSSimon Schubert   {
15535796c8dcSSimon Schubert     enum lval_type lval;
15545796c8dcSSimon Schubert     int optimized;
1555c50c785cSJohn Marino     int unavailable;
15565796c8dcSSimon Schubert     CORE_ADDR addr;
15575796c8dcSSimon Schubert     int realnum;
15585796c8dcSSimon Schubert     int count;
15595796c8dcSSimon Schubert     int i;
15605796c8dcSSimon Schubert     int need_nl = 1;
15615796c8dcSSimon Schubert 
15625796c8dcSSimon Schubert     /* The sp is special; what's displayed isn't the save address, but
15635796c8dcSSimon Schubert        the value of the previous frame's sp.  This is a legacy thing,
15645796c8dcSSimon Schubert        at one stage the frame cached the previous frame's SP instead
15655796c8dcSSimon Schubert        of its address, hence it was easiest to just display the cached
15665796c8dcSSimon Schubert        value.  */
15675796c8dcSSimon Schubert     if (gdbarch_sp_regnum (gdbarch) >= 0)
15685796c8dcSSimon Schubert       {
15695796c8dcSSimon Schubert 	/* Find out the location of the saved stack pointer with out
15705796c8dcSSimon Schubert            actually evaluating it.  */
15715796c8dcSSimon Schubert 	frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
1572c50c785cSJohn Marino 			       &optimized, &unavailable, &lval, &addr,
15735796c8dcSSimon Schubert 			       &realnum, NULL);
1574c50c785cSJohn Marino 	if (!optimized && !unavailable && lval == not_lval)
15755796c8dcSSimon Schubert 	  {
15765796c8dcSSimon Schubert 	    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
15775796c8dcSSimon Schubert 	    int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
15785796c8dcSSimon Schubert 	    gdb_byte value[MAX_REGISTER_SIZE];
15795796c8dcSSimon Schubert 	    CORE_ADDR sp;
1580cf7f2e2dSJohn Marino 
15815796c8dcSSimon Schubert 	    frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
1582c50c785cSJohn Marino 				   &optimized, &unavailable, &lval, &addr,
15835796c8dcSSimon Schubert 				   &realnum, value);
15845796c8dcSSimon Schubert 	    /* NOTE: cagney/2003-05-22: This is assuming that the
15855796c8dcSSimon Schubert                stack pointer was packed as an unsigned integer.  That
15865796c8dcSSimon Schubert                may or may not be valid.  */
15875796c8dcSSimon Schubert 	    sp = extract_unsigned_integer (value, sp_size, byte_order);
15885796c8dcSSimon Schubert 	    printf_filtered (" Previous frame's sp is ");
15895796c8dcSSimon Schubert 	    fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
15905796c8dcSSimon Schubert 	    printf_filtered ("\n");
15915796c8dcSSimon Schubert 	    need_nl = 0;
15925796c8dcSSimon Schubert 	  }
1593c50c785cSJohn Marino 	else if (!optimized && !unavailable && lval == lval_memory)
15945796c8dcSSimon Schubert 	  {
15955796c8dcSSimon Schubert 	    printf_filtered (" Previous frame's sp at ");
15965796c8dcSSimon Schubert 	    fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
15975796c8dcSSimon Schubert 	    printf_filtered ("\n");
15985796c8dcSSimon Schubert 	    need_nl = 0;
15995796c8dcSSimon Schubert 	  }
1600c50c785cSJohn Marino 	else if (!optimized && !unavailable && lval == lval_register)
16015796c8dcSSimon Schubert 	  {
16025796c8dcSSimon Schubert 	    printf_filtered (" Previous frame's sp in %s\n",
16035796c8dcSSimon Schubert 			     gdbarch_register_name (gdbarch, realnum));
16045796c8dcSSimon Schubert 	    need_nl = 0;
16055796c8dcSSimon Schubert 	  }
16065796c8dcSSimon Schubert 	/* else keep quiet.  */
16075796c8dcSSimon Schubert       }
16085796c8dcSSimon Schubert 
16095796c8dcSSimon Schubert     count = 0;
16105796c8dcSSimon Schubert     numregs = gdbarch_num_regs (gdbarch)
16115796c8dcSSimon Schubert 	      + gdbarch_num_pseudo_regs (gdbarch);
16125796c8dcSSimon Schubert     for (i = 0; i < numregs; i++)
16135796c8dcSSimon Schubert       if (i != gdbarch_sp_regnum (gdbarch)
16145796c8dcSSimon Schubert 	  && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
16155796c8dcSSimon Schubert 	{
16165796c8dcSSimon Schubert 	  /* Find out the location of the saved register without
16175796c8dcSSimon Schubert              fetching the corresponding value.  */
1618c50c785cSJohn Marino 	  frame_register_unwind (fi, i, &optimized, &unavailable,
1619c50c785cSJohn Marino 				 &lval, &addr, &realnum, NULL);
16205796c8dcSSimon Schubert 	  /* For moment, only display registers that were saved on the
16215796c8dcSSimon Schubert 	     stack.  */
1622c50c785cSJohn Marino 	  if (!optimized && !unavailable && lval == lval_memory)
16235796c8dcSSimon Schubert 	    {
16245796c8dcSSimon Schubert 	      if (count == 0)
16255796c8dcSSimon Schubert 		puts_filtered (" Saved registers:\n ");
16265796c8dcSSimon Schubert 	      else
16275796c8dcSSimon Schubert 		puts_filtered (",");
16285796c8dcSSimon Schubert 	      wrap_here (" ");
16295796c8dcSSimon Schubert 	      printf_filtered (" %s at ",
16305796c8dcSSimon Schubert 			       gdbarch_register_name (gdbarch, i));
16315796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
16325796c8dcSSimon Schubert 	      count++;
16335796c8dcSSimon Schubert 	    }
16345796c8dcSSimon Schubert 	}
16355796c8dcSSimon Schubert     if (count || need_nl)
16365796c8dcSSimon Schubert       puts_filtered ("\n");
16375796c8dcSSimon Schubert   }
16385796c8dcSSimon Schubert 
16395796c8dcSSimon Schubert   do_cleanups (back_to);
16405796c8dcSSimon Schubert }
16415796c8dcSSimon Schubert 
16425796c8dcSSimon Schubert /* Print briefly all stack frames or just the innermost COUNT_EXP
16435796c8dcSSimon Schubert    frames.  */
16445796c8dcSSimon Schubert 
16455796c8dcSSimon Schubert static void
16465796c8dcSSimon Schubert backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
16475796c8dcSSimon Schubert {
16485796c8dcSSimon Schubert   struct frame_info *fi;
16495796c8dcSSimon Schubert   int count;
16505796c8dcSSimon Schubert   int i;
16515796c8dcSSimon Schubert   struct frame_info *trailing;
16525796c8dcSSimon Schubert   int trailing_level;
16535796c8dcSSimon Schubert 
16545796c8dcSSimon Schubert   if (!target_has_stack)
16555796c8dcSSimon Schubert     error (_("No stack."));
16565796c8dcSSimon Schubert 
16575796c8dcSSimon Schubert   /* The following code must do two things.  First, it must set the
16585796c8dcSSimon Schubert      variable TRAILING to the frame from which we should start
16595796c8dcSSimon Schubert      printing.  Second, it must set the variable count to the number
16605796c8dcSSimon Schubert      of frames which we should print, or -1 if all of them.  */
16615796c8dcSSimon Schubert   trailing = get_current_frame ();
16625796c8dcSSimon Schubert 
16635796c8dcSSimon Schubert   trailing_level = 0;
16645796c8dcSSimon Schubert   if (count_exp)
16655796c8dcSSimon Schubert     {
16665796c8dcSSimon Schubert       count = parse_and_eval_long (count_exp);
16675796c8dcSSimon Schubert       if (count < 0)
16685796c8dcSSimon Schubert 	{
16695796c8dcSSimon Schubert 	  struct frame_info *current;
16705796c8dcSSimon Schubert 
16715796c8dcSSimon Schubert 	  count = -count;
16725796c8dcSSimon Schubert 
16735796c8dcSSimon Schubert 	  current = trailing;
16745796c8dcSSimon Schubert 	  while (current && count--)
16755796c8dcSSimon Schubert 	    {
16765796c8dcSSimon Schubert 	      QUIT;
16775796c8dcSSimon Schubert 	      current = get_prev_frame (current);
16785796c8dcSSimon Schubert 	    }
16795796c8dcSSimon Schubert 
16805796c8dcSSimon Schubert 	  /* Will stop when CURRENT reaches the top of the stack.
16815796c8dcSSimon Schubert 	     TRAILING will be COUNT below it.  */
16825796c8dcSSimon Schubert 	  while (current)
16835796c8dcSSimon Schubert 	    {
16845796c8dcSSimon Schubert 	      QUIT;
16855796c8dcSSimon Schubert 	      trailing = get_prev_frame (trailing);
16865796c8dcSSimon Schubert 	      current = get_prev_frame (current);
16875796c8dcSSimon Schubert 	      trailing_level++;
16885796c8dcSSimon Schubert 	    }
16895796c8dcSSimon Schubert 
16905796c8dcSSimon Schubert 	  count = -1;
16915796c8dcSSimon Schubert 	}
16925796c8dcSSimon Schubert     }
16935796c8dcSSimon Schubert   else
16945796c8dcSSimon Schubert     count = -1;
16955796c8dcSSimon Schubert 
16965796c8dcSSimon Schubert   if (info_verbose)
16975796c8dcSSimon Schubert     {
16985796c8dcSSimon Schubert       /* Read in symbols for all of the frames.  Need to do this in a
16995796c8dcSSimon Schubert          separate pass so that "Reading in symbols for xxx" messages
17005796c8dcSSimon Schubert          don't screw up the appearance of the backtrace.  Also if
17015796c8dcSSimon Schubert          people have strong opinions against reading symbols for
17025796c8dcSSimon Schubert          backtrace this may have to be an option.  */
17035796c8dcSSimon Schubert       i = count;
17045796c8dcSSimon Schubert       for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
17055796c8dcSSimon Schubert 	{
1706cf7f2e2dSJohn Marino 	  CORE_ADDR pc;
1707cf7f2e2dSJohn Marino 
17085796c8dcSSimon Schubert 	  QUIT;
1709cf7f2e2dSJohn Marino 	  pc = get_frame_address_in_block (fi);
1710cf7f2e2dSJohn Marino 	  find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc));
17115796c8dcSSimon Schubert 	}
17125796c8dcSSimon Schubert     }
17135796c8dcSSimon Schubert 
17145796c8dcSSimon Schubert   for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
17155796c8dcSSimon Schubert     {
17165796c8dcSSimon Schubert       QUIT;
17175796c8dcSSimon Schubert 
17185796c8dcSSimon Schubert       /* Don't use print_stack_frame; if an error() occurs it probably
17195796c8dcSSimon Schubert          means further attempts to backtrace would fail (on the other
17205796c8dcSSimon Schubert          hand, perhaps the code does or could be fixed to make sure
17215796c8dcSSimon Schubert          the frame->prev field gets set to NULL in that case).  */
17225796c8dcSSimon Schubert       print_frame_info (fi, 1, LOCATION, 1);
17235796c8dcSSimon Schubert       if (show_locals)
17245796c8dcSSimon Schubert 	print_frame_local_vars (fi, 1, gdb_stdout);
17255796c8dcSSimon Schubert 
17265796c8dcSSimon Schubert       /* Save the last frame to check for error conditions.  */
17275796c8dcSSimon Schubert       trailing = fi;
17285796c8dcSSimon Schubert     }
17295796c8dcSSimon Schubert 
17305796c8dcSSimon Schubert   /* If we've stopped before the end, mention that.  */
17315796c8dcSSimon Schubert   if (fi && from_tty)
17325796c8dcSSimon Schubert     printf_filtered (_("(More stack frames follow...)\n"));
17335796c8dcSSimon Schubert 
17345796c8dcSSimon Schubert   /* If we've run out of frames, and the reason appears to be an error
17355796c8dcSSimon Schubert      condition, print it.  */
17365796c8dcSSimon Schubert   if (fi == NULL && trailing != NULL)
17375796c8dcSSimon Schubert     {
17385796c8dcSSimon Schubert       enum unwind_stop_reason reason;
17395796c8dcSSimon Schubert 
17405796c8dcSSimon Schubert       reason = get_frame_unwind_stop_reason (trailing);
1741*a45ae5f8SJohn Marino       if (reason >= UNWIND_FIRST_ERROR)
17425796c8dcSSimon Schubert 	printf_filtered (_("Backtrace stopped: %s\n"),
17435796c8dcSSimon Schubert 			 frame_stop_reason_string (reason));
17445796c8dcSSimon Schubert     }
17455796c8dcSSimon Schubert }
17465796c8dcSSimon Schubert 
17475796c8dcSSimon Schubert static void
17485796c8dcSSimon Schubert backtrace_command (char *arg, int from_tty)
17495796c8dcSSimon Schubert {
1750*a45ae5f8SJohn Marino   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
17515796c8dcSSimon Schubert   int fulltrace_arg = -1, arglen = 0, argc = 0;
17525796c8dcSSimon Schubert 
17535796c8dcSSimon Schubert   if (arg)
17545796c8dcSSimon Schubert     {
17555796c8dcSSimon Schubert       char **argv;
17565796c8dcSSimon Schubert       int i;
17575796c8dcSSimon Schubert 
17585796c8dcSSimon Schubert       argv = gdb_buildargv (arg);
1759*a45ae5f8SJohn Marino       make_cleanup_freeargv (argv);
17605796c8dcSSimon Schubert       argc = 0;
17615796c8dcSSimon Schubert       for (i = 0; argv[i]; i++)
17625796c8dcSSimon Schubert 	{
17635796c8dcSSimon Schubert 	  unsigned int j;
17645796c8dcSSimon Schubert 
17655796c8dcSSimon Schubert 	  for (j = 0; j < strlen (argv[i]); j++)
17665796c8dcSSimon Schubert 	    argv[i][j] = tolower (argv[i][j]);
17675796c8dcSSimon Schubert 
17685796c8dcSSimon Schubert 	  if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
17695796c8dcSSimon Schubert 	    fulltrace_arg = argc;
17705796c8dcSSimon Schubert 	  else
17715796c8dcSSimon Schubert 	    {
17725796c8dcSSimon Schubert 	      arglen += strlen (argv[i]);
17735796c8dcSSimon Schubert 	      argc++;
17745796c8dcSSimon Schubert 	    }
17755796c8dcSSimon Schubert 	}
17765796c8dcSSimon Schubert       arglen += argc;
17775796c8dcSSimon Schubert       if (fulltrace_arg >= 0)
17785796c8dcSSimon Schubert 	{
17795796c8dcSSimon Schubert 	  if (arglen > 0)
17805796c8dcSSimon Schubert 	    {
17815796c8dcSSimon Schubert 	      arg = xmalloc (arglen + 1);
1782*a45ae5f8SJohn Marino 	      make_cleanup (xfree, arg);
1783*a45ae5f8SJohn Marino 	      arg[0] = 0;
17845796c8dcSSimon Schubert 	      for (i = 0; i < (argc + 1); i++)
17855796c8dcSSimon Schubert 		{
17865796c8dcSSimon Schubert 		  if (i != fulltrace_arg)
17875796c8dcSSimon Schubert 		    {
17885796c8dcSSimon Schubert 		      strcat (arg, argv[i]);
17895796c8dcSSimon Schubert 		      strcat (arg, " ");
17905796c8dcSSimon Schubert 		    }
17915796c8dcSSimon Schubert 		}
17925796c8dcSSimon Schubert 	    }
17935796c8dcSSimon Schubert 	  else
17945796c8dcSSimon Schubert 	    arg = NULL;
17955796c8dcSSimon Schubert 	}
17965796c8dcSSimon Schubert     }
17975796c8dcSSimon Schubert 
1798*a45ae5f8SJohn Marino   backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty);
17995796c8dcSSimon Schubert 
18005796c8dcSSimon Schubert   do_cleanups (old_chain);
18015796c8dcSSimon Schubert }
18025796c8dcSSimon Schubert 
18035796c8dcSSimon Schubert static void
18045796c8dcSSimon Schubert backtrace_full_command (char *arg, int from_tty)
18055796c8dcSSimon Schubert {
1806*a45ae5f8SJohn Marino   backtrace_command_1 (arg, 1 /* show_locals */, from_tty);
18075796c8dcSSimon Schubert }
18085796c8dcSSimon Schubert 
18095796c8dcSSimon Schubert 
1810cf7f2e2dSJohn Marino /* Iterate over the local variables of a block B, calling CB with
1811cf7f2e2dSJohn Marino    CB_DATA.  */
18125796c8dcSSimon Schubert 
1813cf7f2e2dSJohn Marino static void
1814cf7f2e2dSJohn Marino iterate_over_block_locals (struct block *b,
1815cf7f2e2dSJohn Marino 			   iterate_over_block_arg_local_vars_cb cb,
1816cf7f2e2dSJohn Marino 			   void *cb_data)
18175796c8dcSSimon Schubert {
18185796c8dcSSimon Schubert   struct dict_iterator iter;
18195796c8dcSSimon Schubert   struct symbol *sym;
18205796c8dcSSimon Schubert 
18215796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (b, iter, sym)
18225796c8dcSSimon Schubert     {
18235796c8dcSSimon Schubert       switch (SYMBOL_CLASS (sym))
18245796c8dcSSimon Schubert 	{
18255796c8dcSSimon Schubert 	case LOC_LOCAL:
18265796c8dcSSimon Schubert 	case LOC_REGISTER:
18275796c8dcSSimon Schubert 	case LOC_STATIC:
18285796c8dcSSimon Schubert 	case LOC_COMPUTED:
18295796c8dcSSimon Schubert 	  if (SYMBOL_IS_ARGUMENT (sym))
18305796c8dcSSimon Schubert 	    break;
1831cf7f2e2dSJohn Marino 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
18325796c8dcSSimon Schubert 	  break;
18335796c8dcSSimon Schubert 
18345796c8dcSSimon Schubert 	default:
18355796c8dcSSimon Schubert 	  /* Ignore symbols which are not locals.  */
18365796c8dcSSimon Schubert 	  break;
18375796c8dcSSimon Schubert 	}
18385796c8dcSSimon Schubert     }
18395796c8dcSSimon Schubert }
18405796c8dcSSimon Schubert 
1841cf7f2e2dSJohn Marino 
18425796c8dcSSimon Schubert /* Same, but print labels.  */
18435796c8dcSSimon Schubert 
1844cf7f2e2dSJohn Marino #if 0
1845cf7f2e2dSJohn Marino /* Commented out, as the code using this function has also been
1846cf7f2e2dSJohn Marino    commented out.  FIXME:brobecker/2009-01-13: Find out why the code
1847cf7f2e2dSJohn Marino    was commented out in the first place.  The discussion introducing
1848cf7f2e2dSJohn Marino    this change (2007-12-04: Support lexical blocks and function bodies
1849cf7f2e2dSJohn Marino    that occupy non-contiguous address ranges) did not explain why
1850cf7f2e2dSJohn Marino    this change was made.  */
18515796c8dcSSimon Schubert static int
18525796c8dcSSimon Schubert print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
18535796c8dcSSimon Schubert 			  int *have_default, struct ui_file *stream)
18545796c8dcSSimon Schubert {
18555796c8dcSSimon Schubert   struct dict_iterator iter;
18565796c8dcSSimon Schubert   struct symbol *sym;
18575796c8dcSSimon Schubert   int values_printed = 0;
18585796c8dcSSimon Schubert 
18595796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (b, iter, sym)
18605796c8dcSSimon Schubert     {
18615796c8dcSSimon Schubert       if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
18625796c8dcSSimon Schubert 	{
18635796c8dcSSimon Schubert 	  if (*have_default)
18645796c8dcSSimon Schubert 	    continue;
18655796c8dcSSimon Schubert 	  *have_default = 1;
18665796c8dcSSimon Schubert 	}
18675796c8dcSSimon Schubert       if (SYMBOL_CLASS (sym) == LOC_LABEL)
18685796c8dcSSimon Schubert 	{
18695796c8dcSSimon Schubert 	  struct symtab_and_line sal;
18705796c8dcSSimon Schubert 	  struct value_print_options opts;
1871cf7f2e2dSJohn Marino 
18725796c8dcSSimon Schubert 	  sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
18735796c8dcSSimon Schubert 	  values_printed = 1;
18745796c8dcSSimon Schubert 	  fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
18755796c8dcSSimon Schubert 	  get_user_print_options (&opts);
18765796c8dcSSimon Schubert 	  if (opts.addressprint)
18775796c8dcSSimon Schubert 	    {
18785796c8dcSSimon Schubert 	      fprintf_filtered (stream, " ");
18795796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
18805796c8dcSSimon Schubert 			      stream);
18815796c8dcSSimon Schubert 	    }
18825796c8dcSSimon Schubert 	  fprintf_filtered (stream, " in file %s, line %d\n",
18835796c8dcSSimon Schubert 			    sal.symtab->filename, sal.line);
18845796c8dcSSimon Schubert 	}
18855796c8dcSSimon Schubert     }
18865796c8dcSSimon Schubert 
18875796c8dcSSimon Schubert   return values_printed;
18885796c8dcSSimon Schubert }
1889cf7f2e2dSJohn Marino #endif
18905796c8dcSSimon Schubert 
1891cf7f2e2dSJohn Marino /* Iterate over all the local variables in block B, including all its
1892cf7f2e2dSJohn Marino    superblocks, stopping when the top-level block is reached.  */
18935796c8dcSSimon Schubert 
1894cf7f2e2dSJohn Marino void
1895cf7f2e2dSJohn Marino iterate_over_block_local_vars (struct block *block,
1896cf7f2e2dSJohn Marino 			       iterate_over_block_arg_local_vars_cb cb,
1897cf7f2e2dSJohn Marino 			       void *cb_data)
1898cf7f2e2dSJohn Marino {
1899cf7f2e2dSJohn Marino   while (block)
1900cf7f2e2dSJohn Marino     {
1901cf7f2e2dSJohn Marino       iterate_over_block_locals (block, cb, cb_data);
1902cf7f2e2dSJohn Marino       /* After handling the function's top-level block, stop.  Don't
1903cf7f2e2dSJohn Marino 	 continue to its superblock, the block of per-file
1904cf7f2e2dSJohn Marino 	 symbols.  */
1905cf7f2e2dSJohn Marino       if (BLOCK_FUNCTION (block))
1906cf7f2e2dSJohn Marino 	break;
1907cf7f2e2dSJohn Marino       block = BLOCK_SUPERBLOCK (block);
1908cf7f2e2dSJohn Marino     }
1909cf7f2e2dSJohn Marino }
1910cf7f2e2dSJohn Marino 
1911cf7f2e2dSJohn Marino /* Data to be passed around in the calls to the locals and args
1912cf7f2e2dSJohn Marino    iterators.  */
1913cf7f2e2dSJohn Marino 
1914cf7f2e2dSJohn Marino struct print_variable_and_value_data
1915cf7f2e2dSJohn Marino {
1916cf7f2e2dSJohn Marino   struct frame_info *frame;
1917cf7f2e2dSJohn Marino   int num_tabs;
1918cf7f2e2dSJohn Marino   struct ui_file *stream;
1919cf7f2e2dSJohn Marino   int values_printed;
1920cf7f2e2dSJohn Marino };
1921cf7f2e2dSJohn Marino 
1922c50c785cSJohn Marino /* The callback for the locals and args iterators.  */
1923cf7f2e2dSJohn Marino 
1924cf7f2e2dSJohn Marino static void
1925cf7f2e2dSJohn Marino do_print_variable_and_value (const char *print_name,
1926cf7f2e2dSJohn Marino 			     struct symbol *sym,
1927cf7f2e2dSJohn Marino 			     void *cb_data)
1928cf7f2e2dSJohn Marino {
1929cf7f2e2dSJohn Marino   struct print_variable_and_value_data *p = cb_data;
1930cf7f2e2dSJohn Marino 
1931cf7f2e2dSJohn Marino   print_variable_and_value (print_name, sym,
1932cf7f2e2dSJohn Marino 			    p->frame, p->stream, p->num_tabs);
1933cf7f2e2dSJohn Marino   p->values_printed = 1;
1934cf7f2e2dSJohn Marino }
19355796c8dcSSimon Schubert 
19365796c8dcSSimon Schubert static void
19375796c8dcSSimon Schubert print_frame_local_vars (struct frame_info *frame, int num_tabs,
19385796c8dcSSimon Schubert 			struct ui_file *stream)
19395796c8dcSSimon Schubert {
1940cf7f2e2dSJohn Marino   struct print_variable_and_value_data cb_data;
1941cf7f2e2dSJohn Marino   struct block *block;
1942c50c785cSJohn Marino   CORE_ADDR pc;
1943c50c785cSJohn Marino 
1944c50c785cSJohn Marino   if (!get_frame_pc_if_available (frame, &pc))
1945c50c785cSJohn Marino     {
1946c50c785cSJohn Marino       fprintf_filtered (stream,
1947c50c785cSJohn Marino 			_("PC unavailable, cannot determine locals.\n"));
1948c50c785cSJohn Marino       return;
1949c50c785cSJohn Marino     }
19505796c8dcSSimon Schubert 
1951cf7f2e2dSJohn Marino   block = get_frame_block (frame, 0);
19525796c8dcSSimon Schubert   if (block == 0)
19535796c8dcSSimon Schubert     {
19545796c8dcSSimon Schubert       fprintf_filtered (stream, "No symbol table info available.\n");
19555796c8dcSSimon Schubert       return;
19565796c8dcSSimon Schubert     }
19575796c8dcSSimon Schubert 
1958cf7f2e2dSJohn Marino   cb_data.frame = frame;
1959cf7f2e2dSJohn Marino   cb_data.num_tabs = 4 * num_tabs;
1960cf7f2e2dSJohn Marino   cb_data.stream = stream;
1961cf7f2e2dSJohn Marino   cb_data.values_printed = 0;
19625796c8dcSSimon Schubert 
1963cf7f2e2dSJohn Marino   iterate_over_block_local_vars (block,
1964cf7f2e2dSJohn Marino 				 do_print_variable_and_value,
1965cf7f2e2dSJohn Marino 				 &cb_data);
1966cf7f2e2dSJohn Marino 
1967cf7f2e2dSJohn Marino   if (!cb_data.values_printed)
19685796c8dcSSimon Schubert     fprintf_filtered (stream, _("No locals.\n"));
19695796c8dcSSimon Schubert }
19705796c8dcSSimon Schubert 
19715796c8dcSSimon Schubert /* Same, but print labels.  */
19725796c8dcSSimon Schubert 
19735796c8dcSSimon Schubert static void
19745796c8dcSSimon Schubert print_frame_label_vars (struct frame_info *frame, int this_level_only,
19755796c8dcSSimon Schubert 			struct ui_file *stream)
19765796c8dcSSimon Schubert {
19775796c8dcSSimon Schubert #if 1
19785796c8dcSSimon Schubert   fprintf_filtered (stream, "print_frame_label_vars disabled.\n");
19795796c8dcSSimon Schubert #else
19805796c8dcSSimon Schubert   struct blockvector *bl;
19815796c8dcSSimon Schubert   struct block *block = get_frame_block (frame, 0);
19825796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
19835796c8dcSSimon Schubert   int values_printed = 0;
19845796c8dcSSimon Schubert   int index, have_default = 0;
19855796c8dcSSimon Schubert   char *blocks_printed;
19865796c8dcSSimon Schubert   CORE_ADDR pc = get_frame_pc (frame);
19875796c8dcSSimon Schubert 
19885796c8dcSSimon Schubert   if (block == 0)
19895796c8dcSSimon Schubert     {
19905796c8dcSSimon Schubert       fprintf_filtered (stream, "No symbol table info available.\n");
19915796c8dcSSimon Schubert       return;
19925796c8dcSSimon Schubert     }
19935796c8dcSSimon Schubert 
19945796c8dcSSimon Schubert   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
19955796c8dcSSimon Schubert   blocks_printed = alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
19965796c8dcSSimon Schubert   memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
19975796c8dcSSimon Schubert 
19985796c8dcSSimon Schubert   while (block != 0)
19995796c8dcSSimon Schubert     {
20005796c8dcSSimon Schubert       CORE_ADDR end = BLOCK_END (block) - 4;
20015796c8dcSSimon Schubert       int last_index;
20025796c8dcSSimon Schubert 
20035796c8dcSSimon Schubert       if (bl != blockvector_for_pc (end, &index))
20045796c8dcSSimon Schubert 	error (_("blockvector blotch"));
20055796c8dcSSimon Schubert       if (BLOCKVECTOR_BLOCK (bl, index) != block)
20065796c8dcSSimon Schubert 	error (_("blockvector botch"));
20075796c8dcSSimon Schubert       last_index = BLOCKVECTOR_NBLOCKS (bl);
20085796c8dcSSimon Schubert       index += 1;
20095796c8dcSSimon Schubert 
20105796c8dcSSimon Schubert       /* Don't print out blocks that have gone by.  */
20115796c8dcSSimon Schubert       while (index < last_index
20125796c8dcSSimon Schubert 	     && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
20135796c8dcSSimon Schubert 	index++;
20145796c8dcSSimon Schubert 
20155796c8dcSSimon Schubert       while (index < last_index
20165796c8dcSSimon Schubert 	     && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
20175796c8dcSSimon Schubert 	{
20185796c8dcSSimon Schubert 	  if (blocks_printed[index] == 0)
20195796c8dcSSimon Schubert 	    {
20205796c8dcSSimon Schubert 	      if (print_block_frame_labels (gdbarch,
20215796c8dcSSimon Schubert 					    BLOCKVECTOR_BLOCK (bl, index),
20225796c8dcSSimon Schubert 					    &have_default, stream))
20235796c8dcSSimon Schubert 		values_printed = 1;
20245796c8dcSSimon Schubert 	      blocks_printed[index] = 1;
20255796c8dcSSimon Schubert 	    }
20265796c8dcSSimon Schubert 	  index++;
20275796c8dcSSimon Schubert 	}
20285796c8dcSSimon Schubert       if (have_default)
20295796c8dcSSimon Schubert 	return;
20305796c8dcSSimon Schubert       if (values_printed && this_level_only)
20315796c8dcSSimon Schubert 	return;
20325796c8dcSSimon Schubert 
20335796c8dcSSimon Schubert       /* After handling the function's top-level block, stop.  Don't
20345796c8dcSSimon Schubert          continue to its superblock, the block of per-file symbols.
20355796c8dcSSimon Schubert          Also do not continue to the containing function of an inlined
20365796c8dcSSimon Schubert          function.  */
20375796c8dcSSimon Schubert       if (BLOCK_FUNCTION (block))
20385796c8dcSSimon Schubert 	break;
20395796c8dcSSimon Schubert       block = BLOCK_SUPERBLOCK (block);
20405796c8dcSSimon Schubert     }
20415796c8dcSSimon Schubert 
20425796c8dcSSimon Schubert   if (!values_printed && !this_level_only)
20435796c8dcSSimon Schubert     fprintf_filtered (stream, _("No catches.\n"));
20445796c8dcSSimon Schubert #endif
20455796c8dcSSimon Schubert }
20465796c8dcSSimon Schubert 
20475796c8dcSSimon Schubert void
20485796c8dcSSimon Schubert locals_info (char *args, int from_tty)
20495796c8dcSSimon Schubert {
20505796c8dcSSimon Schubert   print_frame_local_vars (get_selected_frame (_("No frame selected.")),
20515796c8dcSSimon Schubert 			  0, gdb_stdout);
20525796c8dcSSimon Schubert }
20535796c8dcSSimon Schubert 
20545796c8dcSSimon Schubert static void
20555796c8dcSSimon Schubert catch_info (char *ignore, int from_tty)
20565796c8dcSSimon Schubert {
20575796c8dcSSimon Schubert   /* Assume g++ compiled code; old GDB 4.16 behaviour.  */
20585796c8dcSSimon Schubert   print_frame_label_vars (get_selected_frame (_("No frame selected.")),
20595796c8dcSSimon Schubert                           0, gdb_stdout);
20605796c8dcSSimon Schubert }
20615796c8dcSSimon Schubert 
2062cf7f2e2dSJohn Marino /* Iterate over all the argument variables in block B.
2063cf7f2e2dSJohn Marino 
2064cf7f2e2dSJohn Marino    Returns 1 if any argument was walked; 0 otherwise.  */
2065cf7f2e2dSJohn Marino 
2066cf7f2e2dSJohn Marino void
2067cf7f2e2dSJohn Marino iterate_over_block_arg_vars (struct block *b,
2068cf7f2e2dSJohn Marino 			     iterate_over_block_arg_local_vars_cb cb,
2069cf7f2e2dSJohn Marino 			     void *cb_data)
20705796c8dcSSimon Schubert {
20715796c8dcSSimon Schubert   struct dict_iterator iter;
20725796c8dcSSimon Schubert   struct symbol *sym, *sym2;
20735796c8dcSSimon Schubert 
20745796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (b, iter, sym)
20755796c8dcSSimon Schubert     {
20765796c8dcSSimon Schubert       /* Don't worry about things which aren't arguments.  */
20775796c8dcSSimon Schubert       if (SYMBOL_IS_ARGUMENT (sym))
20785796c8dcSSimon Schubert 	{
20795796c8dcSSimon Schubert 	  /* We have to look up the symbol because arguments can have
20805796c8dcSSimon Schubert 	     two entries (one a parameter, one a local) and the one we
20815796c8dcSSimon Schubert 	     want is the local, which lookup_symbol will find for us.
20825796c8dcSSimon Schubert 	     This includes gcc1 (not gcc2) on the sparc when passing a
20835796c8dcSSimon Schubert 	     small structure and gcc2 when the argument type is float
20845796c8dcSSimon Schubert 	     and it is passed as a double and converted to float by
20855796c8dcSSimon Schubert 	     the prologue (in the latter case the type of the LOC_ARG
20865796c8dcSSimon Schubert 	     symbol is double and the type of the LOC_LOCAL symbol is
20875796c8dcSSimon Schubert 	     float).  There are also LOC_ARG/LOC_REGISTER pairs which
20885796c8dcSSimon Schubert 	     are not combined in symbol-reading.  */
20895796c8dcSSimon Schubert 
20905796c8dcSSimon Schubert 	  sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
20915796c8dcSSimon Schubert 				b, VAR_DOMAIN, NULL);
2092cf7f2e2dSJohn Marino 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
2093cf7f2e2dSJohn Marino 	}
20945796c8dcSSimon Schubert     }
20955796c8dcSSimon Schubert }
20965796c8dcSSimon Schubert 
2097cf7f2e2dSJohn Marino static void
2098cf7f2e2dSJohn Marino print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
2099cf7f2e2dSJohn Marino {
2100cf7f2e2dSJohn Marino   struct print_variable_and_value_data cb_data;
2101cf7f2e2dSJohn Marino   struct symbol *func;
2102c50c785cSJohn Marino   CORE_ADDR pc;
2103c50c785cSJohn Marino 
2104c50c785cSJohn Marino   if (!get_frame_pc_if_available (frame, &pc))
2105c50c785cSJohn Marino     {
2106c50c785cSJohn Marino       fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
2107c50c785cSJohn Marino       return;
2108c50c785cSJohn Marino     }
2109cf7f2e2dSJohn Marino 
2110cf7f2e2dSJohn Marino   func = get_frame_function (frame);
2111cf7f2e2dSJohn Marino   if (func == NULL)
2112cf7f2e2dSJohn Marino     {
2113cf7f2e2dSJohn Marino       fprintf_filtered (stream, _("No symbol table info available.\n"));
2114cf7f2e2dSJohn Marino       return;
2115cf7f2e2dSJohn Marino     }
2116cf7f2e2dSJohn Marino 
2117cf7f2e2dSJohn Marino   cb_data.frame = frame;
2118cf7f2e2dSJohn Marino   cb_data.num_tabs = 0;
2119cf7f2e2dSJohn Marino   cb_data.stream = gdb_stdout;
2120cf7f2e2dSJohn Marino   cb_data.values_printed = 0;
2121cf7f2e2dSJohn Marino 
2122cf7f2e2dSJohn Marino   iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
2123cf7f2e2dSJohn Marino 			       do_print_variable_and_value, &cb_data);
2124cf7f2e2dSJohn Marino 
2125cf7f2e2dSJohn Marino   if (!cb_data.values_printed)
21265796c8dcSSimon Schubert     fprintf_filtered (stream, _("No arguments.\n"));
21275796c8dcSSimon Schubert }
21285796c8dcSSimon Schubert 
21295796c8dcSSimon Schubert void
21305796c8dcSSimon Schubert args_info (char *ignore, int from_tty)
21315796c8dcSSimon Schubert {
21325796c8dcSSimon Schubert   print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
21335796c8dcSSimon Schubert 			gdb_stdout);
21345796c8dcSSimon Schubert }
21355796c8dcSSimon Schubert 
21365796c8dcSSimon Schubert 
21375796c8dcSSimon Schubert static void
21385796c8dcSSimon Schubert args_plus_locals_info (char *ignore, int from_tty)
21395796c8dcSSimon Schubert {
21405796c8dcSSimon Schubert   args_info (ignore, from_tty);
21415796c8dcSSimon Schubert   locals_info (ignore, from_tty);
21425796c8dcSSimon Schubert }
21435796c8dcSSimon Schubert 
21445796c8dcSSimon Schubert 
21455796c8dcSSimon Schubert /* Select frame FRAME.  Also print the stack frame and show the source
21465796c8dcSSimon Schubert    if this is the tui version.  */
21475796c8dcSSimon Schubert static void
21485796c8dcSSimon Schubert select_and_print_frame (struct frame_info *frame)
21495796c8dcSSimon Schubert {
21505796c8dcSSimon Schubert   select_frame (frame);
21515796c8dcSSimon Schubert   if (frame)
21525796c8dcSSimon Schubert     print_stack_frame (frame, 1, SRC_AND_LOC);
21535796c8dcSSimon Schubert }
21545796c8dcSSimon Schubert 
21555796c8dcSSimon Schubert /* Return the symbol-block in which the selected frame is executing.
21565796c8dcSSimon Schubert    Can return zero under various legitimate circumstances.
21575796c8dcSSimon Schubert 
21585796c8dcSSimon Schubert    If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
21595796c8dcSSimon Schubert    code address within the block returned.  We use this to decide
21605796c8dcSSimon Schubert    which macros are in scope.  */
21615796c8dcSSimon Schubert 
21625796c8dcSSimon Schubert struct block *
21635796c8dcSSimon Schubert get_selected_block (CORE_ADDR *addr_in_block)
21645796c8dcSSimon Schubert {
21655796c8dcSSimon Schubert   if (!has_stack_frames ())
21665796c8dcSSimon Schubert     return 0;
21675796c8dcSSimon Schubert 
21685796c8dcSSimon Schubert   return get_frame_block (get_selected_frame (NULL), addr_in_block);
21695796c8dcSSimon Schubert }
21705796c8dcSSimon Schubert 
21715796c8dcSSimon Schubert /* Find a frame a certain number of levels away from FRAME.
21725796c8dcSSimon Schubert    LEVEL_OFFSET_PTR points to an int containing the number of levels.
21735796c8dcSSimon Schubert    Positive means go to earlier frames (up); negative, the reverse.
21745796c8dcSSimon Schubert    The int that contains the number of levels is counted toward
21755796c8dcSSimon Schubert    zero as the frames for those levels are found.
21765796c8dcSSimon Schubert    If the top or bottom frame is reached, that frame is returned,
21775796c8dcSSimon Schubert    but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
21785796c8dcSSimon Schubert    how much farther the original request asked to go.  */
21795796c8dcSSimon Schubert 
21805796c8dcSSimon Schubert struct frame_info *
21815796c8dcSSimon Schubert find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
21825796c8dcSSimon Schubert {
21835796c8dcSSimon Schubert   /* Going up is simple: just call get_prev_frame enough times or
21845796c8dcSSimon Schubert      until the initial frame is reached.  */
21855796c8dcSSimon Schubert   while (*level_offset_ptr > 0)
21865796c8dcSSimon Schubert     {
21875796c8dcSSimon Schubert       struct frame_info *prev = get_prev_frame (frame);
2188cf7f2e2dSJohn Marino 
21895796c8dcSSimon Schubert       if (!prev)
21905796c8dcSSimon Schubert 	break;
21915796c8dcSSimon Schubert       (*level_offset_ptr)--;
21925796c8dcSSimon Schubert       frame = prev;
21935796c8dcSSimon Schubert     }
21945796c8dcSSimon Schubert 
21955796c8dcSSimon Schubert   /* Going down is just as simple.  */
21965796c8dcSSimon Schubert   while (*level_offset_ptr < 0)
21975796c8dcSSimon Schubert     {
21985796c8dcSSimon Schubert       struct frame_info *next = get_next_frame (frame);
2199cf7f2e2dSJohn Marino 
22005796c8dcSSimon Schubert       if (!next)
22015796c8dcSSimon Schubert 	break;
22025796c8dcSSimon Schubert       (*level_offset_ptr)++;
22035796c8dcSSimon Schubert       frame = next;
22045796c8dcSSimon Schubert     }
22055796c8dcSSimon Schubert 
22065796c8dcSSimon Schubert   return frame;
22075796c8dcSSimon Schubert }
22085796c8dcSSimon Schubert 
22095796c8dcSSimon Schubert /* The "select_frame" command.  With no argument this is a NOP.
22105796c8dcSSimon Schubert    Select the frame at level LEVEL_EXP if it is a valid level.
22115796c8dcSSimon Schubert    Otherwise, treat LEVEL_EXP as an address expression and select it.
22125796c8dcSSimon Schubert 
22135796c8dcSSimon Schubert    See parse_frame_specification for more info on proper frame
22145796c8dcSSimon Schubert    expressions.  */
22155796c8dcSSimon Schubert 
22165796c8dcSSimon Schubert void
22175796c8dcSSimon Schubert select_frame_command (char *level_exp, int from_tty)
22185796c8dcSSimon Schubert {
22195796c8dcSSimon Schubert   select_frame (parse_frame_specification_1 (level_exp, "No stack.", NULL));
22205796c8dcSSimon Schubert }
22215796c8dcSSimon Schubert 
22225796c8dcSSimon Schubert /* The "frame" command.  With no argument, print the selected frame
22235796c8dcSSimon Schubert    briefly.  With an argument, behave like select_frame and then print
22245796c8dcSSimon Schubert    the selected frame.  */
22255796c8dcSSimon Schubert 
22265796c8dcSSimon Schubert static void
22275796c8dcSSimon Schubert frame_command (char *level_exp, int from_tty)
22285796c8dcSSimon Schubert {
22295796c8dcSSimon Schubert   select_frame_command (level_exp, from_tty);
22305796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
22315796c8dcSSimon Schubert }
22325796c8dcSSimon Schubert 
22335796c8dcSSimon Schubert /* The XDB Compatibility command to print the current frame.  */
22345796c8dcSSimon Schubert 
22355796c8dcSSimon Schubert static void
22365796c8dcSSimon Schubert current_frame_command (char *level_exp, int from_tty)
22375796c8dcSSimon Schubert {
22385796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC);
22395796c8dcSSimon Schubert }
22405796c8dcSSimon Schubert 
22415796c8dcSSimon Schubert /* Select the frame up one or COUNT_EXP stack levels from the
22425796c8dcSSimon Schubert    previously selected frame, and print it briefly.  */
22435796c8dcSSimon Schubert 
22445796c8dcSSimon Schubert static void
22455796c8dcSSimon Schubert up_silently_base (char *count_exp)
22465796c8dcSSimon Schubert {
22475796c8dcSSimon Schubert   struct frame_info *frame;
22485796c8dcSSimon Schubert   int count = 1;
22495796c8dcSSimon Schubert 
22505796c8dcSSimon Schubert   if (count_exp)
22515796c8dcSSimon Schubert     count = parse_and_eval_long (count_exp);
22525796c8dcSSimon Schubert 
22535796c8dcSSimon Schubert   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
22545796c8dcSSimon Schubert   if (count != 0 && count_exp == NULL)
22555796c8dcSSimon Schubert     error (_("Initial frame selected; you cannot go up."));
22565796c8dcSSimon Schubert   select_frame (frame);
22575796c8dcSSimon Schubert }
22585796c8dcSSimon Schubert 
22595796c8dcSSimon Schubert static void
22605796c8dcSSimon Schubert up_silently_command (char *count_exp, int from_tty)
22615796c8dcSSimon Schubert {
22625796c8dcSSimon Schubert   up_silently_base (count_exp);
22635796c8dcSSimon Schubert }
22645796c8dcSSimon Schubert 
22655796c8dcSSimon Schubert static void
22665796c8dcSSimon Schubert up_command (char *count_exp, int from_tty)
22675796c8dcSSimon Schubert {
22685796c8dcSSimon Schubert   up_silently_base (count_exp);
22695796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
22705796c8dcSSimon Schubert }
22715796c8dcSSimon Schubert 
22725796c8dcSSimon Schubert /* Select the frame down one or COUNT_EXP stack levels from the previously
22735796c8dcSSimon Schubert    selected frame, and print it briefly.  */
22745796c8dcSSimon Schubert 
22755796c8dcSSimon Schubert static void
22765796c8dcSSimon Schubert down_silently_base (char *count_exp)
22775796c8dcSSimon Schubert {
22785796c8dcSSimon Schubert   struct frame_info *frame;
22795796c8dcSSimon Schubert   int count = -1;
2280cf7f2e2dSJohn Marino 
22815796c8dcSSimon Schubert   if (count_exp)
22825796c8dcSSimon Schubert     count = -parse_and_eval_long (count_exp);
22835796c8dcSSimon Schubert 
22845796c8dcSSimon Schubert   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
22855796c8dcSSimon Schubert   if (count != 0 && count_exp == NULL)
22865796c8dcSSimon Schubert     {
22875796c8dcSSimon Schubert       /* We only do this if COUNT_EXP is not specified.  That way
22885796c8dcSSimon Schubert          "down" means to really go down (and let me know if that is
22895796c8dcSSimon Schubert          impossible), but "down 9999" can be used to mean go all the
22905796c8dcSSimon Schubert          way down without getting an error.  */
22915796c8dcSSimon Schubert 
22925796c8dcSSimon Schubert       error (_("Bottom (innermost) frame selected; you cannot go down."));
22935796c8dcSSimon Schubert     }
22945796c8dcSSimon Schubert 
22955796c8dcSSimon Schubert   select_frame (frame);
22965796c8dcSSimon Schubert }
22975796c8dcSSimon Schubert 
22985796c8dcSSimon Schubert static void
22995796c8dcSSimon Schubert down_silently_command (char *count_exp, int from_tty)
23005796c8dcSSimon Schubert {
23015796c8dcSSimon Schubert   down_silently_base (count_exp);
23025796c8dcSSimon Schubert }
23035796c8dcSSimon Schubert 
23045796c8dcSSimon Schubert static void
23055796c8dcSSimon Schubert down_command (char *count_exp, int from_tty)
23065796c8dcSSimon Schubert {
23075796c8dcSSimon Schubert   down_silently_base (count_exp);
23085796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
23095796c8dcSSimon Schubert }
23105796c8dcSSimon Schubert 
23115796c8dcSSimon Schubert 
23125796c8dcSSimon Schubert void
23135796c8dcSSimon Schubert return_command (char *retval_exp, int from_tty)
23145796c8dcSSimon Schubert {
23155796c8dcSSimon Schubert   struct frame_info *thisframe;
23165796c8dcSSimon Schubert   struct gdbarch *gdbarch;
23175796c8dcSSimon Schubert   struct symbol *thisfun;
23185796c8dcSSimon Schubert   struct value *return_value = NULL;
23195796c8dcSSimon Schubert   const char *query_prefix = "";
23205796c8dcSSimon Schubert 
23215796c8dcSSimon Schubert   thisframe = get_selected_frame ("No selected frame.");
23225796c8dcSSimon Schubert   thisfun = get_frame_function (thisframe);
23235796c8dcSSimon Schubert   gdbarch = get_frame_arch (thisframe);
23245796c8dcSSimon Schubert 
23255796c8dcSSimon Schubert   if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
23265796c8dcSSimon Schubert     error (_("Can not force return from an inlined function."));
23275796c8dcSSimon Schubert 
23285796c8dcSSimon Schubert   /* Compute the return value.  If the computation triggers an error,
23295796c8dcSSimon Schubert      let it bail.  If the return type can't be handled, set
23305796c8dcSSimon Schubert      RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
23315796c8dcSSimon Schubert      message.  */
23325796c8dcSSimon Schubert   if (retval_exp)
23335796c8dcSSimon Schubert     {
23345796c8dcSSimon Schubert       struct expression *retval_expr = parse_expression (retval_exp);
23355796c8dcSSimon Schubert       struct cleanup *old_chain = make_cleanup (xfree, retval_expr);
23365796c8dcSSimon Schubert       struct type *return_type = NULL;
23375796c8dcSSimon Schubert 
23385796c8dcSSimon Schubert       /* Compute the return value.  Should the computation fail, this
23395796c8dcSSimon Schubert          call throws an error.  */
23405796c8dcSSimon Schubert       return_value = evaluate_expression (retval_expr);
23415796c8dcSSimon Schubert 
23425796c8dcSSimon Schubert       /* Cast return value to the return type of the function.  Should
23435796c8dcSSimon Schubert          the cast fail, this call throws an error.  */
23445796c8dcSSimon Schubert       if (thisfun != NULL)
23455796c8dcSSimon Schubert 	return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
23465796c8dcSSimon Schubert       if (return_type == NULL)
23475796c8dcSSimon Schubert       	{
23485796c8dcSSimon Schubert 	  if (retval_expr->elts[0].opcode != UNOP_CAST)
23495796c8dcSSimon Schubert 	    error (_("Return value type not available for selected "
23505796c8dcSSimon Schubert 		     "stack frame.\n"
23515796c8dcSSimon Schubert 		     "Please use an explicit cast of the value to return."));
23525796c8dcSSimon Schubert 	  return_type = value_type (return_value);
23535796c8dcSSimon Schubert 	}
23545796c8dcSSimon Schubert       do_cleanups (old_chain);
23555796c8dcSSimon Schubert       CHECK_TYPEDEF (return_type);
23565796c8dcSSimon Schubert       return_value = value_cast (return_type, return_value);
23575796c8dcSSimon Schubert 
23585796c8dcSSimon Schubert       /* Make sure the value is fully evaluated.  It may live in the
23595796c8dcSSimon Schubert          stack frame we're about to pop.  */
23605796c8dcSSimon Schubert       if (value_lazy (return_value))
23615796c8dcSSimon Schubert 	value_fetch_lazy (return_value);
23625796c8dcSSimon Schubert 
23635796c8dcSSimon Schubert       if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
23645796c8dcSSimon Schubert 	/* If the return-type is "void", don't try to find the
23655796c8dcSSimon Schubert            return-value's location.  However, do still evaluate the
23665796c8dcSSimon Schubert            return expression so that, even when the expression result
23675796c8dcSSimon Schubert            is discarded, side effects such as "return i++" still
23685796c8dcSSimon Schubert            occur.  */
23695796c8dcSSimon Schubert 	return_value = NULL;
23705796c8dcSSimon Schubert       else if (thisfun != NULL
23715796c8dcSSimon Schubert 	       && using_struct_return (gdbarch,
23725796c8dcSSimon Schubert 				       SYMBOL_TYPE (thisfun), return_type))
23735796c8dcSSimon Schubert 	{
2374c50c785cSJohn Marino 	  query_prefix = "The location at which to store the "
2375c50c785cSJohn Marino 	    "function's return value is unknown.\n"
2376c50c785cSJohn Marino 	    "If you continue, the return value "
2377c50c785cSJohn Marino 	    "that you specified will be ignored.\n";
23785796c8dcSSimon Schubert 	  return_value = NULL;
23795796c8dcSSimon Schubert 	}
23805796c8dcSSimon Schubert     }
23815796c8dcSSimon Schubert 
23825796c8dcSSimon Schubert   /* Does an interactive user really want to do this?  Include
23835796c8dcSSimon Schubert      information, such as how well GDB can handle the return value, in
23845796c8dcSSimon Schubert      the query message.  */
23855796c8dcSSimon Schubert   if (from_tty)
23865796c8dcSSimon Schubert     {
23875796c8dcSSimon Schubert       int confirmed;
2388cf7f2e2dSJohn Marino 
23895796c8dcSSimon Schubert       if (thisfun == NULL)
23905796c8dcSSimon Schubert 	confirmed = query (_("%sMake selected stack frame return now? "),
23915796c8dcSSimon Schubert 			   query_prefix);
23925796c8dcSSimon Schubert       else
23935796c8dcSSimon Schubert 	confirmed = query (_("%sMake %s return now? "), query_prefix,
23945796c8dcSSimon Schubert 			   SYMBOL_PRINT_NAME (thisfun));
23955796c8dcSSimon Schubert       if (!confirmed)
23965796c8dcSSimon Schubert 	error (_("Not confirmed"));
23975796c8dcSSimon Schubert     }
23985796c8dcSSimon Schubert 
23995796c8dcSSimon Schubert   /* Discard the selected frame and all frames inner-to it.  */
24005796c8dcSSimon Schubert   frame_pop (get_selected_frame (NULL));
24015796c8dcSSimon Schubert 
24025796c8dcSSimon Schubert   /* Store RETURN_VALUE in the just-returned register set.  */
24035796c8dcSSimon Schubert   if (return_value != NULL)
24045796c8dcSSimon Schubert     {
24055796c8dcSSimon Schubert       struct type *return_type = value_type (return_value);
24065796c8dcSSimon Schubert       struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ());
24075796c8dcSSimon Schubert       struct type *func_type = thisfun == NULL ? NULL : SYMBOL_TYPE (thisfun);
24085796c8dcSSimon Schubert 
24095796c8dcSSimon Schubert       gdb_assert (gdbarch_return_value (gdbarch, func_type, return_type, NULL,
24105796c8dcSSimon Schubert 					NULL, NULL)
24115796c8dcSSimon Schubert 		  == RETURN_VALUE_REGISTER_CONVENTION);
24125796c8dcSSimon Schubert       gdbarch_return_value (gdbarch, func_type, return_type,
24135796c8dcSSimon Schubert 			    get_current_regcache (), NULL /*read*/,
24145796c8dcSSimon Schubert 			    value_contents (return_value) /*write*/);
24155796c8dcSSimon Schubert     }
24165796c8dcSSimon Schubert 
24175796c8dcSSimon Schubert   /* If we are at the end of a call dummy now, pop the dummy frame
24185796c8dcSSimon Schubert      too.  */
24195796c8dcSSimon Schubert   if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
24205796c8dcSSimon Schubert     frame_pop (get_current_frame ());
24215796c8dcSSimon Schubert 
24225796c8dcSSimon Schubert   /* If interactive, print the frame that is now current.  */
24235796c8dcSSimon Schubert   if (from_tty)
24245796c8dcSSimon Schubert     frame_command ("0", 1);
24255796c8dcSSimon Schubert   else
24265796c8dcSSimon Schubert     select_frame_command ("0", 0);
24275796c8dcSSimon Schubert }
24285796c8dcSSimon Schubert 
24295796c8dcSSimon Schubert /* Sets the scope to input function name, provided that the function
2430c50c785cSJohn Marino    is within the current stack frame.  */
24315796c8dcSSimon Schubert 
24325796c8dcSSimon Schubert struct function_bounds
24335796c8dcSSimon Schubert {
24345796c8dcSSimon Schubert   CORE_ADDR low, high;
24355796c8dcSSimon Schubert };
24365796c8dcSSimon Schubert 
24375796c8dcSSimon Schubert static void
24385796c8dcSSimon Schubert func_command (char *arg, int from_tty)
24395796c8dcSSimon Schubert {
24405796c8dcSSimon Schubert   struct frame_info *frame;
24415796c8dcSSimon Schubert   int found = 0;
24425796c8dcSSimon Schubert   struct symtabs_and_lines sals;
24435796c8dcSSimon Schubert   int i;
24445796c8dcSSimon Schubert   int level = 1;
24455796c8dcSSimon Schubert   struct function_bounds *func_bounds = NULL;
2446*a45ae5f8SJohn Marino   struct cleanup *cleanups;
24475796c8dcSSimon Schubert 
24485796c8dcSSimon Schubert   if (arg != NULL)
24495796c8dcSSimon Schubert     return;
24505796c8dcSSimon Schubert 
24515796c8dcSSimon Schubert   frame = parse_frame_specification ("0");
2452*a45ae5f8SJohn Marino   sals = decode_line_spec (arg, DECODE_LINE_FUNFIRSTLINE);
2453*a45ae5f8SJohn Marino   cleanups = make_cleanup (xfree, sals.sals);
24545796c8dcSSimon Schubert   func_bounds = (struct function_bounds *) xmalloc (
24555796c8dcSSimon Schubert 			      sizeof (struct function_bounds) * sals.nelts);
2456*a45ae5f8SJohn Marino   make_cleanup (xfree, func_bounds);
24575796c8dcSSimon Schubert   for (i = 0; (i < sals.nelts && !found); i++)
24585796c8dcSSimon Schubert     {
2459*a45ae5f8SJohn Marino       if (sals.sals[i].pspace != current_program_space)
2460*a45ae5f8SJohn Marino 	func_bounds[i].low = func_bounds[i].high = 0;
2461*a45ae5f8SJohn Marino       else if (sals.sals[i].pc == 0
24625796c8dcSSimon Schubert 	       || find_pc_partial_function (sals.sals[i].pc, NULL,
24635796c8dcSSimon Schubert 					    &func_bounds[i].low,
24645796c8dcSSimon Schubert 					    &func_bounds[i].high) == 0)
24655796c8dcSSimon Schubert 	{
24665796c8dcSSimon Schubert 	  func_bounds[i].low = func_bounds[i].high = 0;
24675796c8dcSSimon Schubert 	}
24685796c8dcSSimon Schubert     }
24695796c8dcSSimon Schubert 
24705796c8dcSSimon Schubert   do
24715796c8dcSSimon Schubert     {
24725796c8dcSSimon Schubert       for (i = 0; (i < sals.nelts && !found); i++)
24735796c8dcSSimon Schubert 	found = (get_frame_pc (frame) >= func_bounds[i].low
24745796c8dcSSimon Schubert 		 && get_frame_pc (frame) < func_bounds[i].high);
24755796c8dcSSimon Schubert       if (!found)
24765796c8dcSSimon Schubert 	{
24775796c8dcSSimon Schubert 	  level = 1;
24785796c8dcSSimon Schubert 	  frame = find_relative_frame (frame, &level);
24795796c8dcSSimon Schubert 	}
24805796c8dcSSimon Schubert     }
24815796c8dcSSimon Schubert   while (!found && level == 0);
24825796c8dcSSimon Schubert 
2483*a45ae5f8SJohn Marino   do_cleanups (cleanups);
24845796c8dcSSimon Schubert 
24855796c8dcSSimon Schubert   if (!found)
24865796c8dcSSimon Schubert     printf_filtered (_("'%s' not within current stack frame.\n"), arg);
24875796c8dcSSimon Schubert   else if (frame != get_selected_frame (NULL))
24885796c8dcSSimon Schubert     select_and_print_frame (frame);
24895796c8dcSSimon Schubert }
24905796c8dcSSimon Schubert 
24915796c8dcSSimon Schubert /* Gets the language of the current frame.  */
24925796c8dcSSimon Schubert 
24935796c8dcSSimon Schubert enum language
24945796c8dcSSimon Schubert get_frame_language (void)
24955796c8dcSSimon Schubert {
24965796c8dcSSimon Schubert   struct frame_info *frame = deprecated_safe_get_selected_frame ();
24975796c8dcSSimon Schubert 
24985796c8dcSSimon Schubert   if (frame)
24995796c8dcSSimon Schubert     {
2500c50c785cSJohn Marino       volatile struct gdb_exception ex;
2501c50c785cSJohn Marino       CORE_ADDR pc = 0;
2502c50c785cSJohn Marino       struct symtab *s;
2503c50c785cSJohn Marino 
25045796c8dcSSimon Schubert       /* We determine the current frame language by looking up its
25055796c8dcSSimon Schubert          associated symtab.  To retrieve this symtab, we use the frame
25065796c8dcSSimon Schubert          PC.  However we cannot use the frame PC as is, because it
25075796c8dcSSimon Schubert          usually points to the instruction following the "call", which
25085796c8dcSSimon Schubert          is sometimes the first instruction of another function.  So
25095796c8dcSSimon Schubert          we rely on get_frame_address_in_block(), it provides us with
25105796c8dcSSimon Schubert          a PC that is guaranteed to be inside the frame's code
25115796c8dcSSimon Schubert          block.  */
25125796c8dcSSimon Schubert 
2513c50c785cSJohn Marino       TRY_CATCH (ex, RETURN_MASK_ERROR)
2514c50c785cSJohn Marino 	{
2515c50c785cSJohn Marino 	  pc = get_frame_address_in_block (frame);
2516c50c785cSJohn Marino 	}
2517c50c785cSJohn Marino       if (ex.reason < 0)
2518c50c785cSJohn Marino 	{
2519c50c785cSJohn Marino 	  if (ex.error != NOT_AVAILABLE_ERROR)
2520c50c785cSJohn Marino 	    throw_exception (ex);
2521c50c785cSJohn Marino 	}
2522c50c785cSJohn Marino       else
2523c50c785cSJohn Marino 	{
2524c50c785cSJohn Marino 	  s = find_pc_symtab (pc);
2525c50c785cSJohn Marino 	  if (s != NULL)
25265796c8dcSSimon Schubert 	    return s->language;
25275796c8dcSSimon Schubert 	}
2528c50c785cSJohn Marino     }
25295796c8dcSSimon Schubert 
25305796c8dcSSimon Schubert   return language_unknown;
25315796c8dcSSimon Schubert }
25325796c8dcSSimon Schubert 
25335796c8dcSSimon Schubert 
25345796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes.  */
25355796c8dcSSimon Schubert void _initialize_stack (void);
25365796c8dcSSimon Schubert 
25375796c8dcSSimon Schubert void
25385796c8dcSSimon Schubert _initialize_stack (void)
25395796c8dcSSimon Schubert {
25405796c8dcSSimon Schubert   add_com ("return", class_stack, return_command, _("\
25415796c8dcSSimon Schubert Make selected stack frame return to its caller.\n\
25425796c8dcSSimon Schubert Control remains in the debugger, but when you continue\n\
25435796c8dcSSimon Schubert execution will resume in the frame above the one now selected.\n\
25445796c8dcSSimon Schubert If an argument is given, it is an expression for the value to return."));
25455796c8dcSSimon Schubert 
25465796c8dcSSimon Schubert   add_com ("up", class_stack, up_command, _("\
25475796c8dcSSimon Schubert Select and print stack frame that called this one.\n\
25485796c8dcSSimon Schubert An argument says how many frames up to go."));
25495796c8dcSSimon Schubert   add_com ("up-silently", class_support, up_silently_command, _("\
25505796c8dcSSimon Schubert Same as the `up' command, but does not print anything.\n\
25515796c8dcSSimon Schubert This is useful in command scripts."));
25525796c8dcSSimon Schubert 
25535796c8dcSSimon Schubert   add_com ("down", class_stack, down_command, _("\
25545796c8dcSSimon Schubert Select and print stack frame called by this one.\n\
25555796c8dcSSimon Schubert An argument says how many frames down to go."));
25565796c8dcSSimon Schubert   add_com_alias ("do", "down", class_stack, 1);
25575796c8dcSSimon Schubert   add_com_alias ("dow", "down", class_stack, 1);
25585796c8dcSSimon Schubert   add_com ("down-silently", class_support, down_silently_command, _("\
25595796c8dcSSimon Schubert Same as the `down' command, but does not print anything.\n\
25605796c8dcSSimon Schubert This is useful in command scripts."));
25615796c8dcSSimon Schubert 
25625796c8dcSSimon Schubert   add_com ("frame", class_stack, frame_command, _("\
2563c50c785cSJohn Marino Select and print a stack frame.\nWith no argument, \
2564c50c785cSJohn Marino print the selected stack frame.  (See also \"info frame\").\n\
25655796c8dcSSimon Schubert An argument specifies the frame to select.\n\
25665796c8dcSSimon Schubert It can be a stack frame number or the address of the frame.\n\
25675796c8dcSSimon Schubert With argument, nothing is printed if input is coming from\n\
25685796c8dcSSimon Schubert a command file or a user-defined command."));
25695796c8dcSSimon Schubert 
25705796c8dcSSimon Schubert   add_com_alias ("f", "frame", class_stack, 1);
25715796c8dcSSimon Schubert 
25725796c8dcSSimon Schubert   if (xdb_commands)
25735796c8dcSSimon Schubert     {
25745796c8dcSSimon Schubert       add_com ("L", class_stack, current_frame_command,
25755796c8dcSSimon Schubert 	       _("Print the current stack frame.\n"));
25765796c8dcSSimon Schubert       add_com_alias ("V", "frame", class_stack, 1);
25775796c8dcSSimon Schubert     }
25785796c8dcSSimon Schubert   add_com ("select-frame", class_stack, select_frame_command, _("\
25795796c8dcSSimon Schubert Select a stack frame without printing anything.\n\
25805796c8dcSSimon Schubert An argument specifies the frame to select.\n\
25815796c8dcSSimon Schubert It can be a stack frame number or the address of the frame.\n"));
25825796c8dcSSimon Schubert 
25835796c8dcSSimon Schubert   add_com ("backtrace", class_stack, backtrace_command, _("\
25845796c8dcSSimon Schubert Print backtrace of all stack frames, or innermost COUNT frames.\n\
2585c50c785cSJohn Marino With a negative argument, print outermost -COUNT frames.\nUse of the \
2586c50c785cSJohn Marino 'full' qualifier also prints the values of the local variables.\n"));
25875796c8dcSSimon Schubert   add_com_alias ("bt", "backtrace", class_stack, 0);
25885796c8dcSSimon Schubert   if (xdb_commands)
25895796c8dcSSimon Schubert     {
25905796c8dcSSimon Schubert       add_com_alias ("t", "backtrace", class_stack, 0);
25915796c8dcSSimon Schubert       add_com ("T", class_stack, backtrace_full_command, _("\
25925796c8dcSSimon Schubert Print backtrace of all stack frames, or innermost COUNT frames\n\
25935796c8dcSSimon Schubert and the values of the local variables.\n\
25945796c8dcSSimon Schubert With a negative argument, print outermost -COUNT frames.\n\
25955796c8dcSSimon Schubert Usage: T <count>\n"));
25965796c8dcSSimon Schubert     }
25975796c8dcSSimon Schubert 
25985796c8dcSSimon Schubert   add_com_alias ("where", "backtrace", class_alias, 0);
25995796c8dcSSimon Schubert   add_info ("stack", backtrace_command,
26005796c8dcSSimon Schubert 	    _("Backtrace of the stack, or innermost COUNT frames."));
26015796c8dcSSimon Schubert   add_info_alias ("s", "stack", 1);
26025796c8dcSSimon Schubert   add_info ("frame", frame_info,
26035796c8dcSSimon Schubert 	    _("All about selected stack frame, or frame at ADDR."));
26045796c8dcSSimon Schubert   add_info_alias ("f", "frame", 1);
26055796c8dcSSimon Schubert   add_info ("locals", locals_info,
26065796c8dcSSimon Schubert 	    _("Local variables of current stack frame."));
26075796c8dcSSimon Schubert   add_info ("args", args_info,
26085796c8dcSSimon Schubert 	    _("Argument variables of current stack frame."));
26095796c8dcSSimon Schubert   if (xdb_commands)
26105796c8dcSSimon Schubert     add_com ("l", class_info, args_plus_locals_info,
26115796c8dcSSimon Schubert 	     _("Argument and local variables of current stack frame."));
26125796c8dcSSimon Schubert 
26135796c8dcSSimon Schubert   if (dbx_commands)
26145796c8dcSSimon Schubert     add_com ("func", class_stack, func_command, _("\
26155796c8dcSSimon Schubert Select the stack frame that contains <func>.\n\
26165796c8dcSSimon Schubert Usage: func <name>\n"));
26175796c8dcSSimon Schubert 
26185796c8dcSSimon Schubert   add_info ("catch", catch_info,
26195796c8dcSSimon Schubert 	    _("Exceptions that can be caught in the current stack frame."));
26205796c8dcSSimon Schubert 
26215796c8dcSSimon Schubert   add_setshow_enum_cmd ("frame-arguments", class_stack,
26225796c8dcSSimon Schubert 			print_frame_arguments_choices, &print_frame_arguments,
26235796c8dcSSimon Schubert 			_("Set printing of non-scalar frame arguments"),
26245796c8dcSSimon Schubert 			_("Show printing of non-scalar frame arguments"),
26255796c8dcSSimon Schubert 			NULL, NULL, NULL, &setprintlist, &showprintlist);
26265796c8dcSSimon Schubert 
26275796c8dcSSimon Schubert   add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
26285796c8dcSSimon Schubert 			        &disassemble_next_line, _("\
2629c50c785cSJohn Marino Set whether to disassemble next source line or insn when execution stops."),
2630c50c785cSJohn Marino 				_("\
2631c50c785cSJohn Marino Show whether to disassemble next source line or insn when execution stops."),
2632c50c785cSJohn Marino 				_("\
26335796c8dcSSimon Schubert If ON, GDB will display disassembly of the next source line, in addition\n\
26345796c8dcSSimon Schubert to displaying the source line itself.  If the next source line cannot\n\
26355796c8dcSSimon Schubert be displayed (e.g., source is unavailable or there's no line info), GDB\n\
26365796c8dcSSimon Schubert will display disassembly of next instruction instead of showing the\n\
26375796c8dcSSimon Schubert source line.\n\
26385796c8dcSSimon Schubert If AUTO, display disassembly of next instruction only if the source line\n\
26395796c8dcSSimon Schubert cannot be displayed.\n\
26405796c8dcSSimon Schubert If OFF (which is the default), never display the disassembly of the next\n\
26415796c8dcSSimon Schubert source line."),
26425796c8dcSSimon Schubert 			        NULL,
26435796c8dcSSimon Schubert 			        show_disassemble_next_line,
26445796c8dcSSimon Schubert 			        &setlist, &showlist);
26455796c8dcSSimon Schubert   disassemble_next_line = AUTO_BOOLEAN_FALSE;
2646*a45ae5f8SJohn Marino 
2647*a45ae5f8SJohn Marino   add_setshow_enum_cmd ("entry-values", class_stack,
2648*a45ae5f8SJohn Marino 			print_entry_values_choices, &print_entry_values,
2649*a45ae5f8SJohn Marino 			_("Set printing of function arguments at function "
2650*a45ae5f8SJohn Marino 			  "entry"),
2651*a45ae5f8SJohn Marino 			_("Show printing of function arguments at function "
2652*a45ae5f8SJohn Marino 			  "entry"),
2653*a45ae5f8SJohn Marino 			_("\
2654*a45ae5f8SJohn Marino GDB can sometimes determine the values of function arguments at entry,\n\
2655*a45ae5f8SJohn Marino in addition to their current values.  This option tells GDB whether\n\
2656*a45ae5f8SJohn Marino to print the current value, the value at entry (marked as val@entry),\n\
2657*a45ae5f8SJohn Marino or both.  Note that one or both of these values may be <optimized out>."),
2658*a45ae5f8SJohn Marino 			NULL, NULL, &setprintlist, &showprintlist);
26595796c8dcSSimon Schubert }
2660