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

[RFA/commit] Fix SP register unwinding on alpha-tru64


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: alpha-tdep.c.diff
Description: Text document


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