diff --git a/llvm/include/llvm/ObjectYAML/DWARFYAML.h b/llvm/include/llvm/ObjectYAML/DWARFYAML.h --- a/llvm/include/llvm/ObjectYAML/DWARFYAML.h +++ b/llvm/include/llvm/ObjectYAML/DWARFYAML.h @@ -120,8 +120,10 @@ }; struct Unit { - dwarf::FormParams FormParams; + dwarf::DwarfFormat Format; Optional Length; + uint16_t Version; + uint8_t AddrSize; llvm::dwarf::UnitType Type; // Added in DWARF 5 yaml::Hex64 AbbrOffset; std::vector Entries; diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp --- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp +++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp @@ -251,7 +251,7 @@ } static Expected writeDIE(ArrayRef AbbrevDecls, - const DWARFYAML::Unit &Unit, + const dwarf::FormParams &Params, const DWARFYAML::Entry &Entry, raw_ostream &OS, bool IsLittleEndian) { uint64_t EntryBegin = OS.tell(); @@ -278,14 +278,14 @@ case dwarf::DW_FORM_addr: // TODO: Test this error. if (Error Err = writeVariableSizedInteger( - FormVal->Value, Unit.FormParams.AddrSize, OS, IsLittleEndian)) + FormVal->Value, Params.AddrSize, OS, IsLittleEndian)) return std::move(Err); break; case dwarf::DW_FORM_ref_addr: // TODO: Test this error. - if (Error Err = writeVariableSizedInteger( - FormVal->Value, Unit.FormParams.getRefAddrByteSize(), OS, - IsLittleEndian)) + if (Error Err = writeVariableSizedInteger(FormVal->Value, + Params.getRefAddrByteSize(), + OS, IsLittleEndian)) return std::move(Err); break; case dwarf::DW_FORM_exprloc: @@ -367,9 +367,9 @@ case dwarf::DW_FORM_GNU_strp_alt: case dwarf::DW_FORM_line_strp: case dwarf::DW_FORM_strp_sup: - cantFail(writeVariableSizedInteger( - FormVal->Value, Unit.FormParams.getDwarfOffsetByteSize(), OS, - IsLittleEndian)); + cantFail(writeVariableSizedInteger(FormVal->Value, + Params.getDwarfOffsetByteSize(), OS, + IsLittleEndian)); break; default: break; @@ -382,10 +382,11 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) { for (const DWARFYAML::Unit &Unit : DI.CompileUnits) { + dwarf::FormParams Params = {Unit.Version, (uint8_t)Unit.AddrSize, + Unit.Format}; uint64_t Length = 3; // sizeof(version) + sizeof(address_size) - Length += Unit.FormParams.Version >= 5 ? 1 : 0; // sizeof(unit_type) - Length += - Unit.FormParams.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset) + Length += Unit.Version >= 5 ? 1 : 0; // sizeof(unit_type) + Length += Params.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 @@ -396,7 +397,7 @@ for (const DWARFYAML::Entry &Entry : Unit.Entries) { if (Expected EntryLength = writeDIE( - DI.AbbrevDecls, Unit, Entry, EntryBufferOS, DI.IsLittleEndian)) + DI.AbbrevDecls, Params, Entry, EntryBufferOS, DI.IsLittleEndian)) Length += *EntryLength; else return EntryLength.takeError(); @@ -407,17 +408,15 @@ if (Unit.Length) Length = *Unit.Length; - writeInitialLength(Unit.FormParams.Format, Length, OS, DI.IsLittleEndian); - writeInteger((uint16_t)Unit.FormParams.Version, OS, DI.IsLittleEndian); - if (Unit.FormParams.Version >= 5) { + writeInitialLength(Unit.Format, Length, OS, DI.IsLittleEndian); + writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian); + if (Unit.Version >= 5) { writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian); - writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian); - writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS, - DI.IsLittleEndian); + writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian); + writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian); } else { - writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS, - DI.IsLittleEndian); - writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian); + writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian); + writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian); } OS.write(EntryBuffer.data(), EntryBuffer.size()); @@ -473,8 +472,7 @@ case dwarf::DW_LNE_set_discriminator: // TODO: Test this error. if (Error Err = writeVariableSizedInteger( - Op.Data, DI.CompileUnits[0].FormParams.AddrSize, OS, - DI.IsLittleEndian)) + Op.Data, DI.CompileUnits[0].AddrSize, OS, DI.IsLittleEndian)) return Err; break; case dwarf::DW_LNE_define_file: diff --git a/llvm/lib/ObjectYAML/DWARFYAML.cpp b/llvm/lib/ObjectYAML/DWARFYAML.cpp --- a/llvm/lib/ObjectYAML/DWARFYAML.cpp +++ b/llvm/lib/ObjectYAML/DWARFYAML.cpp @@ -144,13 +144,13 @@ } void MappingTraits::mapping(IO &IO, DWARFYAML::Unit &Unit) { - IO.mapOptional("Format", Unit.FormParams.Format, dwarf::DWARF32); + IO.mapOptional("Format", Unit.Format, dwarf::DWARF32); IO.mapOptional("Length", Unit.Length); - IO.mapRequired("Version", Unit.FormParams.Version); - if (Unit.FormParams.Version >= 5) + IO.mapRequired("Version", Unit.Version); + if (Unit.Version >= 5) IO.mapRequired("UnitType", Unit.Type); IO.mapRequired("AbbrOffset", Unit.AbbrOffset); - IO.mapRequired("AddrSize", Unit.FormParams.AddrSize); + IO.mapRequired("AddrSize", Unit.AddrSize); IO.mapOptional("Entries", Unit.Entries); } diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp --- a/llvm/tools/obj2yaml/dwarf2yaml.cpp +++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp @@ -167,13 +167,13 @@ void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) { for (const auto &CU : DCtx.compile_units()) { DWARFYAML::Unit NewUnit; - NewUnit.FormParams.Format = CU->getFormat(); + NewUnit.Format = CU->getFormat(); NewUnit.Length = CU->getLength(); - NewUnit.FormParams.Version = CU->getVersion(); - if (NewUnit.FormParams.Version >= 5) + NewUnit.Version = CU->getVersion(); + if (NewUnit.Version >= 5) NewUnit.Type = (dwarf::UnitType)CU->getUnitType(); NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset(); - NewUnit.FormParams.AddrSize = CU->getAddressByteSize(); + NewUnit.AddrSize = CU->getAddressByteSize(); for (auto DIE : CU->dies()) { DWARFYAML::Entry NewEntry; DataExtractor EntryData = CU->getDebugInfoExtractor();