Index: lldb/trunk/include/lldb/Utility/Log.h =================================================================== --- lldb/trunk/include/lldb/Utility/Log.h +++ lldb/trunk/include/lldb/Utility/Log.h @@ -96,6 +96,9 @@ } }; + + static void Initialize(); + //------------------------------------------------------------------ // Static accessors for logging channels //------------------------------------------------------------------ @@ -193,6 +196,9 @@ static uint32_t GetFlags(llvm::raw_ostream &stream, const ChannelMap::value_type &entry, llvm::ArrayRef categories); + static void LockAllChannels(); + static void UnlockAllChannels(); + Log(const Log &) = delete; void operator=(const Log &) = delete; }; Index: lldb/trunk/include/lldb/Utility/Logging.h =================================================================== --- lldb/trunk/include/lldb/Utility/Logging.h +++ lldb/trunk/include/lldb/Utility/Logging.h @@ -62,7 +62,7 @@ Log *GetLogIfAnyCategoriesSet(uint32_t mask); -void InitializeLog(); +void InitializeLldbChannel(); } // namespace lldb_private Index: lldb/trunk/source/Initialization/SystemInitializerCommon.cpp =================================================================== --- lldb/trunk/source/Initialization/SystemInitializerCommon.cpp +++ lldb/trunk/source/Initialization/SystemInitializerCommon.cpp @@ -70,7 +70,7 @@ #endif llvm::EnablePrettyStackTrace(); - InitializeLog(); + Log::Initialize(); HostInfo::Initialize(); static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); Index: lldb/trunk/source/Utility/Log.cpp =================================================================== --- lldb/trunk/source/Utility/Log.cpp +++ lldb/trunk/source/Utility/Log.cpp @@ -32,6 +32,7 @@ #include // for getpid #else #include +#include #endif using namespace lldb_private; @@ -181,6 +182,13 @@ Printf("warning: %s", Content.c_str()); } +void Log::Initialize() { +#ifdef LLVM_ON_UNIX + pthread_atfork(&Log::LockAllChannels, &Log::UnlockAllChannels, &Log::UnlockAllChannels); +#endif + InitializeLldbChannel(); +} + void Log::Register(llvm::StringRef name, Channel &channel) { auto iter = g_channel_map->try_emplace(name, channel); assert(iter.second == true); @@ -321,3 +329,13 @@ message << payload << "\n"; WriteMessage(message.str()); } + +void Log::LockAllChannels() { + for (auto &c: *g_channel_map) + c.second.m_mutex.lock(); +} + +void Log::UnlockAllChannels() { + for (auto &c: *g_channel_map) + c.second.m_mutex.unlock(); +} Index: lldb/trunk/source/Utility/Logging.cpp =================================================================== --- lldb/trunk/source/Utility/Logging.cpp +++ lldb/trunk/source/Utility/Logging.cpp @@ -51,7 +51,7 @@ static Log::Channel g_log_channel(g_categories, LIBLLDB_LOG_DEFAULT); -void lldb_private::InitializeLog() { +void lldb_private::InitializeLldbChannel() { Log::Register("lldb", g_log_channel); }