This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH, RFA]: Fix search for shared libraries


I've been looking into the following bug-report:

   http://sources.redhat.com/ml/bug-gdb/2000-12/msg00084.html

In the test-case a relative pathname (./libengine.so) is passed to
dlopen().  However solib.c:solib_open() doesn't find it, the solib
isn't mapped properly, and the symbols from the solib (which are read)
aren't relocated.  Therefore setting a breakpoint at a function in the
solib doesn't work.

The attached patch makes solib_open() look for the solib literally if
its name contains a (back)slash, i.e. if it is a absolute or relative
path.  This is wat the GNU dynamic linker does.  Note that if the path
is relative, we still don't look in SOLIB_ABSOLUTE_PREFIX.

No regressions on i586-pc-linux-gnu.  OK to check this in?

Mark


2000-12-22  Mark Kettenis  <kettenis@gnu.org>

	* solib.c (solib_open): If path is relative, look for it
	literally.  This matches the behaviour of the GNU dynamic linker
	more closely.


Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.30
diff -u -p -r1.30 solib.c
--- solib.c	2000/12/15 01:01:49	1.30
+++ solib.c	2000/12/22 23:31:29
@@ -85,13 +85,13 @@ static char *solib_search_path = NULL;
 
    Search order:
    * If path is absolute, look in SOLIB_ABSOLUTE_PREFIX.
-   * If path is absolute, look for it literally (unmodified).
+   * If path is absolute or relative, look for it literally (unmodified).
    * Look in SOLIB_SEARCH_PATH.
    * Look in inferior's $PATH.
    * Look in inferior's $LD_LIBRARY_PATH.
 
    RETURNS
-   
+
    file handle for opened solib, or -1 for failure.  */
 
 int
@@ -100,16 +100,17 @@ solib_open (char *in_pathname, char **fo
   int found_file = -1;
   char *temp_pathname = NULL;
 
-  if (ROOTED_P (in_pathname))
+  if (strchr (in_pathname, SLASH_CHAR))
     {
-      if (solib_absolute_prefix == NULL)
+      if (! ROOTED_P (in_pathname) || solib_absolute_prefix == NULL)
         temp_pathname = in_pathname;
       else
 	{
-	  int  prefix_len = strlen (solib_absolute_prefix);
+	  int prefix_len = strlen (solib_absolute_prefix);
 
 	  /* Remove trailing slashes from absolute prefix.  */
-	  while (prefix_len > 0 && SLASH_P (solib_absolute_prefix[prefix_len - 1]))
+	  while (prefix_len > 0
+		 && SLASH_P (solib_absolute_prefix[prefix_len - 1]))
 	    prefix_len--;
 
 	  /* Cat the prefixed pathname together.  */
@@ -117,8 +118,8 @@ solib_open (char *in_pathname, char **fo
 	  strncpy (temp_pathname, solib_absolute_prefix, prefix_len);
 	  temp_pathname[prefix_len] = '\0';
 	  strcat (temp_pathname, in_pathname);
-
 	}
+
       /* Now see if we can open it.  */
       found_file = open (temp_pathname, O_RDONLY, 0);
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]