gdb/
[deliverable/binutils-gdb.git] / gdb / solib.c
index 3fed9dbe96e770670d46f7ffbc6535d7064bde9a..837814b5906ab1f6e90689c1296dcbe55367d008 100644 (file)
@@ -47,6 +47,7 @@
 #include "remote.h"
 #include "solib.h"
 #include "interps.h"
+#include "filesystem.h"
 
 /* Architecture-specific operations.  */
 
@@ -67,6 +68,7 @@ static struct target_so_ops *
 solib_ops (struct gdbarch *gdbarch)
 {
   struct target_so_ops **ops = gdbarch_data (gdbarch, solib_data);
+
   return *ops;
 }
 
@@ -76,6 +78,7 @@ void
 set_solib_ops (struct gdbarch *gdbarch, struct target_so_ops *new_ops)
 {
   struct target_so_ops **ops = gdbarch_data (gdbarch, solib_data);
+
   *ops = new_ops;
 }
 \f
@@ -104,6 +107,13 @@ The search path for loading non-absolute shared library symbol files is %s.\n"),
                    value);
 }
 
+/* Same as HAVE_DOS_BASED_FILE_SYSTEM, but useable as an rvalue.  */
+#if (HAVE_DOS_BASED_FILE_SYSTEM)
+#  define DOS_BASED_FILE_SYSTEM 1
+#else
+#  define DOS_BASED_FILE_SYSTEM 0
+#endif
+
 /*
 
    GLOBAL FUNCTION
@@ -133,7 +143,7 @@ The search path for loading non-absolute shared library symbol files is %s.\n"),
    * If gdb_sysroot is NOT set, perform the following two searches:
    *   Look in inferior's $PATH.
    *   Look in inferior's $LD_LIBRARY_PATH.
-   *   
+   *
    * The last check avoids doing this search when targetting remote
    * machines since gdb_sysroot will almost always be set.
 
@@ -152,12 +162,16 @@ solib_find (char *in_pathname, int *fd)
   int gdb_sysroot_is_empty;
   const char *solib_symbols_extension
     = gdbarch_solib_symbols_extension (target_gdbarch);
+  const char *fskind = effective_target_file_system_kind ();
+  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+  char *sysroot = NULL;
 
   /* If solib_symbols_extension is set, replace the file's
      extension.  */
   if (solib_symbols_extension)
     {
       char *p = in_pathname + strlen (in_pathname);
+
       while (p > in_pathname && *p != '.')
        p--;
 
@@ -177,9 +191,7 @@ solib_find (char *in_pathname, int *fd)
 
   gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0);
 
-  if (! IS_ABSOLUTE_PATH (in_pathname) || gdb_sysroot_is_empty)
-    temp_pathname = in_pathname;
-  else
+  if (!gdb_sysroot_is_empty)
     {
       int prefix_len = strlen (gdb_sysroot);
 
@@ -188,61 +200,150 @@ solib_find (char *in_pathname, int *fd)
             && IS_DIR_SEPARATOR (gdb_sysroot[prefix_len - 1]))
        prefix_len--;
 
+      sysroot = savestring (gdb_sysroot, prefix_len);
+      make_cleanup (xfree, sysroot);
+    }
+
+  /* If we're on a non-DOS-based system, backslashes won't be
+     understood as directory separator, so, convert them to forward
+     slashes, iff we're supposed to handle DOS-based file system
+     semantics for target paths.  */
+  if (!DOS_BASED_FILE_SYSTEM && fskind == file_system_kind_dos_based)
+    {
+      char *p;
+
+      /* Avoid clobbering our input.  */
+      p = alloca (strlen (in_pathname) + 1);
+      strcpy (p, in_pathname);
+      in_pathname = p;
+
+      for (; *p; p++)
+       {
+         if (*p == '\\')
+           *p = '/';
+       }
+    }
+
+  /* Note, we're interested in IS_TARGET_ABSOLUTE_PATH, not
+     IS_ABSOLUTE_PATH.  The latter is for host paths only, while
+     IN_PATHNAME is a target path.  For example, if we're supposed to
+     be handling DOS-like semantics we want to consider a
+     'c:/foo/bar.dll' path as an absolute path, even on a Unix box.
+     With such a path, before giving up on the sysroot, we'll try:
+
+       1st attempt, c:/foo/bar.dll ==> /sysroot/c:/foo/bar.dll
+       2nd attempt, c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll
+       3rd attempt, c:/foo/bar.dll ==> /sysroot/foo/bar.dll
+  */
+
+  if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || gdb_sysroot_is_empty)
+    temp_pathname = xstrdup (in_pathname);
+  else
+    {
+      int need_dir_separator;
+
+      need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[0]);
+
       /* Cat the prefixed pathname together.  */
-      temp_pathname = alloca (prefix_len + strlen (in_pathname) + 1);
-      strncpy (temp_pathname, gdb_sysroot, prefix_len);
-      temp_pathname[prefix_len] = '\0';
-      strcat (temp_pathname, in_pathname);
+      temp_pathname = concat (sysroot,
+                             need_dir_separator ? SLASH_STRING : "",
+                             in_pathname, (char *) NULL);
     }
 
   /* Handle remote files.  */
   if (remote_filename_p (temp_pathname))
     {
       *fd = -1;
-      return xstrdup (temp_pathname);
+      return temp_pathname;
     }
 
   /* Now see if we can open it.  */
   found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+  if (found_file < 0)
+    xfree (temp_pathname);
 
-  /* We try to find the library in various ways.  After each attempt
-     (except for the one above), either found_file >= 0 and
-     temp_pathname is a malloc'd string, or found_file < 0 and
-     temp_pathname does not point to storage that needs to be
-     freed.  */
+  /* If the search in gdb_sysroot failed, and the path name has a
+     drive spec (e.g, c:/foo), try stripping ':' from the drive spec,
+     and retrying in the sysroot:
+       c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll.  */
 
