* gdbarch.sh (make_corefile_notes): New architecture callback.
[deliverable/binutils-gdb.git] / gdb / stack.c
index 79c3a433dc38182044d6c0b10915a43c98fc99c0..b15b5fcfa1f139d038d238cd9b6c9581a8a7a8bc 100644 (file)
@@ -1,8 +1,6 @@
 /* Print and select stack frames for GDB, the GNU debugger.
 
-   Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
-   2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1986-2005, 2007-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -47,6 +45,7 @@
 #include "cp-support.h"
 #include "disasm.h"
 #include "inline-frame.h"
+#include "linespec.h"
 
 #include "gdb_assert.h"
 #include <ctype.h>
 
 void (*deprecated_selected_frame_level_changed_hook) (int);
 
-/* The possible choices of "set print frame-arguments, and the value
+/* The possible choices of "set print frame-arguments", and the value
    of this setting.  */
 
 static const char *print_frame_arguments_choices[] =
   {"all", "scalars", "none", NULL};
 static const char *print_frame_arguments = "scalars";
 
+/* The possible choices of "set print entry-values", and the value
+   of this setting.  */
+
+const char print_entry_values_no[] = "no";
+const char print_entry_values_only[] = "only";
+const char print_entry_values_preferred[] = "preferred";
+const char print_entry_values_if_needed[] = "if-needed";
+const char print_entry_values_both[] = "both";
+const char print_entry_values_compact[] = "compact";
+const char print_entry_values_default[] = "default";
+static const char *print_entry_values_choices[] =
+{
+  print_entry_values_no,
+  print_entry_values_only,
+  print_entry_values_preferred,
+  print_entry_values_if_needed,
+  print_entry_values_both,
+  print_entry_values_compact,
+  print_entry_values_default,
+  NULL
+};
+const char *print_entry_values = print_entry_values_default;
+
 /* Prototypes for local functions.  */
 
 static void print_frame_local_vars (struct frame_info *, int,
@@ -73,6 +95,12 @@ static void print_frame (struct frame_info *frame, int print_level,
                         enum print_what print_what,  int print_args,
                         struct symtab_and_line sal);
 
+static void set_last_displayed_sal (int valid,
+                                   struct program_space *pspace,
+                                   CORE_ADDR addr,
+                                   struct symtab *symtab,
+                                   int line);
+
 /* Zero means do things normally; we are interacting directly with the
    user.  One means print the full filename and linenumber when a
    frame is printed, and do so in a format emacs18/emacs19.22 can
@@ -80,28 +108,15 @@ static void print_frame (struct frame_info *frame, int print_level,
    cases and in a slightly different syntax.  */
 
 int annotation_level = 0;
-\f
-
-struct print_stack_frame_args
-{
-  struct frame_info *frame;
-  int print_level;
-  enum print_what print_what;
-  int print_args;
-};
-
-/* Show or print the frame arguments; stub for catch_errors.  */
 
-static int
-print_stack_frame_stub (void *args)
-{
-  struct print_stack_frame_args *p = args;
-  int center = (p->print_what == SRC_LINE || p->print_what == SRC_AND_LOC);
-
-  print_frame_info (p->frame, p->print_level, p->print_what, p->print_args);
-  set_current_sal_from_frame (p->frame, center);
-  return 0;
-}
+/* These variables hold the last symtab and line we displayed to the user.
+ * This is where we insert a breakpoint or a skiplist entry by default.  */
+static int last_displayed_sal_valid = 0;
+static struct program_space *last_displayed_pspace = 0;
+static CORE_ADDR last_displayed_addr = 0;
+static struct symtab *last_displayed_symtab = 0;
+static int last_displayed_line = 0;
+\f
 
 /* Return 1 if we should display the address in addition to the location,
    because we are in the middle of a statement.  */
@@ -137,26 +152,20 @@ void
 print_stack_frame (struct frame_info *frame, int print_level,
                   enum print_what print_what)
 {
-  struct print_stack_frame_args args;
+  volatile struct gdb_exception e;
 
-  args.frame = frame;
-  args.print_level = print_level;
-  args.print_what = print_what;
   /* For mi, alway print location and address.  */
-  args.print_what = ui_out_is_mi_like_p (uiout) ? LOC_AND_ADDRESS : print_what;
-  args.print_args = 1;
+  if (ui_out_is_mi_like_p (current_uiout))
+    print_what = LOC_AND_ADDRESS;
 
-  catch_errors (print_stack_frame_stub, &args, "", RETURN_MASK_ERROR);
-}  
-
-struct print_args_args
-{
-  struct symbol *func;
-  struct frame_info *frame;
-  struct ui_file *stream;
-};
+  TRY_CATCH (e, RETURN_MASK_ERROR)
+    {
+      int center = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
 
-static int print_args_stub (void *args);
+      print_frame_info (frame, print_level, print_what, 1 /* print_args */);
+      set_current_sal_from_frame (frame, center);
+    }
+}
 
 /* Print nameless arguments of frame FRAME on STREAM, where START is
    the offset of the first nameless argument, and NUM is the number of
@@ -189,6 +198,286 @@ print_frame_nameless_args (struct frame_info *frame, long start, int num,
     }
 }
 
+/* Print single argument of inferior function.  ARG must be already
+   read in.
+
+   Errors are printed as if they would be the parameter value.  Use zeroed ARG
+   iff it should not be printed accoring to user settings.  */
+
+static void
+print_frame_arg (const struct frame_arg *arg)
+{
+  struct ui_out *uiout = current_uiout;
+  volatile struct gdb_exception except;
+  struct cleanup *old_chain;
+  struct ui_stream *stb;
+
+  stb = ui_out_stream_new (uiout);
+  old_chain = make_cleanup_ui_out_stream_delete (stb);
+
+  gdb_assert (!arg->val || !arg->error);
+  gdb_assert (arg->entry_kind == print_entry_values_no
+             || arg->entry_kind == print_entry_values_only
+             || (!ui_out_is_mi_like_p (uiout)
+                 && arg->entry_kind == print_entry_values_compact));
+
+  annotate_arg_begin ();
+
+  make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+  fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
+                          SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
+  if (arg->entry_kind == print_entry_values_compact)
+    {
+      /* It is OK to provide invalid MI-like stream as with
+        PRINT_ENTRY_VALUE_COMPACT we never use MI.  */
+      fputs_filtered ("=", stb->stream);
+
+      fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
+                              SYMBOL_LANGUAGE (arg->sym),
+                              DMGL_PARAMS | DMGL_ANSI);
+    }
+  if (arg->entry_kind == print_entry_values_only
+      || arg->entry_kind == print_entry_values_compact)
+    fputs_filtered ("@entry", stb->stream);
+  ui_out_field_stream (uiout, "name", stb);
+  annotate_arg_name_end ();
+  ui_out_text (uiout, "=");
+
+  if (!arg->val && !arg->error)
+    ui_out_text (uiout, "...");
+  else
+    {
+      if (arg->error)
+       except.message = arg->error;
+      else
+       {
+         /* TRY_CATCH has two statements, wrap it in a block.  */
+
+         TRY_CATCH (except, RETURN_MASK_ERROR)
+           {
+             const struct language_defn *language;
+             struct value_print_options opts;
+
+             /* Avoid value_print because it will deref ref parameters.  We
+                just want to print their addresses.  Print ??? for args whose
+                address we do not know.  We pass 2 as "recurse" to val_print
+                because our standard indentation here is 4 spaces, and
+                val_print indents 2 for each recurse.  */ 
+
+             annotate_arg_value (value_type (arg->val));
+
+             /* Use the appropriate language to display our symbol, unless the
+                user forced the language to a specific language.  */
+             if (language_mode == language_mode_auto)
+               language = language_def (SYMBOL_LANGUAGE (arg->sym));
+             else
+               language = current_language;
+
+             get_raw_print_options (&opts);
+             opts.deref_ref = 1;
+
+             /* True in "summary" mode, false otherwise.  */
+             opts.summary = !strcmp (print_frame_arguments, "scalars");
+
+             common_val_print (arg->val, stb->stream, 2, &opts, language);
+           }
+       }
+      if (except.message)
+       fprintf_filtered (stb->stream, _("<error reading variable: %s>"),
+                         except.message);
+    }
+
+  ui_out_field_stream (uiout, "value", stb);
+
+  /* Aleo invoke ui_out_tuple_end.  */
+  do_cleanups (old_chain);
+
+  annotate_arg_end ();
+}
+
+/* Read in inferior function parameter SYM at FRAME into ARGP.  Caller is
+   responsible for xfree of ARGP->ERROR.  This function never throws an
+   exception.  */
+
+void
+read_frame_arg (struct symbol *sym, struct frame_info *frame,
+               struct frame_arg *argp, struct frame_arg *entryargp)
+{
+  struct value *val = NULL, *entryval = NULL;
+  char *val_error = NULL, *entryval_error = NULL;
+  int val_equal = 0;
+  volatile struct gdb_exception except;
+
+  if (print_entry_values != print_entry_values_only
+      && print_entry_values != print_entry_values_preferred)
+    {
+      TRY_CATCH (except, RETURN_MASK_ERROR)
+       {
+         val = read_var_value (sym, frame);
+       }
+      if (!val)
+       {
+         val_error = alloca (strlen (except.message) + 1);
+         strcpy (val_error, except.message);
+       }
+    }
+
+  if (SYMBOL_CLASS (sym) == LOC_COMPUTED
+      && print_entry_values != print_entry_values_no
+      && (print_entry_values != print_entry_values_if_needed
+         || !val || value_optimized_out (val)))
+    {
+      TRY_CATCH (except, RETURN_MASK_ERROR)
+       {
+         const struct symbol_computed_ops *ops;
+
+         ops = SYMBOL_COMPUTED_OPS (sym);
+         entryval = ops->read_variable_at_entry (sym, frame);
+       }
+      if (!entryval)
+       {
+         entryval_error = alloca (strlen (except.message) + 1);
+         strcpy (entryval_error, except.message);
+       }
+
+      if (except.error == NO_ENTRY_VALUE_ERROR
+         || (entryval && value_optimized_out (entryval)))
+       {
+         entryval = NULL;
+         entryval_error = NULL;
+       }
+
+      if (print_entry_values == print_entry_values_compact
+         || print_entry_values == print_entry_values_default)
+       {
+         /* For MI do not try to use print_entry_values_compact for ARGP.  */
+
+         if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
+           {
+             unsigned len = TYPE_LENGTH (value_type (val));
+
+             if (!value_optimized_out (val) && value_lazy (val))
+               value_fetch_lazy (val);
+             if (!value_optimized_out (val) && value_lazy (entryval))
+               value_fetch_lazy (entryval);
+             if (!value_optimized_out (val)
+                 && value_available_contents_eq (val, 0, entryval, 0, len))
+               {
+                 /* Initialize it just to avoid a GCC false warning.  */
+                 struct value *val_deref = NULL, *entryval_deref;
+
+                 /* DW_AT_GNU_call_site_value does match with the current
+                    value.  If it is a reference still try to verify if
+                    dereferenced DW_AT_GNU_call_site_data_value does not
+                    differ.  */
+
+                 TRY_CATCH (except, RETURN_MASK_ERROR)
+                   {
+                     unsigned len_deref;
+
+                     val_deref = coerce_ref (val);
+                     if (value_lazy (val_deref))
+                       value_fetch_lazy (val_deref);
+                     len_deref = TYPE_LENGTH (value_type (val_deref));
+
+                     entryval_deref = coerce_ref (entryval);
+                     if (value_lazy (entryval_deref))
+                       value_fetch_lazy (entryval_deref);
+
+                     /* If the reference addresses match but dereferenced
+                        content does not match print them.  */
+                     if (val != val_deref
+                         && value_available_contents_eq (val_deref, 0,
+                                                         entryval_deref, 0,
+                                                         len_deref))
+                       val_equal = 1;
+                   }
+
+                 /* Value was not a reference; and its content matches.  */
+                 if (val == val_deref)
+                   val_equal = 1;
+                 /* If the dereferenced content could not be fetched do not
+                    display anything.  */
+                 else if (except.error == NO_ENTRY_VALUE_ERROR)
+                   val_equal = 1;
+                 else if (except.message)
+                   {
+                     entryval_error = alloca (strlen (except.message) + 1);
+                     strcpy (entryval_error, except.message);
+                   }
+
+                 if (val_equal)
+                   entryval = NULL;
+               }
+           }
+
+         /* Try to remove possibly duplicate error message for ENTRYARGP even
+            in MI mode.  */
+
+         if (val_error && entryval_error
+             && strcmp (val_error, entryval_error) == 0)
+           {
+             entryval_error = NULL;
+
+             /* Do not se VAL_EQUAL as the same error message may be shown for
+                the entry value even if no entry values are present in the
+                inferior.  */
+           }
+       }
+    }
+
+  if (entryval == NULL)
+    {
+      if (print_entry_values == print_entry_values_preferred)
+       {
+         TRY_CATCH (except, RETURN_MASK_ERROR)
+           {
+             val = read_var_value (sym, frame);
+           }
+         if (!val)
+           {
+             val_error = alloca (strlen (except.message) + 1);
+             strcpy (val_error, except.message);
+           }
+       }
+      if (print_entry_values == print_entry_values_only
+         || print_entry_values == print_entry_values_both
+         || (print_entry_values == print_entry_values_preferred
+             && (!val || value_optimized_out (val))))
+       entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
+    }
+  if ((print_entry_values == print_entry_values_compact
+       || print_entry_values == print_entry_values_if_needed
+       || print_entry_values == print_entry_values_preferred)
+      && (!val || value_optimized_out (val)) && entryval != NULL)
+    {
+      val = NULL;
+      val_error = NULL;
+    }
+
+  argp->sym = sym;
+  argp->val = val;
+  argp->error = val_error ? xstrdup (val_error) : NULL;
+  if (!val && !val_error)
+    argp->entry_kind = print_entry_values_only;
+  else if ((print_entry_values == print_entry_values_compact
+          || print_entry_values == print_entry_values_default) && val_equal)
+    {
+      argp->entry_kind = print_entry_values_compact;
+      gdb_assert (!ui_out_is_mi_like_p (current_uiout));
+    }
+  else
+    argp->entry_kind = print_entry_values_no;
+
+  entryargp->sym = sym;
+  entryargp->val = entryval;
+  entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
+  if (!entryval && !entryval_error)
+    entryargp->entry_kind = print_entry_values_no;
+  else
+    entryargp->entry_kind = print_entry_values_only;
+}
+
 /* Print the arguments of frame FRAME on STREAM, given the function
    FUNC running in that frame (as a symbol), where NUM is the number
    of arguments according to the stack frame (or -1 if the number of
@@ -202,6 +491,7 @@ static void
 print_frame_args (struct symbol *func, struct frame_info *frame,
                  int num, struct ui_file *stream)
 {
+  struct ui_out *uiout = current_uiout;
   int first = 1;
   /* Offset of next stack argument beyond the one we have seen that is
      at the highest offset, or -1 if we haven't come to a stack
@@ -224,10 +514,11 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
       struct block *b = SYMBOL_BLOCK_VALUE (func);
       struct dict_iterator iter;
       struct symbol *sym;
-      struct value *val;
 
       ALL_BLOCK_SYMBOLS (b, iter, sym)
         {
+         struct frame_arg arg, entryarg;
+
          QUIT;
 
          /* Keep track of the highest stack argument offset seen, and
@@ -340,58 +631,34 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
            ui_out_text (uiout, ", ");
          ui_out_wrap_hint (uiout, "    ");
 
-         annotate_arg_begin ();
-
-         list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
-         fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (sym),
-                                  SYMBOL_LANGUAGE (sym),
-                                  DMGL_PARAMS | DMGL_ANSI);
-         ui_out_field_stream (uiout, "name", stb);
-         annotate_arg_name_end ();
-         ui_out_text (uiout, "=");
-
-          if (print_args)
-            {
-             /* Avoid value_print because it will deref ref parameters.
-                We just want to print their addresses.  Print ??? for
-                args whose address we do not know.  We pass 2 as
-                "recurse" to val_print because our standard indentation
-                here is 4 spaces, and val_print indents 2 for each
-                recurse.  */
-             val = read_var_value (sym, frame);
+         if (!print_args)
+           {
+             memset (&arg, 0, sizeof (arg));
+             arg.sym = sym;
+             arg.entry_kind = print_entry_values_no;
+             memset (&entryarg, 0, sizeof (entryarg));
+             entryarg.sym = sym;
+             entryarg.entry_kind = print_entry_values_no;
+           }
+         else
+           read_frame_arg (sym, frame, &arg, &entryarg);
 
