Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Will Newton <will.newton@linaro.org>
To: Taimoor Mirza <tmirza@codesourcery.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix prologue analysis for ldr.w and ldrd instruction
Date: Wed, 07 May 2014 08:01:00 -0000	[thread overview]
Message-ID: <CANu=DmgMWP=dr=9xxQxcnFC-99M-BjdZa9JQa8vHM_w8Ythkxg@mail.gmail.com> (raw)
In-Reply-To: <1399448485-1740-1-git-send-email-tmirza@codesourcery.com>

On 7 May 2014 08:41, Taimoor Mirza <tmirza@codesourcery.com> wrote:
> Hi Guys,
>
> We experienced a problem while debugging startup code on Cortex-M targets (LPC4350 and ATSAM3UEK). On stepping through the code, GDB was throwing "invalid memory access" error. We found out that problem
> is coming because of wrong offset calculation for ldr.w and ldrd instruction during prologue analysis in thumb-mode. Below is problematic code in *thumb_analyze_prologue* function:
>
> else if ((insn & 0xff7f) == 0xf85f)    /* ldr.w Rt,<label> */
>         {
>           /* Constant pool loads.  */
>           unsigned int constant;
>           CORE_ADDR loc;
>
>           offset = bits (insn, 0, 11);
>           if (insn & 0x0080)
>         loc = start + 4 + offset;
>           else
>         loc = start + 4 - offset;
>
>           constant = read_memory_unsigned_integer (loc, 4, byte_order);
>           regs[bits (inst2, 12, 15)] = pv_constant (constant);
>         }
>
> The problem is at line *offset = bits (insn, 0, 11);* where it is obtaining offset from first two bytes of instruction that contain opcode of ldr.w instruction. As per Cortex-M reference manual and BFD code, it should be:
>
> offset = bits (inst2, 0, 11);
>
> inst2 contains next two bytes of ldr.w instruction and it is correctly used to get register information. Similarly inst2 should be used to obtain offset. Similar problem exists in ldrd instruction's offset calculation. Below patch provides fix of this problem. Is it OK?
>
> Thanks,
> Taimoor
>
> 2014-05-06  Taimoor Mirza  <tmirza@codesourcery.com>
>
>         gdb/
>         * arm-tdep.c (thumb_analyze_prologue): Fix offset calculation for
>         ldr.w and ldrd instructions.
> ---
>  gdb/arm-tdep.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index e3b1c3d..7271777 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -1071,7 +1071,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>               unsigned int constant;
>               CORE_ADDR loc;
>
> -             offset = bits (insn, 0, 11);
> +             offset = bits (inst2, 0, 11);
>               if (insn & 0x0080)
>                 loc = start + 4 + offset;
>               else
> @@ -1087,7 +1087,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>               unsigned int constant;
>               CORE_ADDR loc;
>
> -             offset = bits (insn, 0, 7) << 2;
> +             offset = bits (inst2, 0, 7) << 2;
>               if (insn & 0x0080)
>                 loc = start + 4 + offset;
>               else

This looks good to me, assuming the testsuite was run with no regressions.

-- 
Will Newton
Toolchain Working Group, Linaro


  reply	other threads:[~2014-05-07  8:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07  7:41 Taimoor Mirza
2014-05-07  8:01 ` Will Newton [this message]
2014-05-07 13:25   ` Joel Brobecker
2014-05-07 15:33     ` tmirza
2014-05-07 15:41       ` Luis Machado
2014-05-19 15:11       ` Joel Brobecker
2014-05-20  5:19         ` Taimoor
2014-05-20 12:09           ` Joel Brobecker
2014-05-20 13:04             ` Taimoor
2014-05-20 13:18               ` Joel Brobecker

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=DmgMWP=dr=9xxQxcnFC-99M-BjdZa9JQa8vHM_w8Ythkxg@mail.gmail.com' \
    --to=will.newton@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tmirza@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