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 @@ -158,8 +158,6 @@ Expected getModuleDebugStream(PDBFile &File, uint32_t Index); -bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group); - // TODO: Change these callbacks to be function_refs (de-templatify them). template Error iterateOneModule(InputFile &File, const Optional &HeaderScope, @@ -178,12 +176,12 @@ template Error iterateSymbolGroups(InputFile &Input, const Optional &HeaderScope, - CallbackT Callback) { + const LinePrinter &Printer, CallbackT Callback) { AutoIndent Indent(HeaderScope); - if (llvm::pdb::Filters.DumpModi > 0) { - assert(llvm::pdb::Filters.DumpModi == 1); - uint32_t Modi = llvm::pdb::Filters.DumpModi; + uint32_t Modi = Printer.getDumpModi(); + if (Modi > 0) { + assert(Modi == 1); SymbolGroup SG(&Input, Modi); return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)), SG, Modi, Callback); @@ -192,7 +190,7 @@ uint32_t I = 0; for (const auto &SG : Input.symbol_groups()) { - if (shouldDumpSymbolGroup(I, SG)) + if (Printer.shouldDumpSymbolGroup(I, SG)) if (auto Err = iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)), SG, I, Callback)) @@ -206,11 +204,13 @@ template Error iterateModuleSubsections( InputFile &File, const Optional &HeaderScope, + const LinePrinter &Printer, llvm::function_ref Callback) { return iterateSymbolGroups( - File, HeaderScope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { + File, HeaderScope, Printer, + [&](uint32_t Modi, const SymbolGroup &SG) -> Error { for (const auto &SS : SG.getDebugSubsections()) { SubsectionT Subsection; 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 @@ -40,10 +40,9 @@ } // namespace msf namespace pdb { -extern FilterOptions Filters; - class ClassLayout; class PDBFile; +class SymbolGroup; class LinePrinter { friend class WithColor; @@ -87,6 +86,9 @@ bool IsSymbolExcluded(llvm::StringRef SymbolName); bool IsCompilandExcluded(llvm::StringRef CompilandName); + bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) const; + uint32_t getDumpModi() const { return Filters.DumpModi; } + private: template void SetFilters(std::list &List, Iter Begin, Iter End) { @@ -99,6 +101,7 @@ int IndentSpaces; int CurrentIndent; bool UseColor; + FilterOptions Filters; std::list ExcludeCompilandFilters; std::list ExcludeTypeFilters; Index: llvm/lib/DebugInfo/PDB/Native/InputFile.cpp =================================================================== --- llvm/lib/DebugInfo/PDB/Native/InputFile.cpp +++ llvm/lib/DebugInfo/PDB/Native/InputFile.cpp @@ -554,33 +554,3 @@ 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 @@ -30,10 +30,6 @@ using namespace llvm::msf; using namespace llvm::pdb; -// TODO: Move this Filters state inside the LinePrinter class and pass it by -// reference to the iterate* functions. -FilterOptions llvm::pdb::Filters; - namespace { bool IsItemExcluded(llvm::StringRef Item, std::list &IncludeFilters, @@ -59,8 +55,8 @@ LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream, FilterOptions &Filters) - : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) { - llvm::pdb::Filters = Filters; + : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor), + Filters(Filters) { SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(), Filters.ExcludeTypes.end()); SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(), @@ -295,6 +291,37 @@ ExcludeCompilandFilters); } +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 LinePrinter::shouldDumpSymbolGroup(uint32_t Idx, + const SymbolGroup &Group) const { + if (Filters.JustMyCode && !isMyCode(Group)) + return false; + + // If the arg was not specified on the command line, always dump all modules. + if (Filters.DumpModi == 0) + return true; + + // Otherwise, only dump if this is the same module specified. + return (Filters.DumpModi == Idx); +} + WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS), UseColor(P.hasColor()) { if (UseColor) Index: llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp =================================================================== --- llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp +++ llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -481,7 +481,7 @@ const DbiModuleList &Modules = Stream.modules(); return iterateSymbolGroups( - File, PrintScope{P, 11}, + File, PrintScope{P, 11}, P, [&](uint32_t Modi, const SymbolGroup &Strings) -> Error { auto Desc = Modules.getModuleDescriptor(Modi); if (opts::dump::DumpSectionContribs) { @@ -527,7 +527,7 @@ } return iterateSymbolGroups( - File, PrintScope{P, 11}, + File, PrintScope{P, 11}, P, [this](uint32_t Modi, const SymbolGroup &Strings) -> Error { Expected StreamOrErr = getPdb().getPDBDbiStream(); if (!StreamOrErr) @@ -558,7 +558,7 @@ Scope.emplace(P, 2); if (Error Err = iterateSymbolGroups( - File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { + File, Scope, P, [&](uint32_t Modi, const SymbolGroup &SG) -> Error { StatCollection SS = getSymbolStats(SG, SymStats); StatCollection CS = getChunkStats(SG, ChunkStats); @@ -847,7 +847,7 @@ uint32_t LastModi = UINT32_MAX; uint32_t LastNameIndex = UINT32_MAX; return iterateModuleSubsections( - File, PrintScope{P, 4}, + File, PrintScope{P, 4}, P, [this, &LastModi, &LastNameIndex](uint32_t Modi, const SymbolGroup &Strings, DebugLinesSubsectionRef &Lines) -> Error { @@ -885,7 +885,7 @@ } return iterateModuleSubsections( - File, PrintScope{P, 2}, + File, PrintScope{P, 2}, P, [this](uint32_t Modi, const SymbolGroup &Strings, DebugInlineeLinesSubsectionRef &Lines) -> Error { P.formatLine("{0,+8} | {1,+5} | {2}", "Inlinee", "Line", "Source File"); @@ -912,7 +912,7 @@ } return iterateModuleSubsections( - File, PrintScope{P, 2}, + File, PrintScope{P, 2}, P, [this](uint32_t Modi, const SymbolGroup &Strings, DebugCrossModuleImportsSubsectionRef &Imports) -> Error { P.formatLine("{0,=32} | {1}", "Imported Module", "Type IDs"); @@ -952,7 +952,7 @@ } return iterateModuleSubsections( - File, PrintScope{P, 2}, + File, PrintScope{P, 2}, P, [this](uint32_t Modi, const SymbolGroup &Strings, DebugCrossModuleExportsSubsectionRef &Exports) -> Error { P.formatLine("{0,-10} | {1}", "Local ID", "Global ID"); @@ -1131,7 +1131,7 @@ Error DumpOutputStyle::dumpStringTableFromObj() { return iterateModuleSubsections( - File, PrintScope{P, 4}, + File, PrintScope{P, 4}, P, [&](uint32_t Modi, const SymbolGroup &Strings, DebugStringTableSubsectionRef &Strings2) -> Error { BinaryStreamRef StringTableBuffer = Strings2.getBuffer(); @@ -1441,7 +1441,7 @@ CVSymbolVisitor Visitor(Pipeline); return iterateModuleSubsections( - File, PrintScope{P, 2}, + File, PrintScope{P, 2}, P, [&](uint32_t Modi, const SymbolGroup &Strings, DebugSymbolsSubsectionRef &Symbols) -> Error { Dumper.setSymbolGroup(&Strings); @@ -1468,7 +1468,7 @@ auto &Types = File.types(); return iterateSymbolGroups( - File, PrintScope{P, 2}, + File, PrintScope{P, 2}, P, [&](uint32_t I, const SymbolGroup &Strings) -> Error { auto ExpectedModS = getModuleDebugStream(File.pdb(), I); if (!ExpectedModS) {