From patchwork Tue Nov 25 00:03:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 3896 Received: (qmail 10888 invoked by alias); 25 Nov 2014 00:03:23 -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 10879 invoked by uid 89); 25 Nov 2014 00:03:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE 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; Tue, 25 Nov 2014 00:03:21 +0000 Received: from svr-orw-fem-05.mgc.mentorg.com ([147.34.97.43]) by relay1.mentorg.com with esmtp id 1Xt3bC-0000pZ-ML from Sandra_Loosemore@mentor.com for gdb-patches@sourceware.org; Mon, 24 Nov 2014 16:03:18 -0800 Received: from [IPv6:::1] (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.3.181.6; Mon, 24 Nov 2014 16:03:18 -0800 Message-ID: <5473C73F.1040800@codesourcery.com> Date: Mon, 24 Nov 2014 17:03:11 -0700 From: Sandra Loosemore User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: Yao Qi , Subject: [3/3 patch, nios2] clean up prologue/epilogue detection code, v2 References: <545EA0C1.6050104@codesourcery.com> <87bnoeif74.fsf@codesourcery.com> <5473C4BA.2050903@codesourcery.com> In-Reply-To: <5473C4BA.2050903@codesourcery.com> This part of the revised Nios II prologue/epilogue refactoring patch fixes the prologue analyzer to handle the multiple stack adjustment instructions that GCC may now emit in some cases. It replaces the test that caused analysis to terminate when a second adjustment is found with more specific tests that can distinguish between prologue-ish and epilogue-ish adjustments. OK to commit on top of part 1? -Sandra diff -u b/gdb/nios2-tdep.c b/gdb/nios2-tdep.c --- b/gdb/nios2-tdep.c +++ b/gdb/nios2-tdep.c @@ -842,6 +842,11 @@ cache->reg_saved[NIOS2_SP_REGNUM].addr = -4; } + else if (rc == NIOS2_SP_REGNUM && ra == NIOS2_FP_REGNUM) + /* This is setting SP from FP. This only happens in the + function epilogue. */ + break; + else if (rc != 0) { if (value[rb].reg == 0) @@ -853,13 +858,21 @@ value[rc].offset = value[ra].offset + value[rb].offset; } - prologue_end = pc; + /* The add/move is only considered a prologue instruction + if the destination is SP or FP. */ + if (rc == NIOS2_SP_REGNUM || rc == NIOS2_FP_REGNUM) + prologue_end = pc; } else if (nios2_match_sub (insn, op, mach, &ra, &rb, &rc)) { /* SUB rc, ra, rb */ - if (rc != 0) + if (rc == NIOS2_SP_REGNUM && rb == NIOS2_SP_REGNUM + && value[rc].reg != 0) + /* If we are decrementing the SP by a non-constant amount, + this is alloca, not part of the prologue. */ + break; + else if (rc != 0) { if (value[rb].reg == 0) value[rc].reg = value[ra].reg; @@ -873,12 +886,13 @@ { /* ADDI rb, ra, imm */ - /* The first stack adjustment is part of the prologue. - Any subsequent stack adjustments are either down to - alloca or the epilogue so stop analysing when we hit - them. */ + /* A positive stack adjustment has to be part of the epilogue. */ if (rb == NIOS2_SP_REGNUM - && (value[rb].offset != 0 || value[ra].reg != NIOS2_SP_REGNUM)) + && (imm > 0 || value[ra].reg != NIOS2_SP_REGNUM)) + break; + + /* Likewise restoring SP from FP. */ + else if (rb == NIOS2_SP_REGNUM && ra == NIOS2_FP_REGNUM) break; if (rb != 0) @@ -887,7 +901,10 @@ value[rb].offset = value[ra].offset + imm; } - prologue_end = pc; + /* The add is only considered a prologue instruction + if the destination is SP or FP. */ + if (rb == NIOS2_SP_REGNUM || rb == NIOS2_FP_REGNUM) + prologue_end = pc; } else if (nios2_match_orhi (insn, op, mach, &ra, &rb, &uimm))