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 @@ -190,11 +190,11 @@ std::vector Values; }; -struct Rnglist { - std::vector Entries; +template struct ListEntries { + std::vector Entries; }; -struct RnglistTable { +template struct ListTable { dwarf::DwarfFormat Format; Optional Length; yaml::Hex16 Version; @@ -202,7 +202,7 @@ yaml::Hex8 SegSelectorSize; Optional OffsetEntryCount; Optional> Offsets; - std::vector Lists; + std::vector> Lists; }; struct Data { @@ -223,7 +223,7 @@ std::vector CompileUnits; std::vector DebugLines; - Optional> DebugRnglists; + Optional>> DebugRnglists; bool isEmpty() const; @@ -249,8 +249,10 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::SegAddrPair) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::AddrTableEntry) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::StringOffsetsTable) -LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::RnglistTable) -LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::Rnglist) +LLVM_YAML_IS_SEQUENCE_VECTOR( + llvm::DWARFYAML::ListTable) +LLVM_YAML_IS_SEQUENCE_VECTOR( + llvm::DWARFYAML::ListEntries) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::RnglistEntry) namespace llvm { @@ -320,12 +322,14 @@ static void mapping(IO &IO, DWARFYAML::SegAddrPair &SegAddrPair); }; -template <> struct MappingTraits { - static void mapping(IO &IO, DWARFYAML::RnglistTable &RnglistTable); +template +struct MappingTraits> { + static void mapping(IO &IO, DWARFYAML::ListTable &ListTable); }; -template <> struct MappingTraits { - static void mapping(IO &IO, DWARFYAML::Rnglist &Rnglist); +template +struct MappingTraits> { + static void mapping(IO &IO, DWARFYAML::ListEntries &ListEntries); }; template <> struct MappingTraits { 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 @@ -13,6 +13,7 @@ #include "llvm/ObjectYAML/DWARFEmitter.h" #include "DWARFVisitor.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Dwarf.h" @@ -441,9 +442,10 @@ return Error::success(); } -static Expected -writeRnglistEntry(raw_ostream &OS, const DWARFYAML::RnglistEntry &Entry, - uint8_t AddrSize, bool IsLittleEndian) { +static Expected writeListEntry(raw_ostream &OS, + const DWARFYAML::RnglistEntry &Entry, + uint8_t AddrSize, + bool IsLittleEndian) { uint64_t BeginOffset = OS.tell(); writeInteger((uint8_t)Entry.Operator, OS, IsLittleEndian); @@ -515,9 +517,11 @@ return OS.tell() - BeginOffset; } -Error DWARFYAML::emitDebugRnglists(raw_ostream &OS, const Data &DI) { - assert(DI.DebugRnglists && "unexpected emitDebugRnglists() call"); - for (const DWARFYAML::RnglistTable &Table : *DI.DebugRnglists) { +template +Error writeDWARFLists(raw_ostream &OS, + ArrayRef> Tables, + bool IsLittleEndian, bool Is64BitAddrSize) { + for (const DWARFYAML::ListTable &Table : Tables) { // sizeof(version) + sizeof(address_size) + sizeof(segment_selector_size) + // sizeof(offset_entry_count) = 8 uint64_t Length = 8; @@ -526,24 +530,25 @@ if (Table.AddrSize) AddrSize = *Table.AddrSize; else - AddrSize = DI.Is64BitAddrSize ? 8 : 4; + AddrSize = Is64BitAddrSize ? 8 : 4; - // Since the length of the current range lists entry is undetermined yet, we - // firstly write the content of the range lists to a buffer to calculate the - // length and then serialize the buffer content to the actual output stream. + // Since the length of the current range/location lists entry is + // undetermined yet, we firstly write the content of the range/location + // lists to a buffer to calculate the length and then serialize the buffer + // content to the actual output stream. std::string ListBuffer; raw_string_ostream ListBufferOS(ListBuffer); - // Offsets holds offsets for each range list. The i-th element is the offset - // from the beginning of the first range list to the location of the i-th - // range list. + // Offsets holds offsets for each range/location list. The i-th element is + // the offset from the beginning of the first range/location list to the + // location of the i-th range list. std::vector Offsets; - for (const DWARFYAML::Rnglist &List : Table.Lists) { + for (const DWARFYAML::ListEntries &List : Table.Lists) { Offsets.push_back(ListBufferOS.tell()); - for (const DWARFYAML::RnglistEntry &Entry : List.Entries) { + for (const EntryType &Entry : List.Entries) { Expected EntrySize = - writeRnglistEntry(ListBufferOS, Entry, AddrSize, DI.IsLittleEndian); + writeListEntry(ListBufferOS, Entry, AddrSize, IsLittleEndian); if (!EntrySize) return EntrySize.takeError(); Length += *EntrySize; @@ -568,17 +573,17 @@ if (Table.Length) Length = *Table.Length; - writeInitialLength(Table.Format, Length, OS, DI.IsLittleEndian); - writeInteger((uint16_t)Table.Version, OS, DI.IsLittleEndian); - writeInteger((uint8_t)AddrSize, OS, DI.IsLittleEndian); - writeInteger((uint8_t)Table.SegSelectorSize, OS, DI.IsLittleEndian); - writeInteger((uint32_t)OffsetEntryCount, OS, DI.IsLittleEndian); + writeInitialLength(Table.Format, Length, OS, IsLittleEndian); + writeInteger((uint16_t)Table.Version, OS, IsLittleEndian); + writeInteger((uint8_t)AddrSize, OS, IsLittleEndian); + writeInteger((uint8_t)Table.SegSelectorSize, OS, IsLittleEndian); + writeInteger((uint32_t)OffsetEntryCount, OS, IsLittleEndian); auto EmitOffsets = [&](ArrayRef Offsets, uint64_t OffsetsSize) { for (uint64_t Offset : Offsets) { cantFail(writeVariableSizedInteger( OffsetsSize + Offset, Table.Format == dwarf::DWARF64 ? 8 : 4, OS, - DI.IsLittleEndian)); + IsLittleEndian)); } }; @@ -595,6 +600,12 @@ return Error::success(); } +Error DWARFYAML::emitDebugRnglists(raw_ostream &OS, const Data &DI) { + assert(DI.DebugRnglists && "unexpected emitDebugRnglists() call"); + return writeDWARFLists( + OS, *DI.DebugRnglists, DI.IsLittleEndian, DI.Is64BitAddrSize); +} + using EmitFuncType = Error (*)(raw_ostream &, const DWARFYAML::Data &); static Error 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 @@ -242,21 +242,23 @@ IO.mapOptional("Values", RnglistEntry.Values); } -void MappingTraits::mapping(IO &IO, - DWARFYAML::Rnglist &Rnglist) { - IO.mapOptional("Entries", Rnglist.Entries); +template +void MappingTraits>::mapping( + IO &IO, DWARFYAML::ListEntries &ListEntries) { + IO.mapOptional("Entries", ListEntries.Entries); } -void MappingTraits::mapping( - IO &IO, DWARFYAML::RnglistTable &RnglistTable) { - IO.mapOptional("Format", RnglistTable.Format, dwarf::DWARF32); - IO.mapOptional("Length", RnglistTable.Length); - IO.mapOptional("Version", RnglistTable.Version, 5); - IO.mapOptional("AddressSize", RnglistTable.AddrSize); - IO.mapOptional("SegmentSelectorSize", RnglistTable.SegSelectorSize, 0); - IO.mapOptional("OffsetEntryCount", RnglistTable.OffsetEntryCount); - IO.mapOptional("Offsets", RnglistTable.Offsets); - IO.mapOptional("Lists", RnglistTable.Lists); +template +void MappingTraits>::mapping( + IO &IO, DWARFYAML::ListTable &ListTable) { + IO.mapOptional("Format", ListTable.Format, dwarf::DWARF32); + IO.mapOptional("Length", ListTable.Length); + IO.mapOptional("Version", ListTable.Version, 5); + IO.mapOptional("AddressSize", ListTable.AddrSize); + IO.mapOptional("SegmentSelectorSize", ListTable.SegSelectorSize, 0); + IO.mapOptional("OffsetEntryCount", ListTable.OffsetEntryCount); + IO.mapOptional("Offsets", ListTable.Offsets); + IO.mapOptional("Lists", ListTable.Lists); } void MappingTraits::mapping(