2015-02-22 22:03:38 +00:00
|
|
|
//===- 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"
|
2015-02-23 05:58:34 +00:00
|
|
|
#include "llvm-pdbdump.h"
|
2015-02-22 22:03:38 +00:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2015-02-23 05:58:34 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
2015-02-22 22:03:38 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
2015-02-23 05:58:34 +00:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
|
2015-02-22 22:03:38 +00:00
|
|
|
#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"
|
2015-02-23 05:58:34 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
2015-02-22 22:03:38 +00:00
|
|
|
|
2015-02-22 22:20:26 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2015-02-22 22:03:38 +00:00
|
|
|
namespace {
|
|
|
|
template <class T>
|
|
|
|
void dumpClassParentWithScopeOperator(const T &Symbol, llvm::raw_ostream &OS,
|
|
|
|
llvm::FunctionDumper &Dumper) {
|
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
2015-02-22 22:33:57 +00:00
|
|
|
Symbol.getSession().template getConcreteSymbolById<PDBSymbolTypeUDT>(
|
2015-02-22 22:03:38 +00:00
|
|
|
ClassParentId);
|
|
|
|
if (!ClassParent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << ClassParent->getName() << "::";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionDumper::FunctionDumper() : PDBSymDumper(true) {}
|
|
|
|
|
|
|
|
void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol,
|
|
|
|
PointerType Pointer, raw_ostream &OS) {
|
|
|
|
auto ReturnType = Symbol.getReturnType();
|
|
|
|
ReturnType->dump(OS, 0, *this);
|
|
|
|
OS << " ";
|
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
|
|
|
Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
|
|
|
|
ClassParentId);
|
|
|
|
|
2015-02-23 05:58:34 +00:00
|
|
|
PDB_CallingConv CC = Symbol.getCallingConvention();
|
|
|
|
bool ShouldDumpCallingConvention = true;
|
|
|
|
if ((ClassParent && CC == PDB_CallingConv::Thiscall) ||
|
|
|
|
(!ClassParent && CC == PDB_CallingConv::NearStdcall)) {
|
|
|
|
ShouldDumpCallingConvention = false;
|
|
|
|
}
|
|
|
|
|
2015-02-22 22:03:38 +00:00
|
|
|
if (Pointer == PointerType::None) {
|
2015-02-23 05:58:34 +00:00
|
|
|
if (ShouldDumpCallingConvention)
|
|
|
|
OS << CC << " ";
|
2015-02-22 22:03:38 +00:00
|
|
|
if (ClassParent)
|
|
|
|
OS << "(" << ClassParent->getName() << "::)";
|
|
|
|
} else {
|
2015-02-23 05:58:34 +00:00
|
|
|
OS << "(";
|
|
|
|
if (ShouldDumpCallingConvention)
|
|
|
|
OS << CC << " ";
|
|
|
|
OS << Symbol.getCallingConvention() << " ";
|
2015-02-22 22:03:38 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2015-02-23 05:58:34 +00:00
|
|
|
void FunctionDumper::start(const PDBSymbolFunc &Symbol, PointerType Pointer,
|
|
|
|
raw_ostream &OS, int Indent) {
|
|
|
|
uint32_t FuncStart = Symbol.getRelativeVirtualAddress();
|
|
|
|
uint32_t FuncEnd = FuncStart + Symbol.getLength();
|
|
|
|
|
|
|
|
OS << newline(Indent);
|
|
|
|
|
|
|
|
OS << "func [" << format_hex(FuncStart, 8);
|
|
|
|
if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>())
|
|
|
|
OS << "+" << DebugStart->getRelativeVirtualAddress() - FuncStart;
|
|
|
|
OS << " - " << format_hex(FuncEnd, 8);
|
|
|
|
if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>())
|
|
|
|
OS << "-" << FuncEnd - DebugEnd->getRelativeVirtualAddress();
|
|
|
|
OS << "] ";
|
|
|
|
|
|
|
|
if (Symbol.hasFramePointer())
|
|
|
|
OS << "(" << Symbol.getLocalBasePointerRegisterId() << ")";
|
|
|
|
else
|
|
|
|
OS << "(FPO)";
|
|
|
|
|
|
|
|
OS << " ";
|
2015-02-22 22:03:38 +00:00
|
|
|
if (Symbol.isVirtual() || Symbol.isPureVirtual())
|
|
|
|
OS << "virtual ";
|
|
|
|
|
|
|
|
auto Signature = Symbol.getSignature();
|
|
|
|
if (!Signature) {
|
|
|
|
OS << Symbol.getName();
|
2015-02-23 05:58:34 +00:00
|
|
|
if (Pointer == PointerType::Pointer)
|
|
|
|
OS << "*";
|
|
|
|
else if (Pointer == FunctionDumper::PointerType::Reference)
|
|
|
|
OS << "&";
|
2015-02-22 22:03:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ReturnType = Signature->getReturnType();
|
|
|
|
ReturnType->dump(OS, 0, *this);
|
2015-02-23 05:58:34 +00:00
|
|
|
OS << " ";
|
|
|
|
|
|
|
|
auto ClassParent = Symbol.getClassParent();
|
|
|
|
PDB_CallingConv CC = Signature->getCallingConvention();
|
|
|
|
if (Pointer != FunctionDumper::PointerType::None)
|
|
|
|
OS << "(";
|
2015-02-22 22:03:38 +00:00
|
|
|
|
2015-02-23 05:58:34 +00:00
|
|
|
if ((ClassParent && CC != PDB_CallingConv::Thiscall) ||
|
|
|
|
(!ClassParent && CC != PDB_CallingConv::NearStdcall))
|
|
|
|
OS << Signature->getCallingConvention() << " ";
|
2015-02-22 22:03:38 +00:00
|
|
|
OS << Symbol.getName();
|
2015-02-23 05:58:34 +00:00
|
|
|
if (Pointer != FunctionDumper::PointerType::None) {
|
|
|
|
if (Pointer == PointerType::Pointer)
|
|
|
|
OS << "*";
|
|
|
|
else if (Pointer == FunctionDumper::PointerType::Reference)
|
|
|
|
OS << "&";
|
|
|
|
OS << ")";
|
|
|
|
}
|
2015-02-22 22:03:38 +00:00
|
|
|
|
|
|
|
OS << "(";
|
2015-02-23 05:58:34 +00:00
|
|
|
if (auto Arguments = Symbol.getArguments()) {
|
2015-02-22 22:03:38 +00:00
|
|
|
uint32_t Index = 0;
|
2015-02-23 05:58:34 +00:00
|
|
|
while (auto Arg = Arguments->getNext()) {
|
|
|
|
auto ArgType = Arg->getType();
|
|
|
|
ArgType->dump(OS, 0, *this);
|
|
|
|
OS << " " << Arg->getName();
|
|
|
|
if (++Index < Arguments->getChildCount())
|
2015-02-22 22:03:38 +00:00
|
|
|
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
|
2015-02-23 05:58:34 +00:00
|
|
|
// through to the real thing and dump it.
|
2015-02-23 05:59:14 +00:00
|
|
|
Symbol.defaultDump(OS, Indent);
|
2015-02-22 22:03:38 +00:00
|
|
|
uint32_t TypeId = Symbol.getTypeId();
|
|
|
|
auto Type = Symbol.getSession().getSymbolById(TypeId);
|
|
|
|
if (!Type)
|
|
|
|
return;
|
|
|
|
Type->dump(OS, 0, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
|
|
|
|
int Indent) {
|
|
|
|
dumpClassParentWithScopeOperator(Symbol, OS, *this);
|
|
|
|
OS << Symbol.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol, raw_ostream &OS,
|
|
|
|
int Indent) {
|
|
|
|
uint32_t PointeeId = Symbol.getTypeId();
|
|
|
|
auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
|
|
|
|
if (!PointeeType)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
|
|
|
|
FunctionDumper NestedDumper;
|
|
|
|
PointerType Pointer =
|
|
|
|
Symbol.isReference() ? PointerType::Reference : PointerType::Pointer;
|
|
|
|
NestedDumper.start(*FuncSig, Pointer, OS);
|
|
|
|
} else {
|
|
|
|
if (Symbol.isConstType())
|
|
|
|
OS << "const ";
|
|
|
|
if (Symbol.isVolatileType())
|
|
|
|
OS << "volatile ";
|
|
|
|
PointeeType->dump(OS, Indent, *this);
|
|
|
|
OS << (Symbol.isReference() ? "&" : "*");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
|
|
|
|
int Indent) {
|
|
|
|
OS << Symbol.getName();
|
|
|
|
}
|