]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
- update to 6.8.91.20090930-1 from fedora
[packages/gdb.git] / gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
CommitLineData
3a58abaf
AM
1https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
2
32008-02-24 Jan Kratochvil <jan.kratochvil@redhat.com>
4
5 Port to GDB-6.8pre.
6
7currently for trivial nonthreaded helloworld with no debug info up to -ggdb2 you
8will get:
9 (gdb) p errno
10 [some error]
11
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
18
19Attached suggestion patch how to deal with the most common "errno" symbol
20for the most common under-ggdb3 compiled programs.
21
22
23
242007-11-03 Jan Kratochvil <jan.kratochvil@redhat.com>
25
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.
28
29glibc-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
32
7566401a 33Index: gdb-6.8.50.20090802/gdb/gdbtypes.c
3a58abaf 34===================================================================
7566401a
ER
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>");
40
41+ builtin_type->nodebug_text_symbol_errno_location
42+ = lookup_function_type (lookup_pointer_type (builtin_type->builtin_int));
43+
44 return builtin_type;
45 }
46
47Index: gdb-6.8.50.20090802/gdb/gdbtypes.h
3a58abaf 48===================================================================
7566401a
ER
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
3a58abaf 52
7566401a
ER
53 /* This type is used to represent a GDB internal function. */
54 struct type *internal_fn;
55+
3a58abaf 56+ struct type *nodebug_text_symbol_errno_location;
7566401a
ER
57 };
58
59 /* Return the type table for the specified architecture. */
60Index: gdb-6.8.50.20090802/gdb/parse.c
3a58abaf 61===================================================================
7566401a
ER
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
3a58abaf
AM
65 case mst_text:
66 case mst_file_text:
67 case mst_solib_trampoline:
7566401a 68- write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
3a58abaf
AM
69+ if (builtin_type (gdbarch)->nodebug_text_symbol_errno_location != NULL
70+ && strcmp (SYMBOL_LINKAGE_NAME (msymbol), "__errno_location") == 0)
7566401a 71+ write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol_errno_location);
3a58abaf 72+ else
7566401a 73+ write_exp_elt_type (objfile_type (objfile)->nodebug_text_symbol);
3a58abaf
AM
74 break;
75
76 case mst_data:
7566401a 77Index: gdb-6.8.50.20090802/gdb/target.c
3a58abaf 78===================================================================
7566401a
ER
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)
3a58abaf
AM
82 pop_all_targets_above (dummy_stratum, quitting);
83 }
84
85+static int
86+resolve_errno (void *arg)
87+{
88+ CORE_ADDR *arg_addr = arg;
89+ struct expression *expr;
90+ struct cleanup *old_chain = 0;
91+ struct value *val;
92+
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);
98+ value_free (val);
99+ do_cleanups (old_chain);
100+
101+ return 1;
102+}
103+
104 /* Using the objfile specified in OBJFILE, find the address for the
105 current thread's thread-local storage with offset OFFSET. */
106 CORE_ADDR
7566401a 107@@ -1023,7 +1042,28 @@ target_translate_tls_address (struct obj
3a58abaf
AM
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. */
110 else
111- error (_("Cannot find thread-local variables on this target"));
112+ {
113+ struct minimal_symbol *msymbol;
114+
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)))
125+ {
126+ if (!catch_errors (resolve_errno, (void *) &addr, "",
127+ RETURN_MASK_ALL))
128+ error (_("TLS symbol `errno' not resolved for non-TLS program."
129+ " You should compile the program with `gcc -pthread'."));
130+ }
131+ else
132+ error (_("Cannot find thread-local variables on this target"));
133+ }
134
135 return addr;
136 }
7566401a 137Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.c
3a58abaf
AM
138===================================================================
139--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 140+++ gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.c 2009-08-03 12:49:33.000000000 +0200
3a58abaf
AM
141@@ -0,0 +1,28 @@
142+/* This testcase is part of GDB, the GNU debugger.
143+
144+ Copyright 2005, 2007 Free Software Foundation, Inc.
145+
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.
150+
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.
155+
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/>.
158+
159+ Please email any bugs, comments, and/or additions to this file to:
160+ bug-gdb@prep.ai.mit.edu */
161+
162+#include <errno.h>
163+
164+int main()
165+{
166+ errno = 42;
167+
168+ return 0; /* breakpoint */
169+}
7566401a 170Index: gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
3a58abaf
AM
171===================================================================
172--- /dev/null 1970-01-01 00:00:00.000000000 +0000
7566401a 173+++ gdb-6.8.50.20090802/gdb/testsuite/gdb.dwarf2/dw2-errno.exp 2009-08-03 12:49:33.000000000 +0200
3a58abaf
AM
174@@ -0,0 +1,67 @@
175+# Copyright 2007 Free Software Foundation, Inc.
176+
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.
181+#
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.
186+#
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/>.
189+
190+if $tracelevel then {
191+ strace $tracelevel
192+}
193+
194+set prms_id 0
195+set bug_id 0
196+
197+set testfile dw2-errno
198+set srcfile ${testfile}.c
199+set binfile ${objdir}/${subdir}/${testfile}
200+
201+proc prep {} {
202+ global srcdir subdir binfile
203+ gdb_exit
204+ gdb_start
205+ gdb_reinitialize_dir $srcdir/$subdir
206+ gdb_load ${binfile}
207+
208+ runto_main
209+
210+ gdb_breakpoint [gdb_get_line_number "breakpoint"]
211+ gdb_continue_to_breakpoint "breakpoint"
212+}
213+
214+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
215+ untested "Couldn't compile test program"
216+ return -1
217+}
218+prep
219+gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
220+
221+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
222+ untested "Couldn't compile test program"
223+ return -1
224+}
225+prep
226+gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
227+
228+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
229+ return -1
230+}
231+prep
232+gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
233+
234+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
235+ return -1
236+}
237+prep
238+gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
239+
240+# TODO: Test the error on resolving ERRNO with only libc loaded.
241+# Just how to find the current libc filename?
This page took 0.065007 seconds and 4 git commands to generate.