Skip to content

Commit

Permalink
[llvm-pdbdump] Allow pretty to only dump specific types of types.
Browse files Browse the repository at this point in the history
Previously we just had the -types option, which would dump all
classes, typedefs, and enums.  But this produces a lot of output
if you only want to view classes, for example.  This patch breaks
this down into 3 additional options, -classes, -enums, and
-typedefs, and keeps the -types option around which implies all
3 more specific options.

Differential Revision: https://reviews.llvm.org/D31791

llvm-svn: 299732
  • Loading branch information
Zachary Turner committed Apr 6, 2017
1 parent 5dcbbbc commit 63230a4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
64 changes: 38 additions & 26 deletions llvm/tools/llvm-pdbdump/PrettyTypeDumper.cpp
Expand Up @@ -29,35 +29,43 @@ using namespace llvm::pdb;
TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}

void TypeDumper::start(const PDBSymbolExe &Exe) {
auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
Printer << ": (" << Enums->getChildCount() << " items)";
Printer.Indent();
while (auto Enum = Enums->getNext())
Enum->dump(*this);
Printer.Unindent();

auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
Printer << ": (" << Typedefs->getChildCount() << " items)";
Printer.Indent();
while (auto Typedef = Typedefs->getNext())
Typedef->dump(*this);
Printer.Unindent();

auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
Printer << ": (" << Classes->getChildCount() << " items)";
Printer.Indent();
while (auto Class = Classes->getNext())
Class->dump(*this);
Printer.Unindent();
if (opts::pretty::Enums) {
auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
Printer << ": (" << Enums->getChildCount() << " items)";
Printer.Indent();
while (auto Enum = Enums->getNext())
Enum->dump(*this);
Printer.Unindent();
}

if (opts::pretty::Typedefs) {
auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
Printer << ": (" << Typedefs->getChildCount() << " items)";
Printer.Indent();
while (auto Typedef = Typedefs->getNext())
Typedef->dump(*this);
Printer.Unindent();
}

if (opts::pretty::Classes) {
auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
Printer << ": (" << Classes->getChildCount() << " items)";
Printer.Indent();
while (auto Class = Classes->getNext())
Class->dump(*this);
Printer.Unindent();
}
}

void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol) {
assert(opts::pretty::Enums);

if (Symbol.getUnmodifiedTypeId() != 0)
return;
if (Printer.IsTypeExcluded(Symbol.getName()))
Expand All @@ -72,6 +80,8 @@ void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol) {
}

void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
assert(opts::pretty::Typedefs);

if (Printer.IsTypeExcluded(Symbol.getName()))
return;

Expand All @@ -81,6 +91,8 @@ void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
}

void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol) {
assert(opts::pretty::Classes);

if (Symbol.getUnmodifiedTypeId() != 0)
return;
if (Printer.IsTypeExcluded(Symbol.getName()))
Expand Down
21 changes: 18 additions & 3 deletions llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp
Expand Up @@ -112,8 +112,17 @@ cl::opt<bool> Globals("globals", cl::desc("Dump global symbols"),
cl::cat(TypeCategory), cl::sub(PrettySubcommand));
cl::opt<bool> Externals("externals", cl::desc("Dump external symbols"),
cl::cat(TypeCategory), cl::sub(PrettySubcommand));
cl::opt<bool> Types("types", cl::desc("Display types"), cl::cat(TypeCategory),
cl::sub(PrettySubcommand));
cl::opt<bool>
Types("types",
cl::desc("Display all types (implies -classes, -enums, -typedefs)"),
cl::cat(TypeCategory), cl::sub(PrettySubcommand));
cl::opt<bool> Classes("classes", cl::desc("Display class types"),
cl::cat(TypeCategory), cl::sub(PrettySubcommand));
cl::opt<bool> Enums("enums", cl::desc("Display enum types"),
cl::cat(TypeCategory), cl::sub(PrettySubcommand));
cl::opt<bool> Typedefs("typedefs", cl::desc("Display typedef types"),
cl::cat(TypeCategory), cl::sub(PrettySubcommand));

cl::opt<bool> Lines("lines", cl::desc("Line tables"), cl::cat(TypeCategory),
cl::sub(PrettySubcommand));
cl::opt<bool>
Expand Down Expand Up @@ -557,7 +566,7 @@ static void dumpPretty(StringRef Path) {
Printer.Unindent();
}

if (opts::pretty::Types) {
if (opts::pretty::Classes || opts::pretty::Enums || opts::pretty::Typedefs) {
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---";
Printer.Indent();
Expand Down Expand Up @@ -699,6 +708,12 @@ int main(int argc_, const char *argv_[]) {
opts::pretty::Lines = true;
}

if (opts::pretty::Types) {
opts::pretty::Classes = true;
opts::pretty::Typedefs = true;
opts::pretty::Enums = true;
}

// When adding filters for excluded compilands and types, we need to
// remember that these are regexes. So special characters such as * and \
// need to be escaped in the regex. In the case of a literal \, this means
Expand Down
4 changes: 3 additions & 1 deletion llvm/tools/llvm-pdbdump/llvm-pdbdump.h
Expand Up @@ -20,7 +20,9 @@ namespace pretty {
extern llvm::cl::opt<bool> Compilands;
extern llvm::cl::opt<bool> Symbols;
extern llvm::cl::opt<bool> Globals;
extern llvm::cl::opt<bool> Types;
extern llvm::cl::opt<bool> Classes;
extern llvm::cl::opt<bool> Enums;
extern llvm::cl::opt<bool> Typedefs;
extern llvm::cl::opt<bool> All;
extern llvm::cl::opt<bool> ExcludeCompilerGenerated;

Expand Down

0 comments on commit 63230a4

Please sign in to comment.