[Lldb-commits] [lldb] 9951578 - Don't search for sim SDK path until we know we need it

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 24 15:45:03 PDT 2022


Author: Jason Molenda
Date: 2022-03-24T15:44:57-07:00
New Revision: 99515783a63cd5018fa9231872dc5c8b13d64947

URL: https://github.com/llvm/llvm-project/commit/99515783a63cd5018fa9231872dc5c8b13d64947
DIFF: https://github.com/llvm/llvm-project/commit/99515783a63cd5018fa9231872dc5c8b13d64947.diff

LOG: Don't search for sim SDK path until we know we need it

When iterating over all Platforms looking for the best one, on a Mac the
Simulator platforms (iOS, tvOS, watchOS) will first find their SDK
directory by calling xcrun, then decide if they should activate or not.
When that SDK is absent, the call to xcrun to find it can be very slow.
This patch delays that directory search until we know we're activating
this platform, so non-simulator environments don't pay a perf cost ever
time they go through the list of platforms.

Differential Revision: https://reviews.llvm.org/D122373
rdar://87960090

Added: 
    

Modified: 
    lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
    lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index 426e044e7ab72..3d68fcdb653b9 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -379,6 +379,13 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
     args.AppendArgument("--sdk");
     args.AppendArgument(sdk);
 
+    Log *log = GetLog(LLDBLog::Host);
+    if (log) {
+      std::string cmdstr;
+      args.GetCommandString(cmdstr);
+      log->Printf("GetXcodeSDK() running shell cmd '%s'", cmdstr.c_str());
+    }
+
     int status = 0;
     int signo = 0;
     std::string output_str;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
index 4659ad6d6e13b..1728d3855b1a2 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
@@ -274,13 +274,23 @@ std::vector<ArchSpec> PlatformAppleSimulator::GetSupportedArchitectures(
   return result;
 }
 
+static llvm::StringRef GetXcodeSDKDir(std::string preferred,
+                                      std::string secondary) {
+  llvm::StringRef sdk;
+  sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(preferred)));
+  if (sdk.empty())
+    sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(secondary)));
+  return sdk;
+}
+
 PlatformSP PlatformAppleSimulator::CreateInstance(
     const char *class_name, const char *description, ConstString plugin_name,
     llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
     llvm::Triple::OSType preferred_os,
     llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
     llvm::SmallVector<llvm::StringRef, 4> supported_triples,
-    llvm::StringRef sdk, lldb_private::XcodeSDK::Type sdk_type,
+    std::string sdk_name_preferred, std::string sdk_name_secondary,
+    lldb_private::XcodeSDK::Type sdk_type,
     CoreSimulatorSupport::DeviceType::ProductFamilyID kind, bool force,
     const ArchSpec *arch) {
   Log *log = GetLog(LLDBLog::Platform);
@@ -338,6 +348,8 @@ PlatformSP PlatformAppleSimulator::CreateInstance(
   if (create) {
     LLDB_LOGF(log, "%s::%s() creating platform", class_name, __FUNCTION__);
 
+    llvm::StringRef sdk =
+        GetXcodeSDKDir(sdk_name_preferred, sdk_name_secondary);
     return PlatformSP(new PlatformAppleSimulator(
         class_name, description, plugin_name, preferred_os, supported_triples,
         sdk, sdk_type, kind));
@@ -514,15 +526,6 @@ static bool shouldSkipSimulatorPlatform(bool force, const ArchSpec *arch) {
          !arch->TripleEnvironmentWasSpecified();
 }
 
-static llvm::StringRef GetXcodeSDKDir(std::string preferred,
-                                      std::string secondary) {
-  llvm::StringRef sdk;
-  sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(preferred)));
-  if (sdk.empty())
-    sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(secondary)));
-  return sdk;
-}
-
 static const char *g_ios_plugin_name = "ios-simulator";
 static const char *g_ios_description = "iPhone simulator platform plug-in.";
 
@@ -540,10 +543,6 @@ struct PlatformiOSSimulator {
   static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
     if (shouldSkipSimulatorPlatform(force, arch))
       return nullptr;
-    llvm::StringRef sdk;
-    sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.Internal.sdk"));
-    if (sdk.empty())
-      sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.sdk"));
 
     return PlatformAppleSimulator::CreateInstance(
         "PlatformiOSSimulator", g_ios_description,
@@ -566,7 +565,7 @@ struct PlatformiOSSimulator {
 #endif
 #endif
         },
-        GetXcodeSDKDir("iPhoneSimulator.Internal.sdk", "iPhoneSimulator.sdk"),
+        "iPhoneSimulator.Internal.sdk", "iPhoneSimulator.sdk",
         XcodeSDK::Type::iPhoneSimulator,
         CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone, force, arch);
   }
@@ -604,7 +603,7 @@ struct PlatformAppleTVSimulator {
 #endif
 #endif
         },
-        GetXcodeSDKDir("AppleTVSimulator.Internal.sdk", "AppleTVSimulator.sdk"),
+        "AppleTVSimulator.Internal.sdk", "AppleTVSimulator.sdk",
         XcodeSDK::Type::AppleTVSimulator,
         CoreSimulatorSupport::DeviceType::ProductFamilyID::appleTV, force,
         arch);
@@ -646,7 +645,7 @@ struct PlatformAppleWatchSimulator {
 #endif
 #endif
         },
-        GetXcodeSDKDir("WatchSimulator.Internal.sdk", "WatchSimulator.sdk"),
+        "WatchSimulator.Internal.sdk", "WatchSimulator.sdk",
         XcodeSDK::Type::WatchSimulator,
         CoreSimulatorSupport::DeviceType::ProductFamilyID::appleWatch, force,
         arch);

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
index 4cadf9a703431..bac7496a50e61 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
@@ -59,7 +59,8 @@ class PlatformAppleSimulator : public PlatformDarwin {
                  llvm::Triple::OSType preferred_os,
                  llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
                  llvm::SmallVector<llvm::StringRef, 4> supported_triples,
-                 llvm::StringRef sdk, XcodeSDK::Type sdk_type,
+                 std::string sdk_name_preferred, std::string sdk_name_secondary,
+                 XcodeSDK::Type sdk_type,
                  CoreSimulatorSupport::DeviceType::ProductFamilyID kind,
                  bool force, const ArchSpec *arch);
 


        


More information about the lldb-commits mailing list