]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.5-bz216711-clone-is-outermost.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-6.5-bz216711-clone-is-outermost.patch
CommitLineData
3a58abaf
AM
1https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=216711
2
3FIXME: This workaround should be dropped and
4glibc/sysdeps/unix/sysv/linux/x86_64/clone.S should get CFI for the child
5instead.
6
72006-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
8
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'.
16
172006-12-17 Jan Kratochvil <jan.kratochvil@redhat.com>
18
19 * gdb.threads/bt-clone-stop.exp, gdb.threads/bt-clone-stop.c:
20 New file.
21
222007-10-16 Jan Kratochvil <jan.kratochvil@redhat.com>
23
24 Port to GDB-6.7.
25
f412e1b4
PS
26Index: 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
31
32 /* Set the program counter for process PTID to PC. */
33
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. */
39+
40+static const unsigned char linux_clone_code[] =
41+{
42+/* libc/sysdeps/unix/sysv/linux/x86_64/clone.S */
43+/* #ifdef RESET_PID */
44+/* ... */
45+/* mov $SYS_ify(getpid), %eax */
46+/* 0xb8, 0x27, 0x00, 0x00, 0x00 */
47+/* OR */
48+/* mov $SYS_ify(getpid), %rax */
49+/* 0x48, 0xc7, 0xc0, 0x27, 0x00, 0x00, 0x00 */
50+/* so just: */
51+ 0x27, 0x00, 0x00, 0x00,
52+/* syscall */
53+ 0x0f, 0x05,
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,
58+/* #endif */
59+/* |* Set up arguments for the function call. *| */
60+/* popq %rax |* Function to call. *| */
61+ 0x58,
62+/* popq %rdi |* Argument. *| */
63+ 0x5f,
64+/* call *%rax$ */
65+ 0xff, 0xd0
66+};
67+
68+#define LINUX_CLONE_LEN (sizeof linux_clone_code)
69+
70+static int
71+amd64_linux_clone_running (struct frame_info *this_frame)
72+{
73+ CORE_ADDR pc = get_frame_pc (this_frame);
74+ unsigned char buf[LINUX_CLONE_LEN];
75+
76+ if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_LEN, buf,
77+ LINUX_CLONE_LEN))
78+ return 0;
79+
80+ if (memcmp (buf, linux_clone_code, LINUX_CLONE_LEN) != 0)
81+ return 0;
82+
83+ return 1;
84+}
85+
86+static int
87+amd64_linux_outermost_frame (struct frame_info *this_frame)
88+{
89+ CORE_ADDR pc = get_frame_pc (this_frame);
90+ char *name;
91+
92+ find_pc_partial_function (pc, &name, NULL, NULL);
93+
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);
104+
105+ return 0;
106+}
107+
108 static void
109 amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
110 {
111@@ -1321,6 +1395,8 @@ amd64_linux_init_abi (struct gdbarch_inf
112
113 tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
114
115+ tdep->outermost_frame_p = amd64_linux_outermost_frame;
116+
117 /* GNU/Linux uses SVR4-style shared libraries. */
118 set_solib_svr4_fetch_link_map_offsets
119 (gdbarch, svr4_lp64_fetch_link_map_offsets);
120Index: 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
125 {
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));
129
130 if (!cache->base_p)
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;
135
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;
139+
140 return UNWIND_NO_REASON;
141 }
142
143@@ -2125,6 +2130,7 @@ amd64_frame_this_id (struct frame_info *
144 {
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));
148
149 if (!cache->base_p)
150 return;
151@@ -2133,6 +2139,10 @@ amd64_frame_this_id (struct frame_info *
152 if (cache->base == 0)
153 return;
154
155+ /* Detect OS dependent outermost frames; such as `clone'. */
156+ if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
157+ return;
158+
159 (*this_id) = frame_id_build (cache->base + 16, cache->pc);
160 }
161
162Index: 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
167
168 tdep->xsave_xcr0_offset = -1;
169
170+ /* Unwinding stops on i386 automatically. */
171+ tdep->outermost_frame_p = NULL;
172+
173 tdep->record_regmap = i386_record_regmap;
174
175 set_gdbarch_long_long_align_bit (gdbarch, 32);
176Index: 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);
184+
185+ /* Detect OS dependent outermost frames; such as `clone'. */
186+ int (*outermost_frame_p) (struct frame_info *this_frame);
187 };
188
189 /* Floating-point registers. */
190Index: 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
196 };
197
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 ?? () */
202+
203+static char linux_clone2_code[] =
204+{
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,
208+/* st4 [r9]=r8 */
209+/* st4 [r10]=r8 */
210+/* ;; */
211+/* #endif */
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 *| */
216+/* ;; */
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. *| */
220+/* mov b6=out1 */
221+/* br.call.dptk.many rp=b6 |* Call fn(arg) in the child *| */
222+/* ;; */
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 *| */
226+/* mov gp=loc0 */
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. *| */
233+};
234+
235+#define LINUX_CLONE_PRE_SLOTS 3 /* Number of slots before PC. */
236+#define LINUX_CLONE_LEN (sizeof linux_clone2_code)
237+
238+static int
239+ia64_linux_clone2_running (struct frame_info *this_frame)
240+{
241+ CORE_ADDR pc = get_frame_pc (this_frame);
242+ char buf[LINUX_CLONE_LEN];
243+ struct minimal_symbol *minsym;
244+ long long instr;
245+
246+ if (!safe_frame_unwind_memory (this_frame, pc - LINUX_CLONE_PRE_SLOTS * 16,
247+ buf, LINUX_CLONE_LEN))
248+ return 0;
249+
250+ if (memcmp (buf, linux_clone2_code, LINUX_CLONE_PRE_SLOTS * 16) != 0)
251+ return 0;
252+
253+ /* Adjust the expected "_exit" address. */
254+ minsym = lookup_minimal_symbol_text ("_exit", NULL);
255+ if (minsym == NULL)
256+ return 0;
257+
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,
264+ 2);
265+
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)
269+ return 0;
270+
271+ return 1;
272+}
273+
274+static int
275+ia64_outermost_frame (struct frame_info *this_frame)
276+{
277+ CORE_ADDR pc = get_frame_pc (this_frame);
278+ char *name;
279+
280+ find_pc_partial_function (pc, &name, NULL, NULL);
281+
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);
292+
293+ return 0;
294+}
295+
296+static void
297+ia64_clone2_frame_this_id (struct frame_info *this_frame, void **this_cache,
298+ struct frame_id *this_id)
299+{
300+ /* Leave the default outermost frame at *THIS_ID. */
301+}
302+
303+static struct value *
304+ia64_clone2_frame_prev_register (struct frame_info *this_frame,
305+ void **this_cache, int regnum)
306+{
307+ return frame_unwind_got_register (this_frame, regnum, regnum);
308+}
309+
310+static int
311+ia64_clone2_frame_sniffer (const struct frame_unwind *self,
312+ struct frame_info *this_frame,
313+ void **this_prologue_cache)
314+{
315+ if (ia64_outermost_frame (this_frame))
316+ return 1;
317+
318+ return 0;
319+}
320+
321+static const struct frame_unwind ia64_clone2_frame_unwind =
322+{
323+ NORMAL_FRAME,
324+ &ia64_clone2_frame_this_id,
325+ &ia64_clone2_frame_prev_register,
326+ NULL,
327+ &ia64_clone2_frame_sniffer
328+};
329+
330 /* Signal trampolines. */
331
332 static void
333@@ -4153,6 +4285,7 @@ ia64_gdbarch_init (struct gdbarch_info i
334 set_gdbarch_dummy_id (gdbarch, ia64_dummy_id);
335
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);
341Index: gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.c
342===================================================================
3a58abaf 343--- /dev/null 1970-01-01 00:00:00.000000000 +0000
f412e1b4 344+++ gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.c 2012-03-02 22:16:13.530569151 +0100
3a58abaf
AM
345@@ -0,0 +1,39 @@
346+/* This testcase is part of GDB, the GNU debugger.
347+
348+ Copyright 2006 Free Software Foundation, Inc.
349+
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.
354+
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.
359+
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. */
364+
365+
366+#include <pthread.h>
367+#include <unistd.h>
368+#include <assert.h>
369+
370+
371+void *threader (void *arg)
372+{
373+ assert (0);
374+ return NULL;
375+}
376+
377+int main (void)
378+{
379+ pthread_t t1;
380+
381+ pthread_create (&t1, NULL, threader, (void *) NULL);
382+ for (;;)
383+ pause();
384+}
f412e1b4 385Index: gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.exp
3a58abaf
AM
386===================================================================
387--- /dev/null 1970-01-01 00:00:00.000000000 +0000
f412e1b4 388+++ gdb-7.4.50.20120120/gdb/testsuite/gdb.threads/bt-clone-stop.exp 2012-03-02 22:16:13.530569151 +0100
3a58abaf
AM
389@@ -0,0 +1,61 @@
390+# Copyright 2006 Free Software Foundation, Inc.
391+
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.
396+#
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.
401+#
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.
405+
406+# Backtraced `clone' must not have `PC == 0' as its previous frame.
407+
408+if $tracelevel then {
409+ strace $tracelevel
410+}
411+
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"
417+ return -1
418+}
419+
420+# Get things started.
421+
422+gdb_exit
423+gdb_start
424+gdb_reinitialize_dir $srcdir/$subdir
425+gdb_load ${binfile}
426+
427+# threader: threader.c:8: threader: Assertion `0' failed.
428+# Program received signal SIGABRT, Aborted.
429+
430+gdb_test "run" \
431+ "Program received signal SIGABRT.*" \
432+ "run"
433+
434+# Former gdb unwind (the first function is `clone'):
435+# #5 0x0000003421ecd62d in ?? () from /lib64/libc.so.6
436+# #6 0x0000000000000000 in ?? ()
437+# (gdb)
438+# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
439+#
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"
446+ }
447+ -re "in threader \\(.*$gdb_prompt $" {
448+ pass "0x0 entry not found"
449+ }
450+}
This page took 0.109226 seconds and 4 git commands to generate.