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
This commit is contained in:
parent
198f946ffe
commit
b872057a63
12 changed files with 142 additions and 132 deletions
|
@ -306,7 +306,7 @@ gdb_bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size,
|
|||
/* Return the system error number corresponding to ERRNUM. */
|
||||
|
||||
static int
|
||||
fileio_errno_to_host (int errnum)
|
||||
fileio_errno_to_host (fileio_error errnum)
|
||||
{
|
||||
switch (errnum)
|
||||
{
|
||||
|
@ -370,7 +370,8 @@ static void *
|
|||
gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *open_closure)
|
||||
{
|
||||
const char *filename = bfd_get_filename (abfd);
|
||||
int fd, target_errno;
|
||||
int fd;
|
||||
fileio_error target_errno;
|
||||
int *stream;
|
||||
gdb_bfd_open_closure *oclosure = (gdb_bfd_open_closure *) open_closure;
|
||||
|
||||
|
@ -400,7 +401,7 @@ gdb_bfd_iovec_fileio_pread (struct bfd *abfd, void *stream, void *buf,
|
|||
file_ptr nbytes, file_ptr offset)
|
||||
{
|
||||
int fd = *(int *) stream;
|
||||
int target_errno;
|
||||
fileio_error target_errno;
|
||||
file_ptr pos, bytes;
|
||||
|
||||
pos = 0;
|
||||
|
@ -443,7 +444,7 @@ static int
|
|||
gdb_bfd_iovec_fileio_close (struct bfd *abfd, void *stream)
|
||||
{
|
||||
int fd = *(int *) stream;
|
||||
int target_errno;
|
||||
fileio_error target_errno;
|
||||
|
||||
xfree (stream);
|
||||
|
||||
|
@ -472,7 +473,7 @@ gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream,
|
|||
struct stat *sb)
|
||||
{
|
||||
int fd = *(int *) stream;
|
||||
int target_errno;
|
||||
fileio_error target_errno;
|
||||
int result;
|
||||
|
||||
result = target_fileio_fstat (fd, sb, &target_errno);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue