[PATCH] gdb/arm-tdep: fix to adapt insn "str rd, [sp, #-imm]"

chenzefeng chenzefeng2@huawei.com
Thu Dec 19 13:31:00 GMT 2019


In the code below, GDB get an incorrect backtrace:

0x000f13fc <+0>:	str	r4, [sp, #-8]!

according to the ARMV7 manual, the insn of str have
12 bits immediate.

Signed-off-by: chenzefeng <chenzefeng2@huawei.com>
---
 gdb/arm-tdep.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 69c87c5..8a9f878 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -1539,12 +1539,13 @@ arm_analyze_prologue (struct gdbarch *gdbarch,
 	  regs[rd] = pv_add_constant (regs[bits (insn, 16, 19)], -imm);
 	  continue;
 	}
-      else if ((insn & 0xffff0fff) == 0xe52d0004)	/* str Rd,
-							   [sp, #-4]! */
+      else if ((insn & 0xffff0000) == 0xe52d0000)	/* str Rd,
+							   [sp, #-imm]! */
 	{
+	  unsigned imm = insn & 0xfff;
 	  if (stack.store_would_trash (regs[ARM_SP_REGNUM]))
 	    break;
-	  regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -4);
+	  regs[ARM_SP_REGNUM] = pv_add_constant (regs[ARM_SP_REGNUM], -imm);
 	  stack.store (regs[ARM_SP_REGNUM], 4,
 		       regs[bits (insn, 12, 15)]);
 	  continue;
-- 
1.8.5.6



More information about the Gdb-patches mailing list