From: Yodel Eldar <[email protected]> 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. Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Yodel Eldar <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-ID: <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alex Bennée <[email protected]> diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h index 6200416f77a..a09559128b1 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/gdbstub/syscalls.c b/gdbstub/syscalls.c index d8bb90cc1c7..15050984a04 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/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 578a08dfee8..bdc798a28cb 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.47.3
