Skip to content

Commit 8c833be

Browse files
committed
Factor out GetSDKPathFromDebugInfo() (NFC)
1 parent a9a5fb5 commit 8c833be

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,35 @@ static llvm::Optional<StringRef> GetDSYMBundle(Module &module) {
16141614
return dsym;
16151615
}
16161616

1617+
/// Force parsing of the CUs to extract the SDK info.
1618+
static std::string GetSDKPathFromDebugInfo(std::string m_description,
1619+
Module &module) {
1620+
XcodeSDK sdk;
1621+
bool found_public_sdk = false;
1622+
bool found_internal_sdk = false;
1623+
if (SymbolFile *sym_file = module.GetSymbolFile())
1624+
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
1625+
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i))
1626+
if (cu_sp->GetLanguage() == lldb::eLanguageTypeSwift) {
1627+
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
1628+
sdk.Merge(cu_sdk);
1629+
bool is_internal_sdk = cu_sdk.IsAppleInternalSDK();
1630+
found_public_sdk |= !is_internal_sdk;
1631+
found_internal_sdk |= is_internal_sdk;
1632+
}
1633+
1634+
if (found_public_sdk && found_internal_sdk)
1635+
HEALTH_LOG_PRINTF("Unsupported mixing of public and internal SDKs in "
1636+
"'%s'. Mixed use of SDKs indicates use of different "
1637+
"toolchains, which is not supported.",
1638+
module.GetFileSpec().GetFilename().GetCString());
1639+
1640+
std::string sdk_path = HostInfo::GetXcodeSDKPath(sdk).str();
1641+
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Host SDK path for sdk %s is %s.",
1642+
sdk.GetString().str().c_str(), sdk_path.c_str());
1643+
return sdk_path;
1644+
}
1645+
16171646
/// Detect whether a Swift module was "imported" by DWARFImporter.
16181647
/// All this *really* means is that it couldn't be loaded through any
16191648
/// other mechanism.
@@ -1759,30 +1788,7 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
17591788
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Serialized SDK path is %s.",
17601789
serialized_sdk_path.str().c_str());
17611790

1762-
// Force parsing of the CUs to extract the SDK info.
1763-
XcodeSDK sdk;
1764-
bool found_public_sdk = false;
1765-
bool found_internal_sdk = false;
1766-
if (SymbolFile *sym_file = module.GetSymbolFile())
1767-
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i)
1768-
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i))
1769-
if (cu_sp->GetLanguage() == lldb::eLanguageTypeSwift) {
1770-
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
1771-
sdk.Merge(cu_sdk);
1772-
bool is_internal_sdk = cu_sdk.IsAppleInternalSDK();
1773-
found_public_sdk |= !is_internal_sdk;
1774-
found_internal_sdk |= is_internal_sdk;
1775-
}
1776-
1777-
if (found_public_sdk && found_internal_sdk)
1778-
HEALTH_LOG_PRINTF("Unsupported mixing of public and internal SDKs in "
1779-
"'%s'. Mixed use of SDKs indicates use of different "
1780-
"toolchains, which is not supported.",
1781-
module.GetFileSpec().GetFilename().GetCString());
1782-
1783-
std::string sdk_path = HostInfo::GetXcodeSDKPath(sdk).str();
1784-
LOG_PRINTF(LIBLLDB_LOG_TYPES, "Host SDK path for sdk %s is %s.",
1785-
sdk.GetString().str().c_str(), sdk_path.c_str());
1791+
std::string sdk_path = GetSDKPathFromDebugInfo(m_description, module);
17861792
if (FileSystem::Instance().Exists(sdk_path)) {
17871793
// Note that this is not final. InitializeSearchPathOptions()
17881794
// will set the SDK path based on the triple if this fails.

0 commit comments

Comments
 (0)