NFC: DebugInfo: Reduce scope of DebugOffset to simplify code

This was being used as a sort of indirect out parameter from shouldDump
- seems simpler to use it as the actual result of the call. (this does
mean using a pointer to an Optional & actually using all 3 states (null,
None, and present) which is, admittedly, a tad subtle - but given the
limited scope, seems OK to me - open to discussion though, if others
feel strongly about it)

llvm-svn: 346691
This commit is contained in:
David Blaikie 2018-11-12 18:53:28 +00:00
parent e86c8d33b1
commit 582a5ebce0
1 changed files with 33 additions and 31 deletions

View File

@ -317,7 +317,6 @@ void DWARFContext::dump(
raw_ostream &OS, DIDumpOptions DumpOpts,
std::array<Optional<uint64_t>, DIDT_ID_Count> DumpOffsets) {
Optional<uint64_t> DumpOffset;
uint64_t DumpType = DumpOpts.DumpType;
StringRef Extension = sys::path::extension(DObj->getFileName());
@ -334,13 +333,13 @@ void DWARFContext::dump(
bool Explicit = DumpType != DIDT_All && !IsDWO;
bool ExplicitDWO = Explicit && IsDWO;
auto shouldDump = [&](bool Explicit, const char *Name, unsigned ID,
StringRef Section) {
DumpOffset = DumpOffsets[ID];
StringRef Section) -> Optional<uint64_t> * {
unsigned Mask = 1U << ID;
bool Should = (DumpType & Mask) && (Explicit || !Section.empty());
if (Should)
OS << "\n" << Name << " contents:\n";
return Should;
if (!Should)
return nullptr;
OS << "\n" << Name << " contents:\n";
return &DumpOffsets[ID];
};
// Dump individual sections.
@ -353,7 +352,7 @@ void DWARFContext::dump(
auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
OS << '\n' << Name << " contents:\n";
if ((DumpOffset = DumpOffsets[DIDT_ID_DebugInfo]))
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
for (const auto &U : Units)
U->getDIEForOffset(DumpOffset.getValue())
.dump(OS, 0, DumpOpts.noImplicitRecursion());
@ -370,9 +369,8 @@ void DWARFContext::dump(
auto dumpDebugType = [&](const char *Name, unit_iterator_range Units) {
OS << '\n' << Name << " contents:\n";
DumpOffset = DumpOffsets[DIDT_ID_DebugTypes];
for (const auto &U : Units)
if (DumpOffset)
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugTypes])
U->getDIEForOffset(*DumpOffset)
.dump(OS, 0, DumpOpts.noImplicitRecursion());
else
@ -385,28 +383,30 @@ void DWARFContext::dump(
dumpDebugType(".debug_types.dwo", dwo_types_section_units());
}
if (shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
DObj->getLocSection().Data)) {
getDebugLoc()->dump(OS, getRegisterInfo(), DumpOffset);
if (const auto *Off = shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
DObj->getLocSection().Data)) {
getDebugLoc()->dump(OS, getRegisterInfo(), *Off);
}
if (shouldDump(Explicit, ".debug_loclists", DIDT_ID_DebugLoclists,
DObj->getLoclistsSection().Data)) {
if (const auto *Off =
shouldDump(Explicit, ".debug_loclists", DIDT_ID_DebugLoclists,
DObj->getLoclistsSection().Data)) {
DWARFDataExtractor Data(*DObj, DObj->getLoclistsSection(), isLittleEndian(),
0);
dumpLoclistsSection(OS, DumpOpts, Data, getRegisterInfo(), DumpOffset);
dumpLoclistsSection(OS, DumpOpts, Data, getRegisterInfo(), *Off);
}
if (shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
DObj->getLocDWOSection().Data)) {
getDebugLocDWO()->dump(OS, 0, getRegisterInfo(), DumpOffset);
if (const auto *Off =
shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
DObj->getLocDWOSection().Data)) {
getDebugLocDWO()->dump(OS, 0, getRegisterInfo(), *Off);
}
if (shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
DObj->getDebugFrameSection()))
getDebugFrame()->dump(OS, getRegisterInfo(), DumpOffset);
if (const auto *Off = shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
DObj->getDebugFrameSection()))
getDebugFrame()->dump(OS, getRegisterInfo(), *Off);
if (shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
DObj->getEHFrameSection()))
getEHFrame()->dump(OS, getRegisterInfo(), DumpOffset);
if (const auto *Off = shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
DObj->getEHFrameSection()))
getEHFrame()->dump(OS, getRegisterInfo(), *Off);
if (DumpType & DIDT_DebugMacro) {
if (Explicit || !getDebugMacro()->empty()) {
@ -425,7 +425,8 @@ void DWARFContext::dump(
}
auto DumpLineSection = [&](DWARFDebugLine::SectionParser Parser,
DIDumpOptions DumpOpts) {
DIDumpOptions DumpOpts,
Optional<uint64_t> DumpOffset) {
while (!Parser.done()) {
if (DumpOffset && Parser.getOffset() != *DumpOffset) {
Parser.skip(dumpWarning);
@ -442,22 +443,23 @@ void DWARFContext::dump(
}
};
if (shouldDump(Explicit, ".debug_line", DIDT_ID_DebugLine,
DObj->getLineSection().Data)) {
if (const auto *Off = shouldDump(Explicit, ".debug_line", DIDT_ID_DebugLine,
DObj->getLineSection().Data)) {
DWARFDataExtractor LineData(*DObj, DObj->getLineSection(), isLittleEndian(),
0);
DWARFDebugLine::SectionParser Parser(LineData, *this, compile_units(),
type_units());
DumpLineSection(Parser, DumpOpts);
DumpLineSection(Parser, DumpOpts, *Off);
}
if (shouldDump(ExplicitDWO, ".debug_line.dwo", DIDT_ID_DebugLine,
DObj->getLineDWOSection().Data)) {
if (const auto *Off =
shouldDump(ExplicitDWO, ".debug_line.dwo", DIDT_ID_DebugLine,
DObj->getLineDWOSection().Data)) {
DWARFDataExtractor LineData(*DObj, DObj->getLineDWOSection(),
isLittleEndian(), 0);
DWARFDebugLine::SectionParser Parser(LineData, *this, dwo_compile_units(),
dwo_type_units());
DumpLineSection(Parser, DumpOpts);
DumpLineSection(Parser, DumpOpts, *Off);
}
if (shouldDump(Explicit, ".debug_cu_index", DIDT_ID_DebugCUIndex,