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

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