Fix gdb.interrupt race

gdb.interrupt was introduced to implement DAP request cancellation.
However, because it can be run from another thread, and because I
didn't look deeply enough at the implementation, it turns out to be
racy.

The fix here is to lock accesses to certain globals in extension.c.

Note that this won't work in the case where configure detects that the
C++ compiler doesn't provide thread support.  This version of the
patch disables DAP entirely in this situation.

Regression tested on x86-64 Fedora 38.  I also ran gdb.dap/pause.exp
in a thread-sanitizer build tree to make sure the reported race is
gone.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31263
This commit is contained in:
Tom Tromey
2024-02-23 08:59:40 -07:00
parent 4b72a278f4
commit 8bb8f83467
2 changed files with 43 additions and 0 deletions

View File

@@ -92,10 +92,14 @@ call_dap_fn (const char *fn_name)
void
dap_interp::init (bool top_level)
{
#if CXX_STD_THREAD
call_dap_fn ("run");
current_ui->input_fd = -1;
current_ui->m_input_interactive_p = false;
#else
error (_("GDB was compiled without threading, which DAP requires"));
#endif
}
void