16
16
#include " llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
17
17
#include " llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
18
18
#include " llvm/DebugInfo/DWARF/DWARFDebugLine.h"
19
- #include " llvm/MCCAS/MCCASDebugV1.h"
20
19
#include " llvm/MC/MCAsmBackend.h"
21
20
#include " llvm/MC/MCContext.h"
22
21
#include " llvm/MC/MCObjectFileInfo.h"
22
+ #include " llvm/MCCAS/MCCASDebugV1.h"
23
23
#include " llvm/Support/BinaryStreamWriter.h"
24
+ #include " llvm/Support/Compression.h"
24
25
#include " llvm/Support/Endian.h"
25
26
#include " llvm/Support/EndianStream.h"
26
27
#include < memory>
@@ -1900,7 +1901,13 @@ struct DIEDataWriter : public DataWriter {
1900
1901
// / is described by some DIEAbbrevRef block.
1901
1902
struct DistinctDataWriter : public DataWriter {
1902
1903
Expected<DIEDistinctDataRef> getCASNode (MCCASBuilder &CASBuilder) {
1903
- return DIEDistinctDataRef::create (CASBuilder, toStringRef (Data));
1904
+ SmallVector<uint8_t > CompressedBuff;
1905
+ compression::zlib::compress (arrayRefFromStringRef (toStringRef (Data)),
1906
+ CompressedBuff);
1907
+ // Reserve 8 bytes for ULEB to store the size of the uncompressed data.
1908
+ CompressedBuff.append (8 , 0 );
1909
+ encodeULEB128 (Data.size (), CompressedBuff.end () - 8 , 8 /* Pad to*/ );
1910
+ return DIEDistinctDataRef::create (CASBuilder, toStringRef (CompressedBuff));
1904
1911
}
1905
1912
};
1906
1913
@@ -3413,7 +3420,16 @@ Error mccasformats::v1::visitDebugInfo(
3413
3420
return LoadedTopRef.takeError ();
3414
3421
3415
3422
StringRef DistinctData = LoadedTopRef->DistinctData .getData ();
3416
- BinaryStreamReader DistinctReader (DistinctData, endianness::little);
3423
+ ArrayRef<uint8_t > BuffRef = arrayRefFromStringRef (DistinctData);
3424
+ auto UncompressedSize = decodeULEB128 (BuffRef.data () + BuffRef.size () - 8 );
3425
+ BuffRef = BuffRef.drop_back (8 );
3426
+ SmallVector<uint8_t > OutBuff;
3427
+ if (auto E =
3428
+ compression::zlib::decompress (BuffRef, OutBuff, UncompressedSize))
3429
+ return E;
3430
+ auto UncompressedDistinctData = toStringRef (OutBuff);
3431
+ BinaryStreamReader DistinctReader (UncompressedDistinctData,
3432
+ endianness::little);
3417
3433
ArrayRef<char > HeaderData;
3418
3434
3419
3435
auto BeginOffset = DistinctReader.getOffset ();
@@ -3435,7 +3451,7 @@ Error mccasformats::v1::visitDebugInfo(
3435
3451
HeaderCallback (toStringRef (HeaderData));
3436
3452
3437
3453
append_range (TotAbbrevEntries, LoadedTopRef->AbbrevEntries );
3438
- DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, DistinctData ,
3454
+ DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, UncompressedDistinctData ,
3439
3455
HeaderCallback, StartTagCallback, AttrCallback,
3440
3456
EndTagCallback, NewBlockCallback};
3441
3457
return Visitor.visitDIERef (LoadedTopRef->RootDIE );
0 commit comments