[ObjectYAML][DWARF] Let `dumpPubSection` return `DWARFYAML::PubSection`.

Summary: This patch addresses comments in [D80722](https://reviews.llvm.org/D80722#inline-742353)

Reviewers: grimar, jhenderson

Reviewed By: grimar, jhenderson

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80861
This commit is contained in:
Xing GUO 2020-06-02 14:38:15 +08:00
parent 2bcd1927dd
commit d3f49b8d37
1 changed files with 15 additions and 19 deletions

View File

@ -115,10 +115,12 @@ Error dumpDebugRanges(DWARFContext &DCtx, DWARFYAML::Data &Y) {
return ErrorSuccess(); return ErrorSuccess();
} }
void dumpPubSection(DWARFContext &DCtx, DWARFYAML::PubSection &Y, static DWARFYAML::PubSection dumpPubSection(const DWARFContext &DCtx,
DWARFSection Section) { const DWARFSection &Section,
bool IsGNUStyle) {
DWARFDataExtractor PubSectionData(DCtx.getDWARFObj(), Section, DWARFDataExtractor PubSectionData(DCtx.getDWARFObj(), Section,
DCtx.isLittleEndian(), 0); DCtx.isLittleEndian(), 0);
DWARFYAML::PubSection Y(IsGNUStyle);
uint64_t Offset = 0; uint64_t Offset = 0;
dumpInitialLength(PubSectionData, Offset, Y.Length); dumpInitialLength(PubSectionData, Offset, Y.Length);
Y.Version = PubSectionData.getU16(&Offset); Y.Version = PubSectionData.getU16(&Offset);
@ -127,41 +129,35 @@ void dumpPubSection(DWARFContext &DCtx, DWARFYAML::PubSection &Y,
while (Offset < Y.Length.getLength()) { while (Offset < Y.Length.getLength()) {
DWARFYAML::PubEntry NewEntry; DWARFYAML::PubEntry NewEntry;
NewEntry.DieOffset = PubSectionData.getU32(&Offset); NewEntry.DieOffset = PubSectionData.getU32(&Offset);
if (Y.IsGNUStyle) if (IsGNUStyle)
NewEntry.Descriptor = PubSectionData.getU8(&Offset); NewEntry.Descriptor = PubSectionData.getU8(&Offset);
NewEntry.Name = PubSectionData.getCStr(&Offset); NewEntry.Name = PubSectionData.getCStr(&Offset);
Y.Entries.push_back(NewEntry); Y.Entries.push_back(NewEntry);
} }
return Y;
} }
void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) { void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
const DWARFObject &D = DCtx.getDWARFObj(); const DWARFObject &D = DCtx.getDWARFObj();
const DWARFSection PubNames = D.getPubnamesSection(); const DWARFSection PubNames = D.getPubnamesSection();
if (!PubNames.Data.empty()) { if (!PubNames.Data.empty())
Y.PubNames.emplace(/*IsGNUStyle=*/false); Y.PubNames = dumpPubSection(DCtx, PubNames, /*IsGNUStyle=*/false);
dumpPubSection(DCtx, *Y.PubNames, PubNames);
}
const DWARFSection PubTypes = D.getPubtypesSection(); const DWARFSection PubTypes = D.getPubtypesSection();
if (!PubTypes.Data.empty()) { if (!PubTypes.Data.empty())
Y.PubTypes.emplace(/*IsGNUStyle=*/false); Y.PubTypes = dumpPubSection(DCtx, PubTypes, /*IsGNUStyle=*/false);
dumpPubSection(DCtx, *Y.PubTypes, PubTypes);
}
const DWARFSection GNUPubNames = D.getGnuPubnamesSection(); const DWARFSection GNUPubNames = D.getGnuPubnamesSection();
if (!GNUPubNames.Data.empty()) { if (!GNUPubNames.Data.empty())
// TODO: Test dumping .debug_gnu_pubnames section. // TODO: Test dumping .debug_gnu_pubnames section.
Y.GNUPubNames.emplace(/*IsGNUStyle=*/true); Y.GNUPubNames = dumpPubSection(DCtx, GNUPubNames, /*IsGNUStyle=*/true);
dumpPubSection(DCtx, *Y.GNUPubNames, GNUPubNames);
}
const DWARFSection GNUPubTypes = D.getGnuPubtypesSection(); const DWARFSection GNUPubTypes = D.getGnuPubtypesSection();
if (!GNUPubTypes.Data.empty()) { if (!GNUPubTypes.Data.empty())
// TODO: Test dumping .debug_gnu_pubtypes section. // TODO: Test dumping .debug_gnu_pubtypes section.
Y.GNUPubTypes.emplace(/*IsGNUStyle=*/true); Y.GNUPubTypes = dumpPubSection(DCtx, GNUPubTypes, /*IsGNUStyle=*/true);
dumpPubSection(DCtx, *Y.GNUPubTypes, GNUPubTypes);
}
} }
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) { void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {