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

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