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.20090802/gdb/gdbtypes.c
34 ===================================================================
35 --- gdb-6.8.50.20090802.orig/gdb/gdbtypes.c 2009-08-03 09:50:57.000000000 +0200
36 +++ gdb-6.8.50.20090802/gdb/gdbtypes.c 2009-08-03 15:42:51.000000000 +0200
37 @@ -3769,6 +3769,9 @@ gdbtypes_post_init (struct gdbarch *gdba
38 = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0,
39 "<internal function>");
41 + builtin_type->nodebug_text_symbol_errno_location
42 + = lookup_function_type (lookup_pointer_type (builtin_type->builtin_int));
47 Index: gdb-6.8.50.20090802/gdb/gdbtypes.h
48 ===================================================================
49 --- gdb-6.8.50.20090802.orig/gdb/gdbtypes.h 2009-08-03 09:50:57.000000000 +0200
50 +++ gdb-6.8.50.20090802/gdb/gdbtypes.h 2009-08-03 15:40:02.000000000 +0200
51 @@ -1128,6 +1128,8 @@ struct builtin_type
53 /* This type is used to represent a GDB internal function. */
54 struct type *internal_fn;
56 + struct type *nodebug_text_symbol_errno_location;
59 /* Return the type table for the specified architecture. */
60 Index: gdb-6.8.50.20090802/gdb/parse.c
61 ===================================================================
62 --- gdb-6.8.50.20090802.orig/gdb/parse.c 2009-08-03 09:50:57.000000000 +0200
63 +++ gdb-6.8.50.20090802/gdb/parse.c 2009-08-03 15:41:54.000000000 +0200
64 @@ -510,7 +510,11 @@ write_exp_msymbol (struct minimal_symbol
67 case mst_solib_trampoline:
68 - write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
69 + if (builtin_type (gdbarch)->nodebug_text_symbol_errno_location != NULL
70 + && strcmp (SYMBOL_LINKAGE_NAME (msymbol), "__errno_location") == 0)
71 + write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol_errno_location);
73 + write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
77 Index: gdb-6.8.50.20090802/gdb/target.c
78 ===================================================================
79 --- gdb-6.8.50.20090802.orig/gdb/target.c 2009-08-03 12:38:47.000000000 +0200
80 +++ gdb-6.8.50.20090802/gdb/target.c 2009-08-03 12:49:33.000000000 +0200
81 @@ -933,6 +933,25 @@ pop_all_targets (int quitting)
82 pop_all_targets_above (dummy_stratum, quitting);
86 +resolve_errno (void *arg)
88 + CORE_ADDR *arg_addr = arg;
89 + struct expression *expr;
90 + struct cleanup *old_chain = 0;
93 + expr = parse_expression ("__errno_location()");
94 + old_chain = make_cleanup (free_current_contents, &expr);
95 + val = evaluate_expression (expr);
96 + *arg_addr = value_as_address (val);
97 + release_value (val);
99 + do_cleanups (old_chain);
104 /* Using the objfile specified in OBJFILE, find the address for the
105 current thread's thread-local storage with offset OFFSET. */
107 @@ -1023,7 +1042,28 @@ target_translate_tls_address (struct obj
108 /* It wouldn't be wrong here to try a gdbarch method, too; finding
109 TLS is an ABI-specific thing. But we don't do that yet. */
111 - error (_("Cannot find thread-local variables on this target"));
113 + struct minimal_symbol *msymbol;
115 + msymbol = lookup_minimal_symbol ("errno", NULL, NULL);
116 + if (msymbol != NULL
117 + && SYMBOL_VALUE_ADDRESS (msymbol) == offset
118 + && (SYMBOL_OBJ_SECTION (msymbol)->objfile == objfile
119 + || (objfile->separate_debug_objfile != NULL
120 + && SYMBOL_OBJ_SECTION (msymbol)->objfile
121 + == objfile->separate_debug_objfile)
122 + || (objfile->separate_debug_objfile_backlink != NULL
123 + && SYMBOL_OBJ_SECTION (msymbol)->objfile
124 + == objfile->separate_debug_objfile_backlink)))
126 + if (!catch_errors (resolve_errno, (void *) &addr, "",
128 + error (_("TLS symbol `errno' not resolved for non-TLS program."
129 + " You should compile the program with `gcc -pthread'."));
132 + error (_("Cannot find thread-local variables on this target"));
137 Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.c
138 ===================================================================
139 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
140 +++ gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.c 2009-08-03 12:49:33.000000000 +0200
142 +/* This testcase is part of GDB, the GNU debugger.
144 + Copyright 2005, 2007 Free Software Foundation, Inc.
146 + This program is free software; you can redistribute it and/or modify
147 + it under the terms of the GNU General Public License as published by
148 + the Free Software Foundation; either version 3 of the License, or
149 + (at your option) any later version.
151 + This program is distributed in the hope that it will be useful,
152 + but WITHOUT ANY WARRANTY; without even the implied warranty of
153 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
154 + GNU General Public License for more details.
156 + You should have received a copy of the GNU General Public License
157 + along with this program. If not, see <http://www.gnu.org/licenses/>.
159 + Please email any bugs, comments, and/or additions to this file to:
160 + bug-gdb@prep.ai.mit.edu */
168 + return 0; /* breakpoint */
170 Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
171 ===================================================================
172 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
173 +++ gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.exp 2009-08-03 12:49:33.000000000 +0200
175 +# Copyright 2007 Free Software Foundation, Inc.
177 +# This program is free software; you can redistribute it and/or modify
178 +# it under the terms of the GNU General Public License as published by
179 +# the Free Software Foundation; either version 3 of the License, or
180 +# (at your option) any later version.
182 +# This program is distributed in the hope that it will be useful,
183 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
184 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
185 +# GNU General Public License for more details.
187 +# You should have received a copy of the GNU General Public License
188 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
190 +if $tracelevel then {
197 +set testfile dw2-errno
198 +set srcfile ${testfile}.c
199 +set binfile ${objdir}/${subdir}/${testfile}
202 + global srcdir subdir binfile
205 + gdb_reinitialize_dir $srcdir/$subdir
206 + gdb_load ${binfile}
210 + gdb_breakpoint [gdb_get_line_number "breakpoint"]
211 + gdb_continue_to_breakpoint "breakpoint"
214 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
215 + untested "Couldn't compile test program"
219 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
221 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
222 + untested "Couldn't compile test program"
226 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
228 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
232 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
234 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
238 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
240 +# TODO: Test the error on resolving ERRNO with only libc loaded.
241 +# Just how to find the current libc filename?