diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2022-08-26 15:38:26 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2022-09-21 14:11:03 -0400 |
commit | b872057a63c53106e4bf6033a52d53b988f30dfd (patch) | |
tree | 0178e5e9ae12af553f15c2e13cac0eb61e1cdafc /gdb/target.c | |
parent | 198f946ffe9fbfeeb187531e57cab6c3fd9d8b3d (diff) | |
download | gdb-b872057a63c53106e4bf6033a52d53b988f30dfd.zip gdb-b872057a63c53106e4bf6033a52d53b988f30dfd.tar.gz gdb-b872057a63c53106e4bf6033a52d53b988f30dfd.tar.bz2 |
gdbsupport: convert FILEIO_* macros to an enum
Converting from free-form macros to an enum gives a bit of type-safety.
This caught places where we would assign host error numbers to what
should contain a target fileio error number, for instance in
target_fileio_pread.
I added the FILEIO_SUCCESS enumerator, because
remote.c:remote_hostio_parse_result initializes the remote_errno output
variable to 0. It seems better to have an explicit enumerator than to
assign a value for which there is no enumerator. I considered
initializing this variable to FILEIO_EUNKNOWN instead, such that if the
remote side replies with an error and omits the errno value, we'll get
an errno that represents an error instead of 0 (which reprensents no
error). But it's not clear what the consequences of that change would
be, so I prefer to err on the side of caution and just keep the existing
behavior (there is no intended change in behavior with this patch).
Note that remote_hostio_parse_resul still reads blindly what the remote
side sends as a target errno into this variable, so we can still end up
with a nonsensical value here. It's not good, but out of the scope of
this patch.
Convert host_to_fileio_error and fileio_errno_to_host to return / accept
a fileio_error instead of an int, and cascade the change in the whole
chain that uses that.
Change-Id: I454b0e3fcf0732447bc872252fa8e57d138b0e03
Diffstat (limited to 'gdb/target.c')
-rw-r--r-- | gdb/target.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/gdb/target.c b/gdb/target.c index 9d698af..2856098 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -3206,7 +3206,7 @@ fileio_fd_to_fh (int fd) int target_ops::fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) + fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; @@ -3214,7 +3214,7 @@ target_ops::fileio_open (struct inferior *inf, const char *filename, int target_ops::fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; @@ -3222,21 +3222,21 @@ target_ops::fileio_pwrite (int fd, const gdb_byte *write_buf, int len, int target_ops::fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; } int -target_ops::fileio_fstat (int fd, struct stat *sb, int *target_errno) +target_ops::fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; } int -target_ops::fileio_close (int fd, int *target_errno) +target_ops::fileio_close (int fd, fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; @@ -3244,7 +3244,7 @@ target_ops::fileio_close (int fd, int *target_errno) int target_ops::fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return -1; @@ -3252,7 +3252,7 @@ target_ops::fileio_unlink (struct inferior *inf, const char *filename, gdb::optional<std::string> target_ops::fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { *target_errno = FILEIO_ENOSYS; return {}; @@ -3262,7 +3262,7 @@ target_ops::fileio_readlink (struct inferior *inf, const char *filename, int target_fileio_open (struct inferior *inf, const char *filename, - int flags, int mode, bool warn_if_slow, int *target_errno) + int flags, int mode, bool warn_if_slow, fileio_error *target_errno) { for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ()) { @@ -3296,15 +3296,15 @@ target_fileio_open (struct inferior *inf, const char *filename, int target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { fileio_fh_t *fh = fileio_fd_to_fh (fd); int ret = -1; if (fh->is_closed ()) - *target_errno = EBADF; + *target_errno = FILEIO_EBADF; else if (fh->target == NULL) - *target_errno = EIO; + *target_errno = FILEIO_EIO; else ret = fh->target->fileio_pwrite (fh->target_fd, write_buf, len, offset, target_errno); @@ -3322,15 +3322,15 @@ target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len, int target_fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) + ULONGEST offset, fileio_error *target_errno) { fileio_fh_t *fh = fileio_fd_to_fh (fd); int ret = -1; if (fh->is_closed ()) - *target_errno = EBADF; + *target_errno = FILEIO_EBADF; else if (fh->target == NULL) - *target_errno = EIO; + *target_errno = FILEIO_EIO; else ret = fh->target->fileio_pread (fh->target_fd, read_buf, len, offset, target_errno); @@ -3347,15 +3347,15 @@ target_fileio_pread (int fd, gdb_byte *read_buf, int len, /* See target.h. */ int -target_fileio_fstat (int fd, struct stat *sb, int *target_errno) +target_fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) { fileio_fh_t *fh = fileio_fd_to_fh (fd); int ret = -1; if (fh->is_closed ()) - *target_errno = EBADF; + *target_errno = FILEIO_EBADF; else if (fh->target == NULL) - *target_errno = EIO; + *target_errno = FILEIO_EIO; else ret = fh->target->fileio_fstat (fh->target_fd, sb, target_errno); @@ -3369,13 +3369,13 @@ target_fileio_fstat (int fd, struct stat *sb, int *target_errno) /* See target.h. */ int -target_fileio_close (int fd, int *target_errno) +target_fileio_close (int fd, fileio_error *target_errno) { fileio_fh_t *fh = fileio_fd_to_fh (fd); int ret = -1; if (fh->is_closed ()) - *target_errno = EBADF; + *target_errno = FILEIO_EBADF; else { if (fh->target != NULL) @@ -3397,7 +3397,7 @@ target_fileio_close (int fd, int *target_errno) int target_fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ()) { @@ -3423,7 +3423,7 @@ target_fileio_unlink (struct inferior *inf, const char *filename, gdb::optional<std::string> target_fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) + fileio_error *target_errno) { for (target_ops *t = default_fileio_target (); t != NULL; t = t->beneath ()) { @@ -3461,7 +3461,7 @@ public: { if (m_fd >= 0) { - int target_errno; + fileio_error target_errno; target_fileio_close (m_fd, &target_errno); } @@ -3493,7 +3493,7 @@ target_fileio_read_alloc_1 (struct inferior *inf, const char *filename, size_t buf_alloc, buf_pos; gdb_byte *buf; LONGEST n; - int target_errno; + fileio_error target_errno; scoped_target_fd fd (target_fileio_open (inf, filename, FILEIO_O_RDONLY, 0700, false, &target_errno)); |