From patchwork Fri Aug 21 21:22:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 8364 Received: (qmail 112010 invoked by alias); 21 Aug 2015 21:22:27 -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 111997 invoked by uid 89); 21 Aug 2015 21:22:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no 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; Fri, 21 Aug 2015 21:22:26 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id B74388CF76 for ; Fri, 21 Aug 2015 21:22:24 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7LLMN7J030367 for ; Fri, 21 Aug 2015 17:22:24 -0400 Subject: [PATCH v12 16/32] gdb_bfd_open_from_target: Optionally do not close fd From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 21 Aug 2015 23:22:23 +0200 Message-ID: <20150821212223.6673.37844.stgit@host1.jankratochvil.net> In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> References: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, gdb_bfd_open_from_target currently always embedded passed fd into returned BFD and closed that fd after closing that BFD. As one cannot do dup() for target fileio FDs one could not use FD after BFD using it has been closed. Jan gdb/ChangeLog 2015-08-18 Jan Kratochvil * gdb_bfd.c (gdb_bfd_iovec_fileio_close_nop): New function. (gdb_bfd_open_from_target): Add parameter do_close. Optionally pass gdb_bfd_iovec_fileio_close_nop. (gdb_bfd_open): Update caller. * gdb_bfd.h (gdb_bfd_open_from_target): Update prototype. --- 0 files changed diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 51395f9..1224695 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -345,6 +345,18 @@ gdb_bfd_iovec_fileio_close (struct bfd *abfd, void *stream) return 0; } +/* Helper for gdb_bfd_open_from_target when caller did not wish to close + ABFD's FD. */ + +static int +gdb_bfd_iovec_fileio_close_nop (struct bfd *abfd, void *stream) +{ + xfree (stream); + + /* Zero means success. */ + return 0; +} + /* Wrapper for target_fileio_fstat suitable for passing as the STAT_FUNC argument to gdb_bfd_openr_iovec. */ @@ -371,7 +383,8 @@ gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream, gdb_bfd_openr_iovec. */ struct bfd * -gdb_bfd_open_from_target (const char *name, const char *target, int fd) +gdb_bfd_open_from_target (const char *name, const char *target, int fd, + int do_close) { gdb_assert (is_target_filename (name)); gdb_assert (!target_filesystem_is_local ()); @@ -382,7 +395,8 @@ gdb_bfd_open_from_target (const char *name, const char *target, int fd) (fd == -1 ? (void *) current_inferior () : (void *) &fd), gdb_bfd_iovec_fileio_pread, - gdb_bfd_iovec_fileio_close, + (do_close ? gdb_bfd_iovec_fileio_close + : gdb_bfd_iovec_fileio_close_nop), gdb_bfd_iovec_fileio_fstat); } @@ -400,7 +414,7 @@ gdb_bfd_open (const char *name, const char *target, int fd) if (is_target_filename (name)) { if (!target_filesystem_is_local ()) - return gdb_bfd_open_from_target (name, target, fd); + return gdb_bfd_open_from_target (name, target, fd, 1 /* do_close */); name += strlen (TARGET_SYSROOT_PREFIX); } diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h index 0e38d62..dcc6755 100644 --- a/gdb/gdb_bfd.h +++ b/gdb/gdb_bfd.h @@ -54,7 +54,7 @@ int gdb_bfd_has_target_filename (struct bfd *abfd); struct bfd *gdb_bfd_open (const char *name, const char *target, int fd); struct bfd *gdb_bfd_open_from_target (const char *name, const char *target, - int fd); + int fd, int do_close); /* Increment the reference count of ABFD. It is fine for ABFD to be NULL; in this case the function does nothing. */