Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/gdb/6.8: 90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch README.history
Date: Thu, 12 Mar 2009 03:15:57
Message-Id: E1LhbOk-0006fG-Ti@stork.gentoo.org
1 vapier 09/03/12 03:15:54
2
3 Modified: README.history
4 Added:
5 90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
6 Log:
7 add patch from fedora for accessing tls vars (errno)
8
9 Revision Changes Path
10 1.6 src/patchsets/gdb/6.8/README.history
11
12 file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/README.history?rev=1.6&view=markup
13 plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/README.history?rev=1.6&content-type=text/plain
14 diff : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/README.history?r1=1.5&r2=1.6
15
16 Index: README.history
17 ===================================================================
18 RCS file: /var/cvsroot/gentoo/src/patchsets/gdb/6.8/README.history,v
19 retrieving revision 1.5
20 retrieving revision 1.6
21 diff -u -r1.5 -r1.6
22 --- README.history 22 Feb 2009 19:44:29 -0000 1.5
23 +++ README.history 12 Mar 2009 03:15:54 -0000 1.6
24 @@ -1,3 +1,6 @@
25 +1.5 11.03.2009
26 + + 90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
27 +
28 1.4 22.02.2009
29 + 05_all_readline-headers.patch
30
31
32
33
34 1.1 src/patchsets/gdb/6.8/90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
35
36 file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch?rev=1.1&view=markup
37 plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch?rev=1.1&content-type=text/plain
38
39 Index: 90_all_gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
40 ===================================================================
41 (snipped from fedora)
42
43 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
44
45 2008-02-24 Jan Kratochvil <jan.kratochvil@××××××.com>
46
47 Port to GDB-6.8pre.
48
49 currently for trivial nonthreaded helloworld with no debug info up to -ggdb2 you
50 will get:
51 (gdb) p errno
52 [some error]
53
54 * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
55 compiled to "(*__errno_location ())" and the macro definition is not present.
56 Unfortunately gdb will find the TLS symbol and it will try to access it but
57 as the program has been compiled without -lpthread the TLS base register
58 (%gs on i386) is not setup and it will result in:
59 Cannot access memory at address 0x8
60
61 Attached suggestion patch how to deal with the most common "errno" symbol
62 for the most common under-ggdb3 compiled programs.
63
64
65
66 2007-11-03 Jan Kratochvil <jan.kratochvil@××××××.com>
67
68 * ./gdb/dwarf2read.c (read_partial_die, dwarf2_linkage_name): Prefer
69 DW_AT_MIPS_linkage_name over DW_AT_name now only for non-C.
70
71 glibc-debuginfo-2.7-2.x86_64: /usr/lib/debug/lib64/libc.so.6.debug:
72 <81a2> DW_AT_name : (indirect string, offset: 0x280e): __errno_location
73 <81a8> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x2808): *__GI___errno_location
74
75 Index: gdb-6.8cvs20080219/gdb/dwarf2read.c
76 ===================================================================
77 --- gdb-6.8cvs20080219.orig/gdb/dwarf2read.c 2008-02-19 17:27:21.000000000 +0100
78 +++ gdb-6.8cvs20080219/gdb/dwarf2read.c 2008-02-20 13:35:19.000000000 +0100
79 @@ -5679,8 +5679,8 @@ read_partial_die (struct partial_die_inf
80 {
81 case DW_AT_name:
82
83 - /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
84 - if (part_die->name == NULL)
85 + /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name for non-C. */
86 + if (cu->language == language_c || part_die->name == NULL)
87 part_die->name = DW_STRING (&attr);
88 break;
89 case DW_AT_comp_dir:
90 @@ -5688,7 +5688,9 @@ read_partial_die (struct partial_die_inf
91 part_die->dirname = DW_STRING (&attr);
92 break;
93 case DW_AT_MIPS_linkage_name:
94 - part_die->name = DW_STRING (&attr);
95 + /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name for non-C. */
96 + if (cu->language != language_c || part_die->name == NULL)
97 + part_die->name = DW_STRING (&attr);
98 break;
99 case DW_AT_low_pc:
100 has_low_pc_attr = 1;
101 @@ -7936,9 +7938,13 @@ dwarf2_linkage_name (struct die_info *di
102 {
103 struct attribute *attr;
104
105 - attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
106 - if (attr && DW_STRING (attr))
107 - return DW_STRING (attr);
108 + /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name for non-C. */
109 + if (cu->language != language_c)
110 + {
111 + attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu);
112 + if (attr && DW_STRING (attr))
113 + return DW_STRING (attr);
114 + }
115 attr = dwarf2_attr (die, DW_AT_name, cu);
116 if (attr && DW_STRING (attr))
117 return DW_STRING (attr);
118 Index: gdb-6.8cvs20080219/gdb/gdbtypes.c
119 ===================================================================
120 --- gdb-6.8cvs20080219.orig/gdb/gdbtypes.c 2008-02-14 23:03:57.000000000 +0100
121 +++ gdb-6.8cvs20080219/gdb/gdbtypes.c 2008-02-20 13:35:19.000000000 +0100
122 @@ -3106,6 +3106,8 @@ gdbtypes_post_init (struct gdbarch *gdba
123 init_type (TYPE_CODE_INT,
124 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
125 0, "int", (struct objfile *) NULL);
126 + builtin_type->builtin_int_ptr =
127 + make_pointer_type (builtin_type->builtin_int, NULL);
128 builtin_type->builtin_unsigned_int =
129 init_type (TYPE_CODE_INT,
130 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
131 @@ -3215,6 +3217,11 @@ gdbtypes_post_init (struct gdbarch *gdba
132 "<text variable, no debug info>", NULL);
133 TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
134 builtin_type->builtin_int;
135 + builtin_type->nodebug_text_symbol_errno_location =
136 + init_type (TYPE_CODE_FUNC, 1, 0,
137 + "<text variable for __errno_location, no debug info>", NULL);
138 + TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol_errno_location) =
139 + builtin_type->builtin_int_ptr;
140 builtin_type->nodebug_data_symbol =
141 init_type (TYPE_CODE_INT,
142 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
143 Index: gdb-6.8cvs20080219/gdb/gdbtypes.h
144 ===================================================================
145 --- gdb-6.8cvs20080219.orig/gdb/gdbtypes.h 2008-02-14 23:03:57.000000000 +0100
146 +++ gdb-6.8cvs20080219/gdb/gdbtypes.h 2008-02-20 13:35:19.000000000 +0100
147 @@ -942,6 +942,7 @@ struct builtin_type
148
149 /* Types used for symbols with no debug information. */
150 struct type *nodebug_text_symbol;
151 + struct type *nodebug_text_symbol_errno_location;
152 struct type *nodebug_data_symbol;
153 struct type *nodebug_unknown_symbol;
154 struct type *nodebug_tls_symbol;
155 @@ -960,6 +961,7 @@ struct builtin_type
156 struct type *builtin_char;
157 struct type *builtin_short;
158 struct type *builtin_int;
159 + struct type *builtin_int_ptr;
160 struct type *builtin_long;
161 struct type *builtin_signed_char;
162 struct type *builtin_unsigned_char;
163 Index: gdb-6.8cvs20080219/gdb/parse.c
164 ===================================================================
165 --- gdb-6.8cvs20080219.orig/gdb/parse.c 2008-01-02 00:04:03.000000000 +0100
166 +++ gdb-6.8cvs20080219/gdb/parse.c 2008-02-20 13:35:19.000000000 +0100
167 @@ -437,7 +437,12 @@ write_exp_msymbol (struct minimal_symbol
168 case mst_text:
169 case mst_file_text:
170 case mst_solib_trampoline:
171 - write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol);
172 + if (builtin_type (gdbarch)->nodebug_text_symbol_errno_location != NULL
173 + && strcmp (SYMBOL_LINKAGE_NAME (msymbol), "__errno_location") == 0)
174 + write_exp_elt_type (builtin_type (gdbarch)
175 + ->nodebug_text_symbol_errno_location);
176 + else
177 + write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol);
178 break;
179
180 case mst_data:
181 Index: gdb-6.8cvs20080219/gdb/target.c
182 ===================================================================
183 --- gdb-6.8cvs20080219.orig/gdb/target.c 2008-02-19 17:22:33.000000000 +0100
184 +++ gdb-6.8cvs20080219/gdb/target.c 2008-02-20 13:36:17.000000000 +0100
185 @@ -812,6 +812,25 @@ pop_target (void)
186 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
187 }
188
189 +static int
190 +resolve_errno (void *arg)
191 +{
192 + CORE_ADDR *arg_addr = arg;
193 + struct expression *expr;
194 + struct cleanup *old_chain = 0;
195 + struct value *val;
196 +
197 + expr = parse_expression ("__errno_location()");
198 + old_chain = make_cleanup (free_current_contents, &expr);
199 + val = evaluate_expression (expr);
200 + *arg_addr = value_as_address (val);
201 + release_value (val);
202 + value_free (val);
203 + do_cleanups (old_chain);
204 +
205 + return 1;
206 +}
207 +
208 /* Using the objfile specified in OBJFILE, find the address for the
209 current thread's thread-local storage with offset OFFSET. */
210 CORE_ADDR
211 @@ -893,7 +912,28 @@ target_translate_tls_address (struct obj
212 /* It wouldn't be wrong here to try a gdbarch method, too; finding
213 TLS is an ABI-specific thing. But we don't do that yet. */
214 else
215 - error (_("Cannot find thread-local variables on this target"));
216 + {
217 + struct minimal_symbol *msymbol;
218 +
219 + msymbol = lookup_minimal_symbol ("errno", NULL, NULL);
220 + if (msymbol != NULL
221 + && SYMBOL_VALUE_ADDRESS (msymbol) == offset
222 + && (SYMBOL_BFD_SECTION (msymbol)->owner == objfile->obfd
223 + || (objfile->separate_debug_objfile != NULL
224 + && SYMBOL_BFD_SECTION (msymbol)->owner
225 + == objfile->separate_debug_objfile->obfd)
226 + || (objfile->separate_debug_objfile_backlink != NULL
227 + && SYMBOL_BFD_SECTION (msymbol)->owner
228 + == objfile->separate_debug_objfile_backlink->obfd)))
229 + {
230 + if (!catch_errors (resolve_errno, (void *) &addr, "",
231 + RETURN_MASK_ALL))
232 + error (_("TLS symbol `errno' not resolved for non-TLS program."
233 + " You should compile the program with `gcc -pthread'."));
234 + }
235 + else
236 + error (_("Cannot find thread-local variables on this target"));
237 + }
238
239 return addr;
240 }
241 --- ./gdb/elfread.c 2008-08-03 11:02:10.000000000 +0200
242 +++ ./gdb/elfread.c 2008-08-03 11:01:21.000000000 +0200
243 @@ -318,7 +318,8 @@ elf_symtab_read (struct objfile *objfile
244 /* Bfd symbols are section relative. */
245 symaddr = sym->value + sym->section->vma;
246 /* Relocate all non-absolute symbols by the section offset. */
247 - if (sym->section != &bfd_abs_section)
248 + if (sym->section != &bfd_abs_section
249 + && (sym->section->flags & SEC_THREAD_LOCAL) == 0)
250 {
251 symaddr += offset;
252 }
253 Index: gdb-6.8cvs20080219/gdb/testsuite/gdb.dwarf2/dw2-errno.c
254 ===================================================================
255 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
256 +++ gdb-6.8cvs20080219/gdb/testsuite/gdb.dwarf2/dw2-errno.c 2008-02-20 13:35:19.000000000 +0100
257 @@ -0,0 +1,28 @@
258 +/* This testcase is part of GDB, the GNU debugger.
259 +
260 + Copyright 2005, 2007 Free Software Foundation, Inc.
261 +
262 + This program is free software; you can redistribute it and/or modify
263 + it under the terms of the GNU General Public License as published by
264 + the Free Software Foundation; either version 3 of the License, or
265 + (at your option) any later version.
266 +
267 + This program is distributed in the hope that it will be useful,
268 + but WITHOUT ANY WARRANTY; without even the implied warranty of
269 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
270 + GNU General Public License for more details.
271 +
272 + You should have received a copy of the GNU General Public License
273 + along with this program. If not, see <http://www.gnu.org/licenses/>.
274 +
275 + Please email any bugs, comments, and/or additions to this file to:
276 + bug-gdb@×××××××××××.edu */
277 +
278 +#include <errno.h>
279 +
280 +int main()
281 +{
282 + errno = 42;
283 +
284 + return 0; /* breakpoint */
285 +}
286 Index: gdb-6.8cvs20080219/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
287 ===================================================================
288 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
289 +++ gdb-6.8cvs20080219/gdb/testsuite/gdb.dwarf2/dw2-errno.exp 2008-02-20 13:35:19.000000000 +0100
290 @@ -0,0 +1,67 @@
291 +# Copyright 2007 Free Software Foundation, Inc.
292 +
293 +# This program is free software; you can redistribute it and/or modify
294 +# it under the terms of the GNU General Public License as published by
295 +# the Free Software Foundation; either version 3 of the License, or
296 +# (at your option) any later version.
297 +#
298 +# This program is distributed in the hope that it will be useful,
299 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
300 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
301 +# GNU General Public License for more details.
302 +#
303 +# You should have received a copy of the GNU General Public License
304 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
305 +
306 +if $tracelevel then {
307 + strace $tracelevel
308 +}
309 +
310 +set prms_id 0
311 +set bug_id 0
312 +
313 +set testfile dw2-errno
314 +set srcfile ${testfile}.c
315 +set binfile ${objdir}/${subdir}/${testfile}
316 +
317 +proc prep {} {
318 + global srcdir subdir binfile
319 + gdb_exit
320 + gdb_start
321 + gdb_reinitialize_dir $srcdir/$subdir
322 + gdb_load ${binfile}
323 +
324 + runto_main
325 +
326 + gdb_breakpoint [gdb_get_line_number "breakpoint"]
327 + gdb_continue_to_breakpoint "breakpoint"
328 +}
329 +
330 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
331 + untested "Couldn't compile test program"
332 + return -1
333 +}
334 +prep
335 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
336 +
337 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
338 + untested "Couldn't compile test program"
339 + return -1
340 +}
341 +prep
342 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
343 +
344 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
345 + return -1
346 +}
347 +prep
348 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
349 +
350 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
351 + return -1
352 +}
353 +prep
354 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
355 +
356 +# TODO: Test the error on resolving ERRNO with only libc loaded.
357 +# Just how to find the current libc filename?