forked from OSchip/llvm-project
[llvm-pdbutil] Move global state (Filters) inside LinePrinter class.
The changes described by: https://reviews.llvm.org/D121801 https://reviews.llvm.org/D122226 Moved some llvm-pdbutil functionality to the debug PDB library. This patch addresses one outstanding issue concerning the global state (Filters) created in the PDB library. - Move 'Filters' inside the 'LinePrinter' class. - Omit 'Optional' and just pass 'PrintScope &HeaderScope' everywhere. Reviewed By: aganea Differential Revision: https://reviews.llvm.org/D122887
This commit is contained in:
parent
175265ef80
commit
10c11f5c43
|
@ -158,32 +158,32 @@ getModuleDebugStream(PDBFile &File, StringRef &ModuleName, uint32_t Index);
|
|||
Expected<ModuleDebugStreamRef> 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 <typename CallbackT>
|
||||
Error iterateOneModule(InputFile &File, const Optional<PrintScope> &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 <typename CallbackT>
|
||||
Error iterateSymbolGroups(InputFile &Input,
|
||||
const Optional<PrintScope> &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 <typename SubsectionT>
|
||||
Error iterateModuleSubsections(
|
||||
InputFile &File, const Optional<PrintScope> &HeaderScope,
|
||||
InputFile &File, const PrintScope &HeaderScope,
|
||||
llvm::function_ref<Error(uint32_t, const SymbolGroup &, SubsectionT &)>
|
||||
Callback) {
|
||||
|
||||
|
|
|
@ -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 @@ public:
|
|||
bool IsSymbolExcluded(llvm::StringRef SymbolName);
|
||||
bool IsCompilandExcluded(llvm::StringRef CompilandName);
|
||||
|
||||
const FilterOptions &getFilters() const { return Filters; }
|
||||
|
||||
private:
|
||||
template <typename Iter>
|
||||
void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
|
||||
|
@ -99,6 +100,7 @@ private:
|
|||
int IndentSpaces;
|
||||
int CurrentIndent;
|
||||
bool UseColor;
|
||||
const FilterOptions &Filters;
|
||||
|
||||
std::list<Regex> ExcludeCompilandFilters;
|
||||
std::list<Regex> ExcludeTypeFilters;
|
||||
|
@ -120,11 +122,8 @@ struct PrintScope {
|
|||
uint32_t LabelWidth = 0;
|
||||
};
|
||||
|
||||
inline Optional<PrintScope> withLabelWidth(const Optional<PrintScope> &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<PrintScope> &Scope) {
|
||||
if (Scope.hasValue()) {
|
||||
L = &Scope->P;
|
||||
Amount = Scope->IndentLevel;
|
||||
}
|
||||
explicit AutoIndent(const PrintScope &Scope) {
|
||||
L = &Scope.P;
|
||||
Amount = Scope.IndentLevel;
|
||||
}
|
||||
~AutoIndent() {
|
||||
if (L)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<llvm::Regex> &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(),
|
||||
|
|
|
@ -552,10 +552,7 @@ Error DumpOutputStyle::dumpSymbolStats() {
|
|||
|
||||
StatCollection SymStats;
|
||||
StatCollection ChunkStats;
|
||||
|
||||
Optional<PrintScope> 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 {
|
||||
|
|
Loading…
Reference in New Issue