[Lldb-commits] [lldb] f0c08b7 - Move the Xcode SDK path caching to HostInfo
Adrian Prantl via lldb-commits
lldb-commits at lists.llvm.org
Wed May 6 13:44:05 PDT 2020
Author: Adrian Prantl
Date: 2020-05-06T13:43:50-07:00
New Revision: f0c08b7eac16cd380b0932cd8c0377f7daea2b4c
URL: https://github.com/llvm/llvm-project/commit/f0c08b7eac16cd380b0932cd8c0377f7daea2b4c
DIFF: https://github.com/llvm/llvm-project/commit/f0c08b7eac16cd380b0932cd8c0377f7daea2b4c.diff
LOG: Move the Xcode SDK path caching to HostInfo
When debugging a remote platform, the platform you get from
GetPlatformForArchitecture doesn't inherit from PlatformDarwin.
HostInfoMacOSX seems like the right place to have a global store of
local paths.
Differential Revision: https://reviews.llvm.org/D79364
Added:
Modified:
lldb/include/lldb/Host/HostInfoBase.h
lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
lldb/include/lldb/Target/Platform.h
lldb/source/Core/Module.cpp
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
lldb/unittests/Host/HostInfoTest.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h
index f195a9a1f021..dbd11505c21b 100644
--- a/lldb/include/lldb/Host/HostInfoBase.h
+++ b/lldb/include/lldb/Host/HostInfoBase.h
@@ -93,7 +93,7 @@ class HostInfoBase {
llvm::StringRef dir);
/// Return the directory containing a specific Xcode SDK.
- static std::string GetXcodeSDK(XcodeSDK sdk) { return {}; }
+ static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk) { return {}; }
protected:
static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
diff --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
index fdbe869ea475..dacb8c40f0fb 100644
--- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
+++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
@@ -35,7 +35,7 @@ class HostInfoMacOSX : public HostInfoPosix {
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
/// Query xcrun to find an Xcode SDK directory.
- static std::string GetXcodeSDK(XcodeSDK sdk);
+ static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk);
protected:
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 1b130cd02c3d..190ad0653073 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -26,7 +26,6 @@
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/Timeout.h"
#include "lldb/Utility/UserIDResolver.h"
-#include "lldb/Utility/XcodeSDK.h"
#include "lldb/lldb-private-forward.h"
#include "lldb/lldb-public.h"
#include "llvm/Support/VersionTuple.h"
@@ -435,8 +434,6 @@ class Platform : public PluginInterface {
return lldb_private::ConstString();
}
- virtual llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) { return {}; }
-
const std::string &GetRemoteURL() const { return m_remote_url; }
bool IsHost() const {
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index e5fb86ee252b..ed69796d88c2 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -18,6 +18,7 @@
#include "lldb/Core/Section.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Symbol/CompileUnit.h"
@@ -33,7 +34,6 @@
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Target/Language.h"
-#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataBufferHeap.h"
@@ -1598,12 +1598,10 @@ bool Module::RemapSourceFile(llvm::StringRef path,
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {
XcodeSDK sdk(sdk_name.str());
- PlatformSP module_platform =
- Platform::GetPlatformForArchitecture(GetArchitecture(), nullptr);
- ConstString sdk_path(module_platform->GetSDKPath(sdk));
+ ConstString sdk_path(HostInfo::GetXcodeSDKPath(sdk));
if (!sdk_path)
return;
- // If merged SDK changed for a previously registered source path, update it.
+ // If the SDK changed for a previously registered source path, update it.
// This could happend with -fdebug-prefix-map, otherwise it's unlikely.
ConstString sysroot_cs(sysroot);
if (!m_source_mappings.Replace(sysroot_cs, sdk_path, true))
diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index e495c752cb19..79ccc5277d2e 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -297,7 +297,7 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
}
}
-std::string HostInfoMacOSX::GetXcodeSDK(XcodeSDK sdk) {
+static std::string GetXcodeSDK(XcodeSDK sdk) {
XcodeSDK::Info info = sdk.Parse();
std::string sdk_name = XcodeSDK::GetCanonicalName(info);
auto find_sdk = [](std::string sdk_name) -> std::string {
@@ -361,3 +361,14 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
return {};
return path;
}
+
+llvm::StringRef HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) {
+ static llvm::StringMap<std::string> g_sdk_path;
+ static std::mutex g_sdk_path_mutex;
+
+ std::lock_guard<std::mutex> guard(g_sdk_path_mutex);
+ std::string &path = g_sdk_path[sdk.GetString()];
+ if (path.empty())
+ path = GetXcodeSDK(sdk);
+ return path;
+}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 436f93d9d8d6..635dd1f05971 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1761,14 +1761,6 @@ PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
return {};
}
-llvm::StringRef PlatformDarwin::GetSDKPath(XcodeSDK sdk) {
- std::lock_guard<std::mutex> guard(m_sdk_path_mutex);
- std::string &path = m_sdk_path[sdk.GetString()];
- if (path.empty())
- path = HostInfo::GetXcodeSDK(sdk);
- return path;
-}
-
FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
static FileSpec g_xcode_contents_path;
static std::once_flag g_once_flag;
@@ -1797,7 +1789,7 @@ FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
}
}
- FileSpec fspec(HostInfo::GetXcodeSDK(XcodeSDK::GetAnyMacOS()));
+ FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()));
if (fspec) {
if (FileSystem::Instance().Exists(fspec)) {
std::string xcode_contents_dir =
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 0252b093d6be..a197cb3cc8ff 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -89,8 +89,6 @@ class PlatformDarwin : public PlatformPOSIX {
llvm::Expected<lldb_private::StructuredData::DictionarySP>
FetchExtendedCrashInformation(lldb_private::Process &process) override;
- llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) override;
-
static lldb_private::FileSpec GetXcodeContentsDirectory();
static lldb_private::FileSpec GetXcodeDeveloperDirectory();
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index 4fcecf776bd2..84bc85e53c3b 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -208,7 +208,8 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
}
// Use the default SDK as a fallback.
- FileSpec fspec(HostInfo::GetXcodeSDK(lldb_private::XcodeSDK::GetAnyMacOS()));
+ FileSpec fspec(
+ HostInfo::GetXcodeSDKPath(lldb_private::XcodeSDK::GetAnyMacOS()));
if (fspec) {
if (FileSystem::Instance().Exists(fspec))
return ConstString(fspec.GetPath());
diff --git a/lldb/unittests/Host/HostInfoTest.cpp b/lldb/unittests/Host/HostInfoTest.cpp
index d854426e4898..96d47d75794a 100644
--- a/lldb/unittests/Host/HostInfoTest.cpp
+++ b/lldb/unittests/Host/HostInfoTest.cpp
@@ -53,10 +53,10 @@ TEST_F(HostInfoTest, GetHostname) {
#if defined(__APPLE__)
TEST_F(HostInfoTest, GetXcodeSDK) {
- EXPECT_FALSE(HostInfo::GetXcodeSDK(XcodeSDK("MacOSX.sdk")).empty());
+ EXPECT_FALSE(HostInfo::GetXcodeSDKPath(XcodeSDK("MacOSX.sdk")).empty());
// These are expected to fall back to an available version.
- EXPECT_FALSE(HostInfo::GetXcodeSDK(XcodeSDK("MacOSX9999.sdk")).empty());
+ EXPECT_FALSE(HostInfo::GetXcodeSDKPath(XcodeSDK("MacOSX9999.sdk")).empty());
// This is expected to fail.
- EXPECT_TRUE(HostInfo::GetXcodeSDK(XcodeSDK("CeciNestPasUnOS.sdk")).empty());
+ EXPECT_TRUE(HostInfo::GetXcodeSDKPath(XcodeSDK("CeciNestPasUnOS.sdk")).empty());
}
#endif
More information about the lldb-commits
mailing list