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

2c2fa1
  Message-ID: <54BD2C4B.7010102@gmail.com>
2c2fa1
  Date: Tue, 20 Jan 2015 00:09:47 +0800
2c2fa1
  From: Wei-cheng Wang <cole945 at gmail dot com>
2c2fa1
  To: Joel Brobecker <brobecker at adacore dot com>
2c2fa1
  CC: Ulrich Weigand <uweigand at de dot ibm dot com>, gdb-patches at sourceware dot org
2c2fa1
  Subject: Re: [PATCH 2/3 v4] Process record support for PowerPC
2c2fa1
2c2fa1
  On 2015/1/19 下午 03:48, Joel Brobecker wrote:
2c2fa1
  >> Using %s+paddress instead of %lx+long in this patch.
2c2fa1
  > The change looks fine to me, but there is no ChangeLog.
2c2fa1
2c2fa1
  Hi Joel,
2c2fa1
2c2fa1
  ChangeLog is in my last mail.  Re-post below for your review.
2c2fa1
2c2fa1
  2015-01-18  Wei-cheng Wang  <cole945@gmail.com>
2c2fa1
2c2fa1
	      * rs6000-tdep.c (ppc_process_record_op4, ppc_process_record_op19,
2c2fa1
	      ppc_process_record_op31, ppc_process_record_op59,
2c2fa1
	      ppc_process_record_op60, ppc_process_record_op63,
2c2fa1
	      ppc_process_record): Fix -Wformat warning.
2c2fa1
	      * rs6000-tdep.c (rs6000_epilogue_frame_cache, ppc_process_record_op60):
2c2fa1
	      Remove unused variables.
2c2fa1
2c2fa1
  > Also, I ended glancing at some of the patches you recently pushed,
2c2fa1
  > and noticed that you added a lot of new functions for which there
2c2fa1
  > is no introductory comment describing the function's behavior and
2c2fa1
  > arguments. It is now mandatory that all new functions, no matter
2c2fa1
  > how trivial, have such introductory comment. Would you mind going
2c2fa1
  > back over your patches, and send a patch that adds the missing
2c2fa1
  > comments, please?
2c2fa1
2c2fa1
  I've added the missing comments.  See below.
2c2fa1
2c2fa1
  Thanks,
2c2fa1
  Wei-cheng
2c2fa1
2c2fa1
2c2fa1
  2015-01-18  Wei-cheng Wang  <cole945@gmail.com>
2c2fa1
2c2fa1
	      * ppc-linux-tdep.c (ppc_skip_trampoline_code,
2c2fa1
	      ppc_canonicalize_syscall, ppc_linux_syscall_record,
2c2fa1
	      ppc_linux_record_signal, ppc_init_linux_record_tdep): Add comments.
2c2fa1
	      * ppc64-tdep.c (ppc64_skip_trampoline_code): Likewise.
2c2fa1
	      * rs6000-tdep.c (rs6000_epilogue_frame_cache,
2c2fa1
	      rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register,
2c2fa1
	      rs6000_epilogue_frame_sniffer, ppc_record_vsr, ppc_process_record_op4,
2c2fa1
	      ppc_process_record_op19, ppc_process_record_op31,
2c2fa1
	      ppc_process_record_op59, ppc_process_record_op60,
2c2fa1
	      ppc_process_record_op63): Likewise.
2c2fa1
2c2fa1
commit ddeca1dffbe346eea03b893bf3c5bc46e4439e93
2c2fa1
Author: Wei-cheng Wang <cole945@gmail.com>
2c2fa1
Date:   Mon Jan 19 23:34:07 2015 +0800
2c2fa1
2c2fa1
    Add missing comments in rs6000-tdep.c, ppc64-tdep.c and ppc-linux-tdep.c.
2c2fa1
    
2c2fa1
    gdb/ChangeLog:
2c2fa1
    
2c2fa1
    	* ppc-linux-tdep.c (ppc_skip_trampoline_code,
2c2fa1
    	ppc_canonicalize_syscall, ppc_linux_syscall_record,
2c2fa1
    	ppc_linux_record_signal, ppc_init_linux_record_tdep): Add comments.
2c2fa1
    	* ppc64-tdep.c (ppc64_skip_trampoline_code): Likewise.
2c2fa1
    	* rs6000-tdep.c (rs6000_epilogue_frame_cache,
2c2fa1
    	rs6000_epilogue_frame_this_id, rs6000_epilogue_frame_prev_register,
2c2fa1
    	rs6000_epilogue_frame_sniffer, ppc_record_vsr, ppc_process_record_op4,
2c2fa1
    	ppc_process_record_op19, ppc_process_record_op31,
2c2fa1
    	ppc_process_record_op59, ppc_process_record_op60,
2c2fa1
    	ppc_process_record_op63): Likewise.