-             annotate_arg_value (val == NULL ? NULL : value_type (val));
-
-             if (val)
-               {
-                  const struct language_defn *language;
-                 struct value_print_options opts;
-
-                  /* Use the appropriate language to display our symbol,
-                     unless the user forced the language to a specific
-                     language.  */
-                  if (language_mode == language_mode_auto)
-                    language = language_def (SYMBOL_LANGUAGE (sym));
-                  else
-                    language = current_language;
-
-                 get_raw_print_options (&opts);
-                 opts.deref_ref = 0;
-                 opts.summary = summary;
-                 common_val_print (val, stb->stream, 2, &opts, language);
-                 ui_out_field_stream (uiout, "value", stb);
-               }
-             else
-               ui_out_text (uiout, "???");
-            }
-          else
-            ui_out_text (uiout, "...");
+         if (arg.entry_kind != print_entry_values_only)
+           print_frame_arg (&arg);
 
+         if (entryarg.entry_kind != print_entry_values_no)
+           {
+             if (arg.entry_kind != print_entry_values_only)
+               {
+                 ui_out_text (uiout, ", ");
+                 ui_out_wrap_hint (uiout, "    ");
+               }
 
-         /* Invoke ui_out_tuple_end.  */
-         do_cleanups (list_chain);
+             print_frame_arg (&entryarg);
+           }
 
