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/remote.c | |
parent | 198f946ffe9fbfeeb187531e57cab6c3fd9d8b3d (diff) | |
download | binutils-b872057a63c53106e4bf6033a52d53b988f30dfd.zip binutils-b872057a63c53106e4bf6033a52d53b988f30dfd.tar.gz binutils-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/remote.c')
-rw-r--r-- | gdb/remote.c | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/gdb/remote.c b/gdb/remote.c index 5bae654..b57d26a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -560,26 +560,26 @@ public: int fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *target_errno) override; + fileio_error *target_errno) override; int fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *target_errno) override; + ULONGEST offset, fileio_error *target_errno) override; int fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *target_errno) override; + ULONGEST offset, fileio_error *target_errno) override; - int fileio_fstat (int fd, struct stat *sb, int *target_errno) override; + int fileio_fstat (int fd, struct stat *sb, fileio_error *target_errno) override; - int fileio_close (int fd, int *target_errno) override; + int fileio_close (int fd, fileio_error *target_errno) override; int fileio_unlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; gdb::optional<std::string> fileio_readlink (struct inferior *inf, const char *filename, - int *target_errno) override; + fileio_error *target_errno) override; bool supports_enable_disable_tracepoint () override; @@ -701,25 +701,25 @@ public: /* Remote specific methods. */ void remote_file_delete (const char *remote_file, int from_tty); int remote_hostio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno); + ULONGEST offset, fileio_error *remote_errno); int remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *remote_errno); + ULONGEST offset, fileio_error *remote_errno); int remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno); + ULONGEST offset, fileio_error *remote_errno); int remote_hostio_send_command (int command_bytes, int which_packet, - int *remote_errno, const char **attachment, + fileio_error *remote_errno, const char **attachment, int *attachment_len); int remote_hostio_set_filesystem (struct inferior *inf, - int *remote_errno); + fileio_error *remote_errno); /* We should get rid of this and use fileio_open directly. */ int remote_hostio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *remote_errno); - int remote_hostio_close (int fd, int *remote_errno); + fileio_error *remote_errno); + int remote_hostio_close (int fd, fileio_error *remote_errno); int remote_hostio_unlink (inferior *inf, const char *filename, - int *remote_errno); + fileio_error *remote_errno); struct remote_state *get_remote_state (); @@ -12130,7 +12130,7 @@ remote_buffer_add_int (char **buffer, int *left, ULONGEST value) } /* Parse an I/O result packet from BUFFER. Set RETCODE to the return - value, *REMOTE_ERRNO to the remote error number or zero if none + value, *REMOTE_ERRNO to the remote error number or FILEIO_SUCCESS if none was included, and *ATTACHMENT to point to the start of the annex if any. The length of the packet isn't needed here; there may be NUL bytes in BUFFER, but they will be after *ATTACHMENT. @@ -12140,11 +12140,11 @@ remote_buffer_add_int (char **buffer, int *left, ULONGEST value) static int remote_hostio_parse_result (const char *buffer, int *retcode, - int *remote_errno, const char **attachment) + fileio_error *remote_errno, const char **attachment) { char *p, *p2; - *remote_errno = 0; + *remote_errno = FILEIO_SUCCESS; *attachment = NULL; if (buffer[0] != 'F') @@ -12159,7 +12159,7 @@ remote_hostio_parse_result (const char *buffer, int *retcode, if (*p == ',') { errno = 0; - *remote_errno = strtol (p + 1, &p2, 16); + *remote_errno = (fileio_error) strtol (p + 1, &p2, 16); if (errno != 0 || p + 1 == p2) return -1; p = p2; @@ -12196,7 +12196,7 @@ remote_hostio_parse_result (const char *buffer, int *retcode, int remote_target::remote_hostio_send_command (int command_bytes, int which_packet, - int *remote_errno, const char **attachment, + fileio_error *remote_errno, const char **attachment, int *attachment_len) { struct remote_state *rs = get_remote_state (); @@ -12281,7 +12281,7 @@ readahead_cache::invalidate_fd (int fd) int remote_target::remote_hostio_set_filesystem (struct inferior *inf, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); int required_pid = (inf == NULL || inf->fake_pid_p) ? 0 : inf->pid; @@ -12318,7 +12318,7 @@ remote_target::remote_hostio_set_filesystem (struct inferior *inf, int remote_target::remote_hostio_open (inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12361,7 +12361,7 @@ remote_target::remote_hostio_open (inferior *inf, const char *filename, int remote_target::fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, - int *remote_errno) + fileio_error *remote_errno) { return remote_hostio_open (inf, filename, flags, mode, warn_if_slow, remote_errno); @@ -12371,7 +12371,7 @@ remote_target::fileio_open (struct inferior *inf, const char *filename, int remote_target::remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12398,7 +12398,7 @@ remote_target::remote_hostio_pwrite (int fd, const gdb_byte *write_buf, int len, int remote_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { return remote_hostio_pwrite (fd, write_buf, len, offset, remote_errno); } @@ -12408,7 +12408,7 @@ remote_target::fileio_pwrite (int fd, const gdb_byte *write_buf, int len, int remote_target::remote_hostio_pread_vFile (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12468,7 +12468,7 @@ readahead_cache::pread (int fd, gdb_byte *read_buf, size_t len, int remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { int ret; struct remote_state *rs = get_remote_state (); @@ -12508,7 +12508,7 @@ remote_target::remote_hostio_pread (int fd, gdb_byte *read_buf, int len, int remote_target::fileio_pread (int fd, gdb_byte *read_buf, int len, - ULONGEST offset, int *remote_errno) + ULONGEST offset, fileio_error *remote_errno) { return remote_hostio_pread (fd, read_buf, len, offset, remote_errno); } @@ -12516,7 +12516,7 @@ remote_target::fileio_pread (int fd, gdb_byte *read_buf, int len, /* Implementation of to_fileio_close. */ int -remote_target::remote_hostio_close (int fd, int *remote_errno) +remote_target::remote_hostio_close (int fd, fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12533,7 +12533,7 @@ remote_target::remote_hostio_close (int fd, int *remote_errno) } int -remote_target::fileio_close (int fd, int *remote_errno) +remote_target::fileio_close (int fd, fileio_error *remote_errno) { return remote_hostio_close (fd, remote_errno); } @@ -12542,7 +12542,7 @@ remote_target::fileio_close (int fd, int *remote_errno) int remote_target::remote_hostio_unlink (inferior *inf, const char *filename, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12562,7 +12562,7 @@ remote_target::remote_hostio_unlink (inferior *inf, const char *filename, int remote_target::fileio_unlink (struct inferior *inf, const char *filename, - int *remote_errno) + fileio_error *remote_errno) { return remote_hostio_unlink (inf, filename, remote_errno); } @@ -12571,7 +12571,7 @@ remote_target::fileio_unlink (struct inferior *inf, const char *filename, gdb::optional<std::string> remote_target::fileio_readlink (struct inferior *inf, const char *filename, - int *remote_errno) + fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12608,7 +12608,7 @@ remote_target::fileio_readlink (struct inferior *inf, const char *filename, /* Implementation of to_fileio_fstat. */ int -remote_target::fileio_fstat (int fd, struct stat *st, int *remote_errno) +remote_target::fileio_fstat (int fd, struct stat *st, fileio_error *remote_errno) { struct remote_state *rs = get_remote_state (); char *p = rs->buf.data (); @@ -12680,7 +12680,8 @@ remote_target::filesystem_is_local () if (ps == PACKET_SUPPORT_UNKNOWN) { - int fd, remote_errno; + int fd; + fileio_error remote_errno; /* Try opening a file to probe support. The supplied filename is irrelevant, we only care about whether @@ -12715,7 +12716,7 @@ remote_target::filesystem_is_local () } static int -remote_fileio_errno_to_host (int errnum) +remote_fileio_errno_to_host (fileio_error errnum) { switch (errnum) { @@ -12766,7 +12767,7 @@ remote_fileio_errno_to_host (int errnum) } static char * -remote_hostio_error (int errnum) +remote_hostio_error (fileio_error errnum) { int host_error = remote_fileio_errno_to_host (errnum); @@ -12792,7 +12793,7 @@ public: { try { - int remote_errno; + fileio_error remote_errno; m_remote->remote_hostio_close (m_fd, &remote_errno); } catch (...) @@ -12843,7 +12844,8 @@ void remote_target::remote_file_put (const char *local_file, const char *remote_file, int from_tty) { - int retcode, remote_errno, bytes, io_size; + int retcode, bytes, io_size; + fileio_error remote_errno; int bytes_in_buffer; int saw_eof; ULONGEST offset; @@ -12935,7 +12937,8 @@ void remote_target::remote_file_get (const char *remote_file, const char *local_file, int from_tty) { - int remote_errno, bytes, io_size; + fileio_error remote_errno; + int bytes, io_size; ULONGEST offset; scoped_remote_fd fd @@ -12993,7 +12996,8 @@ remote_file_delete (const char *remote_file, int from_tty) void remote_target::remote_file_delete (const char *remote_file, int from_tty) { - int retcode, remote_errno; + int retcode; + fileio_error remote_errno; retcode = remote_hostio_unlink (NULL, remote_file, &remote_errno); if (retcode == -1) |