[DWARFYAML] Replace 'Format', 'Version', etc with 'FormParams'. NFC.

This patch replaces 'Format', 'Version' fields, etc with 'FormParams' to
simplify codes.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D84496
This commit is contained in:
Xing GUO 2020-07-24 16:54:31 +08:00
parent a85ca6be2a
commit bbb057c49a
4 changed files with 29 additions and 38 deletions

View File

@ -119,12 +119,10 @@ struct DWARFContext {
};
struct Unit {
dwarf::DwarfFormat Format;
dwarf::FormParams FormParams;
Optional<yaml::Hex64> Length;
uint16_t Version;
llvm::dwarf::UnitType Type; // Added in DWARF 5
yaml::Hex64 AbbrOffset;
uint8_t AddrSize;
std::vector<Entry> Entries;
};

View File

@ -207,16 +207,6 @@ Error DWARFYAML::emitPubSection(raw_ostream &OS,
return Error::success();
}
static unsigned getOffsetSize(const DWARFYAML::Unit &Unit) {
return Unit.Format == dwarf::DWARF64 ? 8 : 4;
}
static unsigned getRefSize(const DWARFYAML::Unit &Unit) {
if (Unit.Version == 2)
return Unit.AddrSize;
return getOffsetSize(Unit);
}
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
const DWARFYAML::Unit &Unit,
const DWARFYAML::Entry &Entry,
@ -244,14 +234,15 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
switch (Form) {
case dwarf::DW_FORM_addr:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(FormVal->Value, Unit.AddrSize,
OS, IsLittleEndian))
if (Error Err = writeVariableSizedInteger(
FormVal->Value, Unit.FormParams.AddrSize, OS, IsLittleEndian))
return std::move(Err);
break;
case dwarf::DW_FORM_ref_addr:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
FormVal->Value, getRefSize(Unit), OS, IsLittleEndian))
FormVal->Value, Unit.FormParams.getRefAddrByteSize(), OS,
IsLittleEndian))
return std::move(Err);
break;
case dwarf::DW_FORM_exprloc:
@ -333,10 +324,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
case dwarf::DW_FORM_GNU_strp_alt:
case dwarf::DW_FORM_line_strp:
case dwarf::DW_FORM_strp_sup:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
FormVal->Value, getOffsetSize(Unit), OS, IsLittleEndian))
return std::move(Err);
cantFail(writeVariableSizedInteger(
FormVal->Value, Unit.FormParams.getDwarfOffsetByteSize(), OS,
IsLittleEndian));
break;
default:
break;
@ -350,9 +340,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
Length += Unit.Version >= 5 ? 1 : 0; // sizeof(unit_type)
Length += Unit.FormParams.Version >= 5 ? 1 : 0; // sizeof(unit_type)
Length +=
Unit.Format == dwarf::DWARF64 ? 8 : 4; // sizeof(debug_abbrev_offset)
Unit.FormParams.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
// Since the length of the current compilation unit is undetermined yet, we
// firstly write the content of the compilation unit to a buffer to
@ -374,15 +364,17 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
if (Unit.Length)
Length = *Unit.Length;
writeInitialLength(Unit.Format, Length, OS, DI.IsLittleEndian);
writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian);
if (Unit.Version >= 5) {
writeInitialLength(Unit.FormParams.Format, Length, OS, DI.IsLittleEndian);
writeInteger((uint16_t)Unit.FormParams.Version, OS, DI.IsLittleEndian);
if (Unit.FormParams.Version >= 5) {
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
DI.IsLittleEndian);
} else {
writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
DI.IsLittleEndian);
writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
}
OS.write(EntryBuffer.data(), EntryBuffer.size());
@ -438,7 +430,8 @@ Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
case dwarf::DW_LNE_set_discriminator:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
Op.Data, DI.CompileUnits[0].AddrSize, OS, DI.IsLittleEndian))
Op.Data, DI.CompileUnits[0].FormParams.AddrSize, OS,
DI.IsLittleEndian))
return Err;
break;
case dwarf::DW_LNE_define_file:

View File

@ -142,13 +142,13 @@ void MappingTraits<DWARFYAML::PubSection>::mapping(
}
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
IO.mapOptional("Format", Unit.Format, dwarf::DWARF32);
IO.mapOptional("Format", Unit.FormParams.Format, dwarf::DWARF32);
IO.mapOptional("Length", Unit.Length);
IO.mapRequired("Version", Unit.Version);
if (Unit.Version >= 5)
IO.mapRequired("Version", Unit.FormParams.Version);
if (Unit.FormParams.Version >= 5)
IO.mapRequired("UnitType", Unit.Type);
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
IO.mapRequired("AddrSize", Unit.AddrSize);
IO.mapRequired("AddrSize", Unit.FormParams.AddrSize);
IO.mapOptional("Entries", Unit.Entries);
}

View File

@ -165,13 +165,13 @@ void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
for (const auto &CU : DCtx.compile_units()) {
DWARFYAML::Unit NewUnit;
NewUnit.Format = CU->getFormat();
NewUnit.FormParams.Format = CU->getFormat();
NewUnit.Length = CU->getLength();
NewUnit.Version = CU->getVersion();
if(NewUnit.Version >= 5)
NewUnit.FormParams.Version = CU->getVersion();
if (NewUnit.FormParams.Version >= 5)
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
NewUnit.AddrSize = CU->getAddressByteSize();
NewUnit.FormParams.AddrSize = CU->getAddressByteSize();
for (auto DIE : CU->dies()) {
DWARFYAML::Entry NewEntry;
DataExtractor EntryData = CU->getDebugInfoExtractor();