This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] soften up the old frame code


Hello,

The intent of this patch is to soften the requirements placed on the old frame code. That, the theory goes, should make it easier to migrate. It does the following:

- removes the requirement for DEPRECATED_FRAME_INIT_SAVED_REGS
This lets people delete that function if one of the other init functions is already doing the work. This should help.


- removes the need for DEPRECATED_FRAME_CHAIN
If not present, the legacy code will try to use the frame ID unwinder to get the chained frame. This might help.


- adds deprecated_get_next_frame_hack()
Unlike get_next_frame, this verison will return the sentinel frame. The intent is for people to change code like: analyze_prologue (this_frame, &cache) into: analyze_prologue (this_frame->next, &cache) with out needing to worry about a NULL frame.


These might help, but either way ....

Andrew
2003-06-16  Andrew Cagney  <cagney@redhat.com>

	* frame.h (deprecated_get_next_frame_hack): Declare.
	* frame.c (legacy_saved_regs_prev_register): Only require
	DEPRECATED_FRAME_INIT_SAVED_REGS when it is needed.  Assert that
	there are always saved regs.
	(deprecated_generic_get_saved_register): Do not require
	DEPRECATED_FRAME_INIT_SAVED_REGS.
	(legacy_get_prev_frame): Do not require DEPRECATED_FRAME_CHAIN,
	use frame ID unwind instead.
	(deprecated_get_next_frame_hack): New function.

Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.124
diff -u -r1.124 frame.c
--- frame.c	16 Jun 2003 16:47:41 -0000	1.124
+++ frame.c	16 Jun 2003 20:03:31 -0000
@@ -993,14 +993,13 @@
   struct frame_info *frame = next_frame->prev;
   gdb_assert (frame != NULL);
 
-  /* Only (older) architectures that implement the
-     DEPRECATED_FRAME_INIT_SAVED_REGS method should be using this
-     function.  */
-  gdb_assert (DEPRECATED_FRAME_INIT_SAVED_REGS_P ());
-
-  /* Load the saved_regs register cache.  */
   if (get_frame_saved_regs (frame) == NULL)
-    DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
+    {
+      /* If nothing's initialized the saved regs, do it now.  */
+      gdb_assert (DEPRECATED_FRAME_INIT_SAVED_REGS_P ());
+      DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
+      gdb_assert (get_frame_saved_regs (frame) != NULL);
+    }
 
   if (get_frame_saved_regs (frame) != NULL
       && get_frame_saved_regs (frame)[regnum] != 0)
@@ -1112,8 +1111,6 @@
   if (!target_has_registers)
     error ("No registers.");
 
-  gdb_assert (DEPRECATED_FRAME_INIT_SAVED_REGS_P ());
-
   /* Normal systems don't optimize out things with register numbers.  */
   if (optimized != NULL)
     *optimized = 0;
@@ -1267,6 +1264,12 @@
     return NULL;
 }
 
+struct frame_info *
+deprecated_get_next_frame_hack (struct frame_info *this_frame)
+{
+  return this_frame->next;
+}
+
 /* Flush the entire frame cache.  */
 
 void
@@ -1501,6 +1504,12 @@
     /* FIXME: 2002-11-09: There isn't any reason to special case this
        edge condition.  Instead the per-architecture code should hande
        it locally.  */
+    /* FIXME: cagney/2003-06-16: This returns the inner most stack
+       address for the previous frame, that, however, is wrong.  It
+       should be the inner most stack address for the previous to
+       previous frame.  This is because it is the previous to previous
+       frame's innermost stack address that is constant through out
+       the lifetime of the previous frame (trust me :-).  */
     address = get_frame_base (this_frame);
   else
     {
@@ -1519,8 +1528,29 @@
          this to after the ffi test; I'd rather have backtraces from
          start go curfluy than have an abort called from main not show
          main.  */
-      gdb_assert (DEPRECATED_FRAME_CHAIN_P ());
-      address = DEPRECATED_FRAME_CHAIN (this_frame);
+      if (DEPRECATED_FRAME_CHAIN_P ())
+	address = DEPRECATED_FRAME_CHAIN (this_frame);
+      else
+	{
+	  /* Someone is part way through coverting an old architecture
+             to the new frame code.  Implement FRAME_CHAIN the way the
+             new frame will.  */
+	  /* Find PREV frame's unwinder.  */
+	  prev->unwind = frame_unwind_find_by_pc (current_gdbarch,
+						  frame_pc_unwind (this_frame));
+	  /* FIXME: cagney/2003-04-02: Rather than storing the frame's
+	     type in the frame, the unwinder's type should be returned
+	     directly.  Unfortunatly, legacy code, called by
+	     legacy_get_prev_frame, explicitly set the frames type
+	     using the method deprecated_set_frame_type().  */
+	  prev->type = prev->unwind->type;
+	  /* Find PREV frame's ID.  */
+	  prev->unwind->this_id (this_frame,
+				 &prev->prologue_cache,
+				 &prev->this_id.value);
+	  prev->this_id.p = 1;
+	  address = prev->this_id.value.stack_addr;
+	}
 
       if (!legacy_frame_chain_valid (address, this_frame))
 	{
@@ -1663,9 +1693,13 @@
   /* Initialize the code used to unwind the frame PREV based on the PC
      (and probably other architectural information).  The PC lets you
      check things like the debug info at that point (dwarf2cfi?) and
-     use that to decide how the frame should be unwound.  */
-  prev->unwind = frame_unwind_find_by_pc (current_gdbarch,
-					  get_frame_pc (prev));
+     use that to decide how the frame should be unwound.
+
+     If there isn't a FRAME_CHAIN, the code above will have already
+     done this.  */
+  if (prev->unwind == NULL)
+    prev->unwind = frame_unwind_find_by_pc (current_gdbarch,
+					    get_frame_pc (prev));
 
   /* If the unwinder provides a frame type, use it.  Otherwize
      continue on to that heuristic mess.  */
@@ -1673,6 +1707,7 @@
     {
       prev->type = prev->unwind->type;
       if (prev->type == NORMAL_FRAME)
+	/* FIXME: cagney/2003-06-16: would get_frame_pc() be better?  */
 	prev->this_id.value.code_addr
 	  = get_pc_function_start (prev->this_id.value.code_addr);
       if (frame_debug)
Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.100
diff -u -r1.100 frame.h
--- frame.h	14 Jun 2003 22:35:24 -0000	1.100
+++ frame.h	16 Jun 2003 20:03:31 -0000
@@ -154,6 +154,13 @@
 extern struct frame_info *get_prev_frame (struct frame_info *);
 extern struct frame_info *get_next_frame (struct frame_info *);
 
+/* Given a FRAME, return the true next (more inner, younger) frame.
+   This one exposes the sentinel frame and, hence, never returns NULL.
+   It is here strictly to help old targets in their migration path to
+   the new frame code - the new code requires the NEXT, and not THIS
+   frame.  */
+extern struct frame_info *deprecated_get_next_frame_hack (struct frame_info *);
+
 /* Given a frame's ID, relocate the frame.  Returns NULL if the frame
    is not found.  */
 extern struct frame_info *frame_find_by_id (struct frame_id id);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]