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-7.4.50.20120120/gdb/amd64-linux-tdep.c
27 ===================================================================
28 --- gdb-7.4.50.20120120.orig/gdb/amd64-linux-tdep.c 2012-03-02 22:15:48.000000000 +0100
29 +++ gdb-7.4.50.20120120/gdb/amd64-linux-tdep.c 2012-03-02 22:16:13.526569163 +0100
30 @@ -268,6 +268,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 @@ -1321,6 +1395,8 @@ amd64_linux_init_abi (struct gdbarch_inf
113 tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_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-7.4.50.20120120/gdb/amd64-tdep.c
121 ===================================================================
122 --- gdb-7.4.50.20120120.orig/gdb/amd64-tdep.c 2012-01-04 09:16:56.000000000 +0100
123 +++ gdb-7.4.50.20120120/gdb/amd64-tdep.c 2012-03-02 22:17:39.133287571 +0100
124 @@ -2108,6 +2108,7 @@ amd64_frame_unwind_stop_reason (struct f
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));
131 return UNWIND_UNAVAILABLE;
132 @@ -2116,6 +2117,10 @@ amd64_frame_unwind_stop_reason (struct f
133 if (cache->base == 0)
134 return UNWIND_OUTERMOST;
136 + /* Detect OS dependent outermost frames; such as `clone'. */
137 + if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
138 + return UNWIND_OUTERMOST;
140 return UNWIND_NO_REASON;
143 @@ -2125,6 +2130,7 @@ amd64_frame_this_id (struct frame_info *
145 struct amd64_frame_cache *cache =
146 amd64_frame_cache (this_frame, this_cache);
147 + struct gdbarch_tdep *tdep = gdbarch_tdep (get_frame_arch (this_frame));
151 @@ -2133,6 +2139,10 @@ amd64_frame_this_id (struct frame_info *
152 if (cache->base == 0)
155 + /* Detect OS dependent outermost frames; such as `clone'. */
156 + if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
159 (*this_id) = frame_id_build (cache->base + 16, cache->pc);
162 Index: gdb-7.4.50.20120120/gdb/i386-tdep.c
163 ===================================================================
164 --- gdb-7.4.50.20120120.orig/gdb/i386-tdep.c 2012-03-02 22:15:48.000000000 +0100
165 +++ gdb-7.4.50.20120120/gdb/i386-tdep.c 2012-03-02 22:16:13.528569157 +0100
166 @@ -7613,6 +7613,9 @@ i386_gdbarch_init (struct gdbarch_info i
168 tdep->xsave_xcr0_offset = -1;
170 + /* Unwinding stops on i386 automatically. */
171 + tdep->outermost_frame_p = NULL;
173 tdep->record_regmap = i386_record_regmap;
175 set_gdbarch_long_long_align_bit (gdbarch, 32);
176 Index: gdb-7.4.50.20120120/gdb/i386-tdep.h
177 ===================================================================
178 --- gdb-7.4.50.20120120.orig/gdb/i386-tdep.h 2012-03-02 22:15:48.000000000 +0100
179 +++ gdb-7.4.50.20120120/gdb/i386-tdep.h 2012-03-02 22:16:13.529569154 +0100
180 @@ -219,6 +219,9 @@ struct gdbarch_tdep
181 int (*i386_sysenter_record) (struct regcache *regcache);
182 /* Parse syscall args. */
183 int (*i386_syscall_record) (struct regcache *regcache);
185 + /* Detect OS dependent outermost frames; such as `clone'. */
186 + int (*outermost_frame_p) (struct frame_info *this_frame);
189 /* Floating-point registers. */
190 Index: gdb-7.4.50.20120120/gdb/ia64-tdep.c
191 ===================================================================
192 --- gdb-7.4.50.20120120.orig/gdb/ia64-tdep.c 2012-03-02 22:15:48.000000000 +0100
193 +++ gdb-7.4.50.20120120/gdb/ia64-tdep.c 2012-03-02 22:16:13.529569154 +0100
194 @@ -2181,6 +2181,138 @@ static const struct frame_unwind ia64_fr
195 default_frame_sniffer
198 +/* Detect the outermost frame; during unwind of
199 + #6 0x2000000000347100 in __clone2 () from /lib/libc.so.6.1
200 + avoid the additional bogus frame
201 + #7 0x0000000000000000 in ?? () */
203 +static char linux_clone2_code[] =
205 +/* libc/sysdeps/unix/sysv/linux/ia64/clone2.S */
206 + 0x09, 0x00, 0x20, 0x12, 0x90, 0x11, 0x00, 0x40,
207 + 0x28, 0x20, 0x23, 0x00, 0x00, 0x00, 0x04, 0x00,
212 + 0x02, 0x50, 0x21, 0x40, 0x18, 0x14, 0x90, 0x02,
213 + 0x90, 0x00, 0x42, 0x00, 0x00, 0x00, 0x04, 0x00,
214 +/* 1: ld8 out1=[in0],8 |* Retrieve code pointer. *| */
215 +/* mov out0=in4 |* Pass proper argument to fn *| */
217 + 0x11, 0x08, 0x00, 0x40, 0x18, 0x10, 0x60, 0x50,
218 + 0x05, 0x80, 0x03, 0x00, 0x68, 0x00, 0x80, 0x12,
219 +/* ld8 gp=[in0] |* Load function gp. *| */
221 +/* br.call.dptk.many rp=b6 |* Call fn(arg) in the child *| */
223 + 0x10, 0x48, 0x01, 0x10, 0x00, 0x21, 0x10, 0x00,
224 + 0xa0, 0x00, 0x42, 0x00, 0x98, 0xdf, 0xf7, 0x5b,
225 +/* mov out0=r8 |* Argument to _exit *| */
227 +/* .globl HIDDEN_JUMPTARGET(_exit) */
228 +/* br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit) */
229 +/* |* call _exit with result from fn. *| */
230 + 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
231 + 0x00, 0x02, 0x00, 0x80, 0x00, 0x00, 0x84, 0x00
232 +/* ret |* Not reached. *| */
235 +#define LINUX_CLONE_PRE_SLOTS 3 /* Number of slots before PC. */
236 +#define LINUX_CLONE_LEN (sizeof linux_clone2_code)
239 +ia64_linux_clone2_running (struct frame_info *this_frame)
241 + CORE_ADDR pc = get_frame_pc (this_frame);
242 + char buf[LINUX_CLONE_LEN];
243 + struct minimal_symbol *minsym;
246 + if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_PRE_SLOTS * 16,
247 + buf, LINUX_CLONE_LEN))
250 + if (memcmp (buf, linux_clone2_code, LINUX_CLONE_PRE_SLOTS * 16) != 0)
253 + /* Adjust the expected "_exit" address. */
254 + minsym = lookup_minimal_symbol_text ("_exit", NULL);
255 + if (minsym == NULL)
258 + instr = slotN_contents (&linux_clone2_code[LINUX_CLONE_PRE_SLOTS * 16], 2);
259 + instr &= ~(((1L << 20) - 1) << 13);
260 + /* Address is relative to the jump instruction slot, not the next one. */
261 + instr |= (((SYMBOL_VALUE_ADDRESS (minsym) - (pc & ~0xfL)) >> 4)
262 + & ((1L << 20) - 1)) << 13;
263 + replace_slotN_contents (&linux_clone2_code[LINUX_CLONE_PRE_SLOTS * 16], instr,
266 + if (memcmp (&buf[LINUX_CLONE_PRE_SLOTS * 16],
267 + &linux_clone2_code[LINUX_CLONE_PRE_SLOTS * 16],
268 + LINUX_CLONE_LEN - (LINUX_CLONE_PRE_SLOTS * 16)) != 0)
275 +ia64_outermost_frame (struct frame_info *this_frame)
277 + CORE_ADDR pc = get_frame_pc (this_frame);
280 + find_pc_partial_function (pc, &name, NULL, NULL);
282 + /* If we have NAME, we can optimize the search.
283 + `clone' NAME still needs to have the code checked as its name may be
284 + present in the user code.
285 + `__clone' NAME should not be present in the user code but in the initial
286 + parts of the `__clone' implementation the unwind still makes sense.
287 + More detailed unwinding decision would be too much sensitive to possible
288 + subtle changes in specific glibc revisions. */
289 + if (name == NULL || strcmp (name, "clone2") == 0
290 + || strcmp ("__clone2", name) == 0)
291 + return (ia64_linux_clone2_running (this_frame) != 0);
297 +ia64_clone2_frame_this_id (struct frame_info *this_frame, void **this_cache,
298 + struct frame_id *this_id)
300 + /* Leave the default outermost frame at *THIS_ID. */
303 +static struct value *
304 +ia64_clone2_frame_prev_register (struct frame_info *this_frame,
305 + void **this_cache, int regnum)
307 + return frame_unwind_got_register (this_frame, regnum, regnum);
311 +ia64_clone2_frame_sniffer (const struct frame_unwind *self,
312 + struct frame_info *this_frame,
313 + void **this_prologue_cache)
315 + if (ia64_outermost_frame (this_frame))
321 +static const struct frame_unwind ia64_clone2_frame_unwind =
324 + &ia64_clone2_frame_this_id,
325 + &ia64_clone2_frame_prev_register,
327 + &ia64_clone2_frame_sniffer
330 /* Signal trampolines. */
333 @@ -4153,6 +4285,7 @@ ia64_gdbarch_init (struct gdbarch_info i
334 set_gdbarch_dummy_id (gdbarch, ia64_dummy_id);
336 set_gdbarch_unwind_pc (gdbarch, ia64_unwind_pc);
337 + frame_unwind_append_unwinder (gdbarch, &ia64_clone2_frame_unwind);
338 #ifdef HAVE_LIBUNWIND_IA64_H
339 frame_unwind_append_unwinder (gdbarch,
340 &ia64_libunwind_sigtramp_frame_unwind);
341 Index: gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.c
342 ===================================================================
343 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
344 +++ gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.c 2012-03-02 22:16:13.530569151 +0100
346 +/* This testcase is part of GDB, the GNU debugger.
348 + Copyright 2006 Free Software Foundation, Inc.
350 + This program is free software; you can redistribute it and/or modify
351 + it under the terms of the GNU General Public License as published by
352 + the Free Software Foundation; either version 2 of the License, or
353 + (at your option) any later version.
355 + This program is distributed in the hope that it will be useful,
356 + but WITHOUT ANY WARRANTY; without even the implied warranty of
357 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
358 + GNU General Public License for more details.
360 + You should have received a copy of the GNU General Public License
361 + along with this program; if not, write to the Free Software
362 + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
363 + MA 02110-1301, USA. */
366 +#include <pthread.h>
371 +void *threader (void *arg)
381 + pthread_create (&t1, NULL, threader, (void *) NULL);
385 Index: gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.exp
386 ===================================================================
387 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
388 +++ gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.exp 2012-03-02 22:16:13.530569151 +0100
390 +# Copyright 2006 Free Software Foundation, Inc.
392 +# This program is free software; you can redistribute it and/or modify
393 +# it under the terms of the GNU General Public License as published by
394 +# the Free Software Foundation; either version 2 of the License, or
395 +# (at your option) any later version.
397 +# This program is distributed in the hope that it will be useful,
398 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
399 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
400 +# GNU General Public License for more details.
402 +# You should have received a copy of the GNU General Public License
403 +# along with this program; if not, write to the Free Software
404 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
406 +# Backtraced `clone' must not have `PC == 0' as its previous frame.
408 +if $tracelevel then {
412 +set testfile bt-clone-stop
413 +set srcfile ${testfile}.c
414 +set binfile ${objdir}/${subdir}/${testfile}
415 +if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
416 + untested "Couldn't compile test program"
420 +# Get things started.
424 +gdb_reinitialize_dir $srcdir/$subdir
427 +# threader: threader.c:8: threader: Assertion `0' failed.
428 +# Program received signal SIGABRT, Aborted.
431 + "Program received signal SIGABRT.*" \
434 +# Former gdb unwind (the first function is `clone'):
435 +# #5 0x0000003421ecd62d in ?? () from /lib64/libc.so.6
436 +# #6 0x0000000000000000 in ?? ()
438 +# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
440 +# Two `-re' cases below must be in this order (1st is a subset of the 2nd one).
441 +# Unhandled case below should not happen and it is fortunately handled by
442 +# `amd64_linux_outermost_frame' as FAIL (and result `0x0 entry output invalid').
443 +gdb_test_multiple "bt" "0x0 entry output invalid" {
444 + -re "in threader \\(.*\n#\[0-9\]* *0x0* in .*$gdb_prompt $" {
445 + fail "0x0 entry found"
447 + -re "in threader \\(.*$gdb_prompt $" {
448 + pass "0x0 entry not found"