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

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