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

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