public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* gdb/arm: Update the value of active sp when base sp changes
@ 2022-06-17 13:04 Yvan Roux
  2022-06-21 11:12 ` Luis Machado
  0 siblings, 1 reply; 2+ messages in thread
From: Yvan Roux @ 2022-06-17 13:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Torbjorn SVENSSON, Luis Machado

Hi,

For Arm Cortex-M33 with security extensions, there are 4 different
stacks pointers (msp_s, msp_ns, psp_s, psp_ns).
When plain "sp" is updated during unwinding of the stack, the active
stack pointer of the 4 stack pointers needs to be kept in sync.

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 | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 0c907482036..96d70d40b28 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -923,6 +923,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 			CORE_ADDR start, CORE_ADDR limit,
 			struct arm_prologue_cache *cache)
 {
+  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
   int i;
@@ -1398,9 +1399,6 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 	      unrecognized_pc = start;
 	    }
 
-	  arm_gdbarch_tdep *tdep
-	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
-
 	  /* Make sure we are dealing with a target that supports ARMv8.1-m
 	     PACBTI.  */
 	  if (cache != nullptr && tdep->have_pacbti
@@ -1460,7 +1458,11 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
 
   for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
     if (stack.find_reg (gdbarch, i, &offset))
-      cache->saved_regs[i].set_addr (offset);
+      {
+	cache->saved_regs[i].set_addr (offset);
+	if (i == ARM_SP_REGNUM)
+	  arm_cache_set_active_sp_value(cache, tdep, offset);
+      }
 
   return unrecognized_pc;
 }
@@ -2087,7 +2089,11 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
 
       for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
 	if (stack.find_reg (gdbarch, regno, &offset))
-	  cache->saved_regs[regno].set_addr (offset);
+	  {
+	    cache->saved_regs[regno].set_addr (offset);
+	    if (regno == ARM_SP_REGNUM)
+	      arm_cache_set_active_sp_value(cache, tdep, offset);
+	  }
     }
 
   arm_debug_printf ("Prologue scan stopped at %s",
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gdb/arm: Update the value of active sp when base sp changes
  2022-06-17 13:04 gdb/arm: Update the value of active sp when base sp changes Yvan Roux
@ 2022-06-21 11:12 ` Luis Machado
  0 siblings, 0 replies; 2+ messages in thread
From: Luis Machado @ 2022-06-21 11:12 UTC (permalink / raw)
  To: Yvan Roux, gdb-patches; +Cc: Torbjorn SVENSSON

Hi,

On 6/17/22 14:04, Yvan Roux wrote:
> Hi,
> 
> For Arm Cortex-M33 with security extensions, there are 4 different
> stacks pointers (msp_s, msp_ns, psp_s, psp_ns).
> When plain "sp" is updated during unwinding of the stack, the active
> stack pointer of the 4 stack pointers needs to be kept in sync.
> 
> 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 | 16 +++++++++++-----
>   1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 0c907482036..96d70d40b28 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -923,6 +923,7 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>   			CORE_ADDR start, CORE_ADDR limit,
>   			struct arm_prologue_cache *cache)
>   {
> +  arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
>     enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>     enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
>     int i;
> @@ -1398,9 +1399,6 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>   	      unrecognized_pc = start;
>   	    }
>   
> -	  arm_gdbarch_tdep *tdep
> -	    = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
> -
>   	  /* Make sure we are dealing with a target that supports ARMv8.1-m
>   	     PACBTI.  */
>   	  if (cache != nullptr && tdep->have_pacbti
> @@ -1460,7 +1458,11 @@ thumb_analyze_prologue (struct gdbarch *gdbarch,
>   
>     for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
>       if (stack.find_reg (gdbarch, i, &offset))
> -      cache->saved_regs[i].set_addr (offset);
> +      {
> +	cache->saved_regs[i].set_addr (offset);
> +	if (i == ARM_SP_REGNUM)
> +	  arm_cache_set_active_sp_value(cache, tdep, offset);
> +      }
>   
>     return unrecognized_pc;
>   }
> @@ -2087,7 +2089,11 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
>   
>         for (regno = 0; regno < ARM_FPS_REGNUM; regno++)
>   	if (stack.find_reg (gdbarch, regno, &offset))
> -	  cache->saved_regs[regno].set_addr (offset);
> +	  {
> +	    cache->saved_regs[regno].set_addr (offset);
> +	    if (regno == ARM_SP_REGNUM)
> +	      arm_cache_set_active_sp_value(cache, tdep, offset);
> +	  }
>       }
>   
>     arm_debug_printf ("Prologue scan stopped at %s",

Thanks. This is OK.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-21 11:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-17 13:04 gdb/arm: Update the value of active sp when base sp changes Yvan Roux
2022-06-21 11:12 ` Luis Machado

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).