From patchwork Tue Apr 28 18:18:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 6481 Received: (qmail 58139 invoked by alias); 28 Apr 2015 18:18:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 58130 invoked by uid 89); 28 Apr 2015 18:18:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 28 Apr 2015 18:18:21 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 7D81B8E79C for ; Tue, 28 Apr 2015 18:18:20 +0000 (UTC) Received: from blade.nx (ovpn-116-91.ams2.redhat.com [10.36.116.91]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3SIIJR4013802; Tue, 28 Apr 2015 14:18:19 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 94B2F263D6A; Tue, 28 Apr 2015 19:18:18 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves Subject: [PATCH] Allow passing fd == NULL to exec_file_find and solib_find Date: Tue, 28 Apr 2015 19:18:18 +0100 Message-Id: <1430245098-22231-1-git-send-email-gbenson@redhat.com> In-Reply-To: <553F6F79.8000505@redhat.com> References: <553F6F79.8000505@redhat.com> X-IsSubscribed: yes Hi all, 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. Built and regtested on RHEL6.6 x86_64. Ok to commit? Cheers, Gary 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 | 10 ++++++++++ gdb/exec.c | 8 +------- gdb/infrun.c | 7 +------ gdb/solib.c | 25 +++++++++++++++++-------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 872b86c..8a4ab6f 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -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) { diff --git a/gdb/infrun.c b/gdb/infrun.c index f09e2da..a4f0b9f 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -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); diff --git a/gdb/solib.c b/gdb/solib.c index 2466235..358a0a2 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -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. */