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

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