diff options
Diffstat (limited to 'llvm/tools/llvm-pdbdump')
| -rw-r--r-- | llvm/tools/llvm-pdbdump/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/CompilandDumper.cpp | 132 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/CompilandDumper.h | 39 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/FunctionDumper.cpp | 187 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/FunctionDumper.h | 44 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/TypeDumper.cpp | 63 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/TypeDumper.h | 32 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/TypedefDumper.cpp | 84 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/TypedefDumper.h | 38 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp | 47 | ||||
| -rw-r--r-- | llvm/tools/llvm-pdbdump/llvm-pdbdump.h | 28 |
11 files changed, 683 insertions, 15 deletions
diff --git a/llvm/tools/llvm-pdbdump/CMakeLists.txt b/llvm/tools/llvm-pdbdump/CMakeLists.txt index a3bb408097c..64b3d620837 100644 --- a/llvm/tools/llvm-pdbdump/CMakeLists.txt +++ b/llvm/tools/llvm-pdbdump/CMakeLists.txt @@ -5,4 +5,8 @@ set(LLVM_LINK_COMPONENTS add_llvm_tool(llvm-pdbdump llvm-pdbdump.cpp + CompilandDumper.cpp + FunctionDumper.cpp + TypeDumper.cpp + TypedefDumper.cpp ) diff --git a/llvm/tools/llvm-pdbdump/CompilandDumper.cpp b/llvm/tools/llvm-pdbdump/CompilandDumper.cpp new file mode 100644 index 00000000000..ee55228309d --- /dev/null +++ b/llvm/tools/llvm-pdbdump/CompilandDumper.cpp @@ -0,0 +1,132 @@ +//===- CompilandDumper.cpp - llvm-pdbdump compiland symbol dumper *- C++ *-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "CompilandDumper.h" +#include "llvm-pdbdump.h" + +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBExtras.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" +#include "llvm/DebugInfo/PDB/PDBSymbolData.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" +#include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" +#include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" + +#include "FunctionDumper.h" + +#include <utility> +#include <vector> + +using namespace llvm; + +CompilandDumper::CompilandDumper() : PDBSymDumper(true) {} + +void CompilandDumper::dump(const PDBSymbolCompilandDetails &Symbol, + raw_ostream &OS, int Indent) {} + +void CompilandDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, + int Indent) {} + +void CompilandDumper::start(const PDBSymbolCompiland &Symbol, raw_ostream &OS, + int Indent, bool Children) { + std::string FullName = Symbol.getName(); + OS << newline(Indent) << FullName; + if (!Children) + return; + + auto ChildrenEnum = Symbol.findAllChildren(); + while (auto Child = ChildrenEnum->getNext()) + Child->dump(OS, Indent + 2, *this); +} + +void CompilandDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent); + switch (auto LocType = Symbol.getLocationType()) { + case PDB_LocType::Static: + OS << "data: ["; + OS << format_hex(Symbol.getRelativeVirtualAddress(), 10); + OS << "]"; + break; + case PDB_LocType::Constant: + OS << "constant: [" << Symbol.getValue() << "]"; + break; + default: + OS << "data(unexpected type=" << LocType << ")"; + } + + OS << " " << Symbol.getName(); +} + +void CompilandDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, + int Indent) { + uint32_t FuncStart = Symbol.getRelativeVirtualAddress(); + uint32_t FuncEnd = FuncStart + Symbol.getLength(); + OS << newline(Indent) << "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 << "] "; + + if (Symbol.hasFramePointer()) + OS << "(" << Symbol.getLocalBasePointerRegisterId() << ")"; + else + OS << "(FPO)"; + + OS << " "; + + FunctionDumper Dumper; + Dumper.start(Symbol, OS); + OS.flush(); +} + +void CompilandDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent); + OS << "label [" << format_hex(Symbol.getRelativeVirtualAddress(), 10) << "] " + << Symbol.getName(); +} + +void CompilandDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent) << "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); + } else { + OS << "[" << format_hex(RVA, 10); + OS << " - " << format_hex(RVA + Symbol.getLength(), 10) << "]"; + } + OS << " (" << Ordinal << ") "; + std::string Name = Symbol.getName(); + if (!Name.empty()) + OS << Name; +} + +void CompilandDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) {} + +void CompilandDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent); + OS << "unknown (" << Symbol.getSymTag() << ")"; +} diff --git a/llvm/tools/llvm-pdbdump/CompilandDumper.h b/llvm/tools/llvm-pdbdump/CompilandDumper.h new file mode 100644 index 00000000000..abcebc29814 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/CompilandDumper.h @@ -0,0 +1,39 @@ +//===- CompilandDumper.h - llvm-pdbdump compiland symbol dumper *- 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_COMPILANDDUMPER_H +#define LLVM_TOOLS_LLVMPDBDUMP_COMPILANDDUMPER_H + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +namespace llvm { + +class CompilandDumper : public PDBSymDumper { +public: + CompilandDumper(); + + void start(const PDBSymbolCompiland &Symbol, raw_ostream &OS, int Indent, + bool Children); + + void dump(const PDBSymbolCompilandDetails &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolData &Symbol, raw_ostream &OS, int Indent) override; + void dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, int Indent) override; + void dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, int Indent) override; + void dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, int Indent) override; + void dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, + int Indent) override; +}; +} + +#endif diff --git a/llvm/tools/llvm-pdbdump/FunctionDumper.cpp b/llvm/tools/llvm-pdbdump/FunctionDumper.cpp new file mode 100644 index 00000000000..851fa1f773e --- /dev/null +++ b/llvm/tools/llvm-pdbdump/FunctionDumper.cpp @@ -0,0 +1,187 @@ +//===- FunctionDumper.cpp ------------------------------------ *- C++ *-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "FunctionDumper.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" + +namespace { +template <class T> +void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS, + llvm::FunctionDumper &Dumper) { + uint32_t ClassParentId = Symbol.getClassParentId(); + auto ClassParent = + Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>( + ClassParentId); + if (!ClassParent) + return; + + OS << ClassParent->getName() << "::"; +} +} + +using namespace llvm; + +FunctionDumper::FunctionDumper() : PDBSymDumper(true) {} + +void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol, + PointerType Pointer, raw_ostream &OS) { + auto ReturnType = Symbol.getReturnType(); + ReturnType->dump(OS, 0, *this); + OS << " "; + uint32_t ClassParentId = Symbol.getClassParentId(); + auto ClassParent = + Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>( + ClassParentId); + + if (Pointer == PointerType::None) { + OS << Symbol.getCallingConvention() << " "; + if (ClassParent) + OS << "(" << ClassParent->getName() << "::)"; + } else { + OS << "(" << Symbol.getCallingConvention() << " "; + if (ClassParent) + OS << ClassParent->getName() << "::"; + if (Pointer == PointerType::Reference) + OS << "&"; + else + OS << "*"; + OS << ")"; + } + + OS << "("; + if (auto ChildEnum = Symbol.getArguments()) { + uint32_t Index = 0; + while (auto Arg = ChildEnum->getNext()) { + Arg->dump(OS, 0, *this); + if (++Index < ChildEnum->getChildCount()) + OS << ", "; + } + } + OS << ")"; + + if (Symbol.isConstType()) + OS << " const"; + if (Symbol.isVolatileType()) + OS << " volatile"; +} + +void FunctionDumper::start(const PDBSymbolFunc &Symbol, raw_ostream &OS) { + if (Symbol.isVirtual() || Symbol.isPureVirtual()) + OS << "virtual "; + + auto Signature = Symbol.getSignature(); + if (!Signature) { + OS << Symbol.getName(); + return; + } + + auto ReturnType = Signature->getReturnType(); + ReturnType->dump(OS, 0, *this); + + OS << " " << Signature->getCallingConvention() << " "; + OS << Symbol.getName(); + + OS << "("; + if (auto ChildEnum = Signature->getArguments()) { + uint32_t Index = 0; + while (auto Arg = ChildEnum->getNext()) { + Arg->dump(OS, 0, *this); + if (++Index < ChildEnum->getChildCount()) + OS << ", "; + } + } + OS << ")"; + + if (Symbol.isConstType()) + OS << " const"; + if (Symbol.isVolatileType()) + OS << " volatile"; + if (Symbol.isPureVirtual()) + OS << " = 0"; +} + +void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent) { + uint32_t ElementTypeId = Symbol.getTypeId(); + auto ElementType = Symbol.getSession().getSymbolById(ElementTypeId); + if (!ElementType) + return; + + ElementType->dump(OS, 0, *this); + OS << "[" << Symbol.getLength() << "]"; +} + +void FunctionDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent) { + PDB_BuiltinType Type = Symbol.getBuiltinType(); + OS << Type; + if (Type == PDB_BuiltinType::UInt || Type == PDB_BuiltinType::Int) + OS << (8 * Symbol.getLength()) << "_t"; +} + +void FunctionDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) { + dumpClassParentWithScopeOperator(Symbol, OS, *this); + OS << 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. + uint32_t TypeId = Symbol.getTypeId(); + auto Type = Symbol.getSession().getSymbolById(TypeId); + if (!Type) + return; + Type->dump(OS, 0, *this); +} + +void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) { + dumpClassParentWithScopeOperator(Symbol, OS, *this); + OS << Symbol.getName(); +} + +void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent) { + uint32_t PointeeId = Symbol.getTypeId(); + auto PointeeType = Symbol.getSession().getSymbolById(PointeeId); + if (!PointeeType) + return; + + if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) { + FunctionDumper NestedDumper; + PointerType Pointer = + Symbol.isReference() ? PointerType::Reference : PointerType::Pointer; + NestedDumper.start(*FuncSig, Pointer, OS); + } else { + if (Symbol.isConstType()) + OS << "const "; + if (Symbol.isVolatileType()) + OS << "volatile "; + PointeeType->dump(OS, Indent, *this); + OS << (Symbol.isReference() ? "&" : "*"); + } +} + +void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent) { + OS << Symbol.getName(); +} diff --git a/llvm/tools/llvm-pdbdump/FunctionDumper.h b/llvm/tools/llvm-pdbdump/FunctionDumper.h new file mode 100644 index 00000000000..287a79c02c2 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/FunctionDumper.h @@ -0,0 +1,44 @@ +//===- FunctionDumper.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_FUNCTIONDUMPER_H +#define LLVM_TOOLS_LLVMPDBDUMP_FUNCTIONDUMPER_H + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +namespace llvm { + +class FunctionDumper : public PDBSymDumper { +public: + FunctionDumper(); + + enum class PointerType { None, Pointer, Reference }; + + void start(const PDBSymbolTypeFunctionSig &Symbol, PointerType Pointer, + raw_ostream &OS); + void start(const PDBSymbolFunc &Symbol, raw_ostream &OS); + + void dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeFunctionArg &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent) override; +}; +} + +#endif diff --git a/llvm/tools/llvm-pdbdump/TypeDumper.cpp b/llvm/tools/llvm-pdbdump/TypeDumper.cpp new file mode 100644 index 00000000000..72171b0f318 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/TypeDumper.cpp @@ -0,0 +1,63 @@ +//===- TypeDumper.cpp - PDBSymDumper implementation for types *----- C++ *-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "TypeDumper.h" + +#include "FunctionDumper.h" +#include "llvm-pdbdump.h" +#include "TypedefDumper.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" + +using namespace llvm; + +TypeDumper::TypeDumper() : PDBSymDumper(true) {} + +void TypeDumper::start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent) { + auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>(); + OS << newline(Indent) << "Enums: (" << Enums->getChildCount() << " items)"; + while (auto Enum = Enums->getNext()) + Enum->dump(OS, Indent + 2, *this); + + auto FuncSigs = Exe.findAllChildren<PDBSymbolTypeFunctionSig>(); + OS << newline(Indent); + OS << "Function Signatures: (" << FuncSigs->getChildCount() << " items)"; + while (auto Sig = FuncSigs->getNext()) + Sig->dump(OS, Indent + 2, *this); + + auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>(); + OS << newline(Indent) << "Typedefs: (" << Typedefs->getChildCount() + << " items)"; + while (auto Typedef = Typedefs->getNext()) + Typedef->dump(OS, Indent + 2, *this); +} + +void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent) << "enum " << Symbol.getName(); +} + +void TypeDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent); + FunctionDumper Dumper; + Dumper.start(Symbol, FunctionDumper::PointerType::None, OS); +} + +void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) { + OS << newline(Indent); + TypedefDumper Dumper; + Dumper.start(Symbol, OS, Indent); + OS.flush(); +} diff --git a/llvm/tools/llvm-pdbdump/TypeDumper.h b/llvm/tools/llvm-pdbdump/TypeDumper.h new file mode 100644 index 00000000000..6c51d155df8 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/TypeDumper.h @@ -0,0 +1,32 @@ +//===- TypeDumper.h - PDBSymDumper implementation for types *- 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_TYPEDUMPER_H +#define LLVM_TOOLS_LLVMPDBDUMP_TYPEDUMPER_H + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +namespace llvm { + +class TypeDumper : public PDBSymDumper { +public: + TypeDumper(); + + void start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent); + + void dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) override; +}; +} + +#endif diff --git a/llvm/tools/llvm-pdbdump/TypedefDumper.cpp b/llvm/tools/llvm-pdbdump/TypedefDumper.cpp new file mode 100644 index 00000000000..55fcb1a3ade --- /dev/null +++ b/llvm/tools/llvm-pdbdump/TypedefDumper.cpp @@ -0,0 +1,84 @@ +//===- TypedefDumper.cpp - PDBSymDumper impl for typedefs -------- * C++ *-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "TypedefDumper.h" + +#include "FunctionDumper.h" +#include "llvm-pdbdump.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDBExtras.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" + +using namespace llvm; + +TypedefDumper::TypedefDumper() : PDBSymDumper(true) {} + +void TypedefDumper::start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) { + OS << "typedef:" << Symbol.getName() << " -> "; + uint32_t TargetId = Symbol.getTypeId(); + if (auto TypeSymbol = Symbol.getSession().getSymbolById(TargetId)) + TypeSymbol->dump(OS, 0, *this); +} + +void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent) {} + +void TypedefDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent) { + PDB_BuiltinType Type = Symbol.getBuiltinType(); + OS << Type; + if (Type == PDB_BuiltinType::UInt || Type == PDB_BuiltinType::Int) + OS << (8 * Symbol.getLength()) << "_t"; +} + +void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) { + OS << "enum " << Symbol.getName(); +} + +void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent) { + if (Symbol.isConstType()) + OS << "const "; + if (Symbol.isVolatileType()) + OS << "volatile "; + uint32_t PointeeId = Symbol.getTypeId(); + auto PointeeType = Symbol.getSession().getSymbolById(PointeeId); + if (!PointeeType) + return; + if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) { + FunctionDumper::PointerType Pointer = FunctionDumper::PointerType::Pointer; + if (Symbol.isReference()) + Pointer = FunctionDumper::PointerType::Reference; + FunctionDumper NestedDumper; + NestedDumper.start(*FuncSig, Pointer, OS); + OS.flush(); + } else { + PointeeType->dump(OS, Indent, *this); + OS << ((Symbol.isReference()) ? "&" : "*"); + } +} + +void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, + raw_ostream &OS, int Indent) { + FunctionDumper Dumper; + Dumper.start(Symbol, FunctionDumper::PointerType::None, OS); +} + +void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent) { + OS << "class " << Symbol.getName(); +} diff --git a/llvm/tools/llvm-pdbdump/TypedefDumper.h b/llvm/tools/llvm-pdbdump/TypedefDumper.h new file mode 100644 index 00000000000..e6211a8eb43 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/TypedefDumper.h @@ -0,0 +1,38 @@ +//===- TypedefDumper.h - llvm-pdbdump typedef dumper ---------*- 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_TYPEDEFDUMPER_H +#define LLVM_TOOLS_LLVMPDBDUMP_TYPEDEFDUMPER_H + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + +namespace llvm { + +class TypedefDumper : public PDBSymDumper { +public: + TypedefDumper(); + + void start(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, int Indent); + + void dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent) override; + void dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent) override; +}; +} + +#endif diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp index cc51dc0d222..5c34db30f35 100644 --- a/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp @@ -13,6 +13,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm-pdbdump.h" +#include "CompilandDumper.h" +#include "TypeDumper.h" + #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" @@ -24,12 +28,13 @@ #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Process.h" -#include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Signals.h" #if defined(HAVE_DIA_SDK) #include <Windows.h> @@ -61,24 +66,36 @@ static void dumpInput(StringRef Path) { } auto GlobalScope(Session->getGlobalScope()); + std::string FileName(GlobalScope->getSymbolsFileName()); + + outs() << "Summary for " << FileName; + 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: "; + if (GlobalScope->hasCTypes()) + outs() << "HasCTypes "; + if (GlobalScope->hasPrivateSymbols()) + outs() << "HasPrivateSymbols "; + PDB_DumpFlags Flags = PDB_DF_None; - if (opts::DumpTypes) - Flags |= PDB_DF_Children | PDB_DF_Enums | PDB_DF_Funcsigs | - PDB_DF_Typedefs | PDB_DF_VTables; - GlobalScope->dump(outs(), 0, PDB_DumpLevel::Normal, Flags); - outs() << "\n"; + if (opts::DumpTypes) { + outs() << "\nDumping types"; + TypeDumper Dumper; + Dumper.start(*GlobalScope, outs(), 2); + } if (opts::DumpSymbols || opts::DumpCompilands) { - outs() << "Dumping compilands\n"; + outs() << "\nDumping compilands"; auto Compilands = GlobalScope->findAllChildren<PDBSymbolCompiland>(); - Flags = PDB_DF_None; - if (opts::DumpSymbols) - Flags |= PDB_DF_Children | PDB_DF_Data | PDB_DF_Functions | - PDB_DF_Thunks | PDB_DF_Labels; - while (auto Compiland = Compilands->getNext()) { - Compiland->dump(outs(), 2, PDB_DumpLevel::Detailed, Flags); - outs() << "\n"; - } + CompilandDumper Dumper; + while (auto Compiland = Compilands->getNext()) + Dumper.start(*Compiland, outs(), 2, opts::DumpSymbols); } outs().flush(); } diff --git a/llvm/tools/llvm-pdbdump/llvm-pdbdump.h b/llvm/tools/llvm-pdbdump/llvm-pdbdump.h new file mode 100644 index 00000000000..74a171810c7 --- /dev/null +++ b/llvm/tools/llvm-pdbdump/llvm-pdbdump.h @@ -0,0 +1,28 @@ +//===- llvm-pdbdump.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_LLVMPDBDUMP_H +#define LLVM_TOOLS_LLVMPDBDUMP_LLVMPDBDUMP_H + +#include "llvm/Support/raw_ostream.h" + +namespace llvm { +struct newline { + newline(int IndentWidth) : Width(IndentWidth) {} + int Width; +}; + +inline raw_ostream &operator<<(raw_ostream &OS, const newline &Indent) { + OS << "\n"; + OS.indent(Indent.Width); + return OS; +} +} + +#endif
\ No newline at end of file |

