Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: Re: [patch] TLS resolving for separate_debug_objfile
Date: Fri, 01 Sep 2006 23:18:00 -0000	[thread overview]
Message-ID: <20060901231837.GA9252@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <20060901125337.GA7408@nevyn.them.org>

[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]

On Fri, 01 Sep 2006 14:53:37 +0200, Daniel Jacobowitz wrote:
...
> Can you reproduce it on mainline
...
> ?

OK, provided full testsuite this time.

The testsuite also covers the second patch (of `svr4_fetch_objfile_link_map'):
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 also requires my older patch "gdb-solib-path.patch", still not
committed.  Posted as <20060622114016.GA21094@host0.dyn.jankratochvil.net>,
approved by Kevin Buettner <kevinb@redhat.com>:

2006-06-22  Jan Kratochvil  <lace@jankratochvil.net>

	* solib.c (solib_open): Fixed NULL vs. "" refusal to load inferior
	shared libraries.

ChangeLog for "gdb-sharedlibrary-path.patch":

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

	* dwarf2loc.c (dwarf_expr_tls_address): Fix for separate debuginfo.
	* solib-svr4.c (svr4_fetch_objfile_link_map): Match even absolute
	requested pathnames to the internal loaded relative pathnames.

Testsuite results not changed.


Best Regards,
Jan

[-- Attachment #2: gdb-solib-path.patch --]
[-- Type: text/plain, Size: 1660 bytes --]

Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.84
diff -u -p -r1.84 solib.c
--- solib.c	25 Feb 2006 04:36:39 -0000	1.84
+++ solib.c	1 Sep 2006 18:47:11 -0000
@@ -146,13 +146,17 @@ solib_open (char *in_pathname, char **fo
   int found_file = -1;
   char *temp_pathname = NULL;
   char *p = in_pathname;
+  int solib_absolute_prefix_is_empty;
+
+  solib_absolute_prefix_is_empty = (solib_absolute_prefix == NULL
+                                    || *solib_absolute_prefix == 0);
 
   while (*p && !IS_DIR_SEPARATOR (*p))
     p++;
 
   if (*p)
     {
-      if (! IS_ABSOLUTE_PATH (in_pathname) || solib_absolute_prefix == NULL)
+      if (! IS_ABSOLUTE_PATH (in_pathname) || solib_absolute_prefix_is_empty)
         temp_pathname = in_pathname;
       else
 	{
@@ -208,14 +212,14 @@ solib_open (char *in_pathname, char **fo
 					   &temp_pathname);
 
   /* If not found, next search the inferior's $PATH environment variable. */
-  if (found_file < 0 && solib_absolute_prefix == NULL)
+  if (found_file < 0 && solib_absolute_prefix_is_empty)
     found_file = openp (get_in_environ (inferior_environ, "PATH"),
 			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0,
 			&temp_pathname);
 
   /* If not found, next search the inferior's $LD_LIBRARY_PATH 
      environment variable. */
-  if (found_file < 0 && solib_absolute_prefix == NULL)
+  if (found_file < 0 && solib_absolute_prefix_is_empty)
     found_file = openp (get_in_environ (inferior_environ, "LD_LIBRARY_PATH"),
 			OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY, 0,
 			&temp_pathname);

[-- Attachment #3: gdb-sharedlibrary-path.patch --]
[-- Type: text/plain, Size: 11951 bytes --]

Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.33
diff -u -p -r1.33 dwarf2loc.c
--- dwarf2loc.c	17 Dec 2005 22:33:59 -0000	1.33
+++ dwarf2loc.c	1 Sep 2006 18:47:09 -0000
@@ -198,6 +198,12 @@ dwarf_expr_tls_address (void *baton, COR
       struct objfile *objfile = debaton->objfile;
       volatile struct gdb_exception ex;
 
+      /* Resolve: Cannot find shared library
+         `/usr/lib/debug/lib/lib....so.debug' in dynamic linker's load
+         module list  */
+      if (objfile->separate_debug_objfile_backlink != NULL)
+	objfile = objfile->separate_debug_objfile_backlink;
+
       TRY_CATCH (ex, RETURN_MASK_ALL)
 	{
 	  CORE_ADDR lm_addr;
Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.58
diff -u -p -r1.58 solib-svr4.c
--- solib-svr4.c	18 May 2006 20:38:56 -0000	1.58
+++ 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: testsuite/gdb.threads/tls-sepdebug-main.c
===================================================================
RCS file: testsuite/gdb.threads/tls-sepdebug-main.c
diff -N testsuite/gdb.threads/tls-sepdebug-main.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ 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: testsuite/gdb.threads/tls-sepdebug-shared.c
===================================================================
RCS file: testsuite/gdb.threads/tls-sepdebug-shared.c
diff -N testsuite/gdb.threads/tls-sepdebug-shared.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ 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: testsuite/gdb.threads/tls-sepdebug.exp
===================================================================
RCS file: testsuite/gdb.threads/tls-sepdebug.exp
diff -N testsuite/gdb.threads/tls-sepdebug.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ 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"
+}

      reply	other threads:[~2006-09-01 23:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-01 11:12 Jan Kratochvil
2006-09-01 12:53 ` Daniel Jacobowitz
2006-09-01 23:18   ` Jan Kratochvil [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060901231837.GA9252@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox