gdbstub: Export helper to use GDB errno values
v3 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.
Patch 1 adds two GDB File-I/O errno values that were previously undocumented despite having support.
Patch 2 exports 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 passes the host errnos to the newly global mapping function before emitting the result in F reply packets. This is the only patch that still needs review, although it is somewhat similar to the v1 version that Alex reviewed.
I'm resending instead of just pinging, because there were DKIM-signing issues last time, and that led to From-munging of the emails which could be problematic for tooling. I believe that problem's resolved now.
Besides the DKIM-signing issue, the bashism in the commit title of Patch 1 was getting mangled with a spurious space presumably by Mailman, so I've also changed it, despite my partiality for bashisms as that also would've caused DKIM verification failure and possible munging.
Thanks to Richard for the reviews in v2 and for having written that nice helper function exported and used in this series.
Thanks to Alex for the review of v1 that is now Patch 3. I wanted to collect your R-b, but the patch underwent nontrivial change in v2, so I left it out in case you had objections to those changes.
Changes in v3:
No functional changes
- Rebase on mainline (no conflicts)
- Collect R-b's (Thanks, Richard)
- Minor rewording of commit messages
Changes in v2:
- New patch adding two errno values
- New patch exporting helper function that maps errno values
Link to v2:
https://lore.kernel.org/qemu-devel/[email protected]/
Link to v1:
https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://gitlab.com/qemu-project/qemu/-/issues/2751
Thanks,
Yodel
Yodel Eldar (3):
include/gdbstub/syscalls: Add EIO and ENOSYS GDB File-I/O 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.52.0
PATCH v3 1/3 include/gdbstub/syscalls: Add EIO and ENOSYS GDB File-I/O errno values
This patch adds the EIO and ENOSYS errno values that were missing from the GDB Manual [1] when the other errno values were defined.
[1] 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.52.0
Re: [PATCH v3 1/3] include/gdbstub/syscalls: Add EIO and ENOSYS GDB File-I/O errno values
Quoted 10 lines · Yodel Eldar
This patch adds the EIO and ENOSYS errno values that were missing from the GDB Manual [1] when the other errno values were defined.
[1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Errno-Values.html
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Yodel Eldar <[email protected]>--- include/gdbstub/syscalls.h | 2 ++ 1 file changed, 2 insertions(+)
PATCH v3 2/3 gdbstub: Export host_to_gdb_errno File-I/O helper function
In reply to Yodel EldarMove 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.52.0
Re: [PATCH v3 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function
Quoted 6 lines · Yodel Eldar
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 7 lines
Reviewed-by Richard Henderson <[email protected]>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(-)
PATCH v3 3/3 gdbstub/user-target: Convert host errno to GDB File-I/O errno
In reply to Yodel EldarUse 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.52.0
Re: [PATCH v3 3/3] gdbstub/user-target: Convert host errno to GDB File-I/O errno
Quoted 9 lines · Yodel Eldar
Use
host_to_gdb_errnoto 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
Signed-off-by Yodel Eldar <[email protected]>--- gdbstub/user-target.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Quoted 4 lines · Yodel Eldar
Yodel Eldar (3):
include/gdbstub/syscalls: Add EIO and ENOSYS GDB File-I/O errno values
gdbstub: Exporthost_to_gdb_errnoFile-I/O helper function gdbstub/user-target: Convert host errno to GDB File-I/O errno
Series fully reviewed.
Hi, Philippe
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Yodel Eldar
Yodel Eldar (3):
include/gdbstub/syscalls: Add EIO and ENOSYS GDB File-I/O errno values
gdbstub: Exporthost_to_gdb_errnoFile-I/O helper function gdbstub/user-target: Convert host errno to GDB File-I/O errnoSeries fully reviewed.
Thanks for reviewing the series.
Yodel
Hi,
Quoted 59 lines · Yodel Eldar
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.Patch 1 adds two GDB File-I/O errno values that were previously undocumented despite having support.
Patch 2 exports a mapping helper function statically defined in m68k-dependent code by declaring it in
include/gdbstub/syscalls.hwith the GDB File-I/O errno values, and moving the definition togdbstub/syscalls.c.Patch 3 passes the host errnos to the newly global mapping function before emitting the result in F reply packets. This is the only patch that still needs review, although it is somewhat similar to the v1 version that Alex reviewed.
I'm resending instead of just pinging, because there were DKIM-signing issues last time, and that led to From-munging of the emails which could be problematic for tooling. I believe that problem's resolved now.
Besides the DKIM-signing issue, the bashism in the commit title of Patch 1 was getting mangled with a spurious space presumably by Mailman, so I've also changed it, despite my partiality for bashisms as that also would've caused DKIM verification failure and possible munging.
Thanks to Richard for the reviews in v2 and for having written that nice helper function exported and used in this series.
Thanks to Alex for the review of v1 that is now Patch 3. I wanted to collect your R-b, but the patch underwent nontrivial change in v2, so I left it out in case you had objections to those changes.
Changes in v3:
No functional changes
- Rebase on mainline (no conflicts)
- Collect R-b's (Thanks, Richard)
- Minor rewording of commit messagesChanges in v2:
- New patch adding two errno values
- New patch exporting helper function that maps errno valuesLink to v2:
https://lore.kernel.org/qemu-devel/[email protected]/
Link to v1:
https://lore.kernel.org/qemu-devel/[email protected]/[1] https://gitlab.com/qemu-project/qemu/-/issues/2751
Thanks,
YodelYodel Eldar (3):
include/gdbstub/syscalls: Add EIO and ENOSYS GDB File-I/O 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 note: series is fully reviewed.
Link:
https://lore.kernel.org/qemu-devel/[email protected]/
Thanks,
Yodel
Alex Bennée
AppliedQuoted 4 lines · Yodel Eldar
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.
Queued to gdbstub/next, thanks.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro