public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Christophe Lyon <christophe.lyon.oss@gmail.com>
To: Luis Machado <luis.machado@linaro.org>
Cc: Christophe Lyon <christophe.lyon@foss.st.com>,
	gdb-patches@sourceware.org,  torjborn.svensson@st.com
Subject: Re: [PATCH 1/5] gdb/arm: Fix prologue analysis to support vpush
Date: Mon, 24 Jan 2022 14:55:22 +0100	[thread overview]
Message-ID: <CAKhMtS+AaYL8EkLL=++rdcHE26TKd9z7_3vZ7L3+XXCGV4ibVQ@mail.gmail.com> (raw)
In-Reply-To: <eadbabb8-8856-235f-5808-cd485d0abb69@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 2355 bytes --]

On Mon, Jan 17, 2022 at 1:50 PM Luis Machado via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> Hi!
>
> On 1/14/22 1:35 PM, Christophe Lyon via Gdb-patches wrote:
> > While working on adding support for Non-secure/Secure modes unwinding,
> > I noticed that the prologue analysis lacked support for vpush, which
> > is used for instance in the CMSE stub routine.
>
> Thanks for the patch.
>
> >
> > This patch updates thumb_analyze_prologue accordingly.
> > ---
> >   gdb/arm-tdep.c | 21 +++++++++++++++++++++
> >   1 file changed, 21 insertions(+)
> >
> > diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> > index 7495434484e..14ec0bc8f9e 100644
> > --- a/gdb/arm-tdep.c
> > +++ b/gdb/arm-tdep.c
> > @@ -896,6 +896,27 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
> >               regs[bits (insn, 0, 3)] = addr;
> >           }
> >
>
> I wish we'd use constants for instruction masks, but right now the code
> is full of magic numbers, so it is fine to use these. The code doesn't
> change that much anyway.
>

Yeah, I merely cut/pasted the previous code block, just updating the fields.


>
> > +       else if ((insn & 0xff20) == 0xed20    /* vstmdb Rn{!},
> > +                                                { registers } */
> > +                && pv_is_register (regs[bits (insn, 0, 3)],
> ARM_SP_REGNUM))
> > +         {
> > +           pv_t addr = regs[bits (insn, 0, 3)];
> > +           int number = bits (inst2, 0, 7) >> 1;
>
> I'd add a comment making it clear what is being checked/extracted here...
>
> > +
> > +           if (stack.store_would_trash (addr))
> > +             break;
> > +
> > +           /* Calculate offsets of saved registers.  */
> > +           for (; number > 0; number--)
> > +             {
> > +               addr = pv_add_constant (addr, -8);
> > +               stack.store (addr, 8, pv_register (ARM_D0_REGNUM +
> number, 0));
> > +             }
> > +
> > +           if (insn & 0x0020)
> > +             regs[bits (insn, 0, 3)] = addr;
>
> ... and here as well.
>
> > +         }
> > +
> >         else if ((insn & 0xff50) == 0xe940    /* strd Rt, Rt2,
> >                                                  [Rn, #+/-imm]{!} */
> >                  && pv_is_register (regs[bits (insn, 0, 3)],
> ARM_SP_REGNUM))
> >
>
> Otherwise this look good to me.
>

Is the attached patch OK?

Thanks,

Christophe

[-- Attachment #2: 0001-gdb-arm-Fix-prologue-analysis-to-support-vpush.patch --]
[-- Type: text/x-patch, Size: 1756 bytes --]

From 39da58e92d00cb55c3f07d638afc4c617f9c1bb8 Mon Sep 17 00:00:00 2001
From: Christophe Lyon <christophe.lyon@linaro.org>
Date: Fri, 14 Jan 2022 15:24:02 +0100
Subject: [PATCH] gdb/arm: Fix prologue analysis to support vpush

While working on adding support for Non-secure/Secure modes unwinding,
I noticed that the prologue analysis lacked support for vpush, which
is used for instance in the CMSE stub routine.

This patch updates thumb_analyze_prologue accordingly, adding support
for vpush of D-registers.
---
 gdb/arm-tdep.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 7495434484e..32e7b9ceb87 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -896,6 +896,31 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 		regs[bits (insn, 0, 3)] = addr;
 	    }
 
+	  else if ((insn & 0xff20) == 0xed20    /* vstmdb Rn{!}, { D-registers} */
+		   && (insn2 & 0x0f00) == 0x0b00/* (aka vpush) */
+		   && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
+	    {
+	      /* Address SP points to.  */
+	      pv_t addr = regs[bits (insn, 0, 3)];
+
+	      /* Number of registers saved.  */
+	      int number = bits (inst2, 0, 7) >> 1;
+
+	      if (stack.store_would_trash (addr))
+		break;
+
+	      /* Calculate offsets of saved registers.  */
+	      for (; number > 0; number--)
+		{
+		  addr = pv_add_constant (addr, -8);
+		  stack.store (addr, 8, pv_register (ARM_D0_REGNUM + number, 0));
+		}
+
+	      /* Writeback SP if needed.  */
+	      if (insn & 0x0020)
+		regs[bits (insn, 0, 3)] = addr;
+	    }
+
 	  else if ((insn & 0xff50) == 0xe940	/* strd Rt, Rt2,
 						   [Rn, #+/-imm]{!} */
 		   && pv_is_register (regs[bits (insn, 0, 3)], ARM_SP_REGNUM))
-- 
2.25.1


  reply	other threads:[~2022-01-24 13:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14 16:35 Christophe Lyon
2022-01-14 16:35 ` [PATCH 2/5] gdb/arm: Define MSP and PSP registers for M-Profile Christophe Lyon
2022-01-17 12:50   ` Luis Machado
2022-01-14 16:35 ` [PATCH 3/5] gdb/arm: Introduce arm_cache_init Christophe Lyon
2022-01-14 16:35 ` [PATCH 4/5] gdb/arm: Add support for multiple stack pointers on Cortex-M Christophe Lyon
2022-01-14 16:35 ` [PATCH 5/5] gdb/arm: Extend arm_m_addr_is_magic to support FNC_RETURN, add unwind-ns-to-s command Christophe Lyon
2022-01-17 12:49 ` [PATCH 1/5] gdb/arm: Fix prologue analysis to support vpush Luis Machado
2022-01-24 13:55   ` Christophe Lyon [this message]
2022-01-17  8:49 Christophe Lyon

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='CAKhMtS+AaYL8EkLL=++rdcHE26TKd9z7_3vZ7L3+XXCGV4ibVQ@mail.gmail.com' \
    --to=christophe.lyon.oss@gmail.com \
    --cc=christophe.lyon@foss.st.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@linaro.org \
    --cc=torjborn.svensson@st.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).