aprantl created this revision.
aprantl added reviewers: friss, JDevlieghere.
Herald added a subscriber: fedor.sergeev.
aprantl added a parent revision: D79273: Add an explicit API to read the Xcode
SDK DWARF attribute from compile units.
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.
https://reviews.llvm.org/D79364
Files:
lldb/include/lldb/Host/HostInfoBase.h
lldb/include/lldb/Host/macosx/HostInfoMacOSX.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/PlatformMacOSX.cpp
lldb/unittests/Host/HostInfoTest.cpp
Index: lldb/unittests/Host/HostInfoTest.cpp
===================================================================
--- lldb/unittests/Host/HostInfoTest.cpp
+++ 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
Index: lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ 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());
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===================================================================
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1762,11 +1762,7 @@
}
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;
+ return HostInfo::GetXcodeSDKPath(sdk);
}
FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
@@ -1797,7 +1793,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 =
Index: lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
===================================================================
--- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ 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<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;
+}
Index: lldb/source/Core/Module.cpp
===================================================================
--- lldb/source/Core/Module.cpp
+++ lldb/source/Core/Module.cpp
@@ -1598,9 +1598,7 @@
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(Platform::GetHostPlatform()->GetSDKPath(sdk));
if (!sdk_path)
return;
// If merged SDK changed for a previously registered source path, update it.
Index: lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
===================================================================
--- lldb/include/lldb/Host/macosx/HostInfoMacOSX.h
+++ 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,
Index: lldb/include/lldb/Host/HostInfoBase.h
===================================================================
--- lldb/include/lldb/Host/HostInfoBase.h
+++ 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);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits