From 26ebe3fbcd1518c1acb26efcf2b8e89e3c031bea Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sat, 14 Feb 2015 03:54:28 +0000 Subject: [PATCH] llvm-pdbdump: Only dump whitelisted global symbols. Dumping the global scope contains a lot of very uninteresting things and is generally polluted with a lot of random junk. Furthermore, it dumps values unsorted, making it hard to read. This patch dumps known interesting types only, and as a side effect sorts the list by symbol type. llvm-svn: 229232 --- llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h | 3 +- .../include/llvm/DebugInfo/PDB/PDBSymbolExe.h | 4 ++ llvm/lib/DebugInfo/PDB/PDBSymbol.cpp | 7 ++- llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp | 51 ++++++++++--------- llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp | 4 ++ 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h index 60fd041f2fdc..500fa7a45671 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h @@ -68,8 +68,9 @@ public: auto BaseIter = RawSymbol->findChildren(T::Tag); return llvm::make_unique>(std::move(BaseIter)); } - + std::unique_ptr findAllChildren(PDB_SymType Type) const; std::unique_ptr findAllChildren() const; + std::unique_ptr findChildren(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags) const; diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h index 74f69cc9cfa0..cdb6a326d888 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h @@ -36,6 +36,10 @@ public: FORWARD_SYMBOL_METHOD(getSignature) FORWARD_SYMBOL_METHOD(getSymbolsFileName) FORWARD_SYMBOL_METHOD(getSymIndexId) + +private: + void dumpChildren(raw_ostream &OS, StringRef Label, PDB_SymType ChildType, + int Indent) const; }; } // namespace llvm diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp index 358de7993285..9ab8b936a5dc 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp @@ -108,7 +108,12 @@ void PDBSymbol::defaultDump(raw_ostream &OS, int Indent, PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); } std::unique_ptr PDBSymbol::findAllChildren() const { - return RawSymbol->findChildren(PDB_SymType::None); + return findAllChildren(PDB_SymType::None); +} + +std::unique_ptr +PDBSymbol::findAllChildren(PDB_SymType Type) const { + return RawSymbol->findChildren(Type); } std::unique_ptr diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp index e7871e3bd401..6555b814a682 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp @@ -46,31 +46,34 @@ void PDBSymbolExe::dump(raw_ostream &OS, int Indent, OS << "HasPrivateSymbols "; OS << "\n"; - TagStats Stats; - auto ChildrenEnum = getChildStats(Stats); - OS << stream_indent(Indent + 2) << "Children: " << Stats << "\n"; + auto ChildrenEnum = findAllChildren(); + OS << stream_indent(Indent + 2) << ChildrenEnum->getChildCount() + << " children\n"; +#if 0 + dumpChildren(OS, PDB_SymType::None, Indent+4); +#else + dumpChildren(OS, "Compilands", PDB_SymType::Compiland, Indent + 4); + dumpChildren(OS, "Functions", PDB_SymType::Function, Indent + 4); + dumpChildren(OS, "Blocks", PDB_SymType::Block, Indent + 4); + dumpChildren(OS, "Data", PDB_SymType::Data, Indent + 4); + dumpChildren(OS, "Labels", PDB_SymType::Label, Indent + 4); + dumpChildren(OS, "Public Symbols", PDB_SymType::PublicSymbol, Indent + 4); + dumpChildren(OS, "UDTs", PDB_SymType::UDT, Indent + 4); + dumpChildren(OS, "Enums", PDB_SymType::Enum, Indent + 4); + dumpChildren(OS, "Function Signatures", PDB_SymType::FunctionSig, Indent + 4); + dumpChildren(OS, "Typedefs", PDB_SymType::Typedef, Indent + 4); + dumpChildren(OS, "VTables", PDB_SymType::VTable, Indent + 4); + dumpChildren(OS, "Thunks", PDB_SymType::Thunk, Indent + 4); +#endif +} + +void PDBSymbolExe::dumpChildren(raw_ostream &OS, StringRef Label, + PDB_SymType ChildType, int Indent) const { + auto ChildrenEnum = findAllChildren(ChildType); + OS << stream_indent(Indent) << Label << ": (" << ChildrenEnum->getChildCount() + << " items)\n"; while (auto Child = ChildrenEnum->getNext()) { - // Skip uninteresting types. These are useful to print as part of type - // hierarchies, but as general children of the global scope, they are - // not very interesting. - switch (Child->getSymTag()) { - case PDB_SymType::ArrayType: - case PDB_SymType::BaseClass: - case PDB_SymType::BuiltinType: - case PDB_SymType::CompilandEnv: - case PDB_SymType::CustomType: - case PDB_SymType::Dimension: - case PDB_SymType::Friend: - case PDB_SymType::ManagedType: - case PDB_SymType::VTableShape: - case PDB_SymType::PointerType: - case PDB_SymType::FunctionSig: - case PDB_SymType::FunctionArg: - continue; - default: - break; - } - Child->dump(OS, Indent + 4, PDB_DumpLevel::Normal); + Child->dump(OS, Indent + 2, PDB_DumpLevel::Normal); OS << "\n"; } } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp index 49caedc719a3..817279bc3db8 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp @@ -31,6 +31,10 @@ std::unique_ptr PDBSymbolFunc::getSignature() const { void PDBSymbolFunc::dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { OS << stream_indent(Indent); + // if (getName() == "__crtCreateThreadpoolWait") { + // RawSymbol->dump(OS, Indent+2, Level); + // OS.flush(); + //} if (Level >= PDB_DumpLevel::Normal) { uint32_t FuncStart = getRelativeVirtualAddress(); uint32_t FuncEnd = FuncStart + getLength();