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

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