[llvm-pdbdump] Colorize output.
llvm-svn: 230746
diff --git a/llvm/tools/llvm-pdbdump/FunctionDumper.cpp b/llvm/tools/llvm-pdbdump/FunctionDumper.cpp
index 1a1defe..aafbbfa 100644
--- a/llvm/tools/llvm-pdbdump/FunctionDumper.cpp
+++ b/llvm/tools/llvm-pdbdump/FunctionDumper.cpp
@@ -9,6 +9,7 @@
#include "FunctionDumper.h"
#include "BuiltinDumper.h"
+#include "LinePrinter.h"
#include "llvm-pdbdump.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
@@ -29,7 +30,7 @@
namespace {
template <class T>
-void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS,
+void dumpClassParentWithScopeOperator(const T &Symbol, LinePrinter &Printer,
llvm::FunctionDumper &Dumper) {
uint32_t ClassParentId = Symbol.getClassParentId();
auto ClassParent =
@@ -38,18 +39,20 @@
if (!ClassParent)
return;
- OS << ClassParent->getName() << "::";
+ WithColor(Printer, PDB_ColorItem::Type).get() << ClassParent->getName();
+ Printer << "::";
}
}
-FunctionDumper::FunctionDumper() : PDBSymDumper(true) {}
+FunctionDumper::FunctionDumper(LinePrinter &P)
+ : PDBSymDumper(true), Printer(P) {}
void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol,
const char *Name, PointerType Pointer,
raw_ostream &OS) {
auto ReturnType = Symbol.getReturnType();
ReturnType->dump(OS, 0, *this);
- OS << " ";
+ Printer << " ";
uint32_t ClassParentId = Symbol.getClassParentId();
auto ClassParent =
Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
@@ -64,39 +67,46 @@
if (Pointer == PointerType::None) {
if (ShouldDumpCallingConvention)
- OS << CC << " ";
- if (ClassParent)
- OS << "(" << ClassParent->getName() << "::)";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
+ if (ClassParent) {
+ Printer << "(";
+ WithColor(Printer, PDB_ColorItem::Identifier).get()
+ << ClassParent->getName();
+ Printer << "::)";
+ }
} else {
- OS << "(";
+ Printer << "(";
if (ShouldDumpCallingConvention)
- OS << CC << " ";
- if (ClassParent)
- OS << ClassParent->getName() << "::";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
+ if (ClassParent) {
+ WithColor(Printer, PDB_ColorItem::Identifier).get()
+ << ClassParent->getName();
+ Printer << "::";
+ }
if (Pointer == PointerType::Reference)
- OS << "&";
+ Printer << "&";
else
- OS << "*";
+ Printer << "*";
if (Name)
- OS << Name;
- OS << ")";
+ WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
+ Printer << ")";
}
- OS << "(";
+ Printer << "(";
if (auto ChildEnum = Symbol.getArguments()) {
uint32_t Index = 0;
while (auto Arg = ChildEnum->getNext()) {
Arg->dump(OS, 0, *this);
if (++Index < ChildEnum->getChildCount())
- OS << ", ";
+ Printer << ", ";
}
}
- OS << ")";
+ Printer << ")";
if (Symbol.isConstType())
- OS << " const";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
if (Symbol.isVolatileType())
- OS << " volatile";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
}
void FunctionDumper::start(const PDBSymbolFunc &Symbol, PointerType Pointer,
@@ -104,74 +114,83 @@
uint32_t FuncStart = Symbol.getRelativeVirtualAddress();
uint32_t FuncEnd = FuncStart + Symbol.getLength();
- OS << newline(Indent);
-
- OS << "func [" << format_hex(FuncStart, 8);
- if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>())
- OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
- OS << " - " << format_hex(FuncEnd, 8);
- if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>())
- OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
- OS << "] ";
+ Printer << "func ";
+ WithColor(Printer, PDB_ColorItem::Address).get() << "["
+ << format_hex(FuncStart, 8);
+ if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>()) {
+ uint32_t Prologue = DebugStart->getRelativeVirtualAddress() - FuncStart;
+ WithColor(Printer, PDB_ColorItem::Offset).get() << "+" << Prologue;
+ }
+ WithColor(Printer, PDB_ColorItem::Address).get() << " - "
+ << format_hex(FuncEnd, 8);
+ if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>()) {
+ uint32_t Epilogue = FuncEnd - DebugEnd->getRelativeVirtualAddress();
+ WithColor(Printer, PDB_ColorItem::Offset).get() << "-" << Epilogue;
+ }
+ WithColor(Printer, PDB_ColorItem::Address).get() << "] ";
if (Symbol.hasFramePointer())
- OS << "(" << Symbol.getLocalBasePointerRegisterId() << ")";
+ WithColor(Printer, PDB_ColorItem::Address).get()
+ << "(" << Symbol.getLocalBasePointerRegisterId() << ")";
else
- OS << "(FPO)";
+ WithColor(Printer, PDB_ColorItem::Address).get() << "(FPO)";
- OS << " ";
+ Printer << " ";
if (Symbol.isVirtual() || Symbol.isPureVirtual())
- OS << "virtual ";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << "virtual ";
auto Signature = Symbol.getSignature();
if (!Signature) {
- OS << Symbol.getName();
+ WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
if (Pointer == PointerType::Pointer)
- OS << "*";
+ Printer << "*";
else if (Pointer == FunctionDumper::PointerType::Reference)
- OS << "&";
+ Printer << "&";
return;
}
auto ReturnType = Signature->getReturnType();
ReturnType->dump(OS, 0, *this);
- OS << " ";
+ Printer << " ";
auto ClassParent = Symbol.getClassParent();
PDB_CallingConv CC = Signature->getCallingConvention();
if (Pointer != FunctionDumper::PointerType::None)
- OS << "(";
+ Printer << "(";
if ((ClassParent && CC != PDB_CallingConv::Thiscall) ||
- (!ClassParent && CC != PDB_CallingConv::NearStdcall))
- OS << Signature->getCallingConvention() << " ";
- OS << Symbol.getName();
+ (!ClassParent && CC != PDB_CallingConv::NearStdcall)) {
+ WithColor(Printer, PDB_ColorItem::Keyword).get()
+ << Signature->getCallingConvention() << " ";
+ }
+ WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
if (Pointer != FunctionDumper::PointerType::None) {
if (Pointer == PointerType::Pointer)
- OS << "*";
+ Printer << "*";
else if (Pointer == FunctionDumper::PointerType::Reference)
- OS << "&";
- OS << ")";
+ Printer << "&";
+ Printer << ")";
}
- OS << "(";
+ Printer << "(";
if (auto Arguments = Symbol.getArguments()) {
uint32_t Index = 0;
while (auto Arg = Arguments->getNext()) {
auto ArgType = Arg->getType();
ArgType->dump(OS, 0, *this);
- OS << " " << Arg->getName();
+ WithColor(Printer, PDB_ColorItem::Identifier).get() << " "
+ << Arg->getName();
if (++Index < Arguments->getChildCount())
- OS << ", ";
+ Printer << ", ";
}
}
- OS << ")";
+ Printer << ")";
if (Symbol.isConstType())
- OS << " const";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
if (Symbol.isVolatileType())
- OS << " volatile";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
if (Symbol.isPureVirtual())
- OS << " = 0";
+ Printer << " = 0";
}
void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS,
@@ -182,26 +201,27 @@
return;
ElementType->dump(OS, 0, *this);
- OS << "[" << Symbol.getLength() << "]";
+ Printer << "[";
+ WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Symbol.getLength();
+ Printer << "]";
}
void FunctionDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS,
int Indent) {
- BuiltinDumper Dumper;
+ BuiltinDumper Dumper(Printer);
Dumper.start(Symbol, OS);
}
void FunctionDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
int Indent) {
- dumpClassParentWithScopeOperator(Symbol, OS, *this);
- OS << Symbol.getName();
+ dumpClassParentWithScopeOperator(Symbol, Printer, *this);
+ WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
}
void FunctionDumper::dump(const PDBSymbolTypeFunctionArg &Symbol,
raw_ostream &OS, int Indent) {
// PDBSymbolTypeFunctionArg is just a shim over the real argument. Just drill
// through to the real thing and dump it.
- Symbol.defaultDump(OS, Indent);
uint32_t TypeId = Symbol.getTypeId();
auto Type = Symbol.getSession().getSymbolById(TypeId);
if (!Type)
@@ -211,8 +231,8 @@
void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
int Indent) {
- dumpClassParentWithScopeOperator(Symbol, OS, *this);
- OS << Symbol.getName();
+ dumpClassParentWithScopeOperator(Symbol, Printer, *this);
+ WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
}
void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
@@ -223,15 +243,15 @@
return;
if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
- FunctionDumper NestedDumper;
+ FunctionDumper NestedDumper(Printer);
PointerType Pointer =
Symbol.isReference() ? PointerType::Reference : PointerType::Pointer;
NestedDumper.start(*FuncSig, nullptr, Pointer, OS);
} else {
if (Symbol.isConstType())
- OS << "const ";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
if (Symbol.isVolatileType())
- OS << "volatile ";
+ WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
PointeeType->dump(OS, Indent, *this);
OS << (Symbol.isReference() ? "&" : "*");
}
@@ -239,5 +259,5 @@
void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
int Indent) {
- OS << Symbol.getName();
+ WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
}