Blame SOURCES/gdb-rhbz1218710-reverse-debugging-ppc-5of7.patch

7b26da
  Message-ID: <5491BE7E.2060708@gmail.com>
7b26da
  Date: Thu, 18 Dec 2014 01:33:50 +0800
7b26da
  From: Wei-cheng Wang <cole945 at gmail dot com>
7b26da
  To: Ulrich Weigand <uweigand at de dot ibm dot com>
7b26da
  CC: gdb-patches at sourceware dot org
7b26da
  Subject: Re: [PATCH 3/3 v2] Process record support for PowerPC
7b26da
7b26da
  On 2014/12/9 上午 03:13, Ulrich Weigand wrote:
7b26da
  > Wei-cheng Wang wrote:
7b26da
  >> 	    * ppc-linux-tdep.c (powerpc_linux_in_dynsym_resolve_code):
7b26da
  >> 	    Scan PLT stub backward for reverse debugging.
7b26da
  >> 	    (ppc_linux_init_abi): set powerpc_linux_in_dynsym_resolve_code
7b26da
  >> 	    for both 32-bit and 64-bit.
7b26da
  >
7b26da
  > As I said in the reply to the 0/3 mail, I really think it would be
7b26da
  > better to handle this within the PPC skip_trampoline_code implementation,
7b26da
  > instead of having in_dynsym_resolve_code suddenly also cover the
7b26da
  > trampolines ...
7b26da
7b26da
     Hi,
7b26da
7b26da
     See the new patch, I moved the for-loop into skip_trampoline_code,
7b26da
     and removed in_dynsym_resolve_code.
7b26da
7b26da
  > It seems odd to have in_dynsym_resolve_code call into
7b26da
  > skip_trampoline_code.  Is there a reason why the skip_trampoline_code
7b26da
  > implementation cannot accept a PC in the middle of the sequence?
7b26da
7b26da
     I thought skip-trampoline is used to find the target address for
7b26da
     inserting step-resume breakpoint, so it doesn't make sense for
7b26da
     reverse-stepping, because we are just stepping from the target address.
7b26da
     And for forward-stepping, when we reach the very first instruction of
7b26da
     trampoline code, we can just skip the resolving code by inserting
7b26da
     a step-resume breakpoint, so we don't have to step through the resolving
7b26da
     code and check whether we are in the middle of trampoline code.
7b26da
7b26da
     in_dynsym_resolve_code is used to check whether we are in (the middle of)
7b26da
     the resolving code, so we can keep going to step though the resolving code.
7b26da
     Therefor I thought in_dynsym_resolve_code is the proper place to implement.
7b26da
7b26da
     Since skip-trampoline-code had implemented the plt-stub pattern-match code
7b26da
     we need, by calling it in in-dynsym-resolve-code, we don't need to have
7b26da
     duplicate pattern-match code in both functions.
7b26da
7b26da
  Wei-cheng,
7b26da
  Thanks
7b26da
7b26da
  --
7b26da
7b26da
  2014-12-06  Wei-cheng Wang  <cole945@gmail.com>
7b26da
7b26da
	      * ppc-linux-tdep.c (ppc_skip_trampoline_code):
7b26da
	      Scan PLT stub backward for reverse debugging.
7b26da
	      * ppc64-tdep.c (ppc64_skip_trampoline_code): Likewise.
7b26da
7b26da
7b26da
commit cf90fd9a07e8998540bf74f293d348a6653ac120
7b26da
Author: Wei-cheng Wang <cole945@gmail.com>
7b26da
Date:   Sat Jan 17 14:30:59 2015 +0800
7b26da
7b26da
    Skip-trampoline for PowerPC reverse-stepping.
7b26da
7b26da
Index: gdb-7.6.1/gdb/ppc64-tdep.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/ppc64-tdep.c
7b26da
+++ gdb-7.6.1/gdb/ppc64-tdep.c
7b26da
@@ -20,6 +20,7 @@
7b26da
 #include "defs.h"
7b26da
 #include "frame.h"
7b26da
 #include "gdbcore.h"
7b26da
+#include "inferior.h"
7b26da
 #include "ppc-tdep.h"
