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

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