ba67a79
If you provided some relative path to the shared library, such as with
ba67a79
	export LD_LIBRARY_PATH=.
ba67a79
then gdb would fail to match the shared library name during the TLS lookup.
ba67a79
ba67a79
ba67a79
The testsuite needs `gdb-6.3-bz146810-solib_absolute_prefix_is_empty.patch'.
ba67a79
The testsuite needs `gdb-6.5-tls-of-separate-debuginfo.patch'.
ba67a79
ba67a79
ba67a79
2006-09-01  Jan Kratochvil  <jan.kratochvil@redhat.com>
ba67a79
ba67a79
	* solib-svr4.c (svr4_fetch_objfile_link_map): Match even absolute
ba67a79
	requested pathnames to the internal loaded relative pathnames.
ba67a79
ba67a79
ba67a79
Index: gdb-6.5/gdb/solib-svr4.c
ba67a79
===================================================================
ba67a79
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
ba67a79
retrieving revision 1.58
ba67a79
diff -u -p -r1.58 gdb-6.5/gdb/solib-svr4.c
ba67a79
--- gdb-6.5.orig/gdb/solib-svr4.c	18 May 2006 20:38:56 -0000	1.58
ba67a79
+++ gdb-6.5/gdb/solib-svr4.c	1 Sep 2006 18:47:10 -0000
ba67a79
@@ -774,62 +774,81 @@ CORE_ADDR
ba67a79
 svr4_fetch_objfile_link_map (struct objfile *objfile)
