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.


Index: gdb-6.5/gdb/solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.58
diff -u -p -r1.58 gdb-6.5/gdb/solib-svr4.c
--- gdb-6.5.orig/gdb/solib-svr4.c	18 May 2006 20:38:56 -0000	1.58
+++ gdb-6.5/gdb/solib-svr4.c	1 Sep 2006 18:47:10 -0000
@@ -774,62 +774,81 @@ 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... */
 
-  /* Position ourselves on the first link map.  */
-  lm = solib_svr4_r_map ();  
-  while (lm)
+  for (resolve = 0; resolve <= 1; resolve++)
     {
-      /* Get info on the layout of the r_debug and link_map structures. */
-      struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
-      int errcode;
-      char *buffer;
-      struct lm_info objfile_lm_info;
-      struct cleanup *old_chain;
-      CORE_ADDR name_address;
-      gdb_byte *l_name_buf = xmalloc (lmo->l_name_size);
-      old_chain = make_cleanup (xfree, l_name_buf);
-
-      /* Set up the buffer to contain the portion of the link_map
-         structure that gdb cares about.  Note that this is not the
-         whole link_map structure.  */
-      objfile_lm_info.lm = xzalloc (lmo->link_map_size);
-      make_cleanup (xfree, objfile_lm_info.lm);
-
-      /* Read the link map into our internal structure.  */
-      read_memory (lm, objfile_lm_info.lm, lmo->link_map_size);
-
-      /* Read address of name from target memory to GDB.  */
-      read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size);
-
-      /* Extract this object's name.  Assume that the address is
-         unsigned.  */
-      name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size);
-      target_read_string (name_address, &buffer,
-      			  SO_NAME_MAX_PATH_SIZE - 1, &errcode);
-      make_cleanup (xfree, buffer);
-      if (errcode != 0)
-	warning (_("Can't read pathname for load map: %s."),
-		 safe_strerror (errcode));
-      else
-  	{
-	  /* 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.  */
-	  if ((buffer && strcmp (buffer, objfile->name) == 0)
-              || (!(objfile->flags & OBJF_SHARED) && (strcmp (buffer, "") == 0)))
-  	    {
-    	      do_cleanups (old_chain);
-    	      return lm;
-      	    }
-  	}
-      /* Not the file we wanted, continue checking.  Assume that the
-         address is unsigned.  */
-      lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset,
-				     lmo->l_next_size);
-      do_cleanups (old_chain);
+      /* Position ourselves on the first link map.  */
+      lm = solib_svr4_r_map ();  
+      while (lm)
+	{
+	  /* Get info on the layout of the r_debug and link_map structures. */
+	  struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
+	  int errcode;
+	  char *buffer;
+	  struct lm_info objfile_lm_info;
+	  struct cleanup *old_chain;
+	  CORE_ADDR name_address;
+	  gdb_byte *l_name_buf = xmalloc (lmo->l_name_size);
+	  old_chain = make_cleanup (xfree, l_name_buf);
+
+	  /* Set up the buffer to contain the portion of the link_map
+	     structure that gdb cares about.  Note that this is not the
+	     whole link_map structure.  */
+	  objfile_lm_info.lm = xzalloc (lmo->link_map_size);
+	  make_cleanup (xfree, objfile_lm_info.lm);
+
+	  /* Read the link map into our internal structure.  */
+	  read_memory (lm, objfile_lm_info.lm, lmo->link_map_size);
+
+	  /* Read address of name from target memory to GDB.  */
+	  read_memory (lm + lmo->l_name_offset, l_name_buf, lmo->l_name_size);
+
+	  /* Extract this object's name.  Assume that the address is
+	     unsigned.  */
+	  name_address = extract_unsigned_integer (l_name_buf, lmo->l_name_size);
+	  target_read_string (name_address, &buffer,
+			      SO_NAME_MAX_PATH_SIZE - 1, &errcode);
+	  make_cleanup (xfree, buffer);
+	  if (errcode != 0)
+	    warning (_("Can't read pathname for load map: %s."),
+		     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.  */
+	      if ((buffer && strcmp (buffer, objfile->name) == 0)
+		  || (!(objfile->flags & OBJF_SHARED) && (strcmp (buffer, "") == 0)))
+		{
+		  do_cleanups (old_chain);
+		  return lm;
+		}
+	    }
+	  /* Not the file we wanted, continue checking.  Assume that the
+	     address is unsigned.  */
+	  lm = extract_unsigned_integer (objfile_lm_info.lm + lmo->l_next_offset,
+					 lmo->l_next_size);
+	  do_cleanups (old_chain);
+	}
     }
   return 0;
 }
Index: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
===================================================================
RCS file: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
diff -N gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-main.c	1 Sep 2006 18:47:14 -0000
@@ -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.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
===================================================================
RCS file: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
diff -N gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c	1 Sep 2006 18:47:14 -0000
@@ -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.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp
===================================================================
RCS file: gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp
diff -N gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb-6.5/gdb/testsuite/gdb.threads/tls-sepdebug.exp	1 Sep 2006 18:47:14 -0000
@@ -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"
+}