* [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values
@ 2025-10-17 21:11 Yodel Eldar via
  2025-10-17 21:11 ` [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} " Yodel Eldar via
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Yodel Eldar via @ 2025-10-17 21:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Yodel Eldar
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/20251015162520.15736-1-yodel.eldar@yodel.dev/
[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(-)
-- 
2.51.1.dirty
^ permalink raw reply	[flat|nested] 7+ messages in thread
* [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} errno values
  2025-10-17 21:11 [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
@ 2025-10-17 21:11 ` Yodel Eldar via
  2025-10-17 23:54   ` Richard Henderson
  2025-10-17 21:11 ` [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function Yodel Eldar via
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Yodel Eldar via @ 2025-10-17 21:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Yodel Eldar, Alex Bennée, Philippe Mathieu-Daudé
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
Signed-off-by: Yodel Eldar <yodel.eldar@yodel.dev>
---
 include/gdbstub/syscalls.h | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h
index d63228e96b..6200416f77 100644
--- a/include/gdbstub/syscalls.h
+++ b/include/gdbstub/syscalls.h
@@ -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
 
-- 
2.51.1.dirty
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function
  2025-10-17 21:11 [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
  2025-10-17 21:11 ` [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} " Yodel Eldar via
@ 2025-10-17 21:11 ` Yodel Eldar via
  2025-10-17 23:55   ` Richard Henderson
  2025-10-17 21:11 ` [PATCH v2 3/3] gdbstub/user-target: Convert host errno to GDB File-I/O errno Yodel Eldar via
  2025-10-27  8:03 ` [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
  3 siblings, 1 reply; 7+ messages in thread
From: Yodel Eldar via @ 2025-10-17 21:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yodel Eldar, Alex Bennée, Philippe Mathieu-Daudé,
	Laurent Vivier
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
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH v2 3/3] gdbstub/user-target: Convert host errno to GDB File-I/O errno
  2025-10-17 21:11 [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
  2025-10-17 21:11 ` [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} " Yodel Eldar via
  2025-10-17 21:11 ` [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function Yodel Eldar via
@ 2025-10-17 21:11 ` Yodel Eldar via
  2025-10-27  8:03 ` [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
  3 siblings, 0 replies; 7+ messages in thread
From: Yodel Eldar via @ 2025-10-17 21:11 UTC (permalink / raw)
  To: qemu-devel
  Cc: Yodel Eldar, Dominik 'Disconnect3d' Czarnota,
	Alex Bennée, Philippe Mathieu-Daudé
Use 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
Reported-by: Dominik 'Disconnect3d' Czarnota <dominik.b.czarnota@gmail.com>
Signed-off-by: Yodel Eldar <yodel.eldar@yodel.dev>
---
 gdbstub/user-target.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c
index 43231e695e..7ef0282f70 100644
--- a/gdbstub/user-target.c
+++ b/gdbstub/user-target.c
@@ -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;
     }
-- 
2.51.1.dirty
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} errno values
  2025-10-17 21:11 ` [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} " Yodel Eldar via
@ 2025-10-17 23:54   ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2025-10-17 23:54 UTC (permalink / raw)
  To: qemu-devel
On 10/17/25 14:11, Yodel Eldar via wrote:
> 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
> 
> Signed-off-by: Yodel Eldar<yodel.eldar@yodel.dev>
> ---
>   include/gdbstub/syscalls.h | 2 ++
>   1 file changed, 2 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function
  2025-10-17 21:11 ` [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function Yodel Eldar via
@ 2025-10-17 23:55   ` Richard Henderson
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Henderson @ 2025-10-17 23:55 UTC (permalink / raw)
  To: qemu-devel
On 10/17/25 14:11, Yodel Eldar via wrote:
> 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(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values
  2025-10-17 21:11 [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
                   ` (2 preceding siblings ...)
  2025-10-17 21:11 ` [PATCH v2 3/3] gdbstub/user-target: Convert host errno to GDB File-I/O errno Yodel Eldar via
@ 2025-10-27  8:03 ` Yodel Eldar via
  3 siblings, 0 replies; 7+ messages in thread
From: Yodel Eldar via @ 2025-10-27  8:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée, Philippe Mathieu-Daudé, laurent
On 17/10/2025 16:11, Yodel Eldar via wrote:
> 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/20251015162520.15736-1-yodel.eldar@yodel.dev/
> 
> [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(-)
> 
Ping, please?
Thanks,
Yodel
^ permalink raw reply	[flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-27  8:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-17 21:11 [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
2025-10-17 21:11 ` [PATCH v2 1/3] include/gdbstub/syscalls: Add GDB_{EIO, ENOSYS} " Yodel Eldar via
2025-10-17 23:54   ` Richard Henderson
2025-10-17 21:11 ` [PATCH v2 2/3] gdbstub: Export host_to_gdb_errno File-I/O helper function Yodel Eldar via
2025-10-17 23:55   ` Richard Henderson
2025-10-17 21:11 ` [PATCH v2 3/3] gdbstub/user-target: Convert host errno to GDB File-I/O errno Yodel Eldar via
2025-10-27  8:03 ` [PATCH v2 0/3] gdbstub: Export helper to use GDB errno values Yodel Eldar via
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 NNTP newsgroup(s).