diff --git a/lldb/include/lldb/Host/HostInfoBase.h b/lldb/include/lldb/Host/HostInfoBase.h --- a/lldb/include/lldb/Host/HostInfoBase.h +++ b/lldb/include/lldb/Host/HostInfoBase.h @@ -31,6 +31,23 @@ lldb::DataBufferSP data_sp; }; +namespace { +struct HostInfoError : public llvm::ErrorInfo { + static char ID; + const std::string message_; + + HostInfoError(const std::string message) : message_(std::move(message)) {} + + void log(llvm::raw_ostream &OS) const override { OS << "HostInfoError"; } + + std::error_code convertToErrorCode() const override { + return llvm::inconvertibleErrorCode(); + } +}; + +char HostInfoError::ID = 0; +} + class HostInfoBase { private: // Static class, unconstructable. @@ -108,10 +125,14 @@ static FileSpec GetXcodeContentsDirectory() { return {}; } static FileSpec GetXcodeDeveloperDirectory() { return {}; } - - /// Return the directory containing a specific Xcode SDK. - static llvm::Expected GetXcodeSDKPath(XcodeSDK sdk) { - return ""; + + struct SDKOptions { + std::optional XcodeSDK; + }; + + /// Return the directory containing something like a SDK (reused for Swift). + static llvm::Expected GetSDKRoot(SDKOptions options) { + return llvm::make_error("cannot determine SDK root"); } /// Return information about module \p image_name if it is loaded in diff --git a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h --- a/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h +++ b/lldb/include/lldb/Host/macosx/HostInfoMacOSX.h @@ -31,7 +31,7 @@ static FileSpec GetXcodeDeveloperDirectory(); /// Query xcrun to find an Xcode SDK directory. - static llvm::Expected GetXcodeSDKPath(XcodeSDK sdk); + static llvm::Expected GetSDKRoot(SDKOptions options); /// Shared cache utilities static SharedCacheImageInfo diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -1607,8 +1607,7 @@ void Module::RegisterXcodeSDK(llvm::StringRef sdk_name, llvm::StringRef sysroot) { - XcodeSDK sdk(sdk_name.str()); - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(sdk); + auto sdk_path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk_name.str()}); if (!sdk_path_or_err) { Debugger::ReportError("Error while searching for Xcode SDK: " + diff --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm --- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm +++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm @@ -338,7 +338,7 @@ } } - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()); + auto sdk_path_or_err = HostInfo::GetSDKRoot(SDKOptions{XcodeSDK::GetAnyMacOS()}); if (!sdk_path_or_err) { Log *log = GetLog(LLDBLog::Host); LLDB_LOGF(log, "Error while searching for Xcode SDK: %s", @@ -519,7 +519,7 @@ return path; } -llvm::Expected HostInfoMacOSX::GetXcodeSDKPath(XcodeSDK sdk) { +llvm::Expected HostInfoMacOSX::GetSDKRoot(SDKOptions options) { struct ErrorOrPath { std::string str; bool is_error; @@ -539,7 +539,7 @@ else return it->second.str; } - auto path_or_err = GetXcodeSDK(sdk); + auto path_or_err = GetXcodeSDK(options.XcodeSDK); if (!path_or_err) { std::string error = toString(path_or_err.takeError()); g_sdk_path.insert({key, {error, true}}); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -284,7 +284,7 @@ std::string secondary) { llvm::StringRef sdk; auto get_sdk = [&](std::string sdk) -> llvm::StringRef { - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(sdk))); + auto sdk_path_or_err = HostInfo::GetSDKRoot(SDKOptions{XcodeSDK(std::move(sdk))}); if (!sdk_path_or_err) { Debugger::ReportError("Error while searching for Xcode SDK: " + toString(sdk_path_or_err.takeError())); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp --- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp @@ -124,7 +124,7 @@ } // Use the default SDK as a fallback. - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()); + auto sdk_path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{XcodeSDK::GetAnyMacOS()}); if (!sdk_path_or_err) { Debugger::ReportError("Error while searching for Xcode SDK: " + toString(sdk_path_or_err.takeError())); diff --git a/lldb/unittests/Host/HostInfoTest.cpp b/lldb/unittests/Host/HostInfoTest.cpp --- a/lldb/unittests/Host/HostInfoTest.cpp +++ b/lldb/unittests/Host/HostInfoTest.cpp @@ -57,7 +57,7 @@ #if defined(__APPLE__) TEST_F(HostInfoTest, GetXcodeSDK) { auto get_sdk = [](std::string sdk, bool error = false) -> llvm::StringRef { - auto sdk_path_or_err = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(sdk))); + auto sdk_path_or_err = HostInfo::GetSDKRoot(SDKOptions{XcodeSDK(std::move(sdk))}); if (!error) { EXPECT_TRUE((bool)sdk_path_or_err); return *sdk_path_or_err;