public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/arm: Properly unwind S-registers for exception frames
@ 2022-10-10 18:09 Torbjörn SVENSSON
  0 siblings, 0 replies; only message in thread
From: Torbjörn SVENSSON @ 2022-10-10 18:09 UTC (permalink / raw)
  To: gdb-patches

For each D-register, there are 2 S-registers.  In the GDB
architecture, the S-registers are implemented as pseudo registers.

As the value for the S-registers can be stacked, the value needs to
be extracted from the corresponding D-register and returned in the
associated prev_register function.

Signed-off-by: Torbjörn SVENSSON  <torbjorn.svensson@foss.st.com>
---
 gdb/arm-tdep.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d357066653b..7168e2a5edc 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -261,6 +261,8 @@ static void arm_neon_quad_write (struct gdbarch *gdbarch,
 static CORE_ADDR
   arm_get_next_pcs_syscall_next_pc (struct arm_get_next_pcs *self);
 
+static bool is_s_pseudo (struct gdbarch *gdbarch, int regnum);
+
 
 /* get_next_pcs operations.  */
 static struct arm_get_next_pcs_ops arm_get_next_pcs_ops = {
@@ -3726,8 +3728,8 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
   cache = (struct arm_prologue_cache *) *this_cache;
 
   /* The value was already reconstructed into PREV_SP.  */
-  arm_gdbarch_tdep *tdep
-    = gdbarch_tdep<arm_gdbarch_tdep> (get_frame_arch (this_frame));
+  struct gdbarch *gdbarch = get_frame_arch (this_frame);
+  arm_gdbarch_tdep *tdep = gdbarch_tdep<arm_gdbarch_tdep> (gdbarch);
   if (prev_regnum == ARM_SP_REGNUM)
     return frame_unwind_got_constant (this_frame, prev_regnum,
 				      arm_cache_get_prev_sp_value (cache, tdep));
@@ -3756,7 +3758,6 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
      pattern.  */
   if (prev_regnum == ARM_PS_REGNUM)
     {
-      struct gdbarch *gdbarch = get_frame_arch (this_frame);
       struct value *value = trad_frame_get_prev_register (this_frame,
 							  cache->saved_regs,
 							  ARM_PC_REGNUM);
@@ -3770,6 +3771,30 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
       return frame_unwind_got_constant (this_frame, ARM_PS_REGNUM, xpsr);
     }
 
+  /* If we are asked to unwind Sn, unwind Dm where m is n/2 and take the
+     corresponding part of the D register.  */
+  if (is_s_pseudo (gdbarch, prev_regnum))
+    {
+      int single_regnum = prev_regnum - tdep->s_pseudo_base;
+      int double_regnum = ARM_D0_REGNUM + single_regnum / 2;
+      int offset;
+
+      struct value *value = trad_frame_get_prev_register (this_frame,
+							  cache->saved_regs,
+							  double_regnum);
+
+      gdb::array_view<const gdb_byte> raw = value_contents (value);
+
+      /* s0 is always the least significant half of d0.  */
+      if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
+	offset = (single_regnum & 1) ? 0 : 4;
+      else
+	offset = (single_regnum & 1) ? 4 : 0;
+
+      return frame_unwind_got_bytes (this_frame, prev_regnum,
+				     raw.slice (offset).data ());
+    }
+
   return trad_frame_get_prev_register (this_frame, cache->saved_regs,
 				       prev_regnum);
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-10 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 18:09 [PATCH] gdb/arm: Properly unwind S-registers for exception frames Torbjörn SVENSSON

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