Blame SOURCES/gdb-6.3-ppc64syscall-20040622.patch

e1d87d
2004-06-22  Andrew Cagney  <cagney@gnu.org>
e1d87d
e1d87d
	* rs6000-tdep.c (struct rs6000_framedata): Add field "func_start".
e1d87d
	(skip_prologue): Delete local variable "orig_pc", use
e1d87d
	"func_start".  Add local variable "num_skip_linux_syscall_insn",
e1d87d
	use to skip over first half of a GNU/Linux syscall and update
e1d87d
	"func_start".
e1d87d
e1d87d
Index: gdb-7.2.50.20110117/gdb/rs6000-tdep.c
e1d87d
===================================================================
e1d87d
--- gdb-7.2.50.20110117.orig/gdb/rs6000-tdep.c	2011-01-11 20:23:02.000000000 +0100
e1d87d
+++ gdb-7.2.50.20110117/gdb/rs6000-tdep.c	2011-01-17 15:48:19.000000000 +0100
e1d87d
@@ -126,6 +126,7 @@ static const char *powerpc_vector_abi_st
e1d87d
 
e1d87d
 struct rs6000_framedata
e1d87d
   {
e1d87d
+    CORE_ADDR func_start;	/* True function start.  */
e1d87d
     int offset;			/* total size of frame --- the distance
e1d87d
 				   by which we decrement sp to allocate
e1d87d
 				   the frame */
e1d87d
@@ -1496,7 +1497,6 @@ static CORE_ADDR
e1d87d
 skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc, CORE_ADDR lim_pc,
e1d87d
 	       struct rs6000_framedata *fdata)
e1d87d
 {
e1d87d
-  CORE_ADDR orig_pc = pc;
e1d87d
   CORE_ADDR last_prologue_pc = pc;
e1d87d
   CORE_ADDR li_found_pc = 0;
e1d87d
   gdb_byte buf[4];
e1d87d
@@ -1514,12 +1514,14 @@ skip_prologue (struct gdbarch *gdbarch, 
e1d87d
   int minimal_toc_loaded = 0;
e1d87d
   int prev_insn_was_prologue_insn = 1;
e1d87d
   int num_skip_non_prologue_insns = 0;
e1d87d
+  int num_skip_ppc64_gnu_linux_syscall_insn = 0;
e1d87d
   int r0_contains_arg = 0;
e1d87d
   const struct bfd_arch_info *arch_info = gdbarch_bfd_arch_info (gdbarch);
e1d87d
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
e1d87d
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e1d87d
 
e1d87d
   memset (fdata, 0, sizeof (struct rs6000_framedata));
e1d87d
+  fdata->func_start = pc;
e1d87d
   fdata->saved_gpr = -1;
e1d87d
   fdata->saved_fpr = -1;
e1d87d
   fdata->saved_vr = -1;
e1d87d
@@ -1553,6 +1555,55 @@ skip_prologue (struct gdbarch *gdbarch, 
e1d87d
 	break;
e1d87d
       op = extract_unsigned_integer (buf, 4, byte_order);
e1d87d
 
e1d87d
+      /* A PPC64 GNU/Linux system call function is split into two
e1d87d
+	 sub-functions: a non-threaded fast-path (__NAME_nocancel)
e1d87d
+	 which does not use a frame; and a threaded slow-path
e1d87d
+	 (Lpseudo_cancel) that does create a frame.  Ref:
e1d87d
+	 nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
e1d87d
+
e1d87d
+	 *INDENT-OFF*
e1d87d
+	 NAME:
e1d87d
+	 	SINGLE_THREAD_P
e1d87d
+	 	bne- .Lpseudo_cancel
e1d87d
+	 __NAME_nocancel:
e1d87d
+	 	li r0,162
e1d87d
+	 	sc
e1d87d
+	 	bnslr+
e1d87d
+	 	b 0x7fe014ef64 <.__syscall_error>
e1d87d
+	 Lpseudo_cancel:
e1d87d
+	 	stdu r1,-128(r1)
e1d87d
+	 	...
e1d87d
+	 *INDENT-ON*
e1d87d
+
e1d87d
+	 Unfortunatly, because the latter case uses a local label (not
e1d87d
+	 in the symbol table) a PC in "Lpseudo_cancel" appears to be
e1d87d
+	 in "__NAME_nocancel".  The following code recognizes this,
e1d87d
+	 adjusting FUNC_START to point to where "Lpseudo_cancel"
e1d87d
+	 should be, and parsing the prologue sequence as if
e1d87d
+	 "Lpseudo_cancel" was the entry point.  */
e1d87d
+
e1d87d
+      if (((op & 0xffff0000) == 0x38000000 /* li r0,N */
e1d87d
+	   && pc == fdata->func_start + 0
e1d87d
+	   && num_skip_ppc64_gnu_linux_syscall_insn == 0)
e1d87d
+	  || (op == 0x44000002 /* sc */
e1d87d
+	      && pc == fdata->func_start + 4
e1d87d
+	      && num_skip_ppc64_gnu_linux_syscall_insn == 1)
e1d87d
+	  || (op == 0x4ca30020 /* bnslr+ */
e1d87d
+	      && pc == fdata->func_start + 8
e1d87d
+	      && num_skip_ppc64_gnu_linux_syscall_insn == 2))
e1d87d
+	{
e1d87d
+	  num_skip_ppc64_gnu_linux_syscall_insn++;
e1d87d
+	  continue;
e1d87d
+	}
e1d87d
+      else if ((op & 0xfc000003) == 0x48000000 /* b __syscall_error */
e1d87d
+	       && pc == fdata->func_start + 12
e1d87d
+	       && num_skip_ppc64_gnu_linux_syscall_insn == 3)
e1d87d
+	{
e1d87d
+	  num_skip_ppc64_gnu_linux_syscall_insn = -1;
e1d87d
+	  fdata->func_start = pc;
e1d87d
+	  continue;
e1d87d
+	}
e1d87d
+
e1d87d
       if ((op & 0xfc1fffff) == 0x7c0802a6)
e1d87d
 	{			/* mflr Rx */
e1d87d
 	  /* Since shared library / PIC code, which needs to get its
e1d87d
@@ -1734,9 +1785,9 @@ skip_prologue (struct gdbarch *gdbarch, 
e1d87d
 	     we have no line table information or the line info tells
e1d87d
 	     us that the subroutine call is not part of the line
e1d87d
 	     associated with the prologue.  */
e1d87d
-	  if ((pc - orig_pc) > 8)
e1d87d
+	  if ((pc - fdata->func_start) > 8)
e1d87d
 	    {
e1d87d
-	      struct symtab_and_line prologue_sal = find_pc_line (orig_pc, 0);
e1d87d
+	      struct symtab_and_line prologue_sal = find_pc_line (fdata->func_start, 0);
e1d87d
 	      struct symtab_and_line this_sal = find_pc_line (pc, 0);
e1d87d
 
e1d87d
 	      if ((prologue_sal.line == 0)