stack.c revision 194061
119370Spst/* Print and select stack frames for GDB, the GNU debugger.
219370Spst
398944Sobrien   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4130803Smarcel   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
5130803Smarcel   Software Foundation, Inc.
619370Spst
798944Sobrien   This file is part of GDB.
819370Spst
998944Sobrien   This program is free software; you can redistribute it and/or modify
1098944Sobrien   it under the terms of the GNU General Public License as published by
1198944Sobrien   the Free Software Foundation; either version 2 of the License, or
1298944Sobrien   (at your option) any later version.
1319370Spst
1498944Sobrien   This program is distributed in the hope that it will be useful,
1598944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1698944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1798944Sobrien   GNU General Public License for more details.
1819370Spst
1998944Sobrien   You should have received a copy of the GNU General Public License
2098944Sobrien   along with this program; if not, write to the Free Software
2198944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
2298944Sobrien   Boston, MA 02111-1307, USA.  */
2398944Sobrien
2446283Sdfr#include <ctype.h>
2519370Spst#include "defs.h"
2619370Spst#include "gdb_string.h"
2719370Spst#include "value.h"
2819370Spst#include "symtab.h"
2919370Spst#include "gdbtypes.h"
3019370Spst#include "expression.h"
3119370Spst#include "language.h"
3219370Spst#include "frame.h"
3319370Spst#include "gdbcmd.h"
3419370Spst#include "gdbcore.h"
3519370Spst#include "target.h"
36130803Smarcel#include "source.h"
3719370Spst#include "breakpoint.h"
3819370Spst#include "demangle.h"
3919370Spst#include "inferior.h"
4019370Spst#include "annotate.h"
4198944Sobrien#include "ui-out.h"
42130803Smarcel#include "block.h"
43130803Smarcel#include "stack.h"
44130803Smarcel#include "gdb_assert.h"
45130803Smarcel#include "dictionary.h"
46130803Smarcel#include "reggroups.h"
47130803Smarcel#include "regcache.h"
4819370Spst
4946283Sdfr/* Prototypes for exported functions. */
5046283Sdfr
5198944Sobrienvoid args_info (char *, int);
5246283Sdfr
5398944Sobrienvoid locals_info (char *, int);
5446283Sdfr
5598944Sobrienvoid (*selected_frame_level_changed_hook) (int);
5646283Sdfr
5798944Sobrienvoid _initialize_stack (void);
5846283Sdfr
5946283Sdfr/* Prototypes for local functions. */
6046283Sdfr
6198944Sobrienstatic void down_command (char *, int);
6219370Spst
6398944Sobrienstatic void down_silently_base (char *);
6446283Sdfr
6598944Sobrienstatic void down_silently_command (char *, int);
6619370Spst
6798944Sobrienstatic void up_command (char *, int);
6819370Spst
6998944Sobrienstatic void up_silently_base (char *);
7046283Sdfr
7198944Sobrienstatic void up_silently_command (char *, int);
7219370Spst
7398944Sobrienvoid frame_command (char *, int);
7419370Spst
7598944Sobrienstatic void current_frame_command (char *, int);
7619370Spst
7798944Sobrienstatic void print_frame_arg_vars (struct frame_info *, struct ui_file *);
7819370Spst
7998944Sobrienstatic void catch_info (char *, int);
8019370Spst
8198944Sobrienstatic void args_plus_locals_info (char *, int);
8219370Spst
8398944Sobrienstatic void print_frame_label_vars (struct frame_info *, int,
8498944Sobrien				    struct ui_file *);
8519370Spst
8698944Sobrienstatic void print_frame_local_vars (struct frame_info *, int,
8798944Sobrien				    struct ui_file *);
8819370Spst
8998944Sobrienstatic int print_block_frame_labels (struct block *, int *,
9098944Sobrien				     struct ui_file *);
9119370Spst
9298944Sobrienstatic int print_block_frame_locals (struct block *,
9398944Sobrien				     struct frame_info *,
9498944Sobrien				     int,
9598944Sobrien				     struct ui_file *);
9646283Sdfr
9798944Sobrienstatic void print_frame (struct frame_info *fi,
9898944Sobrien			 int level,
9998944Sobrien			 int source,
10098944Sobrien			 int args,
10198944Sobrien			 struct symtab_and_line sal);
10219370Spst
10398944Sobrienstatic void backtrace_command (char *, int);
10498944Sobrien
10598944Sobrienstruct frame_info *parse_frame_specification (char *);
10698944Sobrien
10798944Sobrienstatic void frame_info (char *, int);
10898944Sobrien
10919370Spstextern int addressprint;	/* Print addresses, or stay symbolic only? */
11019370Spst
11119370Spst/* Zero means do things normally; we are interacting directly with the
11219370Spst   user.  One means print the full filename and linenumber when a
11319370Spst   frame is printed, and do so in a format emacs18/emacs19.22 can
11419370Spst   parse.  Two means print similar annotations, but in many more
11519370Spst   cases and in a slightly different syntax.  */
11619370Spst
11719370Spstint annotation_level = 0;
11819370Spst
11919370Spst
12098944Sobrienstruct print_stack_frame_args
12198944Sobrien  {
12298944Sobrien    struct frame_info *fi;
12398944Sobrien    int level;
12498944Sobrien    int source;
12598944Sobrien    int args;
12698944Sobrien  };
12719370Spst
12846283Sdfr/* Show or print the frame arguments.
12946283Sdfr   Pass the args the way catch_errors wants them.  */
13098944Sobrienstatic int print_stack_frame_stub (void *args);
13146283Sdfrstatic int
13298944Sobrienprint_stack_frame_stub (void *args)
13346283Sdfr{
13498944Sobrien  struct print_stack_frame_args *p = (struct print_stack_frame_args *) args;
13546283Sdfr
136130803Smarcel  print_frame_info (p->fi, p->level, p->source, p->args);
13746283Sdfr  return 0;
13846283Sdfr}
13946283Sdfr
140130803Smarcel/* Show or print a stack frame briefly.  FRAME_INFI should be the frame info
14119370Spst   and LEVEL should be its level in the stack (or -1 for level not defined).
14219370Spst   This prints the level, the function executing, the arguments,
14319370Spst   and the file name and line number.
14419370Spst   If the pc is not at the beginning of the source line,
14519370Spst   the actual pc is printed at the beginning.
14619370Spst
14719370Spst   If SOURCE is 1, print the source line as well.
14819370Spst   If SOURCE is -1, print ONLY the source line.  */
14919370Spst
150130803Smarcelvoid
151130803Smarcelprint_stack_frame (struct frame_info *fi, int level, int source)
15246283Sdfr{
15346283Sdfr  struct print_stack_frame_args args;
15446283Sdfr
15546283Sdfr  args.fi = fi;
15646283Sdfr  args.level = level;
15746283Sdfr  args.source = source;
15846283Sdfr  args.args = 1;
15946283Sdfr
160130803Smarcel  catch_errors (print_stack_frame_stub, (char *) &args, "", RETURN_MASK_ALL);
161130803Smarcel}
162130803Smarcel
163130803Smarcelstruct print_args_args
164130803Smarcel{
165130803Smarcel  struct symbol *func;
166130803Smarcel  struct frame_info *fi;
167130803Smarcel  struct ui_file *stream;
168130803Smarcel};
169130803Smarcel
170130803Smarcelstatic int print_args_stub (void *);
171130803Smarcel
172130803Smarcel/* Print nameless args on STREAM.
173130803Smarcel   FI is the frameinfo for this frame, START is the offset
174130803Smarcel   of the first nameless arg, and NUM is the number of nameless args to
175130803Smarcel   print.  FIRST is nonzero if this is the first argument (not just
176130803Smarcel   the first nameless arg).  */
177130803Smarcel
178130803Smarcelstatic void
179130803Smarcelprint_frame_nameless_args (struct frame_info *fi, long start, int num,
180130803Smarcel			   int first, struct ui_file *stream)
181130803Smarcel{
182130803Smarcel  int i;
183130803Smarcel  CORE_ADDR argsaddr;
184130803Smarcel  long arg_value;
185130803Smarcel
186130803Smarcel  for (i = 0; i < num; i++)
187130803Smarcel    {
188130803Smarcel      QUIT;
189130803Smarcel      argsaddr = get_frame_args_address (fi);
190130803Smarcel      if (!argsaddr)
191130803Smarcel	return;
192130803Smarcel      arg_value = read_memory_integer (argsaddr + start, sizeof (int));
193130803Smarcel      if (!first)
194130803Smarcel	fprintf_filtered (stream, ", ");
195130803Smarcel      fprintf_filtered (stream, "%ld", arg_value);
196130803Smarcel      first = 0;
197130803Smarcel      start += sizeof (int);
198130803Smarcel    }
19946283Sdfr}
20046283Sdfr
201130803Smarcel/* Print the arguments of a stack frame, given the function FUNC
202130803Smarcel   running in that frame (as a symbol), the info on the frame,
203130803Smarcel   and the number of args according to the stack frame (or -1 if unknown).  */
20446283Sdfr
205130803Smarcel/* References here and elsewhere to "number of args according to the
206130803Smarcel   stack frame" appear in all cases to refer to "number of ints of args
207130803Smarcel   according to the stack frame".  At least for VAX, i386, isi.  */
20846283Sdfr
209130803Smarcelstatic void
210130803Smarcelprint_frame_args (struct symbol *func, struct frame_info *fi, int num,
211130803Smarcel		  struct ui_file *stream)
21246283Sdfr{
213130803Smarcel  struct block *b = NULL;
214130803Smarcel  int first = 1;
215130803Smarcel  struct dict_iterator iter;
216130803Smarcel  struct symbol *sym;
217130803Smarcel  struct value *val;
218130803Smarcel  /* Offset of next stack argument beyond the one we have seen that is
219130803Smarcel     at the highest offset.
220130803Smarcel     -1 if we haven't come to a stack argument yet.  */
221130803Smarcel  long highest_offset = -1;
222130803Smarcel  int arg_size;
223130803Smarcel  /* Number of ints of arguments that we have printed so far.  */
224130803Smarcel  int args_printed = 0;
225130803Smarcel  struct cleanup *old_chain, *list_chain;
226130803Smarcel  struct ui_stream *stb;
22746283Sdfr
228130803Smarcel  stb = ui_out_stream_new (uiout);
229130803Smarcel  old_chain = make_cleanup_ui_out_stream_delete (stb);
23046283Sdfr
231130803Smarcel  if (func)
232130803Smarcel    {
233130803Smarcel      b = SYMBOL_BLOCK_VALUE (func);
23446283Sdfr
235130803Smarcel      ALL_BLOCK_SYMBOLS (b, iter, sym)
236130803Smarcel        {
237130803Smarcel	  QUIT;
23846283Sdfr
239130803Smarcel	  /* Keep track of the highest stack argument offset seen, and
240130803Smarcel	     skip over any kinds of symbols we don't care about.  */
24146283Sdfr
242130803Smarcel	  switch (SYMBOL_CLASS (sym))
243130803Smarcel	    {
244130803Smarcel	    case LOC_ARG:
245130803Smarcel	    case LOC_REF_ARG:
246130803Smarcel	      {
247130803Smarcel		long current_offset = SYMBOL_VALUE (sym);
248130803Smarcel		arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
24946283Sdfr
250130803Smarcel		/* Compute address of next argument by adding the size of
251130803Smarcel		   this argument and rounding to an int boundary.  */
252130803Smarcel		current_offset =
253130803Smarcel		  ((current_offset + arg_size + sizeof (int) - 1)
254130803Smarcel		   & ~(sizeof (int) - 1));
25519370Spst
256130803Smarcel		/* If this is the highest offset seen yet, set highest_offset.  */
257130803Smarcel		if (highest_offset == -1
258130803Smarcel		    || (current_offset > highest_offset))
259130803Smarcel		  highest_offset = current_offset;
26019370Spst
261130803Smarcel		/* Add the number of ints we're about to print to args_printed.  */
262130803Smarcel		args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
263130803Smarcel	      }
26419370Spst
265130803Smarcel	      /* We care about types of symbols, but don't need to keep track of
266130803Smarcel		 stack offsets in them.  */
267130803Smarcel	    case LOC_REGPARM:
268130803Smarcel	    case LOC_REGPARM_ADDR:
269130803Smarcel	    case LOC_LOCAL_ARG:
270130803Smarcel	    case LOC_BASEREG_ARG:
271130803Smarcel	    case LOC_COMPUTED_ARG:
272130803Smarcel	      break;
27346283Sdfr
274130803Smarcel	    /* Other types of symbols we just skip over.  */
275130803Smarcel	    default:
276130803Smarcel	      continue;
277130803Smarcel	    }
27846283Sdfr
279130803Smarcel	  /* We have to look up the symbol because arguments can have
280130803Smarcel	     two entries (one a parameter, one a local) and the one we
281130803Smarcel	     want is the local, which lookup_symbol will find for us.
282130803Smarcel	     This includes gcc1 (not gcc2) on the sparc when passing a
283130803Smarcel	     small structure and gcc2 when the argument type is float
284130803Smarcel	     and it is passed as a double and converted to float by
285130803Smarcel	     the prologue (in the latter case the type of the LOC_ARG
286130803Smarcel	     symbol is double and the type of the LOC_LOCAL symbol is
287130803Smarcel	     float).  */
288130803Smarcel	  /* But if the parameter name is null, don't try it.
289130803Smarcel	     Null parameter names occur on the RS/6000, for traceback tables.
290130803Smarcel	     FIXME, should we even print them?  */
29146283Sdfr
292130803Smarcel	  if (*DEPRECATED_SYMBOL_NAME (sym))
293130803Smarcel	    {
294130803Smarcel	      struct symbol *nsym;
295130803Smarcel	      nsym = lookup_symbol
296130803Smarcel		(DEPRECATED_SYMBOL_NAME (sym),
297130803Smarcel		 b, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL);
298130803Smarcel	      if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
299130803Smarcel		{
300130803Smarcel		  /* There is a LOC_ARG/LOC_REGISTER pair.  This means that
301130803Smarcel		     it was passed on the stack and loaded into a register,
302130803Smarcel		     or passed in a register and stored in a stack slot.
303130803Smarcel		     GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
30446283Sdfr
305130803Smarcel		     Reasons for using the LOC_ARG:
306130803Smarcel		     (1) because find_saved_registers may be slow for remote
307130803Smarcel		     debugging,
308130803Smarcel		     (2) because registers are often re-used and stack slots
309130803Smarcel		     rarely (never?) are.  Therefore using the stack slot is
310130803Smarcel		     much less likely to print garbage.
31146283Sdfr
312130803Smarcel		     Reasons why we might want to use the LOC_REGISTER:
313130803Smarcel		     (1) So that the backtrace prints the same value as
314130803Smarcel		     "print foo".  I see no compelling reason why this needs
315130803Smarcel		     to be the case; having the backtrace print the value which
316130803Smarcel		     was passed in, and "print foo" print the value as modified
317130803Smarcel		     within the called function, makes perfect sense to me.
31819370Spst
319130803Smarcel		     Additional note:  It might be nice if "info args" displayed
320130803Smarcel		     both values.
321130803Smarcel		     One more note:  There is a case with sparc structure passing
322130803Smarcel		     where we need to use the LOC_REGISTER, but this is dealt with
323130803Smarcel		     by creating a single LOC_REGPARM in symbol reading.  */
32419370Spst
325130803Smarcel		  /* Leave sym (the LOC_ARG) alone.  */
326130803Smarcel		  ;
327130803Smarcel		}
328130803Smarcel	      else
329130803Smarcel		sym = nsym;
330130803Smarcel	    }
331130803Smarcel
332130803Smarcel	  /* Print the current arg.  */
333130803Smarcel	  if (!first)
334130803Smarcel	    ui_out_text (uiout, ", ");
335130803Smarcel	  ui_out_wrap_hint (uiout, "    ");
336130803Smarcel
337130803Smarcel	  annotate_arg_begin ();
338130803Smarcel
339130803Smarcel	  list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
340130803Smarcel	  fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (sym),
341130803Smarcel				   SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
342130803Smarcel	  ui_out_field_stream (uiout, "name", stb);
343130803Smarcel	  annotate_arg_name_end ();
344130803Smarcel	  ui_out_text (uiout, "=");
345130803Smarcel
346130803Smarcel	  /* Avoid value_print because it will deref ref parameters.  We just
347130803Smarcel	     want to print their addresses.  Print ??? for args whose address
348130803Smarcel	     we do not know.  We pass 2 as "recurse" to val_print because our
349130803Smarcel	     standard indentation here is 4 spaces, and val_print indents
350130803Smarcel	     2 for each recurse.  */
351130803Smarcel	  val = read_var_value (sym, fi);
352130803Smarcel
353130803Smarcel	  annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
354130803Smarcel
355130803Smarcel	  if (val)
356130803Smarcel	    {
357130803Smarcel	      val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
358130803Smarcel			 VALUE_ADDRESS (val),
359130803Smarcel			 stb->stream, 0, 0, 2, Val_no_prettyprint);
360130803Smarcel	      ui_out_field_stream (uiout, "value", stb);
361130803Smarcel	    }
362130803Smarcel	  else
363130803Smarcel	    ui_out_text (uiout, "???");
364130803Smarcel
365130803Smarcel	  /* Invoke ui_out_tuple_end.  */
366130803Smarcel	  do_cleanups (list_chain);
367130803Smarcel
368130803Smarcel	  annotate_arg_end ();
369130803Smarcel
370130803Smarcel	  first = 0;
371130803Smarcel	}
372130803Smarcel    }
373130803Smarcel
374130803Smarcel  /* Don't print nameless args in situations where we don't know
375130803Smarcel     enough about the stack to find them.  */
376130803Smarcel  if (num != -1)
377130803Smarcel    {
378130803Smarcel      long start;
379130803Smarcel
380130803Smarcel      if (highest_offset == -1)
381130803Smarcel	start = FRAME_ARGS_SKIP;
382130803Smarcel      else
383130803Smarcel	start = highest_offset;
384130803Smarcel
385130803Smarcel      print_frame_nameless_args (fi, start, num - args_printed,
386130803Smarcel				 first, stream);
387130803Smarcel    }
388130803Smarcel  do_cleanups (old_chain);
389130803Smarcel}
390130803Smarcel
39119370Spst/* Pass the args the way catch_errors wants them.  */
39219370Spst
39319370Spststatic int
394130803Smarcelprint_args_stub (void *args)
39519370Spst{
39619370Spst  int numargs;
39798944Sobrien  struct print_args_args *p = (struct print_args_args *) args;
39819370Spst
399130803Smarcel  if (FRAME_NUM_ARGS_P ())
400130803Smarcel    {
401130803Smarcel      numargs = FRAME_NUM_ARGS (p->fi);
402130803Smarcel      gdb_assert (numargs >= 0);
403130803Smarcel    }
404130803Smarcel  else
405130803Smarcel    numargs = -1;
40698944Sobrien  print_frame_args (p->func, p->fi, numargs, p->stream);
40719370Spst  return 0;
40819370Spst}
40919370Spst
41046283Sdfr/* Print information about a frame for frame "fi" at level "level".
41198944Sobrien   Used in "where" output, also used to emit breakpoint or step
41298944Sobrien   messages.
41398944Sobrien   LEVEL is the level of the frame, or -1 if it is the
41498944Sobrien   innermost frame but we don't want to print the level.
41598944Sobrien   The meaning of the SOURCE argument is:
41698944Sobrien   SRC_LINE: Print only source line
41798944Sobrien   LOCATION: Print only location
41898944Sobrien   LOC_AND_SRC: Print location and source line.  */
41919370Spst
420130803Smarcelvoid
421130803Smarcelprint_frame_info (struct frame_info *fi, int level, int source, int args)
42219370Spst{
42319370Spst  struct symtab_and_line sal;
42498944Sobrien  int source_print;
42598944Sobrien  int location_print;
42619370Spst
427130803Smarcel  if (get_frame_type (fi) == DUMMY_FRAME
428130803Smarcel      || get_frame_type (fi) == SIGTRAMP_FRAME)
429130803Smarcel    {
430130803Smarcel      struct cleanup *uiout_cleanup
431130803Smarcel	= make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
43219370Spst
433130803Smarcel      annotate_frame_begin (level == -1 ? 0 : level, get_frame_pc (fi));
43419370Spst
43519370Spst      /* Do this regardless of SOURCE because we don't have any source
43698944Sobrien         to list for this frame.  */
43719370Spst      if (level >= 0)
438130803Smarcel        {
439130803Smarcel          ui_out_text (uiout, "#");
440130803Smarcel          ui_out_field_fmt_int (uiout, 2, ui_left, "level", level);
441130803Smarcel        }
442130803Smarcel      if (ui_out_is_mi_like_p (uiout))
443130803Smarcel        {
444130803Smarcel          annotate_frame_address ();
445130803Smarcel          ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi));
446130803Smarcel          annotate_frame_address_end ();
447130803Smarcel        }
448130803Smarcel
449130803Smarcel      if (get_frame_type (fi) == DUMMY_FRAME)
450130803Smarcel        {
451130803Smarcel          annotate_function_call ();
452130803Smarcel          ui_out_field_string (uiout, "func", "<function called from gdb>");
453130803Smarcel	}
454130803Smarcel      else if (get_frame_type (fi) == SIGTRAMP_FRAME)
455130803Smarcel        {
456130803Smarcel	  annotate_signal_handler_caller ();
457130803Smarcel          ui_out_field_string (uiout, "func", "<signal handler called>");
458130803Smarcel        }
459130803Smarcel      ui_out_text (uiout, "\n");
46019370Spst      annotate_frame_end ();
46119370Spst
462130803Smarcel      do_cleanups (uiout_cleanup);
46319370Spst      return;
46419370Spst    }
46519370Spst
46619370Spst  /* If fi is not the innermost frame, that normally means that fi->pc
467130803Smarcel     points to *after* the call instruction, and we want to get the
468130803Smarcel     line containing the call, never the next line.  But if the next
469130803Smarcel     frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame
470130803Smarcel     was not entered as the result of a call, and we want to get the
471130803Smarcel     line containing fi->pc.  */
472130803Smarcel  find_frame_sal (fi, &sal);
47319370Spst
47498944Sobrien  location_print = (source == LOCATION
47598944Sobrien		    || source == LOC_AND_ADDRESS
47698944Sobrien		    || source == SRC_AND_LOC);
47798944Sobrien
47898944Sobrien  if (location_print || !sal.symtab)
47998944Sobrien    print_frame (fi, level, source, args, sal);
48098944Sobrien
48198944Sobrien  source_print = (source == SRC_LINE || source == SRC_AND_LOC);
48298944Sobrien
483130803Smarcel  if (sal.symtab)
484130803Smarcel    set_current_source_symtab_and_line (&sal);
485130803Smarcel
48698944Sobrien  if (source_print && sal.symtab)
48798944Sobrien    {
488130803Smarcel      struct symtab_and_line cursal;
48998944Sobrien      int done = 0;
490130803Smarcel      int mid_statement = (source == SRC_LINE) && (get_frame_pc (fi) != sal.pc);
49198944Sobrien
49298944Sobrien      if (annotation_level)
49398944Sobrien	done = identify_source_line (sal.symtab, sal.line, mid_statement,
494130803Smarcel				     get_frame_pc (fi));
49598944Sobrien      if (!done)
49698944Sobrien	{
49798944Sobrien	  if (print_frame_info_listing_hook)
498130803Smarcel	    print_frame_info_listing_hook (sal.symtab, sal.line, sal.line + 1, 0);
49998944Sobrien	  else
50098944Sobrien	    {
50198944Sobrien	      /* We used to do this earlier, but that is clearly
50298944Sobrien		 wrong. This function is used by many different
50398944Sobrien		 parts of gdb, including normal_stop in infrun.c,
50498944Sobrien		 which uses this to print out the current PC
50598944Sobrien		 when we stepi/nexti into the middle of a source
50698944Sobrien		 line. Only the command line really wants this
50798944Sobrien		 behavior. Other UIs probably would like the
50898944Sobrien		 ability to decide for themselves if it is desired. */
50998944Sobrien	      if (addressprint && mid_statement)
51098944Sobrien		{
511130803Smarcel		  ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi));
51298944Sobrien		  ui_out_text (uiout, "\t");
51398944Sobrien		}
51498944Sobrien
51598944Sobrien	      print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
51698944Sobrien	    }
51798944Sobrien	}
518130803Smarcel      /* Make sure we have at least a default source file */
519130803Smarcel      set_default_source_symtab_and_line ();
520130803Smarcel      cursal = get_current_source_symtab_and_line ();
521130803Smarcel      cursal.line = max (sal.line - get_lines_to_list () / 2, 1);
522130803Smarcel      set_current_source_symtab_and_line (&cursal);
52398944Sobrien    }
52498944Sobrien
52598944Sobrien  if (source != 0)
526130803Smarcel    set_default_breakpoint (1, get_frame_pc (fi), sal.symtab, sal.line);
52798944Sobrien
52898944Sobrien  annotate_frame_end ();
52998944Sobrien
53098944Sobrien  gdb_flush (gdb_stdout);
53198944Sobrien}
53298944Sobrien
53398944Sobrienstatic void
53498944Sobrienprint_frame (struct frame_info *fi,
53598944Sobrien	     int level,
53698944Sobrien	     int source,
53798944Sobrien	     int args,
53898944Sobrien	     struct symtab_and_line sal)
53998944Sobrien{
54098944Sobrien  struct symbol *func;
541130803Smarcel  char *funname = 0;
54298944Sobrien  enum language funlang = language_unknown;
54398944Sobrien  struct ui_stream *stb;
54498944Sobrien  struct cleanup *old_chain;
54598944Sobrien  struct cleanup *list_chain;
54698944Sobrien
54798944Sobrien  stb = ui_out_stream_new (uiout);
54898944Sobrien  old_chain = make_cleanup_ui_out_stream_delete (stb);
54998944Sobrien
550130803Smarcel  func = find_pc_function (get_frame_address_in_block (fi));
55119370Spst  if (func)
55219370Spst    {
55319370Spst      /* In certain pathological cases, the symtabs give the wrong
55498944Sobrien         function (when we are in the first function in a file which
55598944Sobrien         is compiled without debugging symbols, the previous function
55698944Sobrien         is compiled with debugging symbols, and the "foo.o" symbol
55798944Sobrien         that is supposed to tell us where the file with debugging symbols
55898944Sobrien         ends has been truncated by ar because it is longer than 15
55998944Sobrien         characters).  This also occurs if the user uses asm() to create
56098944Sobrien         a function but not stabs for it (in a file compiled -g).
56119370Spst
56298944Sobrien         So look in the minimal symbol tables as well, and if it comes
56398944Sobrien         up with a larger address for the function use that instead.
56498944Sobrien         I don't think this can ever cause any problems; there shouldn't
56598944Sobrien         be any minimal symbols in the middle of a function; if this is
56698944Sobrien         ever changed many parts of GDB will need to be changed (and we'll
56798944Sobrien         create a find_pc_minimal_function or some such).  */
56819370Spst
569130803Smarcel      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi));
57019370Spst      if (msymbol != NULL
57198944Sobrien	  && (SYMBOL_VALUE_ADDRESS (msymbol)
57219370Spst	      > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
57319370Spst	{
57419370Spst#if 0
57519370Spst	  /* There is no particular reason to think the line number
57619370Spst	     information is wrong.  Someone might have just put in
57719370Spst	     a label with asm() but left the line numbers alone.  */
57819370Spst	  /* In this case we have no way of knowing the source file
57919370Spst	     and line number, so don't print them.  */
58019370Spst	  sal.symtab = 0;
58119370Spst#endif
58219370Spst	  /* We also don't know anything about the function besides
58319370Spst	     its address and name.  */
58419370Spst	  func = 0;
585130803Smarcel	  funname = DEPRECATED_SYMBOL_NAME (msymbol);
58619370Spst	  funlang = SYMBOL_LANGUAGE (msymbol);
58719370Spst	}
58819370Spst      else
58919370Spst	{
590130803Smarcel	  /* I'd like to use SYMBOL_PRINT_NAME() here, to display the
59198944Sobrien	     demangled name that we already have stored in the symbol
59298944Sobrien	     table, but we stored a version with DMGL_PARAMS turned
59398944Sobrien	     on, and here we don't want to display parameters. So call
59498944Sobrien	     the demangler again, with DMGL_ANSI only. (Yes, I know
59598944Sobrien	     that printf_symbol_filtered() will again try to demangle
59698944Sobrien	     the name on the fly, but the issue is that if
59798944Sobrien	     cplus_demangle() fails here, it'll fail there too. So we
59898944Sobrien	     want to catch the failure ("demangled==NULL" case below)
59998944Sobrien	     here, while we still have our hands on the function
60098944Sobrien	     symbol.) */
60198944Sobrien	  char *demangled;
602130803Smarcel	  funname = DEPRECATED_SYMBOL_NAME (func);
60319370Spst	  funlang = SYMBOL_LANGUAGE (func);
60498944Sobrien	  if (funlang == language_cplus)
60598944Sobrien	    {
60698944Sobrien	      demangled = cplus_demangle (funname, DMGL_ANSI);
60798944Sobrien	      if (demangled == NULL)
60898944Sobrien		/* If the demangler fails, try the demangled name from
60998944Sobrien		   the symbol table. This'll have parameters, but
61098944Sobrien		   that's preferable to diplaying a mangled name. */
611130803Smarcel		funname = SYMBOL_PRINT_NAME (func);
61298944Sobrien	    }
61319370Spst	}
61419370Spst    }
61519370Spst  else
61619370Spst    {
617130803Smarcel      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi));
61846283Sdfr      if (msymbol != NULL)
61919370Spst	{
620130803Smarcel	  funname = DEPRECATED_SYMBOL_NAME (msymbol);
62146283Sdfr	  funlang = SYMBOL_LANGUAGE (msymbol);
62219370Spst	}
62319370Spst    }
62419370Spst
625130803Smarcel  annotate_frame_begin (level == -1 ? 0 : level, get_frame_pc (fi));
62619370Spst
62798944Sobrien  list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
62819370Spst
62998944Sobrien  if (level >= 0)
63098944Sobrien    {
63198944Sobrien      ui_out_text (uiout, "#");
632130803Smarcel      ui_out_field_fmt_int (uiout, 2, ui_left, "level", level);
63319370Spst    }
63498944Sobrien  if (addressprint)
635130803Smarcel    if (get_frame_pc (fi) != sal.pc
636130803Smarcel	|| !sal.symtab
637130803Smarcel	|| source == LOC_AND_ADDRESS)
63898944Sobrien      {
63998944Sobrien	annotate_frame_address ();
640130803Smarcel	ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi));
64198944Sobrien	annotate_frame_address_end ();
64298944Sobrien	ui_out_text (uiout, " in ");
64398944Sobrien      }
64498944Sobrien  annotate_frame_function_name ();
64598944Sobrien  fprintf_symbol_filtered (stb->stream, funname ? funname : "??", funlang,
64698944Sobrien			   DMGL_ANSI);
64798944Sobrien  ui_out_field_stream (uiout, "func", stb);
64898944Sobrien  ui_out_wrap_hint (uiout, "   ");
64998944Sobrien  annotate_frame_args ();
65098944Sobrien
65198944Sobrien  ui_out_text (uiout, " (");
65298944Sobrien  if (args)
65398944Sobrien    {
65498944Sobrien      struct print_args_args args;
65598944Sobrien      struct cleanup *args_list_chain;
65698944Sobrien      args.fi = fi;
65798944Sobrien      args.func = func;
65898944Sobrien      args.stream = gdb_stdout;
65998944Sobrien      args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
66098944Sobrien      catch_errors (print_args_stub, &args, "", RETURN_MASK_ALL);
66198944Sobrien      /* FIXME: args must be a list. If one argument is a string it will
66298944Sobrien		 have " that will not be properly escaped.  */
66398944Sobrien      /* Invoke ui_out_tuple_end.  */
66498944Sobrien      do_cleanups (args_list_chain);
66598944Sobrien      QUIT;
66698944Sobrien    }
66798944Sobrien  ui_out_text (uiout, ")");
66898944Sobrien  if (sal.symtab && sal.symtab->filename)
66998944Sobrien    {
67098944Sobrien      annotate_frame_source_begin ();
67198944Sobrien      ui_out_wrap_hint (uiout, "   ");
67298944Sobrien      ui_out_text (uiout, " at ");
67398944Sobrien      annotate_frame_source_file ();
67498944Sobrien      ui_out_field_string (uiout, "file", sal.symtab->filename);
67598944Sobrien      annotate_frame_source_file_end ();
67698944Sobrien      ui_out_text (uiout, ":");
67798944Sobrien      annotate_frame_source_line ();
67898944Sobrien      ui_out_field_int (uiout, "line", sal.line);
67998944Sobrien      annotate_frame_source_end ();
68098944Sobrien    }
68119370Spst
68298944Sobrien#ifdef PC_SOLIB
68398944Sobrien  if (!funname || (!sal.symtab || !sal.symtab->filename))
68419370Spst    {
685130803Smarcel      char *lib = PC_SOLIB (get_frame_pc (fi));
68698944Sobrien      if (lib)
68719370Spst	{
68898944Sobrien	  annotate_frame_where ();
68998944Sobrien	  ui_out_wrap_hint (uiout, "  ");
69098944Sobrien	  ui_out_text (uiout, " from ");
69198944Sobrien	  ui_out_field_string (uiout, "from", lib);
69219370Spst	}
69319370Spst    }
69498944Sobrien#endif /* PC_SOLIB */
69519370Spst
69698944Sobrien  /* do_cleanups will call ui_out_tuple_end() for us.  */
69798944Sobrien  do_cleanups (list_chain);
69898944Sobrien  ui_out_text (uiout, "\n");
69998944Sobrien  do_cleanups (old_chain);
70019370Spst}
70146283Sdfr
70246283Sdfr/* Show the frame info.  If this is the tui, it will be shown in
70346283Sdfr   the source display otherwise, nothing is done */
70446283Sdfrvoid
70598944Sobrienshow_stack_frame (struct frame_info *fi)
70646283Sdfr{
70746283Sdfr}
70898944Sobrien
70946283Sdfr
71019370Spst/* Read a frame specification in whatever the appropriate format is.
71119370Spst   Call error() if the specification is in any way invalid (i.e.
71219370Spst   this function never returns NULL).  */
71319370Spst
71446283Sdfrstruct frame_info *
71598944Sobrienparse_frame_specification (char *frame_exp)
71619370Spst{
71719370Spst  int numargs = 0;
71819370Spst#define	MAXARGS	4
71919370Spst  CORE_ADDR args[MAXARGS];
72098944Sobrien  int level;
72198944Sobrien
72219370Spst  if (frame_exp)
72319370Spst    {
72419370Spst      char *addr_string, *p;
72519370Spst      struct cleanup *tmp_cleanup;
72619370Spst
72798944Sobrien      while (*frame_exp == ' ')
72898944Sobrien	frame_exp++;
72919370Spst
73019370Spst      while (*frame_exp)
73119370Spst	{
73219370Spst	  if (numargs > MAXARGS)
73319370Spst	    error ("Too many args in frame specification");
73419370Spst	  /* Parse an argument.  */
73598944Sobrien	  for (p = frame_exp; *p && *p != ' '; p++)
73619370Spst	    ;
73798944Sobrien	  addr_string = savestring (frame_exp, p - frame_exp);
73819370Spst
73919370Spst	  {
74098944Sobrien	    struct value *vp;
74198944Sobrien
74298944Sobrien	    tmp_cleanup = make_cleanup (xfree, addr_string);
74398944Sobrien
74498944Sobrien	    /* NOTE: we call parse_and_eval and then both
74598944Sobrien	       value_as_long and value_as_address rather than calling
74698944Sobrien	       parse_and_eval_long and parse_and_eval_address because
74798944Sobrien	       of the issue of potential side effects from evaluating
74898944Sobrien	       the expression.  */
74998944Sobrien	    vp = parse_and_eval (addr_string);
75098944Sobrien	    if (numargs == 0)
75198944Sobrien	      level = value_as_long (vp);
75298944Sobrien
75398944Sobrien	    args[numargs++] = value_as_address (vp);
75419370Spst	    do_cleanups (tmp_cleanup);
75519370Spst	  }
75619370Spst
75719370Spst	  /* Skip spaces, move to possible next arg.  */
75898944Sobrien	  while (*p == ' ')
75998944Sobrien	    p++;
76019370Spst	  frame_exp = p;
76119370Spst	}
76219370Spst    }
76319370Spst
76419370Spst  switch (numargs)
76519370Spst    {
76619370Spst    case 0:
767130803Smarcel      if (deprecated_selected_frame == NULL)
76819370Spst	error ("No selected frame.");
769130803Smarcel      return deprecated_selected_frame;
77019370Spst      /* NOTREACHED */
77119370Spst    case 1:
77219370Spst      {
77319370Spst	struct frame_info *fid =
77498944Sobrien	find_relative_frame (get_current_frame (), &level);
77519370Spst	struct frame_info *tfid;
77619370Spst
77719370Spst	if (level == 0)
77819370Spst	  /* find_relative_frame was successful */
77919370Spst	  return fid;
78019370Spst
78119370Spst	/* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
78219370Spst	   take at least 2 addresses.  It is important to detect this case
78319370Spst	   here so that "frame 100" does not give a confusing error message
78419370Spst	   like "frame specification requires two addresses".  This of course
78519370Spst	   does not solve the "frame 100" problem for machines on which
78619370Spst	   a frame specification can be made with one address.  To solve
78719370Spst	   that, we need a new syntax for a specifying a frame by address.
78819370Spst	   I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
78919370Spst	   two args, etc.), but people might think that is too much typing,
79019370Spst	   so I guess *0x23,0x45 would be a possible alternative (commas
79119370Spst	   really should be used instead of spaces to delimit; using spaces
79219370Spst	   normally works in an expression).  */
79319370Spst#ifdef SETUP_ARBITRARY_FRAME
794130803Smarcel	error ("No frame %s", paddr_d (args[0]));
79519370Spst#endif
79619370Spst
79719370Spst	/* If (s)he specifies the frame with an address, he deserves what
79819370Spst	   (s)he gets.  Still, give the highest one that matches.  */
79919370Spst
80019370Spst	for (fid = get_current_frame ();
801130803Smarcel	     fid && get_frame_base (fid) != args[0];
80219370Spst	     fid = get_prev_frame (fid))
80319370Spst	  ;
80419370Spst
80519370Spst	if (fid)
80619370Spst	  while ((tfid = get_prev_frame (fid)) &&
807130803Smarcel		 (get_frame_base (tfid) == args[0]))
80819370Spst	    fid = tfid;
80998944Sobrien
81019370Spst	/* We couldn't identify the frame as an existing frame, but
81119370Spst	   perhaps we can create one with a single argument.  */
81219370Spst      }
81319370Spst
81498944Sobrien    default:
81519370Spst#ifdef SETUP_ARBITRARY_FRAME
81619370Spst      return SETUP_ARBITRARY_FRAME (numargs, args);
81719370Spst#else
81819370Spst      /* Usual case.  Do it here rather than have everyone supply
81998944Sobrien         a SETUP_ARBITRARY_FRAME that does this.  */
82019370Spst      if (numargs == 1)
82119370Spst	return create_new_frame (args[0], 0);
82219370Spst      error ("Too many args in frame specification");
82319370Spst#endif
82419370Spst      /* NOTREACHED */
82519370Spst    }
82619370Spst  /* NOTREACHED */
82719370Spst}
82819370Spst
82919370Spst/* Print verbosely the selected frame or the frame at address ADDR.
83019370Spst   This means absolutely all information in the frame is printed.  */
83119370Spst
83219370Spststatic void
83398944Sobrienframe_info (char *addr_exp, int from_tty)
83419370Spst{
83519370Spst  struct frame_info *fi;
83619370Spst  struct symtab_and_line sal;
83719370Spst  struct symbol *func;
83819370Spst  struct symtab *s;
83919370Spst  struct frame_info *calling_frame_info;
84019370Spst  int i, count, numregs;
84119370Spst  char *funname = 0;
84219370Spst  enum language funlang = language_unknown;
843130803Smarcel  const char *pc_regname;
84419370Spst
84519370Spst  if (!target_has_stack)
84619370Spst    error ("No stack.");
84719370Spst
848130803Smarcel  /* Name of the value returned by get_frame_pc().  Per comments, "pc"
849130803Smarcel     is not a good name.  */
850130803Smarcel  if (PC_REGNUM >= 0)
851130803Smarcel    /* OK, this is weird.  The PC_REGNUM hardware register's value can
852130803Smarcel       easily not match that of the internal value returned by
853130803Smarcel       get_frame_pc().  */
854130803Smarcel    pc_regname = REGISTER_NAME (PC_REGNUM);
855130803Smarcel  else
856130803Smarcel    /* But then, this is weird to.  Even without PC_REGNUM, an
857130803Smarcel       architectures will often have a hardware register called "pc",
858130803Smarcel       and that register's value, again, can easily not match
859130803Smarcel       get_frame_pc().  */
860130803Smarcel    pc_regname = "pc";
861130803Smarcel
86219370Spst  fi = parse_frame_specification (addr_exp);
86319370Spst  if (fi == NULL)
86419370Spst    error ("Invalid frame specified.");
86519370Spst
866130803Smarcel  find_frame_sal (fi, &sal);
86719370Spst  func = get_frame_function (fi);
868130803Smarcel  /* FIXME: cagney/2002-11-28: Why bother?  Won't sal.symtab contain
869130803Smarcel     the same value.  */
870130803Smarcel  s = find_pc_symtab (get_frame_pc (fi));
87119370Spst  if (func)
87219370Spst    {
873130803Smarcel      /* I'd like to use SYMBOL_PRINT_NAME() here, to display
87446283Sdfr       * the demangled name that we already have stored in
87546283Sdfr       * the symbol table, but we stored a version with
87646283Sdfr       * DMGL_PARAMS turned on, and here we don't want
87746283Sdfr       * to display parameters. So call the demangler again,
87846283Sdfr       * with DMGL_ANSI only. RT
87946283Sdfr       * (Yes, I know that printf_symbol_filtered() will
88046283Sdfr       * again try to demangle the name on the fly, but
88146283Sdfr       * the issue is that if cplus_demangle() fails here,
88246283Sdfr       * it'll fail there too. So we want to catch the failure
88346283Sdfr       * ("demangled==NULL" case below) here, while we still
88446283Sdfr       * have our hands on the function symbol.)
88546283Sdfr       */
88698944Sobrien      char *demangled;
887130803Smarcel      funname = DEPRECATED_SYMBOL_NAME (func);
88898944Sobrien      funlang = SYMBOL_LANGUAGE (func);
88998944Sobrien      if (funlang == language_cplus)
89098944Sobrien	{
89198944Sobrien	  demangled = cplus_demangle (funname, DMGL_ANSI);
89298944Sobrien	  /* If the demangler fails, try the demangled name
89398944Sobrien	   * from the symbol table. This'll have parameters,
89498944Sobrien	   * but that's preferable to diplaying a mangled name.
89598944Sobrien	   */
89698944Sobrien	  if (demangled == NULL)
897130803Smarcel	    funname = SYMBOL_PRINT_NAME (func);
89898944Sobrien	}
89919370Spst    }
90019370Spst  else
90119370Spst    {
902130803Smarcel      struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi));
90319370Spst      if (msymbol != NULL)
90419370Spst	{
905130803Smarcel	  funname = DEPRECATED_SYMBOL_NAME (msymbol);
90619370Spst	  funlang = SYMBOL_LANGUAGE (msymbol);
90719370Spst	}
90819370Spst    }
90919370Spst  calling_frame_info = get_prev_frame (fi);
91019370Spst
911130803Smarcel  if (!addr_exp && frame_relative_level (deprecated_selected_frame) >= 0)
91219370Spst    {
913130803Smarcel      printf_filtered ("Stack level %d, frame at ",
914130803Smarcel		       frame_relative_level (deprecated_selected_frame));
915130803Smarcel      print_address_numeric (get_frame_base (fi), 1, gdb_stdout);
91619370Spst      printf_filtered (":\n");
91719370Spst    }
91819370Spst  else
91919370Spst    {
92019370Spst      printf_filtered ("Stack frame at ");
921130803Smarcel      print_address_numeric (get_frame_base (fi), 1, gdb_stdout);
92219370Spst      printf_filtered (":\n");
92319370Spst    }
924130803Smarcel  printf_filtered (" %s = ", pc_regname);
925130803Smarcel  print_address_numeric (get_frame_pc (fi), 1, gdb_stdout);
92619370Spst
92719370Spst  wrap_here ("   ");
92819370Spst  if (funname)
92919370Spst    {
93019370Spst      printf_filtered (" in ");
93119370Spst      fprintf_symbol_filtered (gdb_stdout, funname, funlang,
93219370Spst			       DMGL_ANSI | DMGL_PARAMS);
93319370Spst    }
93419370Spst  wrap_here ("   ");
93519370Spst  if (sal.symtab)
93619370Spst    printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
93719370Spst  puts_filtered ("; ");
93819370Spst  wrap_here ("    ");
939130803Smarcel  printf_filtered ("saved %s ", pc_regname);
940130803Smarcel  print_address_numeric (frame_pc_unwind (fi), 1, gdb_stdout);
94119370Spst  printf_filtered ("\n");
94219370Spst
94319370Spst  {
94498944Sobrien    int frameless;
945130803Smarcel    frameless = (DEPRECATED_FRAMELESS_FUNCTION_INVOCATION_P ()
946130803Smarcel		 && DEPRECATED_FRAMELESS_FUNCTION_INVOCATION (fi));
94719370Spst    if (frameless)
94819370Spst      printf_filtered (" (FRAMELESS),");
94919370Spst  }
95019370Spst
95119370Spst  if (calling_frame_info)
95219370Spst    {
95319370Spst      printf_filtered (" called by frame at ");
954130803Smarcel      print_address_numeric (get_frame_base (calling_frame_info),
955130803Smarcel			     1, gdb_stdout);
95619370Spst    }
957130803Smarcel  if (get_next_frame (fi) && calling_frame_info)
95819370Spst    puts_filtered (",");
95919370Spst  wrap_here ("   ");
960130803Smarcel  if (get_next_frame (fi))
96119370Spst    {
96219370Spst      printf_filtered (" caller of frame at ");
963130803Smarcel      print_address_numeric (get_frame_base (get_next_frame (fi)), 1,
964130803Smarcel			     gdb_stdout);
96519370Spst    }
966130803Smarcel  if (get_next_frame (fi) || calling_frame_info)
96719370Spst    puts_filtered ("\n");
96819370Spst  if (s)
969130803Smarcel    printf_filtered (" source language %s.\n",
970130803Smarcel		     language_str (s->language));
97119370Spst
97219370Spst  {
97319370Spst    /* Address of the argument list for this frame, or 0.  */
974130803Smarcel    CORE_ADDR arg_list = get_frame_args_address (fi);
97519370Spst    /* Number of args for this frame, or -1 if unknown.  */
97619370Spst    int numargs;
97719370Spst
97819370Spst    if (arg_list == 0)
97919370Spst      printf_filtered (" Arglist at unknown address.\n");
98019370Spst    else
98119370Spst      {
98219370Spst	printf_filtered (" Arglist at ");
98319370Spst	print_address_numeric (arg_list, 1, gdb_stdout);
98419370Spst	printf_filtered (",");
98519370Spst
986130803Smarcel	if (!FRAME_NUM_ARGS_P ())
987130803Smarcel	  {
988130803Smarcel	    numargs = -1;
989130803Smarcel	    puts_filtered (" args: ");
990130803Smarcel	  }
99119370Spst	else
992130803Smarcel	  {
993130803Smarcel	    numargs = FRAME_NUM_ARGS (fi);
994130803Smarcel	    gdb_assert (numargs >= 0);
995130803Smarcel	    if (numargs == 0)
996130803Smarcel	      puts_filtered (" no args.");
997130803Smarcel	    else if (numargs == 1)
998130803Smarcel	      puts_filtered (" 1 arg: ");
999130803Smarcel	    else
1000130803Smarcel	      printf_filtered (" %d args: ", numargs);
1001130803Smarcel	  }
100219370Spst	print_frame_args (func, fi, numargs, gdb_stdout);
100319370Spst	puts_filtered ("\n");
100419370Spst      }
100519370Spst  }
100619370Spst  {
100719370Spst    /* Address of the local variables for this frame, or 0.  */
1008130803Smarcel    CORE_ADDR arg_list = get_frame_locals_address (fi);
100919370Spst
101019370Spst    if (arg_list == 0)
101119370Spst      printf_filtered (" Locals at unknown address,");
101219370Spst    else
101319370Spst      {
101419370Spst	printf_filtered (" Locals at ");
101519370Spst	print_address_numeric (arg_list, 1, gdb_stdout);
101619370Spst	printf_filtered (",");
101719370Spst      }
101819370Spst  }
101919370Spst
1020130803Smarcel  if (DEPRECATED_FRAME_INIT_SAVED_REGS_P ()
1021130803Smarcel      && deprecated_get_frame_saved_regs (fi) == NULL)
1022130803Smarcel    DEPRECATED_FRAME_INIT_SAVED_REGS (fi);
1023130803Smarcel  /* Print as much information as possible on the location of all the
1024130803Smarcel     registers.  */
1025130803Smarcel  {
1026130803Smarcel    enum lval_type lval;
1027130803Smarcel    int optimized;
1028130803Smarcel    CORE_ADDR addr;
1029130803Smarcel    int realnum;
1030130803Smarcel    int count;
1031130803Smarcel    int i;
1032130803Smarcel    int need_nl = 1;
1033130803Smarcel
1034130803Smarcel    /* The sp is special; what's displayed isn't the save address, but
1035130803Smarcel       the value of the previous frame's sp.  This is a legacy thing,
1036130803Smarcel       at one stage the frame cached the previous frame's SP instead
1037130803Smarcel       of its address, hence it was easiest to just display the cached
1038130803Smarcel       value.  */
1039130803Smarcel    if (SP_REGNUM >= 0)
1040130803Smarcel      {
1041130803Smarcel	/* Find out the location of the saved stack pointer with out
1042130803Smarcel           actually evaluating it.  */
1043130803Smarcel	frame_register_unwind (fi, SP_REGNUM, &optimized, &lval, &addr,
1044130803Smarcel			       &realnum, NULL);
1045130803Smarcel	if (!optimized && lval == not_lval)
104646283Sdfr	  {
1047130803Smarcel	    char value[MAX_REGISTER_SIZE];
1048130803Smarcel	    CORE_ADDR sp;
1049130803Smarcel	    frame_register_unwind (fi, SP_REGNUM, &optimized, &lval, &addr,
1050130803Smarcel				   &realnum, value);
1051130803Smarcel	    /* NOTE: cagney/2003-05-22: This is assuming that the
1052130803Smarcel               stack pointer was packed as an unsigned integer.  That
1053130803Smarcel               may or may not be valid.  */
1054130803Smarcel	    sp = extract_unsigned_integer (value, DEPRECATED_REGISTER_RAW_SIZE (SP_REGNUM));
1055130803Smarcel	    printf_filtered (" Previous frame's sp is ");
1056130803Smarcel	    print_address_numeric (sp, 1, gdb_stdout);
1057130803Smarcel	    printf_filtered ("\n");
1058130803Smarcel	    need_nl = 0;
105946283Sdfr	  }
1060130803Smarcel	else if (!optimized && lval == lval_memory)
1061130803Smarcel	  {
1062130803Smarcel	    printf_filtered (" Previous frame's sp at ");
1063130803Smarcel	    print_address_numeric (addr, 1, gdb_stdout);
1064130803Smarcel	    printf_filtered ("\n");
1065130803Smarcel	    need_nl = 0;
1066130803Smarcel	  }
1067130803Smarcel	else if (!optimized && lval == lval_register)
1068130803Smarcel	  {
1069130803Smarcel	    printf_filtered (" Previous frame's sp in %s\n",
1070130803Smarcel			     REGISTER_NAME (realnum));
1071130803Smarcel	    need_nl = 0;
1072130803Smarcel	  }
1073130803Smarcel	/* else keep quiet.  */
1074130803Smarcel      }
1075130803Smarcel
1076130803Smarcel    count = 0;
1077130803Smarcel    numregs = NUM_REGS + NUM_PSEUDO_REGS;
1078130803Smarcel    for (i = 0; i < numregs; i++)
1079130803Smarcel      if (i != SP_REGNUM
1080130803Smarcel	  && gdbarch_register_reggroup_p (current_gdbarch, i, all_reggroup))
1081130803Smarcel	{
1082130803Smarcel	  /* Find out the location of the saved register without
1083130803Smarcel             fetching the corresponding value.  */
1084130803Smarcel	  frame_register_unwind (fi, i, &optimized, &lval, &addr, &realnum,
1085130803Smarcel				 NULL);
1086130803Smarcel	  /* For moment, only display registers that were saved on the
1087130803Smarcel	     stack.  */
1088130803Smarcel	  if (!optimized && lval == lval_memory)
1089130803Smarcel	    {
1090130803Smarcel	      if (count == 0)
1091130803Smarcel		puts_filtered (" Saved registers:\n ");
1092130803Smarcel	      else
1093130803Smarcel		puts_filtered (",");
1094130803Smarcel	      wrap_here (" ");
1095130803Smarcel	      printf_filtered (" %s at ", REGISTER_NAME (i));
1096130803Smarcel	      print_address_numeric (addr, 1, gdb_stdout);
1097130803Smarcel	      count++;
1098130803Smarcel	    }
1099130803Smarcel	}
1100130803Smarcel    if (count || need_nl)
110146283Sdfr      puts_filtered ("\n");
1102130803Smarcel  }
110319370Spst}
110419370Spst
110519370Spst#if 0
110619370Spst/* Set a limit on the number of frames printed by default in a
110719370Spst   backtrace.  */
110819370Spst
110919370Spststatic int backtrace_limit;
111019370Spst
111119370Spststatic void
111298944Sobrienset_backtrace_limit_command (char *count_exp, int from_tty)
111319370Spst{
111498944Sobrien  int count = parse_and_eval_long (count_exp);
111519370Spst
111619370Spst  if (count < 0)
111719370Spst    error ("Negative argument not meaningful as backtrace limit.");
111819370Spst
111919370Spst  backtrace_limit = count;
112019370Spst}
112119370Spst
112219370Spststatic void
112398944Sobrienbacktrace_limit_info (char *arg, int from_tty)
112419370Spst{
112519370Spst  if (arg)
112619370Spst    error ("\"Info backtrace-limit\" takes no arguments.");
112719370Spst
112819370Spst  printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit);
112919370Spst}
113019370Spst#endif
113119370Spst
113219370Spst/* Print briefly all stack frames or just the innermost COUNT frames.  */
113319370Spst
113498944Sobrienstatic void backtrace_command_1 (char *count_exp, int show_locals,
113598944Sobrien				 int from_tty);
113619370Spststatic void
113798944Sobrienbacktrace_command_1 (char *count_exp, int show_locals, int from_tty)
113819370Spst{
113919370Spst  struct frame_info *fi;
1140130803Smarcel  int count;
1141130803Smarcel  int i;
1142130803Smarcel  struct frame_info *trailing;
1143130803Smarcel  int trailing_level;
114419370Spst
114519370Spst  if (!target_has_stack)
114619370Spst    error ("No stack.");
114719370Spst
114819370Spst  /* The following code must do two things.  First, it must
114919370Spst     set the variable TRAILING to the frame from which we should start
115019370Spst     printing.  Second, it must set the variable count to the number
115119370Spst     of frames which we should print, or -1 if all of them.  */
115219370Spst  trailing = get_current_frame ();
115398944Sobrien
115498944Sobrien  /* The target can be in a state where there is no valid frames
115598944Sobrien     (e.g., just connected). */
115698944Sobrien  if (trailing == NULL)
115798944Sobrien    error ("No stack.");
115898944Sobrien
115919370Spst  trailing_level = 0;
116019370Spst  if (count_exp)
116119370Spst    {
116298944Sobrien      count = parse_and_eval_long (count_exp);
116319370Spst      if (count < 0)
116419370Spst	{
116519370Spst	  struct frame_info *current;
116619370Spst
116719370Spst	  count = -count;
116819370Spst
116919370Spst	  current = trailing;
117019370Spst	  while (current && count--)
117119370Spst	    {
117219370Spst	      QUIT;
117319370Spst	      current = get_prev_frame (current);
117419370Spst	    }
117598944Sobrien
117619370Spst	  /* Will stop when CURRENT reaches the top of the stack.  TRAILING
117719370Spst	     will be COUNT below it.  */
117819370Spst	  while (current)
117919370Spst	    {
118019370Spst	      QUIT;
118119370Spst	      trailing = get_prev_frame (trailing);
118219370Spst	      current = get_prev_frame (current);
118319370Spst	      trailing_level++;
118419370Spst	    }
118598944Sobrien
118619370Spst	  count = -1;
118719370Spst	}
118819370Spst    }
118919370Spst  else
119019370Spst    count = -1;
119119370Spst
119219370Spst  if (info_verbose)
119319370Spst    {
119419370Spst      struct partial_symtab *ps;
119598944Sobrien
119619370Spst      /* Read in symbols for all of the frames.  Need to do this in
119798944Sobrien         a separate pass so that "Reading in symbols for xxx" messages
119898944Sobrien         don't screw up the appearance of the backtrace.  Also
119998944Sobrien         if people have strong opinions against reading symbols for
120098944Sobrien         backtrace this may have to be an option.  */
120119370Spst      i = count;
120219370Spst      for (fi = trailing;
120319370Spst	   fi != NULL && i--;
120419370Spst	   fi = get_prev_frame (fi))
120519370Spst	{
120619370Spst	  QUIT;
1207130803Smarcel	  ps = find_pc_psymtab (get_frame_address_in_block (fi));
120819370Spst	  if (ps)
120919370Spst	    PSYMTAB_TO_SYMTAB (ps);	/* Force syms to come in */
121019370Spst	}
121119370Spst    }
121219370Spst
121319370Spst  for (i = 0, fi = trailing;
121419370Spst       fi && count--;
121519370Spst       i++, fi = get_prev_frame (fi))
121619370Spst    {
121719370Spst      QUIT;
121819370Spst
121919370Spst      /* Don't use print_stack_frame; if an error() occurs it probably
122098944Sobrien         means further attempts to backtrace would fail (on the other
122198944Sobrien         hand, perhaps the code does or could be fixed to make sure
122298944Sobrien         the frame->prev field gets set to NULL in that case).  */
1223130803Smarcel      print_frame_info (fi, trailing_level + i, 0, 1);
122446283Sdfr      if (show_locals)
122598944Sobrien	print_frame_local_vars (fi, 1, gdb_stdout);
122619370Spst    }
122719370Spst
122819370Spst  /* If we've stopped before the end, mention that.  */
122919370Spst  if (fi && from_tty)
123019370Spst    printf_filtered ("(More stack frames follow...)\n");
123119370Spst}
123246283Sdfr
1233194061Savgstruct backtrace_command_args
1234194061Savg  {
1235194061Savg    char *count_exp;
1236194061Savg    int show_locals;
1237194061Savg    int from_tty;
1238194061Savg  };
1239194061Savg
1240194061Savg/* Stub to call backtrace_command_1 by way of an error catcher.  */
1241194061Savgstatic int
1242194061Savgbacktrace_command_stub (void *data)
1243194061Savg{
1244194061Savg  struct backtrace_command_args *args = (struct backtrace_command_args *)data;
1245194061Savg  backtrace_command_1 (args->count_exp, args->show_locals, args->from_tty);
1246194061Savg  return 0;
1247194061Savg}
1248194061Savg
124946283Sdfrstatic void
125098944Sobrienbacktrace_command (char *arg, int from_tty)
125146283Sdfr{
125298944Sobrien  struct cleanup *old_chain = (struct cleanup *) NULL;
125398944Sobrien  char **argv = (char **) NULL;
125498944Sobrien  int argIndicatingFullTrace = (-1), totArgLen = 0, argc = 0;
125598944Sobrien  char *argPtr = arg;
1256194061Savg  struct backtrace_command_args btargs;
125746283Sdfr
125898944Sobrien  if (arg != (char *) NULL)
125946283Sdfr    {
126046283Sdfr      int i;
126146283Sdfr
126298944Sobrien      argv = buildargv (arg);
126398944Sobrien      old_chain = make_cleanup_freeargv (argv);
126446283Sdfr      argc = 0;
126598944Sobrien      for (i = 0; (argv[i] != (char *) NULL); i++)
126698944Sobrien	{
126798944Sobrien	  unsigned int j;
126846283Sdfr
126998944Sobrien	  for (j = 0; (j < strlen (argv[i])); j++)
127098944Sobrien	    argv[i][j] = tolower (argv[i][j]);
127146283Sdfr
127298944Sobrien	  if (argIndicatingFullTrace < 0 && subset_compare (argv[i], "full"))
127398944Sobrien	    argIndicatingFullTrace = argc;
127498944Sobrien	  else
127598944Sobrien	    {
127698944Sobrien	      argc++;
127798944Sobrien	      totArgLen += strlen (argv[i]);
127898944Sobrien	    }
127998944Sobrien	}
128046283Sdfr      totArgLen += argc;
128146283Sdfr      if (argIndicatingFullTrace >= 0)
128298944Sobrien	{
128398944Sobrien	  if (totArgLen > 0)
128498944Sobrien	    {
128598944Sobrien	      argPtr = (char *) xmalloc (totArgLen + 1);
128698944Sobrien	      if (!argPtr)
128798944Sobrien		nomem (0);
128898944Sobrien	      else
128998944Sobrien		{
129098944Sobrien		  memset (argPtr, 0, totArgLen + 1);
129198944Sobrien		  for (i = 0; (i < (argc + 1)); i++)
129298944Sobrien		    {
129398944Sobrien		      if (i != argIndicatingFullTrace)
129498944Sobrien			{
129598944Sobrien			  strcat (argPtr, argv[i]);
129698944Sobrien			  strcat (argPtr, " ");
129798944Sobrien			}
129898944Sobrien		    }
129998944Sobrien		}
130098944Sobrien	    }
130198944Sobrien	  else
130298944Sobrien	    argPtr = (char *) NULL;
130398944Sobrien	}
130446283Sdfr    }
130546283Sdfr
1306194061Savg  btargs.count_exp = argPtr;
1307194061Savg  btargs.show_locals = (argIndicatingFullTrace >= 0);
1308194061Savg  btargs.from_tty = from_tty;
1309194061Savg  catch_errors (backtrace_command_stub, (char *)&btargs, "", RETURN_MASK_ERROR);
131046283Sdfr
131146283Sdfr  if (argIndicatingFullTrace >= 0 && totArgLen > 0)
131298944Sobrien    xfree (argPtr);
131346283Sdfr
131446283Sdfr  if (old_chain)
131598944Sobrien    do_cleanups (old_chain);
131646283Sdfr}
131746283Sdfr
131898944Sobrienstatic void backtrace_full_command (char *arg, int from_tty);
131946283Sdfrstatic void
132098944Sobrienbacktrace_full_command (char *arg, int from_tty)
132146283Sdfr{
1322194061Savg  struct backtrace_command_args btargs;
1323194061Savg  btargs.count_exp = arg;
1324194061Savg  btargs.show_locals = 1;
1325194061Savg  btargs.from_tty = from_tty;
1326194061Savg  catch_errors (backtrace_command_stub, (char *)&btargs, "", RETURN_MASK_ERROR);
132746283Sdfr}
132898944Sobrien
132946283Sdfr
133019370Spst/* Print the local variables of a block B active in FRAME.
133119370Spst   Return 1 if any variables were printed; 0 otherwise.  */
133219370Spst
133319370Spststatic int
1334130803Smarcelprint_block_frame_locals (struct block *b, struct frame_info *fi,
1335130803Smarcel			  int num_tabs, struct ui_file *stream)
133619370Spst{
1337130803Smarcel  struct dict_iterator iter;
1338130803Smarcel  int j;
1339130803Smarcel  struct symbol *sym;
1340130803Smarcel  int values_printed = 0;
134119370Spst
1342130803Smarcel  ALL_BLOCK_SYMBOLS (b, iter, sym)
134319370Spst    {
134419370Spst      switch (SYMBOL_CLASS (sym))
134519370Spst	{
134619370Spst	case LOC_LOCAL:
134719370Spst	case LOC_REGISTER:
134819370Spst	case LOC_STATIC:
134919370Spst	case LOC_BASEREG:
1350130803Smarcel	case LOC_COMPUTED:
135119370Spst	  values_printed = 1;
135246283Sdfr	  for (j = 0; j < num_tabs; j++)
135398944Sobrien	    fputs_filtered ("\t", stream);
1354130803Smarcel	  fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
135519370Spst	  fputs_filtered (" = ", stream);
135619370Spst	  print_variable_value (sym, fi, stream);
135719370Spst	  fprintf_filtered (stream, "\n");
135819370Spst	  break;
135919370Spst
136019370Spst	default:
136119370Spst	  /* Ignore symbols which are not locals.  */
136219370Spst	  break;
136319370Spst	}
136419370Spst    }
136519370Spst  return values_printed;
136619370Spst}
136719370Spst
136819370Spst/* Same, but print labels.  */
136919370Spst
137019370Spststatic int
137198944Sobrienprint_block_frame_labels (struct block *b, int *have_default,
1372130803Smarcel			  struct ui_file *stream)
137319370Spst{
1374130803Smarcel  struct dict_iterator iter;
1375130803Smarcel  struct symbol *sym;
1376130803Smarcel  int values_printed = 0;
137719370Spst
1378130803Smarcel  ALL_BLOCK_SYMBOLS (b, iter, sym)
137919370Spst    {
1380130803Smarcel      if (DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (sym), "default"))
138119370Spst	{
138219370Spst	  if (*have_default)
138319370Spst	    continue;
138419370Spst	  *have_default = 1;
138519370Spst	}
138619370Spst      if (SYMBOL_CLASS (sym) == LOC_LABEL)
138719370Spst	{
138819370Spst	  struct symtab_and_line sal;
138919370Spst	  sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
139019370Spst	  values_printed = 1;
1391130803Smarcel	  fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
139219370Spst	  if (addressprint)
139319370Spst	    {
139419370Spst	      fprintf_filtered (stream, " ");
139519370Spst	      print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream);
139619370Spst	    }
139719370Spst	  fprintf_filtered (stream, " in file %s, line %d\n",
139819370Spst			    sal.symtab->filename, sal.line);
139919370Spst	}
140019370Spst    }
140119370Spst  return values_printed;
140219370Spst}
140319370Spst
140419370Spst/* Print on STREAM all the local variables in frame FRAME,
140519370Spst   including all the blocks active in that frame
140619370Spst   at its current pc.
140719370Spst
140819370Spst   Returns 1 if the job was done,
140919370Spst   or 0 if nothing was printed because we have no info
141019370Spst   on the function running in FRAME.  */
141119370Spst
141219370Spststatic void
1413130803Smarcelprint_frame_local_vars (struct frame_info *fi, int num_tabs,
1414130803Smarcel			struct ui_file *stream)
141519370Spst{
1416130803Smarcel  struct block *block = get_frame_block (fi, 0);
1417130803Smarcel  int values_printed = 0;
141819370Spst
141919370Spst  if (block == 0)
142019370Spst    {
142119370Spst      fprintf_filtered (stream, "No symbol table info available.\n");
142219370Spst      return;
142319370Spst    }
142498944Sobrien
142519370Spst  while (block != 0)
142619370Spst    {
142746283Sdfr      if (print_block_frame_locals (block, fi, num_tabs, stream))
142819370Spst	values_printed = 1;
142919370Spst      /* After handling the function's top-level block, stop.
143098944Sobrien         Don't continue to its superblock, the block of
143198944Sobrien         per-file symbols.  */
143219370Spst      if (BLOCK_FUNCTION (block))
143319370Spst	break;
143419370Spst      block = BLOCK_SUPERBLOCK (block);
143519370Spst    }
143619370Spst
143719370Spst  if (!values_printed)
143819370Spst    {
143919370Spst      fprintf_filtered (stream, "No locals.\n");
144019370Spst    }
144119370Spst}
144219370Spst
144319370Spst/* Same, but print labels.  */
144419370Spst
144519370Spststatic void
1446130803Smarcelprint_frame_label_vars (struct frame_info *fi, int this_level_only,
1447130803Smarcel			struct ui_file *stream)
144819370Spst{
1449130803Smarcel  struct blockvector *bl;
1450130803Smarcel  struct block *block = get_frame_block (fi, 0);
1451130803Smarcel  int values_printed = 0;
145219370Spst  int index, have_default = 0;
145319370Spst  char *blocks_printed;
1454130803Smarcel  CORE_ADDR pc = get_frame_pc (fi);
145519370Spst
145619370Spst  if (block == 0)
145719370Spst    {
145819370Spst      fprintf_filtered (stream, "No symbol table info available.\n");
145919370Spst      return;
146019370Spst    }
146119370Spst
146219370Spst  bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
146319370Spst  blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
146419370Spst  memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
146519370Spst
146619370Spst  while (block != 0)
146719370Spst    {
146819370Spst      CORE_ADDR end = BLOCK_END (block) - 4;
146919370Spst      int last_index;
147019370Spst
147119370Spst      if (bl != blockvector_for_pc (end, &index))
147219370Spst	error ("blockvector blotch");
147319370Spst      if (BLOCKVECTOR_BLOCK (bl, index) != block)
147419370Spst	error ("blockvector botch");
147519370Spst      last_index = BLOCKVECTOR_NBLOCKS (bl);
147619370Spst      index += 1;
147719370Spst
147819370Spst      /* Don't print out blocks that have gone by.  */
147919370Spst      while (index < last_index
148019370Spst	     && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
148119370Spst	index++;
148219370Spst
148319370Spst      while (index < last_index
148419370Spst	     && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
148519370Spst	{
148619370Spst	  if (blocks_printed[index] == 0)
148719370Spst	    {
148819370Spst	      if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
148919370Spst		values_printed = 1;
149019370Spst	      blocks_printed[index] = 1;
149119370Spst	    }
149219370Spst	  index++;
149319370Spst	}
149419370Spst      if (have_default)
149519370Spst	return;
149619370Spst      if (values_printed && this_level_only)
149719370Spst	return;
149819370Spst
149919370Spst      /* After handling the function's top-level block, stop.
150098944Sobrien         Don't continue to its superblock, the block of
150198944Sobrien         per-file symbols.  */
150219370Spst      if (BLOCK_FUNCTION (block))
150319370Spst	break;
150419370Spst      block = BLOCK_SUPERBLOCK (block);
150519370Spst    }
150619370Spst
150719370Spst  if (!values_printed && !this_level_only)
150819370Spst    {
150919370Spst      fprintf_filtered (stream, "No catches.\n");
151019370Spst    }
151119370Spst}
151219370Spst
151346283Sdfrvoid
151498944Sobrienlocals_info (char *args, int from_tty)
151519370Spst{
1516130803Smarcel  if (!deprecated_selected_frame)
151719370Spst    error ("No frame selected.");
1518130803Smarcel  print_frame_local_vars (deprecated_selected_frame, 0, gdb_stdout);
151919370Spst}
152019370Spst
152119370Spststatic void
152298944Sobriencatch_info (char *ignore, int from_tty)
152319370Spst{
152498944Sobrien  struct symtab_and_line *sal;
152546283Sdfr
152698944Sobrien  /* Check for target support for exception handling */
152746283Sdfr  sal = target_enable_exception_callback (EX_EVENT_CATCH, 1);
152846283Sdfr  if (sal)
152946283Sdfr    {
153046283Sdfr      /* Currently not handling this */
153146283Sdfr      /* Ideally, here we should interact with the C++ runtime
153246283Sdfr         system to find the list of active handlers, etc. */
153346283Sdfr      fprintf_filtered (gdb_stdout, "Info catch not supported with this target/compiler combination.\n");
153446283Sdfr#if 0
1535130803Smarcel      if (!deprecated_selected_frame)
153698944Sobrien	error ("No frame selected.");
153746283Sdfr#endif
153846283Sdfr    }
153946283Sdfr  else
154046283Sdfr    {
154198944Sobrien      /* Assume g++ compiled code -- old v 4.16 behaviour */
1542130803Smarcel      if (!deprecated_selected_frame)
154398944Sobrien	error ("No frame selected.");
154498944Sobrien
1545130803Smarcel      print_frame_label_vars (deprecated_selected_frame, 0, gdb_stdout);
154646283Sdfr    }
154719370Spst}
154819370Spst
154919370Spststatic void
1550130803Smarcelprint_frame_arg_vars (struct frame_info *fi,
1551130803Smarcel		      struct ui_file *stream)
155219370Spst{
155319370Spst  struct symbol *func = get_frame_function (fi);
1554130803Smarcel  struct block *b;
1555130803Smarcel  struct dict_iterator iter;
1556130803Smarcel  struct symbol *sym, *sym2;
1557130803Smarcel  int values_printed = 0;
155819370Spst
155919370Spst  if (func == 0)
156019370Spst    {
156119370Spst      fprintf_filtered (stream, "No symbol table info available.\n");
156219370Spst      return;
156319370Spst    }
156419370Spst
156519370Spst  b = SYMBOL_BLOCK_VALUE (func);
1566130803Smarcel  ALL_BLOCK_SYMBOLS (b, iter, sym)
156719370Spst    {
156819370Spst      switch (SYMBOL_CLASS (sym))
156919370Spst	{
157019370Spst	case LOC_ARG:
157119370Spst	case LOC_LOCAL_ARG:
157219370Spst	case LOC_REF_ARG:
157319370Spst	case LOC_REGPARM:
157419370Spst	case LOC_REGPARM_ADDR:
157519370Spst	case LOC_BASEREG_ARG:
1576130803Smarcel	case LOC_COMPUTED_ARG:
157719370Spst	  values_printed = 1;
1578130803Smarcel	  fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
157919370Spst	  fputs_filtered (" = ", stream);
158019370Spst
158119370Spst	  /* We have to look up the symbol because arguments can have
158219370Spst	     two entries (one a parameter, one a local) and the one we
158319370Spst	     want is the local, which lookup_symbol will find for us.
158419370Spst	     This includes gcc1 (not gcc2) on the sparc when passing a
158519370Spst	     small structure and gcc2 when the argument type is float
158619370Spst	     and it is passed as a double and converted to float by
158719370Spst	     the prologue (in the latter case the type of the LOC_ARG
158819370Spst	     symbol is double and the type of the LOC_LOCAL symbol is
158919370Spst	     float).  There are also LOC_ARG/LOC_REGISTER pairs which
159019370Spst	     are not combined in symbol-reading.  */
159119370Spst
1592130803Smarcel	  sym2 = lookup_symbol (DEPRECATED_SYMBOL_NAME (sym),
1593130803Smarcel		   b, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL);
159419370Spst	  print_variable_value (sym2, fi, stream);
159519370Spst	  fprintf_filtered (stream, "\n");
159619370Spst	  break;
159719370Spst
159819370Spst	default:
159919370Spst	  /* Don't worry about things which aren't arguments.  */
160019370Spst	  break;
160119370Spst	}
160219370Spst    }
160319370Spst  if (!values_printed)
160419370Spst    {
160519370Spst      fprintf_filtered (stream, "No arguments.\n");
160619370Spst    }
160719370Spst}
160819370Spst
160946283Sdfrvoid
161098944Sobrienargs_info (char *ignore, int from_tty)
161119370Spst{
1612130803Smarcel  if (!deprecated_selected_frame)
161319370Spst    error ("No frame selected.");
1614130803Smarcel  print_frame_arg_vars (deprecated_selected_frame, gdb_stdout);
161519370Spst}
161646283Sdfr
161746283Sdfr
161846283Sdfrstatic void
161998944Sobrienargs_plus_locals_info (char *ignore, int from_tty)
162046283Sdfr{
162198944Sobrien  args_info (ignore, from_tty);
162298944Sobrien  locals_info (ignore, from_tty);
162346283Sdfr}
162498944Sobrien
162546283Sdfr
1626130803Smarcel/* Select frame FI.  Also print the stack frame and show the source if
1627130803Smarcel   this is the tui version.  */
1628130803Smarcelstatic void
1629130803Smarcelselect_and_print_frame (struct frame_info *fi)
163019370Spst{
1631130803Smarcel  select_frame (fi);
163219370Spst  if (fi)
163398944Sobrien    {
1634130803Smarcel      print_stack_frame (fi, frame_relative_level (fi), 1);
163519370Spst    }
163619370Spst}
163798944Sobrien
1638130803Smarcel/* Return the symbol-block in which the selected frame is executing.
1639130803Smarcel   Can return zero under various legitimate circumstances.
164019370Spst
1641130803Smarcel   If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1642130803Smarcel   code address within the block returned.  We use this to decide
1643130803Smarcel   which macros are in scope.  */
164446283Sdfr
164519370Spststruct block *
1646130803Smarcelget_selected_block (CORE_ADDR *addr_in_block)
164719370Spst{
164819370Spst  if (!target_has_stack)
164919370Spst    return 0;
165019370Spst
1651130803Smarcel  /* NOTE: cagney/2002-11-28: Why go to all this effort to not create
1652130803Smarcel     a selected/current frame?  Perhaphs this function is called,
1653130803Smarcel     indirectly, by WFI in "infrun.c" where avoiding the creation of
1654130803Smarcel     an inner most frame is very important (it slows down single
1655130803Smarcel     step).  I suspect, though that this was true in the deep dark
1656130803Smarcel     past but is no longer the case.  A mindless look at all the
1657130803Smarcel     callers tends to support this theory.  I think we should be able
1658130803Smarcel     to assume that there is always a selcted frame.  */
1659130803Smarcel  /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel
1660130803Smarcel     lucky? */
1661130803Smarcel  if (!deprecated_selected_frame)
1662130803Smarcel    {
1663130803Smarcel      CORE_ADDR pc = read_pc ();
1664130803Smarcel      if (addr_in_block != NULL)
1665130803Smarcel	*addr_in_block = pc;
1666130803Smarcel      return block_for_pc (pc);
1667130803Smarcel    }
1668130803Smarcel  return get_frame_block (deprecated_selected_frame, addr_in_block);
166919370Spst}
167019370Spst
167119370Spst/* Find a frame a certain number of levels away from FRAME.
167219370Spst   LEVEL_OFFSET_PTR points to an int containing the number of levels.
167319370Spst   Positive means go to earlier frames (up); negative, the reverse.
167419370Spst   The int that contains the number of levels is counted toward
167519370Spst   zero as the frames for those levels are found.
167619370Spst   If the top or bottom frame is reached, that frame is returned,
167719370Spst   but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
167819370Spst   how much farther the original request asked to go.  */
167919370Spst
168019370Spststruct frame_info *
1681130803Smarcelfind_relative_frame (struct frame_info *frame,
1682130803Smarcel		     int *level_offset_ptr)
168319370Spst{
1684130803Smarcel  struct frame_info *prev;
1685130803Smarcel  struct frame_info *frame1;
168619370Spst
168719370Spst  /* Going up is simple: just do get_prev_frame enough times
168819370Spst     or until initial frame is reached.  */
168919370Spst  while (*level_offset_ptr > 0)
169019370Spst    {
169119370Spst      prev = get_prev_frame (frame);
169219370Spst      if (prev == 0)
169319370Spst	break;
169419370Spst      (*level_offset_ptr)--;
169519370Spst      frame = prev;
169619370Spst    }
169719370Spst  /* Going down is just as simple.  */
169819370Spst  if (*level_offset_ptr < 0)
169919370Spst    {
170098944Sobrien      while (*level_offset_ptr < 0)
170198944Sobrien	{
170298944Sobrien	  frame1 = get_next_frame (frame);
170398944Sobrien	  if (!frame1)
170498944Sobrien	    break;
170598944Sobrien	  frame = frame1;
170698944Sobrien	  (*level_offset_ptr)++;
170798944Sobrien	}
170819370Spst    }
170919370Spst  return frame;
171019370Spst}
171119370Spst
171219370Spst/* The "select_frame" command.  With no arg, NOP.
171319370Spst   With arg LEVEL_EXP, select the frame at level LEVEL if it is a
171419370Spst   valid level.  Otherwise, treat level_exp as an address expression
171519370Spst   and select it.  See parse_frame_specification for more info on proper
171619370Spst   frame expressions. */
171719370Spst
171898944Sobrienvoid
171998944Sobrienselect_frame_command (char *level_exp, int from_tty)
172019370Spst{
1721130803Smarcel  struct frame_info *frame;
1722130803Smarcel  int level = frame_relative_level (deprecated_selected_frame);
172319370Spst
172419370Spst  if (!target_has_stack)
172519370Spst    error ("No stack.");
172619370Spst
172719370Spst  frame = parse_frame_specification (level_exp);
172819370Spst
1729130803Smarcel  select_frame (frame);
1730130803Smarcel  if (level != frame_relative_level (deprecated_selected_frame))
1731130803Smarcel    selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame));
173219370Spst}
173319370Spst
173419370Spst/* The "frame" command.  With no arg, print selected frame briefly.
173519370Spst   With arg, behaves like select_frame and then prints the selected
173619370Spst   frame.  */
173719370Spst
173846283Sdfrvoid
173998944Sobrienframe_command (char *level_exp, int from_tty)
174019370Spst{
174119370Spst  select_frame_command (level_exp, from_tty);
1742130803Smarcel  print_stack_frame (deprecated_selected_frame,
1743130803Smarcel		     frame_relative_level (deprecated_selected_frame), 1);
174419370Spst}
174519370Spst
174646283Sdfr/* The XDB Compatibility command to print the current frame. */
174746283Sdfr
174898944Sobrienstatic void
174998944Sobriencurrent_frame_command (char *level_exp, int from_tty)
175046283Sdfr{
1751130803Smarcel  if (target_has_stack == 0 || deprecated_selected_frame == 0)
175298944Sobrien    error ("No stack.");
1753130803Smarcel  print_stack_frame (deprecated_selected_frame,
1754130803Smarcel			  frame_relative_level (deprecated_selected_frame), 1);
175598944Sobrien}
175646283Sdfr
175719370Spst/* Select the frame up one or COUNT stack levels
175819370Spst   from the previously selected frame, and print it briefly.  */
175919370Spst
176019370Spststatic void
176198944Sobrienup_silently_base (char *count_exp)
176219370Spst{
1763130803Smarcel  struct frame_info *fi;
176419370Spst  int count = 1, count1;
176519370Spst  if (count_exp)
176698944Sobrien    count = parse_and_eval_long (count_exp);
176719370Spst  count1 = count;
176898944Sobrien
1769130803Smarcel  if (target_has_stack == 0 || deprecated_selected_frame == 0)
177019370Spst    error ("No stack.");
177119370Spst
1772130803Smarcel  fi = find_relative_frame (deprecated_selected_frame, &count1);
177319370Spst  if (count1 != 0 && count_exp == 0)
177419370Spst    error ("Initial frame selected; you cannot go up.");
1775130803Smarcel  select_frame (fi);
1776130803Smarcel  selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame));
177719370Spst}
177819370Spst
177919370Spststatic void
178098944Sobrienup_silently_command (char *count_exp, int from_tty)
178146283Sdfr{
178298944Sobrien  up_silently_base (count_exp);
178346283Sdfr}
178446283Sdfr
178546283Sdfrstatic void
178698944Sobrienup_command (char *count_exp, int from_tty)
178719370Spst{
178846283Sdfr  up_silently_base (count_exp);
1789130803Smarcel  print_stack_frame (deprecated_selected_frame,
1790130803Smarcel		     frame_relative_level (deprecated_selected_frame), 1);
179119370Spst}
179219370Spst
179319370Spst/* Select the frame down one or COUNT stack levels
179419370Spst   from the previously selected frame, and print it briefly.  */
179519370Spst
179619370Spststatic void
179798944Sobriendown_silently_base (char *count_exp)
179819370Spst{
1799130803Smarcel  struct frame_info *frame;
180019370Spst  int count = -1, count1;
180119370Spst  if (count_exp)
180298944Sobrien    count = -parse_and_eval_long (count_exp);
180319370Spst  count1 = count;
180498944Sobrien
1805130803Smarcel  if (target_has_stack == 0 || deprecated_selected_frame == 0)
180619370Spst    error ("No stack.");
180719370Spst
1808130803Smarcel  frame = find_relative_frame (deprecated_selected_frame, &count1);
180919370Spst  if (count1 != 0 && count_exp == 0)
181019370Spst    {
181119370Spst
181219370Spst      /* We only do this if count_exp is not specified.  That way "down"
181398944Sobrien         means to really go down (and let me know if that is
181498944Sobrien         impossible), but "down 9999" can be used to mean go all the way
181598944Sobrien         down without getting an error.  */
181619370Spst
181719370Spst      error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
181819370Spst    }
181919370Spst
1820130803Smarcel  select_frame (frame);
1821130803Smarcel  selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame));
182219370Spst}
182319370Spst
182446283Sdfrstatic void
182598944Sobriendown_silently_command (char *count_exp, int from_tty)
182646283Sdfr{
182746283Sdfr  down_silently_base (count_exp);
182846283Sdfr}
182919370Spst
183019370Spststatic void
183198944Sobriendown_command (char *count_exp, int from_tty)
183219370Spst{
183346283Sdfr  down_silently_base (count_exp);
1834130803Smarcel  print_stack_frame (deprecated_selected_frame,
1835130803Smarcel		     frame_relative_level (deprecated_selected_frame), 1);
183619370Spst}
183719370Spst
183898944Sobrienvoid
183998944Sobrienreturn_command (char *retval_exp, int from_tty)
184019370Spst{
184119370Spst  struct symbol *thisfun;
184298944Sobrien  struct value *return_value = NULL;
1843130803Smarcel  const char *query_prefix = "";
184419370Spst
1845130803Smarcel  /* FIXME: cagney/2003-10-20: Perform a minimal existance test on the
1846130803Smarcel     target.  If that fails, error out.  For the moment don't rely on
1847130803Smarcel     get_selected_frame as it's error message is the the singularly
1848130803Smarcel     obscure "No registers".  */
1849130803Smarcel  if (!target_has_registers)
185019370Spst    error ("No selected frame.");
1851130803Smarcel  thisfun = get_frame_function (get_selected_frame ());
185219370Spst
1853130803Smarcel  /* Compute the return value.  If the computation triggers an error,
1854130803Smarcel     let it bail.  If the return type can't be handled, set
1855130803Smarcel     RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
1856130803Smarcel     message.  */
185719370Spst  if (retval_exp)
185819370Spst    {
185919370Spst      struct type *return_type = NULL;
186019370Spst
1861130803Smarcel      /* Compute the return value.  Should the computation fail, this
1862130803Smarcel         call throws an error.  */
186319370Spst      return_value = parse_and_eval (retval_exp);
186419370Spst
1865130803Smarcel      /* Cast return value to the return type of the function.  Should
1866130803Smarcel         the cast fail, this call throws an error.  */
186719370Spst      if (thisfun != NULL)
186819370Spst	return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
186919370Spst      if (return_type == NULL)
187019370Spst	return_type = builtin_type_int;
187119370Spst      return_value = value_cast (return_type, return_value);
187219370Spst
1873130803Smarcel      /* Make sure the value is fully evaluated.  It may live in the
1874130803Smarcel         stack frame we're about to pop.  */
187519370Spst      if (VALUE_LAZY (return_value))
187619370Spst	value_fetch_lazy (return_value);
1877130803Smarcel
1878130803Smarcel      if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
1879130803Smarcel	/* If the return-type is "void", don't try to find the
1880130803Smarcel           return-value's location.  However, do still evaluate the
1881130803Smarcel           return expression so that, even when the expression result
1882130803Smarcel           is discarded, side effects such as "return i++" still
1883130803Smarcel           occure.  */
1884130803Smarcel	return_value = NULL;
1885130803Smarcel      /* FIXME: cagney/2004-01-17: If the architecture implements both
1886130803Smarcel         return_value and extract_returned_value_address, should allow
1887130803Smarcel         "return" to work - don't set return_value to NULL.  */
1888130803Smarcel      else if (!gdbarch_return_value_p (current_gdbarch)
1889130803Smarcel	       && (TYPE_CODE (return_type) == TYPE_CODE_STRUCT
1890130803Smarcel		   || TYPE_CODE (return_type) == TYPE_CODE_UNION))
1891130803Smarcel	{
1892130803Smarcel	  /* NOTE: cagney/2003-10-20: Compatibility hack for legacy
1893130803Smarcel	     code.  Old architectures don't expect STORE_RETURN_VALUE
1894130803Smarcel	     to be called with with a small struct that needs to be
1895130803Smarcel	     stored in registers.  Don't start doing it now.  */
1896130803Smarcel	  query_prefix = "\
1897130803SmarcelA structure or union return type is not supported by this architecture.\n\
1898130803SmarcelIf you continue, the return value that you specified will be ignored.\n";
1899130803Smarcel	  return_value = NULL;
1900130803Smarcel	}
1901130803Smarcel      else if (using_struct_return (return_type, 0))
1902130803Smarcel	{
1903130803Smarcel	  query_prefix = "\
1904130803SmarcelThe location at which to store the function's return value is unknown.\n\
1905130803SmarcelIf you continue, the return value that you specified will be ignored.\n";
1906130803Smarcel	  return_value = NULL;
1907130803Smarcel	}
190819370Spst    }
190919370Spst
1910130803Smarcel  /* Does an interactive user really want to do this?  Include
1911130803Smarcel     information, such as how well GDB can handle the return value, in
1912130803Smarcel     the query message.  */
191319370Spst  if (from_tty)
191419370Spst    {
1915130803Smarcel      int confirmed;
1916130803Smarcel      if (thisfun == NULL)
1917130803Smarcel	confirmed = query ("%sMake selected stack frame return now? ",
1918130803Smarcel			   query_prefix);
1919130803Smarcel      else
1920130803Smarcel	confirmed = query ("%sMake %s return now? ", query_prefix,
1921130803Smarcel			   SYMBOL_PRINT_NAME (thisfun));
1922130803Smarcel      if (!confirmed)
1923130803Smarcel	error ("Not confirmed");
192419370Spst    }
192519370Spst
1926130803Smarcel  /* NOTE: cagney/2003-01-18: Is this silly?  Rather than pop each
1927130803Smarcel     frame in turn, should this code just go straight to the relevant
1928130803Smarcel     frame and pop that?  */
192919370Spst
1930130803Smarcel  /* First discard all frames inner-to the selected frame (making the
1931130803Smarcel     selected frame current).  */
1932130803Smarcel  {
1933130803Smarcel    struct frame_id selected_id = get_frame_id (get_selected_frame ());
1934130803Smarcel    while (!frame_id_eq (selected_id, get_frame_id (get_current_frame ())))
1935130803Smarcel      {
1936130803Smarcel	if (frame_id_inner (selected_id, get_frame_id (get_current_frame ())))
1937130803Smarcel	  /* Caught in the safety net, oops!  We've gone way past the
1938130803Smarcel             selected frame.  */
1939130803Smarcel	  error ("Problem while popping stack frames (corrupt stack?)");
1940130803Smarcel	frame_pop (get_current_frame ());
1941130803Smarcel      }
1942130803Smarcel  }
194319370Spst
1944130803Smarcel  /* Second discard the selected frame (which is now also the current
1945130803Smarcel     frame).  */
1946130803Smarcel  frame_pop (get_current_frame ());
194719370Spst
1948130803Smarcel  /* Store RETURN_VAUE in the just-returned register set.  */
1949130803Smarcel  if (return_value != NULL)
1950130803Smarcel    {
1951130803Smarcel      struct type *return_type = VALUE_TYPE (return_value);
1952130803Smarcel      if (!gdbarch_return_value_p (current_gdbarch))
1953130803Smarcel	{
1954130803Smarcel	  STORE_RETURN_VALUE (return_type, current_regcache,
1955130803Smarcel			      VALUE_CONTENTS (return_value));
1956130803Smarcel	}
1957130803Smarcel      /* FIXME: cagney/2004-01-17: If extract_returned_value_address
1958130803Smarcel         is available and the function is using
1959130803Smarcel         RETURN_VALUE_STRUCT_CONVENTION, should use it to find the
1960130803Smarcel         address of the returned value so that it can be assigned.  */
1961130803Smarcel      else
1962130803Smarcel	{
1963130803Smarcel	  gdb_assert (gdbarch_return_value (current_gdbarch, return_type,
1964130803Smarcel					    NULL, NULL, NULL)
1965130803Smarcel		      == RETURN_VALUE_REGISTER_CONVENTION);
1966130803Smarcel	  gdbarch_return_value (current_gdbarch, return_type,
1967130803Smarcel				current_regcache, NULL /*read*/,
1968130803Smarcel				VALUE_CONTENTS (return_value) /*write*/);
1969130803Smarcel	}
1970130803Smarcel    }
197119370Spst
1972130803Smarcel  /* If we are at the end of a call dummy now, pop the dummy frame
1973130803Smarcel     too.  */
1974130803Smarcel  /* NOTE: cagney/2003-01-18: Is this silly?  Instead of popping all
1975130803Smarcel     the frames in sequence, should this code just pop the dummy frame
1976130803Smarcel     directly?  */
1977130803Smarcel#ifdef DEPRECATED_CALL_DUMMY_HAS_COMPLETED
1978130803Smarcel  /* Since all up-to-date architectures return direct to the dummy
1979130803Smarcel     breakpoint address, a dummy frame has, by definition, always
1980130803Smarcel     completed.  Hence this method is no longer needed.  */
1981130803Smarcel  if (DEPRECATED_CALL_DUMMY_HAS_COMPLETED (read_pc(), read_sp (),
1982130803Smarcel					   get_frame_base (get_current_frame ())))
1983130803Smarcel    frame_pop (get_current_frame ());
1984130803Smarcel#else
1985130803Smarcel  if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
1986130803Smarcel    frame_pop (get_current_frame ());
1987130803Smarcel#endif
198819370Spst
198919370Spst  /* If interactive, print the frame that is now current.  */
199019370Spst  if (from_tty)
199119370Spst    frame_command ("0", 1);
199219370Spst  else
199319370Spst    select_frame_command ("0", 0);
199419370Spst}
199519370Spst
199646283Sdfr/* Sets the scope to input function name, provided that the
199746283Sdfr   function is within the current stack frame */
199846283Sdfr
199946283Sdfrstruct function_bounds
200046283Sdfr{
200146283Sdfr  CORE_ADDR low, high;
200246283Sdfr};
200346283Sdfr
200498944Sobrienstatic void func_command (char *arg, int from_tty);
200546283Sdfrstatic void
200698944Sobrienfunc_command (char *arg, int from_tty)
200746283Sdfr{
200846283Sdfr  struct frame_info *fp;
200946283Sdfr  int found = 0;
201046283Sdfr  struct symtabs_and_lines sals;
201146283Sdfr  int i;
201246283Sdfr  int level = 1;
201346283Sdfr  struct function_bounds *func_bounds = (struct function_bounds *) NULL;
201446283Sdfr
201546283Sdfr  if (arg != (char *) NULL)
201646283Sdfr    return;
201746283Sdfr
201846283Sdfr  fp = parse_frame_specification ("0");
201946283Sdfr  sals = decode_line_spec (arg, 1);
202046283Sdfr  func_bounds = (struct function_bounds *) xmalloc (
202146283Sdfr			      sizeof (struct function_bounds) * sals.nelts);
202246283Sdfr  for (i = 0; (i < sals.nelts && !found); i++)
202346283Sdfr    {
202446283Sdfr      if (sals.sals[i].pc == (CORE_ADDR) 0 ||
202546283Sdfr	  find_pc_partial_function (sals.sals[i].pc,
202646283Sdfr				    (char **) NULL,
202746283Sdfr				    &func_bounds[i].low,
202846283Sdfr				    &func_bounds[i].high) == 0)
202946283Sdfr	{
203046283Sdfr	  func_bounds[i].low =
203146283Sdfr	    func_bounds[i].high = (CORE_ADDR) NULL;
203246283Sdfr	}
203346283Sdfr    }
203446283Sdfr
203546283Sdfr  do
203646283Sdfr    {
203746283Sdfr      for (i = 0; (i < sals.nelts && !found); i++)
2038130803Smarcel	found = (get_frame_pc (fp) >= func_bounds[i].low &&
2039130803Smarcel		 get_frame_pc (fp) < func_bounds[i].high);
204046283Sdfr      if (!found)
204146283Sdfr	{
204246283Sdfr	  level = 1;
204346283Sdfr	  fp = find_relative_frame (fp, &level);
204446283Sdfr	}
204546283Sdfr    }
204646283Sdfr  while (!found && level == 0);
204746283Sdfr
204846283Sdfr  if (func_bounds)
204998944Sobrien    xfree (func_bounds);
205046283Sdfr
205146283Sdfr  if (!found)
205246283Sdfr    printf_filtered ("'%s' not within current stack frame.\n", arg);
2053130803Smarcel  else if (fp != deprecated_selected_frame)
2054130803Smarcel    select_and_print_frame (fp);
205546283Sdfr}
205646283Sdfr
205719370Spst/* Gets the language of the current frame.  */
205819370Spst
205919370Spstenum language
206098944Sobrienget_frame_language (void)
206119370Spst{
2062130803Smarcel  struct symtab *s;
206319370Spst  enum language flang;		/* The language of the current frame */
206498944Sobrien
2065130803Smarcel  if (deprecated_selected_frame)
206619370Spst    {
2067130803Smarcel      /* We determine the current frame language by looking up its
2068130803Smarcel         associated symtab.  To retrieve this symtab, we use the frame PC.
2069130803Smarcel         However we cannot use the frame pc as is, because it usually points
2070130803Smarcel         to the instruction following the "call", which is sometimes the first
2071130803Smarcel         instruction of another function.  So we rely on
2072130803Smarcel         get_frame_address_in_block(), it provides us with a PC which is
2073130803Smarcel         guaranteed to be inside the frame's code block.  */
2074130803Smarcel      s = find_pc_symtab (get_frame_address_in_block (deprecated_selected_frame));
207519370Spst      if (s)
207619370Spst	flang = s->language;
207719370Spst      else
207819370Spst	flang = language_unknown;
207919370Spst    }
208019370Spst  else
208119370Spst    flang = language_unknown;
208219370Spst
208319370Spst  return flang;
208419370Spst}
208519370Spst
208619370Spstvoid
208798944Sobrien_initialize_stack (void)
208819370Spst{
208998944Sobrien#if 0
209019370Spst  backtrace_limit = 30;
209119370Spst#endif
209219370Spst
209319370Spst  add_com ("return", class_stack, return_command,
209419370Spst	   "Make selected stack frame return to its caller.\n\
209519370SpstControl remains in the debugger, but when you continue\n\
209619370Spstexecution will resume in the frame above the one now selected.\n\
209719370SpstIf an argument is given, it is an expression for the value to return.");
209819370Spst
209919370Spst  add_com ("up", class_stack, up_command,
210019370Spst	   "Select and print stack frame that called this one.\n\
210119370SpstAn argument says how many frames up to go.");
210219370Spst  add_com ("up-silently", class_support, up_silently_command,
210319370Spst	   "Same as the `up' command, but does not print anything.\n\
210419370SpstThis is useful in command scripts.");
210519370Spst
210619370Spst  add_com ("down", class_stack, down_command,
210719370Spst	   "Select and print stack frame called by this one.\n\
210819370SpstAn argument says how many frames down to go.");
210919370Spst  add_com_alias ("do", "down", class_stack, 1);
211019370Spst  add_com_alias ("dow", "down", class_stack, 1);
211119370Spst  add_com ("down-silently", class_support, down_silently_command,
211219370Spst	   "Same as the `down' command, but does not print anything.\n\
211319370SpstThis is useful in command scripts.");
211419370Spst
211519370Spst  add_com ("frame", class_stack, frame_command,
211619370Spst	   "Select and print a stack frame.\n\
211719370SpstWith no argument, print the selected stack frame.  (See also \"info frame\").\n\
211819370SpstAn argument specifies the frame to select.\n\
211919370SpstIt can be a stack frame number or the address of the frame.\n\
212019370SpstWith argument, nothing is printed if input is coming from\n\
212119370Spsta command file or a user-defined command.");
212219370Spst
212319370Spst  add_com_alias ("f", "frame", class_stack, 1);
212419370Spst
212546283Sdfr  if (xdb_commands)
212646283Sdfr    {
212798944Sobrien      add_com ("L", class_stack, current_frame_command,
212898944Sobrien	       "Print the current stack frame.\n");
212946283Sdfr      add_com_alias ("V", "frame", class_stack, 1);
213046283Sdfr    }
213119370Spst  add_com ("select-frame", class_stack, select_frame_command,
213219370Spst	   "Select a stack frame without printing anything.\n\
213319370SpstAn argument specifies the frame to select.\n\
213419370SpstIt can be a stack frame number or the address of the frame.\n");
213519370Spst
213619370Spst  add_com ("backtrace", class_stack, backtrace_command,
213719370Spst	   "Print backtrace of all stack frames, or innermost COUNT frames.\n\
213846283SdfrWith a negative argument, print outermost -COUNT frames.\n\
213946283SdfrUse of the 'full' qualifier also prints the values of the local variables.\n");
214019370Spst  add_com_alias ("bt", "backtrace", class_stack, 0);
214146283Sdfr  if (xdb_commands)
214246283Sdfr    {
214346283Sdfr      add_com_alias ("t", "backtrace", class_stack, 0);
214446283Sdfr      add_com ("T", class_stack, backtrace_full_command,
214598944Sobrien	       "Print backtrace of all stack frames, or innermost COUNT frames \n\
214646283Sdfrand the values of the local variables.\n\
214746283SdfrWith a negative argument, print outermost -COUNT frames.\n\
214846283SdfrUsage: T <count>\n");
214946283Sdfr    }
215046283Sdfr
215119370Spst  add_com_alias ("where", "backtrace", class_alias, 0);
215219370Spst  add_info ("stack", backtrace_command,
215319370Spst	    "Backtrace of the stack, or innermost COUNT frames.");
215419370Spst  add_info_alias ("s", "stack", 1);
215519370Spst  add_info ("frame", frame_info,
215619370Spst	    "All about selected stack frame, or frame at ADDR.");
215719370Spst  add_info_alias ("f", "frame", 1);
215819370Spst  add_info ("locals", locals_info,
215919370Spst	    "Local variables of current stack frame.");
216019370Spst  add_info ("args", args_info,
216119370Spst	    "Argument variables of current stack frame.");
216246283Sdfr  if (xdb_commands)
216398944Sobrien    add_com ("l", class_info, args_plus_locals_info,
216498944Sobrien	     "Argument and local variables of current stack frame.");
216546283Sdfr
216646283Sdfr  if (dbx_commands)
216798944Sobrien    add_com ("func", class_stack, func_command,
216898944Sobrien      "Select the stack frame that contains <func>.\nUsage: func <name>\n");
216946283Sdfr
217019370Spst  add_info ("catch", catch_info,
217119370Spst	    "Exceptions that can be caught in the current stack frame.");
217219370Spst
217319370Spst#if 0
217498944Sobrien  add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
217598944Sobrien  "Specify maximum number of frames for \"backtrace\" to print by default.",
217619370Spst	   &setlist);
217719370Spst  add_info ("backtrace-limit", backtrace_limit_info,
217898944Sobrien     "The maximum number of frames for \"backtrace\" to print by default.");
217919370Spst#endif
218019370Spst}
2181