forked from OSchip/llvm-project
[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:
parent
a85ca6be2a
commit
bbb057c49a
|
@ -119,12 +119,10 @@ struct DWARFContext {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Unit {
|
struct Unit {
|
||||||
dwarf::DwarfFormat Format;
|
dwarf::FormParams FormParams;
|
||||||
Optional<yaml::Hex64> Length;
|
Optional<yaml::Hex64> Length;
|
||||||
uint16_t Version;
|
|
||||||
llvm::dwarf::UnitType Type; // Added in DWARF 5
|
llvm::dwarf::UnitType Type; // Added in DWARF 5
|
||||||
yaml::Hex64 AbbrOffset;
|
yaml::Hex64 AbbrOffset;
|
||||||
uint8_t AddrSize;
|
|
||||||
std::vector<Entry> Entries;
|
std::vector<Entry> Entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -207,16 +207,6 @@ Error DWARFYAML::emitPubSection(raw_ostream &OS,
|
||||||
return Error::success();
|
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,
|
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
|
||||||
const DWARFYAML::Unit &Unit,
|
const DWARFYAML::Unit &Unit,
|
||||||
const DWARFYAML::Entry &Entry,
|
const DWARFYAML::Entry &Entry,
|
||||||
|
@ -244,14 +234,15 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
|
||||||
switch (Form) {
|
switch (Form) {
|
||||||
case dwarf::DW_FORM_addr:
|
case dwarf::DW_FORM_addr:
|
||||||
// TODO: Test this error.
|
// TODO: Test this error.
|
||||||
if (Error Err = writeVariableSizedInteger(FormVal->Value, Unit.AddrSize,
|
if (Error Err = writeVariableSizedInteger(
|
||||||
OS, IsLittleEndian))
|
FormVal->Value, Unit.FormParams.AddrSize, OS, IsLittleEndian))
|
||||||
return std::move(Err);
|
return std::move(Err);
|
||||||
break;
|
break;
|
||||||
case dwarf::DW_FORM_ref_addr:
|
case dwarf::DW_FORM_ref_addr:
|
||||||
// TODO: Test this error.
|
// TODO: Test this error.
|
||||||
if (Error Err = writeVariableSizedInteger(
|
if (Error Err = writeVariableSizedInteger(
|
||||||
FormVal->Value, getRefSize(Unit), OS, IsLittleEndian))
|
FormVal->Value, Unit.FormParams.getRefAddrByteSize(), OS,
|
||||||
|
IsLittleEndian))
|
||||||
return std::move(Err);
|
return std::move(Err);
|
||||||
break;
|
break;
|
||||||
case dwarf::DW_FORM_exprloc:
|
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_GNU_strp_alt:
|
||||||
case dwarf::DW_FORM_line_strp:
|
case dwarf::DW_FORM_line_strp:
|
||||||
case dwarf::DW_FORM_strp_sup:
|
case dwarf::DW_FORM_strp_sup:
|
||||||
// TODO: Test this error.
|
cantFail(writeVariableSizedInteger(
|
||||||
if (Error Err = writeVariableSizedInteger(
|
FormVal->Value, Unit.FormParams.getDwarfOffsetByteSize(), OS,
|
||||||
FormVal->Value, getOffsetSize(Unit), OS, IsLittleEndian))
|
IsLittleEndian));
|
||||||
return std::move(Err);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -350,9 +340,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
|
||||||
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
||||||
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
|
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
|
||||||
uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
|
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 +=
|
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
|
// Since the length of the current compilation unit is undetermined yet, we
|
||||||
// firstly write the content of the compilation unit to a buffer to
|
// 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)
|
if (Unit.Length)
|
||||||
Length = *Unit.Length;
|
Length = *Unit.Length;
|
||||||
|
|
||||||
writeInitialLength(Unit.Format, Length, OS, DI.IsLittleEndian);
|
writeInitialLength(Unit.FormParams.Format, Length, OS, DI.IsLittleEndian);
|
||||||
writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian);
|
writeInteger((uint16_t)Unit.FormParams.Version, OS, DI.IsLittleEndian);
|
||||||
if (Unit.Version >= 5) {
|
if (Unit.FormParams.Version >= 5) {
|
||||||
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
|
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
|
||||||
writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
|
writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
|
||||||
writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
|
writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
|
||||||
|
DI.IsLittleEndian);
|
||||||
} else {
|
} else {
|
||||||
writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
|
writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
|
||||||
writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
|
DI.IsLittleEndian);
|
||||||
|
writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
|
||||||
}
|
}
|
||||||
|
|
||||||
OS.write(EntryBuffer.data(), EntryBuffer.size());
|
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:
|
case dwarf::DW_LNE_set_discriminator:
|
||||||
// TODO: Test this error.
|
// TODO: Test this error.
|
||||||
if (Error Err = writeVariableSizedInteger(
|
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;
|
return Err;
|
||||||
break;
|
break;
|
||||||
case dwarf::DW_LNE_define_file:
|
case dwarf::DW_LNE_define_file:
|
||||||
|
|
|
@ -142,13 +142,13 @@ void MappingTraits<DWARFYAML::PubSection>::mapping(
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
|
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.mapOptional("Length", Unit.Length);
|
||||||
IO.mapRequired("Version", Unit.Version);
|
IO.mapRequired("Version", Unit.FormParams.Version);
|
||||||
if (Unit.Version >= 5)
|
if (Unit.FormParams.Version >= 5)
|
||||||
IO.mapRequired("UnitType", Unit.Type);
|
IO.mapRequired("UnitType", Unit.Type);
|
||||||
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
|
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
|
||||||
IO.mapRequired("AddrSize", Unit.AddrSize);
|
IO.mapRequired("AddrSize", Unit.FormParams.AddrSize);
|
||||||
IO.mapOptional("Entries", Unit.Entries);
|
IO.mapOptional("Entries", Unit.Entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,13 +165,13 @@ void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
||||||
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
|
||||||
for (const auto &CU : DCtx.compile_units()) {
|
for (const auto &CU : DCtx.compile_units()) {
|
||||||
DWARFYAML::Unit NewUnit;
|
DWARFYAML::Unit NewUnit;
|
||||||
NewUnit.Format = CU->getFormat();
|
NewUnit.FormParams.Format = CU->getFormat();
|
||||||
NewUnit.Length = CU->getLength();
|
NewUnit.Length = CU->getLength();
|
||||||
NewUnit.Version = CU->getVersion();
|
NewUnit.FormParams.Version = CU->getVersion();
|
||||||
if(NewUnit.Version >= 5)
|
if (NewUnit.FormParams.Version >= 5)
|
||||||
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
|
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
|
||||||
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
|
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
|
||||||
NewUnit.AddrSize = CU->getAddressByteSize();
|
NewUnit.FormParams.AddrSize = CU->getAddressByteSize();
|
||||||
for (auto DIE : CU->dies()) {
|
for (auto DIE : CU->dies()) {
|
||||||
DWARFYAML::Entry NewEntry;
|
DWARFYAML::Entry NewEntry;
|
||||||
DataExtractor EntryData = CU->getDebugInfoExtractor();
|
DataExtractor EntryData = CU->getDebugInfoExtractor();
|
||||||
|
|
Loading…
Reference in New Issue