-         annotate_arg_end ();
+         xfree (arg.error);
+         xfree (entryarg.error);
 
          first = 0;
        }
@@ -415,26 +682,6 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
   do_cleanups (old_chain);
 }
 
-/* Stub for catch_errors.  */
-
-static int
-print_args_stub (void *args)
-{
-  struct print_args_args *p = args;
-  struct gdbarch *gdbarch = get_frame_arch (p->frame);
-  int numargs;
-
-  if (gdbarch_frame_num_args_p (gdbarch))
-    {
-      numargs = gdbarch_frame_num_args (gdbarch, p->frame);
-      gdb_assert (numargs >= 0);
-    }
-  else
-    numargs = -1;
-  print_frame_args (p->func, p->frame, numargs, p->stream);
-  return 0;
-}
-
 /* Set the current source and line to the location given by frame
    FRAME, if possible.  When CENTER is true, adjust so the relevant
    line is in the center of the next 'list'.  */
@@ -472,26 +719,6 @@ show_disassemble_next_line (struct ui_file *file, int from_tty,
                     value);
 }
 
-/* Show assembly codes; stub for catch_errors.  */
-
-struct gdb_disassembly_stub_args
-{
-  struct gdbarch *gdbarch;
-  int how_many;
-  CORE_ADDR low;
-  CORE_ADDR high;
-};
-
-static void
-gdb_disassembly_stub (void *args)
-{
-  struct gdb_disassembly_stub_args *p = args;
-
-  gdb_disassembly (p->gdbarch, uiout, 0,
-                   DISASSEMBLY_RAW_INSN, p->how_many,
-                   p->low, p->high);
-}
-
 /* Use TRY_CATCH to catch the exception from the gdb_disassembly
    because it will be broken by filter sometime.  */
 
