Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Will Newton <will.newton@linaro.org>
To: Yao Qi <yao@codesourcery.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/4] Stop prologue analysis when past the epilogue
Date: Thu, 03 Jul 2014 08:39:00 -0000	[thread overview]
Message-ID: <CANu=Dmi5xkEtj4zc2om=QAgPw-cwX_ic-c_VRGM9PewzHJoYMQ@mail.gmail.com> (raw)
In-Reply-To: <1404367792-23234-4-git-send-email-yao@codesourcery.com>

On 3 July 2014 07:09, Yao Qi <yao@codesourcery.com> wrote:
> We see a fail in gdb.trace/entry-values.exp on armv4t thumb,
>
> bt^M
> #0  0x000086fc in foo (i=0, i@entry=<optimized out>, j=2, j@entry=<optimized out>)^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=<optimized out>)
> #2  0x00008758 in main ()
>
> gdb:
>
> 2014-07-02  Yao Qi  <yao@codesourcery.com>
>
>         * 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


  reply	other threads:[~2014-07-03  8:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-03  6:11 [PATCH 0/4] Fix gdb.trace/entry-values.exp fails in thumb mode Yao Qi
2014-07-03  6:11 ` [PATCH 4/4] Fix gdb.trace/entry-values.exp for " Yao Qi
2014-07-07 15:15   ` Joel Brobecker
2014-07-08  8:53     ` Yao Qi
2014-07-03  6:11 ` [PATCH 1/4] Restrict matching add/sub sp, #imm Yao Qi
2014-07-03  8:31   ` Will Newton
2014-07-07  1:38     ` Yao Qi
2014-07-11 13:25       ` Joel Brobecker
2014-07-11 13:49         ` Yao Qi
2014-07-03  6:11 ` [PATCH 3/4] Stop prologue analysis when past the epilogue Yao Qi
2014-07-03  8:39   ` Will Newton [this message]
2014-07-11 13:39   ` Joel Brobecker
2014-07-03  6:11 ` [PATCH 2/4] Match instruction adjusts SP in thumb Yao Qi
2014-07-03  8:35   ` Will Newton
2014-07-11 13:25   ` Joel Brobecker
2014-09-24 12:56   ` Yao Qi
2014-07-11  7:34 ` [PATCH 0/4] Fix gdb.trace/entry-values.exp fails in thumb mode Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANu=Dmi5xkEtj4zc2om=QAgPw-cwX_ic-c_VRGM9PewzHJoYMQ@mail.gmail.com' \
    --to=will.newton@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=yao@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox