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

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