@@ -500,24 +727,23 @@ do_gdb_disassembly (struct gdbarch *gdbarch,
                    int how_many, CORE_ADDR low, CORE_ADDR high)
 {
   volatile struct gdb_exception exception;
-  struct gdb_disassembly_stub_args args;
 
-  args.gdbarch = gdbarch;
-  args.how_many = how_many;
-  args.low = low;
-  args.high = high;
-  TRY_CATCH (exception, RETURN_MASK_ALL)
+  TRY_CATCH (exception, RETURN_MASK_ERROR)
     {
-      gdb_disassembly_stub (&args);
+      gdb_disassembly (gdbarch, current_uiout, 0,
+                      DISASSEMBLY_RAW_INSN, how_many,
+                      low, high);
+    }
+  if (exception.reason < 0)
+    {
+      /* If an exception was thrown while doing the disassembly, print
+        the error message, to give the user a clue of what happened.  */
+      exception_print (gdb_stderr, exception);
     }
-  /* If an exception was thrown while doing the disassembly, print
-     the error message, to give the user a clue of what happened.  */
-  if (exception.reason == RETURN_ERROR)
-    exception_print (gdb_stderr, exception);
 }
 
 /* Print information about frame FRAME.  The output is format according
-   to PRINT_LEVEL and PRINT_WHAT and PRINT ARGS.  The meaning of
+   to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS.  The meaning of
    PRINT_WHAT is:
    
    SRC_LINE: Print only source line.
@@ -535,6 +761,7 @@ print_frame_info (struct frame_info *frame, int print_level,
   struct symtab_and_line sal;
   int source_print;
   int location_print;
+  struct ui_out *uiout = current_uiout;
 
   if (get_frame_type (frame) == DUMMY_FRAME
       || get_frame_type (frame) == SIGTRAMP_FRAME
@@ -654,14 +881,120 @@ print_frame_info (struct frame_info *frame, int print_level,
     }
 
   if (print_what != LOCATION)
-    set_default_breakpoint (1, sal.pspace,
-                           get_frame_pc (frame), sal.symtab, sal.line);
+    {
+      CORE_ADDR pc;
+
+      if (get_frame_pc_if_available (frame, &pc))
+       set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
+      else
+       set_last_displayed_sal (0, 0, 0, 0, 0);
+    }
 
   annotate_frame_end ();
 
   gdb_flush (gdb_stdout);
 }
 
+/* Remember the last symtab and line we displayed, which we use e.g.
+ * as the place to put a breakpoint when the `break' command is
+ * invoked with no arguments.  */
+
+static void
+set_last_displayed_sal (int valid, struct program_space *pspace,
+                       CORE_ADDR addr, struct symtab *symtab,
+                       int line)
+{
+  last_displayed_sal_valid = valid;
+  last_displayed_pspace = pspace;
+  last_displayed_addr = addr;
+  last_displayed_symtab = symtab;
+  last_displayed_line = line;
+}
+
+/* Forget the last sal we displayed.  */
+
+void
+clear_last_displayed_sal (void)
+{
+  last_displayed_sal_valid = 0;
+  last_displayed_pspace = 0;
+  last_displayed_addr = 0;
+  last_displayed_symtab = 0;
+  last_displayed_line = 0;
+}
+
+/* Is our record of the last sal we displayed valid?  If not,
+ * the get_last_displayed_* functions will return NULL or 0, as
+ * appropriate.  */
+
+int
+last_displayed_sal_is_valid (void)
+{
+  return last_displayed_sal_valid;
+}
+
+/* Get the pspace of the last sal we displayed, if it's valid.  */
+
+struct program_space *
+get_last_displayed_pspace (void)
+{
+  if (last_displayed_sal_valid)
+    return last_displayed_pspace;
+  return 0;
+}
+
+/* Get the address of the last sal we displayed, if it's valid.  */
+
+CORE_ADDR
+get_last_displayed_addr (void)
+{
+  if (last_displayed_sal_valid)
+    return last_displayed_addr;
+  return 0;
+}
+
+/* Get the symtab of the last sal we displayed, if it's valid.  */
+
+struct symtab*
+get_last_displayed_symtab (void)
+{
+  if (last_displayed_sal_valid)
+    return last_displayed_symtab;
+  return 0;
+}
+
+/* Get the line of the last sal we displayed, if it's valid.  */
+
+int
+get_last_displayed_line (void)
+{
+  if (last_displayed_sal_valid)
+    return last_displayed_line;
+  return 0;
+}
+
+/* Get the last sal we displayed, if it's valid.  */
+
+void
+get_last_displayed_sal (struct symtab_and_line *sal)
+{
+  if (last_displayed_sal_valid)
+    {
+      sal->pspace = last_displayed_pspace;
+      sal->pc = last_displayed_addr;
+      sal->symtab = last_displayed_symtab;
+      sal->line = last_displayed_line;
+    }
+  else
+    {
+      sal->pspace = 0;
+      sal->pc = 0;
+      sal->symtab = 0;
+      sal->line = 0;
+    }
+}
+
+
 /* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
    corresponding to FRAME.  */
 
@@ -740,9 +1073,13 @@ find_frame_funname (struct frame_info *frame, char **funname,
     }
   else
     {
-      struct minimal_symbol *msymbol = 
-       lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
+      struct minimal_symbol *msymbol;
+      CORE_ADDR pc;
 
+      if (!get_frame_address_in_block_if_available (frame, &pc))
+       return;
+
+      msymbol = lookup_minimal_symbol_by_pc (pc);
       if (msymbol != NULL)
        {
          *funname = SYMBOL_PRINT_NAME (msymbol);
@@ -757,12 +1094,17 @@ print_frame (struct frame_info *frame, int print_level,
             struct symtab_and_line sal)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
+  struct ui_out *uiout = current_uiout;
   char *funname = NULL;
   enum language funlang = language_unknown;
   struct ui_stream *stb;
   struct cleanup *old_chain, *list_chain;
   struct value_print_options opts;
   struct symbol *func;
+  CORE_ADDR pc = 0;
+  int pc_p;
+
+  pc_p = get_frame_pc_if_available (frame, &pc);
 
   stb = ui_out_stream_new (uiout);
   old_chain = make_cleanup_ui_out_stream_delete (stb);
@@ -770,7 +1112,7 @@ print_frame (struct frame_info *frame, int print_level,
   find_frame_funname (frame, &funname, &funlang, &func);
 
   annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
-                       gdbarch, get_frame_pc (frame));
+                       gdbarch, pc);
 
   list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
 
@@ -782,11 +1124,15 @@ print_frame (struct frame_info *frame, int print_level,
     }
   get_user_print_options (&opts);
   if (opts.addressprint)
-    if (frame_show_address (frame, sal) || !sal.symtab
+    if (!sal.symtab
+       || frame_show_address (frame, sal)
        || print_what == LOC_AND_ADDRESS)
       {
        annotate_frame_address ();
-       ui_out_field_core_addr (uiout, "addr", gdbarch, get_frame_pc (frame));
+       if (pc_p)
+         ui_out_field_core_addr (uiout, "addr", gdbarch, pc);
+       else
+         ui_out_field_string (uiout, "addr", "<unavailable>");
        annotate_frame_address_end ();
        ui_out_text (uiout, " in ");
       }
@@ -800,14 +1146,24 @@ print_frame (struct frame_info *frame, int print_level,
   ui_out_text (uiout, " (");
   if (print_args)
     {
-      struct print_args_args args;
+      struct gdbarch *gdbarch = get_frame_arch (frame);
+      int numargs;
       struct cleanup *args_list_chain;
+      volatile struct gdb_exception e;
 
-      args.frame = frame;
-      args.func = func;
-      args.stream = gdb_stdout;
+      if (gdbarch_frame_num_args_p (gdbarch))
+       {
+         numargs = gdbarch_frame_num_args (gdbarch, frame);
+         gdb_assert (numargs >= 0);
+       }
+      else
+       numargs = -1;
+    
       args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
-      catch_errors (print_args_stub, &args, "", RETURN_MASK_ERROR);
+      TRY_CATCH (e, RETURN_MASK_ERROR)
+       {
+         print_frame_args (func, frame, numargs, gdb_stdout);
+       }
       /* FIXME: ARGS must be a list.  If one argument is a string it
          will have " that will not be properly escaped.  */
       /* Invoke ui_out_tuple_end.  */
@@ -836,7 +1192,7 @@ print_frame (struct frame_info *frame, int print_level,
       annotate_frame_source_end ();
     }
 
-  if (!funname || (!sal.symtab || !sal.symtab->filename))
+  if (pc_p && (!funname || (!sal.symtab || !sal.symtab->filename)))
     {
 #ifdef PC_SOLIB
       char *lib = PC_SOLIB (get_frame_pc (frame));
@@ -1013,6 +1369,9 @@ frame_info (char *addr_exp, int from_tty)
   int selected_frame_p;
   struct gdbarch *gdbarch;
   struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
+  CORE_ADDR frame_pc;
+  int frame_pc_p;
+  CORE_ADDR caller_pc;
 
   fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
   gdbarch = get_frame_arch (fi);
@@ -1031,11 +1390,10 @@ frame_info (char *addr_exp, int from_tty)
        get_frame_pc().  */
     pc_regname = "pc";
 
+  frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
   find_frame_sal (fi, &sal);
   func = get_frame_function (fi);
-  /* FIXME: cagney/2002-11-28: Why bother?  Won't sal.symtab contain
-     the same value?  */
-  s = find_pc_symtab (get_frame_pc (fi));
+  s = sal.symtab;
   if (func)
     {
       funname = SYMBOL_PRINT_NAME (func);
@@ -1056,11 +1414,11 @@ frame_info (char *addr_exp, int from_tty)
            }
        }
     }
-  else
+  else if (frame_pc_p)
     {
       struct minimal_symbol *msymbol;
 
-      msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi));
+      msymbol = lookup_minimal_symbol_by_pc (frame_pc);
       if (msymbol != NULL)
        {
          funname = SYMBOL_PRINT_NAME (msymbol);
@@ -1081,7 +1439,10 @@ frame_info (char *addr_exp, int from_tty)
   fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
   printf_filtered (":\n");
   printf_filtered (" %s = ", pc_regname);
-  fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
+  if (frame_pc_p)
+    fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
+  else
+    fputs_filtered ("<unavailable>", gdb_stdout);
 
   wrap_here ("   ");
   if (funname)
@@ -1096,7 +1457,10 @@ frame_info (char *addr_exp, int from_tty)
   puts_filtered ("; ");
   wrap_here ("    ");
   printf_filtered ("saved %s ", pc_regname);
-  fputs_filtered (paddress (gdbarch, frame_unwind_caller_pc (fi)), gdb_stdout);
+  if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
+    fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
+  else
+    fputs_filtered ("<unavailable>", gdb_stdout);
   printf_filtered ("\n");
 
   if (calling_frame_info == NULL)
@@ -1108,6 +1472,8 @@ frame_info (char *addr_exp, int from_tty)
        printf_filtered (_(" Outermost frame: %s\n"),
                         frame_stop_reason_string (reason));
     }
+  else if (get_frame_type (fi) == TAILCALL_FRAME)
+    puts_filtered (" tail call frame");
   else if (get_frame_type (fi) == INLINE_FRAME)
     printf_filtered (" inlined into frame %d",
                     frame_relative_level (get_prev_frame (fi)));
@@ -1372,36 +1738,17 @@ backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
       enum unwind_stop_reason reason;
 
       reason = get_frame_unwind_stop_reason (trailing);
-      if (reason > UNWIND_FIRST_ERROR)
+      if (reason >= UNWIND_FIRST_ERROR)
        printf_filtered (_("Backtrace stopped: %s\n"),
                         frame_stop_reason_string (reason));
     }
 }
 
