From 9a818ad193d19ef2f560e6da4b0fcf6748979fdb Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sun, 22 Feb 2015 22:03:38 +0000 Subject: [PATCH] [llvm-pdbdump] Rewrite dumper using visitor pattern. This increases the flexibility of how to dump different symbol types -- necessary for context-sensitive formatting of symbol types -- and also improves the modularity by allowing the dumping to be implemented in the actual dumper, as opposed to in the PDB library. llvm-svn: 230184 --- llvm/include/llvm/DebugInfo/PDB/PDBExtras.h | 6 - llvm/include/llvm/DebugInfo/PDB/PDBSymDumper.h | 85 ++++++++++ llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h | 5 +- .../llvm/DebugInfo/PDB/PDBSymbolAnnotation.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolBlock.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolCompiland.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolCustom.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolData.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolFunc.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolLabel.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolThunk.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeArray.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h | 2 +- .../include/llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypePointer.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h | 2 +- .../llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h | 2 +- llvm/include/llvm/DebugInfo/PDB/PDBTypes.h | 4 +- llvm/lib/DebugInfo/PDB/CMakeLists.txt | 1 + llvm/lib/DebugInfo/PDB/PDBExtras.cpp | 5 - llvm/lib/DebugInfo/PDB/PDBSymDumper.cpp | 177 +++++++++++++++++++ llvm/lib/DebugInfo/PDB/PDBSymbol.cpp | 7 + llvm/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp | 6 +- llvm/lib/DebugInfo/PDB/PDBSymbolBlock.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp | 53 +----- .../DebugInfo/PDB/PDBSymbolCompilandDetails.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolCustom.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolData.cpp | 72 +------- llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp | 118 +------------ llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp | 64 +------ llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolLabel.cpp | 9 +- llvm/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp | 6 +- llvm/lib/DebugInfo/PDB/PDBSymbolThunk.cpp | 23 +-- llvm/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp | 12 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp | 6 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp | 10 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp | 18 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp | 5 +- .../lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp | 11 +- .../lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp | 36 +--- llvm/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp | 27 +-- llvm/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp | 20 +-- llvm/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp | 23 +-- llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp | 22 +-- .../lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp | 5 +- llvm/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp | 5 +- llvm/test/DebugInfo/PDB/pdbdump-symbol-format.test | 18 +- llvm/tools/llvm-pdbdump/CMakeLists.txt | 4 + llvm/tools/llvm-pdbdump/CompilandDumper.cpp | 132 +++++++++++++++ llvm/tools/llvm-pdbdump/CompilandDumper.h | 39 +++++ llvm/tools/llvm-pdbdump/FunctionDumper.cpp | 187 +++++++++++++++++++++ llvm/tools/llvm-pdbdump/FunctionDumper.h | 44 +++++ llvm/tools/llvm-pdbdump/TypeDumper.cpp | 63 +++++++ llvm/tools/llvm-pdbdump/TypeDumper.h | 32 ++++ llvm/tools/llvm-pdbdump/TypedefDumper.cpp | 84 +++++++++ llvm/tools/llvm-pdbdump/TypedefDumper.h | 38 +++++ llvm/tools/llvm-pdbdump/llvm-pdbdump.cpp | 47 ++++-- llvm/tools/llvm-pdbdump/llvm-pdbdump.h | 28 +++ 82 files changed, 1106 insertions(+), 563 deletions(-) create mode 100644 llvm/include/llvm/DebugInfo/PDB/PDBSymDumper.h create mode 100644 llvm/lib/DebugInfo/PDB/PDBSymDumper.cpp create mode 100644 llvm/tools/llvm-pdbdump/CompilandDumper.cpp create mode 100644 llvm/tools/llvm-pdbdump/CompilandDumper.h create mode 100644 llvm/tools/llvm-pdbdump/FunctionDumper.cpp create mode 100644 llvm/tools/llvm-pdbdump/FunctionDumper.h create mode 100644 llvm/tools/llvm-pdbdump/TypeDumper.cpp create mode 100644 llvm/tools/llvm-pdbdump/TypeDumper.h create mode 100644 llvm/tools/llvm-pdbdump/TypedefDumper.cpp create mode 100644 llvm/tools/llvm-pdbdump/TypedefDumper.h create mode 100644 llvm/tools/llvm-pdbdump/llvm-pdbdump.h diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBExtras.h b/llvm/include/llvm/DebugInfo/PDB/PDBExtras.h index d6e2fa2..cbbe171 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBExtras.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBExtras.h @@ -17,12 +17,6 @@ namespace llvm { typedef std::unordered_map TagStats; -struct stream_indent { - stream_indent(int IndentWidth) : Width(IndentWidth) {} - int Width; -}; -raw_ostream &operator<<(raw_ostream &OS, const stream_indent &Indent); - raw_ostream &operator<<(raw_ostream &OS, const PDB_VariantType &Value); raw_ostream &operator<<(raw_ostream &OS, const PDB_CallingConv &Conv); raw_ostream &operator<<(raw_ostream &OS, const PDB_DataKind &Data); diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymDumper.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymDumper.h new file mode 100644 index 0000000..dee601c --- /dev/null +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymDumper.h @@ -0,0 +1,85 @@ +//===- PDBSymDumper.h - base interface for PDB 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_DEBUGINFO_PDB_PDBSYMDUMPER_H +#define LLVM_DEBUGINFO_PDB_PDBSYMDUMPER_H + +#include "PDBTypes.h" + +namespace llvm { + +class raw_ostream; + +class PDBSymDumper { +public: + PDBSymDumper(bool ShouldRequireImpl); + virtual ~PDBSymDumper(); + + virtual void dump(const PDBSymbolAnnotation &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolBlock &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolCompiland &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolCompilandDetails &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolCustom &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolData &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolExe &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolFuncDebugEnd &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolFuncDebugStart &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolPublicSymbol &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, int Indent); + virtual void dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeBaseClass &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeCustom &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeDimension &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeFriend &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeFunctionArg &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeManaged &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeVTable &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolTypeVTableShape &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, + int Indent); + virtual void dump(const PDBSymbolUsingNamespace &Symbol, raw_ostream &OS, + int Indent); + +private: + bool RequireImpl; +}; +} + +#endif diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h index 4f1ca5f..28bff14 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbol.h @@ -53,7 +53,8 @@ public: /// call dump() on the underlying RawSymbol, which allows us to discover /// unknown properties, but individual implementations of PDBSymbol may /// override the behavior to only dump known fields. - virtual void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const = 0; + virtual void dump(raw_ostream &OS, int Indent, + PDBSymDumper &Dumper) const = 0; void defaultDump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const; PDB_SymType getSymTag() const; @@ -83,6 +84,8 @@ public: const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; } IPDBRawSymbol &getRawSymbol() { return *RawSymbol; } + const IPDBSession &getSession() const { return Session; } + protected: std::unique_ptr getChildStats(TagStats &Stats) const; diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolAnnotation.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolAnnotation.h index b931b07..347e30a 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolAnnotation.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolAnnotation.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Annotation) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressSection) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolBlock.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolBlock.h index 6462159..a0091bea 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolBlock.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolBlock.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Block) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressSection) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h index 0363c86..055e444 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompiland.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Compiland) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(isEditAndContinueEnabled) FORWARD_SYMBOL_METHOD(getLexicalParentId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h index 83ca9b5..8836828 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandDetails) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; void getFrontEndVersion(VersionInfo &Version) const { RawSymbol->getFrontEndVersion(Version); diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h index 5f621b9..c3502a0 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CompilandEnv) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getLexicalParentId) FORWARD_SYMBOL_METHOD(getName) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCustom.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCustom.h index 741d073..b433dde 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCustom.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolCustom.h @@ -28,7 +28,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Custom) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; void getDataBytes(llvm::SmallVector &bytes); FORWARD_SYMBOL_METHOD(getSymIndexId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolData.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolData.h index f6eca3e..87dd6ac 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolData.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolData.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Data) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getAddressOffset) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h index a5327f3..33046f3 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolExe.h @@ -25,7 +25,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Exe) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAge) FORWARD_SYMBOL_METHOD(getGuid) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFunc.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFunc.h index 030e57f..be40af9 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFunc.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFunc.h @@ -22,7 +22,7 @@ public: PDBSymbolFunc(const IPDBSession &PDBSession, std::unique_ptr FuncSymbol); - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; std::unique_ptr getSignature() const; diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h index 9e4697f..bd49314 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugEnd) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressSection) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h index 36bc167..a62eada 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FuncDebugStart) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressSection) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolLabel.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolLabel.h index 21b33b0..d006495 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolLabel.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolLabel.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Label) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressSection) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h index 019c3e9..a8de89d 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PublicSymbol) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAddressOffset) FORWARD_SYMBOL_METHOD(getAddressSection) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolThunk.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolThunk.h index 2ebd29c..88588f1 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolThunk.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolThunk.h @@ -25,7 +25,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Thunk) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getAddressOffset) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeArray.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeArray.h index d9e86fd5..602d9d5 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeArray.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeArray.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ArrayType) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getArrayIndexTypeId) FORWARD_SYMBOL_METHOD(isConstType) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h index c0763a6..a3dcc02 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BaseClass) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getAccess) FORWARD_SYMBOL_METHOD(getClassParentId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h index 3c16f13..1cede08 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::BuiltinType) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getBuiltinType) FORWARD_SYMBOL_METHOD(isConstType) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h index 0e3cff0..90a043f 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::CustomType) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getOemId) FORWARD_SYMBOL_METHOD(getOemSymbolId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h index 78a6ac3..f871681 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Dimension) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getLowerBoundId) FORWARD_SYMBOL_METHOD(getUpperBoundId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h index 3266c82..2cc1bf8 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Enum) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getBuiltinType) FORWARD_SYMBOL_METHOD(getClassParentId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h index e1846de..964246f 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Friend) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getClassParentId) FORWARD_SYMBOL_METHOD(getName) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h index 39504276..22f1455 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::FunctionArg) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getClassParentId) FORWARD_SYMBOL_METHOD(getLexicalParentId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h index 068472c..b544d6b 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h @@ -28,7 +28,7 @@ public: std::unique_ptr getArguments() const; std::unique_ptr getClassParent() const; - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; void dumpArgList(raw_ostream &OS) const; FORWARD_SYMBOL_METHOD(getCallingConvention) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h index 4b6fad6..42f5867 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::ManagedType) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getName) FORWARD_SYMBOL_METHOD(getSymIndexId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypePointer.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypePointer.h index f52c474..702ea6d 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypePointer.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypePointer.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::PointerType) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(isConstType) FORWARD_SYMBOL_METHOD(getLength) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h index ddf4f46..d3a9ca2 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::Typedef) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getBuiltinType) FORWARD_SYMBOL_METHOD(getClassParentId) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h index aea5d92..8c82633 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UDT) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getClassParentId) FORWARD_SYMBOL_METHOD(hasConstructor) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h index 5a2a7c3..6b6d99b 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTable) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getClassParentId) FORWARD_SYMBOL_METHOD(isConstType) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h index 4676a35..e866106 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::VTableShape) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(isConstType) FORWARD_SYMBOL_METHOD(getCount) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h index dbcbf07..7f8c6f9 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUnknown.h @@ -21,7 +21,7 @@ public: PDBSymbolUnknown(const IPDBSession &PDBSession, std::unique_ptr UnknownSymbol); - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; static bool classof(const PDBSymbol *S) { return (S->getSymTag() == PDB_SymType::None || diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h index d0d624d1..59ec16b 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h @@ -24,7 +24,7 @@ public: DECLARE_PDB_SYMBOL_CONCRETE_TYPE(PDB_SymType::UsingNamespace) - void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level, PDB_DumpFlags Flags) const override; + void dump(raw_ostream &OS, int Indent, PDBSymDumper &Dumper) const override; FORWARD_SYMBOL_METHOD(getLexicalParentId) FORWARD_SYMBOL_METHOD(getName) diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h b/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h index 1b44a5f..c797cca 100644 --- a/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBTypes.h @@ -16,10 +16,8 @@ namespace llvm { +class PDBSymDumper; class PDBSymbol; -class PDBSymbolCompiland; -class PDBSymbolFunc; -class PDBSymbolExe; class IPDBDataStream; template class IPDBEnumChildren; diff --git a/llvm/lib/DebugInfo/PDB/CMakeLists.txt b/llvm/lib/DebugInfo/PDB/CMakeLists.txt index d86c8bd..ed8c674 100644 --- a/llvm/lib/DebugInfo/PDB/CMakeLists.txt +++ b/llvm/lib/DebugInfo/PDB/CMakeLists.txt @@ -66,6 +66,7 @@ add_llvm_library(LLVMDebugInfoPDB PDBSymbolTypeVTableShape.cpp PDBSymbolUnknown.cpp PDBSymbolUsingNamespace.cpp + PDBSymDumper.cpp ${PDB_IMPL_SOURCES} ADDITIONAL_HEADER_DIRS diff --git a/llvm/lib/DebugInfo/PDB/PDBExtras.cpp b/llvm/lib/DebugInfo/PDB/PDBExtras.cpp index c9cc9c3..1002b2e 100644 --- a/llvm/lib/DebugInfo/PDB/PDBExtras.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBExtras.cpp @@ -21,11 +21,6 @@ using namespace llvm; #define CASE_OUTPUT_ENUM_CLASS_NAME(Class, Value, Stream) \ CASE_OUTPUT_ENUM_CLASS_STR(Class, Value, #Value, Stream) -raw_ostream &llvm::operator<<(raw_ostream &OS, const stream_indent &Indent) { - OS.indent(Indent.Width); - return OS; -} - raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_VariantType &Type) { switch (Type) { CASE_OUTPUT_ENUM_CLASS_NAME(PDB_VariantType, Bool, OS) diff --git a/llvm/lib/DebugInfo/PDB/PDBSymDumper.cpp b/llvm/lib/DebugInfo/PDB/PDBSymDumper.cpp new file mode 100644 index 0000000..0f29c74 --- /dev/null +++ b/llvm/lib/DebugInfo/PDB/PDBSymDumper.cpp @@ -0,0 +1,177 @@ +//===- PDBSymDumper.cpp - ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" +#include "llvm/Support/ErrorHandling.h" + +using namespace llvm; + +#define PDB_SYMDUMP_UNREACHABLE(Type) \ + if (RequireImpl) \ + llvm_unreachable("Attempt to dump " #Type " with no dump implementation"); + +PDBSymDumper::PDBSymDumper(bool ShouldRequireImpl) + : RequireImpl(ShouldRequireImpl) {} + +PDBSymDumper::~PDBSymDumper() {} + +void PDBSymDumper::dump(const PDBSymbolAnnotation &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolAnnotation) +} + +void PDBSymDumper::dump(const PDBSymbolBlock &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolBlock) +} + +void PDBSymDumper::dump(const PDBSymbolCompiland &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCompiland) +} + +void PDBSymDumper::dump(const PDBSymbolCompilandDetails &Symbol, + raw_ostream &OS, int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCompilandDetails) +} + +void PDBSymDumper::dump(const PDBSymbolCompilandEnv &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCompilandEnv) +} + +void PDBSymDumper::dump(const PDBSymbolCustom &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolCustom) +} + +void PDBSymDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolData) +} + +void PDBSymDumper::dump(const PDBSymbolExe &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolExe) +} + +void PDBSymDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolFunc) +} + +void PDBSymDumper::dump(const PDBSymbolFuncDebugEnd &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolFuncDebugEnd) +} + +void PDBSymDumper::dump(const PDBSymbolFuncDebugStart &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolFuncDebugStart) +} + +void PDBSymDumper::dump(const PDBSymbolLabel &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolLabel) +} + +void PDBSymDumper::dump(const PDBSymbolPublicSymbol &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolPublicSymbol) +} + +void PDBSymDumper::dump(const PDBSymbolThunk &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolThunk) +} + +void PDBSymDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeArray) +} + +void PDBSymDumper::dump(const PDBSymbolTypeBaseClass &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeBaseClass) +} + +void PDBSymDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeBuiltin) +} + +void PDBSymDumper::dump(const PDBSymbolTypeCustom &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeCustom) +} + +void PDBSymDumper::dump(const PDBSymbolTypeDimension &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeDimension) +} + +void PDBSymDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeEnum) +} + +void PDBSymDumper::dump(const PDBSymbolTypeFriend &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeFriend) +} + +void PDBSymDumper::dump(const PDBSymbolTypeFunctionArg &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeFunctionArg) +} + +void PDBSymDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeFunctionSig) +} + +void PDBSymDumper::dump(const PDBSymbolTypeManaged &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeManaged) +} + +void PDBSymDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypePointer) +} + +void PDBSymDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeTypedef) +} + +void PDBSymDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeUDT) +} + +void PDBSymDumper::dump(const PDBSymbolTypeVTable &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeVTable) +} + +void PDBSymDumper::dump(const PDBSymbolTypeVTableShape &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolTypeVTableShape) +} + +void PDBSymDumper::dump(const PDBSymbolUnknown &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolUnknown) +} + +void PDBSymDumper::dump(const PDBSymbolUsingNamespace &Symbol, raw_ostream &OS, + int Indent) { + PDB_SYMDUMP_UNREACHABLE(PDBSymbolUsingNamespace) +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp index 9ab8b93..f24e318 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbol.cpp @@ -42,6 +42,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include #include @@ -100,6 +101,12 @@ PDBSymbol::create(const IPDBSession &PDBSession, } } +#define TRY_DUMP_TYPE(Type) \ + if (const Type *DerivedThis = dyn_cast(this)) \ + Dumper.dump(OS, Indent, *DerivedThis); + +#define ELSE_TRY_DUMP_TYPE(Type, Dumper) else TRY_DUMP_TYPE(Type, Dumper) + void PDBSymbol::defaultDump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const { RawSymbol->dump(OS, Indent, Level); diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp index c965d1d9..4c76e3b 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolAnnotation.cpp @@ -9,7 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +20,6 @@ PDBSymbolAnnotation::PDBSymbolAnnotation(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolAnnotation::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolBlock.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolBlock.cpp index 2e350ad..bb159d5 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolBlock.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolBlock.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolBlock::PDBSymbolBlock(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolBlock::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp index f014b39..0c9b190 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolCompiland.cpp @@ -9,18 +9,9 @@ #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" -#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/IPDBSourceFile.h" -#include "llvm/DebugInfo/PDB/PDBExtras.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" -#include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h" -#include "llvm/Support/Path.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include -#include using namespace llvm; @@ -28,45 +19,7 @@ PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession, std::unique_ptr Symbol) : PDBSymbol(PDBSession, std::move(Symbol)) {} -#define SKIP_SYMBOL_IF_FLAG_UNSET(Tag, Flag) \ - case PDB_SymType::Tag: \ - if ((Flags & Flag) == 0) \ - continue; \ - break; - void PDBSymbolCompiland::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - if (Level == PDB_DumpLevel::Detailed) { - std::string FullName = getName(); - OS << stream_indent(Indent) << FullName; - if (Flags & PDB_DF_Children) { - if (Level >= PDB_DumpLevel::Detailed) { - auto ChildrenEnum = findAllChildren(); - while (auto Child = ChildrenEnum->getNext()) { - switch (Child->getSymTag()) { - SKIP_SYMBOL_IF_FLAG_UNSET(Function, PDB_DF_Functions) - SKIP_SYMBOL_IF_FLAG_UNSET(Data, PDB_DF_Data) - SKIP_SYMBOL_IF_FLAG_UNSET(Label, PDB_DF_Labels) - SKIP_SYMBOL_IF_FLAG_UNSET(PublicSymbol, PDB_DF_PublicSyms) - SKIP_SYMBOL_IF_FLAG_UNSET(UDT, PDB_DF_Classes) - SKIP_SYMBOL_IF_FLAG_UNSET(Enum, PDB_DF_Enums) - SKIP_SYMBOL_IF_FLAG_UNSET(FunctionSig, PDB_DF_Funcsigs) - SKIP_SYMBOL_IF_FLAG_UNSET(VTable, PDB_DF_VTables) - SKIP_SYMBOL_IF_FLAG_UNSET(Thunk, PDB_DF_Thunks) - SKIP_SYMBOL_IF_FLAG_UNSET(Compiland, PDB_DF_ObjFiles) - default: - continue; - } - PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed) - ? PDB_DumpLevel::Normal - : PDB_DumpLevel::Compact; - OS << "\n"; - Child->dump(OS, Indent + 2, ChildLevel, PDB_DF_Children); - } - } - } - } else { - std::string FullName = getName(); - OS << stream_indent(Indent) << "Compiland: " << FullName; - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp index 9194376..208d68f 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandDetails.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolCompilandDetails::PDBSymbolCompilandDetails( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolCompilandDetails::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp index b44dc57..c54b8fb 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolCompilandEnv.cpp @@ -11,6 +11,7 @@ #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -26,4 +27,6 @@ std::string PDBSymbolCompilandEnv::getValue() const { } void PDBSymbolCompilandEnv::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolCustom.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolCustom.cpp index 68f2b45..1b6b50b 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolCustom.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolCustom.cpp @@ -11,6 +11,7 @@ #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -25,4 +26,6 @@ void PDBSymbolCustom::getDataBytes(llvm::SmallVector &bytes) { } void PDBSymbolCustom::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} \ No newline at end of file + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} \ No newline at end of file diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolData.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolData.cpp index 9a04ecd..09b96bc 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolData.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolData.cpp @@ -9,11 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolData.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBExtras.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" -#include "llvm/Support/Format.h" -#include +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -24,68 +20,6 @@ PDBSymbolData::PDBSymbolData(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(DataSymbol)) {} void PDBSymbolData::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - PDB_LocType Loc = getLocationType(); - PDB_DataKind Kind = getDataKind(); - switch (Loc) { - case PDB_LocType::Static: { - uint32_t RVA = getRelativeVirtualAddress(); - OS << Kind << " data["; - if (RVA != 0) - OS << format_hex(RVA, 10); - else - OS << "???"; - break; - } - case PDB_LocType::TLS: - OS << "threadlocal " << Kind << " data["; - OS << getAddressSection() << ":" << format_hex(getAddressOffset(), 10); - break; - case PDB_LocType::RegRel: - OS << "regrel " << Kind << " data["; - OS << getRegisterId() << " + " << getOffset(); - break; - case PDB_LocType::ThisRel: { - uint32_t Offset = getOffset(); - OS << Kind << " data[this + " << format_hex(Offset, 4); - break; - } - case PDB_LocType::Enregistered: - OS << "register " << Kind << " data[" << getRegisterId(); - break; - case PDB_LocType::BitField: { - OS << "bitfield data[this + "; - uint32_t Offset = getOffset(); - uint32_t BitPos = getBitPosition(); - uint32_t Length = getLength(); - OS << format_hex(Offset, 4) << ":" << BitPos << "," << Length; - break; - } - case PDB_LocType::Slot: - OS << getSlot(); - break; - case PDB_LocType::Constant: { - OS << "constant data["; - OS << getValue(); - break; - } - case PDB_LocType::IlRel: - case PDB_LocType::MetaData: - default: - OS << "???"; - } - - OS << "] "; - if (Kind == PDB_DataKind::Member || Kind == PDB_DataKind::StaticMember) { - uint32_t ClassId = getClassParentId(); - if (auto Class = Session.getSymbolById(ClassId)) { - if (auto UDT = dyn_cast(Class.get())) - OS << UDT->getName(); - else - OS << "{class " << Class->getSymTag() << "}"; - OS << "::"; - } - } - OS << getName(); + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } \ No newline at end of file diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp index efd28bc..ef09193 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolExe.cpp @@ -9,129 +9,17 @@ #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" -#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" -#include "llvm/DebugInfo/PDB/PDBExtras.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/Support/ConvertUTF.h" -#include "llvm/Support/FileSystem.h" -#include "llvm/Support/raw_ostream.h" -#include +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include using namespace llvm; -#define SKIP_SYMBOL_IF_FLAG_UNSET(Tag, Flag) \ - case PDB_SymType::Tag: \ - if ((Flags & Flag) == 0) \ - continue; \ - break; - PDBSymbolExe::PDBSymbolExe(const IPDBSession &PDBSession, std::unique_ptr Symbol) : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolExe::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - std::string FileName(getSymbolsFileName()); - - OS << stream_indent(Indent) << "Summary for " << FileName << "\n"; - - uint64_t FileSize = 0; - if (!llvm::sys::fs::file_size(FileName, FileSize)) - OS << stream_indent(Indent + 2) << "Size: " << FileSize << " bytes\n"; - else - OS << stream_indent(Indent + 2) << "Size: (Unable to obtain file size)\n"; - PDB_UniqueId Guid = getGuid(); - OS << stream_indent(Indent + 2) << "Guid: " << Guid << "\n"; - OS << stream_indent(Indent + 2) << "Age: " << getAge() << "\n"; - OS << stream_indent(Indent + 2) << "Attributes: "; - if (hasCTypes()) - OS << "HasCTypes "; - if (hasPrivateSymbols()) - OS << "HasPrivateSymbols "; - OS << "\n"; - - if (Flags & PDB_DF_Children) { - OS << stream_indent(Indent + 2) << "Dumping types\n"; - if (Flags & PDB_DF_Hidden) { - // For some reason, for each SymTag T, this dumps more items of type T - // than are dumped by calling dumpChildren(T). In other words, there are - // "hidden" symbols. For example, it causes functions to be dumped which - // have no address information, whereas specifically dumping only - // functions will not find those symbols. - // - // My suspicion is that in the underlying DIA call, when you call - // findChildren, passing a value of SymTagNone means all children - // recursively, whereas passing a concrete tag value means only immediate - // children of the global scope. So perhaps we need to find these - // mysterious missing values by recursing through the hierarchy. - // - // On the other hand, there may just be some symbols that DIA tries to - // hide from you because it thinks you don't care about them. However - // experimentation shows that even vtables, for example, can't be found - // without an exhaustive search. - auto ChildrenEnum = findAllChildren(); - OS << stream_indent(Indent + 2) << ChildrenEnum->getChildCount() - << " symbols"; - - while (auto Child = ChildrenEnum->getNext()) { - switch (Child->getSymTag()) { - SKIP_SYMBOL_IF_FLAG_UNSET(Function, PDB_DF_Functions) - SKIP_SYMBOL_IF_FLAG_UNSET(Data, PDB_DF_Data) - SKIP_SYMBOL_IF_FLAG_UNSET(Label, PDB_DF_Labels) - SKIP_SYMBOL_IF_FLAG_UNSET(PublicSymbol, PDB_DF_PublicSyms) - SKIP_SYMBOL_IF_FLAG_UNSET(UDT, PDB_DF_Classes) - SKIP_SYMBOL_IF_FLAG_UNSET(Enum, PDB_DF_Enums) - SKIP_SYMBOL_IF_FLAG_UNSET(FunctionSig, PDB_DF_Funcsigs) - SKIP_SYMBOL_IF_FLAG_UNSET(VTable, PDB_DF_VTables) - SKIP_SYMBOL_IF_FLAG_UNSET(Thunk, PDB_DF_Thunks) - SKIP_SYMBOL_IF_FLAG_UNSET(Compiland, PDB_DF_ObjFiles) - default: - continue; - } - PDB_DumpLevel ChildLevel = (Level == PDB_DumpLevel::Detailed) - ? PDB_DumpLevel::Normal - : PDB_DumpLevel::Compact; - OS << "\n"; - Child->dump(OS, Indent + 4, ChildLevel, PDB_DF_Children); - } - } else { - if (Flags & PDB_DF_ObjFiles) - dumpChildren(OS, "Compilands", PDB_SymType::Compiland, Indent + 4); - if (Flags & PDB_DF_Functions) - dumpChildren(OS, "Functions", PDB_SymType::Function, Indent + 4); - if (Flags & PDB_DF_Data) - dumpChildren(OS, "Data", PDB_SymType::Data, Indent + 4); - if (Flags & PDB_DF_Labels) - dumpChildren(OS, "Labels", PDB_SymType::Label, Indent + 4); - if (Flags & PDB_DF_PublicSyms) - dumpChildren(OS, "Public Symbols", PDB_SymType::PublicSymbol, - Indent + 4); - if (Flags & PDB_DF_Classes) - dumpChildren(OS, "UDTs", PDB_SymType::UDT, Indent + 4); - if (Flags & PDB_DF_Enums) - dumpChildren(OS, "Enums", PDB_SymType::Enum, Indent + 4); - if (Flags & PDB_DF_Funcsigs) - dumpChildren(OS, "Function Signatures", PDB_SymType::FunctionSig, - Indent + 4); - if (Flags & PDB_DF_Typedefs) - dumpChildren(OS, "Typedefs", PDB_SymType::Typedef, Indent + 4); - if (Flags & PDB_DF_VTables) - dumpChildren(OS, "VTables", PDB_SymType::VTable, Indent + 4); - if (Flags & PDB_DF_Thunks) - dumpChildren(OS, "Thunks", PDB_SymType::Thunk, Indent + 4); - } - } -} - -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()) { - Child->dump(OS, Indent + 2, PDB_DumpLevel::Normal, PDB_DF_None); - OS << "\n"; - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp index cd01423..4702d6d 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolFunc.cpp @@ -9,14 +9,10 @@ #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" -#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" -#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" -#include "llvm/Support/Format.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" + #include using namespace llvm; @@ -29,58 +25,6 @@ std::unique_ptr PDBSymbolFunc::getSignature() const { } void PDBSymbolFunc::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - uint32_t FuncStart = getRelativeVirtualAddress(); - uint32_t FuncEnd = FuncStart + getLength(); - OS << stream_indent(Indent); - if (FuncStart == 0 && FuncEnd == 0) { - OS << "func [???] "; - } else { - OS << "func "; - OS << "[" << format_hex(FuncStart, 8); - if (auto DebugStart = findOneChild()) - OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart; - OS << " - " << format_hex(FuncEnd, 8); - if (auto DebugEnd = findOneChild()) - OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress(); - OS << "] "; - } - - PDB_RegisterId Reg = getLocalBasePointerRegisterId(); - if (Reg == PDB_RegisterId::VFrame) - OS << "(VFrame)"; - else if (hasFramePointer()) - OS << "(" << Reg << ")"; - else - OS << "(FPO)"; - - OS << " "; - if (isVirtual() || isPureVirtual()) - OS << "virtual "; - - if (auto FuncSig = getSignature()) { - // If we have a signature, dump the name with the signature. - if (auto ReturnType = FuncSig->getReturnType()) { - ReturnType->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - OS << " "; - } - - OS << FuncSig->getCallingConvention() << " "; - - OS << getName(); - FuncSig->dumpArgList(OS); - if (isPureVirtual()) - OS << " = 0"; - } else { - uint32_t ClassId = getClassParentId(); - if (ClassId != 0) { - if (auto Class = Session.getSymbolById(ClassId)) { - if (auto UDT = dyn_cast(Class.get())) - OS << UDT->getName() << "::"; - else - OS << "{class " << Class->getSymTag() << "}::"; - } - } - OS << getName(); - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp index 8658be9..c207488 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugEnd.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolFuncDebugEnd::PDBSymbolFuncDebugEnd( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolFuncDebugEnd::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp index 64cd3e3..83df22e 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolFuncDebugStart.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolFuncDebugStart::PDBSymbolFuncDebugStart( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolFuncDebugStart::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolLabel.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolLabel.cpp index abb5163..ce569e2 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolLabel.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolLabel.cpp @@ -9,8 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/Support/Format.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,8 +20,6 @@ PDBSymbolLabel::PDBSymbolLabel(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolLabel::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - OS << "label [" << format_hex(getRelativeVirtualAddress(), 10) << "] " - << getName(); + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp index a2cea8b..a7f156c 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolPublicSymbol.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,7 +21,6 @@ PDBSymbolPublicSymbol::PDBSymbolPublicSymbol( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolPublicSymbol::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - OS << "public symbol: " << getName(); + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolThunk.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolThunk.cpp index c62c96b..edade83 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolThunk.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolThunk.cpp @@ -9,8 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/Support/Format.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,22 +20,6 @@ PDBSymbolThunk::PDBSymbolThunk(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolThunk::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS.indent(Indent); - OS << "thunk "; - PDB_ThunkOrdinal Ordinal = getThunkOrdinal(); - uint32_t RVA = getRelativeVirtualAddress(); - if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) { - OS << format_hex(RVA, 10); - } else { - OS << "[" << format_hex(RVA, 10); - OS << " - " << format_hex(RVA + getLength(), 10) << "]"; - } - OS << " (" << Ordinal << ")"; - if (Ordinal == PDB_ThunkOrdinal::TrampIncremental) - OS << " -> " << format_hex(getTargetRelativeVirtualAddress(), 10); - OS << " "; - std::string Name = getName(); - if (!Name.empty()) - OS << Name; + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp index b418e33..1759bd8 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeArray.cpp @@ -9,8 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,11 +20,6 @@ PDBSymbolTypeArray::PDBSymbolTypeArray(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeArray::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - if (auto ElementType = Session.getSymbolById(getTypeId())) - ElementType->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - else - OS << ""; - OS << "[" << getLength() << "]"; + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp index 532e8b8..c44cc52 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBaseClass.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,7 +21,6 @@ PDBSymbolTypeBaseClass::PDBSymbolTypeBaseClass( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeBaseClass::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - OS << " " << getName(); + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp index b7afdcd..f0c94c7 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeBuiltin.cpp @@ -9,7 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,10 +20,6 @@ PDBSymbolTypeBuiltin::PDBSymbolTypeBuiltin( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeBuiltin::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - PDB_BuiltinType Type = getBuiltinType(); - OS << Type; - if (Type == PDB_BuiltinType::UInt || Type == PDB_BuiltinType::Int) - OS << (8 * getLength()) << "_t"; + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp index 0bfa8eb..0fa8f45 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeCustom.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolTypeCustom::PDBSymbolTypeCustom(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeCustom::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp index 84f48ea..47fb08d 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeDimension.cpp @@ -11,6 +11,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,4 +22,6 @@ PDBSymbolTypeDimension::PDBSymbolTypeDimension( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeDimension::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp index 512b602..121d41e 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeEnum.cpp @@ -9,8 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,17 +20,6 @@ PDBSymbolTypeEnum::PDBSymbolTypeEnum(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeEnum::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - if (Level >= PDB_DumpLevel::Normal) - OS << "enum "; - - uint32_t ClassId = getClassParentId(); - if (ClassId != 0) { - if (auto ClassParent = Session.getSymbolById(ClassId)) { - ClassParent->dump(OS, 0, Level, PDB_DF_Children); - OS << "::"; - } - } - OS << getName(); + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp index 236304e..b2bf72e 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFriend.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolTypeFriend::PDBSymbolTypeFriend(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeFriend::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp index 4b8cc26..f394c04 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionArg.cpp @@ -9,8 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,10 +20,6 @@ PDBSymbolTypeFunctionArg::PDBSymbolTypeFunctionArg( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeFunctionArg::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - uint32_t TypeId = getTypeId(); - if (auto Type = Session.getSymbolById(TypeId)) { - Type->dump(OS, 0, Level, PDB_DF_Children); - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp index 13b89b2..1ba397b 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp @@ -14,6 +14,7 @@ #include "llvm/DebugInfo/PDB/IPDBSession.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -82,38 +83,7 @@ std::unique_ptr PDBSymbolTypeFunctionSig::getClassParent() const { return Session.getSymbolById(ClassId); } -void PDBSymbolTypeFunctionSig::dumpArgList(raw_ostream &OS) const { - OS << "("; - if (auto ChildEnum = getArguments()) { - uint32_t Index = 0; - while (auto Arg = ChildEnum->getNext()) { - Arg->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - if (++Index < ChildEnum->getChildCount()) - OS << ", "; - } - } - OS << ")"; - if (isConstType()) - OS << " const"; - if (isVolatileType()) - OS << " volatile"; -} - void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - - if (auto ReturnType = getReturnType()) { - ReturnType->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - OS << " "; - } - - OS << getCallingConvention() << " "; - if (auto ClassParent = getClassParent()) { - OS << "("; - ClassParent->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - OS << "::*)"; - } - - dumpArgList(OS); + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp index 32602dc..e04fb66 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeManaged.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolTypeManaged::PDBSymbolTypeManaged( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeManaged::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp index 3461928..cac23f7 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypePointer.cpp @@ -9,9 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -22,25 +20,6 @@ PDBSymbolTypePointer::PDBSymbolTypePointer( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypePointer::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - if (isConstType()) - OS << "const "; - if (isVolatileType()) - OS << "volatile "; - uint32_t PointeeId = getTypeId(); - if (auto PointeeType = Session.getSymbolById(PointeeId)) { - // Function pointers get special treatment, since we need to print the * in - // the middle of the signature. - if (auto FuncSig = dyn_cast(PointeeType.get())) { - if (auto ReturnType = FuncSig->getReturnType()) - ReturnType->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - OS << " (" << FuncSig->getCallingConvention() << " "; - OS << ((isReference()) ? "&" : "*") << ")"; - FuncSig->dumpArgList(OS); - } else { - PointeeType->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - OS << ((isReference()) ? "&" : "*"); - } - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp index 9554d70..12e3ead 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeTypedef.cpp @@ -9,9 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -22,18 +20,6 @@ PDBSymbolTypeTypedef::PDBSymbolTypeTypedef( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeTypedef::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS.indent(Indent); - if (Level >= PDB_DumpLevel::Normal) { - std::string Name = getName(); - OS << "typedef:" << Name << " -> "; - std::string TargetTypeName; - uint32_t TargetId = getTypeId(); - if (auto TypeSymbol = Session.getSymbolById(TargetId)) { - TypeSymbol->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - } - OS << TargetTypeName; - } else { - OS << getName(); - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp index ea884bd..8a72368 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeUDT.cpp @@ -9,8 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -21,22 +20,6 @@ PDBSymbolTypeUDT::PDBSymbolTypeUDT(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeUDT::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - if (Level >= PDB_DumpLevel::Normal) - OS << "class "; - - if (isNested()) { - uint32_t ClassId = getClassParentId(); - if (ClassId != 0) { - if (auto ClassParent = Session.getSymbolById(ClassId)) { - ClassParent->dump(OS, 0, Level, PDB_DF_Children); - OS << "::"; - } - } - } - OS << getName(); - - if (Level >= PDB_DumpLevel::Normal) - OS << " (" << getLength() << " bytes)"; + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp index 4c1f05e..a100526 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTable.cpp @@ -9,10 +9,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBSymbol.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -23,19 +20,6 @@ PDBSymbolTypeVTable::PDBSymbolTypeVTable(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeVTable::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const { - OS << stream_indent(Indent); - uint32_t ClassId = getClassParentId(); - if (auto ClassParent = Session.getSymbolById(ClassId)) { - ClassParent->dump(OS, 0, PDB_DumpLevel::Compact, PDB_DF_Children); - OS << "::"; - } - OS << " "; - if (auto VtblPointer = - Session.getConcreteSymbolById(getTypeId())) { - if (auto VtblShape = - Session.getConcreteSymbolById( - VtblPointer->getTypeId())) - OS << "(" << VtblShape->getCount() << " entries)"; - } + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); } diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp index cff0d03..6aaa668e 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeVTableShape.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolTypeVTableShape::PDBSymbolTypeVTableShape( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolTypeVTableShape::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp index b7b4c38..9cfb88a 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolUnknown.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolUnknown::PDBSymbolUnknown(const IPDBSession &PDBSession, : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolUnknown::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp index 077d2b3..9176dfb 100644 --- a/llvm/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolUsingNamespace.cpp @@ -10,6 +10,7 @@ #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h" #include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymDumper.h" #include @@ -20,4 +21,6 @@ PDBSymbolUsingNamespace::PDBSymbolUsingNamespace( : PDBSymbol(PDBSession, std::move(Symbol)) {} void PDBSymbolUsingNamespace::dump(raw_ostream &OS, int Indent, - PDB_DumpLevel Level, PDB_DumpFlags Flags) const {} + PDBSymDumper &Dumper) const { + Dumper.dump(*this, OS, Indent); +} diff --git a/llvm/test/DebugInfo/PDB/pdbdump-symbol-format.test b/llvm/test/DebugInfo/PDB/pdbdump-symbol-format.test index 243fcc4..9d50ae2 100644 --- a/llvm/test/DebugInfo/PDB/pdbdump-symbol-format.test +++ b/llvm/test/DebugInfo/PDB/pdbdump-symbol-format.test @@ -3,7 +3,7 @@ ; The format is func [0x+ - 0x-] ; SYM_FORMAT: symbolformat-fpo.obj -; SYM_FORMAT-DAG: func [0x001130+0 - 0x001137-1] (VFrame) uint32_t __cdecl fpo_func(uint32_t) +; SYM_FORMAT-DAG: func [0x001130+0 - 0x001137-1] (FPO) uint32_t __cdecl fpo_func(uint32_t) ; SYM_FORMAT: symbolformat.obj ; SYM_FORMAT-DAG: func [0x001060+3 - 0x001067-2] (EBP) int32_t __cdecl _purecall() ; SYM_FORMAT-DAG: func [0x001070+6 - 0x001099-4] (EBP) int32_t __cdecl main(int32_t, char**) @@ -17,11 +17,11 @@ ; TYPES_FORMAT: Function Signatures ; TYPES_FORMAT-DAG: int32_t __cdecl () ; TYPES_FORMAT-DAG: int32_t __cdecl (int32_t, char**) -; TYPES_FORMAT-DAG: void __thiscall (A::*)() -; TYPES_FORMAT-DAG: void __thiscall (B::*)() -; TYPES_FORMAT-DAG: void __thiscall (B::*)(B&) -; TYPES_FORMAT-DAG: void __thiscall (B::*)() -; TYPES_FORMAT-DAG: B& __thiscall (B::*)(B&) -; TYPES_FORMAT-DAG: void __thiscall (A::*)(A&) -; TYPES_FORMAT-DAG: void __thiscall (A::*)() -; TYPES_FORMAT-DAG: A& __thiscall (A::*)(A&) +; TYPES_FORMAT-DAG: void __thiscall (A::)() +; TYPES_FORMAT-DAG: void __thiscall (B::)() +; TYPES_FORMAT-DAG: void __thiscall (B::)(B&) +; TYPES_FORMAT-DAG: void __thiscall (B::)() +; TYPES_FORMAT-DAG: B& __thiscall (B::)(B&) +; TYPES_FORMAT-DAG: void __thiscall (A::)(A&) +; TYPES_FORMAT-DAG: void __thiscall (A::)() +; TYPES_FORMAT-DAG: A& __thiscall (A::)(A&) diff --git a/llvm/tools/llvm-pdbdump/CMakeLists.txt b/llvm/tools/llvm-pdbdump/CMakeLists.txt index a3bb408..64b3d62 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 0000000..ee55228 --- /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 +#include + +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()) + OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart; + OS << " - " << format_hex(FuncEnd, 8); + if (auto DebugEnd = Symbol.findOneChild()) + 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 0000000..abcebc2 --- /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 0000000..851fa1f --- /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 +void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS, + llvm::FunctionDumper &Dumper) { + uint32_t ClassParentId = Symbol.getClassParentId(); + auto ClassParent = + Symbol.getSession().getConcreteSymbolById( + 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( + 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(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 0000000..287a79c --- /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 0000000..72171b0 --- /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(); + OS << newline(Indent) << "Enums: (" << Enums->getChildCount() << " items)"; + while (auto Enum = Enums->getNext()) + Enum->dump(OS, Indent + 2, *this); + + auto FuncSigs = Exe.findAllChildren(); + OS << newline(Indent); + OS << "Function Signatures: (" << FuncSigs->getChildCount() << " items)"; + while (auto Sig = FuncSigs->getNext()) + Sig->dump(OS, Indent + 2, *this); + + auto Typedefs = Exe.findAllChildren(); + 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 0000000..6c51d15 --- /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 0000000..55fcb1a --- /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(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 0000000..e6211a8 --- /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 cc51dc0..5c34db3 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 @@ -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(); - 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 0000000..74a1718 --- /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 -- 2.7.4