[llvm-pdbdump] Fix dumping of function pointers and basic types.

Function pointers were not correctly handled by the dumper, and
they would print as "* name".  They now print as
"int (__cdecl *name)(int arg1, int arg2)" as they should.

Also, doubles were being printed as floats.  This fixes that bug
as well, and adds tests for all builtin types. as well as a test
for function pointers.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230703 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Zachary Turner 2015-02-26 23:49:23 +00:00
parent ed009f6b57
commit 6aba383ab5
12 changed files with 93 additions and 65 deletions

View File

@ -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);

View File

@ -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";

View File

@ -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;

View File

@ -4,23 +4,23 @@
; The format is func [0x<rva_start>+<prologue_length> - 0x<rva_end>-<epilogue_length>]
; 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: }

View File

@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(llvm-pdbdump
llvm-pdbdump.cpp
BuiltinDumper.cpp
ClassDefinitionDumper.cpp
CompilandDumper.cpp
FunctionDumper.cpp

View File

@ -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 ";

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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 {
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<PDBSymbolTypePointer>(&Type)) {
auto PointeeType = PointerType->getPointeeType();
if (auto *FunctionSig =
dyn_cast<PDBSymbolTypeFunctionSig>(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;
}

View File

@ -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);
};
}