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>
@@ -1905,7 +1906,13 @@ struct DIEDataWriter : public DataWriter {
1905
1906
// / is described by some DIEAbbrevRef block.
1906
1907
struct DistinctDataWriter : public DataWriter {
1907
1908
Expected<DIEDistinctDataRef> getCASNode (MCCASBuilder &CASBuilder) {
1908
- return DIEDistinctDataRef::create (CASBuilder, toStringRef (Data));
1909
+ SmallVector<uint8_t > CompressedBuff;
1910
+ compression::zlib::compress (arrayRefFromStringRef (toStringRef (Data)),
1911
+ CompressedBuff);
1912
+ // Reserve 8 bytes for ULEB to store the size of the uncompressed data.
1913
+ CompressedBuff.append (8 , 0 );
1914
+ encodeULEB128 (Data.size (), CompressedBuff.end () - 8 , 8 /* Pad to*/ );
1915
+ return DIEDistinctDataRef::create (CASBuilder, toStringRef (CompressedBuff));
1909
1916
}
1910
1917
};
1911
1918
@@ -3243,7 +3250,16 @@ Error mccasformats::v1::visitDebugInfo(
3243
3250
return LoadedTopRef.takeError ();
3244
3251
3245
3252
StringRef DistinctData = LoadedTopRef->DistinctData .getData ();
3246
- BinaryStreamReader DistinctReader (DistinctData, endianness::little);
3253
+ ArrayRef<uint8_t > BuffRef = arrayRefFromStringRef (DistinctData);
3254
+ auto UncompressedSize = decodeULEB128 (BuffRef.data () + BuffRef.size () - 8 );
3255
+ BuffRef = BuffRef.drop_back (8 );
3256
+ SmallVector<uint8_t > OutBuff;
3257
+ if (auto E =
3258
+ compression::zlib::decompress (BuffRef, OutBuff, UncompressedSize))
3259
+ return E;
3260
+ auto UncompressedDistinctData = toStringRef (OutBuff);
3261
+ BinaryStreamReader DistinctReader (UncompressedDistinctData,
3262
+ endianness::little);
3247
3263
ArrayRef<char > HeaderData;
3248
3264
3249
3265
auto BeginOffset = DistinctReader.getOffset ();
@@ -3265,7 +3281,7 @@ Error mccasformats::v1::visitDebugInfo(
3265
3281
HeaderCallback (toStringRef (HeaderData));
3266
3282
3267
3283
append_range (TotAbbrevEntries, LoadedTopRef->AbbrevEntries );
3268
- DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, DistinctData ,
3284
+ DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, UncompressedDistinctData ,
3269
3285
HeaderCallback, StartTagCallback, AttrCallback,
3270
3286
EndTagCallback, NewBlockCallback};
3271
3287
return Visitor.visitDIERef (LoadedTopRef->RootDIE );
0 commit comments