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

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