S390: Fix displaced stepping of "basr r,0"

Message ID m37em0z9sw.fsf@oc1027705133.ibm.com
State New, archived
Headers

Commit Message

Andreas Arnez July 12, 2018, 4:41 p.m. UTC
  The BASR instruction behaves differently depending on whether the second
operand is a number from 1 to 15, or zero.  In the former case BASR jumps
to the address contained in the general register of that number, but in
the latter case no jump is performed.  GDB's displaced-stepping logic does
not distinguish these cases, although it should.

This is fixed.  In the case where no jump is performed the PC is adjusted
to point back after the original instruction.  Otherwise the PC is left
alone.

gdb/ChangeLog:

	* s390-tdep.c (s390_displaced_step_fixup): Adjust PC for a
	non-branching basr.
---
 gdb/s390-tdep.c | 3 +++
 1 file changed, 3 insertions(+)
  

Patch

diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 77e64af..e962824 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -492,6 +492,9 @@  s390_displaced_step_fixup (struct gdbarch *gdbarch,
       /* Recompute saved return address in R1.  */
       regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
 				      amode | (from + insnlen));
+      /* Update PC iff the instruction doesn't actually branch.  */
+      if (insn[0] == op_basr && r2 == 0)
+	regcache_write_pc (regs, from + insnlen);
     }
 
   /* Handle absolute branch instructions.  */