summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-readobj/COFFDumper.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-10-20 18:31:19 +0000
committerZachary Turner <zturner@google.com>2016-10-20 18:31:19 +0000
commit4d49eb9fa0bb4ddc87329192ca24ffebedd05e1b (patch)
tree79095d7ef7bcc737b2e8854662d25ffa834b0b9c /llvm/tools/llvm-readobj/COFFDumper.cpp
parentf70a906a11d68f716a7337341b4dddb418081a3f (diff)
downloadbcm5719-llvm-4d49eb9fa0bb4ddc87329192ca24ffebedd05e1b.tar.gz
bcm5719-llvm-4d49eb9fa0bb4ddc87329192ca24ffebedd05e1b.zip
[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 llvm-svn: 284762
Diffstat (limited to 'llvm/tools/llvm-readobj/COFFDumper.cpp')
-rw-r--r--llvm/tools/llvm-readobj/COFFDumper.cpp47
1 files changed, 29 insertions, 18 deletions
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 2b45d1de143..73118eb7cd0 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/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);
}
}
OpenPOWER on IntegriCloud