Skip to content

Commit 56885e7

Browse files
committed
Find SDK path more lazily in Apple Simulator platforms
In https://reviews.llvm.org/D122373 I delayed the search for the SDK filepath until the simulator platform is Created. In the qProcessInfo binary-addresses key, I have to force-Create every platform to find one that can handle a kernel fileset; this forced all of the simulator platforms to create, taking the SDK filepath discovery perf hit. This patch delays that path search further until the Apple Simulator platform calls a method that actually needs the full filepath; it saves the SDK name ("WatchSimulator.sdk" etc) until it needs to expand it. Differential Revision: https://reviews.llvm.org/D143932 rdar://103380717 (cherry picked from commit ee88f11)
1 parent 86068dd commit 56885e7

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ PlatformAppleSimulator::PlatformAppleSimulator(
4141
const char *class_name, const char *description, ConstString plugin_name,
4242
llvm::Triple::OSType preferred_os,
4343
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
44-
llvm::StringRef sdk, lldb_private::XcodeSDK::Type sdk_type,
44+
std::string sdk_name_primary, std::string sdk_name_secondary,
45+
lldb_private::XcodeSDK::Type sdk_type,
4546
CoreSimulatorSupport::DeviceType::ProductFamilyID kind)
4647
: PlatformDarwin(true), m_class_name(class_name),
4748
m_description(description), m_plugin_name(plugin_name), m_kind(kind),
4849
m_os_type(preferred_os), m_supported_triples(supported_triples),
49-
m_sdk(sdk), m_sdk_type(sdk_type) {}
50+
m_sdk_name_primary(std::move(sdk_name_primary)),
51+
m_sdk_name_secondary(std::move(sdk_name_secondary)),
52+
m_sdk_type(sdk_type) {}
5053

5154
/// Destructor.
5255
///
@@ -83,8 +86,9 @@ lldb_private::Status PlatformAppleSimulator::LaunchProcess(
8386

8487
void PlatformAppleSimulator::GetStatus(Stream &strm) {
8588
Platform::GetStatus(strm);
86-
if (!m_sdk.empty())
87-
strm << " SDK Path: \"" << m_sdk << "\"\n";
89+
llvm::StringRef sdk = GetSDKFilepath();
90+
if (!sdk.empty())
91+
strm << " SDK Path: \"" << sdk << "\"\n";
8892
else
8993
strm << " SDK Path: error: unable to locate SDK\n";
9094

@@ -295,13 +299,21 @@ static llvm::StringRef GetXcodeSDKDir(std::string preferred,
295299
return sdk;
296300
}
297301

302+
llvm::StringRef PlatformAppleSimulator::GetSDKFilepath() {
303+
if (!m_have_searched_for_sdk) {
304+
m_sdk = GetXcodeSDKDir(m_sdk_name_primary, m_sdk_name_secondary);
305+
m_have_searched_for_sdk = true;
306+
}
307+
return m_sdk;
308+
}
309+
298310
PlatformSP PlatformAppleSimulator::CreateInstance(
299311
const char *class_name, const char *description, ConstString plugin_name,
300312
llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
301313
llvm::Triple::OSType preferred_os,
302314
llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
303315
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
304-
std::string sdk_name_preferred, std::string sdk_name_secondary,
316+
std::string sdk_name_primary, std::string sdk_name_secondary,
305317
lldb_private::XcodeSDK::Type sdk_type,
306318
CoreSimulatorSupport::DeviceType::ProductFamilyID kind, bool force,
307319
const ArchSpec *arch) {
@@ -360,11 +372,9 @@ PlatformSP PlatformAppleSimulator::CreateInstance(
360372
if (create) {
361373
LLDB_LOGF(log, "%s::%s() creating platform", class_name, __FUNCTION__);
362374

363-
llvm::StringRef sdk =
364-
GetXcodeSDKDir(sdk_name_preferred, sdk_name_secondary);
365375
return PlatformSP(new PlatformAppleSimulator(
366376
class_name, description, plugin_name, preferred_os, supported_triples,
367-
sdk, sdk_type, kind));
377+
sdk_name_primary, sdk_name_secondary, sdk_type, kind));
368378
}
369379

370380
LLDB_LOGF(log, "%s::%s() aborting creation of platform", class_name,
@@ -456,9 +466,10 @@ Status PlatformAppleSimulator::GetSymbolFile(const FileSpec &platform_file,
456466
if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) {
457467
char resolved_path[PATH_MAX];
458468

459-
if (!m_sdk.empty()) {
469+
llvm::StringRef sdk = GetSDKFilepath();
470+
if (!sdk.empty()) {
460471
::snprintf(resolved_path, sizeof(resolved_path), "%s/%s",
461-
m_sdk.str().c_str(), platform_file_path);
472+
sdk.str().c_str(), platform_file_path);
462473

463474
// First try in the SDK and see if the file is in there
464475
local_file.SetFile(resolved_path, FileSpec::Style::native);

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class PlatformAppleSimulator : public PlatformDarwin {
4949
const char *class_name, const char *description, ConstString plugin_name,
5050
llvm::Triple::OSType preferred_os,
5151
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
52-
llvm::StringRef sdk, XcodeSDK::Type sdk_type,
52+
std::string sdk_name_primary, std::string sdk_name_secondary,
53+
XcodeSDK::Type sdk_type,
5354
CoreSimulatorSupport::DeviceType::ProductFamilyID kind);
5455

5556
static lldb::PlatformSP
@@ -59,7 +60,7 @@ class PlatformAppleSimulator : public PlatformDarwin {
5960
llvm::Triple::OSType preferred_os,
6061
llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
6162
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
62-
std::string sdk_name_preferred, std::string sdk_name_secondary,
63+
std::string sdk_name_primary, std::string sdk_name_secondary,
6364
XcodeSDK::Type sdk_type,
6465
CoreSimulatorSupport::DeviceType::ProductFamilyID kind,
6566
bool force, const ArchSpec *arch);
@@ -117,8 +118,13 @@ class PlatformAppleSimulator : public PlatformDarwin {
117118

118119
FileSpec GetCoreSimulatorPath();
119120

121+
llvm::StringRef GetSDKFilepath();
122+
120123
llvm::Triple::OSType m_os_type = llvm::Triple::UnknownOS;
121124
llvm::SmallVector<llvm::StringRef, 4> m_supported_triples = {};
125+
std::string m_sdk_name_primary;
126+
std::string m_sdk_name_secondary;
127+
bool m_have_searched_for_sdk = false;
122128
llvm::StringRef m_sdk;
123129
XcodeSDK::Type m_sdk_type;
124130

0 commit comments

Comments
 (0)