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.
22 Original patch hooked into target_translate_tls_address. But its inferior
23 call invalidates `struct frame *' in the callers - RH BZ 690908.
26 2007-11-03 Jan Kratochvil <jan.kratochvil@redhat.com>
28 * ./gdb/dwarf2read.c (read_partial_die, dwarf2_linkage_name): Prefer
29 DW_AT_MIPS_linkage_name over DW_AT_name now only for non-C.
31 glibc-debuginfo-2.7-2.x86_64: /usr/lib/debug/lib64/libc.so.6.debug:
32 <81a2> DW_AT_name : (indirect string, offset: 0x280e): __errno_location
33 <81a8> DW_AT_MIPS_linkage_name: (indirect string, offset: 0x2808): *__GI___errno_location
35 Index: gdb-7.2/gdb/printcmd.c
36 ===================================================================
37 --- gdb-7.2.orig/gdb/printcmd.c 2011-03-29 10:55:32.000000000 +0200
38 +++ gdb-7.2/gdb/printcmd.c 2011-03-29 10:56:00.000000000 +0200
39 @@ -947,10 +947,10 @@ validate_format (struct format_data fmt,
41 print_command_1 (char *exp, int inspect, int voidprint)
43 - struct expression *expr;
44 struct cleanup *old_chain = 0;
47 + /* False GCC warning due to the TRY_CATCH. */
48 + struct value *val = NULL;
49 struct format_data fmt;
52 @@ -971,10 +971,25 @@ print_command_1 (char *exp, int inspect,
56 + struct expression *expr;
57 + volatile struct gdb_exception except;
59 expr = parse_expression (exp);
60 - old_chain = make_cleanup (free_current_contents, &expr);
61 + old_chain = make_cleanup (xfree, expr);
63 - val = evaluate_expression (expr);
64 + TRY_CATCH (except, RETURN_MASK_ERROR)
66 + val = evaluate_expression (expr);
68 + if (except.reason < 0)
70 + if (strcmp (exp, "errno") != 0)
71 + throw_exception (except);
73 + expr = parse_expression ("*((int *(*) (void)) __errno_location) ()");
74 + make_cleanup (xfree, expr);
75 + val = evaluate_expression (expr);
79 val = access_value_history (0);
80 Index: gdb-7.2/gdb/testsuite/gdb.dwarf2/dw2-errno.c
81 ===================================================================
82 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
83 +++ gdb-7.2/gdb/testsuite/gdb.dwarf2/dw2-errno.c 2011-03-29 10:55:35.000000000 +0200
85 +/* This testcase is part of GDB, the GNU debugger.
87 + Copyright 2005, 2007 Free Software Foundation, Inc.
89 + This program is free software; you can redistribute it and/or modify
90 + it under the terms of the GNU General Public License as published by
91 + the Free Software Foundation; either version 3 of the License, or
92 + (at your option) any later version.
94 + This program is distributed in the hope that it will be useful,
95 + but WITHOUT ANY WARRANTY; without even the implied warranty of
96 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 + GNU General Public License for more details.
99 + You should have received a copy of the GNU General Public License
100 + along with this program. If not, see <http://www.gnu.org/licenses/>.
102 + Please email any bugs, comments, and/or additions to this file to:
103 + bug-gdb@prep.ai.mit.edu */
111 + return 0; /* breakpoint */
113 Index: gdb-7.2/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
114 ===================================================================
115 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
116 +++ gdb-7.2/gdb/testsuite/gdb.dwarf2/dw2-errno.exp 2011-03-29 10:55:35.000000000 +0200
118 +# Copyright 2007 Free Software Foundation, Inc.
120 +# This program is free software; you can redistribute it and/or modify
121 +# it under the terms of the GNU General Public License as published by
122 +# the Free Software Foundation; either version 3 of the License, or
123 +# (at your option) any later version.
125 +# This program is distributed in the hope that it will be useful,
126 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
127 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128 +# GNU General Public License for more details.
130 +# You should have received a copy of the GNU General Public License
131 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
133 +set testfile dw2-errno
134 +set srcfile ${testfile}.c
135 +set binfile ${objdir}/${subdir}/${testfile}
138 + global srcdir subdir binfile
141 + gdb_reinitialize_dir $srcdir/$subdir
142 + gdb_load ${binfile}
146 + gdb_breakpoint [gdb_get_line_number "breakpoint"]
147 + gdb_continue_to_breakpoint "breakpoint"
150 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
151 + untested "Couldn't compile test program"
155 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
157 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
158 + untested "Couldn't compile test program"
162 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
164 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
168 +gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
170 +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
174 +gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
176 +# TODO: Test the error on resolving ERRNO with only libc loaded.
177 +# Just how to find the current libc filename?