Skip to content

Factor out GetSDKPathFromDebugInfo() (NFC) #3877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,35 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
return dsym;
}

/// Force parsing of the CUs to extract the SDK info.
static std::string GetSDKPathFromDebugInfo(std::string m_description,
Module &module) {
XcodeSDK sdk;
bool found_public_sdk = false;
bool found_internal_sdk = false;
if (SymbolFile *sym_file = module.GetSymbolFile())
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i))
if (cu_sp->GetLanguage() == lldb::eLanguageTypeSwift) {
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
sdk.Merge(cu_sdk);
bool is_internal_sdk = cu_sdk.IsAppleInternalSDK();
found_public_sdk |= !is_internal_sdk;
found_internal_sdk |= is_internal_sdk;
}

if (found_public_sdk && found_internal_sdk)
HEALTH_LOG_PRINTF("Unsupported mixing of public and internal SDKs in "
"'%s'. Mixed use of SDKs indicates use of different "
"toolchains, which is not supported.",
module.GetFileSpec().GetFilename().GetCString());

std::string sdk_path = HostInfo::GetXcodeSDKPath(sdk).str();
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Host SDK path for sdk %s is %s.",
sdk.GetString().str().c_str(), sdk_path.c_str());
return sdk_path;
}

/// Detect whether a Swift module was "imported" by DWARFImporter.
/// All this *really* means is that it couldn't be loaded through any
/// other mechanism.
Expand Down Expand Up @@ -1759,30 +1788,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Serialized SDK path is %s.",
serialized_sdk_path.str().c_str());

// Force parsing of the CUs to extract the SDK info.
XcodeSDK sdk;
bool found_public_sdk = false;
bool found_internal_sdk = false;
if (SymbolFile *sym_file = module.GetSymbolFile())
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i))
if (cu_sp->GetLanguage() == lldb::eLanguageTypeSwift) {
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
sdk.Merge(cu_sdk);
bool is_internal_sdk = cu_sdk.IsAppleInternalSDK();
found_public_sdk |= !is_internal_sdk;
found_internal_sdk |= is_internal_sdk;
}

if (found_public_sdk && found_internal_sdk)
HEALTH_LOG_PRINTF("Unsupported mixing of public and internal SDKs in "
"'%s'. Mixed use of SDKs indicates use of different "
"toolchains, which is not supported.",
module.GetFileSpec().GetFilename().GetCString());

std::string sdk_path = HostInfo::GetXcodeSDKPath(sdk).str();
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Host SDK path for sdk %s is %s.",
sdk.GetString().str().c_str(), sdk_path.c_str());
std::string sdk_path = GetSDKPathFromDebugInfo(m_description, module);
if (FileSystem::Instance().Exists(sdk_path)) {
// Note that this is not final. InitializeSearchPathOptions()
// will set the SDK path based on the triple if this fails.
Expand Down