]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix step-over-syscall.exp failure
authorLuis Machado <luis.machado@linaro.org>
Thu, 9 Jan 2020 19:04:36 +0000 (16:04 -0300)
committerLuis Machado <luis.machado@linaro.org>
Tue, 21 Jan 2020 13:25:15 +0000 (10:25 -0300)
In particular, this one:

FAIL: gdb.base/step-over-syscall.exp: fork: displaced=on: check_pc_after_cross_syscall: single step over fork final pc

When ptrace fork event reporting is enabled, GDB gets a PTRACE_EVENT_FORK
event whenever the inferior executes the fork syscall.

Then the logic is that GDB needs to step the inferior yet again in order to
receive a predetermined SIGTRAP, but no execution takes place because the
signal was already queued for delivery. That means the PC should stay the same.

I noticed the aarch64 code is currently adjusting the PC in this situation,
making the inferior skip an instruction without executing it.

The following change checks if we did not execute the instruction
(pc - to == 0), making proper adjustments for such case.

Regression tested on aarch64-linux-gnu on the tryserver.

gdb/ChangeLog:

2020-01-21  Luis Machado  <luis.machado@linaro.org>

* aarch64-tdep.c (struct aarch64_displaced_step_closure )
<pc_adjust>: Adjust the documentation.
(aarch64_displaced_step_fixup): Check if PC really moved before
adjusting it.

gdb/ChangeLog
gdb/aarch64-tdep.c

index 93a125b3e7d32e43a78a5db4a3366e9cd2bfe56f..146767f06976aec890b03019bd4cadfb664ac59f 100644 (file)
@@ -1,3 +1,10 @@
+2020-01-21  Luis Machado  <luis.machado@linaro.org>
+
+       * aarch64-tdep.c (struct aarch64_displaced_step_closure )
+       <pc_adjust>: Adjust the documentation.
+       (aarch64_displaced_step_fixup): Check if PC really moved before
+       adjusting it.
+
 2020-01-19  Tom Tromey  <tom@tromey.com>
 
        * disasm.c (~gdb_disassembler): New destructor.
index 8451a916dc3e6465062f5ab250328d0dcf4ad3f7..fb7b8621ba20a05ea90552fe173d540b3e168c0f 100644 (file)
@@ -2737,7 +2737,8 @@ struct aarch64_displaced_step_closure : public displaced_step_closure
      is being displaced stepping.  */
   int cond = 0;
 
-  /* PC adjustment offset after displaced stepping.  */
+  /* PC adjustment offset after displaced stepping.  If 0, then we don't
+     write the PC back, assuming the PC is already the right address.  */
   int32_t pc_adjust = 0;
 };
 
@@ -3032,11 +3033,12 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch,
 {
   aarch64_displaced_step_closure *dsc = (aarch64_displaced_step_closure *) dsc_;
 
+  ULONGEST pc;
+
+  regcache_cooked_read_unsigned (regs, AARCH64_PC_REGNUM, &pc);
+
   if (dsc->cond)
     {
-      ULONGEST pc;
-
-      regcache_cooked_read_unsigned (regs, AARCH64_PC_REGNUM, &pc);
       if (pc - to == 8)
        {
          /* Condition is true.  */
@@ -3052,6 +3054,13 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch,
 
   if (dsc->pc_adjust != 0)
     {
+      /* Make sure the previous instruction was executed (that is, the PC
+        has changed).  If the PC didn't change, then discard the adjustment
+        offset.  Otherwise we may skip an instruction before its execution
+        took place.  */
+      if ((pc - to) == 0)
+       dsc->pc_adjust = 0;
+
       if (debug_displaced)
        {
          debug_printf ("displaced: fixup: set PC to %s:%d\n",