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

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