diff mbox series

[v3,4/5] gdbstub: Add Xfer:siginfo:read stub

Message ID 20240309030901.1726211-5-gustavo.romero@linaro.org
State New
Headers show
Series Add stub to handle Xfer:siginfo:read query | expand

Commit Message

Gustavo Romero March 9, 2024, 3:09 a.m. UTC
Add stub to handle Xfer:siginfo:read packet query that requests the
machine's siginfo data.

This is used when GDB user executes 'print $_siginfo' and when the
machine stops due to a signal, for instance, on SIGSEGV. The information
in siginfo allows GDB to determiner further details on the signal, like
the fault address/insn when the SIGSEGV is caught.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
---
 gdbstub/gdbstub.c   |  8 ++++++++
 gdbstub/internals.h |  1 +
 gdbstub/user.c      | 23 +++++++++++++++++++++++
 3 files changed, 32 insertions(+)

Comments

Richard Henderson March 11, 2024, 5:21 p.m. UTC | #1
On 3/8/24 17:09, Gustavo Romero wrote:
> Add stub to handle Xfer:siginfo:read packet query that requests the
> machine's siginfo data.
> 
> This is used when GDB user executes 'print $_siginfo' and when the
> machine stops due to a signal, for instance, on SIGSEGV. The information
> in siginfo allows GDB to determiner further details on the signal, like
> the fault address/insn when the SIGSEGV is caught.
> 
> Signed-off-by: Gustavo Romero<gustavo.romero@linaro.org>
> ---
>   gdbstub/gdbstub.c   |  8 ++++++++
>   gdbstub/internals.h |  1 +
>   gdbstub/user.c      | 23 +++++++++++++++++++++++
>   3 files changed, 32 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 2909bc8c69..ab38cea46b 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -1651,6 +1651,8 @@  static void handle_query_supported(GArray *params, void *user_ctx)
         g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+");
     }
     g_string_append(gdbserver_state.str_buf, ";QCatchSyscalls+");
+
+    g_string_append(gdbserver_state.str_buf, ";qXfer:siginfo:read+");
 #endif
     g_string_append(gdbserver_state.str_buf, ";qXfer:exec-file:read+");
 #endif
@@ -1799,6 +1801,12 @@  static const GdbCmdParseEntry gdb_gen_query_table[] = {
         .cmd_startswith = 1,
         .schema = "l,l0"
     },
+    {
+        .handler = gdb_handle_query_xfer_siginfo,
+        .cmd = "Xfer:siginfo:read::",
+        .cmd_startswith = 1,
+        .schema = "l,l0"
+     },
 #endif
     {
         .handler = gdb_handle_query_xfer_exec_file,
diff --git a/gdbstub/internals.h b/gdbstub/internals.h
index 56b7c13b75..fcfe7c2d26 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -190,6 +190,7 @@  typedef union GdbCmdVariant {
 void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */
 void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */
 void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */
+void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx); /*user */
 void gdb_handle_v_file_open(GArray *params, void *user_ctx); /* user */
 void gdb_handle_v_file_close(GArray *params, void *user_ctx); /* user */
 void gdb_handle_v_file_pread(GArray *params, void *user_ctx); /* user */
diff --git a/gdbstub/user.c b/gdbstub/user.c
index df040c6ffa..5e175b5d62 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -616,3 +616,26 @@  void gdb_handle_set_catch_syscalls(GArray *params, void *user_ctx)
 err:
     gdb_put_packet("E00");
 }
+
+void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx)
+{
+    unsigned long offset, len;
+    uint8_t *siginfo_offset;
+
+    offset = get_param(params, 0)->val_ul;
+    len = get_param(params, 1)->val_ul;
+
+    if (offset + len > gdbserver_user_state.siginfo_len) {
+        /* Invalid offset and/or requested length. */
+        gdb_put_packet("E01");
+        return;
+    }
+
+    siginfo_offset = (uint8_t *)gdbserver_user_state.siginfo + offset;
+
+    /* Reply */
+    g_string_assign(gdbserver_state.str_buf, "l");
+    gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len);
+    gdb_put_packet_binary(gdbserver_state.str_buf->str,
+                          gdbserver_state.str_buf->len, true);
+}