Fix typo in gdb.python/py-objfile.exp
[deliverable/binutils-gdb.git] / gdb / solib.c
index 2466235678e0b064a5e1190714126968b7fb5050..eb933c044d55b99f6042ff88ec4eca0ce9d6bf30 100644 (file)
@@ -114,8 +114,9 @@ show_solib_search_path (struct ui_file *file, int from_tty,
 
 /* Return the full pathname of a binary file (the main executable
    or a shared library file), or NULL if not found.  The returned
-   pathname is malloc'ed and must be freed by the caller.  *FD is
-   set to either -1 or an open file handle for the binary file.
+   pathname is malloc'ed and must be freed by the caller.  If FD
+   is non-NULL, *FD is set to either -1 or an open file handle for
+   the binary file.
 
    Global variable GDB_SYSROOT is used as a prefix directory
    to search for binary files if they have an absolute path.
@@ -157,32 +158,27 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   const char *fskind = effective_target_file_system_kind ();
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   char *sysroot = gdb_sysroot;
-
-  if (sysroot != NULL)
+  int prefix_len, orig_prefix_len;
+
+  /* If the absolute prefix starts with "target:" but the filesystem
+     accessed by the target_fileio_* methods is the local filesystem
+     then we strip the "target:" prefix now and work with the local
+     filesystem.  This ensures that the same search algorithm is used
+     for all local files regardless of whether a "target:" prefix was
+     used.  */
+  if (is_target_filename (sysroot) && target_filesystem_is_local ())
+    sysroot += strlen (TARGET_SYSROOT_PREFIX);
+
+  /* Strip any trailing slashes from the absolute prefix.  */
+  prefix_len = orig_prefix_len = strlen (sysroot);
+
+  while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
+    prefix_len--;
+
+  if (prefix_len == 0)
+    sysroot = NULL;
+  else if (prefix_len != orig_prefix_len)
     {
-      /* If the absolute prefix starts with "target:" but the
-        filesystem accessed by the target_fileio_* methods
-        is the local filesystem then we strip the "target:"
-        prefix now and work with the local filesystem.  This
-        ensures that the same search algorithm is used for
-        all local files regardless of whether a "target:"
-        prefix was used.  */
-      if (is_target_filename (sysroot) && target_filesystem_is_local ())
-       sysroot += strlen (TARGET_SYSROOT_PREFIX);
-
-      if (*sysroot == '\0')
-       sysroot = NULL;
-    }
-
-  if (sysroot != NULL)
-    {
-      int prefix_len = strlen (sysroot);
-
-      /* Remove trailing slashes from absolute prefix.  */
-      while (prefix_len > 0
-            && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
-       prefix_len--;
-
       sysroot = savestring (sysroot, prefix_len);
       make_cleanup (xfree, sysroot);
     }
@@ -254,7 +250,8 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
   /* Handle files to be accessed via the target.  */
   if (is_target_filename (temp_pathname))
     {
-      *fd = -1;
+      if (fd != NULL)
+       *fd = -1;
       do_cleanups (old_chain);
       return temp_pathname;
     }
@@ -367,14 +364,21 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
                        OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
                        O_RDONLY | O_BINARY, &temp_pathname);
 
-  *fd = found_file;
+  if (fd == NULL)
+    {
+      if (found_file >= 0)
+       close (found_file);
+    }
+  else
+    *fd = found_file;
+
   return temp_pathname;
 }
 
 /* Return the full pathname of the main executable, or NULL if not
    found.  The returned pathname is malloc'ed and must be freed by
-   the caller.  *FD is set to either -1 or an open file handle for
-   the main executable.
+   the caller.  If FD is non-NULL, *FD is set to either -1 or an open
+   file handle for the main executable.
 
    The search algorithm used is described in solib_find_1's comment
    above.  */
@@ -405,8 +409,8 @@ exec_file_find (char *in_pathname, int *fd)
 
 /* Return the full pathname of a shared library file, or NULL if not
    found.  The returned pathname is malloc'ed and must be freed by
-   the caller.  *FD is set to either -1 or an open file handle for
-   the shared library.
+   the caller.  If FD is non-NULL, *FD is set to either -1 or an open
+   file handle for the shared library.
 
    The search algorithm used is described in solib_find_1's comment
    above.  */
@@ -1666,6 +1670,7 @@ _initialize_solib (void)
           _("Load shared object library symbols for files matching REGEXP."));
   add_info ("sharedlibrary", info_sharedlibrary_command,
            _("Status of loaded shared object libraries."));
+  add_info_alias ("dll", "sharedlibrary", 1);
   add_com ("nosharedlibrary", class_files, no_shared_libraries,
           _("Unload all shared object library symbols."));
 
This page took 0.025255 seconds and 4 git commands to generate.