diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h --- a/lldb/include/lldb/Host/HostInfoBase.h +++ b/lldb/include/lldb/Host/HostInfoBase.h @@ -93,7 +93,7 @@ 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 --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -35,7 +35,7 @@ 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 --- 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 @@ 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 --- 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 @@ 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 --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -297,7 +297,7 @@ } } -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 @@ return {}; return path; } + +llvm::StringRef HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) { + static llvm::StringMap g_sdk_path; + static std::mutex g_sdk_path_mutex; + + std::lock_guard 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.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -89,8 +89,6 @@ llvm::Expected 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/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1761,14 +1761,6 @@ return {}; } -llvm::StringRef PlatformDarwin::GetSDKPath(XcodeSDK sdk) { - std::lock_guard 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 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/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -208,7 +208,8 @@ } // 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 --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -53,10 +53,10 @@ #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