[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 30 07:33:03 PDT 2025


================
@@ -1152,6 +1150,46 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
   }
 }
 
+llvm::Expected<lldb_private::FileSpec>
+lldb_private::PlatformDarwin::ResolveSDKPathFromDebugInfo(
+    lldb_private::Target *target) {
+
+  ModuleSP exe_module_sp = target->GetExecutableModule();
+  if (!exe_module_sp)
+    return llvm::createStringError(
+        llvm::inconvertibleErrorCode(),
+        llvm::formatv("Failed to get module from target"));
+
+  SymbolFile *sym_file = exe_module_sp->GetSymbolFile();
+  if (!sym_file)
+    return llvm::createStringError(
+        llvm::inconvertibleErrorCode(),
+        llvm::formatv("Failed to get symbol file from module"));
+
+  XcodeSDK merged_sdk;
+  for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
+    if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) {
+      auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
+      merged_sdk.Merge(cu_sdk);
+    }
+  }
+
+  // TODO: The result of this loop is almost equivalent to deriving the SDK
+  // from the target triple, which would be a lot cheaper.
+  FileSpec sdk_path = merged_sdk.GetSysroot();
+  if (FileSystem::Instance().Exists(sdk_path)) {
+    return sdk_path;
+  }
+  auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk});
+  if (path_or_err)
----------------
Michael137 wrote:

Minor nit: I would invert this condition and return error if `!path_or_err`.

Then return `FileSpec(*path_or_err)` as the last return from this function. So we're consistent with all the other early returns in this function

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


More information about the lldb-commits mailing list