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

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