From: Gary Benson Date: Thu, 2 Apr 2015 12:38:28 +0000 (+0100) Subject: Introduce target_fileio_fstat X-Git-Tag: gdb-7.10-release~969 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b15c1f0419ae693fdcf6cca399e9a916e14c48e;p=external%2Fbinutils.git Introduce target_fileio_fstat 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a712076..22b9289 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2015-04-02 Gary Benson + + * 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. + 2015-04-01 Sasha Smundak * Makefile.in (SUBDIR_PYTHON_OBJS): Add py-unwind.o. diff --git a/gdb/inf-child.c b/gdb/inf-child.c index 494f4b8..b7161ab 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -374,6 +374,20 @@ inf_child_fileio_pread (struct target_ops *self, return ret; } +/* Implementation of to_fileio_fstat. */ +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 +514,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 131ebf1..e0c831e 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -11817,6 +11817,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 6f6029b..306c21d 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2839,6 +2839,25 @@ target_fileio_pread (int fd, gdb_byte *read_buf, int len, return ret; } +/* See target.h. */ +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 19254d6..c4440ce 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -846,6 +846,12 @@ 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 on success, 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 +1939,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 on success, 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);