[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] gdbstub: Add Xfer:siginfo:read stub
From: |
Gustavo Romero |
Subject: |
[PATCH 1/2] gdbstub: Add Xfer:siginfo:read stub |
Date: |
Sun, 3 Mar 2024 19:26:09 +0000 |
Add stub to handle Xfer:siginfo:read query that requests the machine's
siginfo data.
This is used when GDB users execute 'print $_siginfo' and when the
machine stops due to a signal, like on a SIGSEGV. The information in
siginfo allows GDB to determine further details on the signal, like the
fault address/insn when the SIGSEGV is caught. The siginfo is also used
by GDB to find out the si_code automatically and show additional info to
the user in some cases.
This is only a QEMU user mode and Linux-only feature.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
---
gdbstub/gdbstub.c | 9 +++++++++
gdbstub/internals.h | 1 +
gdbstub/user-target.c | 31 +++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+)
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 2909bc8c69..54c1f6fb3c 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -1650,7 +1650,10 @@ static void handle_query_supported(GArray *params, void
*user_ctx)
if (gdbserver_state.c_cpu->opaque) {
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 +1802,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-target.c b/gdbstub/user-target.c
index b7d4c37cd8..3a4cf96622 100644
--- a/gdbstub/user-target.c
+++ b/gdbstub/user-target.c
@@ -284,6 +284,37 @@ 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)
+{
+ TaskState *ts;
+ unsigned long offset, len;
+ target_siginfo_t tmp_siginfo;
+ 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;
+ }
+
+ ts = gdbserver_state.c_cpu->opaque;
+
+ /* Filter out si_type from si_code. See comment in siginfo_noswap(). */
+ tmp_siginfo = ts->sync_signal.info;
+ tmp_siginfo.si_code = sextract32(tmp_siginfo.si_code, 0, 16);
+
+ siginfo_offset = (uint8_t *)&tmp_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
- [PATCH 1/2] gdbstub: Add Xfer:siginfo:read stub,
Gustavo Romero <=
- [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Gustavo Romero, 2024/03/03
- Re: [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Richard Henderson, 2024/03/04
- Re: [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Gustavo Romero, 2024/03/04
- Re: [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Richard Henderson, 2024/03/04
- Re: [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Gustavo Romero, 2024/03/07
- Re: [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Richard Henderson, 2024/03/07
- Re: [PATCH 2/2] tests/tcg: Add multiarch test for Xfer:siginfo:read stub, Gustavo Romero, 2024/03/08
Re: [PATCH 1/2] gdbstub: Add Xfer:siginfo:read stub, Richard Henderson, 2024/03/04