From 7f318aee5713b8a1e3e86c006bba1f2298427d33 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Thu, 3 Aug 2017 23:11:52 +0000 Subject: [PATCH] [llvm-pdbutil] Add an option to only dump specific module indices. Often something interesting (like a symbol) is in a particular module, and you don't want to dump symbols from all other 300 modules to see the one you want. This adds a -modi option so that we only dump the specified module. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310000 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-pdbutil/DumpOutputStyle.cpp | 96 ++++++++++++++------------ tools/llvm-pdbutil/llvm-pdbutil.cpp | 4 ++ tools/llvm-pdbutil/llvm-pdbutil.h | 1 + 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/tools/llvm-pdbutil/DumpOutputStyle.cpp b/tools/llvm-pdbutil/DumpOutputStyle.cpp index 892017efc51..248e0de675e 100644 --- a/tools/llvm-pdbutil/DumpOutputStyle.cpp +++ b/tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -343,6 +343,20 @@ public: }; } // namespace +template +static void iterateOneModule(PDBFile &File, LinePrinter &P, + const DbiModuleDescriptor &Descriptor, + uint32_t Modi, uint32_t IndentLevel, + uint32_t Digits, CallbackT Callback) { + P.formatLine( + "Mod {0:4} | `{1}`: ", fmt_align(Modi, AlignStyle::Right, Digits), + Descriptor.getModuleName()); + + StringsAndChecksumsPrinter Strings(File, Modi); + AutoIndent Indent2(P, IndentLevel); + Callback(Modi, Strings); +} + template static void iterateModules(PDBFile &File, LinePrinter &P, uint32_t IndentLevel, CallbackT Callback) { @@ -357,16 +371,21 @@ static void iterateModules(PDBFile &File, LinePrinter &P, uint32_t IndentLevel, auto &Stream = Err(File.getPDBDbiStream()); const DbiModuleList &Modules = Stream.modules(); + + if (opts::dump::DumpModi.getNumOccurrences() > 0) { + assert(opts::dump::DumpModi.getNumOccurrences() == 1); + uint32_t Modi = opts::dump::DumpModi; + auto Descriptor = Modules.getModuleDescriptor(Modi); + iterateOneModule(File, P, Descriptor, Modi, IndentLevel, NumDigits(Modi), + Callback); + return; + } + uint32_t Count = Modules.getModuleCount(); uint32_t Digits = NumDigits(Count); for (uint32_t I = 0; I < Count; ++I) { - auto Modi = Modules.getModuleDescriptor(I); - P.formatLine("Mod {0:4} | `{1}`: ", fmt_align(I, AlignStyle::Right, Digits), - Modi.getModuleName()); - - StringsAndChecksumsPrinter Strings(File, I); - AutoIndent Indent2(P, IndentLevel); - Callback(I, Strings); + auto Descriptor = Modules.getModuleDescriptor(I); + iterateOneModule(File, P, Descriptor, I, IndentLevel, Digits, Callback); } } @@ -813,47 +832,34 @@ Error DumpOutputStyle::dumpModuleSyms() { ExitOnError Err("Unexpected error processing symbols: "); - auto &Stream = Err(File.getPDBDbiStream()); - auto &Types = Err(initializeTypes(StreamTPI)); - const DbiModuleList &Modules = Stream.modules(); - uint32_t Count = Modules.getModuleCount(); - uint32_t Digits = NumDigits(Count); - for (uint32_t I = 0; I < Count; ++I) { - auto Modi = Modules.getModuleDescriptor(I); - P.formatLine("Mod {0:4} | `{1}`: ", fmt_align(I, AlignStyle::Right, Digits), - Modi.getModuleName()); - uint16_t ModiStream = Modi.getModuleStreamIndex(); - if (ModiStream == kInvalidStreamIndex) { - P.formatLine(" "); - continue; - } - auto ModStreamData = MappedBlockStream::createIndexedStream( - File.getMsfLayout(), File.getMsfBuffer(), ModiStream, - File.getAllocator()); - - ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); - if (auto EC = ModS.reload()) { - P.formatLine("Error loading module stream {0}. {1}", I, - toString(std::move(EC))); - continue; - } + iterateModules( + File, P, 2, [&](uint32_t I, StringsAndChecksumsPrinter &Strings) { + auto ExpectedModS = getModuleDebugStream(File, I); + if (!ExpectedModS) { + P.formatLine("Error loading module stream {0}. {1}", I, + toString(ExpectedModS.takeError())); + return; + } - SymbolVisitorCallbackPipeline Pipeline; - SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb); - MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Types); - - Pipeline.addCallbackToPipeline(Deserializer); - Pipeline.addCallbackToPipeline(Dumper); - CVSymbolVisitor Visitor(Pipeline); - auto SS = ModS.getSymbolsSubstream(); - if (auto EC = Visitor.visitSymbolStream(ModS.getSymbolArray(), SS.Offset)) { - P.formatLine("Error while processing symbol records. {0}", - toString(std::move(EC))); - continue; - } - } + ModuleDebugStreamRef &ModS = *ExpectedModS; + + SymbolVisitorCallbackPipeline Pipeline; + SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb); + MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, Types); + + Pipeline.addCallbackToPipeline(Deserializer); + Pipeline.addCallbackToPipeline(Dumper); + CVSymbolVisitor Visitor(Pipeline); + auto SS = ModS.getSymbolsSubstream(); + if (auto EC = + Visitor.visitSymbolStream(ModS.getSymbolArray(), SS.Offset)) { + P.formatLine("Error while processing symbol records. {0}", + toString(std::move(EC))); + return; + } + }); return Error::success(); } diff --git a/tools/llvm-pdbutil/llvm-pdbutil.cpp b/tools/llvm-pdbutil/llvm-pdbutil.cpp index 051977ba5c2..1cf9a86b1ea 100644 --- a/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ b/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -503,6 +503,10 @@ cl::opt DumpXme( cl::desc( "dump cross module exports (DEBUG_S_CROSSSCOPEEXPORTS subsection)"), cl::cat(FileOptions), cl::sub(DumpSubcommand)); +cl::opt DumpModi("modi", cl::Optional, + cl::desc("For all options that iterate over " + "modules, limit to the specified module"), + cl::cat(FileOptions), cl::sub(DumpSubcommand)); // MISCELLANEOUS OPTIONS cl::opt DumpStringTable("string-table", cl::desc("dump PDB String Table"), diff --git a/tools/llvm-pdbutil/llvm-pdbutil.h b/tools/llvm-pdbutil/llvm-pdbutil.h index 88bebf95aaa..ccdb992db38 100644 --- a/tools/llvm-pdbutil/llvm-pdbutil.h +++ b/tools/llvm-pdbutil/llvm-pdbutil.h @@ -144,6 +144,7 @@ extern llvm::cl::opt DumpIds; extern llvm::cl::opt DumpIdData; extern llvm::cl::opt DumpIdExtras; extern llvm::cl::list DumpIdIndex; +extern llvm::cl::opt DumpModi; extern llvm::cl::opt DumpSymbols; extern llvm::cl::opt DumpSymRecordBytes; extern llvm::cl::opt DumpGlobals; -- 2.50.1