Skip to content

Commit

Permalink
gdbstub: Support disablement in a multi-threaded process
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Ilya Leoshkevich <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Alex Bennée <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
iii-i authored and stsquad committed Mar 6, 2024
1 parent 13ddcf0 commit 1ea96f1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions gdbstub/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down

0 comments on commit 1ea96f1

Please sign in to comment.