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]
Other format: [Raw text]

[RFC]: Solib search (Was: Re: Cross solib support; continued)


Daniel Jacobowitz wrote:
> 
> Other than that, we should fall back to solib-search-path and the
> basename if solib-absolute-path fails for us, IMO.  Would that work for
> you?  Set the absolute-path to /dev/null or so and then add the
> fallback code.

A quick recap: I'm doing solib debugging in a cross-environment, but the path to the
target's solibs on my host doesn't correspond to the path on the target.  More
specifically, the path where I want to get the solibs from on my host doesn't end in
/lib.

This is a first shot at it.  The latter part of the patch implements what Daniel
suggested, but the first part is more controversial.  The problem is when in_pathname
contains an absolute path (say /lib/libc.so.6), but it's not found in the path
specified by solib_absolute_prefix.  When we try and search for the solib in
solib_search_path, openp will find that the file name is an absolute path and open it
(ignoring the supplied solib_search_path).  As a result, it will pick up
/lib/libc.so.6 on my host.

My thought was to make the path relative if the search for the absolute path failed,
by simply getting rid of the leading '/'.  (It won't work with DOS based file
systems, as the dir separator could be '\\', but that would be easy to add.) 
Needless to say, this works for me, but I'm not sure it's The Right Thing to do. 
(Another approach would be to change openp, but I'm sure there's a good reason for
its current behaviour.)


2001-11-27  Orjan Friberg  <orjanf@axis.com>

	* solib.c (solib_open): Make path relative if search for absolute path
	failed.  If search for relative path in solib_search_path failed, fall
	back to search for basename only.


Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.45
diff -u -r1.45 solib.c
--- solib.c     2001/11/01 16:17:08     1.45
+++ solib.c     2001/11/27 14:31:15
@@ -131,10 +131,25 @@
       found_file = open (temp_pathname, O_RDONLY, 0);
     }
 
+  /* If the search in solib_absolute_prefix failed, and the path name is
+     absolute at this point, make it relative.  (openp will try and open the
+     file according to its absolute path otherwise, which is not what we want.)
+     Affects all subsequent searches for this solib.  */
+  if (found_file < 0 && IS_DIR_SEPARATOR (in_pathname[0]))
+    in_pathname++;
+
   /* If not found, next search the solib_search_path (if any).  */
   if (found_file < 0 && solib_search_path != NULL)
     found_file = openp (solib_search_path,
                        1, in_pathname, O_RDONLY, 0, &temp_pathname);
+  
+  /* If not found, next search the solib_search_path (if any) for the
+     basename only (ignoring the path).  This is to allow reading solibs
+     from a path that doesn't end in, say, /lib.  */
+  if (found_file < 0 && solib_search_path != NULL)
+    found_file = openp (solib_search_path, 
+                        1, lbasename (in_pathname), O_RDONLY, 0,
+                        &temp_pathname);
 
   /* If not found, next search the inferior's $PATH environment variable. */
   if (found_file < 0 && solib_search_path != NULL)

-- 
Orjan Friberg
Axis Communications AB


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