diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.h b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.h --- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.h +++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.h @@ -214,6 +214,9 @@ void writeProloguePayload(const DWARFDebugLine::Prologue &Prologue, AsmPrinter &Asm) const; + // Calculate the number of bytes the Contents will take up. + size_t getContentsSize() const; + llvm::Optional Prologue; std::vector CustomPrologue; std::vector Contents; diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp --- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp @@ -27,6 +27,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptionsCommandFlags.inc" #include "llvm/PassAnalysisSupport.h" +#include "llvm/Support/LEB128.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetLoweringObjectFile.h" @@ -175,7 +176,7 @@ P.TotalLength += 4; P.FormParams.Format = DWARF64; } - P.TotalLength += Contents.size(); + P.TotalLength += getContentsSize(); P.FormParams.Version = Version; P.MinInstLength = 1; P.MaxOpsPerInst = 1; @@ -259,6 +260,24 @@ } } +size_t dwarfgen::LineTable::getContentsSize() const { + size_t Size = 0; + for (auto Entry : Contents) { + switch (Entry.Length) { + case ULEB: + Size += getULEB128Size(Entry.Value); + break; + case SLEB: + Size += getSLEB128Size(Entry.Value); + break; + default: + Size += Entry.Length; + break; + } + } + return Size; +} + MCSymbol *dwarfgen::LineTable::writeDefaultPrologue(AsmPrinter &Asm) const { MCSymbol *UnitStart = Asm.createTempSymbol("line_unit_start"); MCSymbol *UnitEnd = Asm.createTempSymbol("line_unit_end");