]> git.pld-linux.org Git - packages/gdb.git/blob - gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
- obsolete file
[packages/gdb.git] / gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
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
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>",
53 +              OBJFILE_INTERNAL);
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
64  
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
84      case mst_text:
85      case mst_file_text:
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);
92 +      else
93 +       write_exp_elt_type (builtin_type (gdbarch)->nodebug_text_symbol);
94        break;
95  
96      case mst_data:
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);
103  }
104  
105 +static int
106 +resolve_errno (void *arg)
107 +{
108 +  CORE_ADDR *arg_addr = arg;
109 +  struct expression *expr;
110 +  struct cleanup *old_chain = 0;
111 +  struct value *val;
112 +
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);
118 +  value_free (val);
119 +  do_cleanups (old_chain);
120 +
121 +  return 1;
122 +}
123 +
124  /* Using the objfile specified in OBJFILE, find the address for the
125     current thread's thread-local storage with offset OFFSET.  */
126  CORE_ADDR
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.  */
130    else
131 -    error (_("Cannot find thread-local variables on this target"));
132 +    {
133 +      struct minimal_symbol *msymbol;
134 +
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)))
145 +       {
146 +         if (!catch_errors (resolve_errno, (void *) &addr, "",
147 +                            RETURN_MASK_ALL))
148 +           error (_("TLS symbol `errno' not resolved for non-TLS program."
149 +                    "  You should compile the program with `gcc -pthread'."));
150 +       }
151 +      else
152 +       error (_("Cannot find thread-local variables on this target"));
153 +    }
154  
155    return addr;
156  }
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
161 @@ -0,0 +1,28 @@
162 +/* This testcase is part of GDB, the GNU debugger.
163 +
164 +   Copyright 2005, 2007 Free Software Foundation, Inc.
165 +
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.
170 +
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.
175 +
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/>.
178 +
179 +   Please email any bugs, comments, and/or additions to this file to:
180 +   bug-gdb@prep.ai.mit.edu  */
181 +
182 +#include <errno.h>
183 +
184 +int main()
185 +{
186 +  errno = 42;
187 +
188 +  return 0;    /* breakpoint */
189 +}
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
194 @@ -0,0 +1,67 @@
195 +# Copyright 2007 Free Software Foundation, Inc.
196 +
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.
201 +#
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.
206 +#
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/>.
209 +
210 +if $tracelevel then {
211 +    strace $tracelevel
212 +}
213 +
214 +set prms_id 0
215 +set bug_id 0
216 +
217 +set testfile dw2-errno
218 +set srcfile ${testfile}.c
219 +set binfile ${objdir}/${subdir}/${testfile}
220 +
221 +proc prep {} {
222 +    global srcdir subdir binfile
223 +    gdb_exit
224 +    gdb_start
225 +    gdb_reinitialize_dir $srcdir/$subdir
226 +    gdb_load ${binfile}
227 +
228 +    runto_main
229 +
230 +    gdb_breakpoint [gdb_get_line_number "breakpoint"]
231 +    gdb_continue_to_breakpoint "breakpoint"
232 +}
233 +
234 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
235 +    untested "Couldn't compile test program"
236 +    return -1
237 +}
238 +prep
239 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
240 +
241 +if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
242 +    untested "Couldn't compile test program"
243 +    return -1
244 +}
245 +prep
246 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
247 +
248 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
249 +    return -1
250 +}
251 +prep
252 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
253 +
254 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
255 +    return -1
256 +}
257 +prep
258 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
259 +
260 +# TODO: Test the error on resolving ERRNO with only libc loaded.
261 +# Just how to find the current libc filename?
This page took 0.04855 seconds and 3 git commands to generate.