Skip to content

Commit 0352007

Browse files
committed
Convert UpdateExternalModuleListIfNeeded to use early exits.
1 parent 83f5287 commit 0352007

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,72 +1618,72 @@ void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() {
16181618

16191619
DWARFDebugInfo *debug_info = DebugInfo();
16201620

1621+
// Follow DWO skeleton unit breadcrumbs.
16211622
const uint32_t num_compile_units = GetNumCompileUnits();
16221623
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
16231624
DWARFUnit *dwarf_cu = debug_info->GetUnitAtIndex(cu_idx);
1624-
16251625
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
1626-
if (die && !die.HasChildren()) {
1627-
const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1628-
1629-
if (name) {
1630-
ConstString const_name(name);
1631-
if (m_external_type_modules.find(const_name) ==
1632-
m_external_type_modules.end()) {
1633-
ModuleSP module_sp;
1634-
const char *dwo_path =
1635-
die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr);
1636-
if (dwo_path) {
1637-
ModuleSpec dwo_module_spec;
1638-
dwo_module_spec.GetFileSpec().SetFile(dwo_path,
1639-
FileSpec::Style::native);
1640-
if (dwo_module_spec.GetFileSpec().IsRelative()) {
1641-
const char *comp_dir =
1642-
die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr);
1643-
if (comp_dir) {
1644-
dwo_module_spec.GetFileSpec().SetFile(comp_dir,
1645-
FileSpec::Style::native);
1646-
FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec());
1647-
dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path);
1648-
}
1649-
}
1650-
dwo_module_spec.GetArchitecture() =
1651-
m_objfile_sp->GetModule()->GetArchitecture();
1652-
1653-
// When LLDB loads "external" modules it looks at the presence of
1654-
// DW_AT_GNU_dwo_name. However, when the already created module
1655-
// (corresponding to .dwo itself) is being processed, it will see
1656-
// the presence of DW_AT_GNU_dwo_name (which contains the name of
1657-
// dwo file) and will try to call ModuleList::GetSharedModule
1658-
// again. In some cases (i.e. for empty files) Clang 4.0 generates
1659-
// a *.dwo file which has DW_AT_GNU_dwo_name, but no
1660-
// DW_AT_comp_dir. In this case the method
1661-
// ModuleList::GetSharedModule will fail and the warning will be
1662-
// printed. However, as one can notice in this case we don't
1663-
// actually need to try to load the already loaded module
1664-
// (corresponding to .dwo) so we simply skip it.
1665-
if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" &&
1666-
llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath())
1667-
.endswith(dwo_module_spec.GetFileSpec().GetPath())) {
1668-
continue;
1669-
}
1626+
if (!die || die.HasChildren())
1627+
continue;
16701628

1671-
Status error = ModuleList::GetSharedModule(
1672-
dwo_module_spec, module_sp, nullptr, nullptr, nullptr);
1673-
if (!module_sp) {
1674-
GetObjectFile()->GetModule()->ReportWarning(
1675-
"0x%8.8x: unable to locate module needed for external types: "
1676-
"%s\nerror: %s\nDebugging will be degraded due to missing "
1677-
"types. Rebuilding your project will regenerate the needed "
1678-
"module files.",
1679-
die.GetOffset(),
1680-
dwo_module_spec.GetFileSpec().GetPath().c_str(),
1681-
error.AsCString("unknown error"));
1682-
}
1683-
}
1684-
m_external_type_modules[const_name] = module_sp;
1629+
const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1630+
if (!name)
1631+
continue;
1632+
1633+
ConstString const_name(name);
1634+
ModuleSP &module_sp = m_external_type_modules[const_name];
1635+
if (module_sp)
1636+
continue;
1637+
1638+
const char *dwo_path =
1639+
die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr);
1640+
if (!dwo_path)
1641+
dwo_path = die.GetAttributeValueAsString(DW_AT_dwo_name, nullptr);
1642+
if (dwo_path) {
1643+
ModuleSpec dwo_module_spec;
1644+
dwo_module_spec.GetFileSpec().SetFile(dwo_path, FileSpec::Style::native);
1645+
if (dwo_module_spec.GetFileSpec().IsRelative()) {
1646+
const char *comp_dir =
1647+
die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr);
1648+
if (comp_dir) {
1649+
dwo_module_spec.GetFileSpec().SetFile(comp_dir,
1650+
FileSpec::Style::native);
1651+
FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec());
1652+
dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path);
16851653
}
16861654
}
1655+
dwo_module_spec.GetArchitecture() =
1656+
m_objfile_sp->GetModule()->GetArchitecture();
1657+
1658+
// When LLDB loads "external" modules it looks at the presence
1659+
// of DW_AT_dwo_name. However, when the already created module
1660+
// (corresponding to .dwo itself) is being processed, it will
1661+
// see the presence of DW_AT_dwo_name (which contains the name
1662+
// of dwo file) and will try to call ModuleList::GetSharedModule
1663+
// again. In some cases (i.e., for empty files) Clang 4.0
1664+
// generates a *.dwo file which has DW_AT_dwo_name, but no
1665+
// DW_AT_comp_dir. In this case the method
1666+
// ModuleList::GetSharedModule will fail and the warning will be
1667+
// printed. However, as one can notice in this case we don't
1668+
// actually need to try to load the already loaded module
1669+
// (corresponding to .dwo) so we simply skip it.
1670+
if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" &&
1671+
llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath())
1672+
.endswith(dwo_module_spec.GetFileSpec().GetPath())) {
1673+
continue;
1674+
}
1675+
1676+
Status error = ModuleList::GetSharedModule(dwo_module_spec, module_sp,
1677+
nullptr, nullptr, nullptr);
1678+
if (!module_sp) {
1679+
GetObjectFile()->GetModule()->ReportWarning(
1680+
"0x%8.8x: unable to locate module needed for external types: "
1681+
"%s\nerror: %s\nDebugging will be degraded due to missing "
1682+
"types. Rebuilding your project will regenerate the needed "
1683+
"module files.",
1684+
die.GetOffset(), dwo_module_spec.GetFileSpec().GetPath().c_str(),
1685+
error.AsCString("unknown error"));
1686+
}
16871687
}
16881688
}
16891689
}

0 commit comments

Comments
 (0)