summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-05-03 17:11:11 +0000
committerZachary Turner <zturner@google.com>2017-05-03 17:11:11 +0000
commit2d5c2cd3ce208ebfac2bceb4c73157bef4e00fdc (patch)
treef3a5c0de380443aa47cc2d67fc0badacbceaf3d9 /llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp
parent761bcdaf066f55075989dac2dbf0ebb148198ee0 (diff)
downloadbcm5719-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/DebugInfo/PDB/Native/PDBStringTable.cpp')
-rw-r--r--llvm/lib/DebugInfo/PDB/Native/PDBStringTable.cpp20
1 files changed, 13 insertions, 7 deletions
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 {
OpenPOWER on IntegriCloud