diff options
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Native')
20 files changed, 127 insertions, 131 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp index 51a868f8770..d8169434143 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiStream.cpp @@ -10,8 +10,6 @@ #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/ADT/StringRef.h" #include "llvm/DebugInfo/MSF/BinaryStreamArray.h" -#include "llvm/DebugInfo/MSF/BinaryStreamArray.h" -#include "llvm/DebugInfo/MSF/BinaryStreamReader.h" #include "llvm/DebugInfo/MSF/BinaryStreamReader.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h" @@ -36,7 +34,7 @@ using namespace llvm::support; template <typename ContribType> static Error loadSectionContribs(FixedStreamArray<ContribType> &Output, - BinaryStreamReader &Reader) { + StreamReader &Reader) { if (Reader.bytesRemaining() % sizeof(ContribType) != 0) return make_error<RawError>( raw_error_code::corrupt_file, @@ -54,7 +52,7 @@ DbiStream::DbiStream(PDBFile &File, std::unique_ptr<MappedBlockStream> Stream) DbiStream::~DbiStream() = default; Error DbiStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); if (Stream->getLength() < sizeof(DbiStreamHeader)) return make_error<RawError>(raw_error_code::corrupt_file, @@ -147,7 +145,7 @@ Error DbiStream::reload() { "Found unexpected bytes in DBI Stream."); if (ECSubstream.getLength() > 0) { - BinaryStreamReader ECReader(ECSubstream); + StreamReader ECReader(ECSubstream); if (auto EC = ECNames.load(ECReader)) return EC; } @@ -209,16 +207,16 @@ PDB_Machine DbiStream::getMachineType() const { return static_cast<PDB_Machine>(Machine); } -FixedStreamArray<object::coff_section> DbiStream::getSectionHeaders() { +msf::FixedStreamArray<object::coff_section> DbiStream::getSectionHeaders() { return SectionHeaders; } -FixedStreamArray<object::FpoData> DbiStream::getFpoRecords() { +msf::FixedStreamArray<object::FpoData> DbiStream::getFpoRecords() { return FpoRecords; } ArrayRef<ModuleInfoEx> DbiStream::modules() const { return ModuleInfos; } -FixedStreamArray<SecMapEntry> DbiStream::getSectionMap() const { +msf::FixedStreamArray<SecMapEntry> DbiStream::getSectionMap() const { return SectionMap; } @@ -237,8 +235,8 @@ Error DbiStream::initializeSectionContributionData() { if (SecContrSubstream.getLength() == 0) return Error::success(); - BinaryStreamReader SCReader(SecContrSubstream); - if (auto EC = SCReader.readEnum(SectionContribVersion)) + StreamReader SCReader(SecContrSubstream); + if (auto EC = SCReader.readEnum(SectionContribVersion, llvm::support::little)) return EC; if (SectionContribVersion == DbiSecContribVer60) @@ -256,7 +254,7 @@ Error DbiStream::initializeModInfoArray() { // Since each ModInfo in the stream is a variable length, we have to iterate // them to know how many there actually are. - BinaryStreamReader Reader(ModInfoSubstream); + StreamReader Reader(ModInfoSubstream); VarStreamArray<ModInfo> ModInfoArray; if (auto EC = Reader.readArray(ModInfoArray, ModInfoSubstream.getLength())) @@ -286,7 +284,7 @@ Error DbiStream::initializeSectionHeadersData() { "Corrupted section header stream."); size_t NumSections = StreamLen / sizeof(object::coff_section); - BinaryStreamReader Reader(*SHS); + msf::StreamReader Reader(*SHS); if (auto EC = Reader.readArray(SectionHeaders, NumSections)) return make_error<RawError>(raw_error_code::corrupt_file, "Could not read a bitmap."); @@ -318,7 +316,7 @@ Error DbiStream::initializeFpoRecords() { "Corrupted New FPO stream."); size_t NumRecords = StreamLen / sizeof(object::FpoData); - BinaryStreamReader Reader(*FS); + msf::StreamReader Reader(*FS); if (auto EC = Reader.readArray(FpoRecords, NumRecords)) return make_error<RawError>(raw_error_code::corrupt_file, "Corrupted New FPO stream."); @@ -330,7 +328,7 @@ Error DbiStream::initializeSectionMapData() { if (SecMapSubstream.getLength() == 0) return Error::success(); - BinaryStreamReader SMReader(SecMapSubstream); + StreamReader SMReader(SecMapSubstream); const SecMapHeader *Header; if (auto EC = SMReader.readObject(Header)) return EC; @@ -344,7 +342,7 @@ Error DbiStream::initializeFileInfo() { return Error::success(); const FileInfoSubstreamHeader *FH; - BinaryStreamReader FISR(FileInfoSubstream); + StreamReader FISR(FileInfoSubstream); if (auto EC = FISR.readObject(FH)) return EC; @@ -413,14 +411,14 @@ uint32_t DbiStream::getDebugStreamIndex(DbgHeaderType Type) const { } Expected<StringRef> DbiStream::getFileNameForIndex(uint32_t Index) const { - BinaryStreamReader Names(NamesBuffer); + StreamReader Names(NamesBuffer); if (Index >= FileNameOffsets.size()) return make_error<RawError>(raw_error_code::index_out_of_bounds); uint32_t FileOffset = FileNameOffsets[Index]; Names.setOffset(FileOffset); StringRef Name; - if (auto EC = Names.readCString(Name)) + if (auto EC = Names.readZeroString(Name)) return std::move(EC); return Name; } diff --git a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp index ac40330c5dc..60687ac23b0 100644 --- a/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp @@ -11,7 +11,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" -#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/DebugInfo/MSF/MSFBuilder.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" @@ -154,19 +153,18 @@ Error DbiStreamBuilder::generateModiSubstream() { uint32_t Size = calculateModiSubstreamSize(); auto Data = Allocator.Allocate<uint8_t>(Size); - ModInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size), - llvm::support::little); + ModInfoBuffer = MutableByteStream(MutableArrayRef<uint8_t>(Data, Size)); - BinaryStreamWriter ModiWriter(ModInfoBuffer); + StreamWriter ModiWriter(ModInfoBuffer); for (const auto &M : ModuleInfoList) { ModuleInfoHeader Layout = {}; Layout.ModDiStream = kInvalidStreamIndex; Layout.NumFiles = M->SourceFiles.size(); if (auto EC = ModiWriter.writeObject(Layout)) return EC; - if (auto EC = ModiWriter.writeCString(M->Mod)) + if (auto EC = ModiWriter.writeZeroString(M->Mod)) return EC; - if (auto EC = ModiWriter.writeCString(M->Obj)) + if (auto EC = ModiWriter.writeZeroString(M->Obj)) return EC; } if (ModiWriter.bytesRemaining() > sizeof(uint32_t)) @@ -181,26 +179,29 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { auto Data = Allocator.Allocate<uint8_t>(Size); uint32_t NamesOffset = Size - NameSize; - FileInfoBuffer = MutableBinaryByteStream(MutableArrayRef<uint8_t>(Data, Size), - llvm::support::little); + FileInfoBuffer = MutableByteStream(MutableArrayRef<uint8_t>(Data, Size)); - WritableBinaryStreamRef MetadataBuffer = - WritableBinaryStreamRef(FileInfoBuffer).keep_front(NamesOffset); - BinaryStreamWriter MetadataWriter(MetadataBuffer); + WritableStreamRef MetadataBuffer = + WritableStreamRef(FileInfoBuffer).keep_front(NamesOffset); + StreamWriter MetadataWriter(MetadataBuffer); uint16_t ModiCount = std::min<uint32_t>(UINT16_MAX, ModuleInfos.size()); uint16_t FileCount = std::min<uint32_t>(UINT16_MAX, SourceFileNames.size()); - if (auto EC = MetadataWriter.writeInteger(ModiCount)) // NumModules + if (auto EC = MetadataWriter.writeInteger( + ModiCount, llvm::support::little)) // NumModules return EC; - if (auto EC = MetadataWriter.writeInteger(FileCount)) // NumSourceFiles + if (auto EC = MetadataWriter.writeInteger( + FileCount, llvm::support::little)) // NumSourceFiles return EC; for (uint16_t I = 0; I < ModiCount; ++I) { - if (auto EC = MetadataWriter.writeInteger(I)) // Mod Indices + if (auto EC = MetadataWriter.writeInteger( + I, llvm::support::little)) // Mod Indices return EC; } for (const auto MI : ModuleInfoList) { FileCount = static_cast<uint16_t>(MI->SourceFiles.size()); - if (auto EC = MetadataWriter.writeInteger(FileCount)) // Mod File Counts + if (auto EC = MetadataWriter.writeInteger( + FileCount, llvm::support::little)) // Mod File Counts return EC; } @@ -208,11 +209,11 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { // A side effect of this is that this will actually compute the various // file name offsets, so we can then go back and write the FileNameOffsets // array to the other substream. - NamesBuffer = WritableBinaryStreamRef(FileInfoBuffer).drop_front(NamesOffset); - BinaryStreamWriter NameBufferWriter(NamesBuffer); + NamesBuffer = WritableStreamRef(FileInfoBuffer).drop_front(NamesOffset); + StreamWriter NameBufferWriter(NamesBuffer); for (auto &Name : SourceFileNames) { Name.second = NameBufferWriter.getOffset(); - if (auto EC = NameBufferWriter.writeCString(Name.getKey())) + if (auto EC = NameBufferWriter.writeZeroString(Name.getKey())) return EC; } @@ -222,7 +223,8 @@ Error DbiStreamBuilder::generateFileInfoSubstream() { if (Result == SourceFileNames.end()) return make_error<RawError>(raw_error_code::no_entry, "The source file was not found."); - if (auto EC = MetadataWriter.writeInteger(Result->second)) + if (auto EC = MetadataWriter.writeInteger(Result->second, + llvm::support::little)) return EC; } } @@ -361,14 +363,14 @@ std::vector<SecMapEntry> DbiStreamBuilder::createSectionMap( } Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, - WritableBinaryStreamRef Buffer) { + const msf::WritableStream &Buffer) { if (auto EC = finalize()) return EC; auto InfoS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamDBI); - BinaryStreamWriter Writer(*InfoS); + StreamWriter Writer(*InfoS); if (auto EC = Writer.writeObject(*Header)) return EC; @@ -376,7 +378,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; if (!SectionContribs.empty()) { - if (auto EC = Writer.writeEnum(DbiSecContribVer60)) + if (auto EC = Writer.writeEnum(DbiSecContribVer60, llvm::support::little)) return EC; if (auto EC = Writer.writeArray(SectionContribs)) return EC; @@ -395,7 +397,8 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, return EC; for (auto &Stream : DbgStreams) - if (auto EC = Writer.writeInteger(Stream.StreamNumber)) + if (auto EC = + Writer.writeInteger(Stream.StreamNumber, llvm::support::little)) return EC; for (auto &Stream : DbgStreams) { @@ -403,7 +406,7 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout, continue; auto WritableStream = WritableMappedBlockStream::createIndexedStream( Layout, Buffer, Stream.StreamNumber); - BinaryStreamWriter DbgStreamWriter(*WritableStream); + StreamWriter DbgStreamWriter(*WritableStream); if (auto EC = DbgStreamWriter.writeArray(Stream.Data)) return EC; } diff --git a/llvm/lib/DebugInfo/PDB/Native/GSI.cpp b/llvm/lib/DebugInfo/PDB/Native/GSI.cpp index 3a7e1e1529f..5a727910e20 100644 --- a/llvm/lib/DebugInfo/PDB/Native/GSI.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/GSI.cpp @@ -28,9 +28,9 @@ static Error checkHashHdrVersion(const GSIHashHeader *HashHdr) { return Error::success(); } -Error readGSIHashBuckets(FixedStreamArray<support::ulittle32_t> &HashBuckets, - const GSIHashHeader *HashHdr, - BinaryStreamReader &Reader) { +Error readGSIHashBuckets( + msf::FixedStreamArray<support::ulittle32_t> &HashBuckets, + const GSIHashHeader *HashHdr, msf::StreamReader &Reader) { if (auto EC = checkHashHdrVersion(HashHdr)) return EC; @@ -57,7 +57,7 @@ Error readGSIHashBuckets(FixedStreamArray<support::ulittle32_t> &HashBuckets, } Error readGSIHashHeader(const GSIHashHeader *&HashHdr, - BinaryStreamReader &Reader) { + msf::StreamReader &Reader) { if (Reader.readObject(HashHdr)) return make_error<RawError>(raw_error_code::corrupt_file, "Stream does not contain a GSIHashHeader."); @@ -70,9 +70,9 @@ Error readGSIHashHeader(const GSIHashHeader *&HashHdr, return Error::success(); } -Error readGSIHashRecords(FixedStreamArray<PSHashRecord> &HashRecords, +Error readGSIHashRecords(msf::FixedStreamArray<PSHashRecord> &HashRecords, const GSIHashHeader *HashHdr, - BinaryStreamReader &Reader) { + msf::StreamReader &Reader) { if (auto EC = checkHashHdrVersion(HashHdr)) return EC; diff --git a/llvm/lib/DebugInfo/PDB/Native/GSI.h b/llvm/lib/DebugInfo/PDB/Native/GSI.h index f47321a2f14..5c5596c0484 100644 --- a/llvm/lib/DebugInfo/PDB/Native/GSI.h +++ b/llvm/lib/DebugInfo/PDB/Native/GSI.h @@ -33,7 +33,9 @@ namespace llvm { -class BinaryStreamReader; +namespace msf { +class StreamReader; +} namespace pdb { @@ -54,14 +56,14 @@ struct GSIHashHeader { support::ulittle32_t NumBuckets; }; -Error readGSIHashBuckets(FixedStreamArray<support::ulittle32_t> &HashBuckets, - const GSIHashHeader *HashHdr, - BinaryStreamReader &Reader); +Error readGSIHashBuckets( + msf::FixedStreamArray<support::ulittle32_t> &HashBuckets, + const GSIHashHeader *HashHdr, msf::StreamReader &Reader); Error readGSIHashHeader(const GSIHashHeader *&HashHdr, - BinaryStreamReader &Reader); -Error readGSIHashRecords(FixedStreamArray<PSHashRecord> &HashRecords, + msf::StreamReader &Reader); +Error readGSIHashRecords(msf::FixedStreamArray<PSHashRecord> &HashRecords, const GSIHashHeader *HashHdr, - BinaryStreamReader &Reader); + msf::StreamReader &Reader); } } diff --git a/llvm/lib/DebugInfo/PDB/Native/GlobalsStream.cpp b/llvm/lib/DebugInfo/PDB/Native/GlobalsStream.cpp index 7d6d39d43d2..d5c80ba42b5 100644 --- a/llvm/lib/DebugInfo/PDB/Native/GlobalsStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/GlobalsStream.cpp @@ -23,7 +23,7 @@ GlobalsStream::GlobalsStream(std::unique_ptr<MappedBlockStream> Stream) GlobalsStream::~GlobalsStream() = default; Error GlobalsStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); const GSIHashHeader *HashHdr; if (auto EC = readGSIHashHeader(HashHdr, Reader)) diff --git a/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp b/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp index ebf8c9c04db..dd95c078d7e 100644 --- a/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/HashTable.cpp @@ -22,7 +22,7 @@ HashTable::HashTable() : HashTable(8) {} HashTable::HashTable(uint32_t Capacity) { Buckets.resize(Capacity); } -Error HashTable::load(BinaryStreamReader &Stream) { +Error HashTable::load(msf::StreamReader &Stream) { const Header *H; if (auto EC = Stream.readObject(H)) return EC; @@ -48,9 +48,9 @@ Error HashTable::load(BinaryStreamReader &Stream) { "Present bit vector interesects deleted!"); for (uint32_t P : Present) { - if (auto EC = Stream.readInteger(Buckets[P].first)) + if (auto EC = Stream.readInteger(Buckets[P].first, llvm::support::little)) return EC; - if (auto EC = Stream.readInteger(Buckets[P].second)) + if (auto EC = Stream.readInteger(Buckets[P].second, llvm::support::little)) return EC; } @@ -77,7 +77,7 @@ uint32_t HashTable::calculateSerializedLength() const { return Size; } -Error HashTable::commit(BinaryStreamWriter &Writer) const { +Error HashTable::commit(msf::StreamWriter &Writer) const { Header H; H.Size = size(); H.Capacity = capacity(); @@ -91,9 +91,9 @@ Error HashTable::commit(BinaryStreamWriter &Writer) const { return EC; for (const auto &Entry : *this) { - if (auto EC = Writer.writeInteger(Entry.first)) + if (auto EC = Writer.writeInteger(Entry.first, llvm::support::little)) return EC; - if (auto EC = Writer.writeInteger(Entry.second)) + if (auto EC = Writer.writeInteger(Entry.second, llvm::support::little)) return EC; } return Error::success(); @@ -209,10 +209,10 @@ void HashTable::grow() { assert(size() == S); } -Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, +Error HashTable::readSparseBitVector(msf::StreamReader &Stream, SparseBitVector<> &V) { uint32_t NumWords; - if (auto EC = Stream.readInteger(NumWords)) + if (auto EC = Stream.readInteger(NumWords, llvm::support::little)) return joinErrors( std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, @@ -220,7 +220,7 @@ Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, for (uint32_t I = 0; I != NumWords; ++I) { uint32_t Word; - if (auto EC = Stream.readInteger(Word)) + if (auto EC = Stream.readInteger(Word, llvm::support::little)) return joinErrors(std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, "Expected hash table word")); @@ -231,11 +231,11 @@ Error HashTable::readSparseBitVector(BinaryStreamReader &Stream, return Error::success(); } -Error HashTable::writeSparseBitVector(BinaryStreamWriter &Writer, +Error HashTable::writeSparseBitVector(msf::StreamWriter &Writer, SparseBitVector<> &Vec) { int ReqBits = Vec.find_last() + 1; uint32_t NumWords = alignTo(ReqBits, sizeof(uint32_t)) / sizeof(uint32_t); - if (auto EC = Writer.writeInteger(NumWords)) + if (auto EC = Writer.writeInteger(NumWords, llvm::support::little)) return joinErrors( std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, @@ -248,7 +248,7 @@ Error HashTable::writeSparseBitVector(BinaryStreamWriter &Writer, if (Vec.test(Idx)) Word |= (1 << WordIdx); } - if (auto EC = Writer.writeInteger(Word)) + if (auto EC = Writer.writeInteger(Word, llvm::support::little)) return joinErrors(std::move(EC), make_error<RawError>( raw_error_code::corrupt_file, "Could not write linear map word")); diff --git a/llvm/lib/DebugInfo/PDB/Native/InfoStream.cpp b/llvm/lib/DebugInfo/PDB/Native/InfoStream.cpp index 9c4fca7aa5e..692099256d8 100644 --- a/llvm/lib/DebugInfo/PDB/Native/InfoStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/InfoStream.cpp @@ -26,7 +26,7 @@ InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream) : Stream(std::move(Stream)) {} Error InfoStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); const InfoStreamHeader *H; if (auto EC = Reader.readObject(H)) diff --git a/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp index db7e18df1ab..0b6a563b5a9 100644 --- a/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp @@ -10,7 +10,6 @@ #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" #include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" -#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/DebugInfo/MSF/MSFBuilder.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" @@ -45,10 +44,10 @@ Error InfoStreamBuilder::finalizeMsfLayout() { } Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout, - WritableBinaryStreamRef Buffer) const { + const msf::WritableStream &Buffer) const { auto InfoS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StreamPDB); - BinaryStreamWriter Writer(*InfoS); + StreamWriter Writer(*InfoS); InfoStreamHeader H; H.Age = Age; diff --git a/llvm/lib/DebugInfo/PDB/Native/ModInfo.cpp b/llvm/lib/DebugInfo/PDB/Native/ModInfo.cpp index 5e229663844..501188e96f6 100644 --- a/llvm/lib/DebugInfo/PDB/Native/ModInfo.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/ModInfo.cpp @@ -16,6 +16,7 @@ #include <cstdint> using namespace llvm; +using namespace llvm::msf; using namespace llvm::pdb; using namespace llvm::support; @@ -25,15 +26,15 @@ ModInfo::ModInfo(const ModInfo &Info) = default; ModInfo::~ModInfo() = default; -Error ModInfo::initialize(BinaryStreamRef Stream, ModInfo &Info) { - BinaryStreamReader Reader(Stream); +Error ModInfo::initialize(ReadableStreamRef Stream, ModInfo &Info) { + StreamReader Reader(Stream); if (auto EC = Reader.readObject(Info.Layout)) return EC; - if (auto EC = Reader.readCString(Info.ModuleName)) + if (auto EC = Reader.readZeroString(Info.ModuleName)) return EC; - if (auto EC = Reader.readCString(Info.ObjFileName)) + if (auto EC = Reader.readZeroString(Info.ObjFileName)) return EC; return Error::success(); } diff --git a/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp b/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp index df9ec818a1d..9f035cf3e94 100644 --- a/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/ModStream.cpp @@ -31,7 +31,7 @@ ModStream::ModStream(const ModInfo &Module, ModStream::~ModStream() = default; Error ModStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize(); uint32_t C11Size = Mod.getLineInfoByteSize(); @@ -41,9 +41,9 @@ Error ModStream::reload() { return make_error<RawError>(raw_error_code::corrupt_file, "Module has both C11 and C13 line info"); - BinaryStreamRef S; + ReadableStreamRef S; - if (auto EC = Reader.readInteger(Signature)) + if (auto EC = Reader.readInteger(Signature, llvm::support::little)) return EC; if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4)) return EC; @@ -53,12 +53,12 @@ Error ModStream::reload() { if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size)) return EC; - BinaryStreamReader LineReader(C13LinesSubstream); + StreamReader LineReader(C13LinesSubstream); if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining())) return EC; uint32_t GlobalRefsSize; - if (auto EC = Reader.readInteger(GlobalRefsSize)) + if (auto EC = Reader.readInteger(GlobalRefsSize, llvm::support::little)) return EC; if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize)) return EC; diff --git a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp index 1fa9bc443ec..ceeca10c5c5 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NamedStreamMap.cpp @@ -21,22 +21,23 @@ #include <cstdint> using namespace llvm; +using namespace llvm::msf; using namespace llvm::pdb; NamedStreamMap::NamedStreamMap() = default; -Error NamedStreamMap::load(BinaryStreamReader &Stream) { +Error NamedStreamMap::load(StreamReader &Stream) { Mapping.clear(); FinalizedHashTable.clear(); FinalizedInfo.reset(); uint32_t StringBufferSize; - if (auto EC = Stream.readInteger(StringBufferSize)) + if (auto EC = Stream.readInteger(StringBufferSize, llvm::support::little)) return joinErrors(std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, "Expected string buffer size")); - BinaryStreamRef StringsBuffer; + msf::ReadableStreamRef StringsBuffer; if (auto EC = Stream.readStreamRef(StringsBuffer, StringBufferSize)) return EC; @@ -50,11 +51,11 @@ Error NamedStreamMap::load(BinaryStreamReader &Stream) { std::tie(NameOffset, NameIndex) = Entry; // Compute the offset of the start of the string relative to the stream. - BinaryStreamReader NameReader(StringsBuffer); + msf::StreamReader NameReader(StringsBuffer); NameReader.setOffset(NameOffset); // Pump out our c-string from the stream. StringRef Str; - if (auto EC = NameReader.readCString(Str)) + if (auto EC = NameReader.readZeroString(Str)) return joinErrors(std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, "Expected name map name")); @@ -66,16 +67,17 @@ Error NamedStreamMap::load(BinaryStreamReader &Stream) { return Error::success(); } -Error NamedStreamMap::commit(BinaryStreamWriter &Writer) const { +Error NamedStreamMap::commit(msf::StreamWriter &Writer) const { assert(FinalizedInfo.hasValue()); // The first field is the number of bytes of string data. - if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes)) + if (auto EC = Writer.writeInteger(FinalizedInfo->StringDataBytes, + llvm::support::little)) return EC; // Now all of the string data itself. for (const auto &Item : Mapping) { - if (auto EC = Writer.writeCString(Item.getKey())) + if (auto EC = Writer.writeZeroString(Item.getKey())) return EC; } diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp index dff53344545..4c858253b79 100644 --- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp @@ -45,8 +45,7 @@ Error NativeSession::createFromPdb(StringRef Path, return make_error<GenericError>(generic_error_code::invalid_path); std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); - auto Stream = llvm::make_unique<MemoryBufferByteStream>( - std::move(Buffer), llvm::support::little); + auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer)); auto Allocator = llvm::make_unique<BumpPtrAllocator>(); auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator); diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp index 7e4f1652114..e1cf9102773 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PDBFile.cpp @@ -11,11 +11,8 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/DebugInfo/MSF/BinaryStream.h" -#include "llvm/DebugInfo/MSF/BinaryStream.h" -#include "llvm/DebugInfo/MSF/BinaryStreamArray.h" #include "llvm/DebugInfo/MSF/BinaryStreamArray.h" #include "llvm/DebugInfo/MSF/BinaryStreamReader.h" -#include "llvm/DebugInfo/MSF/BinaryStreamReader.h" #include "llvm/DebugInfo/MSF/MSFCommon.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" @@ -42,7 +39,7 @@ namespace { typedef FixedStreamArray<support::ulittle32_t> ulittle_array; } // end anonymous namespace -PDBFile::PDBFile(StringRef Path, std::unique_ptr<BinaryStream> PdbFileBuffer, +PDBFile::PDBFile(StringRef Path, std::unique_ptr<ReadableStream> PdbFileBuffer, BumpPtrAllocator &Allocator) : FilePath(Path), Allocator(Allocator), Buffer(std::move(PdbFileBuffer)) {} @@ -116,7 +113,7 @@ Error PDBFile::setBlockData(uint32_t BlockIndex, uint32_t Offset, } Error PDBFile::parseFileHeaders() { - BinaryStreamReader Reader(*Buffer); + StreamReader Reader(*Buffer); // Initialize SB. const msf::SuperBlock *SB = nullptr; @@ -150,7 +147,7 @@ Error PDBFile::parseFileHeaders() { // See the function fpmPn() for more information: // https://github.com/Microsoft/microsoft-pdb/blob/master/PDB/msf/msf.cpp#L489 auto FpmStream = MappedBlockStream::createFpmStream(ContainerLayout, *Buffer); - BinaryStreamReader FpmReader(*FpmStream); + StreamReader FpmReader(*FpmStream); ArrayRef<uint8_t> FpmBytes; if (auto EC = FpmReader.readBytes(FpmBytes, msf::getFullFpmByteSize(ContainerLayout))) @@ -188,8 +185,8 @@ Error PDBFile::parseStreamData() { // subclass of IPDBStreamData which only accesses the fields that have already // been parsed, we can avoid this and reuse MappedBlockStream. auto DS = MappedBlockStream::createDirectoryStream(ContainerLayout, *Buffer); - BinaryStreamReader Reader(*DS); - if (auto EC = Reader.readInteger(NumStreams)) + StreamReader Reader(*DS); + if (auto EC = Reader.readInteger(NumStreams, llvm::support::little)) return EC; if (auto EC = Reader.readArray(ContainerLayout.StreamSizes, NumStreams)) @@ -353,7 +350,7 @@ Expected<StringTable &> PDBFile::getStringTable() { if (!NS) return NS.takeError(); - BinaryStreamReader Reader(**NS); + StreamReader Reader(**NS); auto N = llvm::make_unique<StringTable>(); if (auto EC = N->load(Reader)) return std::move(EC); @@ -406,7 +403,7 @@ bool PDBFile::hasStringTable() { /// contain the stream returned by createIndexedStream(). Expected<std::unique_ptr<MappedBlockStream>> PDBFile::safelyCreateIndexedStream(const MSFLayout &Layout, - BinaryStreamRef MsfData, + const ReadableStream &MsfData, uint32_t StreamIndex) const { if (StreamIndex >= getNumStreams()) return make_error<RawError>(raw_error_code::no_stream); diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp index 298382fdc7d..fde61ddc650 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp @@ -12,8 +12,6 @@ #include "llvm/ADT/BitVector.h" #include "llvm/DebugInfo/MSF/BinaryStream.h" -#include "llvm/DebugInfo/MSF/BinaryStream.h" -#include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/DebugInfo/MSF/BinaryStreamWriter.h" #include "llvm/DebugInfo/MSF/MSFBuilder.h" #include "llvm/DebugInfo/PDB/GenericError.h" @@ -120,9 +118,8 @@ Error PDBFileBuilder::commit(StringRef Filename) { if (OutFileOrError.getError()) return llvm::make_error<pdb::GenericError>(generic_error_code::invalid_path, Filename); - FileBufferByteStream Buffer(std::move(*OutFileOrError), - llvm::support::little); - BinaryStreamWriter Writer(Buffer); + FileBufferByteStream Buffer(std::move(*OutFileOrError)); + StreamWriter Writer(Buffer); if (auto EC = Writer.writeObject(*Layout.SB)) return EC; @@ -134,8 +131,9 @@ Error PDBFileBuilder::commit(StringRef Filename) { auto DirStream = WritableMappedBlockStream::createDirectoryStream(Layout, Buffer); - BinaryStreamWriter DW(*DirStream); - if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size())) + StreamWriter DW(*DirStream); + if (auto EC = DW.writeInteger<uint32_t>(Layout.StreamSizes.size(), + llvm::support::little)) return EC; if (auto EC = DW.writeArray(Layout.StreamSizes)) @@ -152,7 +150,7 @@ Error PDBFileBuilder::commit(StringRef Filename) { auto NS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, StringTableStreamNo); - BinaryStreamWriter NSWriter(*NS); + StreamWriter NSWriter(*NS); if (auto EC = Strings.commit(NSWriter)) return EC; diff --git a/llvm/lib/DebugInfo/PDB/Native/PublicsStream.cpp b/llvm/lib/DebugInfo/PDB/Native/PublicsStream.cpp index fe85a329a58..57b77b8254d 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PublicsStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PublicsStream.cpp @@ -27,7 +27,6 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/MSF/BinaryStreamReader.h" -#include "llvm/DebugInfo/MSF/BinaryStreamReader.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" @@ -70,7 +69,7 @@ uint32_t PublicsStream::getAddrMap() const { return Header->AddrMap; } // we skip over the hash table which we believe contains information about // public symbols. Error PublicsStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); // Check stream size. if (Reader.bytesRemaining() < sizeof(HeaderInfo) + sizeof(GSIHashHeader)) diff --git a/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp b/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp index 79a78c92598..c81bff48191 100644 --- a/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/StringTable.cpp @@ -17,12 +17,13 @@ #include "llvm/Support/Endian.h" using namespace llvm; +using namespace llvm::msf; using namespace llvm::support; using namespace llvm::pdb; StringTable::StringTable() : Signature(0), HashVersion(0), NameCount(0) {} -Error StringTable::load(BinaryStreamReader &Stream) { +Error StringTable::load(StreamReader &Stream) { const StringTableHeader *H; if (auto EC = Stream.readObject(H)) return EC; @@ -54,7 +55,7 @@ Error StringTable::load(BinaryStreamReader &Stream) { return make_error<RawError>(raw_error_code::corrupt_file, "Missing name count"); - if (auto EC = Stream.readInteger(NameCount)) + if (auto EC = Stream.readInteger(NameCount, llvm::support::little)) return EC; return Error::success(); } @@ -67,9 +68,9 @@ StringRef StringTable::getStringForID(uint32_t ID) const { // the starting offset of the string we're looking for. So just seek into // the desired offset and a read a null terminated stream from that offset. StringRef Result; - BinaryStreamReader NameReader(NamesBuffer); + StreamReader NameReader(NamesBuffer); NameReader.setOffset(ID); - if (auto EC = NameReader.readCString(Result)) + if (auto EC = NameReader.readZeroString(Result)) consumeError(std::move(EC)); return Result; } diff --git a/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp index 9df97c9753e..8fad775ecdc 100644 --- a/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/StringTableBuilder.cpp @@ -52,7 +52,7 @@ uint32_t StringTableBuilder::finalize() { return Size; } -Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { +Error StringTableBuilder::commit(msf::StreamWriter &Writer) const { // Write a header StringTableHeader H; H.Signature = StringTableSignature; @@ -67,14 +67,14 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { StringRef S = Pair.first; uint32_t Offset = Pair.second; Writer.setOffset(StringStart + Offset); - if (auto EC = Writer.writeCString(S)) + if (auto EC = Writer.writeZeroString(S)) return EC; } Writer.setOffset(StringStart + StringSize); // Write a hash table. uint32_t BucketCount = computeBucketCount(Strings.size()); - if (auto EC = Writer.writeInteger(BucketCount)) + if (auto EC = Writer.writeInteger(BucketCount, llvm::support::little)) return EC; std::vector<ulittle32_t> Buckets(BucketCount); @@ -96,7 +96,8 @@ Error StringTableBuilder::commit(BinaryStreamWriter &Writer) const { if (auto EC = Writer.writeArray(ArrayRef<ulittle32_t>(Buckets))) return EC; - if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()))) + if (auto EC = Writer.writeInteger(static_cast<uint32_t>(Strings.size()), + llvm::support::little)) return EC; return Error::success(); } diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp index e0b8924c306..3f0e07a99e1 100644 --- a/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/SymbolStream.cpp @@ -17,7 +17,6 @@ #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" -#include "llvm/DebugInfo/MSF/BinaryStreamReader.h" #include "llvm/Support/Endian.h" using namespace llvm; @@ -31,7 +30,7 @@ SymbolStream::SymbolStream(std::unique_ptr<MappedBlockStream> Stream) SymbolStream::~SymbolStream() {} Error SymbolStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); if (auto EC = Reader.readArray(SymbolRecords, Stream->getLength())) return EC; diff --git a/llvm/lib/DebugInfo/PDB/Native/TpiStream.cpp b/llvm/lib/DebugInfo/PDB/Native/TpiStream.cpp index 954374ca4df..8f9dd0a793b 100644 --- a/llvm/lib/DebugInfo/PDB/Native/TpiStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/TpiStream.cpp @@ -14,7 +14,6 @@ #include "llvm/DebugInfo/CodeView/TypeRecord.h" #include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h" #include "llvm/DebugInfo/MSF/BinaryStreamReader.h" -#include "llvm/DebugInfo/MSF/BinaryStreamReader.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBTypeServerHandler.h" @@ -55,7 +54,7 @@ Error TpiStream::verifyHashValues() { } Error TpiStream::reload() { - BinaryStreamReader Reader(*Stream); + StreamReader Reader(*Stream); if (Reader.bytesRemaining() < sizeof(TpiStreamHeader)) return make_error<RawError>(raw_error_code::corrupt_file, @@ -94,7 +93,7 @@ Error TpiStream::reload() { auto HS = MappedBlockStream::createIndexedStream( Pdb.getMsfLayout(), Pdb.getMsfBuffer(), Header->HashStreamIndex); - BinaryStreamReader HSR(*HS); + StreamReader HSR(*HS); uint32_t NumHashValues = Header->HashValueBuffer.Length / sizeof(ulittle32_t); diff --git a/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp index 7d532ee56d8..29c1ec00fc7 100644 --- a/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp @@ -34,8 +34,7 @@ using namespace llvm::pdb; using namespace llvm::support; TpiStreamBuilder::TpiStreamBuilder(MSFBuilder &Msf, uint32_t StreamIdx) - : Msf(Msf), Allocator(Msf.getAllocator()), - TypeRecordStream(llvm::support::little), Header(nullptr), Idx(StreamIdx) { + : Msf(Msf), Allocator(Msf.getAllocator()), Header(nullptr), Idx(StreamIdx) { } TpiStreamBuilder::~TpiStreamBuilder() = default; @@ -83,7 +82,7 @@ Error TpiStreamBuilder::finalize() { return Error::success(); } -uint32_t TpiStreamBuilder::calculateSerializedLength() { +uint32_t TpiStreamBuilder::calculateSerializedLength() const { return sizeof(TpiStreamHeader) + TypeRecordStream.getLength(); } @@ -114,20 +113,19 @@ Error TpiStreamBuilder::finalizeMsfLayout() { } ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(HashBuffer.data()), HashBufferSize); - HashValueStream = - llvm::make_unique<BinaryByteStream>(Bytes, llvm::support::little); + HashValueStream = llvm::make_unique<ByteStream>(Bytes); return Error::success(); } Error TpiStreamBuilder::commit(const msf::MSFLayout &Layout, - WritableBinaryStreamRef Buffer) { + const msf::WritableStream &Buffer) { if (auto EC = finalize()) return EC; auto InfoS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, Idx); - BinaryStreamWriter Writer(*InfoS); + StreamWriter Writer(*InfoS); if (auto EC = Writer.writeObject(*Header)) return EC; @@ -138,7 +136,7 @@ Error TpiStreamBuilder::commit(const msf::MSFLayout &Layout, if (HashStreamIndex != kInvalidStreamIndex) { auto HVS = WritableMappedBlockStream::createIndexedStream(Layout, Buffer, HashStreamIndex); - BinaryStreamWriter HW(*HVS); + StreamWriter HW(*HVS); if (auto EC = HW.writeStreamRef(*HashValueStream)) return EC; } |