* [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig
@ 2024-03-07 18:26 Gustavo Romero
2024-03-07 18:26 ` [PATCH v2 2/5] linux-user: Move tswap_siginfo out of target code Gustavo Romero
` (5 more replies)
0 siblings, 6 replies; 21+ messages in thread
From: Gustavo Romero @ 2024-03-07 18:26 UTC (permalink / raw)
To: qemu-devel, richard.henderson
Cc: alex.bennee, peter.maydell, laurent, philmd, gustavo.romero
Rename gdb_handlesig_reason back to gdb_handlesig. There is no need to
add a wrapper for gdb_handlesig and rename it when a new parameter is
added.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
---
gdbstub/user.c | 8 ++++----
include/gdbstub/user.h | 15 ++-------------
linux-user/main.c | 2 +-
linux-user/signal.c | 2 +-
4 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/gdbstub/user.c b/gdbstub/user.c
index 14918d1a21..a157e67f95 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -131,7 +131,7 @@ void gdb_qemu_exit(int code)
exit(code);
}
-int gdb_handlesig_reason(CPUState *cpu, int sig, const char *reason)
+int gdb_handlesig(CPUState *cpu, int sig, const char *reason)
{
char buf[256];
int n;
@@ -510,7 +510,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);
+ gdb_handlesig(gdbserver_state.c_cpu, 0, NULL);
}
static bool should_catch_syscall(int num)
@@ -528,7 +528,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_reason(cs, gdb_target_sigtrap(), reason);
+ gdb_handlesig(cs, gdb_target_sigtrap(), reason);
}
}
@@ -536,7 +536,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_reason(cs, gdb_target_sigtrap(), reason);
+ gdb_handlesig(cs, gdb_target_sigtrap(), reason);
}
}
diff --git a/include/gdbstub/user.h b/include/gdbstub/user.h
index 68b6534130..6647af2123 100644
--- a/include/gdbstub/user.h
+++ b/include/gdbstub/user.h
@@ -10,7 +10,7 @@
#define GDBSTUB_USER_H
/**
- * gdb_handlesig_reason() - yield control to gdb
+ * 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
@@ -25,18 +25,7 @@
* or 0 if no signal should be delivered, ie the signal that caused
* us to stop should be ignored.
*/
-int gdb_handlesig_reason(CPUState *, int, const char *);
-
-/**
- * gdb_handlesig() - yield control to gdb
- * @cpu CPU
- * @sig: if non-zero, the signal number which caused us to stop
- * @see gdb_handlesig_reason()
- */
-static inline int gdb_handlesig(CPUState *cpu, int sig)
-{
- return gdb_handlesig_reason(cpu, sig, NULL);
-}
+int gdb_handlesig(CPUState *, int, const char *);
/**
* gdb_signalled() - inform remote gdb of sig exit
diff --git a/linux-user/main.c b/linux-user/main.c
index 551acf1661..049fd85a2a 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);
+ gdb_handlesig(cpu, 0, NULL);
}
#ifdef CONFIG_SEMIHOSTING
diff --git a/linux-user/signal.c b/linux-user/signal.c
index d3e62ab030..a57c45de35 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -1180,7 +1180,7 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
/* dequeue signal */
k->pending = 0;
- sig = gdb_handlesig(cpu, sig);
+ sig = gdb_handlesig(cpu, sig, NULL);
if (!sig) {
sa = NULL;
handler = TARGET_SIG_IGN;
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 2/5] linux-user: Move tswap_siginfo out of target code
2024-03-07 18:26 [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Gustavo Romero
@ 2024-03-07 18:26 ` Gustavo Romero
2024-03-07 19:21 ` Alex Bennée
2024-03-07 20:44 ` Richard Henderson
2024-03-07 18:26 ` [PATCH v2 3/5] gdbstub: Save target's siginfo Gustavo Romero
` (4 subsequent siblings)
5 siblings, 2 replies; 21+ messages in thread
From: Gustavo Romero @ 2024-03-07 18:26 UTC (permalink / raw)
To: qemu-devel, richard.henderson
Cc: alex.bennee, peter.maydell, laurent, philmd, gustavo.romero
Move tswap_siginfo from target code to handle_pending_signal. This will
allow some cleanups and having the siginfo ready to be used in gdbstub.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/aarch64/signal.c | 2 +-
linux-user/alpha/signal.c | 2 +-
linux-user/arm/signal.c | 2 +-
linux-user/hexagon/signal.c | 2 +-
linux-user/hppa/signal.c | 2 +-
linux-user/i386/signal.c | 6 +++---
linux-user/loongarch64/signal.c | 2 +-
linux-user/m68k/signal.c | 4 ++--
linux-user/microblaze/signal.c | 2 +-
linux-user/mips/signal.c | 4 ++--
linux-user/nios2/signal.c | 2 +-
linux-user/openrisc/signal.c | 2 +-
linux-user/ppc/signal.c | 4 ++--
linux-user/riscv/signal.c | 2 +-
linux-user/s390x/signal.c | 2 +-
linux-user/sh4/signal.c | 2 +-
linux-user/signal-common.h | 2 --
linux-user/signal.c | 10 ++++++++--
linux-user/sparc/signal.c | 2 +-
linux-user/xtensa/signal.c | 2 +-
20 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
index a1e22d526d..bc7a13800d 100644
--- a/linux-user/aarch64/signal.c
+++ b/linux-user/aarch64/signal.c
@@ -670,7 +670,7 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
aarch64_set_svcr(env, 0, R_SVCR_SM_MASK | R_SVCR_ZA_MASK);
if (info) {
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info);
env->xregs[2] = frame_addr + offsetof(struct target_rt_sigframe, uc);
}
diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c
index 4ec42994d4..896c2c148a 100644
--- a/linux-user/alpha/signal.c
+++ b/linux-user/alpha/signal.c
@@ -173,7 +173,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
__put_user(0, &frame->uc.tuc_flags);
__put_user(0, &frame->uc.tuc_link);
diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c
index f77f692c63..420fc04cfa 100644
--- a/linux-user/arm/signal.c
+++ b/linux-user/arm/signal.c
@@ -357,7 +357,7 @@ void setup_rt_frame(int usig, struct target_sigaction *ka,
info_addr = frame_addr + offsetof(struct rt_sigframe, info);
uc_addr = frame_addr + offsetof(struct rt_sigframe, sig.uc);
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
setup_sigframe(&frame->sig.uc, set, env);
diff --git a/linux-user/hexagon/signal.c b/linux-user/hexagon/signal.c
index 60fa7e1bce..492b51f155 100644
--- a/linux-user/hexagon/signal.c
+++ b/linux-user/hexagon/signal.c
@@ -162,7 +162,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}
setup_ucontext(&frame->uc, env, set);
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
/*
* The on-stack signal trampoline is no longer executed;
* however, the libgcc signal frame unwinding code checks
diff --git a/linux-user/hppa/signal.c b/linux-user/hppa/signal.c
index d08a97dae6..8960175da3 100644
--- a/linux-user/hppa/signal.c
+++ b/linux-user/hppa/signal.c
@@ -127,7 +127,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
frame->uc.tuc_flags = 0;
frame->uc.tuc_link = 0;
diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
index bc5d45302e..cfe70fc5cf 100644
--- a/linux-user/i386/signal.c
+++ b/linux-user/i386/signal.c
@@ -430,7 +430,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0],
frame_addr + offsetof(struct sigframe, fpstate));
- for(i = 1; i < TARGET_NSIG_WORDS; i++) {
+ for (i = 1; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->extramask[i - 1]);
}
@@ -490,7 +490,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(addr, &frame->puc);
#endif
if (ka->sa_flags & TARGET_SA_SIGINFO) {
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
}
/* Create the ucontext. */
@@ -504,7 +504,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, env,
set->sig[0], frame_addr + offsetof(struct rt_sigframe, fpstate));
- for(i = 0; i < TARGET_NSIG_WORDS; i++) {
+ for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
}
diff --git a/linux-user/loongarch64/signal.c b/linux-user/loongarch64/signal.c
index 39ea82c814..1a322f9697 100644
--- a/linux-user/loongarch64/signal.c
+++ b/linux-user/loongarch64/signal.c
@@ -376,7 +376,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
extctx.end.haddr = (void *)frame + (extctx.end.gaddr - frame_addr);
}
- tswap_siginfo(&frame->rs_info, info);
+ frame->rs_info = *info;
__put_user(0, &frame->rs_uc.tuc_flags);
__put_user(0, &frame->rs_uc.tuc_link);
diff --git a/linux-user/m68k/signal.c b/linux-user/m68k/signal.c
index 5f35354487..77555781aa 100644
--- a/linux-user/m68k/signal.c
+++ b/linux-user/m68k/signal.c
@@ -295,7 +295,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);
__put_user(uc_addr, &frame->puc);
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
/* Create the ucontext */
@@ -307,7 +307,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
if (err)
goto give_sigsegv;
- for(i = 0; i < TARGET_NSIG_WORDS; i++) {
+ for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
}
diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c
index 5188d74025..f6d47d76ff 100644
--- a/linux-user/microblaze/signal.c
+++ b/linux-user/microblaze/signal.c
@@ -147,7 +147,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
return;
}
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
__put_user(0, &frame->uc.tuc_flags);
__put_user(0, &frame->uc.tuc_link);
diff --git a/linux-user/mips/signal.c b/linux-user/mips/signal.c
index 58a9d7a8a3..d69a5d73dd 100644
--- a/linux-user/mips/signal.c
+++ b/linux-user/mips/signal.c
@@ -303,7 +303,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}
- tswap_siginfo(&frame->rs_info, info);
+ frame->rs_info = *info;
__put_user(0, &frame->rs_uc.tuc_flags);
__put_user(0, &frame->rs_uc.tuc_link);
@@ -311,7 +311,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
setup_sigcontext(env, &frame->rs_uc.tuc_mcontext);
- for(i = 0; i < TARGET_NSIG_WORDS; i++) {
+ for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &frame->rs_uc.tuc_sigmask.sig[i]);
}
diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index 32b3dc99c6..64c345f409 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -157,7 +157,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
return;
}
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
/* Create the ucontext. */
__put_user(0, &frame->uc.tuc_flags);
diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c
index be8b68784a..cb74a9fe5e 100644
--- a/linux-user/openrisc/signal.c
+++ b/linux-user/openrisc/signal.c
@@ -103,7 +103,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}
if (ka->sa_flags & SA_SIGINFO) {
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
}
__put_user(0, &frame->uc.tuc_flags);
diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
index 7e7302823b..0ebfc0b26b 100644
--- a/linux-user/ppc/signal.c
+++ b/linux-user/ppc/signal.c
@@ -493,7 +493,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
if (!lock_user_struct(VERIFY_WRITE, rt_sf, rt_sf_addr, 1))
goto sigsegv;
- tswap_siginfo(&rt_sf->info, info);
+ rt_sf->info = *info;
__put_user(0, &rt_sf->uc.tuc_flags);
__put_user(0, &rt_sf->uc.tuc_link);
@@ -502,7 +502,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(h2g (&rt_sf->uc.tuc_mcontext),
&rt_sf->uc.tuc_regs);
#endif
- for(i = 0; i < TARGET_NSIG_WORDS; i++) {
+ for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user(set->sig[i], &rt_sf->uc.tuc_sigmask.sig[i]);
}
diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c
index 941eadce87..358fa1d82d 100644
--- a/linux-user/riscv/signal.c
+++ b/linux-user/riscv/signal.c
@@ -125,7 +125,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}
setup_ucontext(&frame->uc, env, set);
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
env->pc = ka->_sa_handler;
env->gpr[xSP] = frame_addr;
diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index b40f738a70..df49c24708 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -267,7 +267,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}
/* Create siginfo on the signal stack. */
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
/* Create ucontext on the signal stack. */
uc_flags = 0;
diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c
index c16c2c2d57..9ecc026fae 100644
--- a/linux-user/sh4/signal.c
+++ b/linux-user/sh4/signal.c
@@ -233,7 +233,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
goto give_sigsegv;
}
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
/* Create the ucontext. */
__put_user(0, &frame->uc.tuc_flags);
diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h
index 3e2dc604c2..f02d2b6b64 100644
--- a/linux-user/signal-common.h
+++ b/linux-user/signal-common.h
@@ -43,8 +43,6 @@ void host_to_target_sigset_internal(target_sigset_t *d,
const sigset_t *s);
void target_to_host_sigset_internal(sigset_t *d,
const target_sigset_t *s);
-void tswap_siginfo(target_siginfo_t *tinfo,
- const target_siginfo_t *info);
void set_sigmask(const sigset_t *set);
void force_sig(int sig);
void force_sigsegv(int oldsig);
diff --git a/linux-user/signal.c b/linux-user/signal.c
index a57c45de35..7a4c8e416e 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -409,8 +409,8 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
tinfo->si_code = deposit32(si_code, 16, 16, si_type);
}
-void tswap_siginfo(target_siginfo_t *tinfo,
- const target_siginfo_t *info)
+static void tswap_siginfo(target_siginfo_t *tinfo,
+ const target_siginfo_t *info)
{
int si_type = extract32(info->si_code, 16, 16);
int si_code = sextract32(info->si_code, 0, 16);
@@ -1180,6 +1180,12 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
/* dequeue signal */
k->pending = 0;
+ /*
+ * Writes out siginfo values byteswapped, accordingly to the target. It also
+ * cleans the si_type from si_code making it correct for the target.
+ */
+ tswap_siginfo(&k->info, &k->info);
+
sig = gdb_handlesig(cpu, sig, NULL);
if (!sig) {
sa = NULL;
diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index c2dc1000e2..f164b74032 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -333,7 +333,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
__put_user(0, &sf->rwin_save); /* TODO: save_rwin_state */
- tswap_siginfo(&sf->info, info);
+ sf->info = *info;
tswap_sigset(&sf->mask, set);
target_save_altstack(&sf->stack, env);
diff --git a/linux-user/xtensa/signal.c b/linux-user/xtensa/signal.c
index 32dcfa5229..11e60c3c82 100644
--- a/linux-user/xtensa/signal.c
+++ b/linux-user/xtensa/signal.c
@@ -184,7 +184,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
}
if (ka->sa_flags & SA_SIGINFO) {
- tswap_siginfo(&frame->info, info);
+ frame->info = *info;
}
__put_user(0, &frame->uc.tuc_flags);
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 3/5] gdbstub: Save target's siginfo
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 18:26 ` Gustavo Romero
2024-03-07 21:09 ` Richard Henderson
2024-03-07 18:26 ` [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub Gustavo Romero
` (3 subsequent siblings)
5 siblings, 1 reply; 21+ messages in thread
From: Gustavo Romero @ 2024-03-07 18:26 UTC (permalink / raw)
To: qemu-devel, richard.henderson
Cc: alex.bennee, peter.maydell, laurent, philmd, gustavo.romero
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
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub
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 18:26 ` [PATCH v2 3/5] gdbstub: Save target's siginfo Gustavo Romero
@ 2024-03-07 18:26 ` Gustavo Romero
2024-03-07 21:13 ` Richard Henderson
2024-03-07 18:26 ` [PATCH v2 5/5] tests/tcg: Add multiarch test for " Gustavo Romero
` (2 subsequent siblings)
5 siblings, 1 reply; 21+ messages in thread
From: Gustavo Romero @ 2024-03-07 18:26 UTC (permalink / raw)
To: qemu-devel, richard.henderson
Cc: alex.bennee, peter.maydell, laurent, philmd, gustavo.romero
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
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 5/5] tests/tcg: Add multiarch test for Xfer:siginfo:read stub
2024-03-07 18:26 [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Gustavo Romero
` (2 preceding siblings ...)
2024-03-07 18:26 ` [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub Gustavo Romero
@ 2024-03-07 18:26 ` 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
5 siblings, 1 reply; 21+ messages in thread
From: Gustavo Romero @ 2024-03-07 18:26 UTC (permalink / raw)
To: qemu-devel, richard.henderson
Cc: alex.bennee, peter.maydell, laurent, philmd, gustavo.romero
Add multiarch test for testing if Xfer:siginfo:read query is properly
handled by gdbstub.
Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
---
tests/tcg/multiarch/Makefile.target | 10 ++++++-
.../gdbstub/test-qxfer-siginfo-read.py | 26 +++++++++++++++++++
tests/tcg/multiarch/segfault.c | 14 ++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
create mode 100644 tests/tcg/multiarch/gdbstub/test-qxfer-siginfo-read.py
create mode 100644 tests/tcg/multiarch/segfault.c
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
index f11f3b084d..5ab4ba89b2 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -71,6 +71,13 @@ run-gdbstub-qxfer-auxv-read: sha1
--bin $< --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-auxv-read.py, \
basic gdbstub qXfer:auxv:read support)
+run-gdbstub-qxfer-siginfo-read: segfault
+ $(call run-test, $@, $(GDB_SCRIPT) \
+ --gdb $(GDB) \
+ --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
+ --bin "$< -s" --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-siginfo-read.py, \
+ basic gdbstub qXfer:siginfo:read support)
+
run-gdbstub-proc-mappings: sha1
$(call run-test, $@, $(GDB_SCRIPT) \
--gdb $(GDB) \
@@ -113,7 +120,8 @@ endif
EXTRA_RUNS += run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \
run-gdbstub-proc-mappings run-gdbstub-thread-breakpoint \
run-gdbstub-registers run-gdbstub-prot-none \
- run-gdbstub-catch-syscalls
+ run-gdbstub-catch-syscalls \
+ run-gdbstub-qxfer-siginfo-read
# ARM Compatible Semi Hosting Tests
#
diff --git a/tests/tcg/multiarch/gdbstub/test-qxfer-siginfo-read.py b/tests/tcg/multiarch/gdbstub/test-qxfer-siginfo-read.py
new file mode 100644
index 0000000000..862596b07a
--- /dev/null
+++ b/tests/tcg/multiarch/gdbstub/test-qxfer-siginfo-read.py
@@ -0,0 +1,26 @@
+from __future__ import print_function
+#
+# Test gdbstub Xfer:siginfo:read stub.
+#
+# The test runs a binary that causes a SIGSEGV and then looks for additional
+# info about the signal through printing GDB's '$_siginfo' special variable,
+# which sends a Xfer:siginfo:read query to the gdbstub.
+#
+# The binary causes a SIGSEGV at dereferencing a pointer with value 0xdeadbeef,
+# so the test looks for and checks if this address is correctly reported by the
+# gdbstub.
+#
+# This is launched via tests/guest-debug/run-test.py
+#
+
+import gdb
+from test_gdbstub import main, report
+
+def run_test():
+ "Run through the test"
+
+ gdb.execute("continue", False, True)
+ resp = gdb.execute("print/x $_siginfo", False, True)
+ report(resp.find("si_addr = 0xdeadbeef"), "Found fault address.")
+
+main(run_test)
diff --git a/tests/tcg/multiarch/segfault.c b/tests/tcg/multiarch/segfault.c
new file mode 100644
index 0000000000..e6c8ff31ca
--- /dev/null
+++ b/tests/tcg/multiarch/segfault.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <string.h>
+
+/* Cause a segfault for testing purposes. */
+
+int main(int argc, char *argv[])
+{
+ int *ptr = (void *)0xdeadbeef;
+
+ if (argc == 2 && strcmp(argv[1], "-s") == 0) {
+ /* Cause segfault. */
+ printf("%d\n", *ptr);
+ }
+}
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig
2024-03-07 18:26 [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Gustavo Romero
` (3 preceding siblings ...)
2024-03-07 18:26 ` [PATCH v2 5/5] tests/tcg: Add multiarch test for " Gustavo Romero
@ 2024-03-07 19:14 ` Alex Bennée
2024-03-07 20:43 ` Richard Henderson
5 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2024-03-07 19:14 UTC (permalink / raw)
To: Gustavo Romero
Cc: qemu-devel, richard.henderson, peter.maydell, laurent, philmd
Gustavo Romero <gustavo.romero@linaro.org> writes:
> Rename gdb_handlesig_reason back to gdb_handlesig. There is no need to
> add a wrapper for gdb_handlesig and rename it when a new parameter is
> added.
>
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/5] linux-user: Move tswap_siginfo out of target code
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
1 sibling, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2024-03-07 19:21 UTC (permalink / raw)
To: Gustavo Romero
Cc: qemu-devel, richard.henderson, peter.maydell, laurent, philmd
Gustavo Romero <gustavo.romero@linaro.org> writes:
> Move tswap_siginfo from target code to handle_pending_signal. This will
> allow some cleanups and having the siginfo ready to be used in gdbstub.
>
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> linux-user/aarch64/signal.c | 2 +-
> linux-user/alpha/signal.c | 2 +-
> linux-user/arm/signal.c | 2 +-
> linux-user/hexagon/signal.c | 2 +-
> linux-user/hppa/signal.c | 2 +-
> linux-user/i386/signal.c | 6 +++---
> linux-user/loongarch64/signal.c | 2 +-
> linux-user/m68k/signal.c | 4 ++--
> linux-user/microblaze/signal.c | 2 +-
> linux-user/mips/signal.c | 4 ++--
> linux-user/nios2/signal.c | 2 +-
> linux-user/openrisc/signal.c | 2 +-
> linux-user/ppc/signal.c | 4 ++--
> linux-user/riscv/signal.c | 2 +-
> linux-user/s390x/signal.c | 2 +-
> linux-user/sh4/signal.c | 2 +-
> linux-user/signal-common.h | 2 --
> linux-user/signal.c | 10 ++++++++--
> linux-user/sparc/signal.c | 2 +-
> linux-user/xtensa/signal.c | 2 +-
> 20 files changed, 31 insertions(+), 27 deletions(-)
>
> diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
<snip>
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -409,8 +409,8 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
> tinfo->si_code = deposit32(si_code, 16, 16, si_type);
> }
>
> -void tswap_siginfo(target_siginfo_t *tinfo,
> - const target_siginfo_t *info)
> +static void tswap_siginfo(target_siginfo_t *tinfo,
> + const target_siginfo_t *info)
> {
> int si_type = extract32(info->si_code, 16, 16);
> int si_code = sextract32(info->si_code, 0, 16);
> @@ -1180,6 +1180,12 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
> /* dequeue signal */
> k->pending = 0;
>
> + /*
> + * Writes out siginfo values byteswapped, accordingly to the target. It also
> + * cleans the si_type from si_code making it correct for the target.
> + */
> + tswap_siginfo(&k->info, &k->info);
> +
I'm not sure I like this, you have the same pointer to both a const and
non-const arg. Do we assert we come through this once per signal and
don't risk double swapping the contents?
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig
2024-03-07 18:26 [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Gustavo Romero
` (4 preceding siblings ...)
2024-03-07 19:14 ` [PATCH v2 1/5] gdbstub: Rename back gdb_handlesig Alex Bennée
@ 2024-03-07 20:43 ` Richard Henderson
5 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2024-03-07 20:43 UTC (permalink / raw)
To: Gustavo Romero, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
On 3/7/24 08:26, Gustavo Romero wrote:
> Rename gdb_handlesig_reason back to gdb_handlesig. There is no need to
> add a wrapper for gdb_handlesig and rename it when a new parameter is
> added.
>
> Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
> ---
> gdbstub/user.c | 8 ++++----
> include/gdbstub/user.h | 15 ++-------------
> linux-user/main.c | 2 +-
> linux-user/signal.c | 2 +-
> 4 files changed, 8 insertions(+), 19 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/5] linux-user: Move tswap_siginfo out of target code
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:44 ` Richard Henderson
1 sibling, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2024-03-07 20:44 UTC (permalink / raw)
To: Gustavo Romero, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
On 3/7/24 08:26, Gustavo Romero wrote:
> Move tswap_siginfo from target code to handle_pending_signal. This will
> allow some cleanups and having the siginfo ready to be used in gdbstub.
>
> Signed-off-by: Gustavo Romero<gustavo.romero@linaro.org>
> Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> ---
> linux-user/aarch64/signal.c | 2 +-
> linux-user/alpha/signal.c | 2 +-
> linux-user/arm/signal.c | 2 +-
> linux-user/hexagon/signal.c | 2 +-
> linux-user/hppa/signal.c | 2 +-
> linux-user/i386/signal.c | 6 +++---
> linux-user/loongarch64/signal.c | 2 +-
> linux-user/m68k/signal.c | 4 ++--
> linux-user/microblaze/signal.c | 2 +-
> linux-user/mips/signal.c | 4 ++--
> linux-user/nios2/signal.c | 2 +-
> linux-user/openrisc/signal.c | 2 +-
> linux-user/ppc/signal.c | 4 ++--
> linux-user/riscv/signal.c | 2 +-
> linux-user/s390x/signal.c | 2 +-
> linux-user/sh4/signal.c | 2 +-
> linux-user/signal-common.h | 2 --
> linux-user/signal.c | 10 ++++++++--
> linux-user/sparc/signal.c | 2 +-
> linux-user/xtensa/signal.c | 2 +-
> 20 files changed, 31 insertions(+), 27 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/5] linux-user: Move tswap_siginfo out of target code
2024-03-07 19:21 ` Alex Bennée
@ 2024-03-07 20:47 ` Richard Henderson
0 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2024-03-07 20:47 UTC (permalink / raw)
To: Alex Bennée, Gustavo Romero
Cc: qemu-devel, peter.maydell, laurent, philmd
On 3/7/24 09:21, Alex Bennée wrote:
>> + /*
>> + * Writes out siginfo values byteswapped, accordingly to the target. It also
>> + * cleans the si_type from si_code making it correct for the target.
>> + */
>> + tswap_siginfo(&k->info, &k->info);
>> +
>
> I'm not sure I like this, you have the same pointer to both a const and
> non-const arg. Do we assert we come through this once per signal and
> don't risk double swapping the contents?
>
I suggested this as an intermediate step -- the function will work perfectly fine with
dest == source. Follow-up patches should clean this up further, but I told Gustavo to not
get distracted from his goal with *too* much cleanup.
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
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 20:24 ` Gustavo Romero
0 siblings, 2 replies; 21+ messages in thread
From: Richard Henderson @ 2024-03-07 21:09 UTC (permalink / raw)
To: Gustavo Romero, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
On 3/7/24 08:26, Gustavo Romero wrote:
> 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
If we this in GDBUserState in user.c -- no need for ifdefs then.
> --- 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
Why are any changes required here?
Perhaps this is improper patch split from one of the others?
> @@ -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);
> + }
A comment here about asserting the size at compile-time elsewhere would be welcome for
future code browsers.
Need to record siginfo_len for later use -- you don't want to expose all 128 bytes if the
actual structure is smaller.
> @@ -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);
> }
All of this makes me wonder if we should provide a different interface for syscalls, even
if it uses the same code paths internally.
Do we want to zero the gdbserver siginfo to indicate that the contents are no longer
valid? I know it's not a real signal delivered to the process, but might we need to
construct a simple siginfo struct to match the sigtrap?
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub
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
0 siblings, 1 reply; 21+ messages in thread
From: Richard Henderson @ 2024-03-07 21:13 UTC (permalink / raw)
To: Gustavo Romero, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
On 3/7/24 08:26, Gustavo Romero wrote:
> +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)) {
If you save the siginfo_len from gdb_handlesig, you can place this in user.c.
Is it really correct to reject (offset == 0) + (len == large), rather than truncate len?
> + /* Reply */
> + g_string_assign(gdbserver_state.str_buf, "l");
> + gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len);
It seems easy enough to reply with the exact length remaining...
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 5/5] tests/tcg: Add multiarch test for Xfer:siginfo:read stub
2024-03-07 18:26 ` [PATCH v2 5/5] tests/tcg: Add multiarch test for " Gustavo Romero
@ 2024-03-07 21:16 ` Richard Henderson
0 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2024-03-07 21:16 UTC (permalink / raw)
To: Gustavo Romero, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
On 3/7/24 08:26, Gustavo Romero wrote:
> Add multiarch test for testing if Xfer:siginfo:read query is properly
> handled by gdbstub.
>
> Signed-off-by: Gustavo Romero<gustavo.romero@linaro.org>
> ---
> tests/tcg/multiarch/Makefile.target | 10 ++++++-
> .../gdbstub/test-qxfer-siginfo-read.py | 26 +++++++++++++++++++
> tests/tcg/multiarch/segfault.c | 14 ++++++++++
> 3 files changed, 49 insertions(+), 1 deletion(-)
> create mode 100644 tests/tcg/multiarch/gdbstub/test-qxfer-siginfo-read.py
> create mode 100644 tests/tcg/multiarch/segfault.c
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
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 20:24 ` Gustavo Romero
1 sibling, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2024-03-07 22:33 UTC (permalink / raw)
To: Richard Henderson
Cc: Gustavo Romero, qemu-devel, peter.maydell, laurent, philmd
Richard Henderson <richard.henderson@linaro.org> writes:
> On 3/7/24 08:26, Gustavo Romero wrote:
>> 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
>
> If we this in GDBUserState in user.c -- no need for ifdefs then.
Although it does break on FreeBSD's user target:
FAILED: libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o
cc -m64 -mcx16 -Ilibqemu-arm-bsd-user.fa.p -I. -I.. -Itarget/arm -I../target/arm -I../common-user/host/x86_64 -I../bsd-user/include -Ibsd-user/freebsd -I../bsd-user/freebsd -I../bsd-user/host/x86_64 -Ibsd-user -I../bsd-user -I../bsd-user/arm -Iqapi -Itrace -Iui -Iui/shader -I/usr/local/include/capstone -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wredundant-decls -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-gnu-variable-sized-type-not-at-end -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -Wno-string-plus-int -Wno-tautological-type-limit-compare -Wno-typedef-redefinition -Wthread-safety -iquote . -iquote /tmp/cirrus-ci-build -iquote /tmp/cirrus-ci-build/include -iquote /tmp/cirrus-ci-build/host/include/x86_64 -iquote /tmp/cirrus-ci-build/host/include/generic -iquote /tmp/cirrus-ci-build/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fPIE -DNEED_CPU_H '-DCONFIG_TARGET="arm-bsd-user-config-target.h"' '-DCONFIG_DEVICES="arm-bsd-user-config-devices.h"' -MD -MQ libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o -MF libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o.d -o libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o -c ../gdbstub/user-target.c
In file included from ../gdbstub/user-target.c:18:
../gdbstub/internals.h:62:21: error: use of undeclared identifier 'MAX_SIGINFO_LENGTH'
62 | uint8_t siginfo[MAX_SIGINFO_LENGTH];
| ^
1 error generated.
[2084/6731] Compiling C object libqemu-arm
See: https://gitlab.com/stsquad/qemu/-/jobs/6345829419
<snip>
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
2024-03-07 22:33 ` Alex Bennée
@ 2024-03-08 17:01 ` Gustavo Romero
2024-03-08 19:25 ` Alex Bennée
0 siblings, 1 reply; 21+ messages in thread
From: Gustavo Romero @ 2024-03-08 17:01 UTC (permalink / raw)
To: Alex Bennée, Richard Henderson
Cc: qemu-devel, peter.maydell, laurent, philmd
Hi Alex,
On 3/7/24 7:33 PM, Alex Bennée wrote:
> Richard Henderson <richard.henderson@linaro.org> writes:
>
>> On 3/7/24 08:26, Gustavo Romero wrote:
>>> 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
>>
>> If we this in GDBUserState in user.c -- no need for ifdefs then.
>
> Although it does break on FreeBSD's user target:
>
> FAILED: libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o
> cc -m64 -mcx16 -Ilibqemu-arm-bsd-user.fa.p -I. -I.. -Itarget/arm -I../target/arm -I../common-user/host/x86_64 -I../bsd-user/include -Ibsd-user/freebsd -I../bsd-user/freebsd -I../bsd-user/host/x86_64 -Ibsd-user -I../bsd-user -I../bsd-user/arm -Iqapi -Itrace -Iui -Iui/shader -I/usr/local/include/capstone -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wredundant-decls -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-gnu-variable-sized-type-not-at-end -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -Wno-string-plus-int -Wno-tautological-type-limit-compare -Wno-typedef-redefinition -Wthread-safety -iquote . -iquote /tmp/cirrus-ci-build -iquote /tmp/cirrus-ci-build/include -iquote /tmp/cirrus-ci-build/host/include/x86_64 -iquote /tmp/cirrus-ci-build/host/include/generic -iquote /tmp/cirrus-ci-build/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fPIE -DNEED_CPU_H '-DCONFIG_TARGET="arm-bsd-user-config-target.h"' '-DCONFIG_DEVICES="arm-bsd-user-config-devices.h"' -MD -MQ libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o -MF libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o.d -o libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o -c ../gdbstub/user-target.c
> In file included from ../gdbstub/user-target.c:18:
> ../gdbstub/internals.h:62:21: error: use of undeclared identifier 'MAX_SIGINFO_LENGTH'
> 62 | uint8_t siginfo[MAX_SIGINFO_LENGTH];
> | ^
> 1 error generated.
> [2084/6731] Compiling C object libqemu-arm
>
> See: https://gitlab.com/stsquad/qemu/-/jobs/6345829419
argh, I've tested all targets for linux-user, but missed bsd-user. I've tried
once to build it but that requires a BSD-like host, which I don't have at the
moment, then I forgot about it... Let me setup one and review the change in
the light of the comments from you and Richard.
Thanks!
Cheers,
Gustavo
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub
2024-03-07 21:13 ` Richard Henderson
@ 2024-03-08 18:30 ` Gustavo Romero
2024-03-09 0:58 ` Richard Henderson
0 siblings, 1 reply; 21+ messages in thread
From: Gustavo Romero @ 2024-03-08 18:30 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
Hi Richard!
On 3/7/24 6:13 PM, Richard Henderson wrote:
> On 3/7/24 08:26, Gustavo Romero wrote:
>> +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)) {
>
> If you save the siginfo_len from gdb_handlesig, you can place this in user.c
Shouldn't all user-only stubs be placed in user-target.c? Like
gdb_handle_query_xfer_auxv and gdb_handle_query_xfer_exec_file, and since
what controls the inclusion in the build of user-target.c is CONFIG_USER_ONLY?
> Is it really correct to reject (offset == 0) + (len == large), rather than truncate len?
I think this is correct. GDB mentions briefly that an invalid offset
should be treated as an error. Thus, I think that a valid offset but
a non-existing/invalid (large) length should be treated the same,
cause in the end data on invalid offsets are being requested anyways.
>> + /* Reply */
>> + g_string_assign(gdbserver_state.str_buf, "l");
>> + gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len);
>
> It seems easy enough to reply with the exact length remaining...
I think the correct is to reply an error in case GDB asks a data
we don't have rather than returning anything else to satisfy GDB.
If offset+len is inside target_siginfo_t, than that's ok, otherwise
that's an error.
Cheers,
Gustavo
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
2024-03-08 17:01 ` Gustavo Romero
@ 2024-03-08 19:25 ` Alex Bennée
2024-03-09 0:41 ` Richard Henderson
0 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2024-03-08 19:25 UTC (permalink / raw)
To: Gustavo Romero
Cc: Richard Henderson, qemu-devel, peter.maydell, laurent, philmd
Gustavo Romero <gustavo.romero@linaro.org> writes:
> Hi Alex,
>
> On 3/7/24 7:33 PM, Alex Bennée wrote:
>> Richard Henderson <richard.henderson@linaro.org> writes:
>>
>>> On 3/7/24 08:26, Gustavo Romero wrote:
>>>> 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
>>>
>>> If we this in GDBUserState in user.c -- no need for ifdefs then.
>> Although it does break on FreeBSD's user target:
>> FAILED: libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o
>> cc -m64 -mcx16 -Ilibqemu-arm-bsd-user.fa.p -I. -I.. -Itarget/arm -I../target/arm -I../common-user/host/x86_64 -I../bsd-user/include -Ibsd-user/freebsd -I../bsd-user/freebsd -I../bsd-user/host/x86_64 -Ibsd-user -I../bsd-user -I../bsd-user/arm -Iqapi -Itrace -Iui -Iui/shader -I/usr/local/include/capstone -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -fdiagnostics-color=auto -Wall -Winvalid-pch -Werror -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wredundant-decls -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-gnu-variable-sized-type-not-at-end -Wno-initializer-overrides -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -Wno-string-plus-int -Wno-tautological-type-limit-compare -Wno-typedef-redefinition -Wthread-safety -iquote . -iquote /tmp/cirrus-ci-build -iquote /tmp/cirrus-ci-build/include -iquote /tmp/cirrus-ci-build/host/include/x86_64 -iquote /tmp/cirrus-ci-build/host/include/generic -iquote /tmp/cirrus-ci-build/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fPIE -DNEED_CPU_H '-DCONFIG_TARGET="arm-bsd-user-config-target.h"' '-DCONFIG_DEVICES="arm-bsd-user-config-devices.h"' -MD -MQ libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o -MF libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o.d -o libqemu-arm-bsd-user.fa.p/gdbstub_user-target.c.o -c ../gdbstub/user-target.c
>> In file included from ../gdbstub/user-target.c:18:
>> ../gdbstub/internals.h:62:21: error: use of undeclared identifier 'MAX_SIGINFO_LENGTH'
>> 62 | uint8_t siginfo[MAX_SIGINFO_LENGTH];
>> | ^
>> 1 error generated.
>> [2084/6731] Compiling C object libqemu-arm
>> See: https://gitlab.com/stsquad/qemu/-/jobs/6345829419
>
> argh, I've tested all targets for linux-user, but missed bsd-user. I've tried
> once to build it but that requires a BSD-like host, which I don't have at the
> moment, then I forgot about it... Let me setup one and review the change in
> the light of the comments from you and Richard.
make vm-build-[open|net|free]bsd
see make vm-help for details.
>
> Thanks!
>
>
> Cheers,
> Gustavo
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
2024-03-07 21:09 ` Richard Henderson
2024-03-07 22:33 ` Alex Bennée
@ 2024-03-08 20:24 ` Gustavo Romero
1 sibling, 0 replies; 21+ messages in thread
From: Gustavo Romero @ 2024-03-08 20:24 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
Hi Richard,
On 3/7/24 6:09 PM, Richard Henderson wrote:
> On 3/7/24 08:26, Gustavo Romero wrote:
>> 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
>
> If we this in GDBUserState in user.c -- no need for ifdefs then.
Thanks, I've moved it to user.c.
>> --- 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
>
> Why are any changes required here?
> Perhaps this is improper patch split from one of the others?
This was intentional. Because I declared siginfo[MAX_SIGINFO_LENGTH] in
GDBState struct, which is in internals.h and MAX_SIGINFO_LENGTH is defined
in gdbstub/user.h I had to move internals.h after user.h was included so
MAX_SIGINFO_LENGTH could be found.
I'm reverting it.
>> @@ -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);
>> + }
>
> A comment here about asserting the size at compile-time elsewhere would be welcome for future code browsers.
Done.
> Need to record siginfo_len for later use -- you don't want to expose all 128 bytes if the actual structure is smaller.
In the stub, the full size is only used to check if the requested offset+len is valid.
So the only size that matters for reading data from siginfo and assembling
the reply is the length in the query, not siginfo_len. But I agree it's better, even
more now that I moved the stub from user-target.c to user.c.
>> @@ -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);
>> }
>
> All of this makes me wonder if we should provide a different interface for syscalls, even if it uses the same code paths internally.
Should I address it in this series? I'm sure how that interface would be.
> Do we want to zero the gdbserver siginfo to indicate that the contents are no longer valid? I know it's not a real signal delivered to the process, but might we need to construct a simple siginfo struct to match the sigtrap?
In gdb_handlesig we always copy the full size of siginfo to gdbserver_user_state siginfo,
which is passed in siginfo_len and now recorded gdbserver siginfo_len too for later use.
Isn't that copy guaranteeing that gdbserver siginfo has always no stale data?
Cheers,
Gustavo
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
2024-03-08 19:25 ` Alex Bennée
@ 2024-03-09 0:41 ` Richard Henderson
2024-03-09 11:43 ` Alex Bennée
0 siblings, 1 reply; 21+ messages in thread
From: Richard Henderson @ 2024-03-09 0:41 UTC (permalink / raw)
To: Alex Bennée, Gustavo Romero
Cc: qemu-devel, peter.maydell, laurent, philmd
On 3/8/24 09:25, Alex Bennée wrote:
> make vm-build-[open|net|free]bsd
>
> see make vm-help for details.
That won't build freebsd user.
Something I've mentioned to you before...
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 4/5] gdbstub: Add Xfer:siginfo:read stub
2024-03-08 18:30 ` Gustavo Romero
@ 2024-03-09 0:58 ` Richard Henderson
0 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2024-03-09 0:58 UTC (permalink / raw)
To: Gustavo Romero, qemu-devel; +Cc: alex.bennee, peter.maydell, laurent, philmd
On 3/8/24 08:30, Gustavo Romero wrote:
> Hi Richard!
>
> On 3/7/24 6:13 PM, Richard Henderson wrote:
>> On 3/7/24 08:26, Gustavo Romero wrote:
>>> +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)) {
>>
>> If you save the siginfo_len from gdb_handlesig, you can place this in user.c
> Shouldn't all user-only stubs be placed in user-target.c? Like
> gdb_handle_query_xfer_auxv and gdb_handle_query_xfer_exec_file, and since
> what controls the inclusion in the build of user-target.c is CONFIG_USER_ONLY?
user.c is also build for CONFIG_USER_ONLY, except that it is compiled only once, and has
no target-specific code in it.
>> Is it really correct to reject (offset == 0) + (len == large), rather than truncate len?
>
> I think this is correct. GDB mentions briefly that an invalid offset
> should be treated as an error. Thus, I think that a valid offset but
> a non-existing/invalid (large) length should be treated the same,
> cause in the end data on invalid offsets are being requested anyways.
Ok.
r~
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/5] gdbstub: Save target's siginfo
2024-03-09 0:41 ` Richard Henderson
@ 2024-03-09 11:43 ` Alex Bennée
0 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2024-03-09 11:43 UTC (permalink / raw)
To: Richard Henderson
Cc: Gustavo Romero, qemu-devel, peter.maydell, laurent, philmd
Richard Henderson <richard.henderson@linaro.org> writes:
> On 3/8/24 09:25, Alex Bennée wrote:
>> make vm-build-[open|net|free]bsd
>> see make vm-help for details.
>
> That won't build freebsd user.
> Something I've mentioned to you before...
make vm-build-freebsd BUILD_TARGET=all
I guess the default "check" target doesn't work due to the missing cross
compilers meaning we have no check-tcg target in the default check list.
>
>
> r~
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2024-03-09 11:44 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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
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).