7b26da
 #include "ppc64-tdep.h"
7b26da
 #include "elf-bfd.h"
7b26da
@@ -464,35 +465,66 @@ ppc64_skip_trampoline_code (struct frame
7b26da
 				    ARRAY_SIZE (ppc64_standard_linkage8))))
7b26da
 		     - 1];
7b26da
   CORE_ADDR target;
7b26da
+  int scan_limit, i;
7b26da
 
7b26da
-  if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage8, insns))
7b26da
-    pc = ppc64_standard_linkage4_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7, insns))
7b26da
-    pc = ppc64_standard_linkage3_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6, insns))
7b26da
-    pc = ppc64_standard_linkage4_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5, insns)
7b26da
-	   && (insns[8] != 0 || insns[9] != 0))
7b26da
-    pc = ppc64_standard_linkage3_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4, insns)
7b26da
-	   && (insns[9] != 0 || insns[10] != 0))
7b26da
-    pc = ppc64_standard_linkage4_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3, insns)
7b26da
-	   && (insns[8] != 0 || insns[9] != 0))
7b26da
-    pc = ppc64_standard_linkage3_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2, insns)
7b26da
-	   && (insns[10] != 0 || insns[11] != 0))
7b26da
-    pc = ppc64_standard_linkage2_target (frame, pc, insns);
7b26da
-  else if (ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1, insns))
7b26da
-    pc = ppc64_standard_linkage1_target (frame, pc, insns);
7b26da
-  else
7b26da
-    return 0;
7b26da
-
7b26da
-  /* The PLT descriptor will either point to the already resolved target
7b26da
-     address, or else to a glink stub.  As the latter carry synthetic @plt
7b26da
-     symbols, find_solib_trampoline_target should be able to resolve them.  */
7b26da
-  target = find_solib_trampoline_target (frame, pc);
7b26da
-  return target ? target : pc;
7b26da
+  scan_limit = 1;
7b26da
+  /* When reverse-debugging, scan backward to check whether we are
7b26da
+     in the middle of trampoline code.  */
7b26da
+  if (execution_direction == EXEC_REVERSE)
7b26da
+    scan_limit = ARRAY_SIZE (insns) - 1;
7b26da
+
7b26da
+  for (i = 0; i < scan_limit; i++)
7b26da
+    {
7b26da
+      if (i < ARRAY_SIZE (ppc64_standard_linkage8) - 1
7b26da
+	  && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage8, insns))
7b26da
+	pc = ppc64_standard_linkage4_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage7) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage7,
7b26da
+					   insns))
7b26da
+	pc = ppc64_standard_linkage3_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage6) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage6,
7b26da
+					   insns))
7b26da
+	pc = ppc64_standard_linkage4_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage5) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage5,
7b26da
+					   insns)
7b26da
+	       && (insns[8] != 0 || insns[9] != 0))
7b26da
+	pc = ppc64_standard_linkage3_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage4) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage4,
7b26da
+					   insns)
7b26da
+	       && (insns[9] != 0 || insns[10] != 0))
7b26da
+	pc = ppc64_standard_linkage4_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage3) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage3,
7b26da
+					   insns)
7b26da
+	       && (insns[8] != 0 || insns[9] != 0))
7b26da
+	pc = ppc64_standard_linkage3_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage2) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage2,
7b26da
+					   insns)
7b26da
+	       && (insns[10] != 0 || insns[11] != 0))
7b26da
+	pc = ppc64_standard_linkage2_target (frame, pc, insns);
7b26da
+      else if (i < ARRAY_SIZE (ppc64_standard_linkage1) - 1
7b26da
+	       && ppc_insns_match_pattern (frame, pc, ppc64_standard_linkage1,
7b26da
+					   insns))
7b26da
+	pc = ppc64_standard_linkage1_target (frame, pc, insns);
7b26da
+      else
7b26da
+	{
7b26da
+	  /* Scan backward one more instructions if doesn't match.  */
7b26da
+	  pc -= 4;
7b26da
+	  continue;
7b26da
+	}
7b26da
+
7b26da
+      /* The PLT descriptor will either point to the already resolved target
7b26da
+         address, or else to a glink stub.  As the latter carry synthetic @plt
7b26da
+         symbols, find_solib_trampoline_target should be able to resolve them.  */
7b26da
+      target = find_solib_trampoline_target (frame, pc);
7b26da
+      return target ? target : pc;
7b26da
+  }
7b26da
+
7b26da
+  return 0;
7b26da
 }
