diff --git a/include/llvm/DebugInfo/PDB/PDBExtras.h b/include/llvm/DebugInfo/PDB/PDBExtras.h index cbbe1716ee0..104fb6f0796 100644 --- a/include/llvm/DebugInfo/PDB/PDBExtras.h +++ b/include/llvm/DebugInfo/PDB/PDBExtras.h @@ -26,7 +26,6 @@ raw_ostream &operator<<(raw_ostream &OS, const PDB_ThunkOrdinal &Thunk); raw_ostream &operator<<(raw_ostream &OS, const PDB_Checksum &Checksum); raw_ostream &operator<<(raw_ostream &OS, const PDB_Lang &Lang); raw_ostream &operator<<(raw_ostream &OS, const PDB_SymType &Tag); -raw_ostream &operator<<(raw_ostream &OS, const PDB_BuiltinType &Type); raw_ostream &operator<<(raw_ostream &OS, const PDB_UniqueId &Id); raw_ostream &operator<<(raw_ostream &OS, const Variant &Value); diff --git a/lib/DebugInfo/PDB/PDBExtras.cpp b/lib/DebugInfo/PDB/PDBExtras.cpp index 1002b2e2dad..5a2856ff254 100644 --- a/lib/DebugInfo/PDB/PDBExtras.cpp +++ b/lib/DebugInfo/PDB/PDBExtras.cpp @@ -247,31 +247,6 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_SymType &Tag) { return OS; } -raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_BuiltinType &Type) { - switch (Type) { - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Void, "void", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Char, "char", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, WCharT, "wchar_t", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Int, "int", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, UInt, "uint", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Float, "float", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, BCD, "BCD", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Bool, "bool", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Long, "long", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, ULong, "ulong", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Currency, "CURRENCY", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Date, "DATE", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Variant, "VARIANT", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Complex, "complex", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, Bitfield, "bitfield", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, BSTR, "BSTR", OS) - CASE_OUTPUT_ENUM_CLASS_STR(PDB_BuiltinType, HResult, "HRESULT", OS) - default: - break; - } - return OS; -} - raw_ostream &llvm::operator<<(raw_ostream &OS, const PDB_UniqueId &Id) { static const char *Lookup = "0123456789ABCDEF"; diff --git a/test/DebugInfo/PDB/Inputs/symbolformat.cpp b/test/DebugInfo/PDB/Inputs/symbolformat.cpp index c069a35c7b9..237913e7221 100644 --- a/test/DebugInfo/PDB/Inputs/symbolformat.cpp +++ b/test/DebugInfo/PDB/Inputs/symbolformat.cpp @@ -26,22 +26,39 @@ struct VirtualBase { struct B : public A, protected virtual VirtualBase { void PureFunc() override {} +}; +struct MemberTest { enum NestedEnum { FirstVal, SecondVal }; typedef int NestedTypedef; - NestedEnum EnumVar; - NestedTypedef TypedefVar; + + NestedEnum m_nested_enum; + NestedTypedef m_typedef; + bool m_bool; + char m_char; + wchar_t m_wchar_t; + int m_int; + unsigned m_unsigned; + long m_long; + unsigned long m_unsigned_long; + __int64 m_int64; + unsigned __int64 m_unsigned_int64; + float m_float; + double m_double; + void (*m_pfn_2_args)(int, double); }; typedef int IntType; typedef A ClassAType; int main(int argc, char **argv) { + // Force symbol references so the linker generates debug info B b; + MemberTest members; auto PureAddr = &B::PureFunc; auto VirtualAddr = &A::PureFunc; auto RegularAddr = &A::RegularFunc; diff --git a/test/DebugInfo/PDB/Inputs/symbolformat.pdb b/test/DebugInfo/PDB/Inputs/symbolformat.pdb index 183870aa164..28832d4090f 100644 Binary files a/test/DebugInfo/PDB/Inputs/symbolformat.pdb and b/test/DebugInfo/PDB/Inputs/symbolformat.pdb differ diff --git a/test/DebugInfo/PDB/pdbdump-symbol-format.test b/test/DebugInfo/PDB/pdbdump-symbol-format.test index 1540e167dbe..5ed65642b7f 100644 --- a/test/DebugInfo/PDB/pdbdump-symbol-format.test +++ b/test/DebugInfo/PDB/pdbdump-symbol-format.test @@ -4,23 +4,23 @@ ; The format is func [0x+ - 0x-] ; SYM_FORMAT: symbolformat-fpo.obj -; SYM_FORMAT-DAG: func [0x001130+0 - 0x001137-1] (FPO) uint32_t __cdecl fpo_func(uint32_t n) +; SYM_FORMAT-DAG: func [{{.*}}] (FPO) unsigned __cdecl fpo_func(unsigned n) ; SYM_FORMAT: symbolformat.obj -; SYM_FORMAT-DAG: func [0x001140+3 - 0x001147-2] (EBP) int32_t __cdecl _purecall() -; SYM_FORMAT-DAG: func [0x001150+6 - 0x0011b6-4] (EBP) int32_t __cdecl main(int32_t argc, char** argv) -; SYM_FORMAT-DAG: func [0x0010b0+7 - 0x0010c7-4] (EBP) void A::A() -; SYM_FORMAT-DAG: func [0x0011c0+7 - 0x0011f1-6] (EBP) void B::B() -; SYM_FORMAT-DAG: thunk [0x000010f6 - 0x000010fa] (Pcode) B::`vcall'{0}' -; SYM_FORMAT-DAG: func [0x001100+7 - 0x00110b-4] (EBP) virtual void B::PureFunc() -; SYM_FORMAT-DAG: func [0x001110+7 - 0x00111b-4] (EBP) void A::RegularFunc() -; SYM_FORMAT-DAG: func [0x001120+7 - 0x00112b-4] (EBP) virtual void A::VirtualFunc() +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) int __cdecl _purecall() +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) int __cdecl main(int argc, char** argv) +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) void A::A() +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) void B::B() +; SYM_FORMAT-DAG: thunk [{{.*}}] (Pcode) B::`vcall'{0}' +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) virtual void B::PureFunc() +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) void A::RegularFunc() +; SYM_FORMAT-DAG: func [{{.*}}] (EBP) virtual void A::VirtualFunc() ; TYPES_FORMAT: Enums ; TYPES_FORMAT-DAG: enum TestEnum ; TYPES_FORMAT-DAG: enum TestEnumClass ; TYPES_FORMAT: Function Signatures -; TYPES_FORMAT-DAG: int32_t __cdecl () -; TYPES_FORMAT-DAG: int32_t __cdecl (int32_t, char**) +; TYPES_FORMAT-DAG: int __cdecl () +; TYPES_FORMAT-DAG: int __cdecl (int, char**) ; TYPES_FORMAT-DAG: void (A::)() ; TYPES_FORMAT-DAG: void (B::)() ; TYPES_FORMAT-DAG: void (B::)(B&) @@ -30,7 +30,7 @@ ; TYPES_FORMAT-DAG: void (A::)() ; TYPES_FORMAT-DAG: A& (A::)(A&) ; TYPES_FORMAT: Typedefs -; TYPES_FORMAT-DAG: typedef int32_t IntType +; TYPES_FORMAT-DAG: typedef int IntType ; TYPES_FORMAT-DAG: typedef class A ClassAType ; TYPES_FORMAT: Classes ; TYPES_FORMAT-DAG: class A @@ -43,7 +43,19 @@ ; FULL_CLASS: virtual void VirtualFunc() ; FULL_CLASS: void RegularFunc() ; FULL_CLASS: } -; FULL_CLASS-DAG: class B { -; FULL_CLASS: public: -; FULL_CLASS: virtual void PureFunc() +; FULL_CLASS-DAG: class MemberTest { +; FULL_CLASS: data +0x00 MemberTest::NestedEnum m_nested_enum +; FULL_CLASS: data +0x04 int m_typedef +; FULL_CLASS: data +0x08 bool m_bool +; FULL_CLASS: data +0x09 char m_char +; FULL_CLASS: data +0x0a wchar_t m_wchar_t +; FULL_CLASS: data +0x0c int m_int +; FULL_CLASS: data +0x10 unsigned m_unsigned +; FULL_CLASS: data +0x14 long m_long +; FULL_CLASS: data +0x18 unsigned long m_unsigned_long +; FULL_CLASS: data +0x20 __int64 m_int64 +; FULL_CLASS: data +0x28 unsigned __int64 m_unsigned_int64 +; FULL_CLASS: data +0x30 float m_float +; FULL_CLASS: data +0x38 double m_double +; FULL_CLASS: data +0x40 void (__cdecl *m_pfn_2_args)(int, double) ; FULL_CLASS: } \ No newline at end of file diff --git a/tools/llvm-pdbdump/CMakeLists.txt b/tools/llvm-pdbdump/CMakeLists.txt index 0519bf0634c..6dae9147bc2 100644 --- a/tools/llvm-pdbdump/CMakeLists.txt +++ b/tools/llvm-pdbdump/CMakeLists.txt @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS add_llvm_tool(llvm-pdbdump llvm-pdbdump.cpp + BuiltinDumper.cpp ClassDefinitionDumper.cpp CompilandDumper.cpp FunctionDumper.cpp diff --git a/tools/llvm-pdbdump/FunctionDumper.cpp b/tools/llvm-pdbdump/FunctionDumper.cpp index e65983034a6..1a1defed042 100644 --- a/tools/llvm-pdbdump/FunctionDumper.cpp +++ b/tools/llvm-pdbdump/FunctionDumper.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "FunctionDumper.h" +#include "BuiltinDumper.h" #include "llvm-pdbdump.h" #include "llvm/DebugInfo/PDB/IPDBSession.h" @@ -16,7 +17,6 @@ #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.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" @@ -45,7 +45,8 @@ void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS, FunctionDumper::FunctionDumper() : PDBSymDumper(true) {} void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol, - PointerType Pointer, raw_ostream &OS) { + const char *Name, PointerType Pointer, + raw_ostream &OS) { auto ReturnType = Symbol.getReturnType(); ReturnType->dump(OS, 0, *this); OS << " "; @@ -70,13 +71,14 @@ void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol, OS << "("; if (ShouldDumpCallingConvention) OS << CC << " "; - OS << Symbol.getCallingConvention() << " "; if (ClassParent) OS << ClassParent->getName() << "::"; if (Pointer == PointerType::Reference) OS << "&"; else OS << "*"; + if (Name) + OS << Name; OS << ")"; } @@ -185,10 +187,8 @@ void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, 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"; + BuiltinDumper Dumper; + Dumper.start(Symbol, OS); } void FunctionDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, @@ -226,7 +226,7 @@ void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, FunctionDumper NestedDumper; PointerType Pointer = Symbol.isReference() ? PointerType::Reference : PointerType::Pointer; - NestedDumper.start(*FuncSig, Pointer, OS); + NestedDumper.start(*FuncSig, nullptr, Pointer, OS); } else { if (Symbol.isConstType()) OS << "const "; diff --git a/tools/llvm-pdbdump/FunctionDumper.h b/tools/llvm-pdbdump/FunctionDumper.h index f9338cb8764..63aa5658f60 100644 --- a/tools/llvm-pdbdump/FunctionDumper.h +++ b/tools/llvm-pdbdump/FunctionDumper.h @@ -20,8 +20,8 @@ public: enum class PointerType { None, Pointer, Reference }; - void start(const PDBSymbolTypeFunctionSig &Symbol, PointerType Pointer, - raw_ostream &OS); + void start(const PDBSymbolTypeFunctionSig &Symbol, const char *Name, + PointerType Pointer, raw_ostream &OS); void start(const PDBSymbolFunc &Symbol, PointerType Pointer, raw_ostream &OS, int Indent); diff --git a/tools/llvm-pdbdump/TypeDumper.cpp b/tools/llvm-pdbdump/TypeDumper.cpp index 3131e9f00cc..7b705961441 100644 --- a/tools/llvm-pdbdump/TypeDumper.cpp +++ b/tools/llvm-pdbdump/TypeDumper.cpp @@ -68,7 +68,7 @@ void TypeDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, OS << newline(Indent); FunctionDumper Dumper; - Dumper.start(Symbol, FunctionDumper::PointerType::None, OS); + Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None, OS); } void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS, diff --git a/tools/llvm-pdbdump/TypedefDumper.cpp b/tools/llvm-pdbdump/TypedefDumper.cpp index 6eea6b69d95..7bb4b9d2d43 100644 --- a/tools/llvm-pdbdump/TypedefDumper.cpp +++ b/tools/llvm-pdbdump/TypedefDumper.cpp @@ -9,12 +9,12 @@ #include "TypedefDumper.h" +#include "BuiltinDumper.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" @@ -39,10 +39,8 @@ void TypedefDumper::dump(const PDBSymbolTypeArray &Symbol, raw_ostream &OS, 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"; + BuiltinDumper Dumper; + Dumper.start(Symbol, OS); } void TypedefDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, @@ -65,7 +63,7 @@ void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, if (Symbol.isReference()) Pointer = FunctionDumper::PointerType::Reference; FunctionDumper NestedDumper; - NestedDumper.start(*FuncSig, Pointer, OS); + NestedDumper.start(*FuncSig, nullptr, Pointer, OS); } else { PointeeType->dump(OS, Indent, *this); OS << ((Symbol.isReference()) ? "&" : "*"); @@ -75,7 +73,7 @@ void TypedefDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS, void TypedefDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS, int Indent) { FunctionDumper Dumper; - Dumper.start(Symbol, FunctionDumper::PointerType::None, OS); + Dumper.start(Symbol, nullptr, FunctionDumper::PointerType::None, OS); } void TypedefDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS, diff --git a/tools/llvm-pdbdump/VariableDumper.cpp b/tools/llvm-pdbdump/VariableDumper.cpp index 913cfee6622..371c270443a 100644 --- a/tools/llvm-pdbdump/VariableDumper.cpp +++ b/tools/llvm-pdbdump/VariableDumper.cpp @@ -9,13 +9,14 @@ #include "VariableDumper.h" +#include "BuiltinDumper.h" #include "llvm-pdbdump.h" #include "FunctionDumper.h" #include "llvm/DebugInfo/PDB/PDBSymbolData.h" #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" +#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" @@ -57,7 +58,8 @@ void VariableDumper::start(const PDBSymbolData &Var, raw_ostream &OS, void VariableDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS, int Indent) { - OS << Symbol.getBuiltinType(); + BuiltinDumper Dumper; + Dumper.start(Symbol, OS); } void VariableDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS, @@ -114,7 +116,29 @@ void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type, ElementType->dump(OS, 0, *this); OS << " " << Name << IndexStream.str(); } else { - Type.dump(OS, 0, *this); - OS << " " << Name; + if (!tryDumpFunctionPointer(Type, Name, OS)) { + Type.dump(OS, 0, *this); + OS << " " << Name; + } } } + +bool VariableDumper::tryDumpFunctionPointer(const PDBSymbol &Type, + StringRef Name, raw_ostream &OS) { + // Function pointers come across as pointers to function signatures. But the + // signature carries no name, so we have to handle this case separately. + if (auto *PointerType = dyn_cast(&Type)) { + auto PointeeType = PointerType->getPointeeType(); + if (auto *FunctionSig = + dyn_cast(PointeeType.get())) { + FunctionDumper Dumper; + FunctionDumper::PointerType PT = FunctionDumper::PointerType::Pointer; + if (PointerType->isReference()) + PT = FunctionDumper::PointerType::Reference; + std::string NameStr(Name.begin(), Name.end()); + Dumper.start(*FunctionSig, NameStr.c_str(), PT, OS); + return true; + } + } + return false; +} diff --git a/tools/llvm-pdbdump/VariableDumper.h b/tools/llvm-pdbdump/VariableDumper.h index e6e71faca31..e8832e3d633 100644 --- a/tools/llvm-pdbdump/VariableDumper.h +++ b/tools/llvm-pdbdump/VariableDumper.h @@ -37,6 +37,8 @@ public: private: void dumpSymbolTypeAndName(const PDBSymbol &Type, StringRef Name, raw_ostream &OS); + bool tryDumpFunctionPointer(const PDBSymbol &Type, StringRef Name, + raw_ostream &OS); }; }