|
|
e1d87d |
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=216711
|
|
|
e1d87d |
|
|
|
e1d87d |
FIXME: This workaround should be dropped and
|
|
|
e1d87d |
glibc/sysdeps/unix/sysv/linux/x86_64/clone.S should get CFI for the child
|
|
|
e1d87d |
instead.
|
|
|
e1d87d |
|
|
|
e1d87d |
2006-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
e1d87d |
|
|
|
e1d87d |
* gdb/amd64-linux-tdep.c (linux_clone_code): New variable.
|
|
|
e1d87d |
(LINUX_CLONE_LEN): New definition.
|
|
|
e1d87d |
(amd64_linux_clone_running, amd64_linux_outermost_frame): New function.
|
|
|
e1d87d |
(amd64_linux_init_abi): Initialize `outermost_frame_p'.
|
|
|
e1d87d |
* gdb/i386-tdep.c (i386_gdbarch_init): Likewise.
|
|
|
e1d87d |
* gdb/i386-tdep.h (gdbarch_tdep): Add `outermost_frame_p' member.
|
|
|
e1d87d |
* gdb/amd64-tdep.c (amd64_frame_this_id): Call `outermost_frame_p'.
|
|
|
e1d87d |
|
|
|
e1d87d |
2006-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
e1d87d |
|
|
|
e1d87d |
* gdb.threads/bt-clone-stop.exp, gdb.threads/bt-clone-stop.c:
|
|
|
e1d87d |
New file.
|
|
|
e1d87d |
|
|
|
e1d87d |
2007-10-16 Jan Kratochvil <jan.kratochvil@redhat.com>
|
|
|
e1d87d |
|
|
|
e1d87d |
Port to GDB-6.7.
|
|
|
e1d87d |
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/amd64-linux-tdep.c
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- gdb-7.10.90.20160211.orig/gdb/amd64-linux-tdep.c 2016-02-15 23:37:06.936501443 +0100
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/amd64-linux-tdep.c 2016-02-15 23:37:39.928735691 +0100
|
|
|
e1d87d |
@@ -292,6 +292,80 @@
|
|
|
e1d87d |
|
|
|
e1d87d |
/* Set the program counter for process PTID to PC. */
|
|
|
e1d87d |
|
|
|
e1d87d |
+/* Detect the outermost frame; during unwind of
|
|
|
e1d87d |
+ #5 0x000000305cec68c3 in clone () from /lib64/tls/libc.so.6
|
|
|
e1d87d |
+ avoid the additional bogus frame
|
|
|
e1d87d |
+ #6 0x0000000000000000 in ??
|
|
|
e1d87d |
+ We compare if the `linux_clone_code' block is _before_ unwound PC. */
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+static const unsigned char linux_clone_code[] =
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+/* libc/sysdeps/unix/sysv/linux/x86_64/clone.S */
|
|
|
e1d87d |
+/* #ifdef RESET_PID */
|
|
|
e1d87d |
+/* ... */
|
|
|
e1d87d |
+/* mov $SYS_ify(getpid), %eax */
|
|
|
e1d87d |
+/* 0xb8, 0x27, 0x00, 0x00, 0x00 */
|
|
|
e1d87d |
+/* OR */
|
|
|
e1d87d |
+/* mov $SYS_ify(getpid), %rax */
|
|
|
e1d87d |
+/* 0x48, 0xc7, 0xc0, 0x27, 0x00, 0x00, 0x00 */
|
|
|
e1d87d |
+/* so just: */
|
|
|
e1d87d |
+ 0x27, 0x00, 0x00, 0x00,
|
|
|
e1d87d |
+/* syscall */
|
|
|
e1d87d |
+ 0x0f, 0x05,
|
|
|
e1d87d |
+/* movl %eax, %fs:PID */
|
|
|
e1d87d |
+ 0x64, 0x89, 0x04, 0x25, 0x94, 0x00, 0x00, 0x00,
|
|
|
e1d87d |
+/* movl %eax, %fs:TID */
|
|
|
e1d87d |
+ 0x64, 0x89, 0x04, 0x25, 0x90, 0x00, 0x00, 0x00,
|
|
|
e1d87d |
+/* #endif */
|
|
|
e1d87d |
+/* |* Set up arguments for the function call. *| */
|
|
|
e1d87d |
+/* popq %rax |* Function to call. *| */
|
|
|
e1d87d |
+ 0x58,
|
|
|
e1d87d |
+/* popq %rdi |* Argument. *| */
|
|
|
e1d87d |
+ 0x5f,
|
|
|
e1d87d |
+/* call *%rax$ */
|
|
|
e1d87d |
+ 0xff, 0xd0
|
|
|
e1d87d |
+};
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+#define LINUX_CLONE_LEN (sizeof linux_clone_code)
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+static int
|
|
|
e1d87d |
+amd64_linux_clone_running (struct frame_info *this_frame)
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ CORE_ADDR pc = get_frame_pc (this_frame);
|
|
|
e1d87d |
+ unsigned char buf[LINUX_CLONE_LEN];
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_LEN, buf,
|
|
|
e1d87d |
+ LINUX_CLONE_LEN))
|
|
|
e1d87d |
+ return 0;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ if (memcmp (buf, linux_clone_code, LINUX_CLONE_LEN) != 0)
|
|
|
e1d87d |
+ return 0;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ return 1;
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+static int
|
|
|
e1d87d |
+amd64_linux_outermost_frame (struct frame_info *this_frame)
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ CORE_ADDR pc = get_frame_pc (this_frame);
|
|
|
e1d87d |
+ const char *name;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ find_pc_partial_function (pc, &name, NULL, NULL);
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ /* If we have NAME, we can optimize the search.
|
|
|
e1d87d |
+ `clone' NAME still needs to have the code checked as its name may be
|
|
|
e1d87d |
+ present in the user code.
|
|
|
e1d87d |
+ `__clone' NAME should not be present in the user code but in the initial
|
|
|
e1d87d |
+ parts of the `__clone' implementation the unwind still makes sense.
|
|
|
e1d87d |
+ More detailed unwinding decision would be too much sensitive to possible
|
|
|
e1d87d |
+ subtle changes in specific glibc revisions. */
|
|
|
e1d87d |
+ if (name == NULL || strcmp (name, "clone") == 0
|
|
|
e1d87d |
+ || strcmp ("__clone", name) == 0)
|
|
|
e1d87d |
+ return (amd64_linux_clone_running (this_frame) != 0);
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ return 0;
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
static void
|
|
|
e1d87d |
amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
|
|
|
e1d87d |
{
|
|
|
e1d87d |
@@ -1800,6 +1874,8 @@
|
|
|
e1d87d |
|
|
|
e1d87d |
tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
|
|
|
e1d87d |
|
|
|
e1d87d |
+ tdep->outermost_frame_p = amd64_linux_outermost_frame;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
/* Add the %orig_rax register used for syscall restarting. */
|
|
|
e1d87d |
set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc);
|
|
|
e1d87d |
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/amd64-tdep.c
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- gdb-7.10.90.20160211.orig/gdb/amd64-tdep.c 2016-02-15 23:37:06.936501443 +0100
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/amd64-tdep.c 2016-02-15 23:37:39.929735698 +0100
|
|
|
e1d87d |
@@ -2494,6 +2494,7 @@
|
|
|
e1d87d |
{
|
|
|
e1d87d |
struct amd64_frame_cache *cache =
|
|
|
e1d87d |
amd64_frame_cache (this_frame, this_cache);
|
|
|
e1d87d |
+ struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
|
|
|
e1d87d |
|
|
|
e1d87d |
if (!cache->base_p)
|
|
|
e1d87d |
return UNWIND_UNAVAILABLE;
|
|
|
e1d87d |
@@ -2502,6 +2503,10 @@
|
|
|
e1d87d |
if (cache->base == 0)
|
|
|
e1d87d |
return UNWIND_OUTERMOST;
|
|
|
e1d87d |
|
|
|
e1d87d |
+ /* Detect OS dependent outermost frames; such as `clone'. */
|
|
|
e1d87d |
+ if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
|
|
|
e1d87d |
+ return UNWIND_OUTERMOST;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
return UNWIND_NO_REASON;
|
|
|
e1d87d |
}
|
|
|
e1d87d |
|
|
|
e1d87d |
@@ -2636,6 +2641,7 @@
|
|
|
e1d87d |
{
|
|
|
e1d87d |
struct amd64_frame_cache *cache =
|
|
|
e1d87d |
amd64_sigtramp_frame_cache (this_frame, this_cache);
|
|
|
e1d87d |
+ struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
|
|
|
e1d87d |
|
|
|
e1d87d |
if (!cache->base_p)
|
|
|
e1d87d |
(*this_id) = frame_id_build_unavailable_stack (get_frame_pc (this_frame));
|
|
|
e1d87d |
@@ -2644,6 +2650,11 @@
|
|
|
e1d87d |
/* This marks the outermost frame. */
|
|
|
e1d87d |
return;
|
|
|
e1d87d |
}
|
|
|
e1d87d |
+ else if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
|
|
|
e1d87d |
+ {
|
|
|
e1d87d |
+ /* Detect OS dependent outermost frames; such as `clone'. */
|
|
|
e1d87d |
+ return;
|
|
|
e1d87d |
+ }
|
|
|
e1d87d |
else
|
|
|
e1d87d |
(*this_id) = frame_id_build (cache->base + 16, get_frame_pc (this_frame));
|
|
|
e1d87d |
}
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/i386-tdep.c
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- gdb-7.10.90.20160211.orig/gdb/i386-tdep.c 2016-02-15 23:37:06.936501443 +0100
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/i386-tdep.c 2016-02-15 23:37:39.931735713 +0100
|
|
|
e1d87d |
@@ -8305,6 +8305,9 @@
|
|
|
e1d87d |
|
|
|
e1d87d |
tdep->xsave_xcr0_offset = -1;
|
|
|
e1d87d |
|
|
|
e1d87d |
+ /* Unwinding stops on i386 automatically. */
|
|
|
e1d87d |
+ tdep->outermost_frame_p = NULL;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
tdep->record_regmap = i386_record_regmap;
|
|
|
e1d87d |
|
|
|
e1d87d |
set_gdbarch_long_long_align_bit (gdbarch, 32);
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/i386-tdep.h
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- gdb-7.10.90.20160211.orig/gdb/i386-tdep.h 2016-02-15 23:37:06.936501443 +0100
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/i386-tdep.h 2016-02-15 23:37:39.932735720 +0100
|
|
|
e1d87d |
@@ -240,6 +240,9 @@
|
|
|
e1d87d |
|
|
|
e1d87d |
/* Regsets. */
|
|
|
e1d87d |
const struct regset *fpregset;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ /* Detect OS dependent outermost frames; such as `clone'. */
|
|
|
e1d87d |
+ int (*outermost_frame_p) (struct frame_info *this_frame);
|
|
|
e1d87d |
};
|
|
|
e1d87d |
|
|
|
e1d87d |
/* Floating-point registers. */
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/bt-clone-stop.c
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/bt-clone-stop.c 2016-02-15 23:37:39.932735720 +0100
|
|
|
e1d87d |
@@ -0,0 +1,39 @@
|
|
|
e1d87d |
+/* This testcase is part of GDB, the GNU debugger.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ Copyright 2006 Free Software Foundation, Inc.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ This program is free software; you can redistribute it and/or modify
|
|
|
e1d87d |
+ it under the terms of the GNU General Public License as published by
|
|
|
e1d87d |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
e1d87d |
+ (at your option) any later version.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ This program is distributed in the hope that it will be useful,
|
|
|
e1d87d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
e1d87d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
e1d87d |
+ GNU General Public License for more details.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ You should have received a copy of the GNU General Public License
|
|
|
e1d87d |
+ along with this program; if not, write to the Free Software
|
|
|
e1d87d |
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
e1d87d |
+ MA 02110-1301, USA. */
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+#include <pthread.h>
|
|
|
e1d87d |
+#include <unistd.h>
|
|
|
e1d87d |
+#include <assert.h>
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+void *threader (void *arg)
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ assert (0);
|
|
|
e1d87d |
+ return NULL;
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+int main (void)
|
|
|
e1d87d |
+{
|
|
|
e1d87d |
+ pthread_t t1;
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+ pthread_create (&t1, NULL, threader, (void *) NULL);
|
|
|
e1d87d |
+ for (;;)
|
|
|
e1d87d |
+ pause();
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
Index: gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/bt-clone-stop.exp
|
|
|
e1d87d |
===================================================================
|
|
|
e1d87d |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
|
|
e1d87d |
+++ gdb-7.10.90.20160211/gdb/testsuite/gdb.threads/bt-clone-stop.exp 2016-02-15 23:37:56.197851204 +0100
|
|
|
e1d87d |
@@ -0,0 +1,61 @@
|
|
|
e1d87d |
+# Copyright 2006 Free Software Foundation, Inc.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# This program is free software; you can redistribute it and/or modify
|
|
|
e1d87d |
+# it under the terms of the GNU General Public License as published by
|
|
|
e1d87d |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
e1d87d |
+# (at your option) any later version.
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+# This program is distributed in the hope that it will be useful,
|
|
|
e1d87d |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
e1d87d |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
e1d87d |
+# GNU General Public License for more details.
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+# You should have received a copy of the GNU General Public License
|
|
|
e1d87d |
+# along with this program; if not, write to the Free Software
|
|
|
e1d87d |
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Backtraced `clone' must not have `PC == 0' as its previous frame.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+if $tracelevel then {
|
|
|
e1d87d |
+ strace $tracelevel
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+set testfile bt-clone-stop
|
|
|
e1d87d |
+set srcfile ${testfile}.c
|
|
|
e1d87d |
+set binfile [standard_output_file ${testfile}]
|
|
|
e1d87d |
+if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
|
|
e1d87d |
+ untested "Couldn't compile test program"
|
|
|
e1d87d |
+ return -1
|
|
|
e1d87d |
+}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Get things started.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+gdb_exit
|
|
|
e1d87d |
+gdb_start
|
|
|
e1d87d |
+gdb_reinitialize_dir $srcdir/$subdir
|
|
|
e1d87d |
+gdb_load ${binfile}
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# threader: threader.c:8: threader: Assertion `0' failed.
|
|
|
e1d87d |
+# Program received signal SIGABRT, Aborted.
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+gdb_test "run" \
|
|
|
e1d87d |
+ {Thread 2 "bt-clone-stop" received signal SIGABRT.*} \
|
|
|
e1d87d |
+ "run"
|
|
|
e1d87d |
+
|
|
|
e1d87d |
+# Former gdb unwind (the first function is `clone'):
|
|
|
e1d87d |
+# #5 0x0000003421ecd62d in ?? () from /lib64/libc.so.6
|
|
|
e1d87d |
+# #6 0x0000000000000000 in ?? ()
|
|
|
e1d87d |
+# (gdb)
|
|
|
e1d87d |
+# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
|
|
|
e1d87d |
+#
|
|
|
e1d87d |
+# Two `-re' cases below must be in this order (1st is a subset of the 2nd one).
|
|
|
e1d87d |
+# Unhandled case below should not happen and it is fortunately handled by
|
|
|
e1d87d |
+# `amd64_linux_outermost_frame' as FAIL (and result `0x0 entry output invalid').
|
|
|
e1d87d |
+gdb_test_multiple "bt" "0x0 entry output invalid" {
|
|
|
e1d87d |
+ -re "in threader \\(.*\n#\[0-9\]* *0x0* in .*$gdb_prompt $" {
|
|
|
e1d87d |
+ fail "0x0 entry found"
|
|
|
e1d87d |
+ }
|
|
|
e1d87d |
+ -re "in threader \\(.*$gdb_prompt $" {
|
|
|
e1d87d |
+ pass "0x0 entry not found"
|
|
|
e1d87d |
+ }
|
|
|
e1d87d |
+}
|