7b26da
 
7b26da
 /* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64
7b26da
Index: gdb-7.6.1/gdb/ppc-linux-tdep.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/ppc-linux-tdep.c
7b26da
+++ gdb-7.6.1/gdb/ppc-linux-tdep.c
7b26da
@@ -52,6 +52,7 @@
7b26da
 #include "linux-tdep.h"
7b26da
 #include "linux-record.h"
7b26da
 #include "record-full.h"
7b26da
+#include "inferior.h"
7b26da
 
7b26da
 #include "stap-probe.h"
7b26da
 #include "ax.h"
7b26da
@@ -362,31 +363,50 @@ ppc_skip_trampoline_code (struct frame_i
7b26da
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
7b26da
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
7b26da
   CORE_ADDR target = 0;
7b26da
+  int scan_limit, i;
7b26da
 
7b26da
-  if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
7b26da
-    {
7b26da
-      /* Insn pattern is
7b26da
-		lis   r11, xxxx
7b26da
-		lwz   r11, xxxx(r11)
7b26da
-	 Branch target is in r11.  */
7b26da
-
7b26da
-      target = (ppc_insn_d_field (insnbuf[0]) << 16)
7b26da
-	| ppc_insn_d_field (insnbuf[1]);
7b26da
-      target = read_memory_unsigned_integer (target, 4, byte_order);
7b26da
-    }
7b26da
+  scan_limit = 1;
7b26da
+  /* When reverse-debugging, scan backward to check whether we are
7b26da
+     in the middle of trampoline code.  */
7b26da
+  if (execution_direction == EXEC_REVERSE)
7b26da
+    scan_limit = 4;	/* At more 4 instructions.  */
7b26da
 
7b26da
-  if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf))
7b26da
+  for (i = 0; i < scan_limit; i++)
7b26da
     {
7b26da
-      /* Insn pattern is
7b26da
-		lwz   r11, xxxx(r30)
7b26da
-	 Branch target is in r11.  */
7b26da
-
7b26da
-      target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30)
7b26da
-	       + ppc_insn_d_field (insnbuf[0]);
7b26da
-      target = read_memory_unsigned_integer (target, 4, byte_order);
7b26da
+      if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
7b26da
+	{
7b26da
+	  /* Insn pattern is
7b26da
+	     lis   r11, xxxx
7b26da
+	     lwz   r11, xxxx(r11)
7b26da
+	     Branch target is in r11.  */
7b26da
+
7b26da
+	  target = (ppc_insn_d_field (insnbuf[0]) << 16)
7b26da
+		   | ppc_insn_d_field (insnbuf[1]);
7b26da
+	  target = read_memory_unsigned_integer (target, 4, byte_order);
7b26da
+	}
7b26da
+      else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so,
7b26da
+					insnbuf))
7b26da
+	{
7b26da
+	  /* Insn pattern is
7b26da
+	     lwz   r11, xxxx(r30)
7b26da
+	     Branch target is in r11.  */
7b26da
+
7b26da
+	  target = get_frame_register_unsigned (frame,
7b26da
+						tdep->ppc_gp0_regnum + 30)
7b26da
+		   + ppc_insn_d_field (insnbuf[0]);
7b26da
+	  target = read_memory_unsigned_integer (target, 4, byte_order);
7b26da
+	}
7b26da
+      else
7b26da
+	{
7b26da
+	  /* Scan backward one more instructions if doesn't match.  */
7b26da
+	  pc -= 4;
7b26da
+	  continue;
7b26da
+	}
7b26da
+
7b26da
+      return target;
7b26da
     }
7b26da
 
7b26da
-  return target;
7b26da
+  return 0;
7b26da
 }
7b26da
 
7b26da
 /* Wrappers to handle Linux-only registers.  */