ba67a79
 {
ba67a79
   CORE_ADDR lm;
ba67a79
+  int resolve;
ba67a79
 
ba67a79
   if ((debug_base = locate_base ()) == 0)
ba67a79
     return 0;   /* failed somehow... */
ba67a79
 
ba67a79
-  /* Position ourselves on the first link map.  */
ba67a79
-  lm = solib_svr4_r_map ();  
ba67a79
-  while (lm)
ba67a79
+  for (resolve = 0; resolve <= 1; resolve++)
ba67a79
     {
ba67a79
-      /* Get info on the layout of the r_debug and link_map structures. */
ba67a79
-      struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
ba67a79
-      int errcode;
ba67a79
-      char *buffer;
ba67a79
-      struct lm_info objfile_lm_info;
ba67a79
-      struct cleanup *old_chain;
ba67a79
-      CORE_ADDR name_address;
ba67a79
-      gdb_byte *l_name_buf = xmalloc (lmo->l_name_size);
ba67a79
-      old_chain = make_cleanup (xfree, l_name_buf);
ba67a79
-
ba67a79
-      /* Set up the buffer to contain the portion of the link_map
ba67a79
-         structure that gdb cares about.  Note that this is not the
ba67a79
-         whole link_map structure.  */
ba67a79
-      objfile_lm_info.lm = xzalloc (lmo->link_map_size);
ba67a79
-      make_cleanup (xfree, objfile_lm_info.lm);
ba67a79
-
ba67a79
-      /* Read the link map into our internal structure.  */
ba67a79
-      read_memory (lm, objfile_lm_info.lm, lmo->link_map_size);
ba67a79
-
ba67a79
-      /* Read address of name from target memory to GDB.  */
ba67a79
-      read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size);
ba67a79
-
ba67a79
-      /* Extract this object's name.  Assume that the address is
ba67a79
-         unsigned.  */
ba67a79
-      name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size);
ba67a79
-      target_read_string (name_address, &buffer,
ba67a79
-      			  SO_NAME_MAX_PATH_SIZE - 1, &errcode);
ba67a79
-      make_cleanup (xfree, buffer);
ba67a79
-      if (errcode != 0)
ba67a79
-	warning (_("Can't read pathname for load map: %s."),
ba67a79
-		 safe_strerror (errcode));
ba67a79
-      else
ba67a79
-  	{
ba67a79
-	  /* Is this the linkmap for the file we want?  */
ba67a79
-	  /* If the file is not a shared library and has no name,
ba67a79
-	     we are sure it is the main executable, so we return that.  */
ba67a79
-	  if ((buffer && strcmp (buffer, objfile->name) == 0)
ba67a79
-              || (!(objfile->flags & OBJF_SHARED) && (strcmp (buffer, "") == 0)))
ba67a79
-  	    {
ba67a79
-    	      do_cleanups (old_chain);
ba67a79
-    	      return lm;
ba67a79
-      	    }
ba67a79
-  	}
ba67a79
-      /* Not the file we wanted, continue checking.  Assume that the
ba67a79
-         address is unsigned.  */
ba67a79
-      lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset,
ba67a79
-				     lmo->l_next_size);
ba67a79
-      do_cleanups (old_chain);
ba67a79
+      /* Position ourselves on the first link map.  */
ba67a79
+      lm = solib_svr4_r_map ();  
ba67a79
+      while (lm)
ba67a79
+	{
ba67a79
+	  /* Get info on the layout of the r_debug and link_map structures. */
ba67a79
+	  struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
ba67a79
+	  int errcode;
ba67a79
+	  char *buffer;
ba67a79
+	  struct lm_info objfile_lm_info;
ba67a79
+	  struct cleanup *old_chain;
ba67a79
+	  CORE_ADDR name_address;
ba67a79
+	  gdb_byte *l_name_buf = xmalloc (lmo->l_name_size);
ba67a79
+	  old_chain = make_cleanup (xfree, l_name_buf);
ba67a79
+
ba67a79
+	  /* Set up the buffer to contain the portion of the link_map
ba67a79
+	     structure that gdb cares about.  Note that this is not the
ba67a79
+	     whole link_map structure.  */
ba67a79
+	  objfile_lm_info.lm = xzalloc (lmo->link_map_size);
ba67a79
+	  make_cleanup (xfree, objfile_lm_info.lm);
ba67a79
+
ba67a79
+	  /* Read the link map into our internal structure.  */
ba67a79
+	  read_memory (lm, objfile_lm_info.lm, lmo->link_map_size);
ba67a79
+
ba67a79
+	  /* Read address of name from target memory to GDB.  */
ba67a79
+	  read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size);
ba67a79
+
ba67a79
+	  /* Extract this object's name.  Assume that the address is
ba67a79
+	     unsigned.  */
ba67a79
+	  name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size);
ba67a79
+	  target_read_string (name_address, &buffer,
ba67a79
+			      SO_NAME_MAX_PATH_SIZE - 1, &errcode);
ba67a79
+	  make_cleanup (xfree, buffer);
ba67a79
+	  if (errcode != 0)
ba67a79
+	    warning (_("Can't read pathname for load map: %s."),
ba67a79
+		     safe_strerror (errcode));
ba67a79
+	  else
ba67a79
+	    {
ba67a79
+	      /* solib_svr4_r_map() may contain relative pathnames while
ba67a79
+	         `objfile->name' is absolute.  */
ba67a79
+	      if (resolve && buffer && buffer[0] != '/')
ba67a79
+	        {
ba67a79
+		  char *absolute;
ba67a79
+		  int fd;
ba67a79
+
ba67a79
+		  fd = solib_open (buffer, &absolute);
ba67a79
+		  if (fd != -1)
ba67a79
+		    {
ba67a79
+		      make_cleanup (xfree, absolute);
ba67a79
+		      buffer = absolute;
ba67a79
+		      close (fd);
ba67a79
+		    }
ba67a79
+		}
ba67a79
+	      /* Is this the linkmap for the file we want?  */
ba67a79
+	      /* If the file is not a shared library and has no name,
ba67a79
+		 we are sure it is the main executable, so we return that.  */
ba67a79
+	      if ((buffer && strcmp (buffer, objfile->name) == 0)
ba67a79
+		  || (!(objfile->flags & OBJF_SHARED) && (strcmp (buffer, "") == 0)))
ba67a79
+		{
ba67a79
+		  do_cleanups (old_chain);
ba67a79
+		  return lm;
ba67a79
+		}
ba67a79
+	    }
ba67a79
+	  /* Not the file we wanted, continue checking.  Assume that the
ba67a79
+	     address is unsigned.  */
ba67a79
+	  lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset,
ba67a79
+					 lmo->l_next_size);
ba67a79
+	  do_cleanups (old_chain);
ba67a79
+	}
ba67a79
     }
