summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-04-26 16:20:00 +0000
committerZachary Turner <zturner@google.com>2016-04-26 16:20:00 +0000
commitf34e01624a95a86247b3ba8888feb24cba1f9006 (patch)
tree8b92d38370952a49f7ee7cb48f81909dccbd8a3e /llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
parent1d99c4d03ce7d8d251f815e49caba968ea94b488 (diff)
downloadbcm5719-llvm-f34e01624a95a86247b3ba8888feb24cba1f9006.tar.gz
bcm5719-llvm-f34e01624a95a86247b3ba8888feb24cba1f9006.zip
Refactor some more PDB reading code into DebugInfoPDB.
Differential Revision: http://reviews.llvm.org/D19445 Reviewed By: David Majnemer llvm-svn: 267564
Diffstat (limited to 'llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp')
-rw-r--r--llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp139
1 files changed, 13 insertions, 126 deletions
diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
index 78a2155cf51..c9c78a97110 100644
--- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
+++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
@@ -36,6 +36,7 @@
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
+#include "llvm/DebugInfo/PDB/Raw/PDBInfoStream.h"
#include "llvm/DebugInfo/PDB/Raw/PDBStream.h"
#include "llvm/DebugInfo/PDB/Raw/RawSession.h"
#include "llvm/Support/CommandLine.h"
@@ -233,135 +234,21 @@ static void dumpStructure(RawSession &RS) {
}
}
- // Stream 1 starts with the following header:
- // uint32_t Version;
- // uint32_t Signature;
- // uint32_t Age;
- // GUID Guid;
- PDBStream Stream1(1, File);
- uint32_t Version;
- uint32_t Signature;
- uint32_t Age;
- PDB_UniqueId Guid;
-
- Stream1.readInteger(Version);
- outs() << "Version: " << Version << '\n';
- // PDB's with versions before PDBImpvVC70 might not have the Guid field, we
- // don't support them.
- if (Version < 20000404)
- reportError("", std::make_error_code(std::errc::not_supported));
-
- // This appears to be the time the PDB was last opened by an MSVC tool?
- // It is definitely a timestamp of some sort.
- Stream1.readInteger(Signature);
- outs() << "Signature: ";
- outs().write_hex(Signature) << '\n';
-
- // This appears to be a number which is used to determine that the PDB is kept
- // in sync with the EXE.
- Stream1.readInteger(Age);
- outs() << "Age: " << Age << '\n';
-
- // I'm not sure what the purpose of the GUID is.
- Stream1.readObject(&Guid);
- outs() << "Guid: " << Guid << '\n';
-
- // This is some sort of weird string-set/hash table encoded in the stream.
- // It starts with the number of bytes in the table.
- uint32_t NumberOfBytes;
- Stream1.readInteger(NumberOfBytes);
- outs() << "NumberOfBytes: " << NumberOfBytes << '\n';
-
- // Following that field is the starting offset of strings in the name table.
- uint32_t StringsOffset = Stream1.getOffset();
- Stream1.setOffset(StringsOffset + NumberOfBytes);
-
- // This appears to be equivalent to the total number of strings *actually*
- // in the name table.
- uint32_t HashSize;
- Stream1.readInteger(HashSize);
- outs() << "HashSize: " << HashSize << '\n';
-
- // This appears to be an upper bound on the number of strings in the name
- // table.
- uint32_t MaxNumberOfStrings;
- Stream1.readInteger(MaxNumberOfStrings);
- outs() << "MaxNumberOfStrings: " << MaxNumberOfStrings << '\n';
-
- // This appears to be a hash table which uses bitfields to determine whether
- // or not a bucket is 'present'.
- uint32_t NumPresentWords;
- Stream1.readInteger(NumPresentWords);
- outs() << "NumPresentWords: " << NumPresentWords << '\n';
-
- // Store all the 'present' bits in a vector for later processing.
- SmallVector<uint32_t, 1> PresentWords;
- for (uint32_t I = 0; I != NumPresentWords; ++I) {
- uint32_t Word;
- Stream1.readInteger(Word);
- PresentWords.push_back(Word);
- outs() << "Word: " << Word << '\n';
- }
-
- // This appears to be a hash table which uses bitfields to determine whether
- // or not a bucket is 'deleted'.
- uint32_t NumDeletedWords;
- Stream1.readInteger(NumDeletedWords);
- outs() << "NumDeletedWords: " << NumDeletedWords << '\n';
-
- // Store all the 'deleted' bits in a vector for later processing.
- SmallVector<uint32_t, 1> DeletedWords;
- for (uint32_t I = 0; I != NumDeletedWords; ++I) {
- uint32_t Word;
- Stream1.readInteger(Word);
- DeletedWords.push_back(Word);
- outs() << "Word: " << Word << '\n';
- }
+ PDBInfoStream InfoStream(File);
+ if (auto EC = InfoStream.reload())
+ reportError("", EC);
- BitVector Present(MaxNumberOfStrings, false);
- if (!PresentWords.empty())
- Present.setBitsInMask(PresentWords.data(), PresentWords.size());
- BitVector Deleted(MaxNumberOfStrings, false);
- if (!DeletedWords.empty())
- Deleted.setBitsInMask(DeletedWords.data(), DeletedWords.size());
-
- StringMap<uint32_t> NamedStreams;
- for (uint32_t I = 0; I < MaxNumberOfStrings; ++I) {
- if (!Present.test(I))
- continue;
-
- // For all present entries, dump out their mapping.
-
- // This appears to be an offset relative to the start of the strings.
- // It tells us where the null-terminated string begins.
- uint32_t NameOffset;
- Stream1.readInteger(NameOffset);
- outs() << "NameOffset: " << NameOffset << '\n';
-
- // This appears to be a stream number into the stream directory.
- uint32_t NameIndex;
- Stream1.readInteger(NameIndex);
- outs() << "NameIndex: " << NameIndex << '\n';
-
- // Compute the offset of the start of the string relative to the stream.
- uint32_t StringOffset = StringsOffset + NameOffset;
- uint32_t OldOffset = Stream1.getOffset();
- // Pump out our c-string from the stream.
- std::string Str;
- Stream1.setOffset(StringOffset);
- Stream1.readZeroString(Str);
- outs() << "String: " << Str << "\n\n";
-
- Stream1.setOffset(OldOffset);
- // Add this to a string-map from name to stream number.
- NamedStreams.insert({Str, NameIndex});
- }
+ outs() << "Version: " << InfoStream.getVersion() << '\n';
+ outs() << "Signature: ";
+ outs().write_hex(InfoStream.getSignature()) << '\n';
+ outs() << "Age: " << InfoStream.getAge() << '\n';
+ outs() << "Guid: " << InfoStream.getGuid() << '\n';
// Let's try to dump out the named stream "/names".
- auto NameI = NamedStreams.find("/names");
- if (NameI != NamedStreams.end()) {
- PDBStream NameStream(NameI->second, File);
- outs() << "NameStream: " << NameI->second << '\n';
+ uint32_t NameStreamIndex = InfoStream.getNamedStreamIndex("/names");
+ if (NameStreamIndex != 0) {
+ PDBStream NameStream(NameStreamIndex, File);
+ outs() << "NameStream: " << NameStreamIndex << '\n';
// The name stream appears to start with a signature and version.
uint32_t NameStreamSignature;
OpenPOWER on IntegriCloud