diff options
author | Zachary Turner <zturner@google.com> | 2016-10-20 18:31:19 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-10-20 18:31:19 +0000 |
commit | a459ab93aad5e94311c7061ef9bb19b1c6b8ee34 (patch) | |
tree | 2f9d0e55941d24ef7e9b1ef1bc86cf630aac3a7e /tools | |
parent | 37962abba13a687c9c59f90819b7f04cb867aa24 (diff) |
[CodeView] Refactor serialization to use StreamInterface.
This was all using ArrayRef<>s before which presents a problem
when you want to serialize to or deserialize from an actual
PDB stream. An ArrayRef<> is really just a special case of
what can be handled with StreamInterface though (e.g. by using
a ByteStream), so changing this to use StreamInterface allows
us to plug in a PDB stream and get all the record serialization
and deserialization for free on a MappedBlockStream.
Subsequent patches will try to remove TypeTableBuilder and
TypeRecordBuilder in favor of class that operate on
Streams as well, which should allow us to completely merge
the reading and writing codepaths for both types and symbols.
Differential Revision: https://reviews.llvm.org/D25831
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284762 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-readobj/COFFDumper.cpp | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 2b45d1de143..73118eb7cd0 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -154,8 +154,13 @@ public: Sec = Obj->getCOFFSection(SR); } - uint32_t getRecordOffset(ArrayRef<uint8_t> Record) override { - return Record.data() - SectionContents.bytes_begin(); + uint32_t getRecordOffset(msf::StreamReader Reader) override { + ArrayRef<uint8_t> Data; + if (auto EC = Reader.readLongestContiguousChunk(Data)) { + llvm::consumeError(std::move(EC)); + return 0; + } + return Data.data() - SectionContents.bytes_begin(); } void printRelocatedField(StringRef Label, uint32_t RelocOffset, @@ -835,8 +840,10 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, } case ModuleSubstreamKind::FrameData: { // First four bytes is a relocation against the function. + msf::ByteStream S(Contents); + msf::StreamReader SR(S); const uint32_t *CodePtr; - error(consumeObject(Contents, CodePtr)); + error(SR.readObject(CodePtr)); StringRef LinkageName; error(resolveSymbolName(Obj->getCOFFSection(Section), SectionContents, CodePtr, LinkageName)); @@ -844,9 +851,9 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, // To find the active frame description, search this array for the // smallest PC range that includes the current PC. - while (!Contents.empty()) { + while (!SR.empty()) { const FrameData *FD; - error(consumeObject(Contents, FD)); + error(SR.readObject(FD)); if (FD->FrameFunc >= CVStringTable.size()) error(object_error::parse_failed); @@ -974,11 +981,12 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, } void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) { - StringRef Data = Subsection; - while (!Data.empty()) { + msf::ByteStream S(Subsection); + msf::StreamReader SR(S); + while (!SR.empty()) { DictScope S(W, "FileChecksum"); const FileChecksum *FC; - error(consumeObject(Data, FC)); + error(SR.readObject(FC)); if (FC->FileNameOffset >= CVStringTable.size()) error(object_error::parse_failed); StringRef Filename = @@ -987,27 +995,30 @@ void COFFDumper::printCodeViewFileChecksums(StringRef Subsection) { W.printHex("ChecksumSize", FC->ChecksumSize); W.printEnum("ChecksumKind", uint8_t(FC->ChecksumKind), makeArrayRef(FileChecksumKindNames)); - if (FC->ChecksumSize >= Data.size()) + if (FC->ChecksumSize >= SR.bytesRemaining()) error(object_error::parse_failed); - StringRef ChecksumBytes = Data.substr(0, FC->ChecksumSize); + ArrayRef<uint8_t> ChecksumBytes; + error(SR.readBytes(ChecksumBytes, FC->ChecksumSize)); W.printBinary("ChecksumBytes", ChecksumBytes); unsigned PaddedSize = alignTo(FC->ChecksumSize + sizeof(FileChecksum), 4) - sizeof(FileChecksum); - if (PaddedSize > Data.size()) + PaddedSize -= ChecksumBytes.size(); + if (PaddedSize > SR.bytesRemaining()) error(object_error::parse_failed); - Data = Data.drop_front(PaddedSize); + error(SR.skip(PaddedSize)); } } void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { - StringRef Data = Subsection; + msf::ByteStream S(Subsection); + msf::StreamReader SR(S); uint32_t Signature; - error(consume(Data, Signature)); + error(SR.readInteger(Signature)); bool HasExtraFiles = Signature == unsigned(InlineeLinesSignature::ExtraFiles); - while (!Data.empty()) { + while (!SR.empty()) { const InlineeSourceLine *ISL; - error(consumeObject(Data, ISL)); + error(SR.readObject(ISL)); DictScope S(W, "InlineeSourceLine"); printTypeIndex("Inlinee", ISL->Inlinee); printFileNameForOffset("FileID", ISL->FileID); @@ -1015,12 +1026,12 @@ void COFFDumper::printCodeViewInlineeLines(StringRef Subsection) { if (HasExtraFiles) { uint32_t ExtraFileCount; - error(consume(Data, ExtraFileCount)); + error(SR.readInteger(ExtraFileCount)); W.printNumber("ExtraFileCount", ExtraFileCount); ListScope ExtraFiles(W, "ExtraFiles"); for (unsigned I = 0; I < ExtraFileCount; ++I) { uint32_t FileID; - error(consume(Data, FileID)); + error(SR.readInteger(FileID)); printFileNameForOffset("FileID", FileID); } } |