qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gustavo Romero <gustavo.romero@linaro.org>
To: qemu-devel@nongnu.org, richard.henderson@linaro.org
Cc: alex.bennee@linaro.org, peter.maydell@linaro.org,
	laurent@vivier.eu, philmd@linaro.org, gustavo.romero@linaro.org
Subject: [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub
Date: Thu,  7 Mar 2024 18:26:22 +0000	[thread overview]
Message-ID: <20240307182623.1450717-4-gustavo.romero@linaro.org> (raw)
In-Reply-To: <20240307182623.1450717-1-gustavo.romero@linaro.org>

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-target.c | 23 +++++++++++++++++++++++
 3 files changed, 32 insertions(+)

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 a7cc69dab3..15c01c525a 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -193,6 +193,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-target.c b/gdbstub/user-target.c
index 215bf33ab3..93739852b0 100644
--- a/gdbstub/user-target.c
+++ b/gdbstub/user-target.c
@@ -285,6 +285,29 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx)
     gdb_put_packet_binary(gdbserver_state.str_buf->str,
                       gdbserver_state.str_buf->len, true);
 }
+
+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 > sizeof(target_siginfo_t)) {
+        /* Invalid offset and/or requested length. */
+        gdb_put_packet("E01");
+        return;
+    }
+
+    siginfo_offset = (uint8_t *)gdbserver_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);
+}
 #endif
 
 static const char *get_filename_param(GArray *params, int i)
-- 
2.34.1



  parent reply	other threads:[~2024-03-07 18:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 18:26 [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Gustavo Romero
2024-03-07 18:26 ` [PATCH v2 2/5] linux-user: Move tswap_siginfo out of target code Gustavo Romero
2024-03-07 19:21   ` Alex Bennée
2024-03-07 20:47     ` Richard Henderson
2024-03-07 20:44   ` Richard Henderson
2024-03-07 18:26 ` [PATCH v2 3/5] gdbstub: Save target's siginfo Gustavo Romero
2024-03-07 21:09   ` Richard Henderson
2024-03-07 22:33     ` Alex Bennée
2024-03-08 17:01       ` Gustavo Romero
2024-03-08 19:25         ` Alex Bennée
2024-03-09  0:41           ` Richard Henderson
2024-03-09 11:43             ` Alex Bennée
2024-03-08 20:24     ` Gustavo Romero
2024-03-07 18:26 ` Gustavo Romero [this message]
2024-03-07 21:13   ` [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub Richard Henderson
2024-03-08 18:30     ` Gustavo Romero
2024-03-09  0:58       ` Richard Henderson
2024-03-07 18:26 ` [PATCH v2 5/5] tests/tcg: Add multiarch test for " Gustavo Romero
2024-03-07 21:16   ` Richard Henderson
2024-03-07 19:14 ` [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Alex Bennée
2024-03-07 20:43 ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240307182623.1450717-4-gustavo.romero@linaro.org \
    --to=gustavo.romero@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).