From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 3/3] gdbsupport: move fileio_errno_to_host to fileio.{h, cc} and rename
Date: Mon, 29 Aug 2022 12:29:26 -0400 [thread overview]
Message-ID: <20220829162926.3752040-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20220829162926.3752040-1-simon.marchi@polymtl.ca>
gdb_bfd.c and remote.c contain identical implementations of a
fileio_error -> errno function. Factor that out to
gdbsupport/fileio.{h,cc}.
Rename it fileio_error_to_host, for symmetry with host_to_fileio_error.
Change-Id: Ib9b8807683de2f809c94a5303e708acc2251a0df
---
gdb/gdb_bfd.c | 59 +++-----------------------------------------
gdb/remote.c | 53 +--------------------------------------
gdbsupport/fileio.cc | 53 +++++++++++++++++++++++++++++++++++++++
gdbsupport/fileio.h | 4 +++
4 files changed, 61 insertions(+), 108 deletions(-)
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 46e2c357e3f4..58244708eb07 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -302,59 +302,6 @@ gdb_bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size,
mem_bfd_iovec_stat);
}
-/* Return the system error number corresponding to ERRNUM. */
-
-static int
-fileio_errno_to_host (fileio_error errnum)
-{
- switch (errnum)
- {
- case FILEIO_EPERM:
- return EPERM;
- case FILEIO_ENOENT:
- return ENOENT;
- case FILEIO_EINTR:
- return EINTR;
- case FILEIO_EIO:
- return EIO;
- case FILEIO_EBADF:
- return EBADF;
- case FILEIO_EACCES:
- return EACCES;
- case FILEIO_EFAULT:
- return EFAULT;
- case FILEIO_EBUSY:
- return EBUSY;
- case FILEIO_EEXIST:
- return EEXIST;
- case FILEIO_ENODEV:
- return ENODEV;
- case FILEIO_ENOTDIR:
- return ENOTDIR;
- case FILEIO_EISDIR:
- return EISDIR;
- case FILEIO_EINVAL:
- return EINVAL;
- case FILEIO_ENFILE:
- return ENFILE;
- case FILEIO_EMFILE:
- return EMFILE;
- case FILEIO_EFBIG:
- return EFBIG;
- case FILEIO_ENOSPC:
- return ENOSPC;
- case FILEIO_ESPIPE:
- return ESPIPE;
- case FILEIO_EROFS:
- return EROFS;
- case FILEIO_ENOSYS:
- return ENOSYS;
- case FILEIO_ENAMETOOLONG:
- return ENAMETOOLONG;
- }
- return -1;
-}
-
/* bfd_openr_iovec OPEN_CLOSURE data for gdb_bfd_open. */
struct gdb_bfd_open_closure
{
@@ -382,7 +329,7 @@ gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *open_closure)
&target_errno);
if (fd == -1)
{
- errno = fileio_errno_to_host (target_errno);
+ errno = fileio_error_to_host (target_errno);
bfd_set_error (bfd_error_system_call);
return NULL;
}
@@ -416,7 +363,7 @@ gdb_bfd_iovec_fileio_pread (struct bfd *abfd, void *stream, void *buf,
break;
if (bytes == -1)
{
- errno = fileio_errno_to_host (target_errno);
+ errno = fileio_error_to_host (target_errno);
bfd_set_error (bfd_error_system_call);
return -1;
}
@@ -478,7 +425,7 @@ gdb_bfd_iovec_fileio_fstat (struct bfd *abfd, void *stream,
result = target_fileio_fstat (fd, sb, &target_errno);
if (result == -1)
{
- errno = fileio_errno_to_host (target_errno);
+ errno = fileio_error_to_host (target_errno);
bfd_set_error (bfd_error_system_call);
}
diff --git a/gdb/remote.c b/gdb/remote.c
index b57d26a70edb..2f6cb2d01eeb 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -12715,61 +12715,10 @@ remote_target::filesystem_is_local ()
return false;
}
-static int
-remote_fileio_errno_to_host (fileio_error errnum)
-{
- switch (errnum)
- {
- case FILEIO_EPERM:
- return EPERM;
- case FILEIO_ENOENT:
- return ENOENT;
- case FILEIO_EINTR:
- return EINTR;
- case FILEIO_EIO:
- return EIO;
- case FILEIO_EBADF:
- return EBADF;
- case FILEIO_EACCES:
- return EACCES;
- case FILEIO_EFAULT:
- return EFAULT;
- case FILEIO_EBUSY:
- return EBUSY;
- case FILEIO_EEXIST:
- return EEXIST;
- case FILEIO_ENODEV:
- return ENODEV;
- case FILEIO_ENOTDIR:
- return ENOTDIR;
- case FILEIO_EISDIR:
- return EISDIR;
- case FILEIO_EINVAL:
- return EINVAL;
- case FILEIO_ENFILE:
- return ENFILE;
- case FILEIO_EMFILE:
- return EMFILE;
- case FILEIO_EFBIG:
- return EFBIG;
- case FILEIO_ENOSPC:
- return ENOSPC;
- case FILEIO_ESPIPE:
- return ESPIPE;
- case FILEIO_EROFS:
- return EROFS;
- case FILEIO_ENOSYS:
- return ENOSYS;
- case FILEIO_ENAMETOOLONG:
- return ENAMETOOLONG;
- }
- return -1;
-}
-
static char *
remote_hostio_error (fileio_error errnum)
{
- int host_error = remote_fileio_errno_to_host (errnum);
+ int host_error = fileio_error_to_host (errnum);
if (host_error == -1)
error (_("Unknown remote I/O error %d"), errnum);
diff --git a/gdbsupport/fileio.cc b/gdbsupport/fileio.cc
index db7c1a7c488d..60a08f649770 100644
--- a/gdbsupport/fileio.cc
+++ b/gdbsupport/fileio.cc
@@ -77,6 +77,59 @@ host_to_fileio_error (int error)
/* See fileio.h. */
+int
+fileio_error_to_host (fileio_error errnum)
+{
+ switch (errnum)
+ {
+ case FILEIO_EPERM:
+ return EPERM;
+ case FILEIO_ENOENT:
+ return ENOENT;
+ case FILEIO_EINTR:
+ return EINTR;
+ case FILEIO_EIO:
+ return EIO;
+ case FILEIO_EBADF:
+ return EBADF;
+ case FILEIO_EACCES:
+ return EACCES;
+ case FILEIO_EFAULT:
+ return EFAULT;
+ case FILEIO_EBUSY:
+ return EBUSY;
+ case FILEIO_EEXIST:
+ return EEXIST;
+ case FILEIO_ENODEV:
+ return ENODEV;
+ case FILEIO_ENOTDIR:
+ return ENOTDIR;
+ case FILEIO_EISDIR:
+ return EISDIR;
+ case FILEIO_EINVAL:
+ return EINVAL;
+ case FILEIO_ENFILE:
+ return ENFILE;
+ case FILEIO_EMFILE:
+ return EMFILE;
+ case FILEIO_EFBIG:
+ return EFBIG;
+ case FILEIO_ENOSPC:
+ return ENOSPC;
+ case FILEIO_ESPIPE:
+ return ESPIPE;
+ case FILEIO_EROFS:
+ return EROFS;
+ case FILEIO_ENOSYS:
+ return ENOSYS;
+ case FILEIO_ENAMETOOLONG:
+ return ENAMETOOLONG;
+ }
+ return -1;
+}
+
+/* See fileio.h. */
+
int
fileio_to_host_openflags (int fileio_open_flags, int *open_flags_p)
{
diff --git a/gdbsupport/fileio.h b/gdbsupport/fileio.h
index 6a5297c64330..203e671f3e73 100644
--- a/gdbsupport/fileio.h
+++ b/gdbsupport/fileio.h
@@ -139,6 +139,10 @@ struct fio_timeval
extern fileio_error host_to_fileio_error (int error);
+/* Convert a File-I/O error number to a host-format errno value. */
+
+extern int fileio_error_to_host (fileio_error errnum);
+
/* Convert File-I/O open flags FFLAGS to host format, storing
the result in *FLAGS. Return 0 on success, -1 on error. */
--
2.37.2
prev parent reply other threads:[~2022-08-29 16:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 19:54 [PATCH 1/3] gdbsupport: move include/gdb/fileio.h contents to fileio.h Simon Marchi
2022-08-26 19:54 ` [PATCH 2/3] gdbsupport: convert FILEIO_* macros to an enum Simon Marchi
2022-08-26 19:54 ` [PATCH 3/3] gdbsupport: move fileio_errno_to_host to fileio.{h.cc} and rename Simon Marchi
2022-08-29 16:29 ` [PATCH v2 0/3] fileio error cleanups Simon Marchi
2022-08-29 16:29 ` [PATCH v2 1/3] gdbsupport: move include/gdb/fileio.h contents to fileio.h Simon Marchi
2022-09-21 18:13 ` Simon Marchi
2022-08-29 16:29 ` [PATCH v2 2/3] gdbsupport: convert FILEIO_* macros to an enum Simon Marchi
2022-08-29 16:29 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220829162926.3752040-4-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).