Allow passing fd == NULL to exec_file_find and solib_find
authorGary Benson <gbenson@redhat.com>
Wed, 29 Apr 2015 14:20:22 +0000 (15:20 +0100)
committerGary Benson <gbenson@redhat.com>
Wed, 29 Apr 2015 14:20:22 +0000 (15:20 +0100)
This commit allows NULL to be passed as the int *fd argument
to exec_file_find and solib_find to simplify use cases where
the caller does not require the file to be opened.

gdb/ChangeLog:

* solib.c (solib_find_1): Allow fd argument to be NULL.
(exec_file_find): Update comment.
(solib_find): Likewise.
* exec.c (exec_file_locate_attach): Use NULL as fd
argument to exec_file_find to avoid having to close
the opened file.
* infrun.c (follow_exec): Likewise.

gdb/ChangeLog
gdb/exec.c
gdb/infrun.c
gdb/solib.c

index 92d972e7b523142282f8670b9601fe03dd1e88b9..425282c945059a014d9af30468737e085188153a 100644 (file)
@@ -1,3 +1,13 @@
+2015-04-29  Gary Benson <gbenson@redhat.com>
+
+       * solib.c (solib_find_1): Allow fd argument to be NULL.
+       (exec_file_find): Update comment.
+       (solib_find): Likewise.
+       * exec.c (exec_file_locate_attach): Use NULL as fd
+       argument to exec_file_find to avoid having to close
+       the opened file.
+       * infrun.c (follow_exec): Likewise.
+
 2015-04-28  Doug Evans  <dje@google.com>
 
        PR python/18299
index 872b86c69802a0b6721f6a580736baf6fcfea557..8a4ab6f083221850ecd182b06c9480c308feb749 100644 (file)
@@ -156,13 +156,7 @@ exec_file_locate_attach (int pid, int from_tty)
      is absolute then prefix the filename with gdb_sysroot.  */
   if (gdb_sysroot != NULL && *gdb_sysroot != '\0'
       && IS_ABSOLUTE_PATH (exec_file))
-    {
-      int fd = -1;
-
-      full_exec_path = exec_file_find (exec_file, &fd);
-      if (fd >= 0)
-       close (fd);
-    }
+    full_exec_path = exec_file_find (exec_file, NULL);
 
   if (full_exec_path == NULL)
     {
index f09e2daa94560a7548f5d4bb5c8646bb168d1422..a4f0b9f02e3c786d189c5b3cad51f51df181bf7e 100644 (file)
@@ -1136,12 +1136,7 @@ follow_exec (ptid_t ptid, char *execd_pathname)
 
   if (gdb_sysroot != NULL && *gdb_sysroot != '\0')
     {
-      int fd = -1;
-      char *name;
-
-      name = exec_file_find (execd_pathname, &fd);
-      if (fd >= 0)
-       close (fd);
+      char *name = exec_file_find (execd_pathname, NULL);
 
       execd_pathname = alloca (strlen (name) + 1);
       strcpy (execd_pathname, name);
index 2466235678e0b064a5e1190714126968b7fb5050..358a0a263cb00aa86f63fe42d6fb6be091802fa0 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.
@@ -254,7 +255,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 +369,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 +414,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.  */
This page took 0.031694 seconds and 4 git commands to generate.