Commit
04de24e690d3ff23bf63bc3901765cd8f07723f3
by Jonas Devlieghere[lldb/IOHandler] Improve synchronization between IO handlers.
The way the IO handlers are currently managed by the debugger is wrong.
The implementation lacks proper synchronization between RunIOHandlerSync
and RunIOHandlers. The latter is meant to be run by the "main thread",
while the former is meant to be run synchronously, potentially from a
different thread.
Imagine a scenario where RunIOHandlerSync is called from a different
thread than RunIOHandlers. Both functions manipulate the debugger's
IOHandlerStack. Although the push and pop operations are synchronized,
the logic to activate, deactivate and run IO handlers is not.
While investigating PR44352, I noticed some weird behavior in the
Editline implementation. One of its members (m_editor_status) was
modified from another thread. This happened because the main thread,
while running RunIOHandlers ended up execution the IOHandlerEditline
created by the breakpoint callback thread. Even worse, due to the lack
of synchronization within the IO handler implementation, both threads
ended up executing the same IO handler.
Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit
file.
I've added a (recursive) mutex to prevent another thread from messing
with the IO handlers wile another thread is running one synchronously.
It has to be recursive, because we might have to source another file
when encountering a command source in the original file.
Differential revision: https://reviews.llvm.org/D72748