Blame SOURCES/gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch

f9426a
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=185337
f9426a
f9426a
2008-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
f9426a
f9426a
	Port to GDB-6.8pre.
f9426a
f9426a
currently for trivial nonthreaded helloworld with no debug info up to -ggdb2 you
f9426a
will get:
f9426a
        (gdb) p errno
f9426a
        [some error]
f9426a
f9426a
* with -ggdb2 and less "errno" in fact does not exist anywhere as it was
f9426a
  compiled to "(*__errno_location ())" and the macro definition is not present.
f9426a
  Unfortunately gdb will find the TLS symbol and it will try to access it but
f9426a
  as the program has been compiled without -lpthread the TLS base register
f9426a
  (%gs on i386) is not setup and it will result in:
f9426a
        Cannot access memory at address 0x8
f9426a
f9426a
Attached suggestion patch how to deal with the most common "errno" symbol
f9426a
for the most common under-ggdb3 compiled programs.
f9426a
f9426a
Original patch hooked into target_translate_tls_address.  But its inferior
f9426a
call invalidates `struct frame *' in the callers - RH BZ 690908.
f9426a
f9426a
f9426a
2007-11-03  Jan Kratochvil  <jan.kratochvil@redhat.com>
f9426a
f9426a
	* ./gdb/dwarf2read.c (read_partial_die, dwarf2_linkage_name): Prefer
f9426a
	DW_AT_MIPS_linkage_name over DW_AT_name now only for non-C.
f9426a
f9426a
glibc-debuginfo-2.7-2.x86_64: /usr/lib/debug/lib64/libc.so.6.debug:
f9426a
  <81a2>     DW_AT_name        : (indirect string, offset: 0x280e): __errno_location
f9426a
  <81a8>     DW_AT_MIPS_linkage_name: (indirect string, offset: 0x2808): *__GI___errno_location
f9426a
f9426a
Index: gdb-7.6.50.20130731-cvs/gdb/printcmd.c
f9426a
===================================================================
f9426a
--- gdb-7.6.50.20130731-cvs.orig/gdb/printcmd.c	2013-08-02 16:21:13.665758324 +0200
f9426a
+++ gdb-7.6.50.20130731-cvs/gdb/printcmd.c	2013-08-02 16:22:24.367853322 +0200
f9426a
@@ -982,6 +982,8 @@ print_command_1 (const char *exp, int vo
f9426a
 
f9426a
   if (exp && *exp)
f9426a
     {
f9426a
+      if (strcmp (exp, "errno") == 0)
f9426a
+	exp = "*((int *(*) (void)) __errno_location) ()";
f9426a
       expr = parse_expression (exp);
f9426a
       make_cleanup (free_current_contents, &expr;;
f9426a
       val = evaluate_expression (expr);
f9426a
Index: gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.dwarf2/dw2-errno.c
f9426a
===================================================================
f9426a
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
f9426a
+++ gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.dwarf2/dw2-errno.c	2013-08-02 16:21:13.665758324 +0200
f9426a
@@ -0,0 +1,28 @@
f9426a
+/* This testcase is part of GDB, the GNU debugger.
f9426a
+
f9426a
+   Copyright 2005, 2007 Free Software Foundation, Inc.
f9426a
+
f9426a
+   This program is free software; you can redistribute it and/or modify
f9426a
+   it under the terms of the GNU General Public License as published by
f9426a
+   the Free Software Foundation; either version 3 of the License, or
f9426a
+   (at your option) any later version.
f9426a
+
f9426a
+   This program is distributed in the hope that it will be useful,
f9426a
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
f9426a
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9426a
+   GNU General Public License for more details.
f9426a
+
f9426a
+   You should have received a copy of the GNU General Public License
f9426a
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
f9426a
+
f9426a
+   Please email any bugs, comments, and/or additions to this file to:
f9426a
+   bug-gdb@prep.ai.mit.edu  */
f9426a
+
f9426a
+#include <errno.h>
f9426a
+
f9426a
+int main()
f9426a
+{
f9426a
+  errno = 42;
f9426a
+
f9426a
+  return 0;	/* breakpoint */
f9426a
+}
f9426a
Index: gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.dwarf2/dw2-errno.exp
f9426a
===================================================================
f9426a
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
f9426a
+++ gdb-7.6.50.20130731-cvs/gdb/testsuite/gdb.dwarf2/dw2-errno.exp	2013-08-02 16:21:13.665758324 +0200
f9426a
@@ -0,0 +1,60 @@
f9426a
+# Copyright 2007 Free Software Foundation, Inc.
f9426a
+
f9426a
+# This program is free software; you can redistribute it and/or modify
f9426a
+# it under the terms of the GNU General Public License as published by
f9426a
+# the Free Software Foundation; either version 3 of the License, or
f9426a
+# (at your option) any later version.
f9426a
+#
f9426a
+# This program is distributed in the hope that it will be useful,
f9426a
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
f9426a
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9426a
+# GNU General Public License for more details.
f9426a
+#
f9426a
+# You should have received a copy of the GNU General Public License
f9426a
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
f9426a
+
f9426a
+set testfile dw2-errno
f9426a
+set srcfile ${testfile}.c
f9426a
+set binfile ${objdir}/${subdir}/${testfile}
f9426a
+
f9426a
+proc prep {} {
f9426a
+    global srcdir subdir binfile
f9426a
+    gdb_exit
f9426a
+    gdb_start
f9426a
+    gdb_reinitialize_dir $srcdir/$subdir
f9426a
+    gdb_load ${binfile}
f9426a
+
f9426a
+    runto_main
f9426a
+
f9426a
+    gdb_breakpoint [gdb_get_line_number "breakpoint"]
f9426a
+    gdb_continue_to_breakpoint "breakpoint"
f9426a
+}
f9426a
+
f9426a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
f9426a
+    untested "Couldn't compile test program"
f9426a
+    return -1
f9426a
+}
f9426a
+prep
f9426a
+gdb_test "print errno" ".* = 42" "errno with macros=N threads=N"
f9426a
+
f9426a
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
f9426a
+    untested "Couldn't compile test program"
f9426a
+    return -1
f9426a
+}
f9426a
+prep
f9426a
+gdb_test "print errno" ".* = 42" "errno with macros=Y threads=N"
f9426a
+
f9426a
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g2"] != "" } {
f9426a
+    return -1
f9426a
+}
f9426a
+prep
f9426a
+gdb_test "print errno" ".* = 42" "errno with macros=N threads=Y"
f9426a
+
f9426a
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "additional_flags=-g3"] != "" } {
f9426a
+    return -1
f9426a
+}
f9426a
+prep
f9426a
+gdb_test "print errno" ".* = 42" "errno with macros=Y threads=Y"
f9426a
+
f9426a
+# TODO: Test the error on resolving ERRNO with only libc loaded.
f9426a
+# Just how to find the current libc filename?