Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/commit] Fix SP register unwinding on alpha-tru64
@ 2008-05-30 15:13 Joel Brobecker
  2008-05-30 15:20 ` Ulrich Weigand
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2008-05-30 15:13 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2320 bytes --]

Hello,

While working on the alpha-tru64 port, I noticed that some backtraces
would break:

    (gdb) bt
    #0  0x000003000003d3dc in __hstTransferRegistersPC ()
       from /usr/shlib/libpthread.so
    #1  0x000003000002e694 in __osTransferContext ()
       from /usr/shlib/libpthread.so
    #2  0x0000030000020e80 in __dspDispatch () from /usr/shlib/libpthread.so
    Backtrace stopped: previous frame inner to this frame (corrupt stack?)

I traced the issue down to computing the wrong value for the SP register
for frame #2. As the RA register was saved on the stack at of offset
of the SP, we end up computing the wrong return address, leading to
the breakage.

The 'heuristic' frame unwinder relies on trad frames to compute
register values.  But we have to handle the case of the SP a little
differently because it is not necessarily saved on the stack. In fact,
in our case, the code in frame #1 looks like this:

    0x000003000002e4b0 <__osTransferContext+0>:     ldah    gp,16322(t12)
    0x000003000002e4b4 <__osTransferContext+4>:     unop
    0x000003000002e4b8 <__osTransferContext+8>:     lda     gp,-1168(gp)
    0x000003000002e4bc <__osTransferContext+12>:    unop
    0x000003000002e4c0 <__osTransferContext+16>:    lda     sp,-64(sp)
    0x000003000002e4c4 <__osTransferContext+20>:    stq     ra,0(sp)
    0x000003000002e4c8 <__osTransferContext+24>:    stq     s0,8(sp)
    0x000003000002e4cc <__osTransferContext+28>:    stq     s1,16(sp)
    0x000003000002e4d0 <__osTransferContext+32>:    stq     s2,24(sp)
    0x000003000002e4d4 <__osTransferContext+36>:    stq     s3,32(sp)
    0x000003000002e4d8 <__osTransferContext+40>:    stq     s4,40(sp)
    0x000003000002e4dc <__osTransferContext+44>:    stq     fp,48(sp)
    0x000003000002e4e0 <__osTransferContext+48>:    mov     sp,fp

So the SP has been saved inside the FP register.

Fortunately, the prologue parser already determines the frame base
(aka the "vfp"), and this frame base is in practice the sp in the
caller's frame...

2008-05-29  Joel Brobecker  <brobecker@adacore.com>

        * alpha-tdep.c (alpha_heuristic_frame_prev_register): Fix handling
        of the SP register.

This testcase fixes the problem and was successfully tested with
the AdaCore testsuite. I'll commit in a week unless we get some
comments...

-- 
Joel

[-- Attachment #2: alpha-tdep.c.diff --]
[-- Type: text/plain, Size: 691 bytes --]

Index: alpha-tdep.c
===================================================================
--- alpha-tdep.c	(revision 131678)
+++ alpha-tdep.c	(working copy)
@@ -1175,6 +1175,10 @@ alpha_heuristic_frame_prev_register (str
   struct alpha_heuristic_unwind_cache *info
     = alpha_heuristic_frame_unwind_cache (this_frame, this_prologue_cache, 0);
 
+  /* The stack pointer of the previous frame is this frame's vfp.  */
+  if (regnum == ALPHA_SP_REGNUM)
+    return frame_unwind_got_constant (this_frame, regnum, info->vfp);
+
   /* The PC of the previous frame is stored in the link register of
      the current frame.  Frob regnum so that we pull the value from
      the correct place.  */

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-30 15:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-30 15:13 [RFA/commit] Fix SP register unwinding on alpha-tru64 Joel Brobecker
2008-05-30 15:20 ` Ulrich Weigand
2008-05-31  6:46   ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox