From 2d11c20445efe9ff69522e907e4be6b95c98eeba Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 27 Feb 2015 09:15:59 +0000 Subject: [PATCH] [llvm-pdbdump] Colorize output. llvm-svn: 230746 --- llvm/tools/llvm-pdbdump/BuiltinDumper.cpp | 48 +++--- llvm/tools/llvm-pdbdump/BuiltinDumper.h | 7 +- llvm/tools/llvm-pdbdump/CMakeLists.txt | 1 + .../llvm-pdbdump/ClassDefinitionDumper.cpp | 46 ++++-- .../llvm-pdbdump/ClassDefinitionDumper.h | 6 +- llvm/tools/llvm-pdbdump/CompilandDumper.cpp | 60 +++++--- llvm/tools/llvm-pdbdump/CompilandDumper.h | 7 +- llvm/tools/llvm-pdbdump/FunctionDumper.cpp | 144 ++++++++++-------- llvm/tools/llvm-pdbdump/FunctionDumper.h | 7 +- llvm/tools/llvm-pdbdump/LinePrinter.cpp | 80 ++++++++++ llvm/tools/llvm-pdbdump/LinePrinter.h | 69 +++++++++ llvm/tools/llvm-pdbdump/TypeDumper.cpp | 42 +++-- llvm/tools/llvm-pdbdump/TypeDumper.h | 5 +- llvm/tools/llvm-pdbdump/TypedefDumper.cpp | 23 +-- llvm/tools/llvm-pdbdump/TypedefDumper.h | 7 +- llvm/tools/llvm-pdbdump/VariableDumper.cpp | 53 ++++--- llvm/tools/llvm-pdbdump/VariableDumper.h | 6 +- llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp | 71 ++++++--- 18 files changed, 492 insertions(+), 190 deletions(-) create mode 100644 llvm/tools/llvm-pdbdump/LinePrinter.cpp create mode 100644 llvm/tools/llvm-pdbdump/LinePrinter.h diff --git a/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp b/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp index 753663fe1557..03f3d42808b2 100644 --- a/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp +++ b/llvm/tools/llvm-pdbdump/BuiltinDumper.cpp @@ -8,73 +8,81 @@ //===----------------------------------------------------------------------===// #include "BuiltinDumper.h" +#include "LinePrinter.h" #include "llvm-pdbdump.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" using namespace llvm; -BuiltinDumper::BuiltinDumper() : PDBSymDumper(false) {} +BuiltinDumper::BuiltinDumper(LinePrinter &P) + : PDBSymDumper(false), Printer(P) {} void BuiltinDumper::start(const PDBSymbolTypeBuiltin &Symbol, llvm::raw_ostream &OS) { PDB_BuiltinType Type = Symbol.getBuiltinType(); switch (Type) { case PDB_BuiltinType::Float: - OS << ((Symbol.getLength() == 4) ? "float" : "double"); + if (Symbol.getLength() == 4) + WithColor(Printer, PDB_ColorItem::Type).get() << "float"; + else + WithColor(Printer, PDB_ColorItem::Type).get() << "double"; break; case PDB_BuiltinType::UInt: - OS << "unsigned"; + WithColor(Printer, PDB_ColorItem::Type).get() << "unsigned"; if (Symbol.getLength() == 8) - OS << " __int64"; + WithColor(Printer, PDB_ColorItem::Type).get() << " __int64"; break; case PDB_BuiltinType::Int: - OS << ((Symbol.getLength() == 4) ? "int" : "__int64"); + if (Symbol.getLength() == 4) + WithColor(Printer, PDB_ColorItem::Type).get() << "int"; + else + WithColor(Printer, PDB_ColorItem::Type).get() << "__int64"; break; case PDB_BuiltinType::Char: - OS << "char"; + WithColor(Printer, PDB_ColorItem::Type).get() << "char"; break; case PDB_BuiltinType::WCharT: - OS << "wchar_t"; + WithColor(Printer, PDB_ColorItem::Type).get() << "wchar_t"; break; case PDB_BuiltinType::Void: - OS << "void"; + WithColor(Printer, PDB_ColorItem::Type).get() << "void"; break; case PDB_BuiltinType::Long: - OS << "long"; + WithColor(Printer, PDB_ColorItem::Type).get() << "long"; break; case PDB_BuiltinType::ULong: - OS << "unsigned long"; + WithColor(Printer, PDB_ColorItem::Type).get() << "unsigned long"; break; case PDB_BuiltinType::Bool: - OS << "bool"; + WithColor(Printer, PDB_ColorItem::Type).get() << "bool"; break; case PDB_BuiltinType::Currency: - OS << "CURRENCY"; + WithColor(Printer, PDB_ColorItem::Type).get() << "CURRENCY"; break; case PDB_BuiltinType::Date: - OS << "DATE"; + WithColor(Printer, PDB_ColorItem::Type).get() << "DATE"; break; case PDB_BuiltinType::Variant: - OS << "VARIANT"; + WithColor(Printer, PDB_ColorItem::Type).get() << "VARIANT"; break; case PDB_BuiltinType::Complex: - OS << "complex"; + WithColor(Printer, PDB_ColorItem::Type).get() << "complex"; break; case PDB_BuiltinType::Bitfield: - OS << "bitfield"; + WithColor(Printer, PDB_ColorItem::Type).get() << "bitfield"; break; case PDB_BuiltinType::BSTR: - OS << "BSTR"; + WithColor(Printer, PDB_ColorItem::Type).get() << "BSTR"; break; case PDB_BuiltinType::HResult: - OS << "HRESULT"; + WithColor(Printer, PDB_ColorItem::Type).get() << "HRESULT"; break; case PDB_BuiltinType::BCD: - OS << "HRESULT"; + WithColor(Printer, PDB_ColorItem::Type).get() << "HRESULT"; break; default: - OS << "(unknown builtin type)"; + WithColor(Printer, PDB_ColorItem::Type).get() << "(unknown)"; break; } } diff --git a/llvm/tools/llvm-pdbdump/BuiltinDumper.h b/llvm/tools/llvm-pdbdump/BuiltinDumper.h index 5e30fac779af..99e11a11445a 100644 --- a/llvm/tools/llvm-pdbdump/BuiltinDumper.h +++ b/llvm/tools/llvm-pdbdump/BuiltinDumper.h @@ -14,11 +14,16 @@ namespace llvm { +class LinePrinter; + class BuiltinDumper : public PDBSymDumper { public: - BuiltinDumper(); + BuiltinDumper(LinePrinter &P); void start(const PDBSymbolTypeBuiltin &Symbol, llvm::raw_ostream &OS); + +private: + LinePrinter &Printer; }; } diff --git a/llvm/tools/llvm-pdbdump/CMakeLists.txt b/llvm/tools/llvm-pdbdump/CMakeLists.txt index 6dae9147bc23..341a8496a1b4 100644 --- a/llvm/tools/llvm-pdbdump/CMakeLists.txt +++ b/llvm/tools/llvm-pdbdump/CMakeLists.txt @@ -9,6 +9,7 @@ add_llvm_tool(llvm-pdbdump ClassDefinitionDumper.cpp CompilandDumper.cpp FunctionDumper.cpp + LinePrinter.cpp TypeDumper.cpp TypedefDumper.cpp VariableDumper.cpp diff --git a/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.cpp b/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.cpp index edf6eb42b2cb..8a0c04fc5e49 100644 --- a/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.cpp +++ b/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.cpp @@ -9,6 +9,7 @@ #include "ClassDefinitionDumper.h" #include "FunctionDumper.h" +#include "LinePrinter.h" #include "llvm-pdbdump.h" #include "TypedefDumper.h" #include "VariableDumper.h" @@ -27,11 +28,15 @@ using namespace llvm; -ClassDefinitionDumper::ClassDefinitionDumper() : PDBSymDumper(true) {} +ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P) + : PDBSymDumper(true), Printer(P) {} void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class, raw_ostream &OS, int Indent) { - OS << "class " << Class.getName() << " {"; + std::string Name = Class.getName(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "class "; + WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName(); + Printer << " {"; auto Children = Class.findAllChildren(); if (Children->getChildCount() == 0) { OS << "}"; @@ -81,9 +86,8 @@ void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class, Groups[(int)PDB_MemberAccess::Protected], OS, Indent); Count += dumpAccessGroup(PDB_MemberAccess::Private, Groups[(int)PDB_MemberAccess::Private], OS, Indent); - if (Count > 0) - OS << newline(Indent); + Printer.NewLine(); OS << "}"; } @@ -94,12 +98,20 @@ int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access, return 0; int Count = 0; - if (Access == PDB_MemberAccess::Private) - OS << newline(Indent) << "private:"; - else if (Access == PDB_MemberAccess::Protected) - OS << newline(Indent) << "protected:"; - else if (Access == PDB_MemberAccess::Public) - OS << newline(Indent) << "public:"; + if (Access == PDB_MemberAccess::Private) { + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "private"; + Printer << ":"; + } else if (Access == PDB_MemberAccess::Protected) { + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected"; + Printer << ":"; + } else if (Access == PDB_MemberAccess::Public) { + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "public"; + Printer << ":"; + } + Printer.Indent(); for (auto iter = Group.Functions.begin(), end = Group.Functions.end(); iter != end; ++iter) { ++Count; @@ -115,6 +127,7 @@ int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access, ++Count; (*iter)->dump(OS, Indent + 2, *this); } + Printer.Unindent(); return Count; } @@ -123,13 +136,14 @@ void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol, void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS, int Indent) { - VariableDumper Dumper; + VariableDumper Dumper(Printer); Dumper.start(Symbol, OS, Indent); } void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, int Indent) { - FunctionDumper Dumper; + Printer.NewLine(); + FunctionDumper Dumper(Printer); Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent); } @@ -138,13 +152,15 @@ void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol, void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, int Indent) { - OS << newline(Indent) << "enum " << Symbol.getName(); + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; + WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); } void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, int Indent) { - OS << newline(Indent); - TypedefDumper Dumper; + Printer.NewLine(); + TypedefDumper Dumper(Printer); Dumper.start(Symbol, OS, Indent); } diff --git a/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.h b/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.h index aaf03769fbe0..092e3b1f2e05 100644 --- a/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.h +++ b/llvm/tools/llvm-pdbdump/ClassDefinitionDumper.h @@ -20,9 +20,11 @@ namespace llvm { +class LinePrinter; + class ClassDefinitionDumper : public PDBSymDumper { public: - ClassDefinitionDumper(); + ClassDefinitionDumper(LinePrinter &P); void start(const PDBSymbolTypeUDT &Exe, raw_ostream &OS, int Indent); @@ -40,6 +42,8 @@ public: int Indent) override; private: + LinePrinter &Printer; + struct SymbolGroup { SymbolGroup() {} SymbolGroup(SymbolGroup &&Other) { diff --git a/llvm/tools/llvm-pdbdump/CompilandDumper.cpp b/llvm/tools/llvm-pdbdump/CompilandDumper.cpp index 852ddfa02a5a..ff956a0c1419 100644 --- a/llvm/tools/llvm-pdbdump/CompilandDumper.cpp +++ b/llvm/tools/llvm-pdbdump/CompilandDumper.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "CompilandDumper.h" +#include "LinePrinter.h" #include "llvm-pdbdump.h" #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" @@ -34,7 +35,8 @@ using namespace llvm; -CompilandDumper::CompilandDumper() : PDBSymDumper(true) {} +CompilandDumper::CompilandDumper(LinePrinter &P) + : Printer(P), PDBSymDumper(true) {} void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol, raw_ostream &OS, int Indent) {} @@ -45,32 +47,39 @@ void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS, int Indent, bool Children) { std::string FullName = Symbol.getName(); - OS << newline(Indent) << FullName; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Path).get() << FullName; if (!Children) return; auto ChildrenEnum = Symbol.findAllChildren(); + Printer.Indent(); while (auto Child = ChildrenEnum->getNext()) Child->dump(OS, Indent + 2, *this); + Printer.Unindent(); } void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS, int Indent) { - OS << newline(Indent); + Printer.NewLine(); + switch (auto LocType = Symbol.getLocationType()) { case PDB_LocType::Static: - OS << "data: ["; - OS << format_hex(Symbol.getRelativeVirtualAddress(), 10); - OS << "]"; + Printer << "data: "; + WithColor(Printer, PDB_ColorItem::Address).get() + << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "]"; break; case PDB_LocType::Constant: - OS << "constant: [" << Symbol.getValue() << "]"; + Printer << "constant: "; + WithColor(Printer, PDB_ColorItem::LiteralValue).get() + << "[" << Symbol.getValue() << "]"; break; default: - OS << "data(unexpected type=" << LocType << ")"; + Printer << "data(unexpected type=" << LocType << ")"; } - OS << " " << Symbol.getName(); + Printer << " "; + WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName(); } void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, @@ -78,33 +87,40 @@ void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, if (Symbol.getLength() == 0) return; - FunctionDumper Dumper; + Printer.NewLine(); + FunctionDumper Dumper(Printer); Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent); } void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, int Indent) { - OS << newline(Indent); - OS << "label [" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] " - << Symbol.getName(); + Printer.NewLine(); + Printer << "label "; + WithColor(Printer, PDB_ColorItem::Address).get() + << "[" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] "; + WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName(); } void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, int Indent) { - OS << newline(Indent) << "thunk "; + Printer.NewLine(); + Printer << "thunk "; PDB_ThunkOrdinal Ordinal = Symbol.getThunkOrdinal(); uint32_t RVA = Symbol.getRelativeVirtualAddress(); if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) { - OS << format_hex(RVA, 10); - OS << " -> " << format_hex(Symbol.getTargetRelativeVirtualAddress(), 10); + uint32_t Target = Symbol.getTargetRelativeVirtualAddress(); + WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(RVA, 10); + Printer << " -> "; + WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(Target, 10); } else { - OS << "[" << format_hex(RVA, 10); - OS << " - " << format_hex(RVA + Symbol.getLength(), 10) << "]"; + WithColor(Printer, PDB_ColorItem::Address).get() + << "[" << format_hex(RVA, 10) << " - " + << format_hex(RVA + Symbol.getLength(), 10) << "]"; } - OS << " (" << Ordinal << ") "; + Printer << " (" << Ordinal << ") "; std::string Name = Symbol.getName(); if (!Name.empty()) - OS << Name; + WithColor(Printer, PDB_ColorItem::Identifier).get() << Name; } void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, @@ -112,6 +128,6 @@ void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, int Indent) { - OS << newline(Indent); - OS << "unknown (" << Symbol.getSymTag() << ")"; + Printer.NewLine(); + Printer << "unknown (" << Symbol.getSymTag() << ")"; } diff --git a/llvm/tools/llvm-pdbdump/CompilandDumper.h b/llvm/tools/llvm-pdbdump/CompilandDumper.h index abcebc298149..f17fa449327b 100644 --- a/llvm/tools/llvm-pdbdump/CompilandDumper.h +++ b/llvm/tools/llvm-pdbdump/CompilandDumper.h @@ -14,9 +14,11 @@ namespace llvm { +class LinePrinter; + class CompilandDumper : public PDBSymDumper { public: - CompilandDumper(); + CompilandDumper(LinePrinter &P); void start(const PDBSymbolCompiland &Symbol, raw_ostream &OS, int Indent, bool Children); @@ -33,6 +35,9 @@ public: int Indent) override; void dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, int Indent) override; + +private: + LinePrinter &Printer; }; } diff --git a/llvm/tools/llvm-pdbdump/FunctionDumper.cpp b/llvm/tools/llvm-pdbdump/FunctionDumper.cpp index 1a1defed0420..aafbbfa64689 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 @@ using namespace llvm; namespace { template -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 @@ void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS, 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( @@ -64,39 +67,46 @@ void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol, 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 @@ void FunctionDumper::start(const PDBSymbolFunc &Symbol, PointerType Pointer, 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()) - OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart; - OS << " - " << format_hex(FuncEnd, 8); - if (auto DebugEnd = Symbol.findOneChild()) - OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress(); - OS << "] "; + Printer << "func "; + WithColor(Printer, PDB_ColorItem::Address).get() << "[" + << format_hex(FuncStart, 8); + if (auto DebugStart = Symbol.findOneChild()) { + 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()) { + 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 @@ void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, 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 PDBSymbolTypeFunctionArg &Symbol, 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 @@ void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, return; if (auto FuncSig = dyn_cast(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 PDBSymbolTypePointer &Symbol, raw_ostream &OS, void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, int Indent) { - OS << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); } diff --git a/llvm/tools/llvm-pdbdump/FunctionDumper.h b/llvm/tools/llvm-pdbdump/FunctionDumper.h index 63aa5658f604..63fde6eb220f 100644 --- a/llvm/tools/llvm-pdbdump/FunctionDumper.h +++ b/llvm/tools/llvm-pdbdump/FunctionDumper.h @@ -14,9 +14,11 @@ namespace llvm { +class LinePrinter; + class FunctionDumper : public PDBSymDumper { public: - FunctionDumper(); + FunctionDumper(LinePrinter &P); enum class PointerType { None, Pointer, Reference }; @@ -39,6 +41,9 @@ public: int Indent) override; void dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, int Indent) override; + +private: + LinePrinter &Printer; }; } diff --git a/llvm/tools/llvm-pdbdump/LinePrinter.cpp b/llvm/tools/llvm-pdbdump/LinePrinter.cpp new file mode 100644 index 000000000000..afdfa37edf34 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/LinePrinter.cpp @@ -0,0 +1,80 @@ +//===- LinePrinter.cpp ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "LinePrinter.h" + +#include + +using namespace llvm; + +LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream) + : IndentSpaces(Indent), CurrentIndent(0), OS(Stream) {} + +void LinePrinter::Indent() { CurrentIndent += IndentSpaces; } + +void LinePrinter::Unindent() { + CurrentIndent = std::max(0, CurrentIndent - IndentSpaces); +} + +void LinePrinter::NewLine() { + OS << "\n"; + OS.indent(CurrentIndent); +} + +WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) { + if (C == PDB_ColorItem::None) + OS.resetColor(); + else { + raw_ostream::Colors Color; + bool Bold; + translateColor(C, Color, Bold); + OS.changeColor(Color, Bold); + } +} + +WithColor::~WithColor() { OS.resetColor(); } + +void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color, + bool &Bold) const { + switch (C) { + case PDB_ColorItem::Address: + Color = raw_ostream::YELLOW; + Bold = true; + return; + case PDB_ColorItem::Keyword: + Color = raw_ostream::MAGENTA; + Bold = true; + return; + case PDB_ColorItem::Offset: + Color = raw_ostream::YELLOW; + Bold = false; + return; + case PDB_ColorItem::Type: + Color = raw_ostream::CYAN; + Bold = true; + return; + case PDB_ColorItem::Identifier: + Color = raw_ostream::CYAN; + Bold = false; + return; + case PDB_ColorItem::Path: + Color = raw_ostream::CYAN; + Bold = false; + return; + case PDB_ColorItem::SectionHeader: + Color = raw_ostream::RED; + Bold = true; + return; + case PDB_ColorItem::LiteralValue: + Color = raw_ostream::GREEN; + Bold = true; + default: + return; + } +} diff --git a/llvm/tools/llvm-pdbdump/LinePrinter.h b/llvm/tools/llvm-pdbdump/LinePrinter.h new file mode 100644 index 000000000000..0f66d1f7c85f --- /dev/null +++ b/llvm/tools/llvm-pdbdump/LinePrinter.h @@ -0,0 +1,69 @@ +//===- LinePrinter.h ------------------------------------------ *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H +#define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H + +#include "llvm/ADT/Twine.h" +#include "llvm/Support/raw_ostream.h" + +namespace llvm { + +class LinePrinter { + friend class WithColor; + +public: + LinePrinter(int Indent, raw_ostream &Stream); + + void Indent(); + void Unindent(); + + void NewLine(); + + raw_ostream &getStream() { return OS; } + +private: + raw_ostream &OS; + int IndentSpaces; + int CurrentIndent; +}; + +template +inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) { + Printer.getStream() << Item; + return Printer.getStream(); +} + +enum class PDB_ColorItem { + None, + Address, + Type, + Keyword, + Offset, + Identifier, + Path, + SectionHeader, + LiteralValue, +}; + +class WithColor { +public: + WithColor(LinePrinter &P, PDB_ColorItem C); + ~WithColor(); + + raw_ostream &get() { return OS; } + +private: + void translateColor(PDB_ColorItem C, raw_ostream::Colors &Color, + bool &Bold) const; + raw_ostream &OS; +}; +} + +#endif diff --git a/llvm/tools/llvm-pdbdump/TypeDumper.cpp b/llvm/tools/llvm-pdbdump/TypeDumper.cpp index d0df9fec7ba5..71ed203637af 100644 --- a/llvm/tools/llvm-pdbdump/TypeDumper.cpp +++ b/llvm/tools/llvm-pdbdump/TypeDumper.cpp @@ -10,6 +10,7 @@ #include "TypeDumper.h" #include "ClassDefinitionDumper.h" +#include "LinePrinter.h" #include "llvm-pdbdump.h" #include "TypedefDumper.h" @@ -21,26 +22,37 @@ using namespace llvm; -TypeDumper::TypeDumper(bool Inline, bool ClassDefs) - : PDBSymDumper(true), InlineDump(Inline), FullClassDefs(ClassDefs) {} +TypeDumper::TypeDumper(LinePrinter &P, bool Inline, bool ClassDefs) + : PDBSymDumper(true), Printer(P), InlineDump(Inline), + FullClassDefs(ClassDefs) {} void TypeDumper::start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent) { auto Enums = Exe.findAllChildren(); - OS << newline(Indent) << "Enums: (" << Enums->getChildCount() << " items)"; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums"; + Printer << ": (" << Enums->getChildCount() << " items)"; + Printer.Indent(); while (auto Enum = Enums->getNext()) Enum->dump(OS, Indent + 2, *this); + Printer.Unindent(); auto Typedefs = Exe.findAllChildren(); - OS << newline(Indent) << "Typedefs: (" << Typedefs->getChildCount() - << " items)"; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs"; + Printer << ": (" << Typedefs->getChildCount() << " items)"; + Printer.Indent(); while (auto Typedef = Typedefs->getNext()) Typedef->dump(OS, Indent + 2, *this); + Printer.Unindent(); auto Classes = Exe.findAllChildren(); - OS << newline(Indent) << "Classes: (" << Classes->getChildCount() - << " items)"; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes"; + Printer << ": (" << Classes->getChildCount() << " items)"; + Printer.Indent(); while (auto Class = Classes->getNext()) Class->dump(OS, Indent + 2, *this); + Printer.Unindent(); } void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, @@ -49,17 +61,18 @@ void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, return; if (!InlineDump) - OS << newline(Indent); + Printer.NewLine(); - OS << "enum " << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; + WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName(); } void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, int Indent) { if (!InlineDump) - OS << newline(Indent); + Printer.NewLine(); - TypedefDumper Dumper; + TypedefDumper Dumper(Printer); Dumper.start(Symbol, OS, Indent); } @@ -68,12 +81,13 @@ void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, if (Symbol.getUnmodifiedTypeId() != 0) return; if (!InlineDump) - OS << newline(Indent); + Printer.NewLine(); if (FullClassDefs) { - ClassDefinitionDumper Dumper; + ClassDefinitionDumper Dumper(Printer); Dumper.start(Symbol, OS, Indent); } else { - OS << "class " << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "class "; + WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName(); } } diff --git a/llvm/tools/llvm-pdbdump/TypeDumper.h b/llvm/tools/llvm-pdbdump/TypeDumper.h index 93e492429ffc..b0bfe570e91f 100644 --- a/llvm/tools/llvm-pdbdump/TypeDumper.h +++ b/llvm/tools/llvm-pdbdump/TypeDumper.h @@ -14,9 +14,11 @@ namespace llvm { +class LinePrinter; + class TypeDumper : public PDBSymDumper { public: - TypeDumper(bool Inline, bool ClassDefs); + TypeDumper(LinePrinter &P, bool Inline, bool ClassDefs); void start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent); @@ -28,6 +30,7 @@ public: int Indent) override; private: + LinePrinter &Printer; bool InlineDump; bool FullClassDefs; }; diff --git a/llvm/tools/llvm-pdbdump/TypedefDumper.cpp b/llvm/tools/llvm-pdbdump/TypedefDumper.cpp index 7bb4b9d2d434..615b8d57aa19 100644 --- a/llvm/tools/llvm-pdbdump/TypedefDumper.cpp +++ b/llvm/tools/llvm-pdbdump/TypedefDumper.cpp @@ -11,6 +11,7 @@ #include "BuiltinDumper.h" #include "FunctionDumper.h" +#include "LinePrinter.h" #include "llvm-pdbdump.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" @@ -23,15 +24,15 @@ using namespace llvm; -TypedefDumper::TypedefDumper() : PDBSymDumper(true) {} +TypedefDumper::TypedefDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {} void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, int Indent) { - OS << "typedef "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef "; uint32_t TargetId = Symbol.getTypeId(); if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId)) TypeSymbol->dump(OS, 0, *this); - OS << " " << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName(); } void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, @@ -39,21 +40,22 @@ void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, int Indent) { - BuiltinDumper Dumper; + BuiltinDumper Dumper(Printer); Dumper.start(Symbol, OS); } void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, int Indent) { - OS << "enum " << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum "; + WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName(); } void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, int Indent) { if (Symbol.isConstType()) - OS << "const "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << "const "; if (Symbol.isVolatileType()) - OS << "volatile "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile "; uint32_t PointeeId = Symbol.getTypeId(); auto PointeeType = Symbol.getSession().getSymbolById(PointeeId); if (!PointeeType) @@ -62,7 +64,7 @@ void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer; if (Symbol.isReference()) Pointer = FunctionDumper::PointerType::Reference; - FunctionDumper NestedDumper; + FunctionDumper NestedDumper(Printer); NestedDumper.start(*FuncSig, nullptr, Pointer, OS); } else { PointeeType->dump(OS, Indent, *this); @@ -72,11 +74,12 @@ void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, int Indent) { - FunctionDumper Dumper; + FunctionDumper Dumper(Printer); Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None, OS); } void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, int Indent) { - OS << "class " << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "class "; + WithColor(Printer, PDB_ColorItem::Type).get() << " " << Symbol.getName(); } diff --git a/llvm/tools/llvm-pdbdump/TypedefDumper.h b/llvm/tools/llvm-pdbdump/TypedefDumper.h index e6211a8eb43a..a5fcf2c4c989 100644 --- a/llvm/tools/llvm-pdbdump/TypedefDumper.h +++ b/llvm/tools/llvm-pdbdump/TypedefDumper.h @@ -14,9 +14,11 @@ namespace llvm { +class LinePrinter; + class TypedefDumper : public PDBSymDumper { public: - TypedefDumper(); + TypedefDumper(LinePrinter &P); void start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, int Indent); @@ -32,6 +34,9 @@ public: int Indent) override; void dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, int Indent) override; + +private: + LinePrinter &Printer; }; } diff --git a/llvm/tools/llvm-pdbdump/VariableDumper.cpp b/llvm/tools/llvm-pdbdump/VariableDumper.cpp index 371c270443af..90c418cf52af 100644 --- a/llvm/tools/llvm-pdbdump/VariableDumper.cpp +++ b/llvm/tools/llvm-pdbdump/VariableDumper.cpp @@ -10,6 +10,7 @@ #include "VariableDumper.h" #include "BuiltinDumper.h" +#include "LinePrinter.h" #include "llvm-pdbdump.h" #include "FunctionDumper.h" @@ -26,45 +27,51 @@ using namespace llvm; -VariableDumper::VariableDumper() : PDBSymDumper(true) {} +VariableDumper::VariableDumper(LinePrinter &P) + : PDBSymDumper(true), Printer(P) {} void VariableDumper::start(const PDBSymbolData &Var, raw_ostream &OS, int Indent) { - OS << newline(Indent); - OS << "data "; + Printer.NewLine(); + Printer << "data "; auto VarType = Var.getType(); switch (auto LocType = Var.getLocationType()) { case PDB_LocType::Static: - OS << "[" << format_hex(Var.getRelativeVirtualAddress(), 10) << "] "; - OS << "static "; + WithColor(Printer, PDB_ColorItem::Address).get() + << "[" << format_hex(Var.getRelativeVirtualAddress(), 10) << "] "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << "static "; dumpSymbolTypeAndName(*VarType, Var.getName(), OS); break; case PDB_LocType::Constant: - OS << "const "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << "const "; dumpSymbolTypeAndName(*VarType, Var.getName(), OS); - OS << "[" << Var.getValue() << "]"; + Printer << "["; + WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getValue(); + Printer << "]"; break; case PDB_LocType::ThisRel: - OS << "+" << format_hex(Var.getOffset(), 4) << " "; + WithColor(Printer, PDB_ColorItem::Offset).get() + << "+" << format_hex(Var.getOffset(), 4) << " "; dumpSymbolTypeAndName(*VarType, Var.getName(), OS); break; default: + OS << "unknown(" << LocType << ") "; + WithColor(Printer, PDB_ColorItem::Identifier).get() << Var.getName(); break; - OS << "unknown(" << LocType << ") " << Var.getName(); } } void VariableDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, int Indent) { - BuiltinDumper Dumper; + BuiltinDumper Dumper(Printer); Dumper.start(Symbol, OS); } void VariableDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, int Indent) { - OS << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); } void VariableDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, @@ -77,29 +84,30 @@ void VariableDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, return; if (auto Func = dyn_cast(PointeeType.get())) { - FunctionDumper NestedDumper; + FunctionDumper NestedDumper(Printer); FunctionDumper::PointerType Pointer = Symbol.isReference() ? FunctionDumper::PointerType::Reference : FunctionDumper::PointerType::Pointer; NestedDumper.start(*Func, Pointer, OS, Indent); } 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() ? "&" : "*"); + Printer << (Symbol.isReference() ? "&" : "*"); } } void VariableDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, int Indent) { - OS << "typedef " << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef "; + WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); } void VariableDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, int Indent) { - OS << Symbol.getName(); + WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName(); } void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type, @@ -109,16 +117,19 @@ void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type, raw_string_ostream IndexStream(IndexSpec); std::unique_ptr ElementType = ArrayType->getElementType(); while (auto NestedArray = dyn_cast(ElementType.get())) { - IndexStream << "[" << NestedArray->getCount() << "]"; + IndexStream << "["; + IndexStream << NestedArray->getCount(); + IndexStream << "]"; ElementType = NestedArray->getElementType(); } IndexStream << "[" << ArrayType->getCount() << "]"; ElementType->dump(OS, 0, *this); - OS << " " << Name << IndexStream.str(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name; + Printer << IndexStream.str(); } else { if (!tryDumpFunctionPointer(Type, Name, OS)) { Type.dump(OS, 0, *this); - OS << " " << Name; + WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name; } } } @@ -131,7 +142,7 @@ bool VariableDumper::tryDumpFunctionPointer(const PDBSymbol &Type, auto PointeeType = PointerType->getPointeeType(); if (auto *FunctionSig = dyn_cast(PointeeType.get())) { - FunctionDumper Dumper; + FunctionDumper Dumper(Printer); FunctionDumper::PointerType PT = FunctionDumper::PointerType::Pointer; if (PointerType->isReference()) PT = FunctionDumper::PointerType::Reference; diff --git a/llvm/tools/llvm-pdbdump/VariableDumper.h b/llvm/tools/llvm-pdbdump/VariableDumper.h index e8832e3d6339..09f1314932ad 100644 --- a/llvm/tools/llvm-pdbdump/VariableDumper.h +++ b/llvm/tools/llvm-pdbdump/VariableDumper.h @@ -15,9 +15,11 @@ namespace llvm { +class LinePrinter; + class VariableDumper : public PDBSymDumper { public: - VariableDumper(); + VariableDumper(LinePrinter &P); void start(const PDBSymbolData &Var, raw_ostream &OS, int Indent); @@ -39,6 +41,8 @@ private: raw_ostream &OS); bool tryDumpFunctionPointer(const PDBSymbol &Type, StringRef Name, raw_ostream &OS); + + LinePrinter &Printer; }; } diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp index e8a105d35d2a..5bc33d06e381 100644 --- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -16,6 +16,7 @@ #include "llvm-pdbdump.h" #include "CompilandDumper.h" #include "FunctionDumper.h" +#include "LinePrinter.h" #include "TypeDumper.h" #include "VariableDumper.h" @@ -73,66 +74,98 @@ static void dumpInput(StringRef Path) { return; } + LinePrinter Printer(2, outs()); + auto GlobalScope(Session->getGlobalScope()); std::string FileName(GlobalScope->getSymbolsFileName()); - outs() << "Summary for " << FileName; + WithColor(Printer, PDB_ColorItem::None).get() << "Summary for "; + WithColor(Printer, PDB_ColorItem::Path).get() << FileName; + Printer.Indent(); uint64_t FileSize = 0; - if (!llvm::sys::fs::file_size(FileName, FileSize)) - outs() << newline(2) << "Size: " << FileSize << " bytes"; - else - outs() << newline(2) << "Size: (Unable to obtain file size)"; - outs() << newline(2) << "Guid: " << GlobalScope->getGuid(); - outs() << newline(2) << "Age: " << GlobalScope->getAge(); - outs() << newline(2) << "Attributes: "; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Size"; + if (!llvm::sys::fs::file_size(FileName, FileSize)) { + Printer << ": " << FileSize << " bytes"; + } else { + Printer << ": (Unable to obtain file size)"; + } + + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Guid"; + Printer << ": " << GlobalScope->getGuid(); + + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Age"; + Printer << ": " << GlobalScope->getAge(); + + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::Identifier).get() << "Attributes"; + Printer << ": "; if (GlobalScope->hasCTypes()) outs() << "HasCTypes "; if (GlobalScope->hasPrivateSymbols()) outs() << "HasPrivateSymbols "; + Printer.Unindent(); if (opts::Compilands) { - outs() << "\n---COMPILANDS---"; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::SectionHeader).get() + << "---COMPILANDS---"; + Printer.Indent(); auto Compilands = GlobalScope->findAllChildren(); - CompilandDumper Dumper; + CompilandDumper Dumper(Printer); while (auto Compiland = Compilands->getNext()) Dumper.start(*Compiland, outs(), 2, false); + Printer.Unindent(); } if (opts::Types) { - outs() << "\n---TYPES---"; - TypeDumper Dumper(false, opts::ClassDefs); + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---TYPES---"; + Printer.Indent(); + TypeDumper Dumper(Printer, false, opts::ClassDefs); Dumper.start(*GlobalScope, outs(), 2); + Printer.Unindent(); } if (opts::Symbols) { - outs() << "\n---SYMBOLS---"; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---SYMBOLS---"; + Printer.Indent(); auto Compilands = GlobalScope->findAllChildren(); - CompilandDumper Dumper; + CompilandDumper Dumper(Printer); while (auto Compiland = Compilands->getNext()) Dumper.start(*Compiland, outs(), 2, true); + Printer.Unindent(); } if (opts::Globals) { - outs() << "\n---GLOBALS---"; + Printer.NewLine(); + WithColor(Printer, PDB_ColorItem::SectionHeader).get() << "---GLOBALS---"; + Printer.Indent(); { - FunctionDumper Dumper; + FunctionDumper Dumper(Printer); auto Functions = GlobalScope->findAllChildren(); - while (auto Function = Functions->getNext()) + while (auto Function = Functions->getNext()) { + Printer.NewLine(); Dumper.start(*Function, FunctionDumper::PointerType::None, outs(), 2); + } } { auto Vars = GlobalScope->findAllChildren(); - VariableDumper Dumper; + VariableDumper Dumper(Printer); while (auto Var = Vars->getNext()) Dumper.start(*Var, outs(), 2); } { auto Thunks = GlobalScope->findAllChildren(); - CompilandDumper Dumper; + CompilandDumper Dumper(Printer); while (auto Thunk = Thunks->getNext()) Dumper.dump(*Thunk, outs(), 2); } + Printer.Unindent(); } outs().flush(); }