gdb/
[deliverable/binutils-gdb.git] / gdb / frame.c
index 650b279819318e70b7d9851baaa39a1beec836da..36fcefe6f7b7b5eff0e3e982855a95e2cffb7652 100644 (file)
@@ -1,7 +1,8 @@
 /* Cache and manage frames for GDB, the GNU debugger.
 
    Copyright (C) 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001,
-   2002, 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -180,8 +181,9 @@ static void
 show_backtrace_past_main (struct ui_file *file, int from_tty,
                          struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Whether backtraces should continue past \"main\" is %s.\n"),
+  fprintf_filtered (file,
+                   _("Whether backtraces should "
+                     "continue past \"main\" is %s.\n"),
                    value);
 }
 
@@ -190,8 +192,8 @@ static void
 show_backtrace_past_entry (struct ui_file *file, int from_tty,
                           struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-Whether backtraces should continue past the entry point of a program is %s.\n"),
+  fprintf_filtered (file, _("Whether backtraces should continue past the "
+                           "entry point of a program is %s.\n"),
                    value);
 }
 
@@ -200,8 +202,9 @@ static void
 show_backtrace_limit (struct ui_file *file, int from_tty,
                      struct cmd_list_element *c, const char *value)
 {
-  fprintf_filtered (file, _("\
-An upper bound on the number of backtrace levels is %s.\n"),
+  fprintf_filtered (file,
+                   _("An upper bound on the number "
+                     "of backtrace levels is %s.\n"),
                    value);
 }
 
@@ -329,7 +332,7 @@ get_frame_id (struct frame_info *fi)
                            fi->level);
       /* Find the unwinder.  */
       if (fi->unwind == NULL)
-       fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
+       frame_unwind_find_by_frame (fi, &fi->prologue_cache);
       /* Find THIS frame's ID.  */
       /* Default to outermost if no ID is found.  */
       fi->this_id.value = outer_frame_id;
