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