dwarfdump: Avoid parsing units unnecessarily

NFC-ish (the parsing of the units is not a functional change - no
errors/warnings are emitted during the shallow parsing - though without
parsing them here, the "max version" would be wrong (still zero) later
on, so in those cases the units do need to be parsed)

llvm-svn: 343884
This commit is contained in:
David Blaikie 2018-10-05 20:55:20 +00:00
parent 5931b4e5b5
commit fdada09fa4
2 changed files with 25 additions and 16 deletions

View File

@ -231,7 +231,17 @@ public:
/// Get a DIE given an exact offset.
DWARFDie getDIEForOffset(uint32_t Offset);
unsigned getMaxVersion() const { return MaxVersion; }
unsigned getMaxVersion() {
// Ensure info units have been parsed to discover MaxVersion
info_section_units();
return MaxVersion;
}
unsigned getMaxDWOVersion() {
// Ensure DWO info units have been parsed to discover MaxVersion
dwo_info_section_units();
return MaxVersion;
}
void setMaxVersionIfGreater(unsigned Version) {
if (Version > MaxVersion)

View File

@ -328,21 +328,20 @@ void DWARFContext::dump(
DObj->getAbbrevDWOSection()))
getDebugAbbrevDWO()->dump(OS);
auto dumpDebugInfo = [&](bool IsExplicit, const char *Name,
DWARFSection Section, unit_iterator_range Units) {
if (shouldDump(IsExplicit, Name, DIDT_ID_DebugInfo, Section.Data)) {
if (DumpOffset)
getDIEForOffset(DumpOffset.getValue())
.dump(OS, 0, DumpOpts.noImplicitRecursion());
else
for (const auto &U : Units)
U->dump(OS, DumpOpts);
}
auto dumpDebugInfo = [&](unit_iterator_range Units) {
if (DumpOffset)
getDIEForOffset(DumpOffset.getValue())
.dump(OS, 0, DumpOpts.noImplicitRecursion());
else
for (const auto &U : Units)
U->dump(OS, DumpOpts);
};
dumpDebugInfo(Explicit, ".debug_info", DObj->getInfoSection(),
info_section_units());
dumpDebugInfo(ExplicitDWO, ".debug_info.dwo", DObj->getInfoDWOSection(),
dwo_info_section_units());
if (shouldDump(Explicit, ".debug_info", DIDT_ID_DebugInfo,
DObj->getInfoSection().Data))
dumpDebugInfo(info_section_units());
if (shouldDump(ExplicitDWO, ".debug_info.dwo", DIDT_ID_DebugInfo,
DObj->getInfoDWOSection().Data))
dumpDebugInfo(dwo_info_section_units());
auto dumpDebugType = [&](const char *Name, unit_iterator_range Units) {
OS << '\n' << Name << " contents:\n";
@ -543,7 +542,7 @@ void DWARFContext::dump(
dumpStringOffsetsSection(OS, "debug_str_offsets.dwo", *DObj,
DObj->getStringOffsetDWOSection(),
DObj->getStringDWOSection(), dwo_units(),
isLittleEndian(), getMaxVersion());
isLittleEndian(), getMaxDWOVersion());
if (shouldDump(Explicit, ".gnu_index", DIDT_ID_GdbIndex,
DObj->getGdbIndexSection())) {