-struct backtrace_command_args
-{
-  char *count_exp;
-  int show_locals;
-  int from_tty;
-};
-
-/* Stub for catch_errors.  */
-
-static int
-backtrace_command_stub (void *data)
-{
-  struct backtrace_command_args *args = data;
-
-  backtrace_command_1 (args->count_exp, args->show_locals, args->from_tty);
-  return 0;
-}
-
 static void
 backtrace_command (char *arg, int from_tty)
 {
-  struct cleanup *old_chain = NULL;
+  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   int fulltrace_arg = -1, arglen = 0, argc = 0;
-  struct backtrace_command_args btargs;
 
   if (arg)
     {
@@ -1409,7 +1756,7 @@ backtrace_command (char *arg, int from_tty)
       int i;
 
       argv = gdb_buildargv (arg);
-      old_chain = make_cleanup_freeargv (argv);
+      make_cleanup_freeargv (argv);
       argc = 0;
       for (i = 0; argv[i]; i++)
        {
@@ -1432,7 +1779,8 @@ backtrace_command (char *arg, int from_tty)
          if (arglen > 0)
            {
              arg = xmalloc (arglen + 1);
-             memset (arg, 0, arglen + 1);
+             make_cleanup (xfree, arg);
+             arg[0] = 0;
              for (i = 0; i < (argc + 1); i++)
                {
                  if (i != fulltrace_arg)
@@ -1447,27 +1795,15 @@ backtrace_command (char *arg, int from_tty)
        }
     }
 
-  btargs.count_exp = arg;
-  btargs.show_locals = (fulltrace_arg >= 0);
-  btargs.from_tty = from_tty;
-  catch_errors (backtrace_command_stub, &btargs, "", RETURN_MASK_ERROR);
-
-  if (fulltrace_arg >= 0 && arglen > 0)
-    xfree (arg);
+  backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty);
 
-  if (old_chain)
-    do_cleanups (old_chain);
+  do_cleanups (old_chain);
 }
 
 static void
 backtrace_full_command (char *arg, int from_tty)
 {
-  struct backtrace_command_args btargs;
-
-  btargs.count_exp = arg;
-  btargs.show_locals = 1;
-  btargs.from_tty = from_tty;
-  catch_errors (backtrace_command_stub, &btargs, "", RETURN_MASK_ERROR);
+  backtrace_command_1 (arg, 1 /* show_locals */, from_tty);
 }
 \f
 
@@ -1603,6 +1939,14 @@ print_frame_local_vars (struct frame_info *frame, int num_tabs,
 {
   struct print_variable_and_value_data cb_data;
   struct block *block;
+  CORE_ADDR pc;
+
+  if (!get_frame_pc_if_available (frame, &pc))
+    {
+      fprintf_filtered (stream,
+                       _("PC unavailable, cannot determine locals.\n"));
+      return;
+    }
 
   block = get_frame_block (frame, 0);
   if (block == 0)
@@ -1755,6 +2099,13 @@ print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
 {
   struct print_variable_and_value_data cb_data;
   struct symbol *func;
+  CORE_ADDR pc;
+
+  if (!get_frame_pc_if_available (frame, &pc))
+    {
+      fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
+      return;
+    }
 
   func = get_frame_function (frame);
   if (func == NULL)
@@ -2092,20 +2443,25 @@ func_command (char *arg, int from_tty)
   int i;
   int level = 1;
   struct function_bounds *func_bounds = NULL;
+  struct cleanup *cleanups;
 
   if (arg != NULL)
     return;
 
   frame = parse_frame_specification ("0");
-  sals = decode_line_spec (arg, 1);
+  sals = decode_line_spec (arg, DECODE_LINE_FUNFIRSTLINE);
+  cleanups = make_cleanup (xfree, sals.sals);
   func_bounds = (struct function_bounds *) xmalloc (
                              sizeof (struct function_bounds) * sals.nelts);
+  make_cleanup (xfree, func_bounds);
   for (i = 0; (i < sals.nelts && !found); i++)
     {
-      if (sals.sals[i].pc == 0
-         || find_pc_partial_function (sals.sals[i].pc, NULL,
-                                      &func_bounds[i].low,
-                                      &func_bounds[i].high) == 0)
+      if (sals.sals[i].pspace != current_program_space)
+       func_bounds[i].low = func_bounds[i].high = 0;
+      else if (sals.sals[i].pc == 0
+              || find_pc_partial_function (sals.sals[i].pc, NULL,
+                                           &func_bounds[i].low,
+                                           &func_bounds[i].high) == 0)
        {
          func_bounds[i].low = func_bounds[i].high = 0;
        }
@@ -2124,8 +2480,7 @@ func_command (char *arg, int from_tty)
     }
   while (!found && level == 0);
 
-  if (func_bounds)
-    xfree (func_bounds);
+  do_cleanups (cleanups);
 
   if (!found)
     printf_filtered (_("'%s' not within current stack frame.\n"), arg);
@@ -2142,6 +2497,10 @@ get_frame_language (void)
 
   if (frame)
     {
+      volatile struct gdb_exception ex;
+      CORE_ADDR pc = 0;
+      struct symtab *s;
+
       /* We determine the current frame language by looking up its
          associated symtab.  To retrieve this symtab, we use the frame
          PC.  However we cannot use the frame PC as is, because it
@@ -2150,11 +2509,22 @@ get_frame_language (void)
          we rely on get_frame_address_in_block(), it provides us with
          a PC that is guaranteed to be inside the frame's code
          block.  */
-      CORE_ADDR pc = get_frame_address_in_block (frame);
-      struct symtab *s = find_pc_symtab (pc);
 
-      if (s)
-       return s->language;
+      TRY_CATCH (ex, RETURN_MASK_ERROR)
+       {
+         pc = get_frame_address_in_block (frame);
+       }
+      if (ex.reason < 0)
+       {
+         if (ex.error != NOT_AVAILABLE_ERROR)
+           throw_exception (ex);
+       }
+      else
+       {
+         s = find_pc_symtab (pc);
+         if (s != NULL)
+           return s->language;
+       }
     }
 
   return language_unknown;
@@ -2273,4 +2643,17 @@ source line."),
                                show_disassemble_next_line,
                                &setlist, &showlist);
   disassemble_next_line = AUTO_BOOLEAN_FALSE;
+
+  add_setshow_enum_cmd ("entry-values", class_stack,
+                       print_entry_values_choices, &print_entry_values,
+                       _("Set printing of function arguments at function "
+                         "entry"),
+                       _("Show printing of function arguments at function "
+                         "entry"),
+                       _("\
+GDB can sometimes determine the values of function arguments at entry,\n\
+in addition to their current values.  This option tells GDB whether\n\
+to print the current value, the value at entry (marked as val@entry),\n\
+or both.  Note that one or both of these values may be <optimized out>."),
+                       NULL, NULL, &setprintlist, &showprintlist);
 }
This page took 0.036143 seconds and 4 git commands to generate.