diff options
author | Zachary Turner <zturner@google.com> | 2017-05-03 17:11:11 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-05-03 17:11:11 +0000 |
commit | 2d5c2cd3ce208ebfac2bceb4c73157bef4e00fdc (patch) | |
tree | f3a5c0de380443aa47cc2d67fc0badacbceaf3d9 /llvm/lib | |
parent | 761bcdaf066f55075989dac2dbf0ebb148198ee0 (diff) | |
download | bcm5719-llvm-2d5c2cd3ce208ebfac2bceb4c73157bef4e00fdc.tar.gz bcm5719-llvm-2d5c2cd3ce208ebfac2bceb4c73157bef4e00fdc.zip |
[llvm-readobj] Update readobj to re-use parsing code.
llvm-readobj hand rolls some CodeView parsing code for string
tables, so this patch updates it to re-use some of the newly
introduced parsing code in LLVMDebugInfoCodeView.
Differential Revision: https://reviews.llvm.org/D32772
llvm-svn: 302052
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/StringTable.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp | 20 |
3 files changed, 32 insertions, 25 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/StringTable.cpp b/llvm/lib/DebugInfo/CodeView/StringTable.cpp index 5d3a0dd9cfa..f496854ffaf 100644 --- a/llvm/lib/DebugInfo/CodeView/StringTable.cpp +++ b/llvm/lib/DebugInfo/CodeView/StringTable.cpp @@ -18,17 +18,17 @@ using namespace llvm::codeview; StringTableRef::StringTableRef() {} -Error StringTableRef::initialize(BinaryStreamReader &Reader) { - return Reader.readStreamRef(Stream, Reader.bytesRemaining()); +Error StringTableRef::initialize(BinaryStreamRef Contents) { + Stream = Contents; + return Error::success(); } -StringRef StringTableRef::getString(uint32_t Offset) const { +Expected<StringRef> StringTableRef::getString(uint32_t Offset) const { BinaryStreamReader Reader(Stream); Reader.setOffset(Offset); StringRef Result; - Error EC = Reader.readCString(Result); - assert(!EC); - consumeError(std::move(EC)); + if (auto EC = Reader.readCString(Result)) + return std::move(EC); return Result; } diff --git a/llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp b/llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp index 134471e81ca..5395e4349b2 100644 --- a/llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp +++ b/llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp @@ -13,6 +13,7 @@ #include "llvm/DebugInfo/CodeView/CVSymbolVisitor.h" #include "llvm/DebugInfo/CodeView/CVTypeDumper.h" #include "llvm/DebugInfo/CodeView/EnumTables.h" +#include "llvm/DebugInfo/CodeView/StringTable.h" #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h" #include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" @@ -369,14 +370,14 @@ Error CVSymbolDumperImpl::visitKnownRecord( DictScope S(W, "DefRangeSubfield"); if (ObjDelegate) { - StringRef StringTable = ObjDelegate->getStringTable(); - auto ProgramStringTableOffset = DefRangeSubfield.Program; - if (ProgramStringTableOffset >= StringTable.size()) + StringTableRef Strings = ObjDelegate->getStringTable(); + auto ExpectedProgram = Strings.getString(DefRangeSubfield.Program); + if (!ExpectedProgram) { + consumeError(ExpectedProgram.takeError()); return llvm::make_error<CodeViewError>( "String table offset outside of bounds of String Table!"); - StringRef Program = - StringTable.drop_front(ProgramStringTableOffset).split('\0').first; - W.printString("Program", Program); + } + W.printString("Program", *ExpectedProgram); } W.printNumber("OffsetInParent", DefRangeSubfield.OffsetInParent); printLocalVariableAddrRange(DefRangeSubfield.Range, @@ -390,14 +391,14 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, DictScope S(W, "DefRange"); if (ObjDelegate) { - StringRef StringTable = ObjDelegate->getStringTable(); - auto ProgramStringTableOffset = DefRange.Program; - if (ProgramStringTableOffset >= StringTable.size()) + StringTableRef Strings = ObjDelegate->getStringTable(); + auto ExpectedProgram = Strings.getString(DefRange.Program); + if (!ExpectedProgram) { + consumeError(ExpectedProgram.takeError()); return llvm::make_error<CodeViewError>( "String table offset outside of bounds of String Table!"); - StringRef Program = - StringTable.drop_front(ProgramStringTableOffset).split('\0').first; - W.printString("Program", Program); + } + W.printString("Program", *ExpectedProgram); } printLocalVariableAddrRange(DefRange.Range, DefRange.getRelocationOffset()); printLocalVariableAddrGap(DefRange.Gaps); diff --git a/llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp b/llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp index ee32f61f16f..e84573fe07b 100644 --- a/llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp @@ -42,7 +42,11 @@ Error PDBStringTable::readHeader(BinaryStreamReader &Reader) { } Error PDBStringTable::readStrings(BinaryStreamReader &Reader) { - if (auto EC = Strings.initialize(Reader)) { + BinaryStreamRef Stream; + if (auto EC = Reader.readStreamRef(Stream)) + return EC; + + if (auto EC = Strings.initialize(Stream)) { return joinErrors(std::move(EC), make_error<RawError>(raw_error_code::corrupt_file, "Invalid hash table byte length")); @@ -99,11 +103,11 @@ Error PDBStringTable::reload(BinaryStreamReader &Reader) { return Error::success(); } -StringRef PDBStringTable::getStringForID(uint32_t ID) const { +Expected<StringRef> PDBStringTable::getStringForID(uint32_t ID) const { return Strings.getString(ID); } -uint32_t PDBStringTable::getIDForString(StringRef Str) const { +Expected<uint32_t> PDBStringTable::getIDForString(StringRef Str) const { uint32_t Hash = (Header->HashVersion == 1) ? hashStringV1(Str) : hashStringV2(Str); size_t Count = IDs.size(); @@ -115,12 +119,14 @@ uint32_t PDBStringTable::getIDForString(StringRef Str) const { uint32_t Index = (Start + I) % Count; uint32_t ID = IDs[Index]; - StringRef S = getStringForID(ID); - if (S == Str) + auto ExpectedStr = getStringForID(ID); + if (!ExpectedStr) + return ExpectedStr.takeError(); + + if (*ExpectedStr == Str) return ID; } - // IDs[0] contains the ID of the "invalid" entry. - return IDs[0]; + return make_error<RawError>(raw_error_code::no_entry); } FixedStreamArray<support::ulittle32_t> PDBStringTable::name_ids() const { |