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

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