Index: llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h =================================================================== --- llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h +++ llvm/include/llvm/DebugInfo/PDB/Native/FormatUtil.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H -#define LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H +#define LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" Index: llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h =================================================================== --- llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h +++ llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H -#define LLVM_TOOLS_LLVMPDBDUMP_INPUTFILE_H +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_INPUTFILE_H +#define LLVM_DEBUGINFO_PDB_NATIVE_INPUTFILE_H #include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerUnion.h" @@ -15,6 +15,7 @@ #include "llvm/ADT/iterator.h" #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h" #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" @@ -54,6 +55,9 @@ getOrCreateTypeCollection(TypeCollectionKind Kind); public: + InputFile(PDBFile *Pdb) { PdbOrObj = Pdb; } + InputFile(object::COFFObjectFile *Obj) { PdbOrObj = Obj; } + InputFile(MemoryBuffer *Buffer) { PdbOrObj = Buffer; } ~InputFile(); InputFile(InputFile &&Other) = default; @@ -91,6 +95,7 @@ explicit SymbolGroup(InputFile *File, uint32_t GroupIndex = 0); Expected getNameFromStringTable(uint32_t Offset) const; + Expected getNameFromChecksums(uint32_t Offset) const; void formatFromFileName(LinePrinter &Printer, StringRef File, bool Append = false) const; @@ -148,6 +153,79 @@ SymbolGroup Value; }; +Expected +getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index); +Expected getModuleDebugStream(PDBFile &File, + uint32_t Index); + +bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group); + +template +Error iterateOneModule(InputFile &File, const Optional &HeaderScope, + const SymbolGroup &SG, uint32_t Modi, + CallbackT Callback) { + if (HeaderScope) { + HeaderScope->P.formatLine( + "Mod {0:4} | `{1}`: ", + fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name()); + } + + AutoIndent Indent(HeaderScope); + return Callback(Modi, SG); +} + +template +Error iterateSymbolGroups(InputFile &Input, + const Optional &HeaderScope, + CallbackT Callback) { + AutoIndent Indent(HeaderScope); + + if (llvm::pdb::Filters.DumpModi > 0) { + assert(llvm::pdb::Filters.DumpModi == 1); + uint32_t Modi = llvm::pdb::Filters.DumpModi; + SymbolGroup SG(&Input, Modi); + return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)), + SG, Modi, Callback); + } + + uint32_t I = 0; + + for (const auto &SG : Input.symbol_groups()) { + if (shouldDumpSymbolGroup(I, SG)) + if (auto Err = + iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)), + SG, I, Callback)) + return Err; + + ++I; + } + return Error::success(); +} + +template +Error iterateModuleSubsections( + InputFile &File, const Optional &HeaderScope, + llvm::function_ref + Callback) { + + return iterateSymbolGroups( + File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { + for (const auto &SS : SG.getDebugSubsections()) { + SubsectionT Subsection; + + if (SS.kind() != Subsection.kind()) + continue; + + BinaryStreamReader Reader(SS.getRecordData()); + if (auto Err = Subsection.initialize(Reader)) + continue; + if (auto Err = Callback(Modi, SG, Subsection)) + return Err; + } + return Error::success(); + }); +} + } // namespace pdb } // namespace llvm Index: llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h =================================================================== --- llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h +++ llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h @@ -6,12 +6,13 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H -#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H +#ifndef LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H +#define LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" #include "llvm/Support/BinaryStreamRef.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Regex.h" @@ -19,12 +20,28 @@ #include +// Container for filter options to control which elements will be printed. +struct FilterOptions { + std::list ExcludeTypes; + std::list ExcludeSymbols; + std::list ExcludeCompilands; + std::list IncludeTypes; + std::list IncludeSymbols; + std::list IncludeCompilands; + uint32_t PaddingThreshold; + uint32_t SizeThreshold; + uint32_t DumpModi; + bool JustMyCode; +}; + namespace llvm { namespace msf { class MSFStreamLayout; } // namespace msf namespace pdb { +extern FilterOptions Filters; + class ClassLayout; class PDBFile; @@ -32,7 +49,8 @@ friend class WithColor; public: - LinePrinter(int Indent, bool UseColor, raw_ostream &Stream); + LinePrinter(int Indent, bool UseColor, raw_ostream &Stream, + FilterOptions &Filters); void Indent(uint32_t Amount = 0); void Unindent(uint32_t Amount = 0); Index: llvm/lib/DebugInfo/PDB/CMakeLists.txt =================================================================== --- llvm/lib/DebugInfo/PDB/CMakeLists.txt +++ llvm/lib/DebugInfo/PDB/CMakeLists.txt @@ -47,12 +47,15 @@ Native/DbiStream.cpp Native/DbiStreamBuilder.cpp Native/EnumTables.cpp + Native/FormatUtil.cpp Native/GlobalsStream.cpp Native/Hash.cpp Native/HashTable.cpp Native/InfoStream.cpp Native/InfoStreamBuilder.cpp Native/InjectedSourceStream.cpp + Native/InputFile.cpp + Native/LinePrinter.cpp Native/ModuleDebugStream.cpp Native/NativeCompilandSymbol.cpp Native/NativeEnumGlobals.cpp Index: llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp +++ llvm/lib/DebugInfo/PDB/Native/FormatUtil.cpp @@ -6,7 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "FormatUtil.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" + #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/BinaryFormat/COFF.h" Index: llvm/lib/DebugInfo/PDB/Native/InputFile.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/InputFile.cpp +++ llvm/lib/DebugInfo/PDB/Native/InputFile.cpp @@ -6,10 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "InputFile.h" - -#include "FormatUtil.h" -#include "LinePrinter.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" #include "llvm/BinaryFormat/Magic.h" #include "llvm/DebugInfo/CodeView/CodeView.h" @@ -17,6 +14,8 @@ #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h" @@ -35,8 +34,9 @@ InputFile::InputFile() {} InputFile::~InputFile() {} -static Expected -getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index) { +Expected +llvm::pdb::getModuleDebugStream(PDBFile &File, StringRef &ModuleName, + uint32_t Index) { Expected DbiOrErr = File.getPDBDbiStream(); if (!DbiOrErr) return DbiOrErr.takeError(); @@ -65,6 +65,30 @@ return std::move(ModS); } +Expected llvm::pdb::getModuleDebugStream(PDBFile &File, + uint32_t Index) { + Expected = File.getPDBDbiStream(); + if (!DbiOrErr) + return DbiOrErr.takeError(); + DbiStream &Dbi = *DbiOrErr; + const auto &Modules = Dbi.modules(); + auto Modi = Modules.getModuleDescriptor(Index); + + uint16_t ModiStream = Modi.getModuleStreamIndex(); + if (ModiStream == kInvalidStreamIndex) + return make_error(raw_error_code::no_stream, + "Module stream not present"); + + auto ModStreamData = File.createIndexedStream(ModiStream); + + ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); + if (Error Err = ModS.reload()) + return make_error(raw_error_code::corrupt_file, + "Invalid module stream"); + + return std::move(ModS); +} + static inline bool isCodeViewDebugSubsection(object::SectionRef Section, StringRef Name, BinaryStreamReader &Reader) { @@ -211,6 +235,26 @@ return SC.strings().getString(Offset); } +Expected SymbolGroup::getNameFromChecksums(uint32_t Offset) const { + StringRef Name; + if (!SC.hasChecksums()) { + return std::move(Name); + } + + auto Iter = SC.checksums().getArray().at(Offset); + if (Iter == SC.checksums().getArray().end()) { + return std::move(Name); + } + + uint32_t FO = Iter->FileNameOffset; + auto ExpectedFile = getNameFromStringTable(FO); + if (!ExpectedFile) { + return std::move(Name); + } + + return *ExpectedFile; +} + void SymbolGroup::formatFromFileName(LinePrinter &Printer, StringRef File, bool Append) const { auto FC = ChecksumsByFile.find(File); @@ -510,3 +554,33 @@ assert(SectionIter.hasValue()); return *SectionIter == Value.File->obj().section_end(); } + +static bool isMyCode(const SymbolGroup &Group) { + if (Group.getFile().isObj()) + return true; + + StringRef Name = Group.name(); + if (Name.startswith("Import:")) + return false; + if (Name.endswith_insensitive(".dll")) + return false; + if (Name.equals_insensitive("* linker *")) + return false; + if (Name.startswith_insensitive("f:\\binaries\\Intermediate\\vctools")) + return false; + if (Name.startswith_insensitive("f:\\dd\\vctools\\crt")) + return false; + return true; +} + +bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) { + if (llvm::pdb::Filters.JustMyCode && !isMyCode(Group)) + return false; + + // If the arg was not specified on the command line, always dump all modules. + if (llvm::pdb::Filters.DumpModi == 0) + return true; + + // Otherwise, only dump if this is the same module specified. + return (llvm::pdb::Filters.DumpModi == Idx); +} Index: llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp +++ llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp @@ -6,16 +6,18 @@ // //===----------------------------------------------------------------------===// -#include "LinePrinter.h" - -#include "llvm-pdbutil.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" #include "llvm/DebugInfo/MSF/MSFCommon.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/UDTLayout.h" +#include "llvm/Object/COFF.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormatAdapters.h" @@ -28,6 +30,8 @@ using namespace llvm::msf; using namespace llvm::pdb; +FilterOptions llvm::pdb::Filters; + namespace { bool IsItemExcluded(llvm::StringRef Item, std::list &IncludeFilters, @@ -51,21 +55,23 @@ using namespace llvm; -LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream) +LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream, + FilterOptions &Filters) : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) { - SetFilters(ExcludeTypeFilters, opts::pretty::ExcludeTypes.begin(), - opts::pretty::ExcludeTypes.end()); - SetFilters(ExcludeSymbolFilters, opts::pretty::ExcludeSymbols.begin(), - opts::pretty::ExcludeSymbols.end()); - SetFilters(ExcludeCompilandFilters, opts::pretty::ExcludeCompilands.begin(), - opts::pretty::ExcludeCompilands.end()); - - SetFilters(IncludeTypeFilters, opts::pretty::IncludeTypes.begin(), - opts::pretty::IncludeTypes.end()); - SetFilters(IncludeSymbolFilters, opts::pretty::IncludeSymbols.begin(), - opts::pretty::IncludeSymbols.end()); - SetFilters(IncludeCompilandFilters, opts::pretty::IncludeCompilands.begin(), - opts::pretty::IncludeCompilands.end()); + llvm::pdb::Filters = Filters; + SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(), + Filters.ExcludeTypes.end()); + SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(), + Filters.ExcludeSymbols.end()); + SetFilters(ExcludeCompilandFilters, Filters.ExcludeCompilands.begin(), + Filters.ExcludeCompilands.end()); + + SetFilters(IncludeTypeFilters, Filters.IncludeTypes.begin(), + Filters.IncludeTypes.end()); + SetFilters(IncludeSymbolFilters, Filters.IncludeSymbols.begin(), + Filters.IncludeSymbols.end()); + SetFilters(IncludeCompilandFilters, Filters.IncludeCompilands.begin(), + Filters.IncludeCompilands.end()); } void LinePrinter::Indent(uint32_t Amount) { @@ -95,7 +101,7 @@ bool LinePrinter::IsClassExcluded(const ClassLayout &Class) { if (IsTypeExcluded(Class.getName(), Class.getSize())) return true; - if (Class.deepPaddingSize() < opts::pretty::PaddingThreshold) + if (Class.deepPaddingSize() < Filters.PaddingThreshold) return true; return false; } @@ -273,7 +279,7 @@ bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size) { if (IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters)) return true; - if (Size < opts::pretty::SizeThreshold) + if (Size < Filters.SizeThreshold) return true; return false; } Index: llvm/tools/llvm-pdbutil/BytesOutputStyle.h =================================================================== --- llvm/tools/llvm-pdbutil/BytesOutputStyle.h +++ llvm/tools/llvm-pdbutil/BytesOutputStyle.h @@ -9,10 +9,10 @@ #ifndef LLVM_TOOLS_LLVMPDBDUMP_BYTESOUTPUTSTYLE_H #define LLVM_TOOLS_LLVMPDBDUMP_BYTESOUTPUTSTYLE_H -#include "LinePrinter.h" #include "OutputStyle.h" #include "StreamUtil.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/Support/Error.h" namespace llvm { Index: llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp =================================================================== --- llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp +++ llvm/tools/llvm-pdbutil/BytesOutputStyle.cpp @@ -8,7 +8,6 @@ #include "BytesOutputStyle.h" -#include "FormatUtil.h" #include "StreamUtil.h" #include "llvm-pdbutil.h" @@ -18,6 +17,7 @@ #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" @@ -83,7 +83,7 @@ } BytesOutputStyle::BytesOutputStyle(PDBFile &File) - : File(File), P(2, false, outs()) {} + : File(File), P(2, false, outs(), opts::Filters) {} Error BytesOutputStyle::dump() { Index: llvm/tools/llvm-pdbutil/CMakeLists.txt =================================================================== --- llvm/tools/llvm-pdbutil/CMakeLists.txt +++ llvm/tools/llvm-pdbutil/CMakeLists.txt @@ -12,10 +12,7 @@ BytesOutputStyle.cpp DumpOutputStyle.cpp ExplainOutputStyle.cpp - InputFile.cpp llvm-pdbutil.cpp - FormatUtil.cpp - LinePrinter.cpp MinimalSymbolDumper.cpp MinimalTypeDumper.cpp PdbYaml.cpp Index: llvm/tools/llvm-pdbutil/DumpOutputStyle.h =================================================================== --- llvm/tools/llvm-pdbutil/DumpOutputStyle.h +++ llvm/tools/llvm-pdbutil/DumpOutputStyle.h @@ -9,13 +9,13 @@ #ifndef LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H #define LLVM_TOOLS_LLVMPDBDUMP_DUMPOUTPUTSTYLE_H -#include "LinePrinter.h" #include "OutputStyle.h" #include "StreamUtil.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/Native/RawConstants.h" #include Index: llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp =================================================================== --- llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp +++ llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -8,8 +8,6 @@ #include "DumpOutputStyle.h" -#include "FormatUtil.h" -#include "InputFile.h" #include "MinimalSymbolDumper.h" #include "MinimalTypeDumper.h" #include "StreamUtil.h" @@ -38,10 +36,13 @@ #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" #include "llvm/DebugInfo/PDB/Native/ISectionContribVisitor.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PublicsStream.h" #include "llvm/DebugInfo/PDB/Native/RawError.h" @@ -61,7 +62,7 @@ using namespace llvm::pdb; DumpOutputStyle::DumpOutputStyle(InputFile &File) - : File(File), P(2, false, outs()) { + : File(File), P(2, false, outs(), opts::Filters) { if (opts::dump::DumpTypeRefStats) RefTracker.reset(new TypeReferenceTracker(File)); } @@ -342,36 +343,6 @@ } } -static bool isMyCode(const SymbolGroup &Group) { - if (Group.getFile().isObj()) - return true; - - StringRef Name = Group.name(); - if (Name.startswith("Import:")) - return false; - if (Name.endswith_insensitive(".dll")) - return false; - if (Name.equals_insensitive("* linker *")) - return false; - if (Name.startswith_insensitive("f:\\binaries\\Intermediate\\vctools")) - return false; - if (Name.startswith_insensitive("f:\\dd\\vctools\\crt")) - return false; - return true; -} - -static bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) { - if (opts::dump::JustMyCode && !isMyCode(Group)) - return false; - - // If the arg was not specified on the command line, always dump all modules. - if (opts::dump::DumpModi.getNumOccurrences() == 0) - return true; - - // Otherwise, only dump if this is the same module specified. - return (opts::dump::DumpModi == Idx); -} - Error DumpOutputStyle::dumpStreamSummary() { printHeader(P, "Streams"); @@ -408,96 +379,6 @@ return Error::success(); } -static Expected getModuleDebugStream(PDBFile &File, - uint32_t Index) { - Expected DbiOrErr = File.getPDBDbiStream(); - if (!DbiOrErr) - return DbiOrErr.takeError(); - DbiStream &Dbi = *DbiOrErr; - const auto &Modules = Dbi.modules(); - auto Modi = Modules.getModuleDescriptor(Index); - - uint16_t ModiStream = Modi.getModuleStreamIndex(); - if (ModiStream == kInvalidStreamIndex) - return make_error(raw_error_code::no_stream, - "Module stream not present"); - - auto ModStreamData = File.createIndexedStream(ModiStream); - - ModuleDebugStreamRef ModS(Modi, std::move(ModStreamData)); - if (auto EC = ModS.reload()) - return make_error(raw_error_code::corrupt_file, - "Invalid module stream"); - - return std::move(ModS); -} - -template -static Error -iterateOneModule(InputFile &File, const Optional &HeaderScope, - const SymbolGroup &SG, uint32_t Modi, CallbackT Callback) { - if (HeaderScope) { - HeaderScope->P.formatLine( - "Mod {0:4} | `{1}`: ", - fmt_align(Modi, AlignStyle::Right, HeaderScope->LabelWidth), SG.name()); - } - - AutoIndent Indent(HeaderScope); - return Callback(Modi, SG); -} - -template -static Error iterateSymbolGroups(InputFile &Input, - const Optional &HeaderScope, - CallbackT Callback) { - AutoIndent Indent(HeaderScope); - - if (opts::dump::DumpModi.getNumOccurrences() > 0) { - assert(opts::dump::DumpModi.getNumOccurrences() == 1); - uint32_t Modi = opts::dump::DumpModi; - SymbolGroup SG(&Input, Modi); - return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)), - SG, Modi, Callback); - } - - uint32_t I = 0; - - for (const auto &SG : Input.symbol_groups()) { - if (shouldDumpSymbolGroup(I, SG)) - if (auto Err = - iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)), - SG, I, Callback)) - return Err; - - ++I; - } - return Error::success(); -} - -template -static Error iterateModuleSubsections( - InputFile &File, const Optional &HeaderScope, - llvm::function_ref - Callback) { - - return iterateSymbolGroups( - File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { - for (const auto &SS : SG.getDebugSubsections()) { - SubsectionT Subsection; - - if (SS.kind() != Subsection.kind()) - continue; - - BinaryStreamReader Reader(SS.getRecordData()); - if (auto Err = Subsection.initialize(Reader)) - continue; - if (auto Err = Callback(Modi, SG, Subsection)) - return Err; - } - return Error::success(); - }); -} - static Expected, ArrayRef>> loadSectionHeaders(PDBFile &File, DbgHeaderType Type) { Index: llvm/tools/llvm-pdbutil/ExplainOutputStyle.h =================================================================== --- llvm/tools/llvm-pdbutil/ExplainOutputStyle.h +++ llvm/tools/llvm-pdbutil/ExplainOutputStyle.h @@ -9,9 +9,10 @@ #ifndef LLVM_TOOLS_LLVMPDBDUMP_EXPLAINOUTPUTSTYLE_H #define LLVM_TOOLS_LLVMPDBDUMP_EXPLAINOUTPUTSTYLE_H -#include "LinePrinter.h" #include "OutputStyle.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" + #include namespace llvm { Index: llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp =================================================================== --- llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp +++ llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp @@ -8,17 +8,20 @@ #include "ExplainOutputStyle.h" -#include "FormatUtil.h" -#include "InputFile.h" #include "StreamUtil.h" #include "llvm-pdbutil.h" #include "llvm/DebugInfo/CodeView/Formatters.h" +#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" #include "llvm/DebugInfo/MSF/MappedBlockStream.h" #include "llvm/DebugInfo/PDB/Native/DbiStream.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/RawTypes.h" +#include "llvm/Object/COFF.h" #include "llvm/Support/BinaryByteStream.h" #include "llvm/Support/BinaryStreamArray.h" #include "llvm/Support/Error.h" @@ -29,7 +32,7 @@ using namespace llvm::pdb; ExplainOutputStyle::ExplainOutputStyle(InputFile &File, uint64_t FileOffset) - : File(File), FileOffset(FileOffset), P(2, false, outs()) {} + : File(File), FileOffset(FileOffset), P(2, false, outs(), opts::Filters) {} Error ExplainOutputStyle::dump() { P.formatLine("Explaining file offset {0} of file '{1}'.", FileOffset, Index: llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp +++ llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp @@ -8,17 +8,19 @@ #include "MinimalSymbolDumper.h" -#include "FormatUtil.h" -#include "InputFile.h" -#include "LinePrinter.h" - #include "llvm/DebugInfo/CodeView/CVRecord.h" #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/Formatters.h" #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBStringTable.h" +#include "llvm/Object/COFF.h" #include "llvm/Support/FormatVariadic.h" using namespace llvm; Index: llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp +++ llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp @@ -8,8 +8,6 @@ #include "MinimalTypeDumper.h" -#include "FormatUtil.h" -#include "LinePrinter.h" #include "TypeReferenceTracker.h" #include "llvm-pdbutil.h" @@ -19,8 +17,13 @@ #include "llvm/DebugInfo/CodeView/Formatters.h" #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" +#include "llvm/DebugInfo/PDB/Native/FormatUtil.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/TpiHashing.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" +#include "llvm/Object/COFF.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/MathExtras.h" Index: llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyBuiltinDumper.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "PrettyBuiltinDumper.h" -#include "LinePrinter.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" using namespace llvm; Index: llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp @@ -8,7 +8,6 @@ #include "PrettyClassDefinitionDumper.h" -#include "LinePrinter.h" #include "PrettyClassLayoutGraphicalDumper.h" #include "llvm-pdbutil.h" Index: llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp @@ -8,7 +8,6 @@ #include "PrettyClassLayoutGraphicalDumper.h" -#include "LinePrinter.h" #include "PrettyClassDefinitionDumper.h" #include "PrettyEnumDumper.h" #include "PrettyFunctionDumper.h" Index: llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyCompilandDumper.cpp @@ -8,7 +8,6 @@ #include "PrettyCompilandDumper.h" -#include "LinePrinter.h" #include "PrettyFunctionDumper.h" #include "llvm-pdbutil.h" Index: llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyEnumDumper.cpp @@ -8,7 +8,6 @@ #include "PrettyEnumDumper.h" -#include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "llvm-pdbutil.h" Index: llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyExternalSymbolDumper.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "PrettyExternalSymbolDumper.h" -#include "LinePrinter.h" #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" #include "llvm/Support/Format.h" Index: llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyFunctionDumper.cpp @@ -7,12 +7,12 @@ //===----------------------------------------------------------------------===// #include "PrettyFunctionDumper.h" -#include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/PDBExtras.h" #include "llvm/DebugInfo/PDB/PDBSymbolData.h" #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" Index: llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyTypeDumper.cpp @@ -8,7 +8,6 @@ #include "PrettyTypeDumper.h" -#include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "PrettyClassDefinitionDumper.h" #include "PrettyEnumDumper.h" Index: llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyTypedefDumper.cpp @@ -8,13 +8,13 @@ #include "PrettyTypedefDumper.h" -#include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "PrettyFunctionDumper.h" #include "PrettyTypeDumper.h" #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/DebugInfo/PDB/PDBExtras.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" Index: llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp =================================================================== --- llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp +++ llvm/tools/llvm-pdbutil/PrettyVariableDumper.cpp @@ -8,7 +8,6 @@ #include "PrettyVariableDumper.h" -#include "LinePrinter.h" #include "PrettyBuiltinDumper.h" #include "PrettyFunctionDumper.h" #include "llvm-pdbutil.h" Index: llvm/tools/llvm-pdbutil/StreamUtil.cpp =================================================================== --- llvm/tools/llvm-pdbutil/StreamUtil.cpp +++ llvm/tools/llvm-pdbutil/StreamUtil.cpp @@ -7,13 +7,13 @@ //===----------------------------------------------------------------------===// #include "StreamUtil.h" -#include "FormatUtil.h" #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/FormatUtil.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" Index: llvm/tools/llvm-pdbutil/TypeReferenceTracker.h =================================================================== --- llvm/tools/llvm-pdbutil/TypeReferenceTracker.h +++ llvm/tools/llvm-pdbutil/TypeReferenceTracker.h @@ -9,14 +9,13 @@ #ifndef LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H #define LLVM_TOOLS_LLVMPDBDUMP_TYPEREFERENCETRACKER_H -#include "InputFile.h" - #include "llvm/ADT/BitVector.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/DebugInfo/CodeView/CVRecord.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/CodeView/TypeIndexDiscovery.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" #include "llvm/Support/Error.h" namespace llvm { Index: llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp =================================================================== --- llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp +++ llvm/tools/llvm-pdbutil/TypeReferenceTracker.cpp @@ -12,7 +12,10 @@ #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" +#include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/SymbolStream.h" +#include "llvm/Object/COFF.h" using namespace llvm; using namespace llvm::pdb; Index: llvm/tools/llvm-pdbutil/llvm-pdbutil.h =================================================================== --- llvm/tools/llvm-pdbutil/llvm-pdbutil.h +++ llvm/tools/llvm-pdbutil/llvm-pdbutil.h @@ -12,6 +12,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/DebugInfo/PDB/Native/LinePrinter.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" @@ -50,6 +51,8 @@ All }; +extern FilterOptions Filters; + namespace pretty { enum class ClassDefinitionFormat { None, Layout, All }; Index: llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp =================================================================== --- llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp +++ llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp @@ -15,8 +15,6 @@ #include "BytesOutputStyle.h" #include "DumpOutputStyle.h" #include "ExplainOutputStyle.h" -#include "InputFile.h" -#include "LinePrinter.h" #include "OutputStyle.h" #include "PrettyClassDefinitionDumper.h" #include "PrettyCompilandDumper.h" @@ -55,6 +53,7 @@ #include "llvm/DebugInfo/PDB/Native/DbiStreamBuilder.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h" +#include "llvm/DebugInfo/PDB/Native/InputFile.h" #include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h" @@ -199,6 +198,8 @@ cl::sub(DiaDumpSubcommand)); } // namespace diadump +FilterOptions Filters; + namespace pretty { cl::list InputFilenames(cl::Positional, cl::desc(""), @@ -1072,7 +1073,7 @@ const bool UseColor = opts::pretty::ColorOutput == cl::BOU_UNSET ? Stream.has_colors() : opts::pretty::ColorOutput == cl::BOU_TRUE; - LinePrinter Printer(2, UseColor, Stream); + LinePrinter Printer(2, UseColor, Stream, opts::Filters); auto GlobalScope(Session->getGlobalScope()); if (!GlobalScope) @@ -1510,6 +1511,25 @@ llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded); + // Initialize the filters for LinePrinter. + auto propagate = [&](auto &Target, auto &Reference) { + for (std::string &Option : Reference) + Target.push_back(Option); + }; + + propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes); + propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes); + propagate(opts::Filters.ExcludeSymbols, opts::pretty::ExcludeSymbols); + propagate(opts::Filters.ExcludeCompilands, opts::pretty::ExcludeCompilands); + propagate(opts::Filters.IncludeTypes, opts::pretty::IncludeTypes); + propagate(opts::Filters.IncludeSymbols, opts::pretty::IncludeSymbols); + propagate(opts::Filters.IncludeCompilands, opts::pretty::IncludeCompilands); + opts::Filters.PaddingThreshold = opts::pretty::PaddingThreshold; + opts::Filters.SizeThreshold = opts::pretty::SizeThreshold; + opts::Filters.JustMyCode = opts::dump::JustMyCode; + if (opts::dump::DumpModi.getNumOccurrences()) + opts::Filters.DumpModi = opts::dump::DumpModi; + if (opts::PdbToYamlSubcommand) { pdb2Yaml(opts::pdb2yaml::InputFilename.front()); } else if (opts::YamlToPdbSubcommand) { @@ -1548,14 +1568,14 @@ // it needs to be escaped again in the C++. So matching a single \ in the // input requires 4 \es in the C++. if (opts::pretty::ExcludeCompilerGenerated) { - opts::pretty::ExcludeTypes.push_back("__vc_attributes"); - opts::pretty::ExcludeCompilands.push_back("\\* Linker \\*"); + opts::Filters.ExcludeTypes.push_back("__vc_attributes"); + opts::Filters.ExcludeCompilands.push_back("\\* Linker \\*"); } if (opts::pretty::ExcludeSystemLibraries) { - opts::pretty::ExcludeCompilands.push_back( + opts::Filters.ExcludeCompilands.push_back( "f:\\\\binaries\\\\Intermediate\\\\vctools\\\\crt_bld"); - opts::pretty::ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt"); - opts::pretty::ExcludeCompilands.push_back( + opts::Filters.ExcludeCompilands.push_back("f:\\\\dd\\\\vctools\\\\crt"); + opts::Filters.ExcludeCompilands.push_back( "d:\\\\th.obj.x86fre\\\\minkernel"); } llvm::for_each(opts::pretty::InputFilenames, dumpPretty);