diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h index d0dd570f0e0565..eeb7c76d2bd876 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/InputFile.h @@ -158,32 +158,32 @@ getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index); Expected getModuleDebugStream(PDBFile &File, uint32_t Index); -bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group); +bool shouldDumpSymbolGroup(uint32_t Idx, const SymbolGroup &Group, + const FilterOptions &Filters); // TODO: Change these callbacks to be function_refs (de-templatify them). template -Error iterateOneModule(InputFile &File, const Optional &HeaderScope, +Error iterateOneModule(InputFile &File, const PrintScope &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()); - } + 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, +Error iterateSymbolGroups(InputFile &Input, const PrintScope &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; + FilterOptions Filters = HeaderScope.P.getFilters(); + uint32_t 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 +192,7 @@ Error iterateSymbolGroups(InputFile &Input, 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)) @@ -205,7 +205,7 @@ Error iterateSymbolGroups(InputFile &Input, template Error iterateModuleSubsections( - InputFile &File, const Optional &HeaderScope, + InputFile &File, const PrintScope &HeaderScope, llvm::function_ref Callback) { diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h index 38abf6635dcd3c..773bf061fb7b11 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/LinePrinter.h @@ -40,17 +40,16 @@ class MSFStreamLayout; } // 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 @@ class LinePrinter { 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 @@ class LinePrinter { int IndentSpaces; int CurrentIndent; bool UseColor; + const FilterOptions &Filters; std::list ExcludeCompilandFilters; std::list ExcludeTypeFilters; @@ -120,11 +122,8 @@ struct PrintScope { uint32_t LabelWidth = 0; }; -inline Optional withLabelWidth(const Optional &Scope, - uint32_t W) { - if (!Scope) - return None; - return PrintScope{*Scope, W}; +inline PrintScope withLabelWidth(const PrintScope &Scope, uint32_t W) { + return PrintScope{Scope, W}; } struct AutoIndent { @@ -132,11 +131,9 @@ struct AutoIndent { : L(&L), Amount(Amount) { L.Indent(Amount); } - explicit AutoIndent(const Optional &Scope) { - if (Scope.hasValue()) { - L = &Scope->P; - Amount = Scope->IndentLevel; - } + explicit AutoIndent(const PrintScope &Scope) { + L = &Scope.P; + Amount = Scope.IndentLevel; } ~AutoIndent() { if (L) diff --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp index 637e0ee294f7bb..ebe410748b670a 100644 --- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp @@ -573,14 +573,15 @@ static bool isMyCode(const SymbolGroup &Group) { 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 FilterOptions &Filters) { + 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); } diff --git a/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp b/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp index 2c4ec80334b52f..c12fedc23833e9 100644 --- a/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/LinePrinter.cpp @@ -30,10 +30,6 @@ using namespace llvm; 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 @@ bool IsItemExcluded(llvm::StringRef Item, 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(), diff --git a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp index 2bcdab14c4d71e..12cda106c036d7 100644 --- a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp +++ b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp @@ -552,10 +552,7 @@ Error DumpOutputStyle::dumpSymbolStats() { StatCollection SymStats; StatCollection ChunkStats; - - Optional Scope; - if (File.isPdb()) - Scope.emplace(P, 2); + PrintScope Scope(P, 2); if (Error Err = iterateSymbolGroups( File, Scope, [&](uint32_t Modi, const SymbolGroup &SG) -> Error {