1 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=216711
3 FIXME: This workaround should be dropped and
4 glibc/sysdeps/unix/sysv/linux/x86_64/clone.S should get CFI for the child
7 2006-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
9 * gdb/amd64-linux-tdep.c (linux_clone_code): New variable.
10 (LINUX_CLONE_LEN): New definition.
11 (amd64_linux_clone_running, amd64_linux_outermost_frame): New function.
12 (amd64_linux_init_abi): Initialize `outermost_frame_p'.
13 * gdb/i386-tdep.c (i386_gdbarch_init): Likewise.
14 * gdb/i386-tdep.h (gdbarch_tdep): Add `outermost_frame_p' member.
15 * gdb/amd64-tdep.c (amd64_frame_this_id): Call `outermost_frame_p'.
17 2006-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
19 * gdb.threads/bt-clone-stop.exp, gdb.threads/bt-clone-stop.c:
22 2007-10-16 Jan Kratochvil <jan.kratochvil@redhat.com>
26 Index: gdb-6.8.50.20081128/gdb/amd64-linux-tdep.c
27 ===================================================================
28 --- gdb-6.8.50.20081128.orig/gdb/amd64-linux-tdep.c 2008-12-08 10:56:17.000000000 +0100
29 +++ gdb-6.8.50.20081128/gdb/amd64-linux-tdep.c 2008-12-08 21:11:08.000000000 +0100
30 @@ -234,6 +234,80 @@ amd64_linux_register_reggroup_p (struct
32 /* Set the program counter for process PTID to PC. */
34 +/* Detect the outermost frame; during unwind of
35 + #5 0x000000305cec68c3 in clone () from /lib64/tls/libc.so.6
36 + avoid the additional bogus frame
37 + #6 0x0000000000000000 in ??
38 + We compare if the `linux_clone_code' block is _before_ unwound PC. */
40 +static const unsigned char linux_clone_code[] =
42 +/* libc/sysdeps/unix/sysv/linux/x86_64/clone.S */
43 +/* #ifdef RESET_PID */
45 +/* mov $SYS_ify(getpid), %eax */
46 +/* 0xb8, 0x27, 0x00, 0x00, 0x00 */
48 +/* mov $SYS_ify(getpid), %rax */
49 +/* 0x48, 0xc7, 0xc0, 0x27, 0x00, 0x00, 0x00 */
51 + 0x27, 0x00, 0x00, 0x00,
54 +/* movl %eax, %fs:PID */
55 + 0x64, 0x89, 0x04, 0x25, 0x94, 0x00, 0x00, 0x00,
56 +/* movl %eax, %fs:TID */
57 + 0x64, 0x89, 0x04, 0x25, 0x90, 0x00, 0x00, 0x00,
59 +/* |* Set up arguments for the function call. *| */
60 +/* popq %rax |* Function to call. *| */
62 +/* popq %rdi |* Argument. *| */
68 +#define LINUX_CLONE_LEN (sizeof linux_clone_code)
71 +amd64_linux_clone_running (struct frame_info *this_frame)
73 + CORE_ADDR pc = get_frame_pc (this_frame);
74 + unsigned char buf[LINUX_CLONE_LEN];
76 + if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_LEN, buf,
80 + if (memcmp (buf, linux_clone_code, LINUX_CLONE_LEN) != 0)
87 +amd64_linux_outermost_frame (struct frame_info *this_frame)
89 + CORE_ADDR pc = get_frame_pc (this_frame);
92 + find_pc_partial_function (pc, &name, NULL, NULL);
94 + /* If we have NAME, we can optimize the search.
95 + `clone' NAME still needs to have the code checked as its name may be
96 + present in the user code.
97 + `__clone' NAME should not be present in the user code but in the initial
98 + parts of the `__clone' implementation the unwind still makes sense.
99 + More detailed unwinding decision would be too much sensitive to possible
100 + subtle changes in specific glibc revisions. */
101 + if (name == NULL || strcmp (name, "clone") == 0
102 + || strcmp ("__clone", name) == 0)
103 + return (amd64_linux_clone_running (this_frame) != 0);
109 amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
111 @@ -272,6 +346,8 @@ amd64_linux_init_abi (struct gdbarch_inf
112 tdep->sc_reg_offset = amd64_linux_sc_reg_offset;
113 tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_offset);
115 + tdep->outermost_frame_p = amd64_linux_outermost_frame;
117 /* GNU/Linux uses SVR4-style shared libraries. */
118 set_solib_svr4_fetch_link_map_offsets
119 (gdbarch, svr4_lp64_fetch_link_map_offsets);
120 Index: gdb-6.8.50.20081128/gdb/amd64-tdep.c
121 ===================================================================
122 --- gdb-6.8.50.20081128.orig/gdb/amd64-tdep.c 2008-12-08 10:56:17.000000000 +0100
123 +++ gdb-6.8.50.20081128/gdb/amd64-tdep.c 2008-12-08 21:05:12.000000000 +0100
124 @@ -1044,11 +1044,16 @@ amd64_frame_this_id (struct frame_info *
126 struct amd64_frame_cache *cache =
127 amd64_frame_cache (this_frame, this_cache);
128 + struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
130 /* This marks the outermost frame. */
131 if (cache->base == 0)
134 + /* Detect OS dependent outermost frames; such as `clone'. */
135 + if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
138 (*this_id) = frame_id_build (cache->base + 16, cache->pc);
141 Index: gdb-6.8.50.20081128/gdb/i386-tdep.c
142 ===================================================================
143 --- gdb-6.8.50.20081128.orig/gdb/i386-tdep.c 2008-12-08 10:56:17.000000000 +0100
144 +++ gdb-6.8.50.20081128/gdb/i386-tdep.c 2008-12-08 11:00:43.000000000 +0100
145 @@ -2698,6 +2698,9 @@ i386_gdbarch_init (struct gdbarch_info i
146 tdep->sc_pc_offset = -1;
147 tdep->sc_sp_offset = -1;
149 + /* Unwinding stops on i386 automatically. */
150 + tdep->outermost_frame_p = NULL;
152 /* The format used for `long double' on almost all i386 targets is
153 the i387 extended floating-point format. In fact, of all targets
154 in the GCC 2.95 tree, only OSF/1 does it different, and insists
155 Index: gdb-6.8.50.20081128/gdb/i386-tdep.h
156 ===================================================================
157 --- gdb-6.8.50.20081128.orig/gdb/i386-tdep.h 2008-12-08 10:56:17.000000000 +0100
158 +++ gdb-6.8.50.20081128/gdb/i386-tdep.h 2008-12-08 21:07:47.000000000 +0100
159 @@ -106,6 +106,9 @@ struct gdbarch_tdep
160 /* ISA-specific data types. */
161 struct type *i386_mmx_type;
162 struct type *i386_sse_type;
164 + /* Detect OS dependent outermost frames; such as `clone'. */
165 + int (*outermost_frame_p) (struct frame_info *this_frame);
168 /* Floating-point registers. */
169 Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/bt-clone-stop.c
170 ===================================================================
171 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
172 +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/bt-clone-stop.c 2008-12-08 11:00:43.000000000 +0100
174 +/* This testcase is part of GDB, the GNU debugger.
176 + Copyright 2006 Free Software Foundation, Inc.
178 + This program is free software; you can redistribute it and/or modify
179 + it under the terms of the GNU General Public License as published by
180 + the Free Software Foundation; either version 2 of the License, or
181 + (at your option) any later version.
183 + This program is distributed in the hope that it will be useful,
184 + but WITHOUT ANY WARRANTY; without even the implied warranty of
185 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
186 + GNU General Public License for more details.
188 + You should have received a copy of the GNU General Public License
189 + along with this program; if not, write to the Free Software
190 + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
191 + MA 02110-1301, USA. */
194 +#include <pthread.h>
199 +void *threader (void *arg)
209 + pthread_create (&t1, NULL, threader, (void *) NULL);
213 Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/bt-clone-stop.exp
214 ===================================================================
215 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
216 +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/bt-clone-stop.exp 2008-12-08 11:00:43.000000000 +0100
218 +# Copyright 2006 Free Software Foundation, Inc.
220 +# This program is free software; you can redistribute it and/or modify
221 +# it under the terms of the GNU General Public License as published by
222 +# the Free Software Foundation; either version 2 of the License, or
223 +# (at your option) any later version.
225 +# This program is distributed in the hope that it will be useful,
226 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
227 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
228 +# GNU General Public License for more details.
230 +# You should have received a copy of the GNU General Public License
231 +# along with this program; if not, write to the Free Software
232 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
234 +# Backtraced `clone' must not have `PC == 0' as its previous frame.
236 +if $tracelevel then {
240 +set testfile bt-clone-stop
241 +set srcfile ${testfile}.c
242 +set binfile ${objdir}/${subdir}/${testfile}
243 +if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
244 + untested "Couldn't compile test program"
248 +# Get things started.
252 +gdb_reinitialize_dir $srcdir/$subdir
255 +# threader: threader.c:8: threader: Assertion `0' failed.
256 +# Program received signal SIGABRT, Aborted.
259 + "Program received signal SIGABRT.*" \
262 +# Former gdb unwind (the first function is `clone'):
263 +# #5 0x0000003421ecd62d in ?? () from /lib64/libc.so.6
264 +# #6 0x0000000000000000 in ?? ()
266 +# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
268 +# Two `-re' cases below must be in this order (1st is a subset of the 2nd one).
269 +# Unhandled case below should not happen and it is fortunately handled by
270 +# `amd64_linux_outermost_frame' as FAIL (and result `0x0 entry output invalid').
271 +gdb_test_multiple "bt" "0x0 entry output invalid" {
272 + -re "in threader \\(.*\n#\[0-9\]* *0x0* in .*$gdb_prompt $" {
273 + fail "0x0 entry found"
275 + -re "in threader \\(.*$gdb_prompt $" {
276 + pass "0x0 entry not found"