Blob Blame History Raw
If you provided some relative path to the shared library, such as with
	export LD_LIBRARY_PATH=.
then gdb would fail to match the shared library name during the TLS lookup.


The testsuite needs `gdb-6.3-bz146810-solib_absolute_prefix_is_empty.patch'.
The testsuite needs `gdb-6.5-tls-of-separate-debuginfo.patch'.


2006-09-01  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* solib-svr4.c (svr4_fetch_objfile_link_map): Match even absolute
	requested pathnames to the internal loaded relative pathnames.

2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Port to GDB-6.7.

Index: gdb-6.7/gdb/solib-svr4.c
===================================================================
--- gdb-6.7.orig/gdb/solib-svr4.c	2007-10-14 23:04:45.000000000 +0200
+++ gdb-6.7/gdb/solib-svr4.c	2007-10-16 15:43:56.000000000 +0200
@@ -1009,10 +1009,14 @@ CORE_ADDR
 svr4_fetch_objfile_link_map (struct objfile *objfile)
 {
   CORE_ADDR lm;
+  int resolve;
 
   if ((debug_base = locate_base ()) == 0)
     return 0;   /* failed somehow... */
 
+for (resolve = 0; resolve <= 1; resolve++)
+{
+
   /* Position ourselves on the first link map.  */
   lm = solib_svr4_r_map ();  
   while (lm)
@@ -1051,6 +1055,21 @@ svr4_fetch_objfile_link_map (struct objf
 		 safe_strerror (errcode));
       else
   	{
+	  /* solib_svr4_r_map() may contain relative pathnames while
+	     `objfile->name' is absolute.  */
+	  if (resolve && buffer && buffer[0] != '/')
+	    {
+	      char *absolute;
+	      int fd;
+
+	      fd = solib_open (buffer, &absolute);
+	      if (fd != -1)
+		{
+		  make_cleanup (xfree, absolute);
+		  buffer = absolute;
+		  close (fd);
+		}
+	    }
 	  /* Is this the linkmap for the file we want?  */
 	  /* If the file is not a shared library and has no name,
 	     we are sure it is the main executable, so we return that.  */
@@ -1069,6 +1088,9 @@ svr4_fetch_objfile_link_map (struct objf
 				  builtin_type_void_data_ptr);
       do_cleanups (old_chain);
     }
+
+}	/* resolve */
+
   return 0;
 }
 
Index: gdb-6.7/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-6.7/gdb/testsuite/gdb.threads/tls-sepdebug-main.c	2007-10-16 15:40:01.000000000 +0200
@@ -0,0 +1,25 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2006 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   Please email any bugs, comments, and/or additions to this file to:
+   bug-gdb@prep.ai.mit.edu  */
+
+int main()
+{
+  return 0;
+}
Index: gdb-6.7/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-6.7/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c	2007-10-16 15:40:01.000000000 +0200
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2006 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+   Please email any bugs, comments, and/or additions to this file to:
+   bug-gdb@prep.ai.mit.edu  */
+
+__thread int var = 42;
Index: gdb-6.7/gdb/testsuite/gdb.threads/tls-sepdebug.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb-6.7/gdb/testsuite/gdb.threads/tls-sepdebug.exp	2007-10-16 15:40:01.000000000 +0200
@@ -0,0 +1,81 @@
+# Copyright 2006 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+set testfile tls-sepdebug
+set srcmainfile   ${testfile}-main.c
+set srcsharedfile ${testfile}-shared.c
+
+# DO NOT use ${objdir} obsolute reference here as we test relative directories
+# below and the absolute pathnames must not get encoded to the binaries.
+
+set binmainfile        ${testfile}-main
+set binsharedfile      ${testfile}-shared.so
+set binshareddebugfile ${testfile}-shared.so.debug
+
+if  { [gdb_compile_shlib "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" {debug}] != "" } {
+    untested "Couldn't compile test library"
+    return -1
+}
+
+# eu-strip(1) works fine but it is a part of `elfutils', not `binutils'.
+if 0 then {
+    remote_exec build "eu-strip -f ${binshareddebugfile} ${binsharedfile}"
+} else {
+    remote_exec build "objcopy --only-keep-debug ${binsharedfile} ${binshareddebugfile}"
+    remote_exec build "objcopy --strip-debug ${binsharedfile}"
+    remote_exec build "objcopy --add-gnu-debuglink=${binshareddebugfile} ${binsharedfile}"
+}
+
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcmainfile}" "${binmainfile}" executable [list debug shlib=${binsharedfile}]] != "" } {
+    untested "Couldn't compile test program"
+    return -1
+}
+
+# Get things started.
+
+# Test also the proper resolving of relative library names to absolute ones.
+# \$PWD is easy - it is the absolute way
+# ${subdir} would fail on "print var"
+
+foreach ld_library_path { \$PWD ${subdir} } name { absolute relative }  {
+
+    gdb_exit
+    gdb_start
+    ###gdb_reinitialize_dir $srcdir/$subdir
+    
+    gdb_test "set env LD_LIBRARY_PATH=$ld_library_path" \
+             "" \
+             "set env LD_LIBRARY_PATH is $name"
+    
+    gdb_load ${binmainfile}
+    
+    # For C programs, "start" should stop in main().
+    
+    gdb_test "start" \
+             "main \\(\\) at .*${srcmainfile}.*" \
+             "start"
+    
+    # Check for: Cannot find shared library `/usr/lib/debug/lib/libc-2.4.90.so.debug' in dynamic linker's load module list
+    # as happens with TLS variables and `separate_debug_objfile_backlink'.
+    
+    gdb_test "print var" \
+             "\\\$1 = \[0-9\].*" \
+             "print TLS variable from a shared library with $name-directory separate debug info file"
+}