1 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
3 2008-02-24 Jan Kratochvil <jan.kratochvil@redhat.com>
7 currently for trivial nonthreaded helloworld with no debug info up to -ggdb2 you
12 * with -ggdb2 and less "errno" in fact does not exist anywhere as it was
13 compiled to "(*__errno_location ())" and the macro definition is not present.
14 Unfortunately gdb will find the TLS symbol and it will try to access it but
15 as the program has been compiled without -lpthread the TLS base register
16 (%gs on i386) is not setup and it will result in:
17 Cannot access memory at address 0x8
19 Attached suggestion patch how to deal with the most common "errno" symbol
20 for the most common under-ggdb3 compiled programs.
24 2007-11-03 Jan Kratochvil <jan.kratochvil@redhat.com>
26 * ./gdb/dwarf2read.c (read_partial_die, dwarf2_linkage_name): Prefer
27 DW_AT_MIPS_linkage_name over DW_AT_name now only for non-C.
29 glibc-debuginfo-2.7-2.x86_64: /usr/lib/debug/lib64/libc.so.6.debug:
30 <81a2> DW_AT_name : (indirect string, offset: 0x280e): __errno_location
31 <81a8> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x2808): *__GI___errno_location
33 Index: gdb-6.8.50.20090228/gdb/gdbtypes.c
34 ===================================================================
35 --- gdb-6.8.50.20090228.orig/gdb/gdbtypes.c 2009-03-02 01:01:15.000000000 +0100
36 +++ gdb-6.8.50.20090228/gdb/gdbtypes.c 2009-03-02 01:01:53.000000000 +0100
37 @@ -3633,6 +3633,8 @@ gdbtypes_post_init (struct gdbarch *gdba
38 init_type (TYPE_CODE_INT,
39 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
40 0, "int", OBJFILE_INTERNAL);
41 + builtin_type->builtin_int_ptr =
42 + make_pointer_type (builtin_type->builtin_int, NULL);
43 builtin_type->builtin_unsigned_int =
44 init_type (TYPE_CODE_INT,
45 gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
46 @@ -3742,6 +3744,12 @@ gdbtypes_post_init (struct gdbarch *gdba
47 "<text variable, no debug info>", OBJFILE_INTERNAL);
48 TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol) =
49 builtin_type->builtin_int;
50 + builtin_type->nodebug_text_symbol_errno_location =
51 + init_type (TYPE_CODE_FUNC, 1, 0,
52 + "<text variable for __errno_location, no debug info>",
54 + TYPE_TARGET_TYPE (builtin_type->nodebug_text_symbol_errno_location) =
55 + builtin_type->builtin_int_ptr;
56 builtin_type->nodebug_data_symbol =
57 init_type (TYPE_CODE_INT,
58 gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
59 Index: gdb-6.8.50.20090228/gdb/gdbtypes.h
60 ===================================================================
61 --- gdb-6.8.50.20090228.orig/gdb/gdbtypes.h 2009-03-02 01:01:15.000000000 +0100
62 +++ gdb-6.8.50.20090228/gdb/gdbtypes.h 2009-03-02 01:01:53.000000000 +0100
63 @@ -1053,6 +1053,7 @@ struct builtin_type
65 /* Types used for symbols with no debug information. */
66 struct type *nodebug_text_symbol;
67 + struct type *nodebug_text_symbol_errno_location;
68 struct type *nodebug_data_symbol;
69 struct type *nodebug_unknown_symbol;
70 struct type *nodebug_tls_symbol;
71 @@ -1065,6 +1066,7 @@ struct builtin_type
72 struct type *builtin_char;
73 struct type *builtin_short;
74 struct type *builtin_int;
75 + struct type *builtin_int_ptr;
76 struct type *builtin_long;
77 struct type *builtin_signed_char;
78 struct type *builtin_unsigned_char;
79 Index: gdb-6.8.50.20090228/gdb/parse.c
80 ===================================================================
81 --- gdb-6.8.50.20090228.orig/gdb/parse.c 2009-03-02 01:01:15.000000000 +0100
82 +++ gdb-6.8.50.20090228/gdb/parse.c 2009-03-02 01:01:53.000000000 +0100
83 @@ -508,7 +508,12 @@ write_exp_msymbol (struct minimal_symbol
86 case mst_solib_trampoline:
87 - write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol);
88 + if (builtin_type (gdbarch)->nodebug_text_symbol_errno_location != NULL
89 + && strcmp (SYMBOL_LINKAGE_NAME (msymbol), "__errno_location") == 0)
90 + write_exp_elt_type (builtin_type (gdbarch)
91 + ->nodebug_text_symbol_errno_location);
93 + write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol);
97 Index: gdb-6.8.50.20090228/gdb/target.c
98 ===================================================================
99 --- gdb-6.8.50.20090228.orig/gdb/target.c 2009-03-02 01:01:44.000000000 +0100
100 +++ gdb-6.8.50.20090228/gdb/target.c 2009-03-02 01:01:53.000000000 +0100
101 @@ -827,6 +827,25 @@ pop_all_targets (int quitting)
102 pop_all_targets_above (dummy_stratum, quitting);
106 +resolve_errno (void *arg)
108 + CORE_ADDR *arg_addr = arg;
109 + struct expression *expr;
110 + struct cleanup *old_chain = 0;
113 + expr = parse_expression ("__errno_location()");
114 + old_chain = make_cleanup (free_current_contents, &expr);
115 + val = evaluate_expression (expr);
116 + *arg_addr = value_as_address (val);
117 + release_value (val);
119 + do_cleanups (old_chain);
124 /* Using the objfile specified in OBJFILE, find the address for the
125 current thread's thread-local storage with offset OFFSET. */
127 @@ -917,7 +936,28 @@ target_translate_tls_address (struct obj
128 /* It wouldn't be wrong here to try a gdbarch method, too; finding
129 TLS is an ABI-specific thing. But we don't do that yet. */
131 - error (_("Cannot find thread-local variables on this target"));
133 + struct minimal_symbol *msymbol;
135 + msymbol = lookup_minimal_symbol ("errno", NULL, NULL);
136 + if (msymbol != NULL
137 + && SYMBOL_VALUE_ADDRESS (msymbol) == offset
138 + && (SYMBOL_OBJ_SECTION (msymbol)->objfile == objfile
139 + || (objfile->separate_debug_objfile != NULL
140 + && SYMBOL_OBJ_SECTION (msymbol)->objfile
141 + == objfile->separate_debug_objfile)
142 + || (objfile->separate_debug_objfile_backlink != NULL
143 + && SYMBOL_OBJ_SECTION (msymbol)->objfile
144 + == objfile->separate_debug_objfile_backlink)))
146 + if (!catch_errors (resolve_errno, (void *) &addr, "",
148 + error (_("TLS symbol `errno' not resolved for non-TLS program."
149 + " You should compile the program with `gcc -pthread'."));
152 + error (_("Cannot find thread-local variables on this target"));
157 Index: gdb-6.8.50.20090228/gdb/testsuite/gdb.dwarf2/dw2-errno.c
158 ===================================================================
159 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
160 +++ gdb-6.8.50.20090228/gdb/testsuite/gdb.dwarf2/dw2-errno.c 2009-03-02 01:01:53.000000000 +0100
162 +/* This testcase is part of GDB, the GNU debugger.
164 + Copyright 2005, 2007 Free Software Foundation, Inc.
166 + This program is free software; you can redistribute it and/or modify
167 + it under the terms of the GNU General Public License as published by
168 + the Free Software Foundation; either version 3 of the License, or
169 + (at your option) any later version.
171 + This program is distributed in the hope that it will be useful,
172 + but WITHOUT ANY WARRANTY; without even the implied warranty of
173 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174 + GNU General Public License for more details.
176 + You should have received a copy of the GNU General Public License
177 + along with this program. If not, see <http://www.gnu.org/licenses/>.
179 + Please email any bugs, comments, and/or additions to this file to:
180 + bug-gdb@prep.ai.mit.edu */
188 + return 0; /* breakpoint */
190 Index: gdb-6.8.50.20090228/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
191 ===================================================================
192 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
193 +++ gdb-6.8.50.20090228/gdb/testsuite/gdb.dwarf2/dw2-errno.exp 2009-03-02 01:01:53.000000000 +0100
195 +# Copyright 2007 Free Software Foundation, Inc.
197 +# This program is free software; you can redistribute it and/or modify
198 +# it under the terms of the GNU General Public License as published by
199 +# the Free Software Foundation; either version 3 of the License, or
200 +# (at your option) any later version.
202 +# This program is distributed in the hope that it will be useful,
203 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
204 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
205 +# GNU General Public License for more details.
207 +# You should have received a copy of the GNU General Public License
208 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
210 +if $tracelevel then {
217 +set testfile dw2-errno
218 +set srcfile ${testfile}.c
219 +set binfile ${objdir}/${subdir}/${testfile}
222 + global srcdir subdir binfile
225 + gdb_reinitialize_dir $srcdir/$subdir
226 + gdb_load ${binfile}
230 + gdb_breakpoint [gdb_get_line_number "breakpoint"]
231 + gdb_continue_to_breakpoint "breakpoint"
234 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
235 + untested "Couldn't compile test program"
239 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
241 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
242 + untested "Couldn't compile test program"
246 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
248 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
252 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
254 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
258 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
260 +# TODO: Test the error on resolving ERRNO with only libc loaded.
261 +# Just how to find the current libc filename?