Skip to content

Commit f0c08b7

Browse files
committed
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
1 parent e557801 commit f0c08b7

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

lldb/include/lldb/Host/HostInfoBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class HostInfoBase {
9393
llvm::StringRef dir);
9494

9595
/// Return the directory containing a specific Xcode SDK.
96-
static std::string GetXcodeSDK(XcodeSDK sdk) { return {}; }
96+
static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk) { return {}; }
9797

9898
protected:
9999
static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);

lldb/include/lldb/Host/macosx/HostInfoMacOSX.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class HostInfoMacOSX : public HostInfoPosix {
3535
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
3636

3737
/// Query xcrun to find an Xcode SDK directory.
38-
static std::string GetXcodeSDK(XcodeSDK sdk);
38+
static llvm::StringRef GetXcodeSDKPath(XcodeSDK sdk);
3939
protected:
4040
static bool ComputeSupportExeDirectory(FileSpec &file_spec);
4141
static void ComputeHostArchitectureSupport(ArchSpec &arch_32,

lldb/include/lldb/Target/Platform.h

-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "lldb/Utility/StructuredData.h"
2727
#include "lldb/Utility/Timeout.h"
2828
#include "lldb/Utility/UserIDResolver.h"
29-
#include "lldb/Utility/XcodeSDK.h"
3029
#include "lldb/lldb-private-forward.h"
3130
#include "lldb/lldb-public.h"
3231
#include "llvm/Support/VersionTuple.h"
@@ -435,8 +434,6 @@ class Platform : public PluginInterface {
435434
return lldb_private::ConstString();
436435
}
437436

438-
virtual llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) { return {}; }
439-
440437
const std::string &GetRemoteURL() const { return m_remote_url; }
441438

442439
bool IsHost() const {

lldb/source/Core/Module.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Core/Section.h"
1919
#include "lldb/Host/FileSystem.h"
2020
#include "lldb/Host/Host.h"
21+
#include "lldb/Host/HostInfo.h"
2122
#include "lldb/Interpreter/CommandInterpreter.h"
2223
#include "lldb/Interpreter/ScriptInterpreter.h"
2324
#include "lldb/Symbol/CompileUnit.h"
@@ -33,7 +34,6 @@
3334
#include "lldb/Symbol/TypeMap.h"
3435
#include "lldb/Symbol/TypeSystem.h"
3536
#include "lldb/Target/Language.h"
36-
#include "lldb/Target/Platform.h"
3737
#include "lldb/Target/Process.h"
3838
#include "lldb/Target/Target.h"
3939
#include "lldb/Utility/DataBufferHeap.h"
@@ -1598,12 +1598,10 @@ bool Module::RemapSourceFile(llvm::StringRef path,
15981598

15991599
void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) {
16001600
XcodeSDK sdk(sdk_name.str());
1601-
PlatformSP module_platform =
1602-
Platform::GetPlatformForArchitecture(GetArchitecture(), nullptr);
1603-
ConstString sdk_path(module_platform->GetSDKPath(sdk));
1601+
ConstString sdk_path(HostInfo::GetXcodeSDKPath(sdk));
16041602
if (!sdk_path)
16051603
return;
1606-
// If merged SDK changed for a previously registered source path, update it.
1604+
// If the SDK changed for a previously registered source path, update it.
16071605
// This could happend with -fdebug-prefix-map, otherwise it's unlikely.
16081606
ConstString sysroot_cs(sysroot);
16091607
if (!m_source_mappings.Replace(sysroot_cs, sdk_path, true))

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

+12-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
297297
}
298298
}
299299

300-
std::string HostInfoMacOSX::GetXcodeSDK(XcodeSDK sdk) {
300+
static std::string GetXcodeSDK(XcodeSDK sdk) {
301301
XcodeSDK::Info info = sdk.Parse();
302302
std::string sdk_name = XcodeSDK::GetCanonicalName(info);
303303
auto find_sdk = [](std::string sdk_name) -> std::string {
@@ -361,3 +361,14 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
361361
return {};
362362
return path;
363363
}
364+
365+
llvm::StringRef HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) {
366+
static llvm::StringMap<std::string> g_sdk_path;
367+
static std::mutex g_sdk_path_mutex;
368+
369+
std::lock_guard<std::mutex> guard(g_sdk_path_mutex);
370+
std::string &path = g_sdk_path[sdk.GetString()];
371+
if (path.empty())
372+
path = GetXcodeSDK(sdk);
373+
return path;
374+
}

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -1761,14 +1761,6 @@ PlatformDarwin::FindXcodeContentsDirectoryInPath(llvm::StringRef path) {
17611761
return {};
17621762
}
17631763

1764-
llvm::StringRef PlatformDarwin::GetSDKPath(XcodeSDK sdk) {
1765-
std::lock_guard<std::mutex> guard(m_sdk_path_mutex);
1766-
std::string &path = m_sdk_path[sdk.GetString()];
1767-
if (path.empty())
1768-
path = HostInfo::GetXcodeSDK(sdk);
1769-
return path;
1770-
}
1771-
17721764
FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
17731765
static FileSpec g_xcode_contents_path;
17741766
static std::once_flag g_once_flag;
@@ -1797,7 +1789,7 @@ FileSpec PlatformDarwin::GetXcodeContentsDirectory() {
17971789
}
17981790
}
17991791

1800-
FileSpec fspec(HostInfo::GetXcodeSDK(XcodeSDK::GetAnyMacOS()));
1792+
FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()));
18011793
if (fspec) {
18021794
if (FileSystem::Instance().Exists(fspec)) {
18031795
std::string xcode_contents_dir =

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class PlatformDarwin : public PlatformPOSIX {
8989
llvm::Expected<lldb_private::StructuredData::DictionarySP>
9090
FetchExtendedCrashInformation(lldb_private::Process &process) override;
9191

92-
llvm::StringRef GetSDKPath(lldb_private::XcodeSDK sdk) override;
93-
9492
static lldb_private::FileSpec GetXcodeContentsDirectory();
9593
static lldb_private::FileSpec GetXcodeDeveloperDirectory();
9694

lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
208208
}
209209

210210
// Use the default SDK as a fallback.
211-
FileSpec fspec(HostInfo::GetXcodeSDK(lldb_private::XcodeSDK::GetAnyMacOS()));
211+
FileSpec fspec(
212+
HostInfo::GetXcodeSDKPath(lldb_private::XcodeSDK::GetAnyMacOS()));
212213
if (fspec) {
213214
if (FileSystem::Instance().Exists(fspec))
214215
return ConstString(fspec.GetPath());

lldb/unittests/Host/HostInfoTest.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ TEST_F(HostInfoTest, GetHostname) {
5353

5454
#if defined(__APPLE__)
5555
TEST_F(HostInfoTest, GetXcodeSDK) {
56-
EXPECT_FALSE(HostInfo::GetXcodeSDK(XcodeSDK("MacOSX.sdk")).empty());
56+
EXPECT_FALSE(HostInfo::GetXcodeSDKPath(XcodeSDK("MacOSX.sdk")).empty());
5757
// These are expected to fall back to an available version.
58-
EXPECT_FALSE(HostInfo::GetXcodeSDK(XcodeSDK("MacOSX9999.sdk")).empty());
58+
EXPECT_FALSE(HostInfo::GetXcodeSDKPath(XcodeSDK("MacOSX9999.sdk")).empty());
5959
// This is expected to fail.
60-
EXPECT_TRUE(HostInfo::GetXcodeSDK(XcodeSDK("CeciNestPasUnOS.sdk")).empty());
60+
EXPECT_TRUE(HostInfo::GetXcodeSDKPath(XcodeSDK("CeciNestPasUnOS.sdk")).empty());
6161
}
6262
#endif

0 commit comments

Comments
 (0)