xref: /dflybsd-src/contrib/gdb-7/gdb/stack.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Print and select stack frames for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 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"
48a45ae5f8SJohn Marino #include "linespec.h"
49*ef5ccd6cSJohn Marino #include "cli/cli-utils.h"
505796c8dcSSimon Schubert 
515796c8dcSSimon Schubert #include "gdb_assert.h"
525796c8dcSSimon Schubert #include <ctype.h>
535796c8dcSSimon Schubert #include "gdb_string.h"
545796c8dcSSimon Schubert 
55cf7f2e2dSJohn Marino #include "psymtab.h"
56cf7f2e2dSJohn Marino #include "symfile.h"
57cf7f2e2dSJohn Marino 
585796c8dcSSimon Schubert void (*deprecated_selected_frame_level_changed_hook) (int);
595796c8dcSSimon Schubert 
60a45ae5f8SJohn Marino /* The possible choices of "set print frame-arguments", and the value
615796c8dcSSimon Schubert    of this setting.  */
625796c8dcSSimon Schubert 
63*ef5ccd6cSJohn Marino static const char *const print_frame_arguments_choices[] =
645796c8dcSSimon Schubert   {"all", "scalars", "none", NULL};
655796c8dcSSimon Schubert static const char *print_frame_arguments = "scalars";
665796c8dcSSimon Schubert 
67a45ae5f8SJohn Marino /* The possible choices of "set print entry-values", and the value
68a45ae5f8SJohn Marino    of this setting.  */
69a45ae5f8SJohn Marino 
70a45ae5f8SJohn Marino const char print_entry_values_no[] = "no";
71a45ae5f8SJohn Marino const char print_entry_values_only[] = "only";
72a45ae5f8SJohn Marino const char print_entry_values_preferred[] = "preferred";
73a45ae5f8SJohn Marino const char print_entry_values_if_needed[] = "if-needed";
74a45ae5f8SJohn Marino const char print_entry_values_both[] = "both";
75a45ae5f8SJohn Marino const char print_entry_values_compact[] = "compact";
76a45ae5f8SJohn Marino const char print_entry_values_default[] = "default";
77*ef5ccd6cSJohn Marino static const char *const print_entry_values_choices[] =
78a45ae5f8SJohn Marino {
79a45ae5f8SJohn Marino   print_entry_values_no,
80a45ae5f8SJohn Marino   print_entry_values_only,
81a45ae5f8SJohn Marino   print_entry_values_preferred,
82a45ae5f8SJohn Marino   print_entry_values_if_needed,
83a45ae5f8SJohn Marino   print_entry_values_both,
84a45ae5f8SJohn Marino   print_entry_values_compact,
85a45ae5f8SJohn Marino   print_entry_values_default,
86a45ae5f8SJohn Marino   NULL
87a45ae5f8SJohn Marino };
88a45ae5f8SJohn Marino const char *print_entry_values = print_entry_values_default;
89a45ae5f8SJohn Marino 
905796c8dcSSimon Schubert /* Prototypes for local functions.  */
915796c8dcSSimon Schubert 
925796c8dcSSimon Schubert static void print_frame_local_vars (struct frame_info *, int,
935796c8dcSSimon Schubert 				    struct ui_file *);
945796c8dcSSimon Schubert 
955796c8dcSSimon Schubert static void print_frame (struct frame_info *frame, int print_level,
965796c8dcSSimon Schubert 			 enum print_what print_what,  int print_args,
975796c8dcSSimon Schubert 			 struct symtab_and_line sal);
985796c8dcSSimon Schubert 
99a45ae5f8SJohn Marino static void set_last_displayed_sal (int valid,
100a45ae5f8SJohn Marino 				    struct program_space *pspace,
101a45ae5f8SJohn Marino 				    CORE_ADDR addr,
102a45ae5f8SJohn Marino 				    struct symtab *symtab,
103a45ae5f8SJohn Marino 				    int line);
104a45ae5f8SJohn Marino 
1055796c8dcSSimon Schubert /* Zero means do things normally; we are interacting directly with the
1065796c8dcSSimon Schubert    user.  One means print the full filename and linenumber when a
1075796c8dcSSimon Schubert    frame is printed, and do so in a format emacs18/emacs19.22 can
1085796c8dcSSimon Schubert    parse.  Two means print similar annotations, but in many more
1095796c8dcSSimon Schubert    cases and in a slightly different syntax.  */
1105796c8dcSSimon Schubert 
1115796c8dcSSimon Schubert int annotation_level = 0;
112a45ae5f8SJohn Marino 
113a45ae5f8SJohn Marino /* These variables hold the last symtab and line we displayed to the user.
114a45ae5f8SJohn Marino  * This is where we insert a breakpoint or a skiplist entry by default.  */
115a45ae5f8SJohn Marino static int last_displayed_sal_valid = 0;
116a45ae5f8SJohn Marino static struct program_space *last_displayed_pspace = 0;
117a45ae5f8SJohn Marino static CORE_ADDR last_displayed_addr = 0;
118a45ae5f8SJohn Marino static struct symtab *last_displayed_symtab = 0;
119a45ae5f8SJohn Marino static int last_displayed_line = 0;
1205796c8dcSSimon Schubert 
1215796c8dcSSimon Schubert 
1225796c8dcSSimon Schubert /* Return 1 if we should display the address in addition to the location,
1235796c8dcSSimon Schubert    because we are in the middle of a statement.  */
1245796c8dcSSimon Schubert 
1255796c8dcSSimon Schubert static int
frame_show_address(struct frame_info * frame,struct symtab_and_line sal)1265796c8dcSSimon Schubert frame_show_address (struct frame_info *frame,
1275796c8dcSSimon Schubert 		    struct symtab_and_line sal)
1285796c8dcSSimon Schubert {
1295796c8dcSSimon Schubert   /* If there is a line number, but no PC, then there is no location
1305796c8dcSSimon Schubert      information associated with this sal.  The only way that should
1315796c8dcSSimon Schubert      happen is for the call sites of inlined functions (SAL comes from
1325796c8dcSSimon Schubert      find_frame_sal).  Otherwise, we would have some PC range if the
1335796c8dcSSimon Schubert      SAL came from a line table.  */
1345796c8dcSSimon Schubert   if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
1355796c8dcSSimon Schubert     {
1365796c8dcSSimon Schubert       if (get_next_frame (frame) == NULL)
1375796c8dcSSimon Schubert 	gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
1385796c8dcSSimon Schubert       else
1395796c8dcSSimon Schubert 	gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
1405796c8dcSSimon Schubert       return 0;
1415796c8dcSSimon Schubert     }
1425796c8dcSSimon Schubert 
1435796c8dcSSimon Schubert   return get_frame_pc (frame) != sal.pc;
1445796c8dcSSimon Schubert }
1455796c8dcSSimon Schubert 
1465796c8dcSSimon Schubert /* Show or print a stack frame FRAME briefly.  The output is format
1475796c8dcSSimon Schubert    according to PRINT_LEVEL and PRINT_WHAT printing the frame's
1485796c8dcSSimon Schubert    relative level, function name, argument list, and file name and
1495796c8dcSSimon Schubert    line number.  If the frame's PC is not at the beginning of the
1505796c8dcSSimon Schubert    source line, the actual PC is printed at the beginning.  */
1515796c8dcSSimon Schubert 
1525796c8dcSSimon Schubert void
print_stack_frame(struct frame_info * frame,int print_level,enum print_what print_what)1535796c8dcSSimon Schubert print_stack_frame (struct frame_info *frame, int print_level,
1545796c8dcSSimon Schubert 		   enum print_what print_what)
1555796c8dcSSimon Schubert {
156a45ae5f8SJohn Marino   volatile struct gdb_exception e;
1575796c8dcSSimon Schubert 
1585796c8dcSSimon Schubert   /* For mi, alway print location and address.  */
159a45ae5f8SJohn Marino   if (ui_out_is_mi_like_p (current_uiout))
160a45ae5f8SJohn Marino     print_what = LOC_AND_ADDRESS;
1615796c8dcSSimon Schubert 
162a45ae5f8SJohn Marino   TRY_CATCH (e, RETURN_MASK_ERROR)
1635796c8dcSSimon Schubert     {
164a45ae5f8SJohn Marino       int center = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
1655796c8dcSSimon Schubert 
166a45ae5f8SJohn Marino       print_frame_info (frame, print_level, print_what, 1 /* print_args */);
167a45ae5f8SJohn Marino       set_current_sal_from_frame (frame, center);
168a45ae5f8SJohn Marino     }
169a45ae5f8SJohn Marino }
1705796c8dcSSimon Schubert 
1715796c8dcSSimon Schubert /* Print nameless arguments of frame FRAME on STREAM, where START is
1725796c8dcSSimon Schubert    the offset of the first nameless argument, and NUM is the number of
1735796c8dcSSimon Schubert    nameless arguments to print.  FIRST is nonzero if this is the first
1745796c8dcSSimon Schubert    argument (not just the first nameless argument).  */
1755796c8dcSSimon Schubert 
1765796c8dcSSimon Schubert static void
print_frame_nameless_args(struct frame_info * frame,long start,int num,int first,struct ui_file * stream)1775796c8dcSSimon Schubert print_frame_nameless_args (struct frame_info *frame, long start, int num,
1785796c8dcSSimon Schubert 			   int first, struct ui_file *stream)
1795796c8dcSSimon Schubert {
1805796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
1815796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1825796c8dcSSimon Schubert   int i;
1835796c8dcSSimon Schubert   CORE_ADDR argsaddr;
1845796c8dcSSimon Schubert   long arg_value;
1855796c8dcSSimon Schubert 
1865796c8dcSSimon Schubert   for (i = 0; i < num; i++)
1875796c8dcSSimon Schubert     {
1885796c8dcSSimon Schubert       QUIT;
1895796c8dcSSimon Schubert       argsaddr = get_frame_args_address (frame);
1905796c8dcSSimon Schubert       if (!argsaddr)
1915796c8dcSSimon Schubert 	return;
1925796c8dcSSimon Schubert       arg_value = read_memory_integer (argsaddr + start,
1935796c8dcSSimon Schubert 				       sizeof (int), byte_order);
1945796c8dcSSimon Schubert       if (!first)
1955796c8dcSSimon Schubert 	fprintf_filtered (stream, ", ");
1965796c8dcSSimon Schubert       fprintf_filtered (stream, "%ld", arg_value);
1975796c8dcSSimon Schubert       first = 0;
1985796c8dcSSimon Schubert       start += sizeof (int);
1995796c8dcSSimon Schubert     }
2005796c8dcSSimon Schubert }
2015796c8dcSSimon Schubert 
202a45ae5f8SJohn Marino /* Print single argument of inferior function.  ARG must be already
203a45ae5f8SJohn Marino    read in.
204a45ae5f8SJohn Marino 
205a45ae5f8SJohn Marino    Errors are printed as if they would be the parameter value.  Use zeroed ARG
206a45ae5f8SJohn Marino    iff it should not be printed accoring to user settings.  */
207a45ae5f8SJohn Marino 
208a45ae5f8SJohn Marino static void
print_frame_arg(const struct frame_arg * arg)209a45ae5f8SJohn Marino print_frame_arg (const struct frame_arg *arg)
210a45ae5f8SJohn Marino {
211a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
212a45ae5f8SJohn Marino   volatile struct gdb_exception except;
213a45ae5f8SJohn Marino   struct cleanup *old_chain;
214*ef5ccd6cSJohn Marino   struct ui_file *stb;
215a45ae5f8SJohn Marino 
216*ef5ccd6cSJohn Marino   stb = mem_fileopen ();
217*ef5ccd6cSJohn Marino   old_chain = make_cleanup_ui_file_delete (stb);
218a45ae5f8SJohn Marino 
219a45ae5f8SJohn Marino   gdb_assert (!arg->val || !arg->error);
220a45ae5f8SJohn Marino   gdb_assert (arg->entry_kind == print_entry_values_no
221a45ae5f8SJohn Marino 	      || arg->entry_kind == print_entry_values_only
222a45ae5f8SJohn Marino 	      || (!ui_out_is_mi_like_p (uiout)
223a45ae5f8SJohn Marino 		  && arg->entry_kind == print_entry_values_compact));
224a45ae5f8SJohn Marino 
225a45ae5f8SJohn Marino   annotate_arg_begin ();
226a45ae5f8SJohn Marino 
227a45ae5f8SJohn Marino   make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
228*ef5ccd6cSJohn Marino   fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
229a45ae5f8SJohn Marino 			   SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
230a45ae5f8SJohn Marino   if (arg->entry_kind == print_entry_values_compact)
231a45ae5f8SJohn Marino     {
232a45ae5f8SJohn Marino       /* It is OK to provide invalid MI-like stream as with
233a45ae5f8SJohn Marino 	 PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
234*ef5ccd6cSJohn Marino       fputs_filtered ("=", stb);
235a45ae5f8SJohn Marino 
236*ef5ccd6cSJohn Marino       fprintf_symbol_filtered (stb, SYMBOL_PRINT_NAME (arg->sym),
237a45ae5f8SJohn Marino 			       SYMBOL_LANGUAGE (arg->sym),
238a45ae5f8SJohn Marino 			       DMGL_PARAMS | DMGL_ANSI);
239a45ae5f8SJohn Marino     }
240a45ae5f8SJohn Marino   if (arg->entry_kind == print_entry_values_only
241a45ae5f8SJohn Marino       || arg->entry_kind == print_entry_values_compact)
242*ef5ccd6cSJohn Marino     fputs_filtered ("@entry", stb);
243a45ae5f8SJohn Marino   ui_out_field_stream (uiout, "name", stb);
244a45ae5f8SJohn Marino   annotate_arg_name_end ();
245a45ae5f8SJohn Marino   ui_out_text (uiout, "=");
246a45ae5f8SJohn Marino 
247a45ae5f8SJohn Marino   if (!arg->val && !arg->error)
248a45ae5f8SJohn Marino     ui_out_text (uiout, "...");
249a45ae5f8SJohn Marino   else
250a45ae5f8SJohn Marino     {
251a45ae5f8SJohn Marino       if (arg->error)
252a45ae5f8SJohn Marino 	except.message = arg->error;
253a45ae5f8SJohn Marino       else
254a45ae5f8SJohn Marino 	{
255a45ae5f8SJohn Marino 	  /* TRY_CATCH has two statements, wrap it in a block.  */
256a45ae5f8SJohn Marino 
257a45ae5f8SJohn Marino 	  TRY_CATCH (except, RETURN_MASK_ERROR)
258a45ae5f8SJohn Marino 	    {
259a45ae5f8SJohn Marino 	      const struct language_defn *language;
260a45ae5f8SJohn Marino 	      struct value_print_options opts;
261a45ae5f8SJohn Marino 
262a45ae5f8SJohn Marino 	      /* Avoid value_print because it will deref ref parameters.  We
263a45ae5f8SJohn Marino 		 just want to print their addresses.  Print ??? for args whose
264a45ae5f8SJohn Marino 		 address we do not know.  We pass 2 as "recurse" to val_print
265a45ae5f8SJohn Marino 		 because our standard indentation here is 4 spaces, and
266a45ae5f8SJohn Marino 		 val_print indents 2 for each recurse.  */
267a45ae5f8SJohn Marino 
268a45ae5f8SJohn Marino 	      annotate_arg_value (value_type (arg->val));
269a45ae5f8SJohn Marino 
270a45ae5f8SJohn Marino 	      /* Use the appropriate language to display our symbol, unless the
271a45ae5f8SJohn Marino 		 user forced the language to a specific language.  */
272a45ae5f8SJohn Marino 	      if (language_mode == language_mode_auto)
273a45ae5f8SJohn Marino 		language = language_def (SYMBOL_LANGUAGE (arg->sym));
274a45ae5f8SJohn Marino 	      else
275a45ae5f8SJohn Marino 		language = current_language;
276a45ae5f8SJohn Marino 
277a45ae5f8SJohn Marino 	      get_raw_print_options (&opts);
278a45ae5f8SJohn Marino 	      opts.deref_ref = 1;
279a45ae5f8SJohn Marino 
280a45ae5f8SJohn Marino 	      /* True in "summary" mode, false otherwise.  */
281a45ae5f8SJohn Marino 	      opts.summary = !strcmp (print_frame_arguments, "scalars");
282a45ae5f8SJohn Marino 
283*ef5ccd6cSJohn Marino 	      common_val_print (arg->val, stb, 2, &opts, language);
284a45ae5f8SJohn Marino 	    }
285a45ae5f8SJohn Marino 	}
286a45ae5f8SJohn Marino       if (except.message)
287*ef5ccd6cSJohn Marino 	fprintf_filtered (stb, _("<error reading variable: %s>"),
288a45ae5f8SJohn Marino 			  except.message);
289a45ae5f8SJohn Marino     }
290a45ae5f8SJohn Marino 
291a45ae5f8SJohn Marino   ui_out_field_stream (uiout, "value", stb);
292a45ae5f8SJohn Marino 
293*ef5ccd6cSJohn Marino   /* Also invoke ui_out_tuple_end.  */
294a45ae5f8SJohn Marino   do_cleanups (old_chain);
295a45ae5f8SJohn Marino 
296a45ae5f8SJohn Marino   annotate_arg_end ();
297a45ae5f8SJohn Marino }
298a45ae5f8SJohn Marino 
299*ef5ccd6cSJohn Marino /* Read in inferior function local SYM at FRAME into ARGP.  Caller is
300*ef5ccd6cSJohn Marino    responsible for xfree of ARGP->ERROR.  This function never throws an
301*ef5ccd6cSJohn Marino    exception.  */
302*ef5ccd6cSJohn Marino 
303*ef5ccd6cSJohn Marino void
read_frame_local(struct symbol * sym,struct frame_info * frame,struct frame_arg * argp)304*ef5ccd6cSJohn Marino read_frame_local (struct symbol *sym, struct frame_info *frame,
305*ef5ccd6cSJohn Marino 		  struct frame_arg *argp)
306*ef5ccd6cSJohn Marino {
307*ef5ccd6cSJohn Marino   volatile struct gdb_exception except;
308*ef5ccd6cSJohn Marino   struct value *val = NULL;
309*ef5ccd6cSJohn Marino 
310*ef5ccd6cSJohn Marino   TRY_CATCH (except, RETURN_MASK_ERROR)
311*ef5ccd6cSJohn Marino     {
312*ef5ccd6cSJohn Marino       val = read_var_value (sym, frame);
313*ef5ccd6cSJohn Marino     }
314*ef5ccd6cSJohn Marino 
315*ef5ccd6cSJohn Marino   argp->error = (val == NULL) ? xstrdup (except.message) : NULL;
316*ef5ccd6cSJohn Marino   argp->sym = sym;
317*ef5ccd6cSJohn Marino   argp->val = val;
318*ef5ccd6cSJohn Marino }
319*ef5ccd6cSJohn Marino 
320a45ae5f8SJohn Marino /* Read in inferior function parameter SYM at FRAME into ARGP.  Caller is
321a45ae5f8SJohn Marino    responsible for xfree of ARGP->ERROR.  This function never throws an
322a45ae5f8SJohn Marino    exception.  */
323a45ae5f8SJohn Marino 
324a45ae5f8SJohn Marino void
read_frame_arg(struct symbol * sym,struct frame_info * frame,struct frame_arg * argp,struct frame_arg * entryargp)325a45ae5f8SJohn Marino read_frame_arg (struct symbol *sym, struct frame_info *frame,
326a45ae5f8SJohn Marino 	        struct frame_arg *argp, struct frame_arg *entryargp)
327a45ae5f8SJohn Marino {
328a45ae5f8SJohn Marino   struct value *val = NULL, *entryval = NULL;
329a45ae5f8SJohn Marino   char *val_error = NULL, *entryval_error = NULL;
330a45ae5f8SJohn Marino   int val_equal = 0;
331a45ae5f8SJohn Marino   volatile struct gdb_exception except;
332a45ae5f8SJohn Marino 
333a45ae5f8SJohn Marino   if (print_entry_values != print_entry_values_only
334a45ae5f8SJohn Marino       && print_entry_values != print_entry_values_preferred)
335a45ae5f8SJohn Marino     {
336a45ae5f8SJohn Marino       TRY_CATCH (except, RETURN_MASK_ERROR)
337a45ae5f8SJohn Marino 	{
338a45ae5f8SJohn Marino 	  val = read_var_value (sym, frame);
339a45ae5f8SJohn Marino 	}
340a45ae5f8SJohn Marino       if (!val)
341a45ae5f8SJohn Marino 	{
342a45ae5f8SJohn Marino 	  val_error = alloca (strlen (except.message) + 1);
343a45ae5f8SJohn Marino 	  strcpy (val_error, except.message);
344a45ae5f8SJohn Marino 	}
345a45ae5f8SJohn Marino     }
346a45ae5f8SJohn Marino 
347a45ae5f8SJohn Marino   if (SYMBOL_CLASS (sym) == LOC_COMPUTED
348a45ae5f8SJohn Marino       && print_entry_values != print_entry_values_no
349a45ae5f8SJohn Marino       && (print_entry_values != print_entry_values_if_needed
350a45ae5f8SJohn Marino 	  || !val || value_optimized_out (val)))
351a45ae5f8SJohn Marino     {
352a45ae5f8SJohn Marino       TRY_CATCH (except, RETURN_MASK_ERROR)
353a45ae5f8SJohn Marino 	{
354a45ae5f8SJohn Marino 	  const struct symbol_computed_ops *ops;
355a45ae5f8SJohn Marino 
356a45ae5f8SJohn Marino 	  ops = SYMBOL_COMPUTED_OPS (sym);
357a45ae5f8SJohn Marino 	  entryval = ops->read_variable_at_entry (sym, frame);
358a45ae5f8SJohn Marino 	}
359a45ae5f8SJohn Marino       if (!entryval)
360a45ae5f8SJohn Marino 	{
361a45ae5f8SJohn Marino 	  entryval_error = alloca (strlen (except.message) + 1);
362a45ae5f8SJohn Marino 	  strcpy (entryval_error, except.message);
363a45ae5f8SJohn Marino 	}
364a45ae5f8SJohn Marino 
365a45ae5f8SJohn Marino       if (except.error == NO_ENTRY_VALUE_ERROR
366a45ae5f8SJohn Marino 	  || (entryval && value_optimized_out (entryval)))
367a45ae5f8SJohn Marino 	{
368a45ae5f8SJohn Marino 	  entryval = NULL;
369a45ae5f8SJohn Marino 	  entryval_error = NULL;
370a45ae5f8SJohn Marino 	}
371a45ae5f8SJohn Marino 
372a45ae5f8SJohn Marino       if (print_entry_values == print_entry_values_compact
373a45ae5f8SJohn Marino 	  || print_entry_values == print_entry_values_default)
374a45ae5f8SJohn Marino 	{
375a45ae5f8SJohn Marino 	  /* For MI do not try to use print_entry_values_compact for ARGP.  */
376a45ae5f8SJohn Marino 
377a45ae5f8SJohn Marino 	  if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
378a45ae5f8SJohn Marino 	    {
379*ef5ccd6cSJohn Marino 	      struct type *type = value_type (val);
380a45ae5f8SJohn Marino 
381a45ae5f8SJohn Marino 	      if (!value_optimized_out (val) && value_lazy (val))
382a45ae5f8SJohn Marino 		value_fetch_lazy (val);
383a45ae5f8SJohn Marino 	      if (!value_optimized_out (val) && value_lazy (entryval))
384a45ae5f8SJohn Marino 		value_fetch_lazy (entryval);
385a45ae5f8SJohn Marino 	      if (!value_optimized_out (val)
386*ef5ccd6cSJohn Marino 		  && value_available_contents_eq (val, 0, entryval, 0,
387*ef5ccd6cSJohn Marino 						  TYPE_LENGTH (type)))
388a45ae5f8SJohn Marino 		{
389a45ae5f8SJohn Marino 		  /* Initialize it just to avoid a GCC false warning.  */
390a45ae5f8SJohn Marino 		  struct value *val_deref = NULL, *entryval_deref;
391a45ae5f8SJohn Marino 
392a45ae5f8SJohn Marino 		  /* DW_AT_GNU_call_site_value does match with the current
393a45ae5f8SJohn Marino 		     value.  If it is a reference still try to verify if
394a45ae5f8SJohn Marino 		     dereferenced DW_AT_GNU_call_site_data_value does not
395a45ae5f8SJohn Marino 		     differ.  */
396a45ae5f8SJohn Marino 
397a45ae5f8SJohn Marino 		  TRY_CATCH (except, RETURN_MASK_ERROR)
398a45ae5f8SJohn Marino 		    {
399*ef5ccd6cSJohn Marino 		      struct type *type_deref;
400a45ae5f8SJohn Marino 
401a45ae5f8SJohn Marino 		      val_deref = coerce_ref (val);
402a45ae5f8SJohn Marino 		      if (value_lazy (val_deref))
403a45ae5f8SJohn Marino 			value_fetch_lazy (val_deref);
404*ef5ccd6cSJohn Marino 		      type_deref = value_type (val_deref);
405a45ae5f8SJohn Marino 
406a45ae5f8SJohn Marino 		      entryval_deref = coerce_ref (entryval);
407a45ae5f8SJohn Marino 		      if (value_lazy (entryval_deref))
408a45ae5f8SJohn Marino 			value_fetch_lazy (entryval_deref);
409a45ae5f8SJohn Marino 
410a45ae5f8SJohn Marino 		      /* If the reference addresses match but dereferenced
411a45ae5f8SJohn Marino 			 content does not match print them.  */
412a45ae5f8SJohn Marino 		      if (val != val_deref
413a45ae5f8SJohn Marino 			  && value_available_contents_eq (val_deref, 0,
414a45ae5f8SJohn Marino 							  entryval_deref, 0,
415*ef5ccd6cSJohn Marino 						      TYPE_LENGTH (type_deref)))
416a45ae5f8SJohn Marino 			val_equal = 1;
417a45ae5f8SJohn Marino 		    }
418a45ae5f8SJohn Marino 
419a45ae5f8SJohn Marino 		  /* Value was not a reference; and its content matches.  */
420a45ae5f8SJohn Marino 		  if (val == val_deref)
421a45ae5f8SJohn Marino 		    val_equal = 1;
422a45ae5f8SJohn Marino 		  /* If the dereferenced content could not be fetched do not
423a45ae5f8SJohn Marino 		     display anything.  */
424a45ae5f8SJohn Marino 		  else if (except.error == NO_ENTRY_VALUE_ERROR)
425a45ae5f8SJohn Marino 		    val_equal = 1;
426a45ae5f8SJohn Marino 		  else if (except.message)
427a45ae5f8SJohn Marino 		    {
428a45ae5f8SJohn Marino 		      entryval_error = alloca (strlen (except.message) + 1);
429a45ae5f8SJohn Marino 		      strcpy (entryval_error, except.message);
430a45ae5f8SJohn Marino 		    }
431a45ae5f8SJohn Marino 
432a45ae5f8SJohn Marino 		  if (val_equal)
433a45ae5f8SJohn Marino 		    entryval = NULL;
434a45ae5f8SJohn Marino 		}
435a45ae5f8SJohn Marino 	    }
436a45ae5f8SJohn Marino 
437a45ae5f8SJohn Marino 	  /* Try to remove possibly duplicate error message for ENTRYARGP even
438a45ae5f8SJohn Marino 	     in MI mode.  */
439a45ae5f8SJohn Marino 
440a45ae5f8SJohn Marino 	  if (val_error && entryval_error
441a45ae5f8SJohn Marino 	      && strcmp (val_error, entryval_error) == 0)
442a45ae5f8SJohn Marino 	    {
443a45ae5f8SJohn Marino 	      entryval_error = NULL;
444a45ae5f8SJohn Marino 
445a45ae5f8SJohn Marino 	      /* Do not se VAL_EQUAL as the same error message may be shown for
446a45ae5f8SJohn Marino 		 the entry value even if no entry values are present in the
447a45ae5f8SJohn Marino 		 inferior.  */
448a45ae5f8SJohn Marino 	    }
449a45ae5f8SJohn Marino 	}
450a45ae5f8SJohn Marino     }
451a45ae5f8SJohn Marino 
452a45ae5f8SJohn Marino   if (entryval == NULL)
453a45ae5f8SJohn Marino     {
454a45ae5f8SJohn Marino       if (print_entry_values == print_entry_values_preferred)
455a45ae5f8SJohn Marino 	{
456a45ae5f8SJohn Marino 	  TRY_CATCH (except, RETURN_MASK_ERROR)
457a45ae5f8SJohn Marino 	    {
458a45ae5f8SJohn Marino 	      val = read_var_value (sym, frame);
459a45ae5f8SJohn Marino 	    }
460a45ae5f8SJohn Marino 	  if (!val)
461a45ae5f8SJohn Marino 	    {
462a45ae5f8SJohn Marino 	      val_error = alloca (strlen (except.message) + 1);
463a45ae5f8SJohn Marino 	      strcpy (val_error, except.message);
464a45ae5f8SJohn Marino 	    }
465a45ae5f8SJohn Marino 	}
466a45ae5f8SJohn Marino       if (print_entry_values == print_entry_values_only
467a45ae5f8SJohn Marino 	  || print_entry_values == print_entry_values_both
468a45ae5f8SJohn Marino 	  || (print_entry_values == print_entry_values_preferred
469a45ae5f8SJohn Marino 	      && (!val || value_optimized_out (val))))
470a45ae5f8SJohn Marino 	entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
471a45ae5f8SJohn Marino     }
472a45ae5f8SJohn Marino   if ((print_entry_values == print_entry_values_compact
473a45ae5f8SJohn Marino        || print_entry_values == print_entry_values_if_needed
474a45ae5f8SJohn Marino        || print_entry_values == print_entry_values_preferred)
475a45ae5f8SJohn Marino       && (!val || value_optimized_out (val)) && entryval != NULL)
476a45ae5f8SJohn Marino     {
477a45ae5f8SJohn Marino       val = NULL;
478a45ae5f8SJohn Marino       val_error = NULL;
479a45ae5f8SJohn Marino     }
480a45ae5f8SJohn Marino 
481a45ae5f8SJohn Marino   argp->sym = sym;
482a45ae5f8SJohn Marino   argp->val = val;
483a45ae5f8SJohn Marino   argp->error = val_error ? xstrdup (val_error) : NULL;
484a45ae5f8SJohn Marino   if (!val && !val_error)
485a45ae5f8SJohn Marino     argp->entry_kind = print_entry_values_only;
486a45ae5f8SJohn Marino   else if ((print_entry_values == print_entry_values_compact
487a45ae5f8SJohn Marino 	   || print_entry_values == print_entry_values_default) && val_equal)
488a45ae5f8SJohn Marino     {
489a45ae5f8SJohn Marino       argp->entry_kind = print_entry_values_compact;
490a45ae5f8SJohn Marino       gdb_assert (!ui_out_is_mi_like_p (current_uiout));
491a45ae5f8SJohn Marino     }
492a45ae5f8SJohn Marino   else
493a45ae5f8SJohn Marino     argp->entry_kind = print_entry_values_no;
494a45ae5f8SJohn Marino 
495a45ae5f8SJohn Marino   entryargp->sym = sym;
496a45ae5f8SJohn Marino   entryargp->val = entryval;
497a45ae5f8SJohn Marino   entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
498a45ae5f8SJohn Marino   if (!entryval && !entryval_error)
499a45ae5f8SJohn Marino     entryargp->entry_kind = print_entry_values_no;
500a45ae5f8SJohn Marino   else
501a45ae5f8SJohn Marino     entryargp->entry_kind = print_entry_values_only;
502a45ae5f8SJohn Marino }
503a45ae5f8SJohn Marino 
5045796c8dcSSimon Schubert /* Print the arguments of frame FRAME on STREAM, given the function
5055796c8dcSSimon Schubert    FUNC running in that frame (as a symbol), where NUM is the number
5065796c8dcSSimon Schubert    of arguments according to the stack frame (or -1 if the number of
5075796c8dcSSimon Schubert    arguments is unknown).  */
5085796c8dcSSimon Schubert 
5095796c8dcSSimon Schubert /* Note that currently the "number of arguments according to the
5105796c8dcSSimon Schubert    stack frame" is only known on VAX where i refers to the "number of
5115796c8dcSSimon Schubert    ints of arguments according to the stack frame".  */
5125796c8dcSSimon Schubert 
5135796c8dcSSimon Schubert static void
print_frame_args(struct symbol * func,struct frame_info * frame,int num,struct ui_file * stream)5145796c8dcSSimon Schubert print_frame_args (struct symbol *func, struct frame_info *frame,
5155796c8dcSSimon Schubert 		  int num, struct ui_file *stream)
5165796c8dcSSimon Schubert {
517a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
5185796c8dcSSimon Schubert   int first = 1;
5195796c8dcSSimon Schubert   /* Offset of next stack argument beyond the one we have seen that is
5205796c8dcSSimon Schubert      at the highest offset, or -1 if we haven't come to a stack
5215796c8dcSSimon Schubert      argument yet.  */
5225796c8dcSSimon Schubert   long highest_offset = -1;
5235796c8dcSSimon Schubert   /* Number of ints of arguments that we have printed so far.  */
5245796c8dcSSimon Schubert   int args_printed = 0;
525*ef5ccd6cSJohn Marino   struct cleanup *old_chain;
526*ef5ccd6cSJohn Marino   struct ui_file *stb;
5275796c8dcSSimon Schubert   /* True if we should print arguments, false otherwise.  */
5285796c8dcSSimon Schubert   int print_args = strcmp (print_frame_arguments, "none");
5295796c8dcSSimon Schubert 
530*ef5ccd6cSJohn Marino   stb = mem_fileopen ();
531*ef5ccd6cSJohn Marino   old_chain = make_cleanup_ui_file_delete (stb);
5325796c8dcSSimon Schubert 
5335796c8dcSSimon Schubert   if (func)
5345796c8dcSSimon Schubert     {
5355796c8dcSSimon Schubert       struct block *b = SYMBOL_BLOCK_VALUE (func);
536*ef5ccd6cSJohn Marino       struct block_iterator iter;
5375796c8dcSSimon Schubert       struct symbol *sym;
5385796c8dcSSimon Schubert 
5395796c8dcSSimon Schubert       ALL_BLOCK_SYMBOLS (b, iter, sym)
5405796c8dcSSimon Schubert         {
541a45ae5f8SJohn Marino 	  struct frame_arg arg, entryarg;
542a45ae5f8SJohn Marino 
5435796c8dcSSimon Schubert 	  QUIT;
5445796c8dcSSimon Schubert 
5455796c8dcSSimon Schubert 	  /* Keep track of the highest stack argument offset seen, and
5465796c8dcSSimon Schubert 	     skip over any kinds of symbols we don't care about.  */
5475796c8dcSSimon Schubert 
5485796c8dcSSimon Schubert 	  if (!SYMBOL_IS_ARGUMENT (sym))
5495796c8dcSSimon Schubert 	    continue;
5505796c8dcSSimon Schubert 
5515796c8dcSSimon Schubert 	  switch (SYMBOL_CLASS (sym))
5525796c8dcSSimon Schubert 	    {
5535796c8dcSSimon Schubert 	    case LOC_ARG:
5545796c8dcSSimon Schubert 	    case LOC_REF_ARG:
5555796c8dcSSimon Schubert 	      {
5565796c8dcSSimon Schubert 		long current_offset = SYMBOL_VALUE (sym);
5575796c8dcSSimon Schubert 		int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
5585796c8dcSSimon Schubert 
5595796c8dcSSimon Schubert 		/* Compute address of next argument by adding the size of
5605796c8dcSSimon Schubert 		   this argument and rounding to an int boundary.  */
5615796c8dcSSimon Schubert 		current_offset =
5625796c8dcSSimon Schubert 		  ((current_offset + arg_size + sizeof (int) - 1)
5635796c8dcSSimon Schubert 		   & ~(sizeof (int) - 1));
5645796c8dcSSimon Schubert 
5655796c8dcSSimon Schubert 		/* If this is the highest offset seen yet, set
5665796c8dcSSimon Schubert 		   highest_offset.  */
5675796c8dcSSimon Schubert 		if (highest_offset == -1
5685796c8dcSSimon Schubert 		    || (current_offset > highest_offset))
5695796c8dcSSimon Schubert 		  highest_offset = current_offset;
5705796c8dcSSimon Schubert 
5715796c8dcSSimon Schubert 		/* Add the number of ints we're about to print to
5725796c8dcSSimon Schubert 		   args_printed.  */
5735796c8dcSSimon Schubert 		args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
5745796c8dcSSimon Schubert 	      }
5755796c8dcSSimon Schubert 
5765796c8dcSSimon Schubert 	      /* We care about types of symbols, but don't need to
5775796c8dcSSimon Schubert 		 keep track of stack offsets in them.  */
5785796c8dcSSimon Schubert 	    case LOC_REGISTER:
5795796c8dcSSimon Schubert 	    case LOC_REGPARM_ADDR:
5805796c8dcSSimon Schubert 	    case LOC_COMPUTED:
5815796c8dcSSimon Schubert 	    case LOC_OPTIMIZED_OUT:
5825796c8dcSSimon Schubert 	    default:
5835796c8dcSSimon Schubert 	      break;
5845796c8dcSSimon Schubert 	    }
5855796c8dcSSimon Schubert 
5865796c8dcSSimon Schubert 	  /* We have to look up the symbol because arguments can have
5875796c8dcSSimon Schubert 	     two entries (one a parameter, one a local) and the one we
5885796c8dcSSimon Schubert 	     want is the local, which lookup_symbol will find for us.
5895796c8dcSSimon Schubert 	     This includes gcc1 (not gcc2) on SPARC when passing a
5905796c8dcSSimon Schubert 	     small structure and gcc2 when the argument type is float
5915796c8dcSSimon Schubert 	     and it is passed as a double and converted to float by
5925796c8dcSSimon Schubert 	     the prologue (in the latter case the type of the LOC_ARG
5935796c8dcSSimon Schubert 	     symbol is double and the type of the LOC_LOCAL symbol is
5945796c8dcSSimon Schubert 	     float).  */
5955796c8dcSSimon Schubert 	  /* But if the parameter name is null, don't try it.  Null
5965796c8dcSSimon Schubert 	     parameter names occur on the RS/6000, for traceback
5975796c8dcSSimon Schubert 	     tables.  FIXME, should we even print them?  */
5985796c8dcSSimon Schubert 
5995796c8dcSSimon Schubert 	  if (*SYMBOL_LINKAGE_NAME (sym))
6005796c8dcSSimon Schubert 	    {
6015796c8dcSSimon Schubert 	      struct symbol *nsym;
602cf7f2e2dSJohn Marino 
6035796c8dcSSimon Schubert 	      nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
6045796c8dcSSimon Schubert 				    b, VAR_DOMAIN, NULL);
6055796c8dcSSimon Schubert 	      gdb_assert (nsym != NULL);
6065796c8dcSSimon Schubert 	      if (SYMBOL_CLASS (nsym) == LOC_REGISTER
6075796c8dcSSimon Schubert 		  && !SYMBOL_IS_ARGUMENT (nsym))
6085796c8dcSSimon Schubert 		{
6095796c8dcSSimon Schubert 		  /* There is a LOC_ARG/LOC_REGISTER pair.  This means
6105796c8dcSSimon Schubert 		     that it was passed on the stack and loaded into a
6115796c8dcSSimon Schubert 		     register, or passed in a register and stored in a
6125796c8dcSSimon Schubert 		     stack slot.  GDB 3.x used the LOC_ARG; GDB
6135796c8dcSSimon Schubert 		     4.0-4.11 used the LOC_REGISTER.
6145796c8dcSSimon Schubert 
6155796c8dcSSimon Schubert 		     Reasons for using the LOC_ARG:
6165796c8dcSSimon Schubert 
6175796c8dcSSimon Schubert 		     (1) Because find_saved_registers may be slow for
6185796c8dcSSimon Schubert 		         remote debugging.
6195796c8dcSSimon Schubert 
6205796c8dcSSimon Schubert 		     (2) Because registers are often re-used and stack
6215796c8dcSSimon Schubert 		         slots rarely (never?) are.  Therefore using
6225796c8dcSSimon Schubert 		         the stack slot is much less likely to print
6235796c8dcSSimon Schubert 		         garbage.
6245796c8dcSSimon Schubert 
6255796c8dcSSimon Schubert 		     Reasons why we might want to use the LOC_REGISTER:
6265796c8dcSSimon Schubert 
6275796c8dcSSimon Schubert 		     (1) So that the backtrace prints the same value
6285796c8dcSSimon Schubert 		         as "print foo".  I see no compelling reason
6295796c8dcSSimon Schubert 		         why this needs to be the case; having the
6305796c8dcSSimon Schubert 		         backtrace print the value which was passed
6315796c8dcSSimon Schubert 		         in, and "print foo" print the value as
6325796c8dcSSimon Schubert 		         modified within the called function, makes
6335796c8dcSSimon Schubert 		         perfect sense to me.
6345796c8dcSSimon Schubert 
6355796c8dcSSimon Schubert 		     Additional note: It might be nice if "info args"
6365796c8dcSSimon Schubert 		     displayed both values.
6375796c8dcSSimon Schubert 
6385796c8dcSSimon Schubert 		     One more note: There is a case with SPARC
6395796c8dcSSimon Schubert 		     structure passing where we need to use the
6405796c8dcSSimon Schubert 		     LOC_REGISTER, but this is dealt with by creating
6415796c8dcSSimon Schubert 		     a single LOC_REGPARM in symbol reading.  */
6425796c8dcSSimon Schubert 
6435796c8dcSSimon Schubert 		  /* Leave sym (the LOC_ARG) alone.  */
6445796c8dcSSimon Schubert 		  ;
6455796c8dcSSimon Schubert 		}
6465796c8dcSSimon Schubert 	      else
6475796c8dcSSimon Schubert 		sym = nsym;
6485796c8dcSSimon Schubert 	    }
6495796c8dcSSimon Schubert 
6505796c8dcSSimon Schubert 	  /* Print the current arg.  */
6515796c8dcSSimon Schubert 	  if (!first)
6525796c8dcSSimon Schubert 	    ui_out_text (uiout, ", ");
6535796c8dcSSimon Schubert 	  ui_out_wrap_hint (uiout, "    ");
6545796c8dcSSimon Schubert 
655a45ae5f8SJohn Marino 	  if (!print_args)
6565796c8dcSSimon Schubert 	    {
657a45ae5f8SJohn Marino 	      memset (&arg, 0, sizeof (arg));
658a45ae5f8SJohn Marino 	      arg.sym = sym;
659a45ae5f8SJohn Marino 	      arg.entry_kind = print_entry_values_no;
660a45ae5f8SJohn Marino 	      memset (&entryarg, 0, sizeof (entryarg));
661a45ae5f8SJohn Marino 	      entryarg.sym = sym;
662a45ae5f8SJohn Marino 	      entryarg.entry_kind = print_entry_values_no;
6635796c8dcSSimon Schubert 	    }
6645796c8dcSSimon Schubert 	  else
665a45ae5f8SJohn Marino 	    read_frame_arg (sym, frame, &arg, &entryarg);
666a45ae5f8SJohn Marino 
667a45ae5f8SJohn Marino 	  if (arg.entry_kind != print_entry_values_only)
668a45ae5f8SJohn Marino 	    print_frame_arg (&arg);
669a45ae5f8SJohn Marino 
670a45ae5f8SJohn Marino 	  if (entryarg.entry_kind != print_entry_values_no)
671a45ae5f8SJohn Marino 	    {
672a45ae5f8SJohn Marino 	      if (arg.entry_kind != print_entry_values_only)
673a45ae5f8SJohn Marino 		{
674a45ae5f8SJohn Marino 		  ui_out_text (uiout, ", ");
675a45ae5f8SJohn Marino 		  ui_out_wrap_hint (uiout, "    ");
6765796c8dcSSimon Schubert 		}
6775796c8dcSSimon Schubert 
678a45ae5f8SJohn Marino 	      print_frame_arg (&entryarg);
679a45ae5f8SJohn Marino 	    }
6805796c8dcSSimon Schubert 
681a45ae5f8SJohn Marino 	  xfree (arg.error);
682a45ae5f8SJohn Marino 	  xfree (entryarg.error);
6835796c8dcSSimon Schubert 
6845796c8dcSSimon Schubert 	  first = 0;
6855796c8dcSSimon Schubert 	}
6865796c8dcSSimon Schubert     }
6875796c8dcSSimon Schubert 
6885796c8dcSSimon Schubert   /* Don't print nameless args in situations where we don't know
6895796c8dcSSimon Schubert      enough about the stack to find them.  */
6905796c8dcSSimon Schubert   if (num != -1)
6915796c8dcSSimon Schubert     {
6925796c8dcSSimon Schubert       long start;
6935796c8dcSSimon Schubert 
6945796c8dcSSimon Schubert       if (highest_offset == -1)
6955796c8dcSSimon Schubert 	start = gdbarch_frame_args_skip (get_frame_arch (frame));
6965796c8dcSSimon Schubert       else
6975796c8dcSSimon Schubert 	start = highest_offset;
6985796c8dcSSimon Schubert 
6995796c8dcSSimon Schubert       print_frame_nameless_args (frame, start, num - args_printed,
7005796c8dcSSimon Schubert 				 first, stream);
7015796c8dcSSimon Schubert     }
7025796c8dcSSimon Schubert 
7035796c8dcSSimon Schubert   do_cleanups (old_chain);
7045796c8dcSSimon Schubert }
7055796c8dcSSimon Schubert 
7065796c8dcSSimon Schubert /* Set the current source and line to the location given by frame
7075796c8dcSSimon Schubert    FRAME, if possible.  When CENTER is true, adjust so the relevant
7085796c8dcSSimon Schubert    line is in the center of the next 'list'.  */
7095796c8dcSSimon Schubert 
7105796c8dcSSimon Schubert void
set_current_sal_from_frame(struct frame_info * frame,int center)7115796c8dcSSimon Schubert set_current_sal_from_frame (struct frame_info *frame, int center)
7125796c8dcSSimon Schubert {
7135796c8dcSSimon Schubert   struct symtab_and_line sal;
7145796c8dcSSimon Schubert 
7155796c8dcSSimon Schubert   find_frame_sal (frame, &sal);
7165796c8dcSSimon Schubert   if (sal.symtab)
7175796c8dcSSimon Schubert     {
7185796c8dcSSimon Schubert       if (center)
7195796c8dcSSimon Schubert         sal.line = max (sal.line - get_lines_to_list () / 2, 1);
7205796c8dcSSimon Schubert       set_current_source_symtab_and_line (&sal);
7215796c8dcSSimon Schubert     }
7225796c8dcSSimon Schubert }
7235796c8dcSSimon Schubert 
7245796c8dcSSimon Schubert /* If ON, GDB will display disassembly of the next source line when
7255796c8dcSSimon Schubert    execution of the program being debugged stops.
7265796c8dcSSimon Schubert    If AUTO (which is the default), or there's no line info to determine
7275796c8dcSSimon Schubert    the source line of the next instruction, display disassembly of next
7285796c8dcSSimon Schubert    instruction instead.  */
7295796c8dcSSimon Schubert 
7305796c8dcSSimon Schubert static enum auto_boolean disassemble_next_line;
7315796c8dcSSimon Schubert 
7325796c8dcSSimon Schubert static void
show_disassemble_next_line(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)7335796c8dcSSimon Schubert show_disassemble_next_line (struct ui_file *file, int from_tty,
7345796c8dcSSimon Schubert 				 struct cmd_list_element *c,
7355796c8dcSSimon Schubert 				 const char *value)
7365796c8dcSSimon Schubert {
737c50c785cSJohn Marino   fprintf_filtered (file,
738c50c785cSJohn Marino 		    _("Debugger's willingness to use "
739c50c785cSJohn Marino 		      "disassemble-next-line is %s.\n"),
7405796c8dcSSimon Schubert                     value);
7415796c8dcSSimon Schubert }
7425796c8dcSSimon Schubert 
7435796c8dcSSimon Schubert /* Use TRY_CATCH to catch the exception from the gdb_disassembly
7445796c8dcSSimon Schubert    because it will be broken by filter sometime.  */
7455796c8dcSSimon Schubert 
7465796c8dcSSimon Schubert static void
do_gdb_disassembly(struct gdbarch * gdbarch,int how_many,CORE_ADDR low,CORE_ADDR high)7475796c8dcSSimon Schubert do_gdb_disassembly (struct gdbarch *gdbarch,
7485796c8dcSSimon Schubert 		    int how_many, CORE_ADDR low, CORE_ADDR high)
7495796c8dcSSimon Schubert {
7505796c8dcSSimon Schubert   volatile struct gdb_exception exception;
7515796c8dcSSimon Schubert 
752a45ae5f8SJohn Marino   TRY_CATCH (exception, RETURN_MASK_ERROR)
7535796c8dcSSimon Schubert     {
754a45ae5f8SJohn Marino       gdb_disassembly (gdbarch, current_uiout, 0,
755a45ae5f8SJohn Marino 		       DISASSEMBLY_RAW_INSN, how_many,
756a45ae5f8SJohn Marino 		       low, high);
7575796c8dcSSimon Schubert     }
758a45ae5f8SJohn Marino   if (exception.reason < 0)
759a45ae5f8SJohn Marino     {
7605796c8dcSSimon Schubert       /* If an exception was thrown while doing the disassembly, print
7615796c8dcSSimon Schubert 	 the error message, to give the user a clue of what happened.  */
7625796c8dcSSimon Schubert       exception_print (gdb_stderr, exception);
7635796c8dcSSimon Schubert     }
764a45ae5f8SJohn Marino }
7655796c8dcSSimon Schubert 
7665796c8dcSSimon Schubert /* Print information about frame FRAME.  The output is format according
767a45ae5f8SJohn Marino    to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS.  The meaning of
7685796c8dcSSimon Schubert    PRINT_WHAT is:
7695796c8dcSSimon Schubert 
7705796c8dcSSimon Schubert    SRC_LINE: Print only source line.
7715796c8dcSSimon Schubert    LOCATION: Print only location.
7725796c8dcSSimon Schubert    LOC_AND_SRC: Print location and source line.
7735796c8dcSSimon Schubert 
7745796c8dcSSimon Schubert    Used in "where" output, and to emit breakpoint or step
7755796c8dcSSimon Schubert    messages.  */
7765796c8dcSSimon Schubert 
7775796c8dcSSimon Schubert void
print_frame_info(struct frame_info * frame,int print_level,enum print_what print_what,int print_args)7785796c8dcSSimon Schubert print_frame_info (struct frame_info *frame, int print_level,
7795796c8dcSSimon Schubert 		  enum print_what print_what, int print_args)
7805796c8dcSSimon Schubert {
7815796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
7825796c8dcSSimon Schubert   struct symtab_and_line sal;
7835796c8dcSSimon Schubert   int source_print;
7845796c8dcSSimon Schubert   int location_print;
785a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
7865796c8dcSSimon Schubert 
7875796c8dcSSimon Schubert   if (get_frame_type (frame) == DUMMY_FRAME
7885796c8dcSSimon Schubert       || get_frame_type (frame) == SIGTRAMP_FRAME
7895796c8dcSSimon Schubert       || get_frame_type (frame) == ARCH_FRAME)
7905796c8dcSSimon Schubert     {
7915796c8dcSSimon Schubert       struct cleanup *uiout_cleanup
7925796c8dcSSimon Schubert 	= make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
7935796c8dcSSimon Schubert 
7945796c8dcSSimon Schubert       annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
7955796c8dcSSimon Schubert 			    gdbarch, get_frame_pc (frame));
7965796c8dcSSimon Schubert 
7975796c8dcSSimon Schubert       /* Do this regardless of SOURCE because we don't have any source
7985796c8dcSSimon Schubert          to list for this frame.  */
7995796c8dcSSimon Schubert       if (print_level)
8005796c8dcSSimon Schubert         {
8015796c8dcSSimon Schubert           ui_out_text (uiout, "#");
8025796c8dcSSimon Schubert           ui_out_field_fmt_int (uiout, 2, ui_left, "level",
8035796c8dcSSimon Schubert 				frame_relative_level (frame));
8045796c8dcSSimon Schubert         }
8055796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
8065796c8dcSSimon Schubert         {
8075796c8dcSSimon Schubert           annotate_frame_address ();
8085796c8dcSSimon Schubert           ui_out_field_core_addr (uiout, "addr",
8095796c8dcSSimon Schubert 				  gdbarch, get_frame_pc (frame));
8105796c8dcSSimon Schubert           annotate_frame_address_end ();
8115796c8dcSSimon Schubert         }
8125796c8dcSSimon Schubert 
8135796c8dcSSimon Schubert       if (get_frame_type (frame) == DUMMY_FRAME)
8145796c8dcSSimon Schubert         {
8155796c8dcSSimon Schubert           annotate_function_call ();
8165796c8dcSSimon Schubert           ui_out_field_string (uiout, "func", "<function called from gdb>");
8175796c8dcSSimon Schubert 	}
8185796c8dcSSimon Schubert       else if (get_frame_type (frame) == SIGTRAMP_FRAME)
8195796c8dcSSimon Schubert         {
8205796c8dcSSimon Schubert 	  annotate_signal_handler_caller ();
8215796c8dcSSimon Schubert           ui_out_field_string (uiout, "func", "<signal handler called>");
8225796c8dcSSimon Schubert         }
8235796c8dcSSimon Schubert       else if (get_frame_type (frame) == ARCH_FRAME)
8245796c8dcSSimon Schubert         {
8255796c8dcSSimon Schubert           ui_out_field_string (uiout, "func", "<cross-architecture call>");
8265796c8dcSSimon Schubert 	}
8275796c8dcSSimon Schubert       ui_out_text (uiout, "\n");
8285796c8dcSSimon Schubert       annotate_frame_end ();
8295796c8dcSSimon Schubert 
8305796c8dcSSimon Schubert       do_cleanups (uiout_cleanup);
8315796c8dcSSimon Schubert       return;
8325796c8dcSSimon Schubert     }
8335796c8dcSSimon Schubert 
8345796c8dcSSimon Schubert   /* If FRAME is not the innermost frame, that normally means that
8355796c8dcSSimon Schubert      FRAME->pc points to *after* the call instruction, and we want to
8365796c8dcSSimon Schubert      get the line containing the call, never the next line.  But if
8375796c8dcSSimon Schubert      the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
8385796c8dcSSimon Schubert      next frame was not entered as the result of a call, and we want
8395796c8dcSSimon Schubert      to get the line containing FRAME->pc.  */
8405796c8dcSSimon Schubert   find_frame_sal (frame, &sal);
8415796c8dcSSimon Schubert 
8425796c8dcSSimon Schubert   location_print = (print_what == LOCATION
8435796c8dcSSimon Schubert 		    || print_what == LOC_AND_ADDRESS
8445796c8dcSSimon Schubert 		    || print_what == SRC_AND_LOC);
8455796c8dcSSimon Schubert 
8465796c8dcSSimon Schubert   if (location_print || !sal.symtab)
8475796c8dcSSimon Schubert     print_frame (frame, print_level, print_what, print_args, sal);
8485796c8dcSSimon Schubert 
8495796c8dcSSimon Schubert   source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
8505796c8dcSSimon Schubert 
8515796c8dcSSimon Schubert   /* If disassemble-next-line is set to auto or on and doesn't have
8525796c8dcSSimon Schubert      the line debug messages for $pc, output the next instruction.  */
8535796c8dcSSimon Schubert   if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
8545796c8dcSSimon Schubert        || disassemble_next_line == AUTO_BOOLEAN_TRUE)
8555796c8dcSSimon Schubert       && source_print && !sal.symtab)
8565796c8dcSSimon Schubert     do_gdb_disassembly (get_frame_arch (frame), 1,
8575796c8dcSSimon Schubert 			get_frame_pc (frame), get_frame_pc (frame) + 1);
8585796c8dcSSimon Schubert 
8595796c8dcSSimon Schubert   if (source_print && sal.symtab)
8605796c8dcSSimon Schubert     {
8615796c8dcSSimon Schubert       int done = 0;
8625796c8dcSSimon Schubert       int mid_statement = ((print_what == SRC_LINE)
8635796c8dcSSimon Schubert 			   && frame_show_address (frame, sal));
8645796c8dcSSimon Schubert 
8655796c8dcSSimon Schubert       if (annotation_level)
8665796c8dcSSimon Schubert 	done = identify_source_line (sal.symtab, sal.line, mid_statement,
8675796c8dcSSimon Schubert 				     get_frame_pc (frame));
8685796c8dcSSimon Schubert       if (!done)
8695796c8dcSSimon Schubert 	{
8705796c8dcSSimon Schubert 	  if (deprecated_print_frame_info_listing_hook)
8715796c8dcSSimon Schubert 	    deprecated_print_frame_info_listing_hook (sal.symtab,
8725796c8dcSSimon Schubert 						      sal.line,
8735796c8dcSSimon Schubert 						      sal.line + 1, 0);
8745796c8dcSSimon Schubert 	  else
8755796c8dcSSimon Schubert 	    {
8765796c8dcSSimon Schubert 	      struct value_print_options opts;
877cf7f2e2dSJohn Marino 
8785796c8dcSSimon Schubert 	      get_user_print_options (&opts);
8795796c8dcSSimon Schubert 	      /* We used to do this earlier, but that is clearly
8805796c8dcSSimon Schubert 		 wrong.  This function is used by many different
8815796c8dcSSimon Schubert 		 parts of gdb, including normal_stop in infrun.c,
8825796c8dcSSimon Schubert 		 which uses this to print out the current PC
8835796c8dcSSimon Schubert 		 when we stepi/nexti into the middle of a source
8845796c8dcSSimon Schubert 		 line.  Only the command line really wants this
8855796c8dcSSimon Schubert 		 behavior.  Other UIs probably would like the
8865796c8dcSSimon Schubert 		 ability to decide for themselves if it is desired.  */
8875796c8dcSSimon Schubert 	      if (opts.addressprint && mid_statement)
8885796c8dcSSimon Schubert 		{
8895796c8dcSSimon Schubert 		  ui_out_field_core_addr (uiout, "addr",
8905796c8dcSSimon Schubert 					  gdbarch, get_frame_pc (frame));
8915796c8dcSSimon Schubert 		  ui_out_text (uiout, "\t");
8925796c8dcSSimon Schubert 		}
8935796c8dcSSimon Schubert 
8945796c8dcSSimon Schubert 	      print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
8955796c8dcSSimon Schubert 	    }
8965796c8dcSSimon Schubert 	}
8975796c8dcSSimon Schubert 
8985796c8dcSSimon Schubert       /* If disassemble-next-line is set to on and there is line debug
8995796c8dcSSimon Schubert          messages, output assembly codes for next line.  */
9005796c8dcSSimon Schubert       if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
901cf7f2e2dSJohn Marino 	do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
9025796c8dcSSimon Schubert     }
9035796c8dcSSimon Schubert 
9045796c8dcSSimon Schubert   if (print_what != LOCATION)
905c50c785cSJohn Marino     {
906c50c785cSJohn Marino       CORE_ADDR pc;
907c50c785cSJohn Marino 
908c50c785cSJohn Marino       if (get_frame_pc_if_available (frame, &pc))
909a45ae5f8SJohn Marino 	set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
910c50c785cSJohn Marino       else
911a45ae5f8SJohn Marino 	set_last_displayed_sal (0, 0, 0, 0, 0);
912c50c785cSJohn Marino     }
9135796c8dcSSimon Schubert 
9145796c8dcSSimon Schubert   annotate_frame_end ();
9155796c8dcSSimon Schubert 
9165796c8dcSSimon Schubert   gdb_flush (gdb_stdout);
9175796c8dcSSimon Schubert }
9185796c8dcSSimon Schubert 
919a45ae5f8SJohn Marino /* Remember the last symtab and line we displayed, which we use e.g.
920a45ae5f8SJohn Marino  * as the place to put a breakpoint when the `break' command is
921a45ae5f8SJohn Marino  * invoked with no arguments.  */
922a45ae5f8SJohn Marino 
923a45ae5f8SJohn Marino static void
set_last_displayed_sal(int valid,struct program_space * pspace,CORE_ADDR addr,struct symtab * symtab,int line)924a45ae5f8SJohn Marino set_last_displayed_sal (int valid, struct program_space *pspace,
925a45ae5f8SJohn Marino 			CORE_ADDR addr, struct symtab *symtab,
926a45ae5f8SJohn Marino 			int line)
927a45ae5f8SJohn Marino {
928a45ae5f8SJohn Marino   last_displayed_sal_valid = valid;
929a45ae5f8SJohn Marino   last_displayed_pspace = pspace;
930a45ae5f8SJohn Marino   last_displayed_addr = addr;
931a45ae5f8SJohn Marino   last_displayed_symtab = symtab;
932a45ae5f8SJohn Marino   last_displayed_line = line;
933*ef5ccd6cSJohn Marino   if (valid && pspace == NULL)
934*ef5ccd6cSJohn Marino     {
935*ef5ccd6cSJohn Marino       clear_last_displayed_sal ();
936*ef5ccd6cSJohn Marino       internal_error (__FILE__, __LINE__,
937*ef5ccd6cSJohn Marino 		      _("Trying to set NULL pspace."));
938*ef5ccd6cSJohn Marino     }
939a45ae5f8SJohn Marino }
940a45ae5f8SJohn Marino 
941a45ae5f8SJohn Marino /* Forget the last sal we displayed.  */
942a45ae5f8SJohn Marino 
943a45ae5f8SJohn Marino void
clear_last_displayed_sal(void)944a45ae5f8SJohn Marino clear_last_displayed_sal (void)
945a45ae5f8SJohn Marino {
946a45ae5f8SJohn Marino   last_displayed_sal_valid = 0;
947a45ae5f8SJohn Marino   last_displayed_pspace = 0;
948a45ae5f8SJohn Marino   last_displayed_addr = 0;
949a45ae5f8SJohn Marino   last_displayed_symtab = 0;
950a45ae5f8SJohn Marino   last_displayed_line = 0;
951a45ae5f8SJohn Marino }
952a45ae5f8SJohn Marino 
953a45ae5f8SJohn Marino /* Is our record of the last sal we displayed valid?  If not,
954a45ae5f8SJohn Marino  * the get_last_displayed_* functions will return NULL or 0, as
955a45ae5f8SJohn Marino  * appropriate.  */
956a45ae5f8SJohn Marino 
957a45ae5f8SJohn Marino int
last_displayed_sal_is_valid(void)958a45ae5f8SJohn Marino last_displayed_sal_is_valid (void)
959a45ae5f8SJohn Marino {
960a45ae5f8SJohn Marino   return last_displayed_sal_valid;
961a45ae5f8SJohn Marino }
962a45ae5f8SJohn Marino 
963a45ae5f8SJohn Marino /* Get the pspace of the last sal we displayed, if it's valid.  */
964a45ae5f8SJohn Marino 
965a45ae5f8SJohn Marino struct program_space *
get_last_displayed_pspace(void)966a45ae5f8SJohn Marino get_last_displayed_pspace (void)
967a45ae5f8SJohn Marino {
968a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
969a45ae5f8SJohn Marino     return last_displayed_pspace;
970a45ae5f8SJohn Marino   return 0;
971a45ae5f8SJohn Marino }
972a45ae5f8SJohn Marino 
973a45ae5f8SJohn Marino /* Get the address of the last sal we displayed, if it's valid.  */
974a45ae5f8SJohn Marino 
975a45ae5f8SJohn Marino CORE_ADDR
get_last_displayed_addr(void)976a45ae5f8SJohn Marino get_last_displayed_addr (void)
977a45ae5f8SJohn Marino {
978a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
979a45ae5f8SJohn Marino     return last_displayed_addr;
980a45ae5f8SJohn Marino   return 0;
981a45ae5f8SJohn Marino }
982a45ae5f8SJohn Marino 
983a45ae5f8SJohn Marino /* Get the symtab of the last sal we displayed, if it's valid.  */
984a45ae5f8SJohn Marino 
985a45ae5f8SJohn Marino struct symtab*
get_last_displayed_symtab(void)986a45ae5f8SJohn Marino get_last_displayed_symtab (void)
987a45ae5f8SJohn Marino {
988a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
989a45ae5f8SJohn Marino     return last_displayed_symtab;
990a45ae5f8SJohn Marino   return 0;
991a45ae5f8SJohn Marino }
992a45ae5f8SJohn Marino 
993a45ae5f8SJohn Marino /* Get the line of the last sal we displayed, if it's valid.  */
994a45ae5f8SJohn Marino 
995a45ae5f8SJohn Marino int
get_last_displayed_line(void)996a45ae5f8SJohn Marino get_last_displayed_line (void)
997a45ae5f8SJohn Marino {
998a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
999a45ae5f8SJohn Marino     return last_displayed_line;
1000a45ae5f8SJohn Marino   return 0;
1001a45ae5f8SJohn Marino }
1002a45ae5f8SJohn Marino 
1003a45ae5f8SJohn Marino /* Get the last sal we displayed, if it's valid.  */
1004a45ae5f8SJohn Marino 
1005a45ae5f8SJohn Marino void
get_last_displayed_sal(struct symtab_and_line * sal)1006a45ae5f8SJohn Marino get_last_displayed_sal (struct symtab_and_line *sal)
1007a45ae5f8SJohn Marino {
1008a45ae5f8SJohn Marino   if (last_displayed_sal_valid)
1009a45ae5f8SJohn Marino     {
1010a45ae5f8SJohn Marino       sal->pspace = last_displayed_pspace;
1011a45ae5f8SJohn Marino       sal->pc = last_displayed_addr;
1012a45ae5f8SJohn Marino       sal->symtab = last_displayed_symtab;
1013a45ae5f8SJohn Marino       sal->line = last_displayed_line;
1014a45ae5f8SJohn Marino     }
1015a45ae5f8SJohn Marino   else
1016a45ae5f8SJohn Marino     {
1017a45ae5f8SJohn Marino       sal->pspace = 0;
1018a45ae5f8SJohn Marino       sal->pc = 0;
1019a45ae5f8SJohn Marino       sal->symtab = 0;
1020a45ae5f8SJohn Marino       sal->line = 0;
1021a45ae5f8SJohn Marino     }
1022a45ae5f8SJohn Marino }
1023a45ae5f8SJohn Marino 
1024a45ae5f8SJohn Marino 
1025c50c785cSJohn Marino /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
1026c50c785cSJohn Marino    corresponding to FRAME.  */
1027c50c785cSJohn Marino 
10285796c8dcSSimon Schubert void
find_frame_funname(struct frame_info * frame,const char ** funname,enum language * funlang,struct symbol ** funcp)1029*ef5ccd6cSJohn Marino find_frame_funname (struct frame_info *frame, const char **funname,
1030c50c785cSJohn Marino 		    enum language *funlang, struct symbol **funcp)
10315796c8dcSSimon Schubert {
10325796c8dcSSimon Schubert   struct symbol *func;
10335796c8dcSSimon Schubert 
10345796c8dcSSimon Schubert   *funname = NULL;
10355796c8dcSSimon Schubert   *funlang = language_unknown;
1036c50c785cSJohn Marino   if (funcp)
1037c50c785cSJohn Marino     *funcp = NULL;
10385796c8dcSSimon Schubert 
10395796c8dcSSimon Schubert   func = get_frame_function (frame);
10405796c8dcSSimon Schubert   if (func)
10415796c8dcSSimon Schubert     {
10425796c8dcSSimon Schubert       /* In certain pathological cases, the symtabs give the wrong
10435796c8dcSSimon Schubert          function (when we are in the first function in a file which
10445796c8dcSSimon Schubert          is compiled without debugging symbols, the previous function
10455796c8dcSSimon Schubert          is compiled with debugging symbols, and the "foo.o" symbol
10465796c8dcSSimon Schubert          that is supposed to tell us where the file with debugging
10475796c8dcSSimon Schubert          symbols ends has been truncated by ar because it is longer
10485796c8dcSSimon Schubert          than 15 characters).  This also occurs if the user uses asm()
10495796c8dcSSimon Schubert          to create a function but not stabs for it (in a file compiled
10505796c8dcSSimon Schubert          with -g).
10515796c8dcSSimon Schubert 
10525796c8dcSSimon Schubert          So look in the minimal symbol tables as well, and if it comes
10535796c8dcSSimon Schubert          up with a larger address for the function use that instead.
10545796c8dcSSimon Schubert          I don't think this can ever cause any problems; there
10555796c8dcSSimon Schubert          shouldn't be any minimal symbols in the middle of a function;
10565796c8dcSSimon Schubert          if this is ever changed many parts of GDB will need to be
10575796c8dcSSimon Schubert          changed (and we'll create a find_pc_minimal_function or some
10585796c8dcSSimon Schubert          such).  */
10595796c8dcSSimon Schubert 
10605796c8dcSSimon Schubert       struct minimal_symbol *msymbol = NULL;
10615796c8dcSSimon Schubert 
10625796c8dcSSimon Schubert       /* Don't attempt to do this for inlined functions, which do not
10635796c8dcSSimon Schubert 	 have a corresponding minimal symbol.  */
10645796c8dcSSimon Schubert       if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
10655796c8dcSSimon Schubert 	msymbol
10665796c8dcSSimon Schubert 	  = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
10675796c8dcSSimon Schubert 
10685796c8dcSSimon Schubert       if (msymbol != NULL
10695796c8dcSSimon Schubert 	  && (SYMBOL_VALUE_ADDRESS (msymbol)
10705796c8dcSSimon Schubert 	      > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
10715796c8dcSSimon Schubert 	{
10725796c8dcSSimon Schubert 	  /* We also don't know anything about the function besides
10735796c8dcSSimon Schubert 	     its address and name.  */
10745796c8dcSSimon Schubert 	  func = 0;
10755796c8dcSSimon Schubert 	  *funname = SYMBOL_PRINT_NAME (msymbol);
10765796c8dcSSimon Schubert 	  *funlang = SYMBOL_LANGUAGE (msymbol);
10775796c8dcSSimon Schubert 	}
10785796c8dcSSimon Schubert       else
10795796c8dcSSimon Schubert 	{
10805796c8dcSSimon Schubert 	  *funname = SYMBOL_PRINT_NAME (func);
10815796c8dcSSimon Schubert 	  *funlang = SYMBOL_LANGUAGE (func);
1082c50c785cSJohn Marino 	  if (funcp)
1083c50c785cSJohn Marino 	    *funcp = func;
10845796c8dcSSimon Schubert 	  if (*funlang == language_cplus)
10855796c8dcSSimon Schubert 	    {
10865796c8dcSSimon Schubert 	      /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
10875796c8dcSSimon Schubert 		 to display the demangled name that we already have
10885796c8dcSSimon Schubert 		 stored in the symbol table, but we stored a version
10895796c8dcSSimon Schubert 		 with DMGL_PARAMS turned on, and here we don't want to
10905796c8dcSSimon Schubert 		 display parameters.  So remove the parameters.  */
10915796c8dcSSimon Schubert 	      char *func_only = cp_remove_params (*funname);
1092cf7f2e2dSJohn Marino 
10935796c8dcSSimon Schubert 	      if (func_only)
10945796c8dcSSimon Schubert 		{
10955796c8dcSSimon Schubert 		  *funname = func_only;
10965796c8dcSSimon Schubert 		  make_cleanup (xfree, func_only);
10975796c8dcSSimon Schubert 		}
10985796c8dcSSimon Schubert 	    }
10995796c8dcSSimon Schubert 	}
11005796c8dcSSimon Schubert     }
11015796c8dcSSimon Schubert   else
11025796c8dcSSimon Schubert     {
1103c50c785cSJohn Marino       struct minimal_symbol *msymbol;
1104c50c785cSJohn Marino       CORE_ADDR pc;
11055796c8dcSSimon Schubert 
1106c50c785cSJohn Marino       if (!get_frame_address_in_block_if_available (frame, &pc))
1107c50c785cSJohn Marino 	return;
1108c50c785cSJohn Marino 
1109c50c785cSJohn Marino       msymbol = lookup_minimal_symbol_by_pc (pc);
11105796c8dcSSimon Schubert       if (msymbol != NULL)
11115796c8dcSSimon Schubert 	{
11125796c8dcSSimon Schubert 	  *funname = SYMBOL_PRINT_NAME (msymbol);
11135796c8dcSSimon Schubert 	  *funlang = SYMBOL_LANGUAGE (msymbol);
11145796c8dcSSimon Schubert 	}
11155796c8dcSSimon Schubert     }
11165796c8dcSSimon Schubert }
11175796c8dcSSimon Schubert 
11185796c8dcSSimon Schubert static void
print_frame(struct frame_info * frame,int print_level,enum print_what print_what,int print_args,struct symtab_and_line sal)11195796c8dcSSimon Schubert print_frame (struct frame_info *frame, int print_level,
11205796c8dcSSimon Schubert 	     enum print_what print_what, int print_args,
11215796c8dcSSimon Schubert 	     struct symtab_and_line sal)
11225796c8dcSSimon Schubert {
11235796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
1124a45ae5f8SJohn Marino   struct ui_out *uiout = current_uiout;
1125*ef5ccd6cSJohn Marino   const char *funname = NULL;
11265796c8dcSSimon Schubert   enum language funlang = language_unknown;
1127*ef5ccd6cSJohn Marino   struct ui_file *stb;
11285796c8dcSSimon Schubert   struct cleanup *old_chain, *list_chain;
11295796c8dcSSimon Schubert   struct value_print_options opts;
1130c50c785cSJohn Marino   struct symbol *func;
1131c50c785cSJohn Marino   CORE_ADDR pc = 0;
1132c50c785cSJohn Marino   int pc_p;
1133c50c785cSJohn Marino 
1134c50c785cSJohn Marino   pc_p = get_frame_pc_if_available (frame, &pc);
11355796c8dcSSimon Schubert 
1136*ef5ccd6cSJohn Marino   stb = mem_fileopen ();
1137*ef5ccd6cSJohn Marino   old_chain = make_cleanup_ui_file_delete (stb);
11385796c8dcSSimon Schubert 
1139c50c785cSJohn Marino   find_frame_funname (frame, &funname, &funlang, &func);
11405796c8dcSSimon Schubert 
11415796c8dcSSimon Schubert   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
1142c50c785cSJohn Marino 			gdbarch, pc);
11435796c8dcSSimon Schubert 
11445796c8dcSSimon Schubert   list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
11455796c8dcSSimon Schubert 
11465796c8dcSSimon Schubert   if (print_level)
11475796c8dcSSimon Schubert     {
11485796c8dcSSimon Schubert       ui_out_text (uiout, "#");
11495796c8dcSSimon Schubert       ui_out_field_fmt_int (uiout, 2, ui_left, "level",
11505796c8dcSSimon Schubert 			    frame_relative_level (frame));
11515796c8dcSSimon Schubert     }
11525796c8dcSSimon Schubert   get_user_print_options (&opts);
11535796c8dcSSimon Schubert   if (opts.addressprint)
1154c50c785cSJohn Marino     if (!sal.symtab
1155c50c785cSJohn Marino 	|| frame_show_address (frame, sal)
11565796c8dcSSimon Schubert 	|| print_what == LOC_AND_ADDRESS)
11575796c8dcSSimon Schubert       {
11585796c8dcSSimon Schubert 	annotate_frame_address ();
1159c50c785cSJohn Marino 	if (pc_p)
1160c50c785cSJohn Marino 	  ui_out_field_core_addr (uiout, "addr", gdbarch, pc);
1161c50c785cSJohn Marino 	else
1162c50c785cSJohn Marino 	  ui_out_field_string (uiout, "addr", "<unavailable>");
11635796c8dcSSimon Schubert 	annotate_frame_address_end ();
11645796c8dcSSimon Schubert 	ui_out_text (uiout, " in ");
11655796c8dcSSimon Schubert       }
11665796c8dcSSimon Schubert   annotate_frame_function_name ();
1167*ef5ccd6cSJohn Marino   fprintf_symbol_filtered (stb, funname ? funname : "??",
11685796c8dcSSimon Schubert 			   funlang, DMGL_ANSI);
11695796c8dcSSimon Schubert   ui_out_field_stream (uiout, "func", stb);
11705796c8dcSSimon Schubert   ui_out_wrap_hint (uiout, "   ");
11715796c8dcSSimon Schubert   annotate_frame_args ();
11725796c8dcSSimon Schubert 
11735796c8dcSSimon Schubert   ui_out_text (uiout, " (");
11745796c8dcSSimon Schubert   if (print_args)
11755796c8dcSSimon Schubert     {
1176a45ae5f8SJohn Marino       struct gdbarch *gdbarch = get_frame_arch (frame);
1177a45ae5f8SJohn Marino       int numargs;
11785796c8dcSSimon Schubert       struct cleanup *args_list_chain;
1179a45ae5f8SJohn Marino       volatile struct gdb_exception e;
1180cf7f2e2dSJohn Marino 
1181a45ae5f8SJohn Marino       if (gdbarch_frame_num_args_p (gdbarch))
1182a45ae5f8SJohn Marino 	{
1183a45ae5f8SJohn Marino 	  numargs = gdbarch_frame_num_args (gdbarch, frame);
1184a45ae5f8SJohn Marino 	  gdb_assert (numargs >= 0);
1185a45ae5f8SJohn Marino 	}
1186a45ae5f8SJohn Marino       else
1187a45ae5f8SJohn Marino 	numargs = -1;
1188a45ae5f8SJohn Marino 
11895796c8dcSSimon Schubert       args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
1190a45ae5f8SJohn Marino       TRY_CATCH (e, RETURN_MASK_ERROR)
1191a45ae5f8SJohn Marino 	{
1192a45ae5f8SJohn Marino 	  print_frame_args (func, frame, numargs, gdb_stdout);
1193a45ae5f8SJohn Marino 	}
11945796c8dcSSimon Schubert       /* FIXME: ARGS must be a list.  If one argument is a string it
11955796c8dcSSimon Schubert 	  will have " that will not be properly escaped.  */
11965796c8dcSSimon Schubert       /* Invoke ui_out_tuple_end.  */
11975796c8dcSSimon Schubert       do_cleanups (args_list_chain);
11985796c8dcSSimon Schubert       QUIT;
11995796c8dcSSimon Schubert     }
12005796c8dcSSimon Schubert   ui_out_text (uiout, ")");
1201*ef5ccd6cSJohn Marino   if (sal.symtab)
12025796c8dcSSimon Schubert     {
1203*ef5ccd6cSJohn Marino       const char *filename_display;
1204*ef5ccd6cSJohn Marino 
1205*ef5ccd6cSJohn Marino       filename_display = symtab_to_filename_for_display (sal.symtab);
12065796c8dcSSimon Schubert       annotate_frame_source_begin ();
12075796c8dcSSimon Schubert       ui_out_wrap_hint (uiout, "   ");
12085796c8dcSSimon Schubert       ui_out_text (uiout, " at ");
12095796c8dcSSimon Schubert       annotate_frame_source_file ();
1210*ef5ccd6cSJohn Marino       ui_out_field_string (uiout, "file", filename_display);
12115796c8dcSSimon Schubert       if (ui_out_is_mi_like_p (uiout))
12125796c8dcSSimon Schubert 	{
12135796c8dcSSimon Schubert 	  const char *fullname = symtab_to_fullname (sal.symtab);
1214cf7f2e2dSJohn Marino 
12155796c8dcSSimon Schubert 	  ui_out_field_string (uiout, "fullname", fullname);
12165796c8dcSSimon Schubert 	}
12175796c8dcSSimon Schubert       annotate_frame_source_file_end ();
12185796c8dcSSimon Schubert       ui_out_text (uiout, ":");
12195796c8dcSSimon Schubert       annotate_frame_source_line ();
12205796c8dcSSimon Schubert       ui_out_field_int (uiout, "line", sal.line);
12215796c8dcSSimon Schubert       annotate_frame_source_end ();
12225796c8dcSSimon Schubert     }
12235796c8dcSSimon Schubert 
1224*ef5ccd6cSJohn Marino   if (pc_p && (funname == NULL || sal.symtab == NULL))
12255796c8dcSSimon Schubert     {
12265796c8dcSSimon Schubert #ifdef PC_SOLIB
12275796c8dcSSimon Schubert       char *lib = PC_SOLIB (get_frame_pc (frame));
12285796c8dcSSimon Schubert #else
1229cf7f2e2dSJohn Marino       char *lib = solib_name_from_address (get_frame_program_space (frame),
1230cf7f2e2dSJohn Marino 					   get_frame_pc (frame));
12315796c8dcSSimon Schubert #endif
12325796c8dcSSimon Schubert       if (lib)
12335796c8dcSSimon Schubert 	{
12345796c8dcSSimon Schubert 	  annotate_frame_where ();
12355796c8dcSSimon Schubert 	  ui_out_wrap_hint (uiout, "  ");
12365796c8dcSSimon Schubert 	  ui_out_text (uiout, " from ");
12375796c8dcSSimon Schubert 	  ui_out_field_string (uiout, "from", lib);
12385796c8dcSSimon Schubert 	}
12395796c8dcSSimon Schubert     }
12405796c8dcSSimon Schubert 
12415796c8dcSSimon Schubert   /* do_cleanups will call ui_out_tuple_end() for us.  */
12425796c8dcSSimon Schubert   do_cleanups (list_chain);
12435796c8dcSSimon Schubert   ui_out_text (uiout, "\n");
12445796c8dcSSimon Schubert   do_cleanups (old_chain);
12455796c8dcSSimon Schubert }
12465796c8dcSSimon Schubert 
12475796c8dcSSimon Schubert 
12485796c8dcSSimon Schubert /* Read a frame specification in whatever the appropriate format is
12495796c8dcSSimon Schubert    from FRAME_EXP.  Call error(), printing MESSAGE, if the
12505796c8dcSSimon Schubert    specification is in any way invalid (so this function never returns
12515796c8dcSSimon Schubert    NULL).  When SEPECTED_P is non-NULL set its target to indicate that
12525796c8dcSSimon Schubert    the default selected frame was used.  */
12535796c8dcSSimon Schubert 
12545796c8dcSSimon Schubert static struct frame_info *
parse_frame_specification_1(const char * frame_exp,const char * message,int * selected_frame_p)12555796c8dcSSimon Schubert parse_frame_specification_1 (const char *frame_exp, const char *message,
12565796c8dcSSimon Schubert 			     int *selected_frame_p)
12575796c8dcSSimon Schubert {
12585796c8dcSSimon Schubert   int numargs;
12595796c8dcSSimon Schubert   struct value *args[4];
12605796c8dcSSimon Schubert   CORE_ADDR addrs[ARRAY_SIZE (args)];
12615796c8dcSSimon Schubert 
12625796c8dcSSimon Schubert   if (frame_exp == NULL)
12635796c8dcSSimon Schubert     numargs = 0;
12645796c8dcSSimon Schubert   else
12655796c8dcSSimon Schubert     {
12665796c8dcSSimon Schubert       numargs = 0;
12675796c8dcSSimon Schubert       while (1)
12685796c8dcSSimon Schubert 	{
12695796c8dcSSimon Schubert 	  char *addr_string;
12705796c8dcSSimon Schubert 	  struct cleanup *cleanup;
12715796c8dcSSimon Schubert 	  const char *p;
12725796c8dcSSimon Schubert 
12735796c8dcSSimon Schubert 	  /* Skip leading white space, bail of EOL.  */
1274*ef5ccd6cSJohn Marino 	  frame_exp = skip_spaces_const (frame_exp);
12755796c8dcSSimon Schubert 	  if (!*frame_exp)
12765796c8dcSSimon Schubert 	    break;
12775796c8dcSSimon Schubert 
12785796c8dcSSimon Schubert 	  /* Parse the argument, extract it, save it.  */
12795796c8dcSSimon Schubert 	  for (p = frame_exp;
12805796c8dcSSimon Schubert 	       *p && !isspace (*p);
12815796c8dcSSimon Schubert 	       p++);
12825796c8dcSSimon Schubert 	  addr_string = savestring (frame_exp, p - frame_exp);
12835796c8dcSSimon Schubert 	  frame_exp = p;
12845796c8dcSSimon Schubert 	  cleanup = make_cleanup (xfree, addr_string);
12855796c8dcSSimon Schubert 
12865796c8dcSSimon Schubert 	  /* NOTE: Parse and evaluate expression, but do not use
12875796c8dcSSimon Schubert 	     functions such as parse_and_eval_long or
12885796c8dcSSimon Schubert 	     parse_and_eval_address to also extract the value.
12895796c8dcSSimon Schubert 	     Instead value_as_long and value_as_address are used.
12905796c8dcSSimon Schubert 	     This avoids problems with expressions that contain
12915796c8dcSSimon Schubert 	     side-effects.  */
12925796c8dcSSimon Schubert 	  if (numargs >= ARRAY_SIZE (args))
12935796c8dcSSimon Schubert 	    error (_("Too many args in frame specification"));
12945796c8dcSSimon Schubert 	  args[numargs++] = parse_and_eval (addr_string);
12955796c8dcSSimon Schubert 
12965796c8dcSSimon Schubert 	  do_cleanups (cleanup);
12975796c8dcSSimon Schubert 	}
12985796c8dcSSimon Schubert     }
12995796c8dcSSimon Schubert 
13005796c8dcSSimon Schubert   /* If no args, default to the selected frame.  */
13015796c8dcSSimon Schubert   if (numargs == 0)
13025796c8dcSSimon Schubert     {
13035796c8dcSSimon Schubert       if (selected_frame_p != NULL)
13045796c8dcSSimon Schubert 	(*selected_frame_p) = 1;
13055796c8dcSSimon Schubert       return get_selected_frame (message);
13065796c8dcSSimon Schubert     }
13075796c8dcSSimon Schubert 
13085796c8dcSSimon Schubert   /* None of the remaining use the selected frame.  */
13095796c8dcSSimon Schubert   if (selected_frame_p != NULL)
13105796c8dcSSimon Schubert     (*selected_frame_p) = 0;
13115796c8dcSSimon Schubert 
13125796c8dcSSimon Schubert   /* Assume the single arg[0] is an integer, and try using that to
13135796c8dcSSimon Schubert      select a frame relative to current.  */
13145796c8dcSSimon Schubert   if (numargs == 1)
13155796c8dcSSimon Schubert     {
13165796c8dcSSimon Schubert       struct frame_info *fid;
13175796c8dcSSimon Schubert       int level = value_as_long (args[0]);
1318cf7f2e2dSJohn Marino 
13195796c8dcSSimon Schubert       fid = find_relative_frame (get_current_frame (), &level);
13205796c8dcSSimon Schubert       if (level == 0)
1321c50c785cSJohn Marino 	/* find_relative_frame was successful.  */
13225796c8dcSSimon Schubert 	return fid;
13235796c8dcSSimon Schubert     }
13245796c8dcSSimon Schubert 
13255796c8dcSSimon Schubert   /* Convert each value into a corresponding address.  */
13265796c8dcSSimon Schubert   {
13275796c8dcSSimon Schubert     int i;
1328cf7f2e2dSJohn Marino 
13295796c8dcSSimon Schubert     for (i = 0; i < numargs; i++)
13305796c8dcSSimon Schubert       addrs[i] = value_as_address (args[i]);
13315796c8dcSSimon Schubert   }
13325796c8dcSSimon Schubert 
13335796c8dcSSimon Schubert   /* Assume that the single arg[0] is an address, use that to identify
13345796c8dcSSimon Schubert      a frame with a matching ID.  Should this also accept stack/pc or
13355796c8dcSSimon Schubert      stack/pc/special.  */
13365796c8dcSSimon Schubert   if (numargs == 1)
13375796c8dcSSimon Schubert     {
13385796c8dcSSimon Schubert       struct frame_id id = frame_id_build_wild (addrs[0]);
13395796c8dcSSimon Schubert       struct frame_info *fid;
13405796c8dcSSimon Schubert 
13415796c8dcSSimon Schubert       /* If (s)he specifies the frame with an address, he deserves
13425796c8dcSSimon Schubert 	 what (s)he gets.  Still, give the highest one that matches.
13435796c8dcSSimon Schubert 	 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
13445796c8dcSSimon Schubert 	 know).  */
13455796c8dcSSimon Schubert       for (fid = get_current_frame ();
13465796c8dcSSimon Schubert 	   fid != NULL;
13475796c8dcSSimon Schubert 	   fid = get_prev_frame (fid))
13485796c8dcSSimon Schubert 	{
13495796c8dcSSimon Schubert 	  if (frame_id_eq (id, get_frame_id (fid)))
13505796c8dcSSimon Schubert 	    {
13515796c8dcSSimon Schubert 	      struct frame_info *prev_frame;
13525796c8dcSSimon Schubert 
13535796c8dcSSimon Schubert 	      while (1)
13545796c8dcSSimon Schubert 		{
13555796c8dcSSimon Schubert 		  prev_frame = get_prev_frame (fid);
13565796c8dcSSimon Schubert 		  if (!prev_frame
13575796c8dcSSimon Schubert 		      || !frame_id_eq (id, get_frame_id (prev_frame)))
13585796c8dcSSimon Schubert 		    break;
13595796c8dcSSimon Schubert 		  fid = prev_frame;
13605796c8dcSSimon Schubert 		}
13615796c8dcSSimon Schubert 	      return fid;
13625796c8dcSSimon Schubert 	    }
13635796c8dcSSimon Schubert 	}
13645796c8dcSSimon Schubert       }
13655796c8dcSSimon Schubert 
13665796c8dcSSimon Schubert   /* We couldn't identify the frame as an existing frame, but
13675796c8dcSSimon Schubert      perhaps we can create one with a single argument.  */
13685796c8dcSSimon Schubert   if (numargs == 1)
13695796c8dcSSimon Schubert     return create_new_frame (addrs[0], 0);
13705796c8dcSSimon Schubert   else if (numargs == 2)
13715796c8dcSSimon Schubert     return create_new_frame (addrs[0], addrs[1]);
13725796c8dcSSimon Schubert   else
13735796c8dcSSimon Schubert     error (_("Too many args in frame specification"));
13745796c8dcSSimon Schubert }
13755796c8dcSSimon Schubert 
13765796c8dcSSimon Schubert static struct frame_info *
parse_frame_specification(char * frame_exp)13775796c8dcSSimon Schubert parse_frame_specification (char *frame_exp)
13785796c8dcSSimon Schubert {
13795796c8dcSSimon Schubert   return parse_frame_specification_1 (frame_exp, NULL, NULL);
13805796c8dcSSimon Schubert }
13815796c8dcSSimon Schubert 
13825796c8dcSSimon Schubert /* Print verbosely the selected frame or the frame at address
13835796c8dcSSimon Schubert    ADDR_EXP.  Absolutely all information in the frame is printed.  */
13845796c8dcSSimon Schubert 
13855796c8dcSSimon Schubert static void
frame_info(char * addr_exp,int from_tty)13865796c8dcSSimon Schubert frame_info (char *addr_exp, int from_tty)
13875796c8dcSSimon Schubert {
13885796c8dcSSimon Schubert   struct frame_info *fi;
13895796c8dcSSimon Schubert   struct symtab_and_line sal;
13905796c8dcSSimon Schubert   struct symbol *func;
13915796c8dcSSimon Schubert   struct symtab *s;
13925796c8dcSSimon Schubert   struct frame_info *calling_frame_info;
1393cf7f2e2dSJohn Marino   int numregs;
1394*ef5ccd6cSJohn Marino   const char *funname = 0;
13955796c8dcSSimon Schubert   enum language funlang = language_unknown;
13965796c8dcSSimon Schubert   const char *pc_regname;
13975796c8dcSSimon Schubert   int selected_frame_p;
13985796c8dcSSimon Schubert   struct gdbarch *gdbarch;
13995796c8dcSSimon Schubert   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
1400c50c785cSJohn Marino   CORE_ADDR frame_pc;
1401c50c785cSJohn Marino   int frame_pc_p;
1402c50c785cSJohn Marino   CORE_ADDR caller_pc;
14035796c8dcSSimon Schubert 
14045796c8dcSSimon Schubert   fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
14055796c8dcSSimon Schubert   gdbarch = get_frame_arch (fi);
14065796c8dcSSimon Schubert 
14075796c8dcSSimon Schubert   /* Name of the value returned by get_frame_pc().  Per comments, "pc"
14085796c8dcSSimon Schubert      is not a good name.  */
14095796c8dcSSimon Schubert   if (gdbarch_pc_regnum (gdbarch) >= 0)
14105796c8dcSSimon Schubert     /* OK, this is weird.  The gdbarch_pc_regnum hardware register's value can
14115796c8dcSSimon Schubert        easily not match that of the internal value returned by
14125796c8dcSSimon Schubert        get_frame_pc().  */
14135796c8dcSSimon Schubert     pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
14145796c8dcSSimon Schubert   else
14155796c8dcSSimon Schubert     /* But then, this is weird to.  Even without gdbarch_pc_regnum, an
14165796c8dcSSimon Schubert        architectures will often have a hardware register called "pc",
14175796c8dcSSimon Schubert        and that register's value, again, can easily not match
14185796c8dcSSimon Schubert        get_frame_pc().  */
14195796c8dcSSimon Schubert     pc_regname = "pc";
14205796c8dcSSimon Schubert 
1421c50c785cSJohn Marino   frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
14225796c8dcSSimon Schubert   find_frame_sal (fi, &sal);
14235796c8dcSSimon Schubert   func = get_frame_function (fi);
1424c50c785cSJohn Marino   s = sal.symtab;
14255796c8dcSSimon Schubert   if (func)
14265796c8dcSSimon Schubert     {
14275796c8dcSSimon Schubert       funname = SYMBOL_PRINT_NAME (func);
14285796c8dcSSimon Schubert       funlang = SYMBOL_LANGUAGE (func);
14295796c8dcSSimon Schubert       if (funlang == language_cplus)
14305796c8dcSSimon Schubert 	{
14315796c8dcSSimon Schubert 	  /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
14325796c8dcSSimon Schubert 	     to display the demangled name that we already have
14335796c8dcSSimon Schubert 	     stored in the symbol table, but we stored a version
14345796c8dcSSimon Schubert 	     with DMGL_PARAMS turned on, and here we don't want to
14355796c8dcSSimon Schubert 	     display parameters.  So remove the parameters.  */
14365796c8dcSSimon Schubert 	  char *func_only = cp_remove_params (funname);
1437cf7f2e2dSJohn Marino 
14385796c8dcSSimon Schubert 	  if (func_only)
14395796c8dcSSimon Schubert 	    {
14405796c8dcSSimon Schubert 	      funname = func_only;
14415796c8dcSSimon Schubert 	      make_cleanup (xfree, func_only);
14425796c8dcSSimon Schubert 	    }
14435796c8dcSSimon Schubert 	}
14445796c8dcSSimon Schubert     }
1445c50c785cSJohn Marino   else if (frame_pc_p)
14465796c8dcSSimon Schubert     {
14475796c8dcSSimon Schubert       struct minimal_symbol *msymbol;
14485796c8dcSSimon Schubert 
1449c50c785cSJohn Marino       msymbol = lookup_minimal_symbol_by_pc (frame_pc);
14505796c8dcSSimon Schubert       if (msymbol != NULL)
14515796c8dcSSimon Schubert 	{
14525796c8dcSSimon Schubert 	  funname = SYMBOL_PRINT_NAME (msymbol);
14535796c8dcSSimon Schubert 	  funlang = SYMBOL_LANGUAGE (msymbol);
14545796c8dcSSimon Schubert 	}
14555796c8dcSSimon Schubert     }
14565796c8dcSSimon Schubert   calling_frame_info = get_prev_frame (fi);
14575796c8dcSSimon Schubert 
14585796c8dcSSimon Schubert   if (selected_frame_p && frame_relative_level (fi) >= 0)
14595796c8dcSSimon Schubert     {
14605796c8dcSSimon Schubert       printf_filtered (_("Stack level %d, frame at "),
14615796c8dcSSimon Schubert 		       frame_relative_level (fi));
14625796c8dcSSimon Schubert     }
14635796c8dcSSimon Schubert   else
14645796c8dcSSimon Schubert     {
14655796c8dcSSimon Schubert       printf_filtered (_("Stack frame at "));
14665796c8dcSSimon Schubert     }
14675796c8dcSSimon Schubert   fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
14685796c8dcSSimon Schubert   printf_filtered (":\n");
14695796c8dcSSimon Schubert   printf_filtered (" %s = ", pc_regname);
1470c50c785cSJohn Marino   if (frame_pc_p)
14715796c8dcSSimon Schubert     fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
1472c50c785cSJohn Marino   else
1473c50c785cSJohn Marino     fputs_filtered ("<unavailable>", gdb_stdout);
14745796c8dcSSimon Schubert 
14755796c8dcSSimon Schubert   wrap_here ("   ");
14765796c8dcSSimon Schubert   if (funname)
14775796c8dcSSimon Schubert     {
14785796c8dcSSimon Schubert       printf_filtered (" in ");
14795796c8dcSSimon Schubert       fprintf_symbol_filtered (gdb_stdout, funname, funlang,
14805796c8dcSSimon Schubert 			       DMGL_ANSI | DMGL_PARAMS);
14815796c8dcSSimon Schubert     }
14825796c8dcSSimon Schubert   wrap_here ("   ");
14835796c8dcSSimon Schubert   if (sal.symtab)
1484*ef5ccd6cSJohn Marino     printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal.symtab),
1485*ef5ccd6cSJohn Marino 		     sal.line);
14865796c8dcSSimon Schubert   puts_filtered ("; ");
14875796c8dcSSimon Schubert   wrap_here ("    ");
14885796c8dcSSimon Schubert   printf_filtered ("saved %s ", pc_regname);
1489c50c785cSJohn Marino   if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
1490c50c785cSJohn Marino     fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
1491c50c785cSJohn Marino   else
1492c50c785cSJohn Marino     fputs_filtered ("<unavailable>", gdb_stdout);
14935796c8dcSSimon Schubert   printf_filtered ("\n");
14945796c8dcSSimon Schubert 
14955796c8dcSSimon Schubert   if (calling_frame_info == NULL)
14965796c8dcSSimon Schubert     {
14975796c8dcSSimon Schubert       enum unwind_stop_reason reason;
14985796c8dcSSimon Schubert 
14995796c8dcSSimon Schubert       reason = get_frame_unwind_stop_reason (fi);
15005796c8dcSSimon Schubert       if (reason != UNWIND_NO_REASON)
15015796c8dcSSimon Schubert 	printf_filtered (_(" Outermost frame: %s\n"),
15025796c8dcSSimon Schubert 			 frame_stop_reason_string (reason));
15035796c8dcSSimon Schubert     }
1504a45ae5f8SJohn Marino   else if (get_frame_type (fi) == TAILCALL_FRAME)
1505a45ae5f8SJohn Marino     puts_filtered (" tail call frame");
15065796c8dcSSimon Schubert   else if (get_frame_type (fi) == INLINE_FRAME)
15075796c8dcSSimon Schubert     printf_filtered (" inlined into frame %d",
15085796c8dcSSimon Schubert 		     frame_relative_level (get_prev_frame (fi)));
15095796c8dcSSimon Schubert   else
15105796c8dcSSimon Schubert     {
15115796c8dcSSimon Schubert       printf_filtered (" called by frame at ");
15125796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
15135796c8dcSSimon Schubert 		      gdb_stdout);
15145796c8dcSSimon Schubert     }
15155796c8dcSSimon Schubert   if (get_next_frame (fi) && calling_frame_info)
15165796c8dcSSimon Schubert     puts_filtered (",");
15175796c8dcSSimon Schubert   wrap_here ("   ");
15185796c8dcSSimon Schubert   if (get_next_frame (fi))
15195796c8dcSSimon Schubert     {
15205796c8dcSSimon Schubert       printf_filtered (" caller of frame at ");
15215796c8dcSSimon Schubert       fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
15225796c8dcSSimon Schubert 		      gdb_stdout);
15235796c8dcSSimon Schubert     }
15245796c8dcSSimon Schubert   if (get_next_frame (fi) || calling_frame_info)
15255796c8dcSSimon Schubert     puts_filtered ("\n");
15265796c8dcSSimon Schubert 
15275796c8dcSSimon Schubert   if (s)
15285796c8dcSSimon Schubert     printf_filtered (" source language %s.\n",
15295796c8dcSSimon Schubert 		     language_str (s->language));
15305796c8dcSSimon Schubert 
15315796c8dcSSimon Schubert   {
15325796c8dcSSimon Schubert     /* Address of the argument list for this frame, or 0.  */
15335796c8dcSSimon Schubert     CORE_ADDR arg_list = get_frame_args_address (fi);
15345796c8dcSSimon Schubert     /* Number of args for this frame, or -1 if unknown.  */
15355796c8dcSSimon Schubert     int numargs;
15365796c8dcSSimon Schubert 
15375796c8dcSSimon Schubert     if (arg_list == 0)
15385796c8dcSSimon Schubert       printf_filtered (" Arglist at unknown address.\n");
15395796c8dcSSimon Schubert     else
15405796c8dcSSimon Schubert       {
15415796c8dcSSimon Schubert 	printf_filtered (" Arglist at ");
15425796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
15435796c8dcSSimon Schubert 	printf_filtered (",");
15445796c8dcSSimon Schubert 
15455796c8dcSSimon Schubert 	if (!gdbarch_frame_num_args_p (gdbarch))
15465796c8dcSSimon Schubert 	  {
15475796c8dcSSimon Schubert 	    numargs = -1;
15485796c8dcSSimon Schubert 	    puts_filtered (" args: ");
15495796c8dcSSimon Schubert 	  }
15505796c8dcSSimon Schubert 	else
15515796c8dcSSimon Schubert 	  {
15525796c8dcSSimon Schubert 	    numargs = gdbarch_frame_num_args (gdbarch, fi);
15535796c8dcSSimon Schubert 	    gdb_assert (numargs >= 0);
15545796c8dcSSimon Schubert 	    if (numargs == 0)
15555796c8dcSSimon Schubert 	      puts_filtered (" no args.");
15565796c8dcSSimon Schubert 	    else if (numargs == 1)
15575796c8dcSSimon Schubert 	      puts_filtered (" 1 arg: ");
15585796c8dcSSimon Schubert 	    else
15595796c8dcSSimon Schubert 	      printf_filtered (" %d args: ", numargs);
15605796c8dcSSimon Schubert 	  }
15615796c8dcSSimon Schubert 	print_frame_args (func, fi, numargs, gdb_stdout);
15625796c8dcSSimon Schubert 	puts_filtered ("\n");
15635796c8dcSSimon Schubert       }
15645796c8dcSSimon Schubert   }
15655796c8dcSSimon Schubert   {
15665796c8dcSSimon Schubert     /* Address of the local variables for this frame, or 0.  */
15675796c8dcSSimon Schubert     CORE_ADDR arg_list = get_frame_locals_address (fi);
15685796c8dcSSimon Schubert 
15695796c8dcSSimon Schubert     if (arg_list == 0)
15705796c8dcSSimon Schubert       printf_filtered (" Locals at unknown address,");
15715796c8dcSSimon Schubert     else
15725796c8dcSSimon Schubert       {
15735796c8dcSSimon Schubert 	printf_filtered (" Locals at ");
15745796c8dcSSimon Schubert 	fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
15755796c8dcSSimon Schubert 	printf_filtered (",");
15765796c8dcSSimon Schubert       }
15775796c8dcSSimon Schubert   }
15785796c8dcSSimon Schubert 
15795796c8dcSSimon Schubert   /* Print as much information as possible on the location of all the
15805796c8dcSSimon Schubert      registers.  */
15815796c8dcSSimon Schubert   {
15825796c8dcSSimon Schubert     enum lval_type lval;
15835796c8dcSSimon Schubert     int optimized;
1584c50c785cSJohn Marino     int unavailable;
15855796c8dcSSimon Schubert     CORE_ADDR addr;
15865796c8dcSSimon Schubert     int realnum;
15875796c8dcSSimon Schubert     int count;
15885796c8dcSSimon Schubert     int i;
15895796c8dcSSimon Schubert     int need_nl = 1;
15905796c8dcSSimon Schubert 
15915796c8dcSSimon Schubert     /* The sp is special; what's displayed isn't the save address, but
15925796c8dcSSimon Schubert        the value of the previous frame's sp.  This is a legacy thing,
15935796c8dcSSimon Schubert        at one stage the frame cached the previous frame's SP instead
15945796c8dcSSimon Schubert        of its address, hence it was easiest to just display the cached
15955796c8dcSSimon Schubert        value.  */
15965796c8dcSSimon Schubert     if (gdbarch_sp_regnum (gdbarch) >= 0)
15975796c8dcSSimon Schubert       {
15985796c8dcSSimon Schubert 	/* Find out the location of the saved stack pointer with out
15995796c8dcSSimon Schubert            actually evaluating it.  */
16005796c8dcSSimon Schubert 	frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
1601c50c785cSJohn Marino 			       &optimized, &unavailable, &lval, &addr,
16025796c8dcSSimon Schubert 			       &realnum, NULL);
1603c50c785cSJohn Marino 	if (!optimized && !unavailable && lval == not_lval)
16045796c8dcSSimon Schubert 	  {
16055796c8dcSSimon Schubert 	    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
16065796c8dcSSimon Schubert 	    int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
16075796c8dcSSimon Schubert 	    gdb_byte value[MAX_REGISTER_SIZE];
16085796c8dcSSimon Schubert 	    CORE_ADDR sp;
1609cf7f2e2dSJohn Marino 
16105796c8dcSSimon Schubert 	    frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
1611c50c785cSJohn Marino 				   &optimized, &unavailable, &lval, &addr,
16125796c8dcSSimon Schubert 				   &realnum, value);
16135796c8dcSSimon Schubert 	    /* NOTE: cagney/2003-05-22: This is assuming that the
16145796c8dcSSimon Schubert                stack pointer was packed as an unsigned integer.  That
16155796c8dcSSimon Schubert                may or may not be valid.  */
16165796c8dcSSimon Schubert 	    sp = extract_unsigned_integer (value, sp_size, byte_order);
16175796c8dcSSimon Schubert 	    printf_filtered (" Previous frame's sp is ");
16185796c8dcSSimon Schubert 	    fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
16195796c8dcSSimon Schubert 	    printf_filtered ("\n");
16205796c8dcSSimon Schubert 	    need_nl = 0;
16215796c8dcSSimon Schubert 	  }
1622c50c785cSJohn Marino 	else if (!optimized && !unavailable && lval == lval_memory)
16235796c8dcSSimon Schubert 	  {
16245796c8dcSSimon Schubert 	    printf_filtered (" Previous frame's sp at ");
16255796c8dcSSimon Schubert 	    fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
16265796c8dcSSimon Schubert 	    printf_filtered ("\n");
16275796c8dcSSimon Schubert 	    need_nl = 0;
16285796c8dcSSimon Schubert 	  }
1629c50c785cSJohn Marino 	else if (!optimized && !unavailable && lval == lval_register)
16305796c8dcSSimon Schubert 	  {
16315796c8dcSSimon Schubert 	    printf_filtered (" Previous frame's sp in %s\n",
16325796c8dcSSimon Schubert 			     gdbarch_register_name (gdbarch, realnum));
16335796c8dcSSimon Schubert 	    need_nl = 0;
16345796c8dcSSimon Schubert 	  }
16355796c8dcSSimon Schubert 	/* else keep quiet.  */
16365796c8dcSSimon Schubert       }
16375796c8dcSSimon Schubert 
16385796c8dcSSimon Schubert     count = 0;
16395796c8dcSSimon Schubert     numregs = gdbarch_num_regs (gdbarch)
16405796c8dcSSimon Schubert 	      + gdbarch_num_pseudo_regs (gdbarch);
16415796c8dcSSimon Schubert     for (i = 0; i < numregs; i++)
16425796c8dcSSimon Schubert       if (i != gdbarch_sp_regnum (gdbarch)
16435796c8dcSSimon Schubert 	  && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
16445796c8dcSSimon Schubert 	{
16455796c8dcSSimon Schubert 	  /* Find out the location of the saved register without
16465796c8dcSSimon Schubert              fetching the corresponding value.  */
1647c50c785cSJohn Marino 	  frame_register_unwind (fi, i, &optimized, &unavailable,
1648c50c785cSJohn Marino 				 &lval, &addr, &realnum, NULL);
16495796c8dcSSimon Schubert 	  /* For moment, only display registers that were saved on the
16505796c8dcSSimon Schubert 	     stack.  */
1651c50c785cSJohn Marino 	  if (!optimized && !unavailable && lval == lval_memory)
16525796c8dcSSimon Schubert 	    {
16535796c8dcSSimon Schubert 	      if (count == 0)
16545796c8dcSSimon Schubert 		puts_filtered (" Saved registers:\n ");
16555796c8dcSSimon Schubert 	      else
16565796c8dcSSimon Schubert 		puts_filtered (",");
16575796c8dcSSimon Schubert 	      wrap_here (" ");
16585796c8dcSSimon Schubert 	      printf_filtered (" %s at ",
16595796c8dcSSimon Schubert 			       gdbarch_register_name (gdbarch, i));
16605796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
16615796c8dcSSimon Schubert 	      count++;
16625796c8dcSSimon Schubert 	    }
16635796c8dcSSimon Schubert 	}
16645796c8dcSSimon Schubert     if (count || need_nl)
16655796c8dcSSimon Schubert       puts_filtered ("\n");
16665796c8dcSSimon Schubert   }
16675796c8dcSSimon Schubert 
16685796c8dcSSimon Schubert   do_cleanups (back_to);
16695796c8dcSSimon Schubert }
16705796c8dcSSimon Schubert 
16715796c8dcSSimon Schubert /* Print briefly all stack frames or just the innermost COUNT_EXP
16725796c8dcSSimon Schubert    frames.  */
16735796c8dcSSimon Schubert 
16745796c8dcSSimon Schubert static void
backtrace_command_1(char * count_exp,int show_locals,int from_tty)16755796c8dcSSimon Schubert backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
16765796c8dcSSimon Schubert {
16775796c8dcSSimon Schubert   struct frame_info *fi;
16785796c8dcSSimon Schubert   int count;
16795796c8dcSSimon Schubert   int i;
16805796c8dcSSimon Schubert   struct frame_info *trailing;
16815796c8dcSSimon Schubert   int trailing_level;
16825796c8dcSSimon Schubert 
16835796c8dcSSimon Schubert   if (!target_has_stack)
16845796c8dcSSimon Schubert     error (_("No stack."));
16855796c8dcSSimon Schubert 
16865796c8dcSSimon Schubert   /* The following code must do two things.  First, it must set the
16875796c8dcSSimon Schubert      variable TRAILING to the frame from which we should start
16885796c8dcSSimon Schubert      printing.  Second, it must set the variable count to the number
16895796c8dcSSimon Schubert      of frames which we should print, or -1 if all of them.  */
16905796c8dcSSimon Schubert   trailing = get_current_frame ();
16915796c8dcSSimon Schubert 
16925796c8dcSSimon Schubert   trailing_level = 0;
16935796c8dcSSimon Schubert   if (count_exp)
16945796c8dcSSimon Schubert     {
16955796c8dcSSimon Schubert       count = parse_and_eval_long (count_exp);
16965796c8dcSSimon Schubert       if (count < 0)
16975796c8dcSSimon Schubert 	{
16985796c8dcSSimon Schubert 	  struct frame_info *current;
16995796c8dcSSimon Schubert 
17005796c8dcSSimon Schubert 	  count = -count;
17015796c8dcSSimon Schubert 
17025796c8dcSSimon Schubert 	  current = trailing;
17035796c8dcSSimon Schubert 	  while (current && count--)
17045796c8dcSSimon Schubert 	    {
17055796c8dcSSimon Schubert 	      QUIT;
17065796c8dcSSimon Schubert 	      current = get_prev_frame (current);
17075796c8dcSSimon Schubert 	    }
17085796c8dcSSimon Schubert 
17095796c8dcSSimon Schubert 	  /* Will stop when CURRENT reaches the top of the stack.
17105796c8dcSSimon Schubert 	     TRAILING will be COUNT below it.  */
17115796c8dcSSimon Schubert 	  while (current)
17125796c8dcSSimon Schubert 	    {
17135796c8dcSSimon Schubert 	      QUIT;
17145796c8dcSSimon Schubert 	      trailing = get_prev_frame (trailing);
17155796c8dcSSimon Schubert 	      current = get_prev_frame (current);
17165796c8dcSSimon Schubert 	      trailing_level++;
17175796c8dcSSimon Schubert 	    }
17185796c8dcSSimon Schubert 
17195796c8dcSSimon Schubert 	  count = -1;
17205796c8dcSSimon Schubert 	}
17215796c8dcSSimon Schubert     }
17225796c8dcSSimon Schubert   else
17235796c8dcSSimon Schubert     count = -1;
17245796c8dcSSimon Schubert 
17255796c8dcSSimon Schubert   if (info_verbose)
17265796c8dcSSimon Schubert     {
17275796c8dcSSimon Schubert       /* Read in symbols for all of the frames.  Need to do this in a
17285796c8dcSSimon Schubert          separate pass so that "Reading in symbols for xxx" messages
17295796c8dcSSimon Schubert          don't screw up the appearance of the backtrace.  Also if
17305796c8dcSSimon Schubert          people have strong opinions against reading symbols for
17315796c8dcSSimon Schubert          backtrace this may have to be an option.  */
17325796c8dcSSimon Schubert       i = count;
17335796c8dcSSimon Schubert       for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
17345796c8dcSSimon Schubert 	{
1735cf7f2e2dSJohn Marino 	  CORE_ADDR pc;
1736cf7f2e2dSJohn Marino 
17375796c8dcSSimon Schubert 	  QUIT;
1738cf7f2e2dSJohn Marino 	  pc = get_frame_address_in_block (fi);
1739cf7f2e2dSJohn Marino 	  find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc));
17405796c8dcSSimon Schubert 	}
17415796c8dcSSimon Schubert     }
17425796c8dcSSimon Schubert 
17435796c8dcSSimon Schubert   for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
17445796c8dcSSimon Schubert     {
17455796c8dcSSimon Schubert       QUIT;
17465796c8dcSSimon Schubert 
17475796c8dcSSimon Schubert       /* Don't use print_stack_frame; if an error() occurs it probably
17485796c8dcSSimon Schubert          means further attempts to backtrace would fail (on the other
17495796c8dcSSimon Schubert          hand, perhaps the code does or could be fixed to make sure
17505796c8dcSSimon Schubert          the frame->prev field gets set to NULL in that case).  */
17515796c8dcSSimon Schubert       print_frame_info (fi, 1, LOCATION, 1);
17525796c8dcSSimon Schubert       if (show_locals)
1753*ef5ccd6cSJohn Marino 	{
1754*ef5ccd6cSJohn Marino 	  struct frame_id frame_id = get_frame_id (fi);
1755*ef5ccd6cSJohn Marino 
17565796c8dcSSimon Schubert 	  print_frame_local_vars (fi, 1, gdb_stdout);
17575796c8dcSSimon Schubert 
1758*ef5ccd6cSJohn Marino 	  /* print_frame_local_vars invalidates FI.  */
1759*ef5ccd6cSJohn Marino 	  fi = frame_find_by_id (frame_id);
1760*ef5ccd6cSJohn Marino 	  if (fi == NULL)
1761*ef5ccd6cSJohn Marino 	    {
1762*ef5ccd6cSJohn Marino 	      trailing = NULL;
1763*ef5ccd6cSJohn Marino 	      warning (_("Unable to restore previously selected frame."));
1764*ef5ccd6cSJohn Marino 	      break;
1765*ef5ccd6cSJohn Marino 	    }
1766*ef5ccd6cSJohn Marino 	}
1767*ef5ccd6cSJohn Marino 
17685796c8dcSSimon Schubert       /* Save the last frame to check for error conditions.  */
17695796c8dcSSimon Schubert       trailing = fi;
17705796c8dcSSimon Schubert     }
17715796c8dcSSimon Schubert 
17725796c8dcSSimon Schubert   /* If we've stopped before the end, mention that.  */
17735796c8dcSSimon Schubert   if (fi && from_tty)
17745796c8dcSSimon Schubert     printf_filtered (_("(More stack frames follow...)\n"));
17755796c8dcSSimon Schubert 
17765796c8dcSSimon Schubert   /* If we've run out of frames, and the reason appears to be an error
17775796c8dcSSimon Schubert      condition, print it.  */
17785796c8dcSSimon Schubert   if (fi == NULL && trailing != NULL)
17795796c8dcSSimon Schubert     {
17805796c8dcSSimon Schubert       enum unwind_stop_reason reason;
17815796c8dcSSimon Schubert 
17825796c8dcSSimon Schubert       reason = get_frame_unwind_stop_reason (trailing);
1783a45ae5f8SJohn Marino       if (reason >= UNWIND_FIRST_ERROR)
17845796c8dcSSimon Schubert 	printf_filtered (_("Backtrace stopped: %s\n"),
17855796c8dcSSimon Schubert 			 frame_stop_reason_string (reason));
17865796c8dcSSimon Schubert     }
17875796c8dcSSimon Schubert }
17885796c8dcSSimon Schubert 
17895796c8dcSSimon Schubert static void
backtrace_command(char * arg,int from_tty)17905796c8dcSSimon Schubert backtrace_command (char *arg, int from_tty)
17915796c8dcSSimon Schubert {
1792a45ae5f8SJohn Marino   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
17935796c8dcSSimon Schubert   int fulltrace_arg = -1, arglen = 0, argc = 0;
17945796c8dcSSimon Schubert 
17955796c8dcSSimon Schubert   if (arg)
17965796c8dcSSimon Schubert     {
17975796c8dcSSimon Schubert       char **argv;
17985796c8dcSSimon Schubert       int i;
17995796c8dcSSimon Schubert 
18005796c8dcSSimon Schubert       argv = gdb_buildargv (arg);
1801a45ae5f8SJohn Marino       make_cleanup_freeargv (argv);
18025796c8dcSSimon Schubert       argc = 0;
18035796c8dcSSimon Schubert       for (i = 0; argv[i]; i++)
18045796c8dcSSimon Schubert 	{
18055796c8dcSSimon Schubert 	  unsigned int j;
18065796c8dcSSimon Schubert 
18075796c8dcSSimon Schubert 	  for (j = 0; j < strlen (argv[i]); j++)
18085796c8dcSSimon Schubert 	    argv[i][j] = tolower (argv[i][j]);
18095796c8dcSSimon Schubert 
18105796c8dcSSimon Schubert 	  if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
18115796c8dcSSimon Schubert 	    fulltrace_arg = argc;
18125796c8dcSSimon Schubert 	  else
18135796c8dcSSimon Schubert 	    {
18145796c8dcSSimon Schubert 	      arglen += strlen (argv[i]);
18155796c8dcSSimon Schubert 	      argc++;
18165796c8dcSSimon Schubert 	    }
18175796c8dcSSimon Schubert 	}
18185796c8dcSSimon Schubert       arglen += argc;
18195796c8dcSSimon Schubert       if (fulltrace_arg >= 0)
18205796c8dcSSimon Schubert 	{
18215796c8dcSSimon Schubert 	  if (arglen > 0)
18225796c8dcSSimon Schubert 	    {
18235796c8dcSSimon Schubert 	      arg = xmalloc (arglen + 1);
1824a45ae5f8SJohn Marino 	      make_cleanup (xfree, arg);
1825a45ae5f8SJohn Marino 	      arg[0] = 0;
18265796c8dcSSimon Schubert 	      for (i = 0; i < (argc + 1); i++)
18275796c8dcSSimon Schubert 		{
18285796c8dcSSimon Schubert 		  if (i != fulltrace_arg)
18295796c8dcSSimon Schubert 		    {
18305796c8dcSSimon Schubert 		      strcat (arg, argv[i]);
18315796c8dcSSimon Schubert 		      strcat (arg, " ");
18325796c8dcSSimon Schubert 		    }
18335796c8dcSSimon Schubert 		}
18345796c8dcSSimon Schubert 	    }
18355796c8dcSSimon Schubert 	  else
18365796c8dcSSimon Schubert 	    arg = NULL;
18375796c8dcSSimon Schubert 	}
18385796c8dcSSimon Schubert     }
18395796c8dcSSimon Schubert 
1840a45ae5f8SJohn Marino   backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty);
18415796c8dcSSimon Schubert 
18425796c8dcSSimon Schubert   do_cleanups (old_chain);
18435796c8dcSSimon Schubert }
18445796c8dcSSimon Schubert 
18455796c8dcSSimon Schubert static void
backtrace_full_command(char * arg,int from_tty)18465796c8dcSSimon Schubert backtrace_full_command (char *arg, int from_tty)
18475796c8dcSSimon Schubert {
1848a45ae5f8SJohn Marino   backtrace_command_1 (arg, 1 /* show_locals */, from_tty);
18495796c8dcSSimon Schubert }
18505796c8dcSSimon Schubert 
18515796c8dcSSimon Schubert 
1852cf7f2e2dSJohn Marino /* Iterate over the local variables of a block B, calling CB with
1853cf7f2e2dSJohn Marino    CB_DATA.  */
18545796c8dcSSimon Schubert 
1855cf7f2e2dSJohn Marino static void
iterate_over_block_locals(struct block * b,iterate_over_block_arg_local_vars_cb cb,void * cb_data)1856cf7f2e2dSJohn Marino iterate_over_block_locals (struct block *b,
1857cf7f2e2dSJohn Marino 			   iterate_over_block_arg_local_vars_cb cb,
1858cf7f2e2dSJohn Marino 			   void *cb_data)
18595796c8dcSSimon Schubert {
1860*ef5ccd6cSJohn Marino   struct block_iterator iter;
18615796c8dcSSimon Schubert   struct symbol *sym;
18625796c8dcSSimon Schubert 
18635796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (b, iter, sym)
18645796c8dcSSimon Schubert     {
18655796c8dcSSimon Schubert       switch (SYMBOL_CLASS (sym))
18665796c8dcSSimon Schubert 	{
18675796c8dcSSimon Schubert 	case LOC_LOCAL:
18685796c8dcSSimon Schubert 	case LOC_REGISTER:
18695796c8dcSSimon Schubert 	case LOC_STATIC:
18705796c8dcSSimon Schubert 	case LOC_COMPUTED:
18715796c8dcSSimon Schubert 	  if (SYMBOL_IS_ARGUMENT (sym))
18725796c8dcSSimon Schubert 	    break;
1873*ef5ccd6cSJohn Marino 	  if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
1874*ef5ccd6cSJohn Marino 	    break;
1875cf7f2e2dSJohn Marino 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
18765796c8dcSSimon Schubert 	  break;
18775796c8dcSSimon Schubert 
18785796c8dcSSimon Schubert 	default:
18795796c8dcSSimon Schubert 	  /* Ignore symbols which are not locals.  */
18805796c8dcSSimon Schubert 	  break;
18815796c8dcSSimon Schubert 	}
18825796c8dcSSimon Schubert     }
18835796c8dcSSimon Schubert }
18845796c8dcSSimon Schubert 
1885cf7f2e2dSJohn Marino 
18865796c8dcSSimon Schubert /* Same, but print labels.  */
18875796c8dcSSimon Schubert 
1888cf7f2e2dSJohn Marino #if 0
1889cf7f2e2dSJohn Marino /* Commented out, as the code using this function has also been
1890cf7f2e2dSJohn Marino    commented out.  FIXME:brobecker/2009-01-13: Find out why the code
1891cf7f2e2dSJohn Marino    was commented out in the first place.  The discussion introducing
1892cf7f2e2dSJohn Marino    this change (2007-12-04: Support lexical blocks and function bodies
1893cf7f2e2dSJohn Marino    that occupy non-contiguous address ranges) did not explain why
1894cf7f2e2dSJohn Marino    this change was made.  */
18955796c8dcSSimon Schubert static int
18965796c8dcSSimon Schubert print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
18975796c8dcSSimon Schubert 			  int *have_default, struct ui_file *stream)
18985796c8dcSSimon Schubert {
1899*ef5ccd6cSJohn Marino   struct block_iterator iter;
19005796c8dcSSimon Schubert   struct symbol *sym;
19015796c8dcSSimon Schubert   int values_printed = 0;
19025796c8dcSSimon Schubert 
19035796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (b, iter, sym)
19045796c8dcSSimon Schubert     {
19055796c8dcSSimon Schubert       if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
19065796c8dcSSimon Schubert 	{
19075796c8dcSSimon Schubert 	  if (*have_default)
19085796c8dcSSimon Schubert 	    continue;
19095796c8dcSSimon Schubert 	  *have_default = 1;
19105796c8dcSSimon Schubert 	}
19115796c8dcSSimon Schubert       if (SYMBOL_CLASS (sym) == LOC_LABEL)
19125796c8dcSSimon Schubert 	{
19135796c8dcSSimon Schubert 	  struct symtab_and_line sal;
19145796c8dcSSimon Schubert 	  struct value_print_options opts;
1915cf7f2e2dSJohn Marino 
19165796c8dcSSimon Schubert 	  sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
19175796c8dcSSimon Schubert 	  values_printed = 1;
19185796c8dcSSimon Schubert 	  fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
19195796c8dcSSimon Schubert 	  get_user_print_options (&opts);
19205796c8dcSSimon Schubert 	  if (opts.addressprint)
19215796c8dcSSimon Schubert 	    {
19225796c8dcSSimon Schubert 	      fprintf_filtered (stream, " ");
19235796c8dcSSimon Schubert 	      fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
19245796c8dcSSimon Schubert 			      stream);
19255796c8dcSSimon Schubert 	    }
19265796c8dcSSimon Schubert 	  fprintf_filtered (stream, " in file %s, line %d\n",
19275796c8dcSSimon Schubert 			    sal.symtab->filename, sal.line);
19285796c8dcSSimon Schubert 	}
19295796c8dcSSimon Schubert     }
19305796c8dcSSimon Schubert 
19315796c8dcSSimon Schubert   return values_printed;
19325796c8dcSSimon Schubert }
1933cf7f2e2dSJohn Marino #endif
19345796c8dcSSimon Schubert 
1935cf7f2e2dSJohn Marino /* Iterate over all the local variables in block B, including all its
1936cf7f2e2dSJohn Marino    superblocks, stopping when the top-level block is reached.  */
19375796c8dcSSimon Schubert 
1938cf7f2e2dSJohn Marino void
iterate_over_block_local_vars(struct block * block,iterate_over_block_arg_local_vars_cb cb,void * cb_data)1939cf7f2e2dSJohn Marino iterate_over_block_local_vars (struct block *block,
1940cf7f2e2dSJohn Marino 			       iterate_over_block_arg_local_vars_cb cb,
1941cf7f2e2dSJohn Marino 			       void *cb_data)
1942cf7f2e2dSJohn Marino {
1943cf7f2e2dSJohn Marino   while (block)
1944cf7f2e2dSJohn Marino     {
1945cf7f2e2dSJohn Marino       iterate_over_block_locals (block, cb, cb_data);
1946cf7f2e2dSJohn Marino       /* After handling the function's top-level block, stop.  Don't
1947cf7f2e2dSJohn Marino 	 continue to its superblock, the block of per-file
1948cf7f2e2dSJohn Marino 	 symbols.  */
1949cf7f2e2dSJohn Marino       if (BLOCK_FUNCTION (block))
1950cf7f2e2dSJohn Marino 	break;
1951cf7f2e2dSJohn Marino       block = BLOCK_SUPERBLOCK (block);
1952cf7f2e2dSJohn Marino     }
1953cf7f2e2dSJohn Marino }
1954cf7f2e2dSJohn Marino 
1955cf7f2e2dSJohn Marino /* Data to be passed around in the calls to the locals and args
1956cf7f2e2dSJohn Marino    iterators.  */
1957cf7f2e2dSJohn Marino 
1958cf7f2e2dSJohn Marino struct print_variable_and_value_data
1959cf7f2e2dSJohn Marino {
1960*ef5ccd6cSJohn Marino   struct frame_id frame_id;
1961cf7f2e2dSJohn Marino   int num_tabs;
1962cf7f2e2dSJohn Marino   struct ui_file *stream;
1963cf7f2e2dSJohn Marino   int values_printed;
1964cf7f2e2dSJohn Marino };
1965cf7f2e2dSJohn Marino 
1966c50c785cSJohn Marino /* The callback for the locals and args iterators.  */
1967cf7f2e2dSJohn Marino 
1968cf7f2e2dSJohn Marino static void
do_print_variable_and_value(const char * print_name,struct symbol * sym,void * cb_data)1969cf7f2e2dSJohn Marino do_print_variable_and_value (const char *print_name,
1970cf7f2e2dSJohn Marino 			     struct symbol *sym,
1971cf7f2e2dSJohn Marino 			     void *cb_data)
1972cf7f2e2dSJohn Marino {
1973cf7f2e2dSJohn Marino   struct print_variable_and_value_data *p = cb_data;
1974*ef5ccd6cSJohn Marino   struct frame_info *frame;
1975cf7f2e2dSJohn Marino 
1976*ef5ccd6cSJohn Marino   frame = frame_find_by_id (p->frame_id);
1977*ef5ccd6cSJohn Marino   if (frame == NULL)
1978*ef5ccd6cSJohn Marino     {
1979*ef5ccd6cSJohn Marino       warning (_("Unable to restore previously selected frame."));
1980*ef5ccd6cSJohn Marino       return;
1981*ef5ccd6cSJohn Marino     }
1982*ef5ccd6cSJohn Marino 
1983*ef5ccd6cSJohn Marino   print_variable_and_value (print_name, sym, frame, p->stream, p->num_tabs);
1984*ef5ccd6cSJohn Marino 
1985*ef5ccd6cSJohn Marino   /* print_variable_and_value invalidates FRAME.  */
1986*ef5ccd6cSJohn Marino   frame = NULL;
1987*ef5ccd6cSJohn Marino 
1988cf7f2e2dSJohn Marino   p->values_printed = 1;
1989cf7f2e2dSJohn Marino }
19905796c8dcSSimon Schubert 
1991*ef5ccd6cSJohn Marino /* Print all variables from the innermost up to the function block of FRAME.
1992*ef5ccd6cSJohn Marino    Print them with values to STREAM indented by NUM_TABS.
1993*ef5ccd6cSJohn Marino 
1994*ef5ccd6cSJohn Marino    This function will invalidate FRAME.  */
1995*ef5ccd6cSJohn Marino 
19965796c8dcSSimon Schubert static void
print_frame_local_vars(struct frame_info * frame,int num_tabs,struct ui_file * stream)19975796c8dcSSimon Schubert print_frame_local_vars (struct frame_info *frame, int num_tabs,
19985796c8dcSSimon Schubert 			struct ui_file *stream)
19995796c8dcSSimon Schubert {
2000cf7f2e2dSJohn Marino   struct print_variable_and_value_data cb_data;
2001cf7f2e2dSJohn Marino   struct block *block;
2002c50c785cSJohn Marino   CORE_ADDR pc;
2003c50c785cSJohn Marino 
2004c50c785cSJohn Marino   if (!get_frame_pc_if_available (frame, &pc))
2005c50c785cSJohn Marino     {
2006c50c785cSJohn Marino       fprintf_filtered (stream,
2007c50c785cSJohn Marino 			_("PC unavailable, cannot determine locals.\n"));
2008c50c785cSJohn Marino       return;
2009c50c785cSJohn Marino     }
20105796c8dcSSimon Schubert 
2011cf7f2e2dSJohn Marino   block = get_frame_block (frame, 0);
20125796c8dcSSimon Schubert   if (block == 0)
20135796c8dcSSimon Schubert     {
20145796c8dcSSimon Schubert       fprintf_filtered (stream, "No symbol table info available.\n");
20155796c8dcSSimon Schubert       return;
20165796c8dcSSimon Schubert     }
20175796c8dcSSimon Schubert 
2018*ef5ccd6cSJohn Marino   cb_data.frame_id = get_frame_id (frame);
2019cf7f2e2dSJohn Marino   cb_data.num_tabs = 4 * num_tabs;
2020cf7f2e2dSJohn Marino   cb_data.stream = stream;
2021cf7f2e2dSJohn Marino   cb_data.values_printed = 0;
20225796c8dcSSimon Schubert 
2023cf7f2e2dSJohn Marino   iterate_over_block_local_vars (block,
2024cf7f2e2dSJohn Marino 				 do_print_variable_and_value,
2025cf7f2e2dSJohn Marino 				 &cb_data);
2026cf7f2e2dSJohn Marino 
2027*ef5ccd6cSJohn Marino   /* do_print_variable_and_value invalidates FRAME.  */
2028*ef5ccd6cSJohn Marino   frame = NULL;
2029*ef5ccd6cSJohn Marino 
2030cf7f2e2dSJohn Marino   if (!cb_data.values_printed)
20315796c8dcSSimon Schubert     fprintf_filtered (stream, _("No locals.\n"));
20325796c8dcSSimon Schubert }
20335796c8dcSSimon Schubert 
20345796c8dcSSimon Schubert void
locals_info(char * args,int from_tty)20355796c8dcSSimon Schubert locals_info (char *args, int from_tty)
20365796c8dcSSimon Schubert {
20375796c8dcSSimon Schubert   print_frame_local_vars (get_selected_frame (_("No frame selected.")),
20385796c8dcSSimon Schubert 			  0, gdb_stdout);
20395796c8dcSSimon Schubert }
20405796c8dcSSimon Schubert 
2041cf7f2e2dSJohn Marino /* Iterate over all the argument variables in block B.
2042cf7f2e2dSJohn Marino 
2043cf7f2e2dSJohn Marino    Returns 1 if any argument was walked; 0 otherwise.  */
2044cf7f2e2dSJohn Marino 
2045cf7f2e2dSJohn Marino void
iterate_over_block_arg_vars(struct block * b,iterate_over_block_arg_local_vars_cb cb,void * cb_data)2046cf7f2e2dSJohn Marino iterate_over_block_arg_vars (struct block *b,
2047cf7f2e2dSJohn Marino 			     iterate_over_block_arg_local_vars_cb cb,
2048cf7f2e2dSJohn Marino 			     void *cb_data)
20495796c8dcSSimon Schubert {
2050*ef5ccd6cSJohn Marino   struct block_iterator iter;
20515796c8dcSSimon Schubert   struct symbol *sym, *sym2;
20525796c8dcSSimon Schubert 
20535796c8dcSSimon Schubert   ALL_BLOCK_SYMBOLS (b, iter, sym)
20545796c8dcSSimon Schubert     {
20555796c8dcSSimon Schubert       /* Don't worry about things which aren't arguments.  */
20565796c8dcSSimon Schubert       if (SYMBOL_IS_ARGUMENT (sym))
20575796c8dcSSimon Schubert 	{
20585796c8dcSSimon Schubert 	  /* We have to look up the symbol because arguments can have
20595796c8dcSSimon Schubert 	     two entries (one a parameter, one a local) and the one we
20605796c8dcSSimon Schubert 	     want is the local, which lookup_symbol will find for us.
20615796c8dcSSimon Schubert 	     This includes gcc1 (not gcc2) on the sparc when passing a
20625796c8dcSSimon Schubert 	     small structure and gcc2 when the argument type is float
20635796c8dcSSimon Schubert 	     and it is passed as a double and converted to float by
20645796c8dcSSimon Schubert 	     the prologue (in the latter case the type of the LOC_ARG
20655796c8dcSSimon Schubert 	     symbol is double and the type of the LOC_LOCAL symbol is
20665796c8dcSSimon Schubert 	     float).  There are also LOC_ARG/LOC_REGISTER pairs which
20675796c8dcSSimon Schubert 	     are not combined in symbol-reading.  */
20685796c8dcSSimon Schubert 
20695796c8dcSSimon Schubert 	  sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
20705796c8dcSSimon Schubert 				b, VAR_DOMAIN, NULL);
2071cf7f2e2dSJohn Marino 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
2072cf7f2e2dSJohn Marino 	}
20735796c8dcSSimon Schubert     }
20745796c8dcSSimon Schubert }
20755796c8dcSSimon Schubert 
2076*ef5ccd6cSJohn Marino /* Print all argument variables of the function of FRAME.
2077*ef5ccd6cSJohn Marino    Print them with values to STREAM.
2078*ef5ccd6cSJohn Marino 
2079*ef5ccd6cSJohn Marino    This function will invalidate FRAME.  */
2080*ef5ccd6cSJohn Marino 
2081cf7f2e2dSJohn Marino static void
print_frame_arg_vars(struct frame_info * frame,struct ui_file * stream)2082cf7f2e2dSJohn Marino print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
2083cf7f2e2dSJohn Marino {
2084cf7f2e2dSJohn Marino   struct print_variable_and_value_data cb_data;
2085cf7f2e2dSJohn Marino   struct symbol *func;
2086c50c785cSJohn Marino   CORE_ADDR pc;
2087c50c785cSJohn Marino 
2088c50c785cSJohn Marino   if (!get_frame_pc_if_available (frame, &pc))
2089c50c785cSJohn Marino     {
2090c50c785cSJohn Marino       fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
2091c50c785cSJohn Marino       return;
2092c50c785cSJohn Marino     }
2093cf7f2e2dSJohn Marino 
2094cf7f2e2dSJohn Marino   func = get_frame_function (frame);
2095cf7f2e2dSJohn Marino   if (func == NULL)
2096cf7f2e2dSJohn Marino     {
2097cf7f2e2dSJohn Marino       fprintf_filtered (stream, _("No symbol table info available.\n"));
2098cf7f2e2dSJohn Marino       return;
2099cf7f2e2dSJohn Marino     }
2100cf7f2e2dSJohn Marino 
2101*ef5ccd6cSJohn Marino   cb_data.frame_id = get_frame_id (frame);
2102cf7f2e2dSJohn Marino   cb_data.num_tabs = 0;
2103cf7f2e2dSJohn Marino   cb_data.stream = gdb_stdout;
2104cf7f2e2dSJohn Marino   cb_data.values_printed = 0;
2105cf7f2e2dSJohn Marino 
2106cf7f2e2dSJohn Marino   iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
2107cf7f2e2dSJohn Marino 			       do_print_variable_and_value, &cb_data);
2108cf7f2e2dSJohn Marino 
2109*ef5ccd6cSJohn Marino   /* do_print_variable_and_value invalidates FRAME.  */
2110*ef5ccd6cSJohn Marino   frame = NULL;
2111*ef5ccd6cSJohn Marino 
2112cf7f2e2dSJohn Marino   if (!cb_data.values_printed)
21135796c8dcSSimon Schubert     fprintf_filtered (stream, _("No arguments.\n"));
21145796c8dcSSimon Schubert }
21155796c8dcSSimon Schubert 
21165796c8dcSSimon Schubert void
args_info(char * ignore,int from_tty)21175796c8dcSSimon Schubert args_info (char *ignore, int from_tty)
21185796c8dcSSimon Schubert {
21195796c8dcSSimon Schubert   print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
21205796c8dcSSimon Schubert 			gdb_stdout);
21215796c8dcSSimon Schubert }
21225796c8dcSSimon Schubert 
21235796c8dcSSimon Schubert 
21245796c8dcSSimon Schubert static void
args_plus_locals_info(char * ignore,int from_tty)21255796c8dcSSimon Schubert args_plus_locals_info (char *ignore, int from_tty)
21265796c8dcSSimon Schubert {
21275796c8dcSSimon Schubert   args_info (ignore, from_tty);
21285796c8dcSSimon Schubert   locals_info (ignore, from_tty);
21295796c8dcSSimon Schubert }
21305796c8dcSSimon Schubert 
21315796c8dcSSimon Schubert 
21325796c8dcSSimon Schubert /* Select frame FRAME.  Also print the stack frame and show the source
21335796c8dcSSimon Schubert    if this is the tui version.  */
21345796c8dcSSimon Schubert static void
select_and_print_frame(struct frame_info * frame)21355796c8dcSSimon Schubert select_and_print_frame (struct frame_info *frame)
21365796c8dcSSimon Schubert {
21375796c8dcSSimon Schubert   select_frame (frame);
21385796c8dcSSimon Schubert   if (frame)
21395796c8dcSSimon Schubert     print_stack_frame (frame, 1, SRC_AND_LOC);
21405796c8dcSSimon Schubert }
21415796c8dcSSimon Schubert 
21425796c8dcSSimon Schubert /* Return the symbol-block in which the selected frame is executing.
21435796c8dcSSimon Schubert    Can return zero under various legitimate circumstances.
21445796c8dcSSimon Schubert 
21455796c8dcSSimon Schubert    If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
21465796c8dcSSimon Schubert    code address within the block returned.  We use this to decide
21475796c8dcSSimon Schubert    which macros are in scope.  */
21485796c8dcSSimon Schubert 
21495796c8dcSSimon Schubert struct block *
get_selected_block(CORE_ADDR * addr_in_block)21505796c8dcSSimon Schubert get_selected_block (CORE_ADDR *addr_in_block)
21515796c8dcSSimon Schubert {
21525796c8dcSSimon Schubert   if (!has_stack_frames ())
21535796c8dcSSimon Schubert     return 0;
21545796c8dcSSimon Schubert 
21555796c8dcSSimon Schubert   return get_frame_block (get_selected_frame (NULL), addr_in_block);
21565796c8dcSSimon Schubert }
21575796c8dcSSimon Schubert 
21585796c8dcSSimon Schubert /* Find a frame a certain number of levels away from FRAME.
21595796c8dcSSimon Schubert    LEVEL_OFFSET_PTR points to an int containing the number of levels.
21605796c8dcSSimon Schubert    Positive means go to earlier frames (up); negative, the reverse.
21615796c8dcSSimon Schubert    The int that contains the number of levels is counted toward
21625796c8dcSSimon Schubert    zero as the frames for those levels are found.
21635796c8dcSSimon Schubert    If the top or bottom frame is reached, that frame is returned,
21645796c8dcSSimon Schubert    but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
21655796c8dcSSimon Schubert    how much farther the original request asked to go.  */
21665796c8dcSSimon Schubert 
21675796c8dcSSimon Schubert struct frame_info *
find_relative_frame(struct frame_info * frame,int * level_offset_ptr)21685796c8dcSSimon Schubert find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
21695796c8dcSSimon Schubert {
21705796c8dcSSimon Schubert   /* Going up is simple: just call get_prev_frame enough times or
21715796c8dcSSimon Schubert      until the initial frame is reached.  */
21725796c8dcSSimon Schubert   while (*level_offset_ptr > 0)
21735796c8dcSSimon Schubert     {
21745796c8dcSSimon Schubert       struct frame_info *prev = get_prev_frame (frame);
2175cf7f2e2dSJohn Marino 
21765796c8dcSSimon Schubert       if (!prev)
21775796c8dcSSimon Schubert 	break;
21785796c8dcSSimon Schubert       (*level_offset_ptr)--;
21795796c8dcSSimon Schubert       frame = prev;
21805796c8dcSSimon Schubert     }
21815796c8dcSSimon Schubert 
21825796c8dcSSimon Schubert   /* Going down is just as simple.  */
21835796c8dcSSimon Schubert   while (*level_offset_ptr < 0)
21845796c8dcSSimon Schubert     {
21855796c8dcSSimon Schubert       struct frame_info *next = get_next_frame (frame);
2186cf7f2e2dSJohn Marino 
21875796c8dcSSimon Schubert       if (!next)
21885796c8dcSSimon Schubert 	break;
21895796c8dcSSimon Schubert       (*level_offset_ptr)++;
21905796c8dcSSimon Schubert       frame = next;
21915796c8dcSSimon Schubert     }
21925796c8dcSSimon Schubert 
21935796c8dcSSimon Schubert   return frame;
21945796c8dcSSimon Schubert }
21955796c8dcSSimon Schubert 
21965796c8dcSSimon Schubert /* The "select_frame" command.  With no argument this is a NOP.
21975796c8dcSSimon Schubert    Select the frame at level LEVEL_EXP if it is a valid level.
21985796c8dcSSimon Schubert    Otherwise, treat LEVEL_EXP as an address expression and select it.
21995796c8dcSSimon Schubert 
22005796c8dcSSimon Schubert    See parse_frame_specification for more info on proper frame
22015796c8dcSSimon Schubert    expressions.  */
22025796c8dcSSimon Schubert 
22035796c8dcSSimon Schubert void
select_frame_command(char * level_exp,int from_tty)22045796c8dcSSimon Schubert select_frame_command (char *level_exp, int from_tty)
22055796c8dcSSimon Schubert {
22065796c8dcSSimon Schubert   select_frame (parse_frame_specification_1 (level_exp, "No stack.", NULL));
22075796c8dcSSimon Schubert }
22085796c8dcSSimon Schubert 
22095796c8dcSSimon Schubert /* The "frame" command.  With no argument, print the selected frame
22105796c8dcSSimon Schubert    briefly.  With an argument, behave like select_frame and then print
22115796c8dcSSimon Schubert    the selected frame.  */
22125796c8dcSSimon Schubert 
22135796c8dcSSimon Schubert static void
frame_command(char * level_exp,int from_tty)22145796c8dcSSimon Schubert frame_command (char *level_exp, int from_tty)
22155796c8dcSSimon Schubert {
22165796c8dcSSimon Schubert   select_frame_command (level_exp, from_tty);
22175796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
22185796c8dcSSimon Schubert }
22195796c8dcSSimon Schubert 
22205796c8dcSSimon Schubert /* The XDB Compatibility command to print the current frame.  */
22215796c8dcSSimon Schubert 
22225796c8dcSSimon Schubert static void
current_frame_command(char * level_exp,int from_tty)22235796c8dcSSimon Schubert current_frame_command (char *level_exp, int from_tty)
22245796c8dcSSimon Schubert {
22255796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC);
22265796c8dcSSimon Schubert }
22275796c8dcSSimon Schubert 
22285796c8dcSSimon Schubert /* Select the frame up one or COUNT_EXP stack levels from the
22295796c8dcSSimon Schubert    previously selected frame, and print it briefly.  */
22305796c8dcSSimon Schubert 
22315796c8dcSSimon Schubert static void
up_silently_base(char * count_exp)22325796c8dcSSimon Schubert up_silently_base (char *count_exp)
22335796c8dcSSimon Schubert {
22345796c8dcSSimon Schubert   struct frame_info *frame;
22355796c8dcSSimon Schubert   int count = 1;
22365796c8dcSSimon Schubert 
22375796c8dcSSimon Schubert   if (count_exp)
22385796c8dcSSimon Schubert     count = parse_and_eval_long (count_exp);
22395796c8dcSSimon Schubert 
22405796c8dcSSimon Schubert   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
22415796c8dcSSimon Schubert   if (count != 0 && count_exp == NULL)
22425796c8dcSSimon Schubert     error (_("Initial frame selected; you cannot go up."));
22435796c8dcSSimon Schubert   select_frame (frame);
22445796c8dcSSimon Schubert }
22455796c8dcSSimon Schubert 
22465796c8dcSSimon Schubert static void
up_silently_command(char * count_exp,int from_tty)22475796c8dcSSimon Schubert up_silently_command (char *count_exp, int from_tty)
22485796c8dcSSimon Schubert {
22495796c8dcSSimon Schubert   up_silently_base (count_exp);
22505796c8dcSSimon Schubert }
22515796c8dcSSimon Schubert 
22525796c8dcSSimon Schubert static void
up_command(char * count_exp,int from_tty)22535796c8dcSSimon Schubert up_command (char *count_exp, int from_tty)
22545796c8dcSSimon Schubert {
22555796c8dcSSimon Schubert   up_silently_base (count_exp);
22565796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
22575796c8dcSSimon Schubert }
22585796c8dcSSimon Schubert 
22595796c8dcSSimon Schubert /* Select the frame down one or COUNT_EXP stack levels from the previously
22605796c8dcSSimon Schubert    selected frame, and print it briefly.  */
22615796c8dcSSimon Schubert 
22625796c8dcSSimon Schubert static void
down_silently_base(char * count_exp)22635796c8dcSSimon Schubert down_silently_base (char *count_exp)
22645796c8dcSSimon Schubert {
22655796c8dcSSimon Schubert   struct frame_info *frame;
22665796c8dcSSimon Schubert   int count = -1;
2267cf7f2e2dSJohn Marino 
22685796c8dcSSimon Schubert   if (count_exp)
22695796c8dcSSimon Schubert     count = -parse_and_eval_long (count_exp);
22705796c8dcSSimon Schubert 
22715796c8dcSSimon Schubert   frame = find_relative_frame (get_selected_frame ("No stack."), &count);
22725796c8dcSSimon Schubert   if (count != 0 && count_exp == NULL)
22735796c8dcSSimon Schubert     {
22745796c8dcSSimon Schubert       /* We only do this if COUNT_EXP is not specified.  That way
22755796c8dcSSimon Schubert          "down" means to really go down (and let me know if that is
22765796c8dcSSimon Schubert          impossible), but "down 9999" can be used to mean go all the
22775796c8dcSSimon Schubert          way down without getting an error.  */
22785796c8dcSSimon Schubert 
22795796c8dcSSimon Schubert       error (_("Bottom (innermost) frame selected; you cannot go down."));
22805796c8dcSSimon Schubert     }
22815796c8dcSSimon Schubert 
22825796c8dcSSimon Schubert   select_frame (frame);
22835796c8dcSSimon Schubert }
22845796c8dcSSimon Schubert 
22855796c8dcSSimon Schubert static void
down_silently_command(char * count_exp,int from_tty)22865796c8dcSSimon Schubert down_silently_command (char *count_exp, int from_tty)
22875796c8dcSSimon Schubert {
22885796c8dcSSimon Schubert   down_silently_base (count_exp);
22895796c8dcSSimon Schubert }
22905796c8dcSSimon Schubert 
22915796c8dcSSimon Schubert static void
down_command(char * count_exp,int from_tty)22925796c8dcSSimon Schubert down_command (char *count_exp, int from_tty)
22935796c8dcSSimon Schubert {
22945796c8dcSSimon Schubert   down_silently_base (count_exp);
22955796c8dcSSimon Schubert   print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
22965796c8dcSSimon Schubert }
22975796c8dcSSimon Schubert 
22985796c8dcSSimon Schubert 
22995796c8dcSSimon Schubert void
return_command(char * retval_exp,int from_tty)23005796c8dcSSimon Schubert return_command (char *retval_exp, int from_tty)
23015796c8dcSSimon Schubert {
2302*ef5ccd6cSJohn Marino   /* Initialize it just to avoid a GCC false warning.  */
2303*ef5ccd6cSJohn Marino   enum return_value_convention rv_conv = RETURN_VALUE_STRUCT_CONVENTION;
23045796c8dcSSimon Schubert   struct frame_info *thisframe;
23055796c8dcSSimon Schubert   struct gdbarch *gdbarch;
23065796c8dcSSimon Schubert   struct symbol *thisfun;
23075796c8dcSSimon Schubert   struct value *return_value = NULL;
2308*ef5ccd6cSJohn Marino   struct value *function = NULL;
23095796c8dcSSimon Schubert   const char *query_prefix = "";
23105796c8dcSSimon Schubert 
23115796c8dcSSimon Schubert   thisframe = get_selected_frame ("No selected frame.");
23125796c8dcSSimon Schubert   thisfun = get_frame_function (thisframe);
23135796c8dcSSimon Schubert   gdbarch = get_frame_arch (thisframe);
23145796c8dcSSimon Schubert 
23155796c8dcSSimon Schubert   if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
23165796c8dcSSimon Schubert     error (_("Can not force return from an inlined function."));
23175796c8dcSSimon Schubert 
23185796c8dcSSimon Schubert   /* Compute the return value.  If the computation triggers an error,
23195796c8dcSSimon Schubert      let it bail.  If the return type can't be handled, set
23205796c8dcSSimon Schubert      RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
23215796c8dcSSimon Schubert      message.  */
23225796c8dcSSimon Schubert   if (retval_exp)
23235796c8dcSSimon Schubert     {
23245796c8dcSSimon Schubert       struct expression *retval_expr = parse_expression (retval_exp);
23255796c8dcSSimon Schubert       struct cleanup *old_chain = make_cleanup (xfree, retval_expr);
23265796c8dcSSimon Schubert       struct type *return_type = NULL;
23275796c8dcSSimon Schubert 
23285796c8dcSSimon Schubert       /* Compute the return value.  Should the computation fail, this
23295796c8dcSSimon Schubert          call throws an error.  */
23305796c8dcSSimon Schubert       return_value = evaluate_expression (retval_expr);
23315796c8dcSSimon Schubert 
23325796c8dcSSimon Schubert       /* Cast return value to the return type of the function.  Should
23335796c8dcSSimon Schubert          the cast fail, this call throws an error.  */
23345796c8dcSSimon Schubert       if (thisfun != NULL)
23355796c8dcSSimon Schubert 	return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
23365796c8dcSSimon Schubert       if (return_type == NULL)
23375796c8dcSSimon Schubert       	{
2338*ef5ccd6cSJohn Marino 	  if (retval_expr->elts[0].opcode != UNOP_CAST
2339*ef5ccd6cSJohn Marino 	      && retval_expr->elts[0].opcode != UNOP_CAST_TYPE)
23405796c8dcSSimon Schubert 	    error (_("Return value type not available for selected "
23415796c8dcSSimon Schubert 		     "stack frame.\n"
23425796c8dcSSimon Schubert 		     "Please use an explicit cast of the value to return."));
23435796c8dcSSimon Schubert 	  return_type = value_type (return_value);
23445796c8dcSSimon Schubert 	}
23455796c8dcSSimon Schubert       do_cleanups (old_chain);
23465796c8dcSSimon Schubert       CHECK_TYPEDEF (return_type);
23475796c8dcSSimon Schubert       return_value = value_cast (return_type, return_value);
23485796c8dcSSimon Schubert 
23495796c8dcSSimon Schubert       /* Make sure the value is fully evaluated.  It may live in the
23505796c8dcSSimon Schubert          stack frame we're about to pop.  */
23515796c8dcSSimon Schubert       if (value_lazy (return_value))
23525796c8dcSSimon Schubert 	value_fetch_lazy (return_value);
23535796c8dcSSimon Schubert 
2354*ef5ccd6cSJohn Marino       if (thisfun != NULL)
2355*ef5ccd6cSJohn Marino 	function = read_var_value (thisfun, thisframe);
2356*ef5ccd6cSJohn Marino 
2357*ef5ccd6cSJohn Marino       rv_conv = RETURN_VALUE_REGISTER_CONVENTION;
23585796c8dcSSimon Schubert       if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
23595796c8dcSSimon Schubert 	/* If the return-type is "void", don't try to find the
23605796c8dcSSimon Schubert            return-value's location.  However, do still evaluate the
23615796c8dcSSimon Schubert            return expression so that, even when the expression result
23625796c8dcSSimon Schubert            is discarded, side effects such as "return i++" still
23635796c8dcSSimon Schubert            occur.  */
23645796c8dcSSimon Schubert 	return_value = NULL;
2365*ef5ccd6cSJohn Marino       else if (thisfun != NULL)
2366*ef5ccd6cSJohn Marino 	{
2367*ef5ccd6cSJohn Marino 	  rv_conv = struct_return_convention (gdbarch, function, return_type);
2368*ef5ccd6cSJohn Marino 	  if (rv_conv == RETURN_VALUE_STRUCT_CONVENTION
2369*ef5ccd6cSJohn Marino 	      || rv_conv == RETURN_VALUE_ABI_RETURNS_ADDRESS)
23705796c8dcSSimon Schubert 	    {
2371c50c785cSJohn Marino 	      query_prefix = "The location at which to store the "
2372c50c785cSJohn Marino 		"function's return value is unknown.\n"
2373c50c785cSJohn Marino 		"If you continue, the return value "
2374c50c785cSJohn Marino 		"that you specified will be ignored.\n";
23755796c8dcSSimon Schubert 	      return_value = NULL;
23765796c8dcSSimon Schubert 	    }
23775796c8dcSSimon Schubert 	}
2378*ef5ccd6cSJohn Marino     }
23795796c8dcSSimon Schubert 
23805796c8dcSSimon Schubert   /* Does an interactive user really want to do this?  Include
23815796c8dcSSimon Schubert      information, such as how well GDB can handle the return value, in
23825796c8dcSSimon Schubert      the query message.  */
23835796c8dcSSimon Schubert   if (from_tty)
23845796c8dcSSimon Schubert     {
23855796c8dcSSimon Schubert       int confirmed;
2386cf7f2e2dSJohn Marino 
23875796c8dcSSimon Schubert       if (thisfun == NULL)
23885796c8dcSSimon Schubert 	confirmed = query (_("%sMake selected stack frame return now? "),
23895796c8dcSSimon Schubert 			   query_prefix);
23905796c8dcSSimon Schubert       else
23915796c8dcSSimon Schubert 	confirmed = query (_("%sMake %s return now? "), query_prefix,
23925796c8dcSSimon Schubert 			   SYMBOL_PRINT_NAME (thisfun));
23935796c8dcSSimon Schubert       if (!confirmed)
23945796c8dcSSimon Schubert 	error (_("Not confirmed"));
23955796c8dcSSimon Schubert     }
23965796c8dcSSimon Schubert 
23975796c8dcSSimon Schubert   /* Discard the selected frame and all frames inner-to it.  */
23985796c8dcSSimon Schubert   frame_pop (get_selected_frame (NULL));
23995796c8dcSSimon Schubert 
24005796c8dcSSimon Schubert   /* Store RETURN_VALUE in the just-returned register set.  */
24015796c8dcSSimon Schubert   if (return_value != NULL)
24025796c8dcSSimon Schubert     {
24035796c8dcSSimon Schubert       struct type *return_type = value_type (return_value);
24045796c8dcSSimon Schubert       struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ());
24055796c8dcSSimon Schubert 
2406*ef5ccd6cSJohn Marino       gdb_assert (rv_conv != RETURN_VALUE_STRUCT_CONVENTION
2407*ef5ccd6cSJohn Marino 		  && rv_conv != RETURN_VALUE_ABI_RETURNS_ADDRESS);
2408*ef5ccd6cSJohn Marino       gdbarch_return_value (gdbarch, function, return_type,
24095796c8dcSSimon Schubert 			    get_current_regcache (), NULL /*read*/,
24105796c8dcSSimon Schubert 			    value_contents (return_value) /*write*/);
24115796c8dcSSimon Schubert     }
24125796c8dcSSimon Schubert 
24135796c8dcSSimon Schubert   /* If we are at the end of a call dummy now, pop the dummy frame
24145796c8dcSSimon Schubert      too.  */
24155796c8dcSSimon Schubert   if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
24165796c8dcSSimon Schubert     frame_pop (get_current_frame ());
24175796c8dcSSimon Schubert 
24185796c8dcSSimon Schubert   /* If interactive, print the frame that is now current.  */
24195796c8dcSSimon Schubert   if (from_tty)
24205796c8dcSSimon Schubert     frame_command ("0", 1);
24215796c8dcSSimon Schubert   else
24225796c8dcSSimon Schubert     select_frame_command ("0", 0);
24235796c8dcSSimon Schubert }
24245796c8dcSSimon Schubert 
24255796c8dcSSimon Schubert /* Sets the scope to input function name, provided that the function
2426c50c785cSJohn Marino    is within the current stack frame.  */
24275796c8dcSSimon Schubert 
24285796c8dcSSimon Schubert struct function_bounds
24295796c8dcSSimon Schubert {
24305796c8dcSSimon Schubert   CORE_ADDR low, high;
24315796c8dcSSimon Schubert };
24325796c8dcSSimon Schubert 
24335796c8dcSSimon Schubert static void
func_command(char * arg,int from_tty)24345796c8dcSSimon Schubert func_command (char *arg, int from_tty)
24355796c8dcSSimon Schubert {
24365796c8dcSSimon Schubert   struct frame_info *frame;
24375796c8dcSSimon Schubert   int found = 0;
24385796c8dcSSimon Schubert   struct symtabs_and_lines sals;
24395796c8dcSSimon Schubert   int i;
24405796c8dcSSimon Schubert   int level = 1;
24415796c8dcSSimon Schubert   struct function_bounds *func_bounds = NULL;
2442a45ae5f8SJohn Marino   struct cleanup *cleanups;
24435796c8dcSSimon Schubert 
24445796c8dcSSimon Schubert   if (arg != NULL)
24455796c8dcSSimon Schubert     return;
24465796c8dcSSimon Schubert 
24475796c8dcSSimon Schubert   frame = parse_frame_specification ("0");
2448*ef5ccd6cSJohn Marino   sals = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
2449a45ae5f8SJohn Marino   cleanups = make_cleanup (xfree, sals.sals);
24505796c8dcSSimon Schubert   func_bounds = (struct function_bounds *) xmalloc (
24515796c8dcSSimon Schubert 			      sizeof (struct function_bounds) * sals.nelts);
2452a45ae5f8SJohn Marino   make_cleanup (xfree, func_bounds);
24535796c8dcSSimon Schubert   for (i = 0; (i < sals.nelts && !found); i++)
24545796c8dcSSimon Schubert     {
2455a45ae5f8SJohn Marino       if (sals.sals[i].pspace != current_program_space)
2456a45ae5f8SJohn Marino 	func_bounds[i].low = func_bounds[i].high = 0;
2457a45ae5f8SJohn Marino       else if (sals.sals[i].pc == 0
24585796c8dcSSimon Schubert 	       || find_pc_partial_function (sals.sals[i].pc, NULL,
24595796c8dcSSimon Schubert 					    &func_bounds[i].low,
24605796c8dcSSimon Schubert 					    &func_bounds[i].high) == 0)
24615796c8dcSSimon Schubert 	{
24625796c8dcSSimon Schubert 	  func_bounds[i].low = func_bounds[i].high = 0;
24635796c8dcSSimon Schubert 	}
24645796c8dcSSimon Schubert     }
24655796c8dcSSimon Schubert 
24665796c8dcSSimon Schubert   do
24675796c8dcSSimon Schubert     {
24685796c8dcSSimon Schubert       for (i = 0; (i < sals.nelts && !found); i++)
24695796c8dcSSimon Schubert 	found = (get_frame_pc (frame) >= func_bounds[i].low
24705796c8dcSSimon Schubert 		 && get_frame_pc (frame) < func_bounds[i].high);
24715796c8dcSSimon Schubert       if (!found)
24725796c8dcSSimon Schubert 	{
24735796c8dcSSimon Schubert 	  level = 1;
24745796c8dcSSimon Schubert 	  frame = find_relative_frame (frame, &level);
24755796c8dcSSimon Schubert 	}
24765796c8dcSSimon Schubert     }
24775796c8dcSSimon Schubert   while (!found && level == 0);
24785796c8dcSSimon Schubert 
2479a45ae5f8SJohn Marino   do_cleanups (cleanups);
24805796c8dcSSimon Schubert 
24815796c8dcSSimon Schubert   if (!found)
24825796c8dcSSimon Schubert     printf_filtered (_("'%s' not within current stack frame.\n"), arg);
24835796c8dcSSimon Schubert   else if (frame != get_selected_frame (NULL))
24845796c8dcSSimon Schubert     select_and_print_frame (frame);
24855796c8dcSSimon Schubert }
24865796c8dcSSimon Schubert 
24875796c8dcSSimon Schubert /* Gets the language of the current frame.  */
24885796c8dcSSimon Schubert 
24895796c8dcSSimon Schubert enum language
get_frame_language(void)24905796c8dcSSimon Schubert get_frame_language (void)
24915796c8dcSSimon Schubert {
24925796c8dcSSimon Schubert   struct frame_info *frame = deprecated_safe_get_selected_frame ();
24935796c8dcSSimon Schubert 
24945796c8dcSSimon Schubert   if (frame)
24955796c8dcSSimon Schubert     {
2496c50c785cSJohn Marino       volatile struct gdb_exception ex;
2497c50c785cSJohn Marino       CORE_ADDR pc = 0;
2498c50c785cSJohn Marino       struct symtab *s;
2499c50c785cSJohn Marino 
25005796c8dcSSimon Schubert       /* We determine the current frame language by looking up its
25015796c8dcSSimon Schubert          associated symtab.  To retrieve this symtab, we use the frame
25025796c8dcSSimon Schubert          PC.  However we cannot use the frame PC as is, because it
25035796c8dcSSimon Schubert          usually points to the instruction following the "call", which
25045796c8dcSSimon Schubert          is sometimes the first instruction of another function.  So
25055796c8dcSSimon Schubert          we rely on get_frame_address_in_block(), it provides us with
25065796c8dcSSimon Schubert          a PC that is guaranteed to be inside the frame's code
25075796c8dcSSimon Schubert          block.  */
25085796c8dcSSimon Schubert 
2509c50c785cSJohn Marino       TRY_CATCH (ex, RETURN_MASK_ERROR)
2510c50c785cSJohn Marino 	{
2511c50c785cSJohn Marino 	  pc = get_frame_address_in_block (frame);
2512c50c785cSJohn Marino 	}
2513c50c785cSJohn Marino       if (ex.reason < 0)
2514c50c785cSJohn Marino 	{
2515c50c785cSJohn Marino 	  if (ex.error != NOT_AVAILABLE_ERROR)
2516c50c785cSJohn Marino 	    throw_exception (ex);
2517c50c785cSJohn Marino 	}
2518c50c785cSJohn Marino       else
2519c50c785cSJohn Marino 	{
2520c50c785cSJohn Marino 	  s = find_pc_symtab (pc);
2521c50c785cSJohn Marino 	  if (s != NULL)
25225796c8dcSSimon Schubert 	    return s->language;
25235796c8dcSSimon Schubert 	}
2524c50c785cSJohn Marino     }
25255796c8dcSSimon Schubert 
25265796c8dcSSimon Schubert   return language_unknown;
25275796c8dcSSimon Schubert }
25285796c8dcSSimon Schubert 
25295796c8dcSSimon Schubert 
25305796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes.  */
25315796c8dcSSimon Schubert void _initialize_stack (void);
25325796c8dcSSimon Schubert 
25335796c8dcSSimon Schubert void
_initialize_stack(void)25345796c8dcSSimon Schubert _initialize_stack (void)
25355796c8dcSSimon Schubert {
25365796c8dcSSimon Schubert   add_com ("return", class_stack, return_command, _("\
25375796c8dcSSimon Schubert Make selected stack frame return to its caller.\n\
25385796c8dcSSimon Schubert Control remains in the debugger, but when you continue\n\
25395796c8dcSSimon Schubert execution will resume in the frame above the one now selected.\n\
25405796c8dcSSimon Schubert If an argument is given, it is an expression for the value to return."));
25415796c8dcSSimon Schubert 
25425796c8dcSSimon Schubert   add_com ("up", class_stack, up_command, _("\
25435796c8dcSSimon Schubert Select and print stack frame that called this one.\n\
25445796c8dcSSimon Schubert An argument says how many frames up to go."));
25455796c8dcSSimon Schubert   add_com ("up-silently", class_support, up_silently_command, _("\
25465796c8dcSSimon Schubert Same as the `up' command, but does not print anything.\n\
25475796c8dcSSimon Schubert This is useful in command scripts."));
25485796c8dcSSimon Schubert 
25495796c8dcSSimon Schubert   add_com ("down", class_stack, down_command, _("\
25505796c8dcSSimon Schubert Select and print stack frame called by this one.\n\
25515796c8dcSSimon Schubert An argument says how many frames down to go."));
25525796c8dcSSimon Schubert   add_com_alias ("do", "down", class_stack, 1);
25535796c8dcSSimon Schubert   add_com_alias ("dow", "down", class_stack, 1);
25545796c8dcSSimon Schubert   add_com ("down-silently", class_support, down_silently_command, _("\
25555796c8dcSSimon Schubert Same as the `down' command, but does not print anything.\n\
25565796c8dcSSimon Schubert This is useful in command scripts."));
25575796c8dcSSimon Schubert 
25585796c8dcSSimon Schubert   add_com ("frame", class_stack, frame_command, _("\
2559c50c785cSJohn Marino Select and print a stack frame.\nWith no argument, \
2560c50c785cSJohn Marino print the selected stack frame.  (See also \"info frame\").\n\
25615796c8dcSSimon Schubert An argument specifies the frame to select.\n\
25625796c8dcSSimon Schubert It can be a stack frame number or the address of the frame.\n\
25635796c8dcSSimon Schubert With argument, nothing is printed if input is coming from\n\
25645796c8dcSSimon Schubert a command file or a user-defined command."));
25655796c8dcSSimon Schubert 
25665796c8dcSSimon Schubert   add_com_alias ("f", "frame", class_stack, 1);
25675796c8dcSSimon Schubert 
25685796c8dcSSimon Schubert   if (xdb_commands)
25695796c8dcSSimon Schubert     {
25705796c8dcSSimon Schubert       add_com ("L", class_stack, current_frame_command,
25715796c8dcSSimon Schubert 	       _("Print the current stack frame.\n"));
25725796c8dcSSimon Schubert       add_com_alias ("V", "frame", class_stack, 1);
25735796c8dcSSimon Schubert     }
25745796c8dcSSimon Schubert   add_com ("select-frame", class_stack, select_frame_command, _("\
25755796c8dcSSimon Schubert Select a stack frame without printing anything.\n\
25765796c8dcSSimon Schubert An argument specifies the frame to select.\n\
25775796c8dcSSimon Schubert It can be a stack frame number or the address of the frame.\n"));
25785796c8dcSSimon Schubert 
25795796c8dcSSimon Schubert   add_com ("backtrace", class_stack, backtrace_command, _("\
25805796c8dcSSimon Schubert Print backtrace of all stack frames, or innermost COUNT frames.\n\
2581c50c785cSJohn Marino With a negative argument, print outermost -COUNT frames.\nUse of the \
2582c50c785cSJohn Marino 'full' qualifier also prints the values of the local variables.\n"));
25835796c8dcSSimon Schubert   add_com_alias ("bt", "backtrace", class_stack, 0);
25845796c8dcSSimon Schubert   if (xdb_commands)
25855796c8dcSSimon Schubert     {
25865796c8dcSSimon Schubert       add_com_alias ("t", "backtrace", class_stack, 0);
25875796c8dcSSimon Schubert       add_com ("T", class_stack, backtrace_full_command, _("\
25885796c8dcSSimon Schubert Print backtrace of all stack frames, or innermost COUNT frames\n\
25895796c8dcSSimon Schubert and the values of the local variables.\n\
25905796c8dcSSimon Schubert With a negative argument, print outermost -COUNT frames.\n\
25915796c8dcSSimon Schubert Usage: T <count>\n"));
25925796c8dcSSimon Schubert     }
25935796c8dcSSimon Schubert 
25945796c8dcSSimon Schubert   add_com_alias ("where", "backtrace", class_alias, 0);
25955796c8dcSSimon Schubert   add_info ("stack", backtrace_command,
25965796c8dcSSimon Schubert 	    _("Backtrace of the stack, or innermost COUNT frames."));
25975796c8dcSSimon Schubert   add_info_alias ("s", "stack", 1);
25985796c8dcSSimon Schubert   add_info ("frame", frame_info,
25995796c8dcSSimon Schubert 	    _("All about selected stack frame, or frame at ADDR."));
26005796c8dcSSimon Schubert   add_info_alias ("f", "frame", 1);
26015796c8dcSSimon Schubert   add_info ("locals", locals_info,
26025796c8dcSSimon Schubert 	    _("Local variables of current stack frame."));
26035796c8dcSSimon Schubert   add_info ("args", args_info,
26045796c8dcSSimon Schubert 	    _("Argument variables of current stack frame."));
26055796c8dcSSimon Schubert   if (xdb_commands)
26065796c8dcSSimon Schubert     add_com ("l", class_info, args_plus_locals_info,
26075796c8dcSSimon Schubert 	     _("Argument and local variables of current stack frame."));
26085796c8dcSSimon Schubert 
26095796c8dcSSimon Schubert   if (dbx_commands)
26105796c8dcSSimon Schubert     add_com ("func", class_stack, func_command, _("\
26115796c8dcSSimon Schubert Select the stack frame that contains <func>.\n\
26125796c8dcSSimon Schubert Usage: func <name>\n"));
26135796c8dcSSimon Schubert 
26145796c8dcSSimon Schubert   add_setshow_enum_cmd ("frame-arguments", class_stack,
26155796c8dcSSimon Schubert 			print_frame_arguments_choices, &print_frame_arguments,
26165796c8dcSSimon Schubert 			_("Set printing of non-scalar frame arguments"),
26175796c8dcSSimon Schubert 			_("Show printing of non-scalar frame arguments"),
26185796c8dcSSimon Schubert 			NULL, NULL, NULL, &setprintlist, &showprintlist);
26195796c8dcSSimon Schubert 
26205796c8dcSSimon Schubert   add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
26215796c8dcSSimon Schubert 			        &disassemble_next_line, _("\
2622c50c785cSJohn Marino Set whether to disassemble next source line or insn when execution stops."),
2623c50c785cSJohn Marino 				_("\
2624c50c785cSJohn Marino Show whether to disassemble next source line or insn when execution stops."),
2625c50c785cSJohn Marino 				_("\
26265796c8dcSSimon Schubert If ON, GDB will display disassembly of the next source line, in addition\n\
26275796c8dcSSimon Schubert to displaying the source line itself.  If the next source line cannot\n\
26285796c8dcSSimon Schubert be displayed (e.g., source is unavailable or there's no line info), GDB\n\
26295796c8dcSSimon Schubert will display disassembly of next instruction instead of showing the\n\
26305796c8dcSSimon Schubert source line.\n\
26315796c8dcSSimon Schubert If AUTO, display disassembly of next instruction only if the source line\n\
26325796c8dcSSimon Schubert cannot be displayed.\n\
26335796c8dcSSimon Schubert If OFF (which is the default), never display the disassembly of the next\n\
26345796c8dcSSimon Schubert source line."),
26355796c8dcSSimon Schubert 			        NULL,
26365796c8dcSSimon Schubert 			        show_disassemble_next_line,
26375796c8dcSSimon Schubert 			        &setlist, &showlist);
26385796c8dcSSimon Schubert   disassemble_next_line = AUTO_BOOLEAN_FALSE;
2639a45ae5f8SJohn Marino 
2640a45ae5f8SJohn Marino   add_setshow_enum_cmd ("entry-values", class_stack,
2641a45ae5f8SJohn Marino 			print_entry_values_choices, &print_entry_values,
2642a45ae5f8SJohn Marino 			_("Set printing of function arguments at function "
2643a45ae5f8SJohn Marino 			  "entry"),
2644a45ae5f8SJohn Marino 			_("Show printing of function arguments at function "
2645a45ae5f8SJohn Marino 			  "entry"),
2646a45ae5f8SJohn Marino 			_("\
2647a45ae5f8SJohn Marino GDB can sometimes determine the values of function arguments at entry,\n\
2648a45ae5f8SJohn Marino in addition to their current values.  This option tells GDB whether\n\
2649a45ae5f8SJohn Marino to print the current value, the value at entry (marked as val@entry),\n\
2650a45ae5f8SJohn Marino or both.  Note that one or both of these values may be <optimized out>."),
2651a45ae5f8SJohn Marino 			NULL, NULL, &setprintlist, &showprintlist);
26525796c8dcSSimon Schubert }
2653