ba67a79
   return 0;
ba67a79
 }
ba67a79
Index: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
ba67a79
===================================================================
ba67a79
RCS file: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
ba67a79
diff -N gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
ba67a79
--- /dev/null	1 Jan 1970 00:00:00 -0000
ba67a79
+++ gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c	1 Sep 2006 18:47:14 -0000
ba67a79
@@ -0,0 +1,25 @@
ba67a79
+/* This testcase is part of GDB, the GNU debugger.
ba67a79
+
ba67a79
+   Copyright 2006 Free Software Foundation, Inc.
ba67a79
+
ba67a79
+   This program is free software; you can redistribute it and/or modify
ba67a79
+   it under the terms of the GNU General Public License as published by
ba67a79
+   the Free Software Foundation; either version 2 of the License, or
ba67a79
+   (at your option) any later version.
ba67a79
+
ba67a79
+   This program is distributed in the hope that it will be useful,
ba67a79
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ba67a79
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ba67a79
+   GNU General Public License for more details.
ba67a79
+ 
ba67a79
+   You should have received a copy of the GNU General Public License
ba67a79
+   along with this program; if not, write to the Free Software
ba67a79
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
ba67a79
+
ba67a79
+   Please email any bugs, comments, and/or additions to this file to:
ba67a79
+   bug-gdb@prep.ai.mit.edu  */
ba67a79
+
ba67a79
+int main()
ba67a79
+{
ba67a79
+  return 0;
ba67a79
+}
ba67a79
Index: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
ba67a79
===================================================================
ba67a79
RCS file: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
ba67a79
diff -N gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
ba67a79
--- /dev/null	1 Jan 1970 00:00:00 -0000
ba67a79
+++ gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c	1 Sep 2006 18:47:14 -0000
ba67a79
@@ -0,0 +1,22 @@
ba67a79
+/* This testcase is part of GDB, the GNU debugger.
ba67a79
+
ba67a79
+   Copyright 2006 Free Software Foundation, Inc.
ba67a79
+
ba67a79
+   This program is free software; you can redistribute it and/or modify
ba67a79
+   it under the terms of the GNU General Public License as published by
ba67a79
+   the Free Software Foundation; either version 2 of the License, or
ba67a79
+   (at your option) any later version.
ba67a79
+
ba67a79
+   This program is distributed in the hope that it will be useful,
ba67a79
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ba67a79
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ba67a79
+   GNU General Public License for more details.
ba67a79
+ 
ba67a79
+   You should have received a copy of the GNU General Public License
ba67a79
+   along with this program; if not, write to the Free Software
ba67a79
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
ba67a79
+
ba67a79
+   Please email any bugs, comments, and/or additions to this file to:
ba67a79
+   bug-gdb@prep.ai.mit.edu  */
ba67a79
+
ba67a79
+__thread int var = 42;
ba67a79
Index: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp
ba67a79
===================================================================
ba67a79
RCS file: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp
ba67a79
diff -N gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp
ba67a79
--- /dev/null	1 Jan 1970 00:00:00 -0000
ba67a79
+++ gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp	1 Sep 2006 18:47:14 -0000
ba67a79
@@ -0,0 +1,81 @@
ba67a79
+# Copyright 2006 Free Software Foundation, Inc.
ba67a79
+
ba67a79
+# This program is free software; you can redistribute it and/or modify
ba67a79
+# it under the terms of the GNU General Public License as published by
ba67a79
+# the Free Software Foundation; either version 2 of the License, or
ba67a79
+# (at your option) any later version.
ba67a79
+# 
ba67a79
+# This program is distributed in the hope that it will be useful,
ba67a79
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ba67a79
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ba67a79
+# GNU General Public License for more details.
ba67a79
+# 
ba67a79
+# You should have received a copy of the GNU General Public License
ba67a79
+# along with this program; if not, write to the Free Software
ba67a79
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
ba67a79
+
ba67a79
+if $tracelevel then {
ba67a79
+    strace $tracelevel
ba67a79
+}
ba67a79
+
ba67a79
+set testfile tls-sepdebug
ba67a79
+set srcmainfile   ${testfile}-main.c
ba67a79
+set srcsharedfile ${testfile}-shared.c
ba67a79
+
ba67a79
+# DO NOT use ${objdir} obsolute reference here as we test relative directories
ba67a79
+# below and the absolute pathnames must not get encoded to the binaries.
ba67a79
+
ba67a79
+set binmainfile        ${testfile}-main
ba67a79
+set binsharedfile      ${testfile}-shared.so
ba67a79
+set binshareddebugfile ${testfile}-shared.so.debug
ba67a79
+
ba67a79
+if  { [gdb_compile_shlib "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" {debug}] != "" } {
ba67a79
+    untested "Couldn't compile test library"
ba67a79
+    return -1
ba67a79
+}
ba67a79
+
ba67a79
+# eu-strip(1) works fine but it is a part of `elfutils', not `binutils'.
ba67a79
+if 0 then {
ba67a79
+    remote_exec build "eu-strip -f ${binshareddebugfile} ${binsharedfile}"
ba67a79
+} else {
ba67a79
+    remote_exec build "objcopy --only-keep-debug ${binsharedfile} ${binshareddebugfile}"
ba67a79
+    remote_exec build "objcopy --strip-debug ${binsharedfile}"
ba67a79
+    remote_exec build "objcopy --add-gnu-debuglink=${binshareddebugfile} ${binsharedfile}"
ba67a79
+}
ba67a79
+
ba67a79
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcmainfile}" "${binmainfile}" executable [list debug shlib=${binsharedfile}]] != "" } {
ba67a79
+    untested "Couldn't compile test program"
ba67a79
+    return -1
ba67a79
+}
ba67a79
+
ba67a79
+# Get things started.
ba67a79
+
ba67a79
+# Test also the proper resolving of relative library names to absolute ones.
ba67a79
+# \$PWD is easy - it is the absolute way
ba67a79
+# ${subdir} would fail on "print var"
ba67a79
+
ba67a79
+foreach ld_library_path { \$PWD ${subdir} } name { absolute relative }  {
ba67a79
+
ba67a79
+    gdb_exit
ba67a79
+    gdb_start
ba67a79
+    ###gdb_reinitialize_dir $srcdir/$subdir
ba67a79
+    
ba67a79
+    gdb_test "set env LD_LIBRARY_PATH=$ld_library_path" \
ba67a79
+             "" \
ba67a79
+             "set env LD_LIBRARY_PATH is $name"
ba67a79
+    
ba67a79
+    gdb_load ${binmainfile}
ba67a79
+    
ba67a79
+    # For C programs, "start" should stop in main().
ba67a79
+    
ba67a79
+    gdb_test "start" \
ba67a79
+             "main \\(\\) at .*${srcmainfile}.*" \
ba67a79
+             "start"
ba67a79
+    
ba67a79
+    # Check for: Cannot find shared library `/usr/lib/debug/lib/libc-2.4.90.so.debug' in dynamic linker's load module list
ba67a79
+    # as happens with TLS variables and `separate_debug_objfile_backlink'.
ba67a79
+    
ba67a79
+    gdb_test "print var" \
ba67a79
+             "\\\$1 = \[0-9\].*" \
ba67a79
+             "print TLS variable from a shared library with $name-directory separate debug info file"
ba67a79
+}