* gdbarch.sh (make_corefile_notes): New architecture callback.
[deliverable/binutils-gdb.git] / gdb / stack.c
index 953d3bd4a34848dba4cf4272b7e1c1459d9300c4..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>
@@ -96,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
@@ -103,6 +108,14 @@ static void print_frame (struct frame_info *frame, int print_level,
    cases and in a slightly different syntax.  */
 
 int annotation_level = 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,
@@ -872,9 +885,9 @@ print_frame_info (struct frame_info *frame, int print_level,
       CORE_ADDR pc;
 
       if (get_frame_pc_if_available (frame, &pc))
-       set_default_breakpoint (1, sal.pspace, pc, sal.symtab, sal.line);
+       set_last_displayed_sal (1, sal.pspace, pc, sal.symtab, sal.line);
       else
-       set_default_breakpoint (0, 0, 0, 0, 0);
+       set_last_displayed_sal (0, 0, 0, 0, 0);
     }
 
   annotate_frame_end ();
@@ -882,6 +895,106 @@ print_frame_info (struct frame_info *frame, int print_level,
   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.  */
 
@@ -1625,7 +1738,7 @@ 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));
     }
@@ -2330,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;
        }
@@ -2362,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);
This page took 0.026012 seconds and 4 git commands to generate.