From patchwork Thu Jul 3 06:09:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 1871 Received: (qmail 29111 invoked by alias); 3 Jul 2014 06:11:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 29024 invoked by uid 89); 3 Jul 2014 06:11:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Jul 2014 06:11:35 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1X2aF2-0006QB-3Q from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Wed, 02 Jul 2014 23:11:32 -0700 Received: from SVR-ORW-FEM-06.mgc.mentorg.com ([147.34.97.120]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 2 Jul 2014 23:11:31 -0700 Received: from qiyao.dyndns.org.com (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.2.247.3; Wed, 2 Jul 2014 23:11:31 -0700 From: Yao Qi To: Subject: [PATCH 3/4] Stop prologue analysis when past the epilogue Date: Thu, 3 Jul 2014 14:09:51 +0800 Message-ID: <1404367792-23234-4-git-send-email-yao@codesourcery.com> In-Reply-To: <1404367792-23234-1-git-send-email-yao@codesourcery.com> References: <1404367792-23234-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes 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(+) 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);