gdbstub: Support disablement in a multi-threaded process

The upcoming follow-fork-mode child support will require disabling
gdbstub in the parent process, which may have multiple threads (which
are represented as CPUs).

Loop over all CPUs in order to remove breakpoints and disable
single-step. Move the respective code into a separate function.

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Message-Id: <20240219141628.246823-2-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20240305121005.3528075-3-alex.bennee@linaro.org>
This commit is contained in:
Ilya Leoshkevich 2024-03-05 12:09:38 +00:00 committed by Alex Bennée
parent 13ddcf0a7a
commit 1ea96f1ded

View File

@ -356,16 +356,27 @@ int gdbserver_start(const char *port_or_path)
return -1;
}
static void disable_gdbstub(CPUState *thread_cpu)
{
CPUState *cpu;
close(gdbserver_user_state.fd);
gdbserver_user_state.fd = -1;
CPU_FOREACH(cpu) {
cpu_breakpoint_remove_all(cpu, BP_GDB);
/* no cpu_watchpoint_remove_all for user-mode */
cpu_single_step(cpu, 0);
}
tb_flush(thread_cpu);
}
/* Disable gdb stub for child processes. */
void gdbserver_fork(CPUState *cpu)
{
if (!gdbserver_state.init || gdbserver_user_state.fd < 0) {
return;
}
close(gdbserver_user_state.fd);
gdbserver_user_state.fd = -1;
cpu_breakpoint_remove_all(cpu, BP_GDB);
/* no cpu_watchpoint_remove_all for user-mode */
disable_gdbstub(cpu);
}
/*