Move host_to_gdb_errno from target/m68k/m68k-semi.c to
gdbstub/syscalls.c. Declare it in include/gdbstub/syscalls.h.
Add both newly added GDB File-I/O supported errno values, EIO and
ENOSYS, to the mapping.
Signed-off-by: Yodel Eldar <yodel.eldar@yodel.dev>
---
gdbstub/syscalls.c | 36 ++++++++++++++++++++++++++++++++++++
include/gdbstub/syscalls.h | 9 +++++++++
target/m68k/m68k-semi.c | 29 -----------------------------
3 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/gdbstub/syscalls.c b/gdbstub/syscalls.c
index e855df21ab..b166f4cc77 100644
--- a/gdbstub/syscalls.c
+++ b/gdbstub/syscalls.c
@@ -145,6 +145,42 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
gdb_syscall_handling(gdbserver_syscall_state.syscall_buf);
}
+/*
+ * Map host error numbers to their GDB protocol counterparts.
+ * For the list of GDB File-I/O supported error numbers, please consult:
+ * https://sourceware.org/gdb/current/onlinedocs/gdb.html/Errno-Values.html
+ */
+int host_to_gdb_errno(int err)
+{
+#define E(X) case E##X: return GDB_E##X
+ switch (err) {
+ E(PERM);
+ E(NOENT);
+ E(INTR);
+ E(IO);
+ E(BADF);
+ E(ACCES);
+ E(FAULT);
+ E(BUSY);
+ E(EXIST);
+ E(NODEV);
+ E(NOTDIR);
+ E(ISDIR);
+ E(INVAL);
+ E(NFILE);
+ E(MFILE);
+ E(FBIG);
+ E(NOSPC);
+ E(SPIPE);
+ E(ROFS);
+ E(NOSYS);
+ E(NAMETOOLONG);
+ default:
+ return GDB_EUNKNOWN;
+ }
+#undef E
+}
+
/*
* GDB Command Handlers
*/
diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h
index 6200416f77..a09559128b 100644
--- a/include/gdbstub/syscalls.h
+++ b/include/gdbstub/syscalls.h
@@ -102,6 +102,15 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
*/
int use_gdb_syscalls(void);
+/**
+ * host_to_gdb_errno: convert host errno to GDB errno value
+ * @err: errno from host
+ *
+ * Given an error number from the host, this helper function returns
+ * its GDB File-I/O specified representation.
+ */
+int host_to_gdb_errno(int err);
+
/**
* gdb_exit: exit gdb session, reporting inferior status
* @code: exit code reported
diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c
index 6fbbd140f3..e33fd6fedd 100644
--- a/target/m68k/m68k-semi.c
+++ b/target/m68k/m68k-semi.c
@@ -46,35 +46,6 @@
#define HOSTED_ISATTY 12
#define HOSTED_SYSTEM 13
-static int host_to_gdb_errno(int err)
-{
-#define E(X) case E##X: return GDB_E##X
- switch (err) {
- E(PERM);
- E(NOENT);
- E(INTR);
- E(BADF);
- E(ACCES);
- E(FAULT);
- E(BUSY);
- E(EXIST);
- E(NODEV);
- E(NOTDIR);
- E(ISDIR);
- E(INVAL);
- E(NFILE);
- E(MFILE);
- E(FBIG);
- E(NOSPC);
- E(SPIPE);
- E(ROFS);
- E(NAMETOOLONG);
- default:
- return GDB_EUNKNOWN;
- }
-#undef E
-}
-
static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err)
{
CPUM68KState *env = cpu_env(cs);
--
2.51.1.dirty