[Lldb-commits] [lldb] [lldb] Prefer selected Darwin platform SDK root for modules (PR #195028)

via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 30 00:43:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Li Teng (lnteng)

<details>
<summary>Changes</summary>

## Summary

Large iOS applications may contain tens of thousands of compile units. During
debug startup, LLDB can spend more than 10 seconds resolving the SDK path from
debug info when preparing Clang module compilation options.

This patch makes Darwin platform module compilation prefer an SDK root that was
explicitly selected by the user before falling back to
`ResolveSDKPathFromDebugInfo`.

Users can avoid the expensive debug-info SDK lookup with:

```lldb
platform select ios-simulator -S /path/to/iPhoneSimulator.sdk

The existing debug-info based SDK resolution remains as a fallback when no valid
SDK root is configured.

For a similar fix in the Swift repository, the corresponding path to consider is
settings set target.sdk-path.


---
Full diff: https://github.com/llvm/llvm-project/pull/195028.diff


2 Files Affected:

- (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (+18-7) 
- (modified) lldb/unittests/Platform/PlatformDarwinTest.cpp (+44) 


``````````diff
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 8db4824be7da5..f07ced4363372 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1242,13 +1242,24 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
   FileSpec sysroot_spec;
 
   if (target) {
-    auto sysroot_spec_or_err = ::ResolveSDKPathFromDebugInfo(target);
-    if (!sysroot_spec_or_err) {
-      LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
-                     sysroot_spec_or_err.takeError(),
-                     "Failed to resolve sysroot: {0}");
-    } else {
-      sysroot_spec = *sysroot_spec_or_err;
+    if (PlatformSP platform_sp = target->GetPlatform()) {
+      FileSpec platform_sdk_spec(platform_sp->GetSDKRootDirectory());
+      if (platform_sdk_spec) {
+        FileSystem::Instance().Resolve(platform_sdk_spec);
+        if (FileSystem::Instance().IsDirectory(platform_sdk_spec.GetPath()))
+          sysroot_spec = platform_sdk_spec;
+      }
+    }
+
+    if (!FileSystem::Instance().IsDirectory(sysroot_spec.GetPath())) {
+      auto sysroot_spec_or_err = ::ResolveSDKPathFromDebugInfo(target);
+      if (!sysroot_spec_or_err) {
+        LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
+                       sysroot_spec_or_err.takeError(),
+                       "Failed to resolve sysroot: {0}");
+      } else {
+        sysroot_spec = *sysroot_spec_or_err;
+      }
     }
   }
 
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
index 04af8081a274e..34c67d1ad5687 100644
--- a/lldb/unittests/Platform/PlatformDarwinTest.cpp
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -18,6 +18,8 @@
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
@@ -126,6 +128,48 @@ TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
   EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V);
 }
 
+TEST_F(PlatformDarwinLocateTest,
+       AddClangModuleCompilationOptionsUsesSelectedPlatformSDKRoot) {
+  llvm::SmallString<128> sdk_root(m_tmp_root_dir);
+  llvm::sys::path::append(sdk_root, "Target.sdk");
+  ASSERT_FALSE(llvm::sys::fs::create_directory(sdk_root))
+      << "Failed to create test SDK root directory.";
+  std::string sdk_root_path = sdk_root.str().str();
+
+  CommandReturnObject result(/*colors*/ false);
+  std::string command =
+      llvm::formatv("platform select ios-simulator -S \"{0}\"", sdk_root_path)
+          .str();
+  m_debugger_sp->GetCommandInterpreter().HandleCommand(command.c_str(),
+                                                       eLazyBoolNo, result);
+  ASSERT_TRUE(result.Succeeded()) << result.GetErrorString();
+
+  PlatformSP platform_sp =
+      m_debugger_sp->GetPlatformList().GetSelectedPlatform();
+  ASSERT_TRUE(platform_sp);
+  ASSERT_EQ(platform_sp->GetPluginName(), llvm::StringRef("ios-simulator"));
+  ASSERT_EQ(platform_sp->GetSDKRootDirectory(), sdk_root_path);
+
+  TargetSP target_sp;
+  ArchSpec arch("x86_64-apple-ios-simulator");
+  m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+                                              lldb_private::eLoadDependentsNo,
+                                              platform_sp, target_sp);
+  ASSERT_TRUE(target_sp);
+
+  std::vector<std::string> options;
+  platform_sp->AddClangModuleCompilationOptions(target_sp.get(), options);
+
+  bool found_sdk_root = false;
+  for (size_t i = 0; i + 1 < options.size(); ++i) {
+    if (options[i] == "-isysroot" && options[i + 1] == sdk_root_path) {
+      found_sdk_root = true;
+      break;
+    }
+  }
+  EXPECT_TRUE(found_sdk_root);
+}
+
 TEST_F(PlatformDarwinLocateTest,
        LocateExecutableScriptingResourcesFromDSYM_StripExtensions) {
   // Tests that LocateExecutableScriptingResourcesFromDSYM will strip module

``````````

</details>


https://github.com/llvm/llvm-project/pull/195028


More information about the lldb-commits mailing list