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

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