[Lldb-commits] [lldb] r216197 - Convert static constructors to be explicitly initialized at startup
Zachary Turner
zturner at google.com
Thu Aug 21 10:57:03 PDT 2014
Author: zturner
Date: Thu Aug 21 12:57:03 2014
New Revision: 216197
URL: http://llvm.org/viewvc/llvm-project?rev=216197&view=rev
Log:
Convert static constructors to be explicitly initialized at startup
Modified:
lldb/trunk/include/lldb/Host/HostInfoBase.h
lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h
lldb/trunk/source/Host/common/HostInfoBase.cpp
lldb/trunk/source/Host/linux/HostInfoLinux.cpp
lldb/trunk/source/lldb.cpp
Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=216197&r1=216196&r2=216197&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostInfoBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostInfoBase.h Thu Aug 21 12:57:03 2014
@@ -33,6 +33,8 @@ class HostInfoBase
~HostInfoBase() {}
public:
+ static void Initialize();
+
//------------------------------------------------------------------
/// Returns the number of CPUs on this current host.
///
@@ -111,22 +113,6 @@ class HostInfoBase
static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64);
-
- static uint32_t m_number_cpus;
- static std::string m_vendor_string;
- static std::string m_os_string;
- static std::string m_host_triple;
-
- static ArchSpec m_host_arch_32;
- static ArchSpec m_host_arch_64;
-
- static FileSpec m_lldb_so_dir;
- static FileSpec m_lldb_support_exe_dir;
- static FileSpec m_lldb_headers_dir;
- static FileSpec m_lldb_python_dir;
- static FileSpec m_lldb_system_plugin_dir;
- static FileSpec m_lldb_user_plugin_dir;
- static FileSpec m_lldb_tmp_dir;
};
}
Modified: lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h?rev=216197&r1=216196&r2=216197&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h (original)
+++ lldb/trunk/include/lldb/Host/linux/HostInfoLinux.h Thu Aug 21 12:57:03 2014
@@ -28,6 +28,8 @@ class HostInfoLinux : public HostInfoPos
~HostInfoLinux();
public:
+ static void Initialize();
+
static bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update);
static llvm::StringRef GetDistributionId();
@@ -35,11 +37,6 @@ class HostInfoLinux : public HostInfoPos
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64);
-
- static std::string m_distribution_id;
- static uint32_t m_os_major;
- static uint32_t m_os_minor;
- static uint32_t m_os_update;
};
}
Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=216197&r1=216196&r2=216197&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Thu Aug 21 12:57:03 2014
@@ -39,6 +39,27 @@ CleanupProcessSpecificLLDBTempDir()
// true to all files that were created for the LLDB process can be cleaned up.
FileSystem::DeleteDirectory(tmpdir_file_spec.GetDirectory().GetCString(), true);
}
+
+struct HostInfoBaseFields
+{
+ uint32_t m_number_cpus;
+ std::string m_vendor_string;
+ std::string m_os_string;
+ std::string m_host_triple;
+
+ ArchSpec m_host_arch_32;
+ ArchSpec m_host_arch_64;
+
+ FileSpec m_lldb_so_dir;
+ FileSpec m_lldb_support_exe_dir;
+ FileSpec m_lldb_headers_dir;
+ FileSpec m_lldb_python_dir;
+ FileSpec m_lldb_system_plugin_dir;
+ FileSpec m_lldb_user_plugin_dir;
+ FileSpec m_lldb_tmp_dir;
+};
+
+HostInfoBaseFields *g_fields = nullptr;
}
#define COMPUTE_LLDB_PATH(compute_function, member_var) \
@@ -54,20 +75,11 @@ CleanupProcessSpecificLLDBTempDir()
result = &member_var; \
}
-uint32_t HostInfoBase::m_number_cpus = 0;
-std::string HostInfoBase::m_vendor_string;
-std::string HostInfoBase::m_os_string;
-std::string HostInfoBase::m_host_triple;
-ArchSpec HostInfoBase::m_host_arch_32;
-ArchSpec HostInfoBase::m_host_arch_64;
-
-FileSpec HostInfoBase::m_lldb_so_dir;
-FileSpec HostInfoBase::m_lldb_support_exe_dir;
-FileSpec HostInfoBase::m_lldb_headers_dir;
-FileSpec HostInfoBase::m_lldb_python_dir;
-FileSpec HostInfoBase::m_lldb_system_plugin_dir;
-FileSpec HostInfoBase::m_lldb_user_plugin_dir;
-FileSpec HostInfoBase::m_lldb_tmp_dir;
+void
+HostInfoBase::Initialize()
+{
+ g_fields = new HostInfoBaseFields();
+}
uint32_t
HostInfoBase::GetNumberCPUS()
@@ -75,11 +87,11 @@ HostInfoBase::GetNumberCPUS()
static bool is_initialized = false;
if (!is_initialized)
{
- m_number_cpus = std::thread::hardware_concurrency();
+ g_fields->m_number_cpus = std::thread::hardware_concurrency();
is_initialized = true;
}
- return m_number_cpus;
+ return g_fields->m_number_cpus;
}
llvm::StringRef
@@ -90,10 +102,10 @@ HostInfoBase::GetVendorString()
{
const ArchSpec &host_arch = HostInfo::GetArchitecture();
const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName();
- m_vendor_string.assign(str_ref.begin(), str_ref.end());
+ g_fields->m_vendor_string.assign(str_ref.begin(), str_ref.end());
is_initialized = true;
}
- return m_vendor_string;
+ return g_fields->m_vendor_string;
}
llvm::StringRef
@@ -104,10 +116,10 @@ HostInfoBase::GetOSString()
{
const ArchSpec &host_arch = HostInfo::GetArchitecture();
const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName();
- m_os_string.assign(str_ref.begin(), str_ref.end());
+ g_fields->m_os_string.assign(str_ref.begin(), str_ref.end());
is_initialized = true;
}
- return m_os_string;
+ return g_fields->m_os_string;
}
llvm::StringRef
@@ -117,10 +129,10 @@ HostInfoBase::GetTargetTriple()
if (!is_initialized)
{
const ArchSpec &host_arch = HostInfo::GetArchitecture();
- m_host_triple = host_arch.GetTriple().getTriple();
+ g_fields->m_host_triple = host_arch.GetTriple().getTriple();
is_initialized = true;
}
- return m_host_triple;
+ return g_fields->m_host_triple;
}
const ArchSpec &
@@ -129,18 +141,18 @@ HostInfoBase::GetArchitecture(Architectu
static bool is_initialized = false;
if (!is_initialized)
{
- HostInfo::ComputeHostArchitectureSupport(m_host_arch_32, m_host_arch_64);
+ HostInfo::ComputeHostArchitectureSupport(g_fields->m_host_arch_32, g_fields->m_host_arch_64);
is_initialized = true;
}
// If an explicit 32 or 64-bit architecture was requested, return that.
if (arch_kind == eArchKind32)
- return m_host_arch_32;
+ return g_fields->m_host_arch_32;
if (arch_kind == eArchKind64)
- return m_host_arch_64;
+ return g_fields->m_host_arch_64;
// Otherwise prefer the 64-bit architecture if it is valid.
- return (m_host_arch_64.IsValid()) ? m_host_arch_64 : m_host_arch_32;
+ return (g_fields->m_host_arch_64.IsValid()) ? g_fields->m_host_arch_64 : g_fields->m_host_arch_32;
}
bool
@@ -158,39 +170,42 @@ HostInfoBase::GetLLDBPath(lldb::PathType
switch (type)
{
case lldb::ePathTypeLLDBShlibDir:
- COMPUTE_LLDB_PATH(ComputeSharedLibraryDirectory, m_lldb_so_dir)
+ COMPUTE_LLDB_PATH(ComputeSharedLibraryDirectory, g_fields->m_lldb_so_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBShlibDir) => '%s'", m_lldb_so_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBShlibDir) => '%s'", g_fields->m_lldb_so_dir.GetPath().c_str());
break;
case lldb::ePathTypeSupportExecutableDir:
- COMPUTE_LLDB_PATH(ComputeSupportExeDirectory, m_lldb_support_exe_dir)
+ COMPUTE_LLDB_PATH(ComputeSupportExeDirectory, g_fields->m_lldb_support_exe_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypeSupportExecutableDir) => '%s'", m_lldb_support_exe_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypeSupportExecutableDir) => '%s'",
+ g_fields->m_lldb_support_exe_dir.GetPath().c_str());
break;
case lldb::ePathTypeHeaderDir:
- COMPUTE_LLDB_PATH(ComputeHeaderDirectory, m_lldb_headers_dir)
+ COMPUTE_LLDB_PATH(ComputeHeaderDirectory, g_fields->m_lldb_headers_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypeHeaderDir) => '%s'", m_lldb_headers_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypeHeaderDir) => '%s'", g_fields->m_lldb_headers_dir.GetPath().c_str());
break;
case lldb::ePathTypePythonDir:
- COMPUTE_LLDB_PATH(ComputePythonDirectory, m_lldb_python_dir)
+ COMPUTE_LLDB_PATH(ComputePythonDirectory, g_fields->m_lldb_python_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypePythonDir) => '%s'", m_lldb_python_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypePythonDir) => '%s'", g_fields->m_lldb_python_dir.GetPath().c_str());
break;
case lldb::ePathTypeLLDBSystemPlugins:
- COMPUTE_LLDB_PATH(ComputeSystemPluginsDirectory, m_lldb_system_plugin_dir)
+ COMPUTE_LLDB_PATH(ComputeSystemPluginsDirectory, g_fields->m_lldb_system_plugin_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBSystemPlugins) => '%s'", m_lldb_system_plugin_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBSystemPlugins) => '%s'",
+ g_fields->m_lldb_system_plugin_dir.GetPath().c_str());
break;
case lldb::ePathTypeLLDBUserPlugins:
- COMPUTE_LLDB_PATH(ComputeUserPluginsDirectory, m_lldb_user_plugin_dir)
+ COMPUTE_LLDB_PATH(ComputeUserPluginsDirectory, g_fields->m_lldb_user_plugin_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBUserPlugins) => '%s'", m_lldb_user_plugin_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBUserPlugins) => '%s'",
+ g_fields->m_lldb_user_plugin_dir.GetPath().c_str());
break;
case lldb::ePathTypeLLDBTempSystemDir:
- COMPUTE_LLDB_PATH(ComputeTempFileDirectory, m_lldb_tmp_dir)
+ COMPUTE_LLDB_PATH(ComputeTempFileDirectory, g_fields->m_lldb_tmp_dir)
if (log)
- log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'", m_lldb_tmp_dir.GetPath().c_str());
+ log->Printf("HostInfoBase::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'", g_fields->m_lldb_tmp_dir.GetPath().c_str());
break;
}
Modified: lldb/trunk/source/Host/linux/HostInfoLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/HostInfoLinux.cpp?rev=216197&r1=216196&r2=216197&view=diff
==============================================================================
--- lldb/trunk/source/Host/linux/HostInfoLinux.cpp (original)
+++ lldb/trunk/source/Host/linux/HostInfoLinux.cpp Thu Aug 21 12:57:03 2014
@@ -18,10 +18,33 @@
using namespace lldb_private;
-std::string HostInfoLinux::m_distribution_id;
-uint32_t HostInfoLinux::m_os_major = 0;
-uint32_t HostInfoLinux::m_os_minor = 0;
-uint32_t HostInfoLinux::m_os_update = 0;
+namespace
+{
+struct HostInfoLinuxFields
+{
+ HostInfoLinuxFields()
+ : m_os_major(0)
+ , m_os_minor(0)
+ , m_os_update(0)
+ {
+ }
+
+ std::string m_distribution_id;
+ uint32_t m_os_major;
+ uint32_t m_os_minor;
+ uint32_t m_os_update;
+};
+
+HostInfoLinuxFields *g_fields = nullptr;
+}
+
+void
+HostInfoLinux::Initialize()
+{
+ HostInfoPosix::Initialize();
+
+ g_fields = new HostInfoLinuxFields();
+}
bool
HostInfoLinux::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update)
@@ -37,7 +60,7 @@ HostInfoLinux::GetOSVersion(uint32_t &ma
if (uname(&un))
goto finished;
- int status = sscanf(un.release, "%u.%u.%u", &major, &minor, &update);
+ int status = sscanf(un.release, "%u.%u.%u", &g_fields->m_os_major, &g_fields->m_os_minor, &g_fields->m_os_update);
if (status == 3)
{
success = true;
@@ -46,15 +69,15 @@ HostInfoLinux::GetOSVersion(uint32_t &ma
// Some kernels omit the update version, so try looking for just "X.Y" and
// set update to 0.
- update = 0;
- status = sscanf(un.release, "%u.%u", &major, &minor);
+ g_fields->m_os_update = 0;
+ status = sscanf(un.release, "%u.%u", &g_fields->m_os_major, &g_fields->m_os_minor);
success = !!(status == 2);
}
finished:
- major = m_os_major;
- minor = m_os_minor;
- update = m_os_update;
+ major = g_fields->m_os_major;
+ minor = g_fields->m_os_minor;
+ update = g_fields->m_os_update;
return success;
}
@@ -122,9 +145,9 @@ HostInfoLinux::GetDistributionId()
return tolower(isspace(ch) ? '_' : ch);
});
- m_distribution_id = id_string;
+ g_fields->m_distribution_id = id_string;
if (log)
- log->Printf("distribution id set to \"%s\"", m_distribution_id.c_str());
+ log->Printf("distribution id set to \"%s\"", g_fields->m_distribution_id.c_str());
}
else
{
@@ -145,7 +168,7 @@ HostInfoLinux::GetDistributionId()
}
}
- return m_distribution_id.c_str();
+ return g_fields->m_distribution_id.c_str();
}
bool
Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=216197&r1=216196&r2=216197&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Thu Aug 21 12:57:03 2014
@@ -18,6 +18,7 @@
#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Timer.h"
#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Interpreter/ScriptInterpreterPython.h"
#include "lldb/Target/Target.h"
@@ -106,6 +107,7 @@ lldb_private::Initialize ()
{
g_inited = true;
Log::Initialize();
+ HostInfo::Initialize();
Timer::Initialize ();
Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
More information about the lldb-commits
mailing list