From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1843 invoked by alias); 3 Jul 2014 08:35:29 -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 1670 invoked by uid 89); 3 Jul 2014 08:35:28 -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-f178.google.com Received: from mail-ie0-f178.google.com (HELO mail-ie0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 03 Jul 2014 08:35:26 +0000 Received: by mail-ie0-f178.google.com with SMTP id rl12so1179544iec.23 for ; Thu, 03 Jul 2014 01:35:24 -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=oHM1vbagRjbfusH7yTDvtO5y8g2QhVfemYVRjsA7WBY=; b=kdvatki+mY5nDS5qVv1T81fOyJL+SrZsNSUOLFhMUnhz1bhiRcKLqy20SIF/nP5AcJ TEE9Ffodu6bZkbKioOLkiCYkArHjk4qFcw6ZXebbupefOD0HznPAMUtmExpe3/CXZON4 t2or1uH/gMMFIpG8NP9aQIeNN4ND3YkV1T6JDvmCqtfdj7+hPv7Wd5seYCECikr0aDhu BGkpfS4/jYk80aBvWWnJTOXnkhlaMabwiUiejIyXb8xLm80ylF2dQ9xgr9v/rTJ5MgHR mLmeIbzbZf98N+fdpy7Yr0ixU2sgGZtlksYVTBxMYOW25TRPKR6eVaQ0wyYFc+0wTZgs Wjpg== X-Gm-Message-State: ALoCoQkGArXI7vDu0xtrlw3bOHymxSY/yREPoMgq12CVjnFV/ivwOh0jJOUq+UJGtwEiY2hGK+4f MIME-Version: 1.0 X-Received: by 10.42.252.201 with SMTP id mx9mr346216icb.78.1404376524027; Thu, 03 Jul 2014 01:35:24 -0700 (PDT) Received: by 10.64.135.33 with HTTP; Thu, 3 Jul 2014 01:35:23 -0700 (PDT) In-Reply-To: <1404367792-23234-3-git-send-email-yao@codesourcery.com> References: <1404367792-23234-1-git-send-email-yao@codesourcery.com> <1404367792-23234-3-git-send-email-yao@codesourcery.com> Date: Thu, 03 Jul 2014 08:35:00 -0000 Message-ID: Subject: Re: [PATCH 2/4] Match instruction adjusts SP in thumb 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/msg00047.txt.bz2 On 3 July 2014 07:09, Yao Qi wrote: > This is a refactor patch, that moves matching instructions adjusting > SP into a new function, thumb_instruction_restores_sp. The second > call to thumb_instruction_restores_sp in thumb_in_function_epilogue_p > is a little different from the original. The original code matches > 'POP without PC', but thumb_in_function_epilogue_p matches > 'POP (with and without PC)'. However, GDB found one > instruction about return and is scanning the previous instruction, > which should be an instruction about return too, so the code change > doesn't affect the functionality. > > gdb: > > 2014-07-02 Yao Qi > > * arm-tdep.c (thumb_instruction_restores_sp): New function. > (thumb_in_function_epilogue_p): Call > thumb_instruction_restores_sp. > --- > gdb/arm-tdep.c | 25 ++++++++++++++----------- > 1 file changed, 14 insertions(+), 11 deletions(-) This patch looks good to me. > diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c > index 0fc7fc1..153ef42 100644 > --- a/gdb/arm-tdep.c > +++ b/gdb/arm-tdep.c > @@ -685,6 +685,17 @@ thumb2_instruction_changes_pc (unsigned short inst1, unsigned short inst2) > return 0; > } > > +/* Return 1 if the 16-bit Thumb instruction INSN restores SP in > + epilogue, 0 otherwise. */ > + > +static int > +thumb_instruction_restores_sp (unsigned short insn) > +{ > + return (insn == 0x46bd /* mov sp, r7 */ > + || (insn & 0xff80) == 0xb000 /* add sp, imm */ > + || (insn & 0xfe00) == 0xbc00); /* pop */ > +} > + > /* Analyze a Thumb prologue, looking for a recognizable stack frame > and frame pointer. Scan until we encounter a store that could > clobber the stack frame unexpectedly, or an unknown instruction. > @@ -3257,14 +3268,10 @@ thumb_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) > found_return = 1; > else if (insn == 0x46f7) /* mov pc, lr */ > found_return = 1; > - else if (insn == 0x46bd) /* mov sp, r7 */ > - found_stack_adjust = 1; > - else if ((insn & 0xff80) == 0xb000) /* add sp, imm */ > - found_stack_adjust = 1; > - else if ((insn & 0xfe00) == 0xbc00) /* pop */ > + else if (thumb_instruction_restores_sp (insn)) > { > found_stack_adjust = 1; > - if (insn & 0x0100) /* include PC. */ > + if ((insn & 0xfe00) == 0xbd00) /* pop */ > found_return = 1; > } > else if (thumb_insn_size (insn) == 4) /* 32-bit Thumb-2 instruction */ > @@ -3317,11 +3324,7 @@ thumb_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) > insn = extract_unsigned_integer (buf, 2, byte_order_for_code); > insn2 = extract_unsigned_integer (buf + 2, 2, byte_order_for_code); > > - if (insn2 == 0x46bd) /* mov sp, r7 */ > - found_stack_adjust = 1; > - else if ((insn2 & 0xff80) == 0xb000) /* add sp, imm */ > - found_stack_adjust = 1; > - else if ((insn2 & 0xff00) == 0xbc00) /* pop without PC */ > + if (thumb_instruction_restores_sp (insn2)) > found_stack_adjust = 1; > else if (insn == 0xe8bd) /* ldm.w sp!, */ > found_stack_adjust = 1; > -- > 1.9.0 > -- Will Newton Toolchain Working Group, Linaro