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

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