Skip to content

Commit

Permalink
[lldb] Fixed lldb-server crash (TestLogHandler was not thread safe) (l…
Browse files Browse the repository at this point in the history
…lvm#101326)

Host::LaunchProcess() requires to SetMonitorProcessCallback. This
callback is called from the child process monitor thread. We cannot
control this thread anyway. lldb-server may crash if there is a logging
around this callback because TestLogHandler is not thread safe. I faced
this issue debugging 100 simultaneous child processes. Note
StreamLogHandler::Emit() in lldb/source/Utility/Log.cpp already contains
the similar mutex.
  • Loading branch information
slydiman authored and clementval committed Jul 31, 2024
1 parent 846f7c2 commit 576060b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lldb/tools/lldb-server/LLDBServerUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class TestLogHandler : public LogHandler {
: m_stream_sp(stream_sp) {}

void Emit(llvm::StringRef message) override {
std::lock_guard<std::mutex> guard(m_mutex);
(*m_stream_sp) << message;
m_stream_sp->flush();
}

private:
std::mutex m_mutex;
std::shared_ptr<raw_ostream> m_stream_sp;
};

Expand Down

0 comments on commit 576060b

Please sign in to comment.