From patchwork Fri Mar 20 16:47:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 5722 Received: (qmail 8871 invoked by alias); 20 Mar 2015 16:48:15 -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 8842 invoked by uid 89); 20 Mar 2015 16:48:14 -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; Fri, 20 Mar 2015 16:48:13 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 16260B598B for ; Fri, 20 Mar 2015 16:48:12 +0000 (UTC) Received: from blade.nx (ovpn-116-93.ams2.redhat.com [10.36.116.93]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2KGmA0d028879 for ; Fri, 20 Mar 2015 12:48:11 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id F2FE5264107 for ; Fri, 20 Mar 2015 16:48:09 +0000 (GMT) From: Gary Benson To: gdb-patches@sourceware.org Subject: [PATCH 1/9] Introduce target_fileio_fstat Date: Fri, 20 Mar 2015 16:47:59 +0000 Message-Id: <1426870087-32654-2-git-send-email-gbenson@redhat.com> In-Reply-To: <1426870087-32654-1-git-send-email-gbenson@redhat.com> References: <1426870087-32654-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes This commit introduces a new target method target_fileio_fstat which can be used to retrieve information about files opened with target_fileio_open. gdb/ChangeLog: * target.h (struct target_ops) : New field. (target_fileio_fstat): New declaration. * target.c (target_fileio_fstat): New function. * inf-child.c (inf_child_fileio_fstat): Likewise. (inf_child_target): Initialize to_fileio_fstat. * remote.c (init_remote_ops): Likewise. --- gdb/ChangeLog | 9 +++++++++ gdb/inf-child.c | 17 +++++++++++++++++ gdb/remote.c | 1 + gdb/target.c | 21 +++++++++++++++++++++ gdb/target.h | 11 +++++++++++ 5 files changed, 59 insertions(+), 0 deletions(-) diff --git a/gdb/inf-child.c b/gdb/inf-child.c index 494f4b8..a0b786c 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -374,6 +374,22 @@ inf_child_fileio_pread (struct target_ops *self, return ret; } +/* Get information about the file opened as FD and put it in SB. + Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ + +static int +inf_child_fileio_fstat (struct target_ops *self, int fd, + struct stat *sb, int *target_errno) +{ + int ret; + + ret = fstat (fd, sb); + if (ret == -1) + *target_errno = inf_child_errno_to_fileio_error (errno); + + return ret; +} + /* Close FD on the target. Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ static int @@ -500,6 +516,7 @@ inf_child_target (void) t->to_fileio_open = inf_child_fileio_open; t->to_fileio_pwrite = inf_child_fileio_pwrite; t->to_fileio_pread = inf_child_fileio_pread; + t->to_fileio_fstat = inf_child_fileio_fstat; t->to_fileio_close = inf_child_fileio_close; t->to_fileio_unlink = inf_child_fileio_unlink; t->to_fileio_readlink = inf_child_fileio_readlink; diff --git a/gdb/remote.c b/gdb/remote.c index dfa68b3..9c6d2e5 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -11844,6 +11844,7 @@ Specify the serial device it is connected to\n\ remote_ops.to_fileio_open = remote_hostio_open; remote_ops.to_fileio_pwrite = remote_hostio_pwrite; remote_ops.to_fileio_pread = remote_hostio_pread; + remote_ops.to_fileio_fstat = remote_hostio_fstat; remote_ops.to_fileio_close = remote_hostio_close; remote_ops.to_fileio_unlink = remote_hostio_unlink; remote_ops.to_fileio_readlink = remote_hostio_readlink; diff --git a/gdb/target.c b/gdb/target.c index bb901b5..44ede10 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2848,6 +2848,27 @@ target_fileio_pread (int fd, gdb_byte *read_buf, int len, return ret; } +/* Get information about the file opened as FD on the target + and put it in SB. Return 0, or -1 if an error occurs (and + set *TARGET_ERRNO). */ +int +target_fileio_fstat (int fd, struct stat *sb, int *target_errno) +{ + fileio_fh_t *fh = fileio_fd_to_fh (fd); + int ret = -1; + + if (is_closed_fileio_fh (fh->fd)) + *target_errno = EBADF; + else + ret = fh->t->to_fileio_fstat (fh->t, fh->fd, sb, target_errno); + + if (targetdebug) + fprintf_unfiltered (gdb_stdlog, + "target_fileio_fstat (%d) = %d (%d)\n", + fd, ret, ret != -1 ? 0 : *target_errno); + return ret; +} + /* Close FD on the target. Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ int diff --git a/gdb/target.h b/gdb/target.h index c95e1a4..d2bd152 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -846,6 +846,11 @@ struct target_ops int fd, gdb_byte *read_buf, int len, ULONGEST offset, int *target_errno); + /* Get information about the file opened as FD and put it in SB. + Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ + int (*to_fileio_fstat) (struct target_ops *, + int fd, struct stat *sb, int *target_errno); + /* Close FD on the target. Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ int (*to_fileio_close) (struct target_ops *, int fd, int *target_errno); @@ -1933,6 +1938,12 @@ extern int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len, extern int target_fileio_pread (int fd, gdb_byte *read_buf, int len, ULONGEST offset, int *target_errno); +/* Get information about the file opened as FD on the target + and put it in SB. Return 0, or -1 if an error occurs (and + set *TARGET_ERRNO). */ +extern int target_fileio_fstat (int fd, struct stat *sb, + int *target_errno); + /* Close FD on the target. Return 0, or -1 if an error occurs (and set *TARGET_ERRNO). */ extern int target_fileio_close (int fd, int *target_errno);