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

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