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,7 +158,8 @@ Expected getModuleDebugStream(PDBFile &File, uint32_t Index); -bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group); +bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group, + const Optional &Filters); // TODO: Change these callbacks to be function_refs (de-templatify them). template @@ -181,9 +182,15 @@ CallbackT Callback) { AutoIndent Indent(HeaderScope); - if (llvm::pdb::Filters.DumpModi > 0) { - assert(llvm::pdb::Filters.DumpModi == 1); - uint32_t Modi = llvm::pdb::Filters.DumpModi; + Optional Filters; + uint32_t Modi = 0; + if (HeaderScope) { + Filters = HeaderScope->P.getFilters(); + Modi = Filters->DumpModi; + } + + if (Modi > 0) { + assert(Modi == 1); SymbolGroup SG(&Input, Modi); return iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(Modi)), SG, Modi, Callback); @@ -192,7 +199,7 @@ uint32_t I = 0; for (const auto &SG : Input.symbol_groups()) { - if (shouldDumpSymbolGroup(I, SG)) + if (shouldDumpSymbolGroup(I, SG, Filters)) if (auto Err = iterateOneModule(Input, withLabelWidth(HeaderScope, NumDigits(I)), SG, I, Callback)) 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,17 +40,16 @@ } // namespace msf namespace pdb { -extern FilterOptions Filters; - class ClassLayout; class PDBFile; +class SymbolGroup; class LinePrinter { friend class WithColor; public: LinePrinter(int Indent, bool UseColor, raw_ostream &Stream, - FilterOptions &Filters); + const FilterOptions &Filters); void Indent(uint32_t Amount = 0); void Unindent(uint32_t Amount = 0); @@ -87,6 +86,8 @@ bool IsSymbolExcluded(llvm::StringRef SymbolName); bool IsCompilandExcluded(llvm::StringRef CompilandName); + const FilterOptions &getFilters() const { return Filters; } + private: template void SetFilters(std::list &List, Iter Begin, Iter End) { @@ -99,6 +100,7 @@ int IndentSpaces; int CurrentIndent; bool UseColor; + const 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 @@ -573,14 +573,19 @@ return true; } -bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group) { - if (llvm::pdb::Filters.JustMyCode && !isMyCode(Group)) +bool llvm::pdb::shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group, + const Optional &Filters) { + // If no available Filters, always process all modules. + if (!Filters) + return true; + + if (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) + if (Filters->DumpModi == 0) return true; // Otherwise, only dump if this is the same module specified. - return (llvm::pdb::Filters.DumpModi == Idx); + return (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, @@ -58,9 +54,9 @@ using namespace llvm; LinePrinter::LinePrinter(int Indent, bool UseColor, llvm::raw_ostream &Stream, - FilterOptions &Filters) - : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor) { - llvm::pdb::Filters = Filters; + const FilterOptions &Filters) + : OS(Stream), IndentSpaces(Indent), CurrentIndent(0), UseColor(UseColor), + Filters(Filters) { SetFilters(ExcludeTypeFilters, Filters.ExcludeTypes.begin(), Filters.ExcludeTypes.end()); SetFilters(ExcludeSymbolFilters, Filters.ExcludeSymbols.begin(),