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.20090802/gdb/amd64-linux-tdep.c
27 ===================================================================
28 --- gdb-6.8.50.20090802.orig/gdb/amd64-linux-tdep.c 2009-07-02 19:25:52.000000000 +0200
29 +++ gdb-6.8.50.20090802/gdb/amd64-linux-tdep.c 2009-08-03 15:50:08.000000000 +0200
30 @@ -238,6 +238,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 @@ -276,6 +350,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.20090802/gdb/amd64-tdep.c
121 ===================================================================
122 --- gdb-6.8.50.20090802.orig/gdb/amd64-tdep.c 2009-07-02 19:25:52.000000000 +0200
123 +++ gdb-6.8.50.20090802/gdb/amd64-tdep.c 2009-08-03 15:50:08.000000000 +0200
124 @@ -1736,11 +1736,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 --- gdb-6.8.50.20090811/gdb/i386-tdep.c.orig 2009-08-10 05:02:39.000000000 +0200
142 +++ gdb-6.8.50.20090811/gdb/i386-tdep.c 2009-08-11 16:33:51.000000000 +0200
143 @@ -5432,6 +5432,9 @@ i386_gdbarch_init (struct gdbarch_info i
144 tdep->sc_pc_offset = -1;
145 tdep->sc_sp_offset = -1;
147 + /* Unwinding stops on i386 automatically. */
148 + tdep->outermost_frame_p = NULL;
150 tdep->record_regmap = i386_record_regmap;
152 /* The format used for `long double' on almost all i386 targets is
153 --- gdb-6.8.50.20090811/gdb/i386-tdep.h.orig 2009-08-10 05:02:39.000000000 +0200
154 +++ gdb-6.8.50.20090811/gdb/i386-tdep.h 2009-08-11 16:34:08.000000000 +0200
155 @@ -120,6 +120,9 @@ struct gdbarch_tdep
156 int (*i386_sysenter_record) (struct regcache *regcache);
157 /* Parse syscall args. */
158 int (*i386_syscall_record) (struct regcache *regcache);
160 + /* Detect OS dependent outermost frames; such as `clone'. */
161 + int (*outermost_frame_p) (struct frame_info *this_frame);
164 /* Floating-point registers. */
165 Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.c
166 ===================================================================
167 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
168 +++ gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.c 2009-08-03 15:50:08.000000000 +0200
170 +/* This testcase is part of GDB, the GNU debugger.
172 + Copyright 2006 Free Software Foundation, Inc.
174 + This program is free software; you can redistribute it and/or modify
175 + it under the terms of the GNU General Public License as published by
176 + the Free Software Foundation; either version 2 of the License, or
177 + (at your option) any later version.
179 + This program is distributed in the hope that it will be useful,
180 + but WITHOUT ANY WARRANTY; without even the implied warranty of
181 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182 + GNU General Public License for more details.
184 + You should have received a copy of the GNU General Public License
185 + along with this program; if not, write to the Free Software
186 + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
187 + MA 02110-1301, USA. */
190 +#include <pthread.h>
195 +void *threader (void *arg)
205 + pthread_create (&t1, NULL, threader, (void *) NULL);
209 Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.exp
210 ===================================================================
211 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
212 +++ gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.exp 2009-08-03 15:50:08.000000000 +0200
214 +# Copyright 2006 Free Software Foundation, Inc.
216 +# This program is free software; you can redistribute it and/or modify
217 +# it under the terms of the GNU General Public License as published by
218 +# the Free Software Foundation; either version 2 of the License, or
219 +# (at your option) any later version.
221 +# This program is distributed in the hope that it will be useful,
222 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
223 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
224 +# GNU General Public License for more details.
226 +# You should have received a copy of the GNU General Public License
227 +# along with this program; if not, write to the Free Software
228 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
230 +# Backtraced `clone' must not have `PC == 0' as its previous frame.
232 +if $tracelevel then {
236 +set testfile bt-clone-stop
237 +set srcfile ${testfile}.c
238 +set binfile ${objdir}/${subdir}/${testfile}
239 +if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
240 + untested "Couldn't compile test program"
244 +# Get things started.
248 +gdb_reinitialize_dir $srcdir/$subdir
251 +# threader: threader.c:8: threader: Assertion `0' failed.
252 +# Program received signal SIGABRT, Aborted.
255 + "Program received signal SIGABRT.*" \
258 +# Former gdb unwind (the first function is `clone'):
259 +# #5 0x0000003421ecd62d in ?? () from /lib64/libc.so.6
260 +# #6 0x0000000000000000 in ?? ()
262 +# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
264 +# Two `-re' cases below must be in this order (1st is a subset of the 2nd one).
265 +# Unhandled case below should not happen and it is fortunately handled by
266 +# `amd64_linux_outermost_frame' as FAIL (and result `0x0 entry output invalid').
267 +gdb_test_multiple "bt" "0x0 entry output invalid" {
268 + -re "in threader \\(.*\n#\[0-9\]* *0x0* in .*$gdb_prompt $" {
269 + fail "0x0 entry found"
271 + -re "in threader \\(.*$gdb_prompt $" {
272 + pass "0x0 entry not found"