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 3/5] gdbstub: Save target's siginfo
Date: Thu, 7 Mar 2024 18:26:21 +0000 [thread overview]
Message-ID: <20240307182623.1450717-3-gustavo.romero@linaro.org> (raw)
In-Reply-To: <20240307182623.1450717-1-gustavo.romero@linaro.org>
Save target's siginfo into gdbserver_state so it can be used later, for
example, in any stub that requires the target's si_signo and si_code.
This change affects only linux-user mode.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
---
gdbstub/internals.h | 3 +++
gdbstub/user-target.c | 3 ++-
gdbstub/user.c | 14 ++++++++++----
include/gdbstub/user.h | 6 +++++-
linux-user/main.c | 2 +-
linux-user/signal.c | 5 ++++-
6 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/gdbstub/internals.h b/gdbstub/internals.h
index 56b7c13b75..a7cc69dab3 100644
--- a/gdbstub/internals.h
+++ b/gdbstub/internals.h
@@ -58,6 +58,9 @@ typedef struct GDBState {
int line_csum; /* checksum at the end of the packet */
GByteArray *last_packet;
int signal;
+#ifdef CONFIG_USER_ONLY
+ uint8_t siginfo[MAX_SIGINFO_LENGTH];
+#endif
bool multiprocess;
GDBProcess *processes;
int process_num;
diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c
index b7d4c37cd8..215bf33ab3 100644
--- a/gdbstub/user-target.c
+++ b/gdbstub/user-target.c
@@ -10,11 +10,12 @@
#include "qemu/osdep.h"
#include "exec/gdbstub.h"
#include "qemu.h"
-#include "internals.h"
#ifdef CONFIG_LINUX
#include "linux-user/loader.h"
#include "linux-user/qemu.h"
+#include "gdbstub/user.h"
#endif
+#include "internals.h"
/*
* Map target signal numbers to GDB protocol signal numbers and vice
diff --git a/gdbstub/user.c b/gdbstub/user.c
index a157e67f95..777fa78ef4 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -131,7 +131,8 @@ void gdb_qemu_exit(int code)
exit(code);
}
-int gdb_handlesig(CPUState *cpu, int sig, const char *reason)
+int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,
+ int siginfo_len)
{
char buf[256];
int n;
@@ -140,6 +141,11 @@ int gdb_handlesig(CPUState *cpu, int sig, const char *reason)
return sig;
}
+ if (siginfo) {
+ /* Save target-specific siginfo. */
+ memcpy(gdbserver_state.siginfo, siginfo, siginfo_len);
+ }
+
/* disable single step if it was enabled */
cpu_single_step(cpu, 0);
tb_flush(cpu);
@@ -510,7 +516,7 @@ void gdb_breakpoint_remove_all(CPUState *cs)
void gdb_syscall_handling(const char *syscall_packet)
{
gdb_put_packet(syscall_packet);
- gdb_handlesig(gdbserver_state.c_cpu, 0, NULL);
+ gdb_handlesig(gdbserver_state.c_cpu, 0, NULL, NULL, 0);
}
static bool should_catch_syscall(int num)
@@ -528,7 +534,7 @@ void gdb_syscall_entry(CPUState *cs, int num)
{
if (should_catch_syscall(num)) {
g_autofree char *reason = g_strdup_printf("syscall_entry:%x;", num);
- gdb_handlesig(cs, gdb_target_sigtrap(), reason);
+ gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
}
}
@@ -536,7 +542,7 @@ void gdb_syscall_return(CPUState *cs, int num)
{
if (should_catch_syscall(num)) {
g_autofree char *reason = g_strdup_printf("syscall_return:%x;", num);
- gdb_handlesig(cs, gdb_target_sigtrap(), reason);
+ gdb_handlesig(cs, gdb_target_sigtrap(), reason, NULL, 0);
}
}
diff --git a/include/gdbstub/user.h b/include/gdbstub/user.h
index 6647af2123..0ec9a7e596 100644
--- a/include/gdbstub/user.h
+++ b/include/gdbstub/user.h
@@ -9,11 +9,15 @@
#ifndef GDBSTUB_USER_H
#define GDBSTUB_USER_H
+#define MAX_SIGINFO_LENGTH 128
+
/**
* gdb_handlesig() - yield control to gdb
* @cpu: CPU
* @sig: if non-zero, the signal number which caused us to stop
* @reason: stop reason for stop reply packet or NULL
+ * @siginfo: target-specific siginfo struct
+ * @siginfo_len: target-specific siginfo struct length
*
* This function yields control to gdb, when a user-mode-only target
* needs to stop execution. If @sig is non-zero, then we will send a
@@ -25,7 +29,7 @@
* or 0 if no signal should be delivered, ie the signal that caused
* us to stop should be ignored.
*/
-int gdb_handlesig(CPUState *, int, const char *);
+int gdb_handlesig(CPUState *, int, const char *, void *, int);
/**
* gdb_signalled() - inform remote gdb of sig exit
diff --git a/linux-user/main.c b/linux-user/main.c
index 049fd85a2a..3187be48d6 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1014,7 +1014,7 @@ int main(int argc, char **argv, char **envp)
gdbstub);
exit(EXIT_FAILURE);
}
- gdb_handlesig(cpu, 0, NULL);
+ gdb_handlesig(cpu, 0, NULL, NULL, 0);
}
#ifdef CONFIG_SEMIHOSTING
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 7a4c8e416e..98d1eacffe 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -34,6 +34,9 @@
#include "user/safe-syscall.h"
#include "tcg/tcg.h"
+/* target_siginfo_t must fit in gdbstub's siginfo save area. */
+QEMU_BUILD_BUG_ON(sizeof(target_siginfo_t) > MAX_SIGINFO_LENGTH);
+
static struct target_sigaction sigact_table[TARGET_NSIG];
static void host_signal_handler(int host_signum, siginfo_t *info,
@@ -1186,7 +1189,7 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
*/
tswap_siginfo(&k->info, &k->info);
- sig = gdb_handlesig(cpu, sig, NULL);
+ sig = gdb_handlesig(cpu, sig, NULL, &k->info, sizeof(k->info));
if (!sig) {
sa = NULL;
handler = TARGET_SIG_IGN;
--
2.34.1
next prev 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 ` Gustavo Romero [this message]
2024-03-07 21:09 ` [PATCH v2 3/5] gdbstub: Save target's siginfo 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 ` [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub Gustavo Romero
2024-03-07 21:13 ` 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-3-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).