public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yvan Roux <yvan.roux@foss.st.com>
To: <gdb-patches@sourceware.org>
Cc: Torbjorn SVENSSON <torbjorn.svensson@foss.st.com>,
	Luis Machado <luis.machado@arm.com>
Subject: [PATCH 3/3] gdb/arm: Make sp alias for one of the other stack pointers
Date: Tue, 14 Jun 2022 17:01:37 +0200	[thread overview]
Message-ID: <20220614150137.GE12000@gnbcxd0114.gnb.st.com> (raw)
In-Reply-To: <20220614145606.GB12000@gnbcxd0114.gnb.st.com>

For Cortex-M targets, the sp register is never detached from msp or
psp, it always has the same value as one of them. Let GDB treat
ARM_SP_REGNUM as an alias similar to what is done in hardware.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
---
 gdb/arm-tdep.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index e497dd1b3b8..694fe8a8859 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -385,9 +385,6 @@ static CORE_ADDR
 arm_cache_get_sp_register (struct arm_prologue_cache *cache,
 			   arm_gdbarch_tdep *tdep, int regnum)
 {
-  if (regnum == ARM_SP_REGNUM)
-    return cache->sp;
-
   if (tdep->have_sec_ext)
     {
       if (regnum == tdep->m_profile_msp_s_regnum)
@@ -402,6 +399,8 @@ arm_cache_get_sp_register (struct arm_prologue_cache *cache,
 	return arm_cache_get_sp_register (cache, tdep, cache->active_msp_regnum);
       if (regnum == tdep->m_profile_psp_regnum)
 	return arm_cache_get_sp_register (cache, tdep, cache->active_psp_regnum);
+      if (regnum == ARM_SP_REGNUM)
+	return arm_cache_get_sp_register (cache, tdep, cache->active_sp_regnum);
     }
   else if (tdep->is_m)
     {
@@ -409,7 +408,11 @@ arm_cache_get_sp_register (struct arm_prologue_cache *cache,
 	return cache->msp_s;
       if (regnum == tdep->m_profile_psp_regnum)
 	return cache->psp_s;
+      if (regnum == ARM_SP_REGNUM)
+	return arm_cache_get_sp_register (cache, tdep, cache->active_sp_regnum);
     }
+  else if (regnum == ARM_SP_REGNUM)
+    return cache->sp;
 
   gdb_assert_not_reached ("Invalid SP selection");
 }
@@ -430,12 +433,6 @@ static void
 arm_cache_set_active_sp_value (struct arm_prologue_cache *cache,
 			       arm_gdbarch_tdep *tdep, CORE_ADDR val)
 {
-  if (cache->active_sp_regnum == ARM_SP_REGNUM)
-    {
-      cache->sp = val;
-      return;
-    }
-
   if (tdep->have_sec_ext)
     {
       if (cache->active_sp_regnum == tdep->m_profile_msp_s_regnum)
@@ -458,6 +455,11 @@ arm_cache_set_active_sp_value (struct arm_prologue_cache *cache,
 
       return;
     }
+  else if (cache->active_sp_regnum == ARM_SP_REGNUM)
+    {
+      cache->sp = val;
+      return;
+    }
 
   gdb_assert_not_reached ("Invalid SP selection");
 }
-- 
2.17.1


      parent reply	other threads:[~2022-06-14 15:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 14:56 [PATCH 0/3] gdb/arm: ARMv8-M Secure/Non-Secure stack support fixes Yvan Roux
2022-06-14 14:59 ` [PATCH 1/3] gdb/arm: Fetch initial sp value prior to compare Yvan Roux
2022-06-15  8:39   ` Luis Machado
2022-06-15  9:20     ` Yvan Roux
2022-06-14 15:00 ` [PATCH 2/3] gdb/arm: Track msp and psp Yvan Roux
2022-06-15  8:57   ` Luis Machado
2022-06-15  9:28     ` Yvan Roux
2022-06-15  9:46       ` Torbjorn SVENSSON
2022-06-15 10:15         ` Luis Machado
2022-06-15 10:46           ` Yvan Roux
2022-06-14 15:01 ` Yvan Roux [this message]

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=20220614150137.GE12000@gnbcxd0114.gnb.st.com \
    --to=yvan.roux@foss.st.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    --cc=torbjorn.svensson@foss.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).