From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29202 invoked by alias); 29 May 2008 20:52:37 -0000 Received: (qmail 29194 invoked by uid 22791); 29 May 2008 20:52:36 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 29 May 2008 20:52:20 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5BDA72A968E for ; Thu, 29 May 2008 16:52:18 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id gtW57Tve310i for ; Thu, 29 May 2008 16:52:18 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id EEFA42A969B for ; Thu, 29 May 2008 16:52:17 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id F1CE0E7ACD; Thu, 29 May 2008 13:52:15 -0700 (PDT) Date: Fri, 30 May 2008 15:13:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA/commit] Fix SP register unwinding on alpha-tru64 Message-ID: <20080529205215.GG13826@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="vGgW1X5XWziG23Ko" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-05/txt/msg00765.txt.bz2 --vGgW1X5XWziG23Ko Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2320 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 * 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 --vGgW1X5XWziG23Ko Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="alpha-tdep.c.diff" Content-length: 691 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. */ --vGgW1X5XWziG23Ko--