[llvm] r230888 - [llvm-pdbdump] Add regex-based filtering.
Zachary Turner
zturner at google.com
Sat Feb 28 22:49:50 PST 2015
Author: zturner
Date: Sun Mar 1 00:49:49 2015
New Revision: 230888
URL: http://llvm.org/viewvc/llvm-project?rev=230888&view=rev
Log:
[llvm-pdbdump] Add regex-based filtering.
Added:
llvm/trunk/test/tools/llvm-pdbdump/
llvm/trunk/test/tools/llvm-pdbdump/Inputs/
llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.cpp
llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.pdb
llvm/trunk/test/tools/llvm-pdbdump/lit.local.cfg
llvm/trunk/test/tools/llvm-pdbdump/regex-filter.test
Modified:
llvm/trunk/tools/llvm-pdbdump/ClassDefinitionDumper.cpp
llvm/trunk/tools/llvm-pdbdump/CompilandDumper.cpp
llvm/trunk/tools/llvm-pdbdump/LinePrinter.cpp
llvm/trunk/tools/llvm-pdbdump/LinePrinter.h
llvm/trunk/tools/llvm-pdbdump/TypeDumper.cpp
llvm/trunk/tools/llvm-pdbdump/TypeDumper.h
llvm/trunk/tools/llvm-pdbdump/VariableDumper.cpp
llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
Added: llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.cpp?rev=230888&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.cpp (added)
+++ llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.cpp Sun Mar 1 00:49:49 2015
@@ -0,0 +1,29 @@
+// Compile with "cl /c /Zi /GR- FilterTest.cpp"
+// Link with "link FilterTest.obj /debug /nodefaultlib /entry:main"
+
+class FilterTestClass {
+public:
+ typedef int NestedTypedef;
+ enum NestedEnum {
+ NestedEnumValue1
+ };
+
+ void MemberFunc() {}
+
+private:
+ int IntMemberVar;
+ double DoubleMemberVar;
+};
+
+int IntGlobalVar;
+double DoubleGlobalVar;
+typedef int GlobalTypedef;
+enum GlobalEnum {
+ GlobalEnumVal1
+} GlobalEnumVar;
+
+int main(int argc, char **argv) {
+ FilterTestClass TestClass;
+ GlobalTypedef v1;
+ return 0;
+}
Added: llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.pdb
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.pdb?rev=230888&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.pdb (added) and llvm/trunk/test/tools/llvm-pdbdump/Inputs/FilterTest.pdb Sun Mar 1 00:49:49 2015 differ
Added: llvm/trunk/test/tools/llvm-pdbdump/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-pdbdump/lit.local.cfg?rev=230888&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-pdbdump/lit.local.cfg (added)
+++ llvm/trunk/test/tools/llvm-pdbdump/lit.local.cfg Sun Mar 1 00:49:49 2015
@@ -0,0 +1 @@
+config.unsupported = not config.have_dia_sdk
Added: llvm/trunk/test/tools/llvm-pdbdump/regex-filter.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-pdbdump/regex-filter.test?rev=230888&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-pdbdump/regex-filter.test (added)
+++ llvm/trunk/test/tools/llvm-pdbdump/regex-filter.test Sun Mar 1 00:49:49 2015
@@ -0,0 +1,76 @@
+; RUN: llvm-pdbdump -symbols -globals -class-definitions -types %p/Inputs/FilterTest.pdb \
+; RUN: | FileCheck --check-prefix=NO_FILTER %s
+; RUN: llvm-pdbdump -class-definitions -types -exclude-types="GlobalTypedef|NestedTypedef" \
+; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_TYPEDEFS %s
+; RUN: llvm-pdbdump -class-definitions -types -exclude-types="GlobalEnum|NestedEnum" \
+; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_ENUMS %s
+; RUN: llvm-pdbdump -class-definitions -types -symbols -globals \
+; RUN: -exclude-symbols="MemberVar|GlobalVar" %p/Inputs/FilterTest.pdb | FileCheck \
+; RUN: --check-prefix=EXCLUDE_VARS %s
+; RUN: llvm-pdbdump -types -class-definitions -exclude-types="FilterTestClass" \
+; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_WHOLE_CLASS %s
+; RUN: llvm-pdbdump -symbols -globals -exclude-compilands="FilterTest.obj" \
+; RUN: %p/Inputs/FilterTest.pdb | FileCheck --check-prefix=EXCLUDE_COMPILAND %s
+
+; NO_FILTER: ---TYPES---
+; NO_FILTER: Enums:
+; NO_FILTER: enum GlobalEnum
+; NO_FILTER: Typedefs
+; NO_FILTER: typedef int GlobalTypedef
+; NO_FILTER: Classes:
+; NO_FILTER: class __vc_attributes
+; NO_FILTER: class FilterTestClass
+; NO_FILTER-DAG: typedef int NestedTypedef
+; NO_FILTER-DAG: enum NestedEnum
+; NO_FILTER-DAG: int IntMemberVar
+; NO_FILTER-DAG: double DoubleMemberVar
+; NO_FILTER: ---SYMBOLS---
+; NO_FILTER: Inputs\FilterTest.obj
+; NO_FILTER: int __cdecl main(int argc, char** argv)
+; NO_FILTER: ---GLOBALS---
+; NO_FILTER-DAG: double DoubleGlobalVar
+; NO_FILTER-DAG: int IntGlobalVar
+; NO_FILTER-DAG: GlobalEnum GlobalEnumVar
+
+; EXCLUDE_TYPEDEFS: ---TYPES---
+; EXCLUDE_TYPEDEFS: Enums:
+; EXCLUDE_TYPEDEFS: GlobalEnum
+; EXCLUDE_TYPEDEFS: Typedefs
+; EXCLUDE_TYPEDEFS-NOT: GlobalTypedef
+; EXCLUDE_TYPEDEFS: Classes
+; EXCLUDE_TYPEDEFS: class FilterTestClass
+; EXCLUDE_TYPEDEFS-NOT: NestedTypedef
+; EXCLUDE_TYPEDEFS: private:
+
+; EXCLUDE_ENUMS: ---TYPES---
+; EXCLUDE_ENUMS: Enums:
+; EXCLUDE_ENUMS-NOT: GlobalEnum
+; EXCLUDE_ENUMS: Typedefs
+; EXCLUDE_ENUMS: GlobalTypedef
+; EXCLUDE_ENUMS: Classes
+; EXCLUDE_ENUMS: class FilterTestClass
+; EXCLUDE_ENUMS-NOT: NestedEnum
+; EXCLUDE_ENUMS: private:
+
+; EXCLUDE_VARS: ---TYPES---
+; EXCLUDE_VARS: Classes:
+; EXCLUDE_VARS: class FilterTestClass
+; EXCLUDE_VARS: private:
+; EXCLUDE_VARS-NOT: IntMemberVar
+; EXCLUDE_VARS-NOT: DoubleMemberVar
+; EXCLUDE_VARS: ---GLOBALS---
+; EXCLUDE_VARS-NOT: DoubleGlobalVar
+; EXCLUDE_VARS-NOT: IntGlobalVar
+
+; EXCLUDE_WHOLE_CLASS: ---TYPES---
+; EXCLUDE_WHOLE_CLASS-NOT: class FilterTestClass
+; EXCLUDE_WHOLE_CLASS-NOT: typedef int NestedTypedef
+; EXCLUDE_WHOLE_CLASS-NOT: enum NestedEnum
+; EXCLUDE_WHOLE_CLASS-NOT: int IntMemberVar
+; EXCLUDE_WHOLE_CLASS-NOT: double DoubleMemberVar
+
+; EXCLUDE_COMPILAND: ---SYMBOLS---
+; EXCLUDE_COMPILAND-NOT: FilterTest.obj
+; EXCLUDE_COMPILAND-NOT: __cdecl main
+; EXCLUDE_COMPILAND: * Linker *
+; EXCLUDE_COMPILAND: ---GLOBALS---
Modified: llvm/trunk/tools/llvm-pdbdump/ClassDefinitionDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/ClassDefinitionDumper.cpp?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/ClassDefinitionDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/ClassDefinitionDumper.cpp Sun Mar 1 00:49:49 2015
@@ -142,6 +142,9 @@ void ClassDefinitionDumper::dump(const P
void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
int Indent) {
+ if (Printer.IsSymbolExcluded(Symbol.getName()))
+ return;
+
Printer.NewLine();
FunctionDumper Dumper(Printer);
Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
@@ -152,6 +155,9 @@ void ClassDefinitionDumper::dump(const P
void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol,
raw_ostream &OS, int Indent) {
+ if (Printer.IsTypeExcluded(Symbol.getName()))
+ return;
+
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
@@ -159,6 +165,9 @@ void ClassDefinitionDumper::dump(const P
void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol,
raw_ostream &OS, int Indent) {
+ if (Printer.IsTypeExcluded(Symbol.getName()))
+ return;
+
Printer.NewLine();
TypedefDumper Dumper(Printer);
Dumper.start(Symbol, OS, Indent);
Modified: llvm/trunk/tools/llvm-pdbdump/CompilandDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/CompilandDumper.cpp?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/CompilandDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/CompilandDumper.cpp Sun Mar 1 00:49:49 2015
@@ -47,6 +47,9 @@ void CompilandDumper::dump(const PDBSymb
void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS,
int Indent, bool Children) {
std::string FullName = Symbol.getName();
+ if (Printer.IsCompilandExcluded(FullName))
+ return;
+
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Path).get() << FullName;
if (!Children)
@@ -61,6 +64,9 @@ void CompilandDumper::start(const PDBSym
void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
int Indent) {
+ if (Printer.IsSymbolExcluded(Symbol.getName()))
+ return;
+
Printer.NewLine();
switch (auto LocType = Symbol.getLocationType()) {
@@ -86,6 +92,8 @@ void CompilandDumper::dump(const PDBSymb
int Indent) {
if (Symbol.getLength() == 0)
return;
+ if (Printer.IsSymbolExcluded(Symbol.getName()))
+ return;
Printer.NewLine();
FunctionDumper Dumper(Printer);
@@ -94,6 +102,9 @@ void CompilandDumper::dump(const PDBSymb
void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS,
int Indent) {
+ if (Printer.IsSymbolExcluded(Symbol.getName()))
+ return;
+
Printer.NewLine();
Printer << "label ";
WithColor(Printer, PDB_ColorItem::Address).get()
@@ -103,6 +114,9 @@ void CompilandDumper::dump(const PDBSymb
void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS,
int Indent) {
+ if (Printer.IsSymbolExcluded(Symbol.getName()))
+ return;
+
Printer.NewLine();
Printer << "thunk ";
PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal();
Modified: llvm/trunk/tools/llvm-pdbdump/LinePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/LinePrinter.cpp?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/LinePrinter.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/LinePrinter.cpp Sun Mar 1 00:49:49 2015
@@ -9,6 +9,8 @@
#include "LinePrinter.h"
+#include "llvm/Support/Regex.h"
+
#include <algorithm>
using namespace llvm;
@@ -27,6 +29,39 @@ void LinePrinter::NewLine() {
OS.indent(CurrentIndent);
}
+bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
+ if (TypeName.empty())
+ return false;
+
+ for (auto &Expr : TypeFilters) {
+ if (Expr.match(TypeName))
+ return true;
+ }
+ return false;
+}
+
+bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
+ if (SymbolName.empty())
+ return false;
+
+ for (auto &Expr : SymbolFilters) {
+ if (Expr.match(SymbolName))
+ return true;
+ }
+ return false;
+}
+
+bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
+ if (CompilandName.empty())
+ return false;
+
+ for (auto &Expr : CompilandFilters) {
+ if (Expr.match(CompilandName))
+ return true;
+ }
+ return false;
+}
+
WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
if (C == PDB_ColorItem::None)
OS.resetColor();
Modified: llvm/trunk/tools/llvm-pdbdump/LinePrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/LinePrinter.h?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/LinePrinter.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/LinePrinter.h Sun Mar 1 00:49:49 2015
@@ -12,6 +12,9 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Regex.h"
+
+#include <list>
namespace llvm {
@@ -21,17 +24,34 @@ class LinePrinter {
public:
LinePrinter(int Indent, raw_ostream &Stream);
+ template <typename Iter> void SetTypeFilters(Iter Begin, Iter End) {
+ TypeFilters.assign(Begin, End);
+ }
+ template <typename Iter> void SetSymbolFilters(Iter Begin, Iter End) {
+ SymbolFilters.assign(Begin, End);
+ }
+ template <typename Iter> void SetCompilandFilters(Iter Begin, Iter End) {
+ CompilandFilters.assign(Begin, End);
+ }
+
void Indent();
void Unindent();
-
void NewLine();
raw_ostream &getStream() { return OS; }
+ bool IsTypeExcluded(llvm::StringRef TypeName);
+ bool IsSymbolExcluded(llvm::StringRef SymbolName);
+ bool IsCompilandExcluded(llvm::StringRef CompilandName);
+
private:
raw_ostream &OS;
int IndentSpaces;
int CurrentIndent;
+
+ std::list<Regex> CompilandFilters;
+ std::list<Regex> TypeFilters;
+ std::list<Regex> SymbolFilters;
};
template <class T>
Modified: llvm/trunk/tools/llvm-pdbdump/TypeDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/TypeDumper.cpp?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/TypeDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/TypeDumper.cpp Sun Mar 1 00:49:49 2015
@@ -22,9 +22,8 @@
using namespace llvm;
-TypeDumper::TypeDumper(LinePrinter &P, bool Inline, bool ClassDefs)
- : PDBSymDumper(true), Printer(P), InlineDump(Inline),
- FullClassDefs(ClassDefs) {}
+TypeDumper::TypeDumper(LinePrinter &P, bool ClassDefs)
+ : PDBSymDumper(true), Printer(P), FullClassDefs(ClassDefs) {}
void TypeDumper::start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent) {
auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
@@ -59,9 +58,9 @@ void TypeDumper::dump(const PDBSymbolTyp
int Indent) {
if (Symbol.getUnmodifiedTypeId() != 0)
return;
-
- if (!InlineDump)
- Printer.NewLine();
+ if (Printer.IsTypeExcluded(Symbol.getName()))
+ return;
+ Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
@@ -69,9 +68,10 @@ void TypeDumper::dump(const PDBSymbolTyp
void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
int Indent) {
- if (!InlineDump)
- Printer.NewLine();
+ if (Printer.IsTypeExcluded(Symbol.getName()))
+ return;
+ Printer.NewLine();
TypedefDumper Dumper(Printer);
Dumper.start(Symbol, OS, Indent);
}
@@ -80,8 +80,10 @@ void TypeDumper::dump(const PDBSymbolTyp
int Indent) {
if (Symbol.getUnmodifiedTypeId() != 0)
return;
- if (!InlineDump)
- Printer.NewLine();
+ if (Printer.IsTypeExcluded(Symbol.getName()))
+ return;
+
+ Printer.NewLine();
if (FullClassDefs) {
ClassDefinitionDumper Dumper(Printer);
Modified: llvm/trunk/tools/llvm-pdbdump/TypeDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/TypeDumper.h?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/TypeDumper.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/TypeDumper.h Sun Mar 1 00:49:49 2015
@@ -18,7 +18,7 @@ class LinePrinter;
class TypeDumper : public PDBSymDumper {
public:
- TypeDumper(LinePrinter &P, bool Inline, bool ClassDefs);
+ TypeDumper(LinePrinter &P, bool ClassDefs);
void start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent);
@@ -31,7 +31,6 @@ public:
private:
LinePrinter &Printer;
- bool InlineDump;
bool FullClassDefs;
};
}
Modified: llvm/trunk/tools/llvm-pdbdump/VariableDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/VariableDumper.cpp?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/VariableDumper.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/VariableDumper.cpp Sun Mar 1 00:49:49 2015
@@ -32,6 +32,9 @@ VariableDumper::VariableDumper(LinePrint
void VariableDumper::start(const PDBSymbolData &Var, raw_ostream &OS,
int Indent) {
+ if (Printer.IsSymbolExcluded(Var.getName()))
+ return;
+
Printer.NewLine();
Printer << "data ";
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=230888&r1=230887&r2=230888&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Sun Mar 1 00:49:49 2015
@@ -63,6 +63,19 @@ cl::opt<bool> Globals("globals", cl::des
cl::opt<bool> Types("types", cl::desc("Display types"));
cl::opt<bool> ClassDefs("class-definitions",
cl::desc("Display full class definitions"));
+
+cl::list<std::string>
+ ExcludeTypes("exclude-types",
+ cl::desc("Exclude types by regular expression"),
+ cl::ZeroOrMore);
+cl::list<std::string>
+ ExcludeSymbols("exclude-symbols",
+ cl::desc("Exclude symbols by regular expression"),
+ cl::ZeroOrMore);
+cl::list<std::string>
+ ExcludeCompilands("exclude-compilands",
+ cl::desc("Exclude compilands by regular expression"),
+ cl::ZeroOrMore);
}
static void dumpInput(StringRef Path) {
@@ -90,6 +103,11 @@ static void dumpInput(StringRef Path) {
}
LinePrinter Printer(2, outs());
+ Printer.SetTypeFilters(opts::ExcludeTypes.begin(), opts::ExcludeTypes.end());
+ Printer.SetSymbolFilters(opts::ExcludeSymbols.begin(),
+ opts::ExcludeSymbols.end());
+ Printer.SetCompilandFilters(opts::ExcludeCompilands.begin(),
+ opts::ExcludeCompilands.end());
auto GlobalScope(Session->getGlobalScope());
std::string FileName(GlobalScope->getSymbolsFileName());
@@ -140,7 +158,7 @@ static void dumpInput(StringRef Path) {
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
Printer.Indent();
- TypeDumper Dumper(Printer, false, opts::ClassDefs);
+ TypeDumper Dumper(Printer, opts::ClassDefs);
Dumper.start(*GlobalScope, outs(), 2);
Printer.Unindent();
}
More information about the llvm-commits
mailing list