* valprint.c (print_longest): Fix a syntax error in #ifdef
[deliverable/binutils-gdb.git] / gdb / blockframe.c
index 0d0e89a8d5f03f9ecb542de2e0077325fec47bdd..8a47bb1bc8e2faf2111807eff9d85942dda4d44b 100644 (file)
@@ -28,6 +28,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "value.h"             /* for read_register */
 #include "target.h"            /* for target_has_stack */
 #include "inferior.h"          /* for read_pc */
+#include "annotate.h"
 
 /* Is ADDR inside the startup file?  Note that if your machine
    has a way to detect the bottom of the stack, there is no need
@@ -117,9 +118,13 @@ struct obstack frame_cache_obstack;
 FRAME
 get_current_frame ()
 {
-  /* We assume its address is kept in a general register;
-     param.h says which register.  */
-
+  if (current_frame == NULL)
+    {
+      if (target_has_stack)
+       current_frame = create_new_frame (read_fp (), read_pc ());
+      else
+       error ("No stack.");
+    }
   return current_frame;
 }
 
@@ -130,6 +135,9 @@ set_current_frame (frame)
   current_frame = frame;
 }
 
+/* Create an arbitrary (i.e. address specified by user) or innermost frame.
+   Always returns a non-NULL value.  */
+
 FRAME
 create_new_frame (addr, pc)
      FRAME_ADDR addr;
@@ -192,14 +200,21 @@ flush_cached_frames ()
   obstack_init (&frame_cache_obstack);
 
   current_frame = (struct frame_info *) 0; /* Invalidate cache */
+  select_frame ((FRAME) 0, -1);
+  annotate_frames_invalid ();
 }
 
 /* Flush the frame cache, and start a new one if necessary.  */
+
 void
 reinit_frame_cache ()
 {
   flush_cached_frames ();
-  if (target_has_stack)
+#if 0
+  /* The inferior_pid test is wrong if there is a corefile.  But I don't
+     think this code is needed at all, now that get_current_frame will
+     create the frame if it is needed.  */
+  if (inferior_pid != 0)
     {
       set_current_frame (create_new_frame (read_fp (), read_pc ()));
       select_frame (get_current_frame (), 0);
@@ -209,6 +224,7 @@ reinit_frame_cache ()
       set_current_frame (0);
       select_frame ((FRAME) 0, -1);
     }
+#endif
 }
 
 /* Return a structure containing various interesting information
@@ -292,10 +308,16 @@ get_prev_frame_info (next_frame)
 
   if (!next_frame)
     {
+#if 0
+      /* This screws value_of_variable, which just wants a nice clean
+        NULL return from block_innermost_frame if there are no frames.
+        I don't think I've ever seen this message happen otherwise.
+        And returning NULL here is a perfectly legitimate thing to do.  */
       if (!current_frame)
        {
          error ("You haven't set up a process's stack to examine.");
        }
+#endif
 
       return current_frame;
     }
@@ -383,13 +405,18 @@ get_prev_frame_info (next_frame)
      Only change here is that create_new_frame would no longer init extra
      frame info; SETUP_ARBITRARY_FRAME would have to do that.
    INIT_PREV_FRAME(fromleaf, prev)
-     Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC.
+     Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC.  This should
+     also return a flag saying whether to keep the new frame, or
+     whether to discard it, because on some machines (e.g.  mips) it
+     is really awkward to have FRAME_CHAIN_VALID called *before*
+     INIT_EXTRA_FRAME_INFO (there is no good way to get information
+     deduced in FRAME_CHAIN_VALID into the extra fields of the new frame).
    std_frame_pc(fromleaf, prev)
      This is the default setting for INIT_PREV_FRAME.  It just does what
      the default INIT_FRAME_PC does.  Some machines will call it from
      INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
      Some machines won't use it.
-   kingdon@cygnus.com, 13Apr93.  */
+   kingdon@cygnus.com, 13Apr93, 31Jan94.  */
 
 #ifdef INIT_FRAME_PC_FIRST
   INIT_FRAME_PC_FIRST (fromleaf, prev);
@@ -400,10 +427,25 @@ get_prev_frame_info (next_frame)
 #endif
 
   /* This entry is in the frame queue now, which is good since
-     FRAME_SAVED_PC may use that queue to figure out it's value
+     FRAME_SAVED_PC may use that queue to figure out its value
      (see tm-sparc.h).  We want the pc saved in the inferior frame. */
   INIT_FRAME_PC(fromleaf, prev);
 
+  /* If ->frame and ->pc are unchanged, we are in the process of getting
+     ourselves into an infinite backtrace.  Some architectures check this
+     in FRAME_CHAIN or thereabouts, but it seems like there is no reason
+     this can't be an architecture-independent check.  */
+  if (next_frame != NULL)
+    {
+      if (prev->frame == next_frame->frame
+         && prev->pc == next_frame->pc)
+       {
+         next_frame->prev = NULL;
+         obstack_free (&frame_cache_obstack, prev);
+         return NULL;
+       }
+    }
+
   find_pc_partial_function (prev->pc, &name,
                            (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
   if (IN_SIGTRAMP (prev->pc, name))
@@ -446,12 +488,13 @@ get_frame_block (frame)
   fi = get_frame_info (frame);
 
   pc = fi->pc;
-  if (fi->next != 0)
-    /* We are not in the innermost frame.  We need to subtract one to
-       get the correct block, in case the call instruction was the
-       last instruction of the block.  If there are any machines on
-       which the saved pc does not point to after the call insn, we
-       probably want to make fi->pc point after the call insn anyway.  */
+  if (fi->next != 0 && fi->next->signal_handler_caller == 0)
+    /* We are not in the innermost frame and we were not interrupted
+       by a signal.  We need to subtract one to get the correct block,
+       in case the call instruction was the last instruction of the block.
+       If there are any machines on which the saved pc does not point to
+       after the call insn, we probably want to make fi->pc point after
+       the call insn anyway.  */
     --pc;
   return block_for_pc (pc);
 }
@@ -648,7 +691,12 @@ find_pc_partial_function (pc, name, address, endaddr)
     {
       /* Need to read the symbols to get a good value for the end address.  */
       if (endaddr != NULL && !pst->readin)
-       PSYMTAB_TO_SYMTAB (pst);
+       {
+         /* Need to get the terminal in case symbol-reading produces
+            output.  */
+         target_terminal_ours_for_output ();
+         PSYMTAB_TO_SYMTAB (pst);
+       }
 
       if (pst->readin)
        {
@@ -714,7 +762,7 @@ find_pc_partial_function (pc, name, address, endaddr)
 
   /* See if we're in a transfer table for Sun shared libs.  */
 
-  if (msymbol -> type == mst_text)
+  if (msymbol -> type == mst_text || msymbol -> type == mst_file_text)
     cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
   else
     /* It is a transfer table for Sun shared libraries.  */
@@ -773,6 +821,29 @@ block_innermost_frame (block)
     }
 }
 
+/* Return the full FRAME which corresponds to the given FRAME_ADDR
+   or NULL if no FRAME on the chain corresponds to FRAME_ADDR.  */
+
+FRAME
+find_frame_addr_in_frame_chain (frame_addr)
+     FRAME_ADDR frame_addr;
+{
+  FRAME frame = NULL;
+
+  if (frame_addr == (CORE_ADDR)0)
+    return NULL;
+
+  while (1)
+    {
+      frame = get_prev_frame (frame);
+      if (frame == NULL)
+       return NULL;
+
+      if (FRAME_FP (frame) == frame_addr)
+       return frame;
+    }
+}
+
 #ifdef SIGCONTEXT_PC_OFFSET
 /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp.  */
 
This page took 0.025435 seconds and 4 git commands to generate.