]>
Commit | Line | Data |
---|---|---|
3a58abaf AM |
1 | https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337 |
2 | ||
3 | 2008-02-24 Jan Kratochvil <jan.kratochvil@redhat.com> | |
4 | ||
5 | Port to GDB-6.8pre. | |
6 | ||
7 | currently for trivial nonthreaded helloworld with no debug info up to -ggdb2 you | |
8 | will 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 | ||
19 | Attached suggestion patch how to deal with the most common "errno" symbol | |
20 | for the most common under-ggdb3 compiled programs. | |
21 | ||
22 | ||
23 | ||
24 | 2007-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 | ||
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 | |
32 | ||
51a5ef0f | 33 | Index: gdb-7.0.50.20100128/gdb/gdbtypes.c |
3a58abaf | 34 | =================================================================== |
51a5ef0f PS |
35 | --- gdb-7.0.50.20100128.orig/gdb/gdbtypes.c 2010-01-28 12:52:17.000000000 +0100 |
36 | +++ gdb-7.0.50.20100128/gdb/gdbtypes.c 2010-01-28 12:52:48.000000000 +0100 | |
37 | @@ -3978,6 +3978,9 @@ gdbtypes_post_init (struct gdbarch *gdba | |
7566401a ER |
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 | ||
51a5ef0f | 47 | Index: gdb-7.0.50.20100128/gdb/gdbtypes.h |
3a58abaf | 48 | =================================================================== |
51a5ef0f PS |
49 | --- gdb-7.0.50.20100128.orig/gdb/gdbtypes.h 2010-01-28 12:52:17.000000000 +0100 |
50 | +++ gdb-7.0.50.20100128/gdb/gdbtypes.h 2010-01-28 12:52:48.000000000 +0100 | |
51 | @@ -1245,6 +1245,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. */ | |
51a5ef0f | 60 | Index: gdb-7.0.50.20100128/gdb/parse.c |
3a58abaf | 61 | =================================================================== |
51a5ef0f PS |
62 | --- gdb-7.0.50.20100128.orig/gdb/parse.c 2010-01-28 12:52:19.000000000 +0100 |
63 | +++ gdb-7.0.50.20100128/gdb/parse.c 2010-01-28 12:53:20.000000000 +0100 | |
64 | @@ -509,7 +509,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 | ||
51a5ef0f PS |
76 | case mst_text_gnu_ifunc: |
77 | Index: gdb-7.0.50.20100128/gdb/target.c | |
3a58abaf | 78 | =================================================================== |
51a5ef0f PS |
79 | --- gdb-7.0.50.20100128.orig/gdb/target.c 2010-01-28 12:52:29.000000000 +0100 |
80 | +++ gdb-7.0.50.20100128/gdb/target.c 2010-01-28 12:52:48.000000000 +0100 | |
81 | @@ -1000,6 +1000,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 | |
51a5ef0f | 107 | @@ -1090,7 +1109,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 | } | |
51a5ef0f | 137 | Index: gdb-7.0.50.20100128/gdb/testsuite/gdb.dwarf2/dw2-errno.c |
3a58abaf AM |
138 | =================================================================== |
139 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
51a5ef0f | 140 | +++ gdb-7.0.50.20100128/gdb/testsuite/gdb.dwarf2/dw2-errno.c 2010-01-28 12:52:48.000000000 +0100 |
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 | +} | |
51a5ef0f | 170 | Index: gdb-7.0.50.20100128/gdb/testsuite/gdb.dwarf2/dw2-errno.exp |
3a58abaf AM |
171 | =================================================================== |
172 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
51a5ef0f PS |
173 | +++ gdb-7.0.50.20100128/gdb/testsuite/gdb.dwarf2/dw2-errno.exp 2010-01-28 12:52:48.000000000 +0100 |
174 | @@ -0,0 +1,60 @@ | |
3a58abaf AM |
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 | + | |
3a58abaf AM |
190 | +set testfile dw2-errno |
191 | +set srcfile ${testfile}.c | |
192 | +set binfile ${objdir}/${subdir}/${testfile} | |
193 | + | |
194 | +proc prep {} { | |
195 | + global srcdir subdir binfile | |
196 | + gdb_exit | |
197 | + gdb_start | |
198 | + gdb_reinitialize_dir $srcdir/$subdir | |
199 | + gdb_load ${binfile} | |
200 | + | |
201 | + runto_main | |
202 | + | |
203 | + gdb_breakpoint [gdb_get_line_number "breakpoint"] | |
204 | + gdb_continue_to_breakpoint "breakpoint" | |
205 | +} | |
206 | + | |
207 | +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } { | |
208 | + untested "Couldn't compile test program" | |
209 | + return -1 | |
210 | +} | |
211 | +prep | |
212 | +gdb_test "print errno" ".* = 42" "errno with macros=N threads=N" | |
213 | + | |
214 | +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } { | |
215 | + untested "Couldn't compile test program" | |
216 | + return -1 | |
217 | +} | |
218 | +prep | |
219 | +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N" | |
220 | + | |
221 | +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } { | |
222 | + return -1 | |
223 | +} | |
224 | +prep | |
225 | +gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y" | |
226 | + | |
227 | +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } { | |
228 | + return -1 | |
229 | +} | |
230 | +prep | |
231 | +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y" | |
232 | + | |
233 | +# TODO: Test the error on resolving ERRNO with only libc loaded. | |
234 | +# Just how to find the current libc filename? |