-    if (found_file < 0)
-      temp_pathname = NULL;
-    else
-      temp_pathname = xstrdup (temp_pathname);
+  if (found_file < 0
+      && !gdb_sysroot_is_empty
+      && HAS_TARGET_DRIVE_SPEC (fskind, in_pathname))
+    {
+      int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
+      char *drive = savestring (in_pathname, 1);
+
+      temp_pathname = concat (sysroot,
+                             SLASH_STRING,
+                             drive,
+                             need_dir_separator ? SLASH_STRING : "",
+                             in_pathname + 2, (char *) NULL);
+      xfree (drive);
+
+      found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+      if (found_file < 0)
+       {
+         xfree (temp_pathname);
+
+         /* If the search in gdb_sysroot still failed, try fully
+            stripping the drive spec, and trying once more in the
+            sysroot before giving up.
+
+            c:/foo/bar.dll ==> /sysroot/foo/bar.dll.  */
+
+         temp_pathname = concat (sysroot,
+                                 need_dir_separator ? SLASH_STRING : "",
+                                 in_pathname + 2, (char *) NULL);
+
+         found_file = open (temp_pathname, O_RDONLY | O_BINARY, 0);
+         if (found_file < 0)
+           xfree (temp_pathname);
+       }
+    }
+
+  do_cleanups (old_chain);
+
+  /* We try to find the library in various ways.  After each attempt,
+     either found_file >= 0 and temp_pathname is a malloc'd string, or
+     found_file < 0 and temp_pathname does not point to storage that
+     needs to be freed.  */
+
+  if (found_file < 0)
+    temp_pathname = NULL;
+
+  /* If not found, search the solib_search_path (if any).  */
+  if (found_file < 0 && solib_search_path != NULL)
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+                       in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
 
   /* If the search in gdb_sysroot 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 subsequent searches for this solib.  */
-  if (found_file < 0 && IS_ABSOLUTE_PATH (in_pathname))
+  if (found_file < 0 && IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname))
     {
       /* First, get rid of any drive letters etc.  */
-      while (!IS_DIR_SEPARATOR (*in_pathname))
-        in_pathname++;
+      while (!IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
+       in_pathname++;
 
       /* Next, get rid of all leading dir separators.  */
-      while (IS_DIR_SEPARATOR (*in_pathname))
-        in_pathname++;
+      while (IS_TARGET_DIR_SEPARATOR (fskind, *in_pathname))
+       in_pathname++;
     }
-  
+
   /* If not found, search the solib_search_path (if any).  */
   if (found_file < 0 && solib_search_path != NULL)
     found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
                        in_pathname, O_RDONLY | O_BINARY, &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 differs from the opened path.  */
   if (found_file < 0 && solib_search_path != NULL)
     found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
-                        lbasename (in_pathname), O_RDONLY | O_BINARY,
-                        &temp_pathname);
+                       target_lbasename (fskind, in_pathname),
+                       O_RDONLY | O_BINARY, &temp_pathname);
 
   /* If not found, try to use target supplied solib search method */
   if (found_file < 0 && ops->find_and_open_solib)
@@ -256,7 +357,7 @@ solib_find (char *in_pathname, int *fd)
                        OPF_TRY_CWD_FIRST, in_pathname, O_RDONLY | O_BINARY,
                        &temp_pathname);
 
-  /* If not found, next search the inferior's $LD_LIBRARY_PATH 
+  /* If not found, next search the inferior's $LD_LIBRARY_PATH
      environment variable. */
   if (found_file < 0 && gdb_sysroot_is_empty)
     found_file = openp (get_in_environ (current_inferior ()->environment,
@@ -448,8 +549,6 @@ solib_map_sections (struct so_list *so)
 static void
 free_so_symbols (struct so_list *so)
 {
-  char *bfd_filename = 0;
-
   if (so->sections)
     {
       xfree (so->sections);
@@ -900,7 +999,6 @@ static void
 info_sharedlibrary_command (char *pattern, int from_tty)
 {
   struct so_list *so = NULL;   /* link map state variable */
-  int header_done = 0;
   int so_missing_debug_info = 0;
   int addr_width;
   int nr_libs;
@@ -1105,6 +1203,7 @@ clear_solib (void)
   while (so_list_head)
     {
       struct so_list *so = so_list_head;
+
       so_list_head = so->next;
       observer_notify_solib_unloaded (so);
       if (so->abfd)
@@ -1134,6 +1233,7 @@ void
 solib_create_inferior_hook (int from_tty)
 {
   struct target_so_ops *ops = solib_ops (target_gdbarch);
+
   ops->solib_create_inferior_hook (from_tty);
 }
 
@@ -1157,6 +1257,7 @@ int
 in_solib_dynsym_resolve_code (CORE_ADDR pc)
 {
   struct target_so_ops *ops = solib_ops (target_gdbarch);
+
   return ops->in_dynsym_resolve_code (pc);
 }
 
@@ -1218,7 +1319,6 @@ reload_shared_libraries_1 (int from_tty)
     {
       char *filename, *found_pathname = NULL;
       bfd *abfd;
-      int scratch_chan;
       int was_loaded = so->symbols_loaded;
       const int flags =
        SYMFILE_DEFER_BP_RESET | (from_tty ? SYMFILE_VERBOSE : 0);
@@ -1354,8 +1454,6 @@ extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
 void
 _initialize_solib (void)
 {
-  struct cmd_list_element *c;
-
   solib_data = gdbarch_data_register_pre_init (solib_init);
 
   add_com ("sharedlibrary", class_files, sharedlibrary_command,
This page took 0.027487 seconds and 4 git commands to generate.