This is the mail archive of the gdb@sourceware.org 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]

Re: PowerPC prologue analysis


Daniel Jacobowitz wrote:
On Tue, Jul 29, 2008 at 11:42:29AM -0400, Aleksandar Ristovski wrote:
And for the reference: Daniel's patch (
http://sourceware.org/ml/gdb-patches/2007-12/msg00111.html ) does
solve the problem with not all registers saved.

Why is the patch not in HEAD gdb?

There's a couple of questions in the posting and I never figured out the answers to them. I'll be back to them at some point.


May I suggest that you break the patch in two patches: one dealing with not-all-registers-saved (i.e. gpr_mask) and the rest?


I extracted the gpr_mask part here with the testsuite changes and I believe this part of the patch is safe to apply.

Attached: Fragment extracted from Daniel's patch.



Index: gdb/rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.318
diff -u -p -r1.318 rs6000-tdep.c
--- gdb/rs6000-tdep.c	15 Jul 2008 18:32:06 -0000	1.318
+++ gdb/rs6000-tdep.c	29 Jul 2008 16:27:53 -0000
@@ -117,6 +117,7 @@ struct rs6000_framedata
 				   by which we decrement sp to allocate
 				   the frame */
     int saved_gpr;		/* smallest # of saved gpr */
+    unsigned int gpr_mask;	/* Each bit is an individual saved GPR.  */
     int saved_fpr;		/* smallest # of saved fpr */
     int saved_vr;               /* smallest # of saved vr */
     int saved_ev;               /* smallest # of saved ev */
@@ -1275,6 +1276,10 @@ skip_prologue (struct gdbarch *gdbarch, 
 	{
 
 	  reg = GET_SRC_REG (op);
+	  if ((op & 0xfc1f0000) == 0xbc010000)
+	    fdata->gpr_mask |= ~((1U << reg) - 1);
+	  else
+	    fdata->gpr_mask |= 1U << reg;
 	  if (fdata->saved_gpr == -1 || fdata->saved_gpr > reg)
 	    {
 	      fdata->saved_gpr = reg;
@@ -1678,11 +1683,15 @@ skip_prologue (struct gdbarch *gdbarch, 
 
       else
 	{
+	  unsigned int all_mask = ~((1U << fdata->saved_gpr) - 1);
+
 	  /* Not a recognized prologue instruction.
 	     Handle optimizer code motions into the prologue by continuing
 	     the search if we have no valid frame yet or if the return
-	     address is not yet saved in the frame.  */
-	  if (fdata->frameless == 0 && fdata->nosavedpc == 0)
+	     address is not yet saved in the frame.  Also skip instructions
+	     if some of the GPRs expected to be saved are not yet saved.  */
+	  if (fdata->frameless == 0 && fdata->nosavedpc == 0
+	      && (fdata->gpr_mask & all_mask) == all_mask)
 	    break;
 
 	  if (op == 0x4e800020		/* blr */
@@ -2573,7 +2582,8 @@ rs6000_frame_cache (struct frame_info *t
       CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset;
       for (i = fdata.saved_gpr; i < ppc_num_gprs; i++)
 	{
-	  cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr;
+	  if (fdata.gpr_mask & (1U << i))
+	    cache->saved_regs[tdep->ppc_gp0_regnum + i].addr = gpr_addr;
 	  gpr_addr += wordsize;
 	}
     }
Index: gdb/testsuite/gdb.arch/powerpc-prologue.exp
===================================================================
--- gdb/testsuite/gdb.arch/powerpc-prologue.exp	(revision 197)
+++ gdb/testsuite/gdb.arch/powerpc-prologue.exp	(working copy)
@@ -64,7 +64,7 @@ gdb_test "backtrace 10" \
 	"backtrace in PIC"
 
 gdb_test "info frame" \
-	".*Saved registers:.*r30 at.*r31 at.*pc at.*lr at.*" \
+	".*Saved registers:.*r30 at.*pc at.*lr at.*" \
 	"saved registers in PIC"
 
 # Testcase for scheduled prologue.
@@ -84,5 +84,5 @@ gdb_test "backtrace 10" \
 	"backtrace in optimized"
 
 gdb_test "info frame" \
-	".*Saved registers:.*r30 at.*r31 at.*pc at.*lr at.*" \
+	".*Saved registers:.*r30 at.*pc at.*lr at.*" \
 	"saved registers in optimized"

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