@@ -446,7 +449,8 @@ frame_id_eq (struct frame_id l, struct frame_id r)
 {
   int eq;
 
-  if (!l.stack_addr_p && l.special_addr_p && !r.stack_addr_p && r.special_addr_p)
+  if (!l.stack_addr_p && l.special_addr_p
+      && !r.stack_addr_p && r.special_addr_p)
     /* The outermost frame marker is equal to itself.  This is the
        dodgy thing about outer_frame_id, since between execution steps
        we might step into another function - from which we can't
@@ -495,7 +499,7 @@ frame_id_eq (struct frame_id l, struct frame_id r)
    to sigaltstack).
 
    However, it can be used as safety net to discover invalid frame
-   IDs in certain circumstances. Assuming that NEXT is the immediate
+   IDs in certain circumstances.  Assuming that NEXT is the immediate
    inner frame to THIS and that NEXT and THIS are both NORMAL frames:
 
    * The stack address of NEXT must be inner-than-or-equal to the stack
@@ -515,7 +519,7 @@ frame_id_eq (struct frame_id l, struct frame_id r)
    is involved, because signal handlers might be executed on a different
    stack than the stack used by the routine that caused the signal
    to be raised.  This can happen for instance when a thread exceeds
-   its maximum stack size. In this case, certain compilers implement
+   its maximum stack size.  In this case, certain compilers implement
    a stack overflow strategy that cause the handler to be run on a
    different stack.  */
 
@@ -592,6 +596,7 @@ frame_find_by_id (struct frame_id id)
   for (frame = get_current_frame (); ; frame = prev_frame)
     {
       struct frame_id this = get_frame_id (frame);
+
       if (frame_id_eq (id, this))
        /* An exact match.  */
        return frame;
@@ -620,6 +625,7 @@ frame_unwind_pc (struct frame_info *this_frame)
   if (!this_frame->prev_pc.p)
     {
       CORE_ADDR pc;
+
       if (gdbarch_unwind_pc_p (frame_unwind_arch (this_frame)))
        {
          /* The right way.  The `pure' way.  The one true way.  This
@@ -646,7 +652,8 @@ frame_unwind_pc (struct frame_info *this_frame)
       this_frame->prev_pc.p = 1;
       if (frame_debug)
        fprintf_unfiltered (gdb_stdlog,
-                           "{ frame_unwind_caller_pc (this_frame=%d) -> %s }\n",
+                           "{ frame_unwind_caller_pc "
+                           "(this_frame=%d) -> %s }\n",
                            this_frame->level,
                            hex_string (this_frame->prev_pc.value));
     }
@@ -769,7 +776,7 @@ frame_register_unwind (struct frame_info *frame, int regnum,
   *addrp = value_address (value);
   *realnump = VALUE_REGNUM (value);
 
-  if (bufferp)
+  if (bufferp && !*optimizedp)
     memcpy (bufferp, value_contents_all (value),
            TYPE_LENGTH (value_type (value)));
 
@@ -829,15 +836,16 @@ frame_unwind_register_value (struct frame_info *frame, int regnum)
 
   if (frame_debug)
     {
-      fprintf_unfiltered (gdb_stdlog, "\
-{ frame_unwind_register_value (frame=%d,regnum=%d(%s),...) ",
+      fprintf_unfiltered (gdb_stdlog,
+                         "{ frame_unwind_register_value "
+                         "(frame=%d,regnum=%d(%s),...) ",
                          frame->level, regnum,
                          user_reg_map_regnum_to_name (gdbarch, regnum));
     }
 
   /* Find the unwinder.  */
   if (frame->unwind == NULL)
-    frame->unwind = frame_unwind_find_by_frame (frame, &frame->prologue_cache);
+    frame_unwind_find_by_frame (frame, &frame->prologue_cache);
 
   /* Ask this frame to unwind its register.  */
   value = frame->unwind->prev_register (frame, &frame->prologue_cache, regnum);
@@ -942,6 +950,7 @@ put_frame_register (struct frame_info *frame, int regnum,
        /* FIXME: write_memory doesn't yet take constant buffers.
            Arrrg!  */
        gdb_byte tmp[MAX_REGISTER_SIZE];
+
        memcpy (tmp, buf, register_size (gdbarch, regnum));
        write_memory (addr, tmp, register_size (gdbarch, regnum));
        break;
@@ -998,6 +1007,7 @@ get_frame_register_bytes (struct frame_info *frame, int regnum,
   for (i = regnum; i < numregs; i++)
     {
       int thissize = register_size (gdbarch, i);
+
       if (thissize == 0)
        break;  /* This register is not available on this architecture.  */
       maxsize += thissize;
@@ -1013,6 +1023,7 @@ get_frame_register_bytes (struct frame_info *frame, int regnum,
   while (len > 0)
     {
       int curr_len = register_size (gdbarch, regnum) - offset;
+
       if (curr_len > len)
        curr_len = len;
 
@@ -1024,6 +1035,7 @@ get_frame_register_bytes (struct frame_info *frame, int regnum,
       else
        {
          gdb_byte buf[MAX_REGISTER_SIZE];
+
          if (!frame_register_read (frame, regnum, buf))
            return 0;
          memcpy (myaddr, buf + offset, curr_len);
@@ -1055,6 +1067,7 @@ put_frame_register_bytes (struct frame_info *frame, int regnum,
   while (len > 0)
     {
       int curr_len = register_size (gdbarch, regnum) - offset;
+
       if (curr_len > len)
        curr_len = len;
 
@@ -1065,6 +1078,7 @@ put_frame_register_bytes (struct frame_info *frame, int regnum,
       else
        {
          gdb_byte buf[MAX_REGISTER_SIZE];
+
          frame_register_read (frame, regnum, buf);
          memcpy (buf + offset, myaddr, curr_len);
          put_frame_register (frame, regnum, buf);
@@ -1092,7 +1106,7 @@ create_sentinel_frame (struct program_space *pspace, struct regcache *regcache)
      information, such as the frame's thread will be added.  */
   frame->prologue_cache = sentinel_frame_cache (regcache);
   /* For the moment there is only one sentinel frame implementation.  */
-  frame->unwind = sentinel_frame_unwind;
+  frame->unwind = &sentinel_frame_unwind;
   /* Link this frame back to itself.  The frame is self referential
      (the unwound PC is the same as the pc), so make it so.  */
   frame->next = frame;
@@ -1109,7 +1123,7 @@ create_sentinel_frame (struct program_space *pspace, struct regcache *regcache)
   return frame;
 }
 
-/* Info about the innermost stack frame (contents of FP register) */
+/* Info about the innermost stack frame (contents of FP register) */
 
 static struct frame_info *current_frame;
 
@@ -1265,7 +1279,7 @@ select_frame (struct frame_info *fi)
 
      Once we have frame-parameterized frame (and frame-related) commands,
      the event notification can be moved here, since this function will only
-     be called when the user's selected frame is being changed. */
+     be called when the user's selected frame is being changed.  */
 
   /* Ensure that symbols for this frame are read in.  Also, determine the
      source language of this frame, and switch to it if desired.  */
@@ -1305,7 +1319,8 @@ create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
 
   fi = FRAME_OBSTACK_ZALLOC (struct frame_info);
 
-  fi->next = create_sentinel_frame (current_program_space, get_current_regcache ());
+  fi->next = create_sentinel_frame (current_program_space,
+                                   get_current_regcache ());
 
   /* Set/update this frame's cached PC value, found in the next frame.
      Do this before looking for this frame's unwinder.  A sniffer is
@@ -1320,7 +1335,7 @@ create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
 
   /* Select/initialize both the unwind function and the frame's type
      based on the PC.  */
-  fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
+  frame_unwind_find_by_frame (fi, &fi->prologue_cache);
 
   fi->this_id.p = 1;
   fi->this_id.value = frame_id_build (addr, pc);
@@ -1372,7 +1387,7 @@ reinit_frame_cache (void)
        fi->base->unwind->dealloc_cache (fi, fi->base_cache);
     }
 
-  /* Since we can't really be sure what the first object allocated was */
+  /* Since we can't really be sure what the first object allocated was */
   obstack_free (&frame_cache_obstack, 0);
   obstack_init (&frame_cache_obstack);
 
@@ -1455,8 +1470,7 @@ get_prev_frame_1 (struct frame_info *this_frame)
      sniffers will think that this frame's sniffer tried to unwind
      further (see frame_cleanup_after_sniffer).  */
   if (this_frame->unwind == NULL)
-    this_frame->unwind
-      = frame_unwind_find_by_frame (this_frame, &this_frame->prologue_cache);
+    frame_unwind_find_by_frame (this_frame, &this_frame->prologue_cache);
 
   this_frame->prev_p = 1;
   this_frame->stop_reason = UNWIND_NO_REASON;
@@ -1494,14 +1508,27 @@ get_prev_frame_1 (struct frame_info *this_frame)
       && frame_id_inner (get_frame_arch (this_frame->next), this_id,
                         get_frame_id (this_frame->next)))
     {
-      if (frame_debug)
+      CORE_ADDR this_pc_in_block;
+      struct minimal_symbol *morestack_msym;
+      const char *morestack_name = NULL;
+      
+      /* gcc -fsplit-stack __morestack can continue the stack anywhere.  */
+      this_pc_in_block = get_frame_address_in_block (this_frame);
+      morestack_msym = lookup_minimal_symbol_by_pc (this_pc_in_block);
+      if (morestack_msym)
+       morestack_name = SYMBOL_LINKAGE_NAME (morestack_msym);
+      if (!morestack_name || strcmp (morestack_name, "__morestack") != 0)
        {
-         fprintf_unfiltered (gdb_stdlog, "-> ");
-         fprint_frame (gdb_stdlog, NULL);
-         fprintf_unfiltered (gdb_stdlog, " // this frame ID is inner }\n");
+         if (frame_debug)
+           {
+             fprintf_unfiltered (gdb_stdlog, "-> ");
+             fprint_frame (gdb_stdlog, NULL);
+             fprintf_unfiltered (gdb_stdlog,
+                                 " // this frame ID is inner }\n");
+           }
+         this_frame->stop_reason = UNWIND_INNER_ID;
+         return NULL;
        }
-      this_frame->stop_reason = UNWIND_INNER_ID;
-      return NULL;
     }
 
   /* Check that this and the next frame are not identical.  If they
@@ -1953,7 +1980,7 @@ int
 frame_unwinder_is (struct frame_info *fi, const struct frame_unwind *unwinder)
 {
   if (fi->unwind == NULL)
-    fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
+    frame_unwind_find_by_frame (fi, &fi->prologue_cache);
   return fi->unwind == unwinder;
 }
 
@@ -1975,7 +2002,7 @@ get_frame_type (struct frame_info *frame)
   if (frame->unwind == NULL)
     /* Initialize the frame's unwinder because that's what
        provides the frame's type.  */
-    frame->unwind = frame_unwind_find_by_frame (frame, &frame->prologue_cache);
+    frame_unwind_find_by_frame (frame, &frame->prologue_cache);
   return frame->unwind->type;
 }
 
@@ -2055,9 +2082,7 @@ frame_unwind_arch (struct frame_info *next_frame)
       struct gdbarch *arch;
 
       if (next_frame->unwind == NULL)
-       next_frame->unwind
-         = frame_unwind_find_by_frame (next_frame,
-                                       &next_frame->prologue_cache);
+       frame_unwind_find_by_frame (next_frame, &next_frame->prologue_cache);
 
       if (next_frame->unwind->prev_arch != NULL)
        arch = next_frame->unwind->prev_arch (next_frame,
@@ -2244,7 +2269,7 @@ Set whether backtraces should continue past the entry point of a program."),
 Show whether backtraces should continue past the entry point of a program."),
                           _("\
 Normally there are no callers beyond the entry point of a program, so GDB\n\
-will terminate the backtrace there.  Set this variable if you need to see \n\
+will terminate the backtrace there.  Set this variable if you need to see\n\
 the rest of the stack trace."),
                           NULL,
                           show_backtrace_past_entry,
@@ -2262,7 +2287,7 @@ Zero is unlimited."),
                           &set_backtrace_cmdlist,
                           &show_backtrace_cmdlist);
 
-  /* Debug this files internals. */
+  /* Debug this files internals.  */
   add_setshow_zinteger_cmd ("frame", class_maintenance, &frame_debug,  _("\
 Set frame debugging."), _("\
 Show frame debugging."), _("\
This page took 0.028556 seconds and 4 git commands to generate.