2c2fa1
2c2fa1
Index: gdb-7.6.1/gdb/ppc64-tdep.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/ppc64-tdep.c
2c2fa1
+++ gdb-7.6.1/gdb/ppc64-tdep.c
2c2fa1
@@ -449,7 +449,10 @@ ppc64_standard_linkage4_target (struct f
2c2fa1
 
2c2fa1
 
2c2fa1
 /* Given that we've begun executing a call trampoline at PC, return
2c2fa1
-   the entry point of the function the trampoline will go to.  */
2c2fa1
+   the entry point of the function the trampoline will go to.
2c2fa1
+
2c2fa1
+   When the execution direction is EXEC_REVERSE, scan backward to
2c2fa1
+   check whether we are in the middle of a PLT stub.  */
2c2fa1
 
2c2fa1
 CORE_ADDR
2c2fa1
 ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
2c2fa1
Index: gdb-7.6.1/gdb/ppc-linux-tdep.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/ppc-linux-tdep.c
2c2fa1
+++ gdb-7.6.1/gdb/ppc-linux-tdep.c
2c2fa1
@@ -353,7 +353,12 @@ powerpc_linux_in_dynsym_resolve_code (CO
2c2fa1
   return 0;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Follow PLT stub to actual routine.  */
2c2fa1
+/* Follow PLT stub to actual routine.
2c2fa1
+
2c2fa1
+   When the execution direction is EXEC_REVERSE, scan backward to
2c2fa1
+   check whether we are in the middle of a PLT stub.  Currently,
2c2fa1
+   we only look-behind at most 4 instructions (the max length of PLT
2c2fa1
+   stub sequence.  */
2c2fa1
 
2c2fa1
 static CORE_ADDR
2c2fa1
 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
2c2fa1
@@ -839,11 +844,16 @@ ppc_linux_get_syscall_number (struct gdb
2c2fa1
 static struct linux_record_tdep ppc_linux_record_tdep;
2c2fa1
 static struct linux_record_tdep ppc64_linux_record_tdep;
2c2fa1
 
2c2fa1
+/* ppc_canonicalize_syscall maps from the native PowerPC Linux set of
2c2fa1
+   syscall ids into a canonical set of syscall ids used by process
2c2fa1
+   record.  (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.)
2c2fa1
+   Return -1 if this system call is not supported by process record.
2c2fa1
+   Otherwise, return the syscall number for preocess reocrd of given
2c2fa1
+   SYSCALL.  */
2c2fa1
+
2c2fa1
 static enum gdb_syscall
2c2fa1
 ppc_canonicalize_syscall (int syscall)
2c2fa1
 {
2c2fa1
-  /* See arch/powerpc/include/uapi/asm/unistd.h */
2c2fa1
-
2c2fa1
   if (syscall <= 165)
2c2fa1
     return syscall;
2c2fa1
   else if (syscall >= 167 && syscall <= 190)	/* Skip query_module 166 */
2c2fa1
@@ -869,6 +879,9 @@ ppc_canonicalize_syscall (int syscall)
2c2fa1
   return -1;
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Record registers which might be clobbered during system call.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
+
2c2fa1
 static int
2c2fa1
 ppc_linux_syscall_record (struct regcache *regcache)
2c2fa1
 {
2c2fa1
@@ -949,6 +962,9 @@ ppc_linux_syscall_record (struct regcach
2c2fa1
   return 0;
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Record registers which might be clobbered during signal handling.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
+
2c2fa1
 static int
2c2fa1
 ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
2c2fa1
 			 enum gdb_signal signal)
2c2fa1
@@ -1470,7 +1486,9 @@ static const struct frame_unwind ppu2spu
2c2fa1
   ppu2spu_prev_arch,
2c2fa1
 };
2c2fa1
 
2c2fa1
-/* Initialize linux_record_tdep if not initialized yet.  */
2c2fa1
+/* Initialize linux_record_tdep if not initialized yet.
2c2fa1
+   WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
2c2fa1
+   Sizes of data structures are initialized accordingly.  */
2c2fa1
 
2c2fa1
 static void
2c2fa1
 ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
2c2fa1
Index: gdb-7.6.1/gdb/rs6000-tdep.c
2c2fa1
===================================================================
2c2fa1
--- gdb-7.6.1.orig/gdb/rs6000-tdep.c
2c2fa1
+++ gdb-7.6.1/gdb/rs6000-tdep.c
2c2fa1
@@ -3398,6 +3398,9 @@ static const struct frame_unwind rs6000_
2c2fa1
   default_frame_sniffer
2c2fa1
 };
2c2fa1
 
2c2fa1
+/* Allocate and initialize a frame cache for an epilogue frame.
2c2fa1
+   SP is restored and prev-PC is stored in LR.  */
2c2fa1
+
2c2fa1
 static struct rs6000_frame_cache *
2c2fa1
 rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
2c2fa1
 {
2c2fa1
@@ -3434,6 +3437,9 @@ rs6000_epilogue_frame_cache (struct fram
2c2fa1
   return cache;
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Implementation of frame_unwind.this_id, as defined in frame_unwind.h.
2c2fa1
+   Return the frame ID of an epilogue frame.  */
2c2fa1
+
2c2fa1
 static void
2c2fa1
 rs6000_epilogue_frame_this_id (struct frame_info *this_frame,
2c2fa1
 			       void **this_cache, struct frame_id *this_id)
2c2fa1
@@ -3449,6 +3455,9 @@ rs6000_epilogue_frame_this_id (struct fr
2c2fa1
     (*this_id) = frame_id_build (info->base, pc);
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Implementation of frame_unwind.prev_register, as defined in frame_unwind.h.
2c2fa1
+   Return the register value of REGNUM in previous frame.  */
2c2fa1
+
2c2fa1
 static struct value *
2c2fa1
 rs6000_epilogue_frame_prev_register (struct frame_info *this_frame,
2c2fa1
 				     void **this_cache, int regnum)
2c2fa1
@@ -3458,6 +3467,9 @@ rs6000_epilogue_frame_prev_register (str
2c2fa1
   return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Implementation of frame_unwind.sniffer, as defined in frame_unwind.h.
2c2fa1
+   Check whether this an epilogue frame.  */
2c2fa1
+
2c2fa1
 static int
2c2fa1
 rs6000_epilogue_frame_sniffer (const struct frame_unwind *self,
2c2fa1
 			       struct frame_info *this_frame,
2c2fa1
@@ -3471,6 +3483,9 @@ rs6000_epilogue_frame_sniffer (const str
2c2fa1
     return 0;
2c2fa1
 }
2c2fa1
 
2c2fa1
+/* Frame unwinder for epilogue frame.  This is required for reverse step-over
2c2fa1
+   a function without debug information.  */
2c2fa1
+
2c2fa1
 static const struct frame_unwind rs6000_epilogue_frame_unwind =
2c2fa1
 {
2c2fa1
   NORMAL_FRAME,
2c2fa1
@@ -3717,7 +3732,9 @@ bfd_uses_spe_extensions (bfd *abfd)
2c2fa1
 #define PPC_XT(insn)	((PPC_TX (insn) << 5) | PPC_T (insn))
2c2fa1
 #define PPC_XER_NB(xer)	(xer & 0x7f)
2c2fa1
 
2c2fa1
-/* Record Vector-Scalar Registers.  */
2c2fa1
+/* Record Vector-Scalar Registers.
2c2fa1
+   For VSR less than 32, it's represented by an FPR and an VSR-upper register.
2c2fa1
+   Otherwise, it's just a VR register.  Record them accordingly.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_record_vsr (struct regcache *regcache, struct gdbarch_tdep *tdep, int vsr)
2c2fa1
@@ -3742,11 +3759,12 @@ ppc_record_vsr (struct regcache *regcach
2c2fa1
   return 0;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Parse instructions of primary opcode-4.  */
2c2fa1
+/* Parse and record instructions primary opcode-4 at ADDR.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_process_record_op4 (struct gdbarch *gdbarch, struct regcache *regcache,
2c2fa1
-			   CORE_ADDR addr, uint32_t insn)
2c2fa1
+			CORE_ADDR addr, uint32_t insn)
2c2fa1
 {
2c2fa1
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2c2fa1
   int ext = PPC_FIELD (insn, 21, 11);
2c2fa1
@@ -4010,7 +4028,8 @@ ppc_process_record_op4 (struct gdbarch *
2c2fa1
   return -1;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Parse instructions of primary opcode-19.  */
2c2fa1
+/* Parse and record instructions of primary opcode-19 at ADDR.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_process_record_op19 (struct gdbarch *gdbarch, struct regcache *regcache,
2c2fa1
@@ -4053,7 +4072,8 @@ ppc_process_record_op19 (struct gdbarch
2c2fa1
   return -1;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Parse instructions of primary opcode-31.  */
2c2fa1
+/* Parse and record instructions of primary opcode-31 at ADDR.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_process_record_op31 (struct gdbarch *gdbarch, struct regcache *regcache,
2c2fa1
@@ -4531,7 +4551,8 @@ UNKNOWN_OP:
2c2fa1
   return -1;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Parse instructions of primary opcode-59.  */
2c2fa1
+/* Parse and record instructions of primary opcode-59 at ADDR.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_process_record_op59 (struct gdbarch *gdbarch, struct regcache *regcache,
2c2fa1
@@ -4623,7 +4644,8 @@ ppc_process_record_op59 (struct gdbarch
2c2fa1
   return -1;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Parse instructions of primary opcode-60.  */
2c2fa1
+/* Parse and record instructions of primary opcode-60 at ADDR.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_process_record_op60 (struct gdbarch *gdbarch, struct regcache *regcache,
2c2fa1
@@ -4905,7 +4927,8 @@ ppc_process_record_op60 (struct gdbarch
2c2fa1
   return -1;
2c2fa1
 }
2c2fa1
 
2c2fa1
-/* Parse instructions of primary opcode-63.  */
2c2fa1
+/* Parse and record instructions of primary opcode-63 at ADDR.
2c2fa1
+   Return 0 if successful.  */
2c2fa1
 
2c2fa1
 static int
2c2fa1
 ppc_process_record_op63 (struct gdbarch *gdbarch, struct regcache *regcache,