In the DWARF 4 Spec section 7.2.2, data in many DWARF sections, and some DWARF structures start with "Initial Length Values", which are a 32-bit length, and an optional 64-bit length if the 32 bit value == UINT32_MAX.
This patch abstracts the Initial Length type in YAML, and extends its use to all the DWARF structures that are supported in the DWARFYAML code that have Initial Length values.
llvm-svn: 296911
///
//===----------------------------------------------------------------------===//
-
#ifndef LLVM_OBJECTYAML_DWARFYAML_H
#define LLVM_OBJECTYAML_DWARFYAML_H
namespace llvm {
namespace DWARFYAML {
+struct InitialLength {
+ uint32_t TotalLength;
+ uint64_t TotalLength64;
+
+ bool isDWARF64() const { return TotalLength == UINT32_MAX; }
+
+ uint64_t getLength() const {
+ return isDWARF64() ? TotalLength64 : TotalLength;
+ }
+
+ void setLength(uint64_t Len) {
+ if (Len >= (uint64_t)UINT32_MAX) {
+ TotalLength64 = Len;
+ TotalLength = UINT32_MAX;
+ } else {
+ TotalLength = Len;
+ }
+ }
+};
+
struct AttributeAbbrev {
llvm::dwarf::Attribute Attribute;
llvm::dwarf::Form Form;
};
struct ARange {
- uint32_t Length;
+ InitialLength Length;
uint16_t Version;
uint32_t CuOffset;
uint8_t AddrSize;
struct PubSection {
PubSection() : IsGNUStyle(false) {}
- uint32_t Length;
+ InitialLength Length;
uint16_t Version;
uint32_t UnitOffset;
uint32_t UnitSize;
};
struct Unit {
- uint32_t Length;
+ InitialLength Length;
uint16_t Version;
uint32_t AbbrOffset;
uint8_t AddrSize;
};
struct LineTable {
- uint32_t TotalLength;
- uint64_t TotalLength64;
+ InitialLength Length;
uint16_t Version;
uint64_t PrologueLength;
uint8_t MinInstLength;
PubSection GNUPubNames;
PubSection GNUPubTypes;
-
+
std::vector<Unit> CompileUnits;
std::vector<LineTable> DebugLines;
template <> struct MappingTraits<DWARFYAML::File> {
static void mapping(IO &IO, DWARFYAML::File &File);
};
-
+
template <> struct MappingTraits<DWARFYAML::LineTableOpcode> {
static void mapping(IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode);
};
static void mapping(IO &IO, DWARFYAML::LineTable &LineTable);
};
+template <> struct MappingTraits<DWARFYAML::InitialLength> {
+ static void mapping(IO &IO, DWARFYAML::InitialLength &DWARF);
+};
+
#define HANDLE_DW_TAG(unused, name) \
io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
OS.write(reinterpret_cast<char *>(FillData.data()), Size);
}
+void writeInitialLength(const DWARFYAML::InitialLength &Length, raw_ostream &OS,
+ bool IsLittleEndian) {
+ writeInteger((uint32_t)Length.TotalLength, OS, IsLittleEndian);
+ if (Length.isDWARF64())
+ writeInteger((uint64_t)Length.TotalLength64, OS, IsLittleEndian);
+}
+
void DWARFYAML::EmitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (auto Str : DI.DebugStrings) {
OS.write(Str.data(), Str.size());
void DWARFYAML::EmitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (auto Range : DI.ARanges) {
auto HeaderStart = OS.tell();
- writeInteger((uint32_t)Range.Length, OS, DI.IsLittleEndian);
+ writeInitialLength(Range.Length, OS, DI.IsLittleEndian);
writeInteger((uint16_t)Range.Version, OS, DI.IsLittleEndian);
writeInteger((uint32_t)Range.CuOffset, OS, DI.IsLittleEndian);
writeInteger((uint8_t)Range.AddrSize, OS, DI.IsLittleEndian);
void DWARFYAML::EmitPubSection(raw_ostream &OS,
const DWARFYAML::PubSection &Sect,
bool IsLittleEndian) {
- writeInteger((uint32_t)Sect.Length, OS, IsLittleEndian);
+ writeInitialLength(Sect.Length, OS, IsLittleEndian);
writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian);
writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian);
writeInteger((uint32_t)Sect.UnitSize, OS, IsLittleEndian);
void DWARFYAML::EmitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (auto CU : DI.CompileUnits) {
- writeInteger((uint32_t)CU.Length, OS, DI.IsLittleEndian);
+ writeInitialLength(CU.Length, OS, DI.IsLittleEndian);
writeInteger((uint16_t)CU.Version, OS, DI.IsLittleEndian);
writeInteger((uint32_t)CU.AbbrOffset, OS, DI.IsLittleEndian);
writeInteger((uint8_t)CU.AddrSize, OS, DI.IsLittleEndian);
void DWARFYAML::EmitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (const auto &LineTable : DI.DebugLines) {
- writeInteger((uint32_t)LineTable.TotalLength, OS, DI.IsLittleEndian);
- uint64_t SizeOfPrologueLength = 4;
- if (LineTable.TotalLength == UINT32_MAX) {
- writeInteger((uint64_t)LineTable.TotalLength64, OS, DI.IsLittleEndian);
- SizeOfPrologueLength = 8;
- }
+ writeInitialLength(LineTable.Length, OS, DI.IsLittleEndian);
+ uint64_t SizeOfPrologueLength = LineTable.Length.isDWARF64() ? 8 : 4;
writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
OS, DI.IsLittleEndian);
void MappingTraits<DWARFYAML::LineTable>::mapping(
IO &IO, DWARFYAML::LineTable &LineTable) {
- IO.mapRequired("TotalLength", LineTable.TotalLength);
- if (LineTable.TotalLength == UINT32_MAX)
- IO.mapRequired("TotalLength64", LineTable.TotalLength64);
+ IO.mapRequired("Length", LineTable.Length);
IO.mapRequired("Version", LineTable.Version);
IO.mapRequired("PrologueLength", LineTable.PrologueLength);
IO.mapRequired("MinInstLength", LineTable.MinInstLength);
IO.mapRequired("Opcodes", LineTable.Opcodes);
}
+void MappingTraits<DWARFYAML::InitialLength>::mapping(
+ IO &IO, DWARFYAML::InitialLength &InitialLength) {
+ IO.mapRequired("TotalLength", InitialLength.TotalLength);
+ if (InitialLength.isDWARF64())
+ IO.mapRequired("TotalLength64", InitialLength.TotalLength64);
+}
+
} // namespace llvm::yaml
} // namespace llvm
- _main
DWARF:
debug_aranges:
- - Length: 44
+ - Length:
+ TotalLength: 44
Version: 2
CuOffset: 0
AddrSize: 8
#CHECK: DWARF:
#CHECK: debug_aranges:
-#CHECK: - Length: 44
+#CHECK: - Length:
+#CHECK: TotalLength: 44
#CHECK: Version: 2
#CHECK: CuOffset: 0
#CHECK: AddrSize: 8
- Attribute: DW_AT_type
Form: DW_FORM_ref4
debug_aranges:
- - Length: 44
+ - Length:
+ TotalLength: 44
Version: 2
CuOffset: 0
AddrSize: 8
- Address: 0x0000000100000F50
Length: 52
debug_info:
- - Length: 117
+ - Length:
+ TotalLength: 117
Version: 4
AbbrOffset: 0
AddrSize: 8
- AbbrCode: 0x00000000
Values:
debug_line:
- - TotalLength: 65
+ - Length:
+ TotalLength: 65
Version: 2
PrologueLength: 36
MinInstLength: 1
#CHECK: DWARF:
#CHECK: debug_info:
-#CHECK: - Length: 117
+#CHECK: - Length:
+#CHECK: TotalLength: 117
#CHECK: Version: 4
#CHECK: AbbrOffset: 0
#CHECK: AddrSize: 8
- Attribute: DW_AT_type
Form: DW_FORM_ref4
debug_aranges:
- - Length: 44
+ - Length:
+ TotalLength: 44
Version: 2
CuOffset: 0
AddrSize: 8
- Address: 0x0000000100000F50
Length: 52
debug_pubnames:
- Length: 23
+ Length:
+ TotalLength: 23
Version: 2
UnitOffset: 0
UnitSize: 121
- DieOffset: 0x0000002A
Name: main
debug_pubtypes:
- Length: 31
+ Length:
+ TotalLength: 31
Version: 2
UnitOffset: 0
UnitSize: 121
- DieOffset: 0x00000071
Name: char
debug_info:
- - Length: 117
+ - Length:
+ TotalLength: 117
Version: 4
AbbrOffset: 0
AddrSize: 8
- AbbrCode: 0x00000000
Values:
debug_line:
- - TotalLength: 65
+ - Length:
+ TotalLength: 65
Version: 2
PrologueLength: 36
MinInstLength: 1
...
#CHECK: debug_line:
-#CHECK: - TotalLength: 65
+#CHECK: - Length:
+#CHECK: TotalLength: 65
#CHECK: Version: 2
#CHECK: PrologueLength: 36
#CHECK: MinInstLength: 1
- int
- char
debug_pubnames:
- Length: 23
+ Length:
+ TotalLength: 23
Version: 2
UnitOffset: 0
UnitSize: 121
- DieOffset: 0x0000002A
Name: main
debug_pubtypes:
- Length: 31
+ Length:
+ TotalLength: 31
Version: 2
UnitOffset: 0
UnitSize: 121
#CHECK: DWARF:
#CHECK: debug_pubnames:
-#CHECK: Length: 23
+#CHECK: Length:
+#CHECK: TotalLength: 23
#CHECK: Version: 2
#CHECK: UnitOffset: 0
#CHECK: UnitSize: 121
#CHECK: - DieOffset: 0x0000002A
#CHECK: Name: main
#CHECK: debug_pubtypes:
-#CHECK: Length: 31
+#CHECK: Length:
+#CHECK: TotalLength: 31
#CHECK: Version: 2
#CHECK: UnitOffset: 0
#CHECK: UnitSize: 121
using namespace llvm;
+void dumpInitialLength(DataExtractor &Data, uint32_t &Offset,
+ DWARFYAML::InitialLength &InitialLength) {
+ InitialLength.TotalLength = Data.getU32(&Offset);
+ if (InitialLength.isDWARF64())
+ InitialLength.TotalLength64 = Data.getU64(&Offset);
+}
+
void dumpDebugAbbrev(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
auto AbbrevSetPtr = DCtx.getDebugAbbrev();
if (AbbrevSetPtr) {
while (Set.extract(ArangesData, &Offset)) {
DWARFYAML::ARange Range;
- Range.Length = Set.getHeader().Length;
+ Range.Length.setLength(Set.getHeader().Length);
Range.Version = Set.getHeader().Version;
Range.CuOffset = Set.getHeader().CuOffset;
Range.AddrSize = Set.getHeader().AddrSize;
StringRef Section) {
DataExtractor PubSectionData(Section, DCtx.isLittleEndian(), 0);
uint32_t Offset = 0;
- Y.Length = PubSectionData.getU32(&Offset);
+ dumpInitialLength(PubSectionData, Offset, Y.Length);
Y.Version = PubSectionData.getU16(&Offset);
Y.UnitOffset = PubSectionData.getU32(&Offset);
Y.UnitSize = PubSectionData.getU32(&Offset);
- while (Offset < Y.Length) {
+ while (Offset < Y.Length.getLength()) {
DWARFYAML::PubEntry NewEntry;
NewEntry.DieOffset = PubSectionData.getU32(&Offset);
if (Y.IsGNUStyle)
void dumpDebugInfo(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
for (const auto &CU : DCtx.compile_units()) {
DWARFYAML::Unit NewUnit;
- NewUnit.Length = CU->getLength();
+ NewUnit.Length.setLength(CU->getLength());
NewUnit.Version = CU->getVersion();
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
NewUnit.AddrSize = CU->getAddressByteSize();
DataExtractor LineData(DCtx.getLineSection().Data, DCtx.isLittleEndian(),
CU->getAddressByteSize());
uint32_t Offset = *StmtOffset;
- uint64_t SizeOfPrologueLength = 4;
- DebugLines.TotalLength = LineData.getU32(&Offset);
- uint64_t LineTableLength = DebugLines.TotalLength;
- if (DebugLines.TotalLength == UINT32_MAX) {
- DebugLines.TotalLength64 = LineData.getU64(&Offset);
- LineTableLength = DebugLines.TotalLength64;
- SizeOfPrologueLength = 8;
- }
+ dumpInitialLength(LineData, Offset, DebugLines.Length);
+ uint64_t LineTableLength = DebugLines.Length.getLength();
+ uint64_t SizeOfPrologueLength = DebugLines.Length.isDWARF64() ? 8 : 4;
DebugLines.Version = LineData.getU16(&Offset);
DebugLines.PrologueLength =
LineData.getUnsigned(&Offset, SizeOfPrologueLength);
" Children: DW_CHILDREN_yes\n"
" Attributes:\n"
"debug_info:\n"
- " - Length: 9\n"
+ " - Length:\n"
+ " TotalLength: 9\n"
" Version: 4\n"
" AbbrOffset: 0\n"
" AddrSize: 8\n"