aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-pdbdump
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-08 17:12:57 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-08 17:12:57 +0000
commitc46e6a5940c50058e00c0c5f9123fd82e338d29a (patch)
tree89a719d723035c54a190b1f81d329834f1f93336 /tools/llvm-pdbdump
parent148779df305667b6942fee7e758fdf81a6498f38 (diff)
downloadsrc-c46e6a5940c50058e00c0c5f9123fd82e338d29a.tar.gz
src-c46e6a5940c50058e00c0c5f9123fd82e338d29a.zip
Vendor import of llvm trunk r302418:vendor/llvm/llvm-trunk-r302418
Notes
Notes: svn path=/vendor/llvm/dist/; revision=317948 svn path=/vendor/llvm/llvm-trunk-r302418/; revision=317950; tag=vendor/llvm/llvm-trunk-r302418
Diffstat (limited to 'tools/llvm-pdbdump')
-rw-r--r--tools/llvm-pdbdump/Analyze.cpp2
-rw-r--r--tools/llvm-pdbdump/LLVMOutputStyle.cpp172
-rw-r--r--tools/llvm-pdbdump/LLVMOutputStyle.h7
-rw-r--r--tools/llvm-pdbdump/StreamUtil.cpp13
-rw-r--r--tools/llvm-pdbdump/YAMLOutputStyle.cpp19
5 files changed, 134 insertions, 79 deletions
diff --git a/tools/llvm-pdbdump/Analyze.cpp b/tools/llvm-pdbdump/Analyze.cpp
index b65dd40d25ff..f7d6ec53b030 100644
--- a/tools/llvm-pdbdump/Analyze.cpp
+++ b/tools/llvm-pdbdump/Analyze.cpp
@@ -74,7 +74,7 @@ Error AnalysisStyle::dump() {
if (!Tpi)
return Tpi.takeError();
- TypeDatabase TypeDB;
+ TypeDatabase TypeDB(Tpi->getNumTypeRecords());
TypeDatabaseVisitor DBV(TypeDB);
TypeDeserializer Deserializer;
TypeVisitorCallbackPipeline Pipeline;
diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/tools/llvm-pdbdump/LLVMOutputStyle.cpp
index ec1325ff2335..2dd4ef0fb30d 100644
--- a/tools/llvm-pdbdump/LLVMOutputStyle.cpp
+++ b/tools/llvm-pdbdump/LLVMOutputStyle.cpp
@@ -39,6 +39,7 @@
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
#include "llvm/DebugInfo/PDB/Native/RawError.h"
+#include "llvm/DebugInfo/PDB/Native/TpiHashing.h"
#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
#include "llvm/DebugInfo/PDB/PDBExtras.h"
#include "llvm/Object/COFF.h"
@@ -609,11 +610,8 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
VerLabel = "IPI Version";
}
- bool IsSilentDatabaseBuild = !DumpRecordBytes && !DumpRecords && !DumpTpiHash;
- if (IsSilentDatabaseBuild) {
- outs().flush();
- errs() << "Building Type Information For " << Label << "\n";
- }
+ if (!DumpRecordBytes && !DumpRecords && !DumpTpiHash)
+ return Error::success();
auto Tpi = (StreamIdx == StreamTPI) ? File.getPDBTpiStream()
: File.getPDBIpiStream();
@@ -623,38 +621,43 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
std::unique_ptr<DictScope> StreamScope;
std::unique_ptr<ListScope> RecordScope;
- if (!IsSilentDatabaseBuild) {
- StreamScope = llvm::make_unique<DictScope>(P, Label);
- P.printNumber(VerLabel, Tpi->getTpiVersion());
- P.printNumber("Record count", Tpi->NumTypeRecords());
- }
-
- TypeDatabase &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
+ StreamScope = llvm::make_unique<DictScope>(P, Label);
+ P.printNumber(VerLabel, Tpi->getTpiVersion());
+ P.printNumber("Record count", Tpi->getNumTypeRecords());
- TypeDatabaseVisitor DBV(StreamDB);
- CompactTypeDumpVisitor CTDV(StreamDB, &P);
- TypeDumpVisitor TDV(TypeDB, &P, false);
- if (StreamIdx == StreamIPI)
- TDV.setItemDB(ItemDB);
- RecordBytesVisitor RBV(P);
- TypeDeserializer Deserializer;
+ Optional<TypeDatabase> &StreamDB = (StreamIdx == StreamTPI) ? TypeDB : ItemDB;
- // We always need to deserialize and add it to the type database. This is
- // true if even if we're not dumping anything, because we could need the
- // type database for the purposes of dumping symbols.
- TypeVisitorCallbackPipeline Pipeline;
- Pipeline.addCallbackToPipeline(Deserializer);
- Pipeline.addCallbackToPipeline(DBV);
+ std::vector<std::unique_ptr<TypeVisitorCallbacks>> Visitors;
+ Visitors.push_back(make_unique<TypeDeserializer>());
+ if (!StreamDB.hasValue()) {
+ StreamDB.emplace(Tpi->getNumTypeRecords());
+ Visitors.push_back(make_unique<TypeDatabaseVisitor>(*StreamDB));
+ }
// If we're in dump mode, add a dumper with the appropriate detail level.
if (DumpRecords) {
+ std::unique_ptr<TypeVisitorCallbacks> Dumper;
if (opts::raw::CompactRecords)
- Pipeline.addCallbackToPipeline(CTDV);
- else
- Pipeline.addCallbackToPipeline(TDV);
+ Dumper = make_unique<CompactTypeDumpVisitor>(*StreamDB, &P);
+ else {
+ assert(TypeDB.hasValue());
+
+ auto X = make_unique<TypeDumpVisitor>(*TypeDB, &P, false);
+ if (StreamIdx == StreamIPI)
+ X->setItemDB(*ItemDB);
+ Dumper = std::move(X);
+ }
+ Visitors.push_back(std::move(Dumper));
}
if (DumpRecordBytes)
- Pipeline.addCallbackToPipeline(RBV);
+ Visitors.push_back(make_unique<RecordBytesVisitor>(P));
+
+ // We always need to deserialize and add it to the type database. This is
+ // true if even if we're not dumping anything, because we could need the
+ // type database for the purposes of dumping symbols.
+ TypeVisitorCallbackPipeline Pipeline;
+ for (const auto &V : Visitors)
+ Pipeline.addCallbackToPipeline(*V);
CVTypeVisitor Visitor(Pipeline);
@@ -680,7 +683,7 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
if (DumpTpiHash) {
DictScope DD(P, "Hash");
- P.printNumber("Number of Hash Buckets", Tpi->NumHashBuckets());
+ P.printNumber("Number of Hash Buckets", Tpi->getNumHashBuckets());
P.printNumber("Hash Key Size", Tpi->getHashKeySize());
P.printList("Values", Tpi->getHashValues());
@@ -700,19 +703,51 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
}
}
- if (!IsSilentDatabaseBuild) {
- ListScope L(P, "TypeIndexOffsets");
- for (const auto &IO : Tpi->getTypeIndexOffsets()) {
- P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
- (uint32_t)IO.Offset)
- .str());
- }
+ ListScope L(P, "TypeIndexOffsets");
+ for (const auto &IO : Tpi->getTypeIndexOffsets()) {
+ P.printString(formatv("Index: {0:x}, Offset: {1:N}", IO.Type.getIndex(),
+ (uint32_t)IO.Offset)
+ .str());
}
P.flush();
return Error::success();
}
+Error LLVMOutputStyle::buildTypeDatabase(uint32_t SN) {
+ assert(SN == StreamIPI || SN == StreamTPI);
+
+ auto &DB = (SN == StreamIPI) ? ItemDB : TypeDB;
+
+ if (DB.hasValue())
+ return Error::success();
+
+ auto Tpi =
+ (SN == StreamTPI) ? File.getPDBTpiStream() : File.getPDBIpiStream();
+
+ if (!Tpi)
+ return Tpi.takeError();
+
+ DB.emplace(Tpi->getNumTypeRecords());
+
+ TypeVisitorCallbackPipeline Pipeline;
+ TypeDeserializer Deserializer;
+ TypeDatabaseVisitor DBV(*DB);
+ Pipeline.addCallbackToPipeline(Deserializer);
+ Pipeline.addCallbackToPipeline(DBV);
+
+ auto HashValues = Tpi->getHashValues();
+ std::unique_ptr<TpiHashVerifier> HashVerifier;
+ if (!HashValues.empty()) {
+ HashVerifier =
+ make_unique<TpiHashVerifier>(HashValues, Tpi->getNumHashBuckets());
+ Pipeline.addCallbackToPipeline(*HashVerifier);
+ }
+
+ CVTypeVisitor Visitor(Pipeline);
+ return Visitor.visitTypeStream(Tpi->types(nullptr));
+}
+
Error LLVMOutputStyle::dumpDbiStream() {
bool DumpModules = opts::raw::DumpModules || opts::raw::DumpModuleSyms ||
opts::raw::DumpModuleFiles || opts::raw::DumpLineInfo;
@@ -750,43 +785,46 @@ Error LLVMOutputStyle::dumpDbiStream() {
if (DumpModules) {
ListScope L(P, "Modules");
- for (auto &Modi : DS->modules()) {
+ const DbiModuleList &Modules = DS->modules();
+ for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
+ const DbiModuleDescriptor &Modi = Modules.getModuleDescriptor(I);
DictScope DD(P);
- P.printString("Name", Modi.Info.getModuleName().str());
- P.printNumber("Debug Stream Index", Modi.Info.getModuleStreamIndex());
- P.printString("Object File Name", Modi.Info.getObjFileName().str());
- P.printNumber("Num Files", Modi.Info.getNumberOfFiles());
- P.printNumber("Source File Name Idx", Modi.Info.getSourceFileNameIndex());
- P.printNumber("Pdb File Name Idx", Modi.Info.getPdbFilePathNameIndex());
- P.printNumber("Line Info Byte Size", Modi.Info.getC11LineInfoByteSize());
- P.printNumber("C13 Line Info Byte Size",
- Modi.Info.getC13LineInfoByteSize());
- P.printNumber("Symbol Byte Size", Modi.Info.getSymbolDebugInfoByteSize());
- P.printNumber("Type Server Index", Modi.Info.getTypeServerIndex());
- P.printBoolean("Has EC Info", Modi.Info.hasECInfo());
+ P.printString("Name", Modi.getModuleName().str());
+ P.printNumber("Debug Stream Index", Modi.getModuleStreamIndex());
+ P.printString("Object File Name", Modi.getObjFileName().str());
+ P.printNumber("Num Files", Modi.getNumberOfFiles());
+ P.printNumber("Source File Name Idx", Modi.getSourceFileNameIndex());
+ P.printNumber("Pdb File Name Idx", Modi.getPdbFilePathNameIndex());
+ P.printNumber("Line Info Byte Size", Modi.getC11LineInfoByteSize());
+ P.printNumber("C13 Line Info Byte Size", Modi.getC13LineInfoByteSize());
+ P.printNumber("Symbol Byte Size", Modi.getSymbolDebugInfoByteSize());
+ P.printNumber("Type Server Index", Modi.getTypeServerIndex());
+ P.printBoolean("Has EC Info", Modi.hasECInfo());
if (opts::raw::DumpModuleFiles) {
- std::string FileListName =
- to_string(Modi.SourceFiles.size()) + " Contributing Source Files";
+ std::string FileListName = to_string(Modules.getSourceFileCount(I)) +
+ " Contributing Source Files";
ListScope LL(P, FileListName);
- for (auto File : Modi.SourceFiles)
- P.printString(File.str());
+ for (auto File : Modules.source_files(I))
+ P.printString(File);
}
- bool HasModuleDI =
- (Modi.Info.getModuleStreamIndex() < File.getNumStreams());
+ bool HasModuleDI = (Modi.getModuleStreamIndex() < File.getNumStreams());
bool ShouldDumpSymbols =
(opts::raw::DumpModuleSyms || opts::raw::DumpSymRecordBytes);
if (HasModuleDI && (ShouldDumpSymbols || opts::raw::DumpLineInfo)) {
auto ModStreamData = MappedBlockStream::createIndexedStream(
File.getMsfLayout(), File.getMsfBuffer(),
- Modi.Info.getModuleStreamIndex());
+ Modi.getModuleStreamIndex());
- ModuleDebugStreamRef ModS(Modi.Info, std::move(ModStreamData));
+ ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData));
if (auto EC = ModS.reload())
return EC;
if (ShouldDumpSymbols) {
+ if (auto EC = buildTypeDatabase(StreamTPI))
+ return EC;
+
ListScope SS(P, "Symbols");
- codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
+ codeview::CVSymbolDumper SD(P, *TypeDB, nullptr, false);
bool HadError = false;
for (auto S : ModS.symbols(&HadError)) {
DictScope LL(P, "");
@@ -807,8 +845,10 @@ Error LLVMOutputStyle::dumpDbiStream() {
}
if (opts::raw::DumpLineInfo) {
ListScope SS(P, "LineInfo");
+ if (auto EC = buildTypeDatabase(StreamIPI))
+ return EC;
- C13RawVisitor V(P, File, ItemDB);
+ C13RawVisitor V(P, File, *ItemDB);
if (auto EC = codeview::visitModuleDebugFragments(
ModS.linesAndChecksums(), V))
return EC;
@@ -846,9 +886,10 @@ Error LLVMOutputStyle::dumpSectionContribs() {
{
DictScope DD(P, "Module");
P.printNumber("Index", SC.Imod);
- auto M = DS.modules();
- if (M.size() > SC.Imod) {
- P.printString("Name", M[SC.Imod].Info.getModuleName());
+ const DbiModuleList &Modules = DS.modules();
+ if (Modules.getModuleCount() > SC.Imod) {
+ P.printString("Name",
+ Modules.getModuleDescriptor(SC.Imod).getModuleName());
}
}
P.printNumber("Data CRC", SC.DataCrc);
@@ -925,7 +966,10 @@ Error LLVMOutputStyle::dumpPublicsStream() {
P.printList("Section Offsets", Publics->getSectionOffsets(),
printSectionOffset);
ListScope L(P, "Symbols");
- codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
+ if (auto EC = buildTypeDatabase(StreamTPI))
+ return EC;
+
+ codeview::CVSymbolDumper SD(P, *TypeDB, nullptr, false);
bool HadError = false;
for (auto S : Publics->getSymbols(&HadError)) {
DictScope DD(P, "");
diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.h b/tools/llvm-pdbdump/LLVMOutputStyle.h
index bfff3b8308db..b0e7e3406b36 100644
--- a/tools/llvm-pdbdump/LLVMOutputStyle.h
+++ b/tools/llvm-pdbdump/LLVMOutputStyle.h
@@ -12,6 +12,7 @@
#include "OutputStyle.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/CodeView/TypeDatabase.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -28,6 +29,8 @@ public:
Error dump() override;
private:
+ Error buildTypeDatabase(uint32_t SN);
+
Error dumpFileHeaders();
Error dumpStreamSummary();
Error dumpFreePageMap();
@@ -51,8 +54,8 @@ private:
PDBFile &File;
ScopedPrinter P;
- codeview::TypeDatabase TypeDB;
- codeview::TypeDatabase ItemDB;
+ Optional<codeview::TypeDatabase> TypeDB;
+ Optional<codeview::TypeDatabase> ItemDB;
SmallVector<std::string, 32> StreamPurposes;
};
}
diff --git a/tools/llvm-pdbdump/StreamUtil.cpp b/tools/llvm-pdbdump/StreamUtil.cpp
index 6577702adac8..81aa256b5002 100644
--- a/tools/llvm-pdbdump/StreamUtil.cpp
+++ b/tools/llvm-pdbdump/StreamUtil.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
+#include "llvm/DebugInfo/PDB/Native/DbiModuleList.h"
#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
@@ -30,14 +31,16 @@ void discoverStreamPurposes(PDBFile &File,
auto Info = File.getPDBInfoStream();
uint32_t StreamCount = File.getNumStreams();
- DenseMap<uint16_t, const ModuleInfoEx *> ModStreams;
+ DenseMap<uint16_t, DbiModuleDescriptor> ModStreams;
DenseMap<uint16_t, std::string> NamedStreams;
if (Dbi) {
- for (auto &ModI : Dbi->modules()) {
- uint16_t SN = ModI.Info.getModuleStreamIndex();
+ const DbiModuleList &Modules = Dbi->modules();
+ for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
+ DbiModuleDescriptor Descriptor = Modules.getModuleDescriptor(I);
+ uint16_t SN = Descriptor.getModuleStreamIndex();
if (SN != kInvalidStreamIndex)
- ModStreams[SN] = &ModI;
+ ModStreams[SN] = Descriptor;
}
}
if (Info) {
@@ -109,7 +112,7 @@ void discoverStreamPurposes(PDBFile &File,
auto NSIter = NamedStreams.find(StreamIdx);
if (ModIter != ModStreams.end()) {
Value = "Module \"";
- Value += ModIter->second->Info.getModuleName().str();
+ Value += ModIter->second.getModuleName();
Value += "\"";
} else if (NSIter != NamedStreams.end()) {
Value = "Named Stream \"";
diff --git a/tools/llvm-pdbdump/YAMLOutputStyle.cpp b/tools/llvm-pdbdump/YAMLOutputStyle.cpp
index b94b5a4abf37..0573b23cdc76 100644
--- a/tools/llvm-pdbdump/YAMLOutputStyle.cpp
+++ b/tools/llvm-pdbdump/YAMLOutputStyle.cpp
@@ -305,23 +305,28 @@ Error YAMLOutputStyle::dumpDbiStream() {
Obj.DbiStream->PdbDllVersion = DS.getPdbDllVersion();
Obj.DbiStream->VerHeader = DS.getDbiVersion();
if (opts::pdb2yaml::DbiModuleInfo) {
- for (const auto &MI : DS.modules()) {
+ const auto &Modules = DS.modules();
+ for (uint32_t I = 0; I < Modules.getModuleCount(); ++I) {
+ DbiModuleDescriptor MI = Modules.getModuleDescriptor(I);
+
Obj.DbiStream->ModInfos.emplace_back();
yaml::PdbDbiModuleInfo &DMI = Obj.DbiStream->ModInfos.back();
- DMI.Mod = MI.Info.getModuleName();
- DMI.Obj = MI.Info.getObjFileName();
- if (opts::pdb2yaml::DbiModuleSourceFileInfo)
- DMI.SourceFiles = MI.SourceFiles;
+ DMI.Mod = MI.getModuleName();
+ DMI.Obj = MI.getObjFileName();
+ if (opts::pdb2yaml::DbiModuleSourceFileInfo) {
+ auto Files = Modules.source_files(I);
+ DMI.SourceFiles.assign(Files.begin(), Files.end());
+ }
- uint16_t ModiStream = MI.Info.getModuleStreamIndex();
+ uint16_t ModiStream = MI.getModuleStreamIndex();
if (ModiStream == kInvalidStreamIndex)
continue;
auto ModStreamData = msf::MappedBlockStream::createIndexedStream(
File.getMsfLayout(), File.getMsfBuffer(), ModiStream);
- pdb::ModuleDebugStreamRef ModS(MI.Info, std::move(ModStreamData));
+ pdb::ModuleDebugStreamRef ModS(MI, std::move(ModStreamData));
if (auto EC = ModS.reload())
return EC;