[RFC,3/5] gdb/dwarf2: Add dwarf2_frame_reg_rule for GDB register number

Message ID 1667641476-31602-3-git-send-email-vanekt@fbl.cz
State New
Headers
Series [RFC,1/5] gdb/arm: Introduce control_s and control_ns registers |

Commit Message

Tomas Vanek Nov. 5, 2022, 9:44 a.m. UTC
  Arm M-profile security extension requires the dwarf2 unwinder to
copy a value from a mode specific stack pointer to the general sp.

We can achive this using DWARF2_FRAME_REG_SAVED_REG but
it is complicated as the DWARF base register number has to be filled
to reg->loc.reg (and dwarf2_frame_prev_register() in turn converts
it back to the GDB register number).

To avoid the useless conversion forth and back introduce a new item
in enum dwarf2_frame_reg_rule for GDB internal use.

DWARF2_FRAME_REG_SAVED_GDB_REG copies the value from a register
indexed by GDB number.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
---
 gdb/dwarf2/frame.c | 4 ++++
 gdb/dwarf2/frame.h | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
index 3f884ab..a0e554f 100644
--- a/gdb/dwarf2/frame.c
+++ b/gdb/dwarf2/frame.c
@@ -1166,6 +1166,10 @@  struct dwarf2_frame_cache
 	(gdbarch, cache->reg[regnum].loc.reg);
       return frame_unwind_got_register (this_frame, regnum, realnum);
 
+    case DWARF2_FRAME_REG_SAVED_GDB_REG:
+      realnum = cache->reg[regnum].loc.reg;
+      return frame_unwind_got_register (this_frame, regnum, realnum);
+
     case DWARF2_FRAME_REG_SAVED_EXP:
       addr = execute_stack_op (cache->reg[regnum].loc.exp.start,
 			       cache->reg[regnum].loc.exp.len,
diff --git a/gdb/dwarf2/frame.h b/gdb/dwarf2/frame.h
index 06c8a10..848e924 100644
--- a/gdb/dwarf2/frame.h
+++ b/gdb/dwarf2/frame.h
@@ -61,7 +61,10 @@  enum dwarf2_frame_reg_rule
   DWARF2_FRAME_REG_RA,		/* Return Address.  */
   DWARF2_FRAME_REG_RA_OFFSET,	/* Return Address with offset.  */
   DWARF2_FRAME_REG_CFA,		/* Call Frame Address.  */
-  DWARF2_FRAME_REG_CFA_OFFSET	/* Call Frame Address with offset.  */
+  DWARF2_FRAME_REG_CFA_OFFSET,	/* Call Frame Address with offset.  */
+  DWARF2_FRAME_REG_SAVED_GDB_REG
+    /* As DWARF2_FRAME_REG_SAVED_REG, loc.reg contains GDB register number,
+       not DWARF register number.  */
 };
 
 /* Register state.  */