]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.5-bz216711-clone-is-outermost.patch
- obsolete file
[packages/gdb.git] / gdb-6.5-bz216711-clone-is-outermost.patch
1 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=216711
2
3 FIXME: This workaround should be dropped and
4 glibc/sysdeps/unix/sysv/linux/x86_64/clone.S should get CFI for the child
5 instead.
6
7 2006-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
17 2006-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
22 2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
23
24         Port to GDB-6.7.
25
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 
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 @@ -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);
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);
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 *
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  
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;
148  
149 +  /* Unwinding stops on i386 automatically.  */
150 +  tdep->outermost_frame_p = NULL;
151 +
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;
163 +
164 +  /* Detect OS dependent outermost frames; such as `clone'.  */
165 +  int (*outermost_frame_p) (struct frame_info *this_frame);
166  };
167  
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
173 @@ -0,0 +1,39 @@
174 +/* This testcase is part of GDB, the GNU debugger.
175 +
176 +   Copyright 2006 Free Software Foundation, Inc.
177 +
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.
182 +
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.
187
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.  */
192 +
193 +
194 +#include <pthread.h>
195 +#include <unistd.h>
196 +#include <assert.h>
197 +
198 +
199 +void *threader (void *arg)
200 +{
201 +       assert (0);
202 +       return NULL;
203 +}
204 +
205 +int main (void)
206 +{
207 +       pthread_t t1;
208 +
209 +       pthread_create (&t1, NULL, threader, (void *) NULL);
210 +       for (;;)
211 +               pause();
212 +}
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
217 @@ -0,0 +1,61 @@
218 +# Copyright 2006 Free Software Foundation, Inc.
219 +
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.
224 +# 
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.
229 +# 
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.  
233 +
234 +# Backtraced `clone' must not have `PC == 0' as its previous frame.
235 +
236 +if $tracelevel then {
237 +    strace $tracelevel
238 +}
239 +
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"
245 +    return -1
246 +}
247 +
248 +# Get things started.
249 +
250 +gdb_exit
251 +gdb_start
252 +gdb_reinitialize_dir $srcdir/$subdir
253 +gdb_load ${binfile}
254 +
255 +# threader: threader.c:8: threader: Assertion `0' failed.
256 +# Program received signal SIGABRT, Aborted.
257 +
258 +gdb_test "run" \
259 +     "Program received signal SIGABRT.*" \
260 +     "run"
261 +
262 +# Former gdb unwind (the first function is `clone'):
263 +# #5  0x0000003421ecd62d in ?? () from /lib64/libc.so.6
264 +# #6  0x0000000000000000 in ?? ()
265 +# (gdb)
266 +# Tested `amd64_linux_outermost_frame' functionality should omit the line `#6'.
267 +# 
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"
274 +    }
275 +    -re "in threader \\(.*$gdb_prompt $" {
276 +       pass "0x0 entry not found"
277 +    }
278 +}
This page took 0.21745 seconds and 3 git commands to generate.