Move Log initialization to Log class Initialize functions and use
std::call_once to guard against multiple calls.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D8186
Files:
source/Plugins/Process/Linux/NativeProcessLinux.cpp
source/Plugins/Process/Linux/NativeProcessLinux.h
source/Plugins/Process/Linux/ProcessLinux.cpp
source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
source/Plugins/Process/POSIX/ProcessPOSIXLog.h
source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
source/lldb.cpp
tools/lldb-server/lldb-gdbserver.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -1125,27 +1125,6 @@
// Public Static Methods
// -----------------------------------------------------------------------------
-void
-NativeProcessLinux::Initialize()
-{
- static ConstString g_name("linux");
- static bool g_initialized = false;
-
- if (!g_initialized)
- {
- g_initialized = true;
-
- Log::Callbacks log_callbacks = {
- ProcessPOSIXLog::DisableLog,
- ProcessPOSIXLog::EnableLog,
- ProcessPOSIXLog::ListLogCategories
- };
-
- Log::RegisterLogChannel (g_name, log_callbacks);
- ProcessPOSIXLog::RegisterPluginName (g_name);
- }
-}
-
lldb_private::Error
NativeProcessLinux::LaunchProcess (
lldb_private::Module *exe_module,
Index: source/Plugins/Process/Linux/NativeProcessLinux.h
===================================================================
--- source/Plugins/Process/Linux/NativeProcessLinux.h
+++ source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -45,12 +45,6 @@
{
public:
- // ---------------------------------------------------------------------
- // Public Static Methods
- // ---------------------------------------------------------------------
- static void
- Initialize();
-
static lldb_private::Error
LaunchProcess (
Module *exe_module,
Index: source/Plugins/Process/Linux/ProcessLinux.cpp
===================================================================
--- source/Plugins/Process/Linux/ProcessLinux.cpp
+++ source/Plugins/Process/Linux/ProcessLinux.cpp
@@ -60,14 +60,7 @@
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(),
CreateInstance);
-
- Log::Callbacks log_callbacks = {
- ProcessPOSIXLog::DisableLog,
- ProcessPOSIXLog::EnableLog,
- ProcessPOSIXLog::ListLogCategories
- };
-
- Log::RegisterLogChannel (ProcessLinux::GetPluginNameStatic(), log_callbacks);
+ ProcessPOSIXLog::Initialize();
ProcessPOSIXLog::RegisterPluginName(GetPluginNameStatic());
}
}
Index: source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
===================================================================
--- source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
+++ source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
@@ -9,6 +9,8 @@
#include "ProcessPOSIXLog.h"
+#include <mutex>
+
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/StreamFile.h"
@@ -33,6 +35,22 @@
return g_log;
}
+void
+ProcessPOSIXLog::Initialize()
+{
+ static ConstString g_name("linux");
+ static std::once_flag g_once_flag;
+
+ std::call_once(g_once_flag, [](){
+ Log::Callbacks log_callbacks = {
+ DisableLog,
+ EnableLog,
+ ListLogCategories
+ };
+
+ Log::RegisterLogChannel (g_name, log_callbacks);
+ });
+}
Log *
ProcessPOSIXLog::GetLogIfAllCategoriesSet (uint32_t mask)
Index: source/Plugins/Process/POSIX/ProcessPOSIXLog.h
===================================================================
--- source/Plugins/Process/POSIX/ProcessPOSIXLog.h
+++ source/Plugins/Process/POSIX/ProcessPOSIXLog.h
@@ -43,6 +43,12 @@
static const char *m_pluginname;
public:
+ // ---------------------------------------------------------------------
+ // Public Static Methods
+ // ---------------------------------------------------------------------
+ static void
+ Initialize();
+
static void
RegisterPluginName(const char *pluginName)
{
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2961,14 +2961,6 @@
GetPluginDescriptionStatic(),
CreateInstance,
DebuggerInitialize);
-
- Log::Callbacks log_callbacks = {
- ProcessGDBRemoteLog::DisableLog,
- ProcessGDBRemoteLog::EnableLog,
- ProcessGDBRemoteLog::ListLogCategories
- };
-
- Log::RegisterLogChannel (ProcessGDBRemote::GetPluginNameStatic(), log_callbacks);
}
}
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
@@ -9,6 +9,8 @@
#include "ProcessGDBRemoteLog.h"
+#include <mutex>
+
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/StreamFile.h"
@@ -32,6 +34,22 @@
return g_log;
}
+void
+ProcessGDBRemoteLog::Initialize()
+{
+ static ConstString g_name("gdb-remote");
+ static std::once_flag g_once_flag;
+
+ std::call_once(g_once_flag, [](){
+ Log::Callbacks log_callbacks = {
+ DisableLog,
+ EnableLog,
+ ListLogCategories
+ };
+
+ Log::RegisterLogChannel (g_name, log_callbacks);
+ });
+}
Log *
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (uint32_t mask)
Index: source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
@@ -35,6 +35,9 @@
class ProcessGDBRemoteLog
{
public:
+ static void
+ Initialize();
+
static lldb_private::Log *
GetLogIfAllCategoriesSet(uint32_t mask = 0);
Index: source/lldb.cpp
===================================================================
--- source/lldb.cpp
+++ source/lldb.cpp
@@ -81,6 +81,7 @@
#if defined (__linux__)
#include "Plugins/Process/Linux/ProcessLinux.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#endif
#if defined (_WIN32)
@@ -95,6 +96,7 @@
#endif
#include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h"
+#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemote.h"
#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
@@ -146,8 +148,9 @@
llvm::install_fatal_error_handler(fatal_error_handler, 0);
- // Initialize plug-ins
+ ProcessGDBRemoteLog::Initialize();
+ // Initialize plug-ins
ObjectContainerBSDArchive::Initialize();
ObjectFileELF::Initialize();
SymbolVendorELF::Initialize();
@@ -186,6 +189,9 @@
PlatformDarwinKernel::Initialize();
ObjectFileMachO::Initialize();
#endif
+#if defined (__linux__)
+ ProcessPOSIXLog::Initialize();
+#endif
#ifndef LLDB_DISABLE_PYTHON
ScriptInterpreterPython::InitializePrivate();
OperatingSystemPython::Initialize();
Index: tools/lldb-server/lldb-gdbserver.cpp
===================================================================
--- tools/lldb-server/lldb-gdbserver.cpp
+++ tools/lldb-server/lldb-gdbserver.cpp
@@ -40,7 +40,6 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
-#include "Plugins/Process/Linux/NativeProcessLinux.h"
#ifndef LLGS_PROGRAM_NAME
#define LLGS_PROGRAM_NAME "lldb-server"
@@ -482,30 +481,17 @@
}
}
-static void
-initialize ()
-{
-#ifndef _WIN32
- // Setup signal handlers first thing.
- signal (SIGPIPE, signal_handler);
- signal (SIGHUP, signal_handler);
-#endif
-
-#if defined (__linux__)
- //----------------------------------------------------------------------
- // Linux hosted plugins
- //----------------------------------------------------------------------
- NativeProcessLinux::Initialize();
-#endif
-}
-
//----------------------------------------------------------------------
// main
//----------------------------------------------------------------------
int
main_gdbserver (int argc, char *argv[])
{
- initialize ();
+#ifndef _WIN32
+ // Setup signal handlers first thing.
+ signal (SIGPIPE, signal_handler);
+ signal (SIGHUP, signal_handler);
+#endif
const char *progname = argv[0];
const char *subcommand = argv[1];
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits