]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.5-bz216711-clone-is-outermost.patch
- update to 6.8.91.20090930-1 from fedora
[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
7566401a 26Index: gdb-6.8.50.20090802/gdb/amd64-linux-tdep.c
3a58abaf 27===================================================================
7566401a
ER
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
3a58abaf
AM
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 {
7566401a 111@@ -276,6 +350,8 @@ amd64_linux_init_abi (struct gdbarch_inf
3a58abaf
AM
112 tdep->sc_reg_offset = amd64_linux_sc_reg_offset;
113 tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_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);
7566401a 120Index: gdb-6.8.50.20090802/gdb/amd64-tdep.c
3a58abaf 121===================================================================
7566401a
ER
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 *
3a58abaf
AM
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 /* This marks the outermost frame. */
131 if (cache->base == 0)
132 return;
133
134+ /* Detect OS dependent outermost frames; such as `clone'. */
135+ if (tdep->outermost_frame_p && tdep->outermost_frame_p (this_frame))
136+ return;
137+
138 (*this_id) = frame_id_build (cache->base + 16, cache->pc);
139 }
140
7566401a
ER
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
3a58abaf
AM
144 tdep->sc_pc_offset = -1;
145 tdep->sc_sp_offset = -1;
146
147+ /* Unwinding stops on i386 automatically. */
148+ tdep->outermost_frame_p = NULL;
149+
7566401a
ER
150 tdep->record_regmap = i386_record_regmap;
151
3a58abaf 152 /* The format used for `long double' on almost all i386 targets is
7566401a
ER
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);
3a58abaf
AM
159+
160+ /* Detect OS dependent outermost frames; such as `clone'. */
161+ int (*outermost_frame_p) (struct frame_info *this_frame);
162 };
163
164 /* Floating-point registers. */
7566401a 165Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.c
3a58abaf
AM
166===================================================================
167--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 168+++ gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.c 2009-08-03 15:50:08.000000000 +0200
3a58abaf
AM
169@@ -0,0 +1,39 @@
170+/* This testcase is part of GDB, the GNU debugger.
171+
172+ Copyright 2006 Free Software Foundation, Inc.
173+
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.
178+
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.
183+
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. */
188+
189+
190+#include <pthread.h>
191+#include <unistd.h>
192+#include <assert.h>
193+
194+
195+void *threader (void *arg)
196+{
197+ assert (0);
198+ return NULL;
199+}
200+
201+int main (void)
202+{
203+ pthread_t t1;
204+
205+ pthread_create (&t1, NULL, threader, (void *) NULL);
206+ for (;;)
207+ pause();
208+}
7566401a 209Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.exp
3a58abaf
AM
210===================================================================
211--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 212+++ gdb-6.8.50.20090802/gdb/testsuite/gdb.threads/bt-clone-stop.exp 2009-08-03 15:50:08.000000000 +0200
3a58abaf
AM
213@@ -0,0 +1,61 @@
214+# Copyright 2006 Free Software Foundation, Inc.
215+
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.
220+#
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.
225+#
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.
229+
230+# Backtraced `clone' must not have `PC == 0' as its previous frame.
231+
232+if $tracelevel then {
233+ strace $tracelevel
234+}
235+
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"
241+ return -1
242+}
243+
244+# Get things started.
245+
246+gdb_exit
247+gdb_start
248+gdb_reinitialize_dir $srcdir/$subdir
249+gdb_load ${binfile}
250+
251+# threader: threader.c:8: threader: Assertion `0' failed.
252+# Program received signal SIGABRT, Aborted.
253+
254+gdb_test "run" \
255+ "Program received signal SIGABRT.*" \
256+ "run"
257+
258+# Former gdb unwind (the first function is `clone'):
259+# #5 0x0000003421ecd62d in ?? () from /lib64/libc.so.6
260+# #6 0x0000000000000000 in ?? ()
261+# (gdb)
262+# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
263+#
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"
270+ }
271+ -re "in threader \\(.*$gdb_prompt $" {
272+ pass "0x0 entry not found"
273+ }
274+}
This page took 0.085946 seconds and 4 git commands to generate.