gdbstub: Export helper to use GDB errno values
v2 cover gdbstub: Export helper to use GDB errno values
Currently, F reply packets in gdbstub/user-target.c emit the host's errno values [1], but to facilitate host<->target independence the GDB File-I/O protocol defines its own set of supported errno values that should be used in replies instead.
This series sees to that by:
Patch 2: Exporting a mapping helper function statically defined in m68k-dependent code by declaring it in include/gdbstub/syscalls.h with the GDB File-I/O errno values, and moving the definition to gdbstub/syscalls.c.
Patch 3: Passing the host errnos to the newly global mapping function before emitting the result in F reply packets. Please note that this patch resolves the final task remaining in GitLab issue #2751.
Patch 1 adds two GDB File-I/O errno values that were previously undocumented despite having support.
To Alex Bennée: Thanks for reviewing v1! I deliberately left out the Reviewed-by git trailer, because the patch underwent nontrivial changes, and I did not think I could include it in good faith. Your comment about the existing File-I/O errno values led me to the helper function in the target-dependent code.
Thanks!
Changes in v2:
- Split into multiple commits
- Use existing mapping function (host_to_gdb_errno) via exportation
Link to v1: https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://gitlab.com/qemu-project/qemu/-/issues/2751
Yodel Eldar (3):
include/gdbstub/syscalls: Add GDB_{EIO,ENOSYS} errno values
gdbstub: Export host_to_gdb_errno File-I/O helper function gdbstub/user-target: Convert host errno to GDB File-I/O errno
gdbstub/syscalls.c | 36 ++++++++++++++++++++++++++++++++++++ gdbstub/user-target.c | 13 +++++++++---- include/gdbstub/syscalls.h | 11 +++++++++++ target/m68k/m68k-semi.c | 29 ----------------------------- 4 files changed, 56 insertions(+), 33 deletions(-)
Signature · 1 line
2.51.1.dirty
PATCH v2 1/3 include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} errno values
This patch adds the EIO and ENOSYS errno values as supported by GDB's File-I/O.
Until recently, they were not documented in the relevant section of the GDB manual:
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Errno-Values.html
--- include/gdbstub/syscalls.h | 2 ++ 1 file changed, 2 insertions(+)
include/gdbstub/syscalls.h +2 -0
@@ -22,6 +22,7 @@#define GDB_EPERM 1#define GDB_ENOENT 2#define GDB_EINTR 4 +#define GDB_EIO 5#define GDB_EBADF 9#define GDB_EACCES 13#define GDB_EFAULT 14
@@ -37,6 +38,7 @@#define GDB_ENOSPC 28#define GDB_ESPIPE 29#define GDB_EROFS 30 +#define GDB_ENOSYS 88#define GDB_ENAMETOOLONG 91#define GDB_EUNKNOWN 9999
Signature · 1 line
2.51.1.dirty
Re: [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} errno values
Quoted 6 lines · Yodel Eldar via
This patch adds the EIO and ENOSYS errno values as supported by GDB's File-I/O.
Until recently, they were not documented in the relevant section of the GDB manual:
Quoted 6 lines
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Errno-Values.html
Signed-off-by Yodel Eldar<[email protected]>--- include/gdbstub/syscalls.h | 2 ++ 1 file changed, 2 insertions(+)
r~
PATCH v2 2/3 gdbstub: Export host_to_gdb_errno File-I/O helper function
In reply to Yodel Eldar viaMove 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.
--- gdbstub/syscalls.c | 36 ++++++++++++++++++++++++++++++++++++ include/gdbstub/syscalls.h | 9 +++++++++ target/m68k/m68k-semi.c | 29 ----------------------------- 3 files changed, 45 insertions(+), 29 deletions(-)
gdbstub/syscalls.c +36 -0
@@ -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 */
include/gdbstub/syscalls.h +9 -0
@@ -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
target/m68k/m68k-semi.c +0 -29
@@ -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);
Signature · 1 line
2.51.1.dirty
Re: [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function
Quoted 6 lines · Yodel Eldar via
Move
host_to_gdb_errnofromtarget/m68k/m68k-semi.ctogdbstub/syscalls.c. Declare it ininclude/gdbstub/syscalls.h.Add both newly added GDB File-I/O supported errno values, EIO and ENOSYS, to the mapping.
Quoted 6 lines
Signed-off-by Yodel Eldar<[email protected]>--- gdbstub/syscalls.c | 36 ++++++++++++++++++++++++++++++++++++ include/gdbstub/syscalls.h | 9 +++++++++ target/m68k/m68k-semi.c | 29 ----------------------------- 3 files changed, 45 insertions(+), 29 deletions(-)
r~
PATCH v2 3/3 gdbstub/user-target: Convert host errno to GDB File-I/O errno
In reply to Yodel Eldar viaUse host_to_gdb_errno to convert host-supplied errnos to their GDB File-I/O remote protocol values, and use them in F reply packets.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2751
--- gdbstub/user-target.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
gdbstub/user-target.c +9 -4
@@ -10,6 +10,7 @@#include "qemu/osdep.h" #include "exec/gdbstub.h" #include "gdbstub/commands.h" +#include "gdbstub/syscalls.h" #include "qemu.h" #include "internals.h" #ifdef CONFIG_LINUX
@@ -315,7 +316,8 @@ void gdb_handle_v_file_open(GArray *params, void *user_ctx)int fd =open (filename, flags, mode);#endif if (fd <0 ) { -g_string_printf (gdbserver_state.str_buf,"F-1,%x" , errno); +int gdb_errno =host_to_gdb_errno (errno); +g_string_printf (gdbserver_state.str_buf,"F-1,%x" , gdb_errno); }else {g_string_printf (gdbserver_state.str_buf,"F%x" , fd); }
@@ -327,7 +329,8 @@ void gdb_handle_v_file_close(GArray *params, void *user_ctx)int fd =gdb_get_cmd_param (params,0 )->val_ul;if (close (fd) ==-1 ) { -g_string_printf (gdbserver_state.str_buf,"F-1,%x" , errno); +int gdb_errno =host_to_gdb_errno (errno); +g_string_printf (gdbserver_state.str_buf,"F-1,%x" , gdb_errno);gdb_put_strbuf ();return ; }
@@ -350,7 +353,8 @@ void gdb_handle_v_file_pread(GArray *params, void *user_ctx)ssize_t n =pread (fd, buf, bufsiz, offset);if (n <0 ) { -g_string_printf (gdbserver_state.str_buf,"F-1,%x" , errno); +int gdb_errno =host_to_gdb_errno (errno); +g_string_printf (gdbserver_state.str_buf,"F-1,%x" , gdb_errno);gdb_put_strbuf ();return ; }
@@ -373,7 +377,8 @@ void gdb_handle_v_file_readlink(GArray *params, void *user_ctx)ssize_t n =readlink (filename, buf,BUFSIZ );#endif if (n <0 ) { -g_string_printf (gdbserver_state.str_buf,"F-1,%x" , errno); +int gdb_errno =host_to_gdb_errno (errno); +g_string_printf (gdbserver_state.str_buf,"F-1,%x" , gdb_errno);gdb_put_strbuf ();return ; }
Signature · 1 line
2.51.1.dirty
Quoted 38 lines · Yodel Eldar via
Currently, F reply packets in
gdbstub/user-target.cemit the host's errno values [1], but to facilitate host<->target independence the GDB File-I/O protocol defines its own set of supported errno values that should be used in replies instead.This series sees to that by:
Patch 2: Exporting a mapping helper function statically defined in m68k-dependent code by declaring it ininclude/gdbstub/syscalls.hwith the GDB File-I/O errno values, and moving the definition togdbstub/syscalls.c.
Patch 3: Passing the host errnos to the newly global mapping function before emitting the result in F reply packets. Please note that this patch resolves the final task remaining in GitLab issue #2751.Patch 1 adds two GDB File-I/O errno values that were previously undocumented despite having support.
To Alex Bennée: Thanks for reviewing v1! I deliberately left out the Reviewed-by git trailer, because the patch underwent nontrivial changes, and I did not think I could include it in good faith. Your comment about the existing File-I/O errno values led me to the helper function in the target-dependent code.
Thanks!
Changes in v2:
- Split into multiple commits
- Use existing mapping function (host_to_gdb_errno) via exportationLink to v1: https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://gitlab.com/qemu-project/qemu/-/issues/2751
Yodel Eldar (3):
include/gdbstub/syscalls: Add GDB_{EIO,ENOSYS} errno values
gdbstub: Exporthost_to_gdb_errnoFile-I/O helper function gdbstub/user-target: Convert host errno to GDB File-I/O errno
Quoted 6 lines
gdbstub/syscalls.c | 36 ++++++++++++++++++++++++++++++++++++ gdbstub/user-target.c | 13 +++++++++---- include/gdbstub/syscalls.h | 11 +++++++++++ target/m68k/m68k-semi.c | 29 ----------------------------- 4 files changed, 56 insertions(+), 33 deletions(-)
Ping, please?
Thanks,
Yodel