gdbstub: Protect gdb_handlesig() with EXCLUSIVE_GUARD()
PATCH 2/3 cpu: Introduce EXCLUSIVE_GUARD()
In reply to Ilya LeoshkevichAdd a macro that produces a start_exclusive() / end_exclusive() pair. Useful to guarantee an exit from an exclusive section in large functions.
--- include/hw/core/cpu.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/hw/core/cpu.h +11 -0
@@ -1063,6 +1063,17 @@ void start_exclusive(void);*/ void end_exclusive (void ); +static inline void exclusive_unlock_guard(int *exclusive_guard G_GNUC_UNUSED) +{ +end_exclusive (); +} + +#define EXCLUSIVE_GUARD () \ + int glue(exclusive_guard, __COUNTER__) \ + G_GNUC_UNUSED \ + __attribute__((cleanup(exclusive_unlock_guard))) = \ + (start_exclusive(), 0); +/** * qemu_init_vcpu: * @cpu: The vCPU to initialize.
Signature · 1 line
2.47.1
PATCH 1/3 cpu: Set current_cpu early in qemu-user
In reply to Ilya Leoshkevichgdb_handlesig() uses current_cpu.
--- bsd-user/main.c | 2 ++ linux-user/main.c | 2 ++ linux-user/syscall.c | 1 + 3 files changed, 5 insertions(+)
bsd-user/main.c +2 -0
@@ -627,6 +627,8 @@ int main(int argc, char **argv)target_cpu_init (env, regs); + current_cpu = cpu; +if (gdbstub) {gdbserver_start (gdbstub);gdb_handlesig (cpu,0 ,NULL ,NULL ,0 );
linux-user/main.c +2 -0
@@ -1022,6 +1022,8 @@ int main(int argc, char **argv, char **envp)target_cpu_copy_regs (env, regs); + current_cpu = cpu; +if (gdbstub) {if (gdbserver_start (gdbstub) <0 ) { fprintf(stderr, "qemu: could not open gdbserver on %s\n",
linux-user/syscall.c +1 -0
@@ -6542,6 +6542,7 @@ static void *clone_func(void *arg) env = info->env; cpu =env_cpu (env); thread_cpu = cpu; + current_cpu = cpu; ts =get_task_state (cpu); info->tid =sys_gettid ();task_settid (ts);
Signature · 1 line
2.47.1
cover gdbstub: Protect gdb_handlesig() with EXCLUSIVE_GUARD()
Hi,
I ran into the issue with only one thread being stopped on a breakpoint hit [1] again [2]. While a proper solution to this includes kicking all threads using a reserved host signal and parking them, and is partially in review and partially in the works, this small series resolves most of the problems that occur during a typical debugging session. Furthermore, it is a subset of the ultimate solution and therefore would not have to be reverted.
Best regards,
Ilya
[1] https://gitlab.com/qemu-project/qemu/-/issues/2465
[2] https://lore.kernel.org/qemu-devel/[email protected]/
Ilya Leoshkevich (3):
cpu: Set current_cpu early in qemu-user
cpu: Introduce EXCLUSIVE_GUARD()
gdbstub: Protect gdb_handlesig() with EXCLUSIVE_GUARD()
bsd-user/main.c | 2 ++ gdbstub/user.c | 2 ++ include/hw/core/cpu.h | 11 +++++++++++ linux-user/main.c | 2 ++ linux-user/syscall.c | 1 + 5 files changed, 18 insertions(+)
Signature · 1 line
2.47.1
PATCH 3/3 gdbstub: Protect gdb_handlesig() with EXCLUSIVE_GUARD()
If multiple threads hit a breakpoint at the same time, GDB gets confused [1]. Prevent this situation by stopping the other threads once a thread hits a breakpoint.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=32023
--- gdbstub/user.c | 2 ++ 1 file changed, 2 insertions(+)
gdbstub/user.c +2 -0
@@ -200,6 +200,8 @@ int gdb_handlesig(CPUState *cpu, int sig, const char *reason, void *siginfo,char buf[256 ];int n; +EXCLUSIVE_GUARD (); +if (!gdbserver_state.init || gdbserver_user_state.fd <0 ) {return sig; }
Signature · 1 line
2.47.1