From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7083 invoked by alias); 3 Jul 2014 08:39:48 -0000 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 Received: (qmail 7057 invoked by uid 89); 3 Jul 2014 08:39:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f172.google.com Received: from mail-ie0-f172.google.com (HELO mail-ie0-f172.google.com) (209.85.223.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 03 Jul 2014 08:39:44 +0000 Received: by mail-ie0-f172.google.com with SMTP id rd18so427727iec.31 for ; Thu, 03 Jul 2014 01:39:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=nOd23VpOG0jhhvOSVcfx8rr+Q4aaTjCSUVP983e0VH4=; b=WT4fsu4pn9oyvhRZgYQwsGt0rchKyVv+JtZPgJ0AGnQuSie8vVM//SviR9vfWDGX+1 UxdnZy2ql4sA98J5KxMULwW4EF+fZashlVY6ff2Pf6secAqy3zQS40dHowgw7PCu+HOe gywUur1Xam9Io24rinoUr1t/yvoeQGQrcoVaJUnEhnd4JfuEmoI5QjvBAFDzB7hUD5DB JUZXNwGrtI4x7a+XK/ZthVQAoSj4XnZoWDvZxfDMzk1g41b/omc33ubKDTgBbqGriryE OdQw8VWyIGTL/KaFop7+gXp9uVBTpGdNEmL3zllVAo8Jj+r3FdrLwol1qSFmnJURxd5o J/3Q== X-Gm-Message-State: ALoCoQmu7+8ZlwvnXMWHj6c2br9Co8c2UWWZEZew51P/Cye9++Ic5S4Z5QQRBLbg3LDncv3bjeDe MIME-Version: 1.0 X-Received: by 10.42.252.201 with SMTP id mx9mr361771icb.78.1404376782678; Thu, 03 Jul 2014 01:39:42 -0700 (PDT) Received: by 10.64.135.33 with HTTP; Thu, 3 Jul 2014 01:39:42 -0700 (PDT) In-Reply-To: <1404367792-23234-4-git-send-email-yao@codesourcery.com> References: <1404367792-23234-1-git-send-email-yao@codesourcery.com> <1404367792-23234-4-git-send-email-yao@codesourcery.com> Date: Thu, 03 Jul 2014 08:39:00 -0000 Message-ID: Subject: Re: [PATCH 3/4] Stop prologue analysis when past the epilogue From: Will Newton To: Yao Qi Cc: "gdb-patches@sourceware.org" Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-07/txt/msg00048.txt.bz2 On 3 July 2014 07:09, Yao Qi wrote: > We see a fail in gdb.trace/entry-values.exp on armv4t thumb, > > bt^M > #0 0x000086fc in foo (i=0, i@entry=, j=2, j@entry=)^M > #1 0x00000002 in ?? ()^M > Backtrace stopped: previous frame identical to this frame (corrupt stack?)^M > (gdb) FAIL: gdb.trace/entry-values.exp: bt (1) (pattern 1) > > The fail is caused by incorrect prologue analysis, which can be illustrated by > setting a breakpoint on function foo, > > (gdb) disassemble foo > Dump of assembler code for function foo: > 0x000086e8 <+0>: push {r7, lr} > 0x000086ea <+2>: sub sp, #8 > 0x000086ec <+4>: add r7, sp, #0 > 0x000086ee <+6>: str r0, [r7, #4] > 0x000086f0 <+8>: str r1, [r7, #0] > 0x000086f2 <+10>: movs r3, #0 > 0x000086f4 <+12>: adds r0, r3, #0 > 0x000086f6 <+14>: mov sp, r7 > 0x000086f8 <+16>: add sp, #8 > 0x000086fa <+18>: pop {r7} > 0x000086fc <+20>: pop {r1} > 0x000086fe <+22>: bx r1 > End of assembler dump. > (gdb) b foo > Breakpoint 1 at 0x86fc > > As we can see, GDB analyzes the prologue and skip the prologue to the last > instruction but one. The breakpoint is set within the epilogue, and GDB > skips too many instruction for prologue. This patch teaches GDB to stop > prologue analysis when goes into the epilogue. With this patch applied, > GDB is able to unwind correctly, > > (gdb) bt > #0 0x000086f6 in foo (i=0, i@entry=2, j=2, j@entry=3) > #1 0x00008718 in bar (i=) > #2 0x00008758 in main () > > gdb: > > 2014-07-02 Yao Qi > > * arm-tdep.c (thumb_analyze_prologue): Break the loop if > thumb_instruction_restores_sp return true. > --- > gdb/arm-tdep.c | 5 +++++ > 1 file changed, 5 insertions(+) This patch looks good to me too. > diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c > index 153ef42..72beeb1 100644 > --- a/gdb/arm-tdep.c > +++ b/gdb/arm-tdep.c > @@ -754,6 +754,11 @@ thumb_analyze_prologue (struct gdbarch *gdbarch, > regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], > -offset); > } > + else if (thumb_instruction_restores_sp (insn)) > + { > + /* Don't scan past the epilogue. */ > + break; > + } > else if ((insn & 0xf800) == 0xa800) /* add Rd, sp, #imm */ > regs[bits (insn, 8, 10)] = pv_add_constant (regs[ARM_SP_REGNUM], > (insn & 0xff) << 2); > -- > 1.9.0 > -- Will Newton Toolchain Working Group, Linaro