b961095
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=216711
b961095
407ebe9
FIXME: This workaround should be dropped and
407ebe9
glibc/sysdeps/unix/sysv/linux/x86_64/clone.S should get CFI for the child
407ebe9
instead.
b961095
b961095
2006-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
b961095
b961095
	* gdb/amd64-linux-tdep.c (linux_clone_code): New variable.
b961095
	(LINUX_CLONE_LEN): New definition.
b961095
	(amd64_linux_clone_running, amd64_linux_outermost_frame): New function.
b961095
	(amd64_linux_init_abi): Initialize `outermost_frame_p'.
b961095
	* gdb/i386-tdep.c (i386_gdbarch_init): Likewise.
b961095
	* gdb/i386-tdep.h (gdbarch_tdep): Add `outermost_frame_p' member.
b961095
	* gdb/amd64-tdep.c (amd64_frame_this_id): Call `outermost_frame_p'.
b961095
b961095
2006-12-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
b961095
b961095
	* gdb.threads/bt-clone-stop.exp, gdb.threads/bt-clone-stop.c:
b961095
	New file.
b961095
eb9d945
2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
b961095
eb9d945
	Port to GDB-6.7.
eb9d945
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/amd64-linux-tdep.c
Jan Kratochvil fb75065
===================================================================
Jan Kratochvil 2c55a54
--- gdb-7.6.90.20140127.orig/gdb/amd64-linux-tdep.c	2014-02-04 23:40:06.263483469 +0100
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/amd64-linux-tdep.c	2014-02-04 23:47:18.438009290 +0100
Jan Kratochvil 2c55a54
@@ -289,6 +289,80 @@ amd64_linux_register_reggroup_p (struct
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
 /* Set the program counter for process PTID to PC.  */
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
+/* Detect the outermost frame; during unwind of
Jan Kratochvil fb75065
+   	#5  0x000000305cec68c3 in clone () from /lib64/tls/libc.so.6
Jan Kratochvil fb75065
+   avoid the additional bogus frame
Jan Kratochvil fb75065
+   	#6  0x0000000000000000 in ??
Jan Kratochvil fb75065
+   We compare if the `linux_clone_code' block is _before_ unwound PC.  */
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static const unsigned char linux_clone_code[] =
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+/* libc/sysdeps/unix/sysv/linux/x86_64/clone.S */
Jan Kratochvil fb75065
+/* #ifdef RESET_PID */
Jan Kratochvil fb75065
+/* ... */
Jan Kratochvil fb75065
+/* 	mov	$SYS_ify(getpid), %eax */
Jan Kratochvil fb75065
+/* 0xb8, 0x27, 0x00, 0x00, 0x00 */
Jan Kratochvil fb75065
+/* OR */
Jan Kratochvil fb75065
+/* 	mov	$SYS_ify(getpid), %rax */
Jan Kratochvil fb75065
+/* 0x48, 0xc7, 0xc0, 0x27, 0x00, 0x00, 0x00 */
Jan Kratochvil fb75065
+/* so just: */
Jan Kratochvil fb75065
+  0x27, 0x00, 0x00, 0x00,
Jan Kratochvil fb75065
+/* 	syscall */
Jan Kratochvil fb75065
+  0x0f, 0x05,
Jan Kratochvil fb75065
+/* 	movl	%eax, %fs:PID */
Jan Kratochvil fb75065
+  0x64, 0x89, 0x04, 0x25, 0x94, 0x00, 0x00, 0x00,
Jan Kratochvil fb75065
+/* 	movl	%eax, %fs:TID */
Jan Kratochvil fb75065
+  0x64, 0x89, 0x04, 0x25, 0x90, 0x00, 0x00, 0x00,
Jan Kratochvil fb75065
+/* #endif */
Jan Kratochvil fb75065
+/* 	|* Set up arguments for the function call.  *| */
Jan Kratochvil fb75065
+/* 	popq	%rax		|* Function to call.  *| */
Jan Kratochvil fb75065
+  0x58,
Jan Kratochvil fb75065
+/* 	popq	%rdi		|* Argument.  *| */
Jan Kratochvil fb75065
+  0x5f,
Jan Kratochvil fb75065
+/* 	call	*%rax$   */
Jan Kratochvil fb75065
+  0xff, 0xd0
Jan Kratochvil fb75065
+};
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+#define LINUX_CLONE_LEN (sizeof linux_clone_code)
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static int
Jan Kratochvil fb75065
+amd64_linux_clone_running (struct frame_info *this_frame)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  CORE_ADDR pc = get_frame_pc (this_frame);
Jan Kratochvil fb75065
+  unsigned char buf[LINUX_CLONE_LEN];
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_LEN, buf,
Jan Kratochvil fb75065
+				 LINUX_CLONE_LEN))
Jan Kratochvil fb75065
+    return 0;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  if (memcmp (buf, linux_clone_code, LINUX_CLONE_LEN) != 0)
Jan Kratochvil fb75065
+    return 0;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  return 1;
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static int
Jan Kratochvil fb75065
+amd64_linux_outermost_frame (struct frame_info *this_frame)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  CORE_ADDR pc = get_frame_pc (this_frame);
Jan Kratochvil f8eee05
+  const char *name;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  find_pc_partial_function (pc, &name, NULL, NULL);
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  /* If we have NAME, we can optimize the search.
Jan Kratochvil fb75065
+     `clone' NAME still needs to have the code checked as its name may be
Jan Kratochvil fb75065
+     present in the user code.
Jan Kratochvil fb75065
+     `__clone' NAME should not be present in the user code but in the initial
Jan Kratochvil fb75065
+     parts of the `__clone' implementation the unwind still makes sense.
Jan Kratochvil fb75065
+     More detailed unwinding decision would be too much sensitive to possible
Jan Kratochvil fb75065
+     subtle changes in specific glibc revisions.  */
Jan Kratochvil fb75065
+  if (name == NULL || strcmp (name, "clone") == 0
Jan Kratochvil fb75065
+      || strcmp ("__clone", name) == 0)
Jan Kratochvil fb75065
+    return (amd64_linux_clone_running (this_frame) != 0);
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  return 0;
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
 static void
Jan Kratochvil fb75065
 amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
Jan Kratochvil fb75065
 {
Jan Kratochvil 2c55a54
@@ -1607,6 +1681,8 @@ amd64_linux_init_abi_common(struct gdbar
Jan Kratochvil fb75065
 
Jan Kratochvil 2c55a54
   tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
+  tdep->outermost_frame_p = amd64_linux_outermost_frame;
Jan Kratochvil fb75065
+
Jan Kratochvil 2c55a54
   /* Add the %orig_rax register used for syscall restarting.  */
Jan Kratochvil 2c55a54
   set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc);
Jan Kratochvil 2c55a54
 
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/amd64-tdep.c
Jan Kratochvil fb75065
===================================================================
Jan Kratochvil 2c55a54
--- gdb-7.6.90.20140127.orig/gdb/amd64-tdep.c	2014-02-04 23:40:06.265483471 +0100
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/amd64-tdep.c	2014-02-04 23:45:40.846891653 +0100
Jan Kratochvil 2c55a54
@@ -2359,6 +2359,7 @@ amd64_frame_unwind_stop_reason (struct f
Jan Kratochvil fb75065
 {
Jan Kratochvil fb75065
   struct amd64_frame_cache *cache =
Jan Kratochvil fb75065
     amd64_frame_cache (this_frame, this_cache);
Jan Kratochvil fb75065
+  struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
   if (!cache->base_p)
Jan Kratochvil fb75065
     return UNWIND_UNAVAILABLE;
Jan Kratochvil 2c55a54
@@ -2367,6 +2368,10 @@ amd64_frame_unwind_stop_reason (struct f
Jan Kratochvil fb75065
   if (cache->base == 0)
Jan Kratochvil fb75065
     return UNWIND_OUTERMOST;
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
+  /* Detect OS dependent outermost frames; such as `clone'.  */
Jan Kratochvil fb75065
+  if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
Jan Kratochvil fb75065
+    return UNWIND_OUTERMOST;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
   return UNWIND_NO_REASON;
Jan Kratochvil fb75065
 }
Jan Kratochvil fb75065
 
Jan Kratochvil 2c55a54
@@ -2498,6 +2503,7 @@ amd64_sigtramp_frame_this_id (struct fra
Jan Kratochvil fb75065
 {
Jan Kratochvil fb75065
   struct amd64_frame_cache *cache =
Jan Kratochvil 2c55a54
     amd64_sigtramp_frame_cache (this_frame, this_cache);
Jan Kratochvil fb75065
+  struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
   if (!cache->base_p)
Jan Kratochvil 2c55a54
     (*this_id) = frame_id_build_unavailable_stack (get_frame_pc (this_frame));
Jan Kratochvil 2c55a54
@@ -2506,6 +2512,11 @@ amd64_sigtramp_frame_this_id (struct fra
Jan Kratochvil 2c55a54
       /* This marks the outermost frame.  */
Jan Kratochvil 2c55a54
       return;
Jan Kratochvil 2c55a54
     }
Jan Kratochvil 2c55a54
+  else if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
Jan Kratochvil 2c55a54
+    {
Jan Kratochvil 2c55a54
+      /* Detect OS dependent outermost frames; such as `clone'.  */
Jan Kratochvil 2c55a54
+      return;
Jan Kratochvil 2c55a54
+    }
Jan Kratochvil 2c55a54
   else
Jan Kratochvil 2c55a54
     (*this_id) = frame_id_build (cache->base + 16, get_frame_pc (this_frame));
Jan Kratochvil fb75065
 }
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/i386-tdep.c
Jan Kratochvil fb75065
===================================================================
Jan Kratochvil 2c55a54
--- gdb-7.6.90.20140127.orig/gdb/i386-tdep.c	2014-02-04 23:40:06.267483473 +0100
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/i386-tdep.c	2014-02-04 23:43:33.048734974 +0100
Jan Kratochvil 2c55a54
@@ -7830,6 +7830,9 @@ i386_gdbarch_init (struct gdbarch_info i
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
   tdep->xsave_xcr0_offset = -1;
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
+  /* Unwinding stops on i386 automatically.  */
Jan Kratochvil fb75065
+  tdep->outermost_frame_p = NULL;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
   tdep->record_regmap = i386_record_regmap;
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
   set_gdbarch_long_long_align_bit (gdbarch, 32);
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/i386-tdep.h
Jan Kratochvil fb75065
===================================================================
Jan Kratochvil 2c55a54
--- gdb-7.6.90.20140127.orig/gdb/i386-tdep.h	2014-02-04 23:40:06.268483475 +0100
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/i386-tdep.h	2014-02-04 23:43:33.048734974 +0100
Jan Kratochvil 2c55a54
@@ -192,6 +192,9 @@ struct gdbarch_tdep
Jan Kratochvil fb75065
   int (*i386_sysenter_record) (struct regcache *regcache);
Jan Kratochvil fb75065
   /* Parse syscall args.  */
Jan Kratochvil fb75065
   int (*i386_syscall_record) (struct regcache *regcache);
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  /* Detect OS dependent outermost frames; such as `clone'.  */
Jan Kratochvil fb75065
+  int (*outermost_frame_p) (struct frame_info *this_frame);
Jan Kratochvil fb75065
 };
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
 /* Floating-point registers.  */
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/ia64-tdep.c
Jan Kratochvil fb75065
===================================================================
Jan Kratochvil 2c55a54
--- gdb-7.6.90.20140127.orig/gdb/ia64-tdep.c	2014-02-04 23:40:06.270483477 +0100
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/ia64-tdep.c	2014-02-04 23:43:33.049734975 +0100
Jan Kratochvil f8eee05
@@ -2176,6 +2176,138 @@ static const struct frame_unwind ia64_fr
Jan Kratochvil fb75065
   default_frame_sniffer
Jan Kratochvil fb75065
 };
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
+/* Detect the outermost frame; during unwind of
Jan Kratochvil fb75065
+   	#6  0x2000000000347100 in __clone2 () from /lib/libc.so.6.1
Jan Kratochvil fb75065
+   avoid the additional bogus frame
Jan Kratochvil fb75065
+   	#7  0x0000000000000000 in ?? ()  */
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static char linux_clone2_code[] =
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+/* libc/sysdeps/unix/sysv/linux/ia64/clone2.S */
Jan Kratochvil fb75065
+  0x09, 0x00, 0x20, 0x12, 0x90, 0x11, 0x00, 0x40,
Jan Kratochvil fb75065
+  0x28, 0x20, 0x23, 0x00, 0x00, 0x00, 0x04, 0x00,
Jan Kratochvil fb75065
+/*         st4 [r9]=r8 */
Jan Kratochvil fb75065
+/*         st4 [r10]=r8 */
Jan Kratochvil fb75065
+/*         ;; */
Jan Kratochvil fb75065
+/* #endif */
Jan Kratochvil fb75065
+  0x02, 0x50, 0x21, 0x40, 0x18, 0x14, 0x90, 0x02,
Jan Kratochvil fb75065
+  0x90, 0x00, 0x42, 0x00, 0x00, 0x00, 0x04, 0x00,
Jan Kratochvil fb75065
+/* 1:      ld8 out1=[in0],8        |* Retrieve code pointer.       *| */
Jan Kratochvil fb75065
+/*         mov out0=in4            |* Pass proper argument to fn *| */
Jan Kratochvil fb75065
+/*         ;; */
Jan Kratochvil fb75065
+  0x11, 0x08, 0x00, 0x40, 0x18, 0x10, 0x60, 0x50,
Jan Kratochvil fb75065
+  0x05, 0x80, 0x03, 0x00, 0x68, 0x00, 0x80, 0x12,
Jan Kratochvil fb75065
+/*         ld8 gp=[in0]            |* Load function gp.            *| */
Jan Kratochvil fb75065
+/*         mov b6=out1 */
Jan Kratochvil fb75065
+/*         br.call.dptk.many rp=b6 |* Call fn(arg) in the child    *| */
Jan Kratochvil fb75065
+/*         ;; */
Jan Kratochvil fb75065
+  0x10, 0x48, 0x01, 0x10, 0x00, 0x21, 0x10, 0x00,
Jan Kratochvil fb75065
+  0xa0, 0x00, 0x42, 0x00, 0x98, 0xdf, 0xf7, 0x5b,
Jan Kratochvil fb75065
+/*         mov out0=r8             |* Argument to _exit            *| */
Jan Kratochvil fb75065
+/*         mov gp=loc0 */
Jan Kratochvil fb75065
+/*         .globl HIDDEN_JUMPTARGET(_exit) */
Jan Kratochvil fb75065
+/*         br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit) */
Jan Kratochvil fb75065
+/*                                 |* call _exit with result from fn.      *| */
Jan Kratochvil fb75065
+  0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
Jan Kratochvil fb75065
+  0x00, 0x02, 0x00, 0x80, 0x00, 0x00, 0x84, 0x00
Jan Kratochvil fb75065
+/*         ret                     |* Not reached.         *| */
Jan Kratochvil fb75065
+};
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+#define LINUX_CLONE_PRE_SLOTS 3	/* Number of slots before PC.  */
Jan Kratochvil fb75065
+#define LINUX_CLONE_LEN (sizeof linux_clone2_code)
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static int
Jan Kratochvil fb75065
+ia64_linux_clone2_running (struct frame_info *this_frame)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  CORE_ADDR pc = get_frame_pc (this_frame);
Jan Kratochvil fb75065
+  char buf[LINUX_CLONE_LEN];
Jan Kratochvil fb75065
+  struct minimal_symbol *minsym;
Jan Kratochvil fb75065
+  long long instr;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_PRE_SLOTS * 16,
Jan Kratochvil fb75065
+				 buf, LINUX_CLONE_LEN))
Jan Kratochvil fb75065
+    return 0;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  if (memcmp (buf, linux_clone2_code, LINUX_CLONE_PRE_SLOTS * 16) != 0)
Jan Kratochvil fb75065
+    return 0;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  /* Adjust the expected "_exit" address.  */
Jan Kratochvil fb75065
+  minsym = lookup_minimal_symbol_text ("_exit", NULL);
Jan Kratochvil fb75065
+  if (minsym == NULL)
Jan Kratochvil fb75065
+    return 0;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  instr = slotN_contents (&linux_clone2_code[LINUX_CLONE_PRE_SLOTS * 16], 2);
Jan Kratochvil fb75065
+  instr &= ~(((1L << 20) - 1) << 13);
Jan Kratochvil fb75065
+  /* Address is relative to the jump instruction slot, not the next one.  */
Jan Kratochvil fb75065
+  instr |= (((SYMBOL_VALUE_ADDRESS (minsym) - (pc & ~0xfL)) >> 4)
Jan Kratochvil fb75065
+	    & ((1L << 20) - 1)) << 13;
Jan Kratochvil fb75065
+  replace_slotN_contents (&linux_clone2_code[LINUX_CLONE_PRE_SLOTS * 16], instr,
Jan Kratochvil fb75065
+			  2);
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  if (memcmp (&buf[LINUX_CLONE_PRE_SLOTS * 16],
Jan Kratochvil fb75065
+              &linux_clone2_code[LINUX_CLONE_PRE_SLOTS * 16],
Jan Kratochvil fb75065
+	      LINUX_CLONE_LEN - (LINUX_CLONE_PRE_SLOTS * 16)) != 0)
Jan Kratochvil fb75065
+    return 0;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  return 1;
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static int
Jan Kratochvil fb75065
+ia64_outermost_frame (struct frame_info *this_frame)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  CORE_ADDR pc = get_frame_pc (this_frame);
Jan Kratochvil fb75065
+  char *name;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  find_pc_partial_function (pc, &name, NULL, NULL);
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  /* If we have NAME, we can optimize the search.
Jan Kratochvil fb75065
+     `clone' NAME still needs to have the code checked as its name may be
Jan Kratochvil fb75065
+     present in the user code.
Jan Kratochvil fb75065
+     `__clone' NAME should not be present in the user code but in the initial
Jan Kratochvil fb75065
+     parts of the `__clone' implementation the unwind still makes sense.
Jan Kratochvil fb75065
+     More detailed unwinding decision would be too much sensitive to possible
Jan Kratochvil fb75065
+     subtle changes in specific glibc revisions.  */
Jan Kratochvil fb75065
+  if (name == NULL || strcmp (name, "clone2") == 0
Jan Kratochvil fb75065
+      || strcmp ("__clone2", name) == 0)
Jan Kratochvil fb75065
+    return (ia64_linux_clone2_running (this_frame) != 0);
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  return 0;
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static void
Jan Kratochvil fb75065
+ia64_clone2_frame_this_id (struct frame_info *this_frame, void **this_cache,
Jan Kratochvil fb75065
+			   struct frame_id *this_id)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  /* Leave the default outermost frame at *THIS_ID.  */
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static struct value *
Jan Kratochvil fb75065
+ia64_clone2_frame_prev_register (struct frame_info *this_frame,
Jan Kratochvil fb75065
+				 void **this_cache, int regnum)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  return frame_unwind_got_register (this_frame, regnum, regnum);
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static int
Jan Kratochvil fb75065
+ia64_clone2_frame_sniffer (const struct frame_unwind *self,
Jan Kratochvil fb75065
+			   struct frame_info *this_frame,
Jan Kratochvil fb75065
+			   void **this_prologue_cache)
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  if (ia64_outermost_frame (this_frame))
Jan Kratochvil fb75065
+    return 1;
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+  return 0;
Jan Kratochvil fb75065
+}
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
+static const struct frame_unwind ia64_clone2_frame_unwind =
Jan Kratochvil fb75065
+{
Jan Kratochvil fb75065
+  NORMAL_FRAME,
Jan Kratochvil fb75065
+  &ia64_clone2_frame_this_id,
Jan Kratochvil fb75065
+  &ia64_clone2_frame_prev_register,
Jan Kratochvil fb75065
+  NULL,
Jan Kratochvil fb75065
+  &ia64_clone2_frame_sniffer
Jan Kratochvil fb75065
+};
Jan Kratochvil fb75065
+
Jan Kratochvil fb75065
 /* Signal trampolines.  */
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
 static void
Jan Kratochvil 2c55a54
@@ -4023,6 +4155,7 @@ ia64_gdbarch_init (struct gdbarch_info i
Jan Kratochvil fb75065
   set_gdbarch_dummy_id (gdbarch, ia64_dummy_id);
Jan Kratochvil fb75065
 
Jan Kratochvil fb75065
   set_gdbarch_unwind_pc (gdbarch, ia64_unwind_pc);
Jan Kratochvil fb75065
+  frame_unwind_append_unwinder (gdbarch, &ia64_clone2_frame_unwind);
Jan Kratochvil fb75065
 #ifdef HAVE_LIBUNWIND_IA64_H
Jan Kratochvil fb75065
   frame_unwind_append_unwinder (gdbarch,
Jan Kratochvil fb75065
                                 &ia64_libunwind_sigtramp_frame_unwind);
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/testsuite/gdb.threads/bt-clone-stop.c
Jan Kratochvil fb75065
===================================================================
eb9d945
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/testsuite/gdb.threads/bt-clone-stop.c	2014-02-04 23:43:33.050734976 +0100
b961095
@@ -0,0 +1,39 @@
b961095
+/* This testcase is part of GDB, the GNU debugger.
b961095
+
b961095
+   Copyright 2006 Free Software Foundation, Inc.
b961095
+
b961095
+   This program is free software; you can redistribute it and/or modify
b961095
+   it under the terms of the GNU General Public License as published by
b961095
+   the Free Software Foundation; either version 2 of the License, or
b961095
+   (at your option) any later version.
b961095
+
b961095
+   This program is distributed in the hope that it will be useful,
b961095
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b961095
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b961095
+   GNU General Public License for more details.
b961095
+ 
b961095
+   You should have received a copy of the GNU General Public License
b961095
+   along with this program; if not, write to the Free Software
b961095
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
b961095
+   MA 02110-1301, USA.  */
b961095
+
b961095
+
b961095
+#include <pthread.h>
b961095
+#include <unistd.h>
b961095
+#include <assert.h>
b961095
+
b961095
+
b961095
+void *threader (void *arg)
b961095
+{
b961095
+	assert (0);
b961095
+	return NULL;
b961095
+}
b961095
+
b961095
+int main (void)
b961095
+{
b961095
+	pthread_t t1;
b961095
+
b961095
+	pthread_create (&t1, NULL, threader, (void *) NULL);
b961095
+	for (;;)
b961095
+		pause();
b961095
+}
Jan Kratochvil 2c55a54
Index: gdb-7.6.90.20140127/gdb/testsuite/gdb.threads/bt-clone-stop.exp
eb9d945
===================================================================
eb9d945
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
Jan Kratochvil 2c55a54
+++ gdb-7.6.90.20140127/gdb/testsuite/gdb.threads/bt-clone-stop.exp	2014-02-04 23:43:33.050734976 +0100
b961095
@@ -0,0 +1,61 @@
b961095
+# Copyright 2006 Free Software Foundation, Inc.
b961095
+
b961095
+# This program is free software; you can redistribute it and/or modify
b961095
+# it under the terms of the GNU General Public License as published by
b961095
+# the Free Software Foundation; either version 2 of the License, or
b961095
+# (at your option) any later version.
b961095
+# 
b961095
+# This program is distributed in the hope that it will be useful,
b961095
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
b961095
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b961095
+# GNU General Public License for more details.
b961095
+# 
b961095
+# You should have received a copy of the GNU General Public License
b961095
+# along with this program; if not, write to the Free Software
b961095
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
b961095
+
b961095
+# Backtraced `clone' must not have `PC == 0' as its previous frame.
b961095
+
b961095
+if $tracelevel then {
b961095
+    strace $tracelevel
b961095
+}
b961095
+
b961095
+set testfile bt-clone-stop
b961095
+set srcfile ${testfile}.c
b961095
+set binfile ${objdir}/${subdir}/${testfile}
b961095
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b961095
+    untested "Couldn't compile test program"
b961095
+    return -1
b961095
+}
b961095
+
b961095
+# Get things started.
b961095
+
b961095
+gdb_exit
b961095
+gdb_start
b961095
+gdb_reinitialize_dir $srcdir/$subdir
b961095
+gdb_load ${binfile}
b961095
+
b961095
+# threader: threader.c:8: threader: Assertion `0' failed.
b961095
+# Program received signal SIGABRT, Aborted.
b961095
+
b961095
+gdb_test "run" \
b961095
+     "Program received signal SIGABRT.*" \
b961095
+     "run"
b961095
+
b961095
+# Former gdb unwind (the first function is `clone'):
b961095
+# #5  0x0000003421ecd62d in ?? () from /lib64/libc.so.6
b961095
+# #6  0x0000000000000000 in ?? ()
b961095
+# (gdb)
b961095
+# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
b961095
+# 
b961095
+# Two `-re' cases below must be in this order (1st is a subset of the 2nd one).
b961095
+# Unhandled case below should not happen and it is fortunately handled by
b961095
+# `amd64_linux_outermost_frame' as FAIL (and result `0x0 entry output invalid').
b961095
+gdb_test_multiple "bt" "0x0 entry output invalid" {
b961095
+    -re "in threader \\(.*\n#\[0-9\]* *0x0* in .*$gdb_prompt $" {
b961095
+    	fail "0x0 entry found"
b961095
+    }
b961095
+    -re "in threader \\(.*$gdb_prompt $" {
b961095
+    	pass "0x0 entry not found"
b961095
+    }
b961095
+}