2015-02-23 06:03:38 +08: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-27 07:49:23 +08:00
|
|
|
#include "BuiltinDumper.h"
|
2015-02-27 17:15:59 +08:00
|
|
|
#include "LinePrinter.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
#include "llvm-pdbdump.h"
|
2015-02-23 06:03:38 +08:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
2015-02-23 06:03:38 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
|
2015-02-23 06:03:38 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.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 13:58:34 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2015-02-23 06:03:38 +08:00
|
|
|
|
2015-02-23 06:20:26 +08:00
|
|
|
using namespace llvm;
|
2016-01-14 03:32:35 +08:00
|
|
|
using namespace llvm::codeview;
|
2015-02-23 06:20:26 +08:00
|
|
|
|
2015-02-23 06:03:38 +08:00
|
|
|
namespace {
|
|
|
|
template <class T>
|
2015-02-27 17:15:59 +08:00
|
|
|
void dumpClassParentWithScopeOperator(const T &Symbol, LinePrinter &Printer,
|
2015-02-23 06:03:38 +08:00
|
|
|
llvm::FunctionDumper &Dumper) {
|
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
2015-02-23 06:33:57 +08:00
|
|
|
Symbol.getSession().template getConcreteSymbolById<PDBSymbolTypeUDT>(
|
2015-02-23 06:03:38 +08:00
|
|
|
ClassParentId);
|
|
|
|
if (!ClassParent)
|
|
|
|
return;
|
|
|
|
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << ClassParent->getName();
|
|
|
|
Printer << "::";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 17:15:59 +08:00
|
|
|
FunctionDumper::FunctionDumper(LinePrinter &P)
|
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-23 06:03:38 +08:00
|
|
|
|
|
|
|
void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol,
|
2015-03-01 14:51:29 +08:00
|
|
|
const char *Name, PointerType Pointer) {
|
2015-02-23 06:03:38 +08:00
|
|
|
auto ReturnType = Symbol.getReturnType();
|
2015-03-01 14:51:29 +08:00
|
|
|
ReturnType->dump(*this);
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << " ";
|
2015-02-23 06:03:38 +08:00
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
|
|
|
Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
|
|
|
|
ClassParentId);
|
|
|
|
|
2016-01-14 03:32:35 +08:00
|
|
|
CallingConvention CC = Symbol.getCallingConvention();
|
2015-02-23 13:58:34 +08:00
|
|
|
bool ShouldDumpCallingConvention = true;
|
2016-01-14 03:32:35 +08:00
|
|
|
if ((ClassParent && CC == CallingConvention::ThisCall) ||
|
|
|
|
(!ClassParent && CC == CallingConvention::NearStdCall)) {
|
2015-02-23 13:58:34 +08:00
|
|
|
ShouldDumpCallingConvention = false;
|
|
|
|
}
|
|
|
|
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Pointer == PointerType::None) {
|
2015-02-23 13:58:34 +08:00
|
|
|
if (ShouldDumpCallingConvention)
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
|
|
|
|
if (ClassParent) {
|
|
|
|
Printer << "(";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get()
|
|
|
|
<< ClassParent->getName();
|
|
|
|
Printer << "::)";
|
|
|
|
}
|
2015-02-23 06:03:38 +08:00
|
|
|
} else {
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "(";
|
2015-02-23 13:58:34 +08:00
|
|
|
if (ShouldDumpCallingConvention)
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
|
|
|
|
if (ClassParent) {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get()
|
|
|
|
<< ClassParent->getName();
|
|
|
|
Printer << "::";
|
|
|
|
}
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Pointer == PointerType::Reference)
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "&";
|
2015-02-23 06:03:38 +08:00
|
|
|
else
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "*";
|
2015-02-27 07:49:23 +08:00
|
|
|
if (Name)
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
|
|
|
|
Printer << ")";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "(";
|
2015-02-23 06:03:38 +08:00
|
|
|
if (auto ChildEnum = Symbol.getArguments()) {
|
|
|
|
uint32_t Index = 0;
|
|
|
|
while (auto Arg = ChildEnum->getNext()) {
|
2015-03-01 14:51:29 +08:00
|
|
|
Arg->dump(*this);
|
2015-02-23 06:03:38 +08:00
|
|
|
if (++Index < ChildEnum->getChildCount())
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << ", ";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
}
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << ")";
|
2015-02-23 06:03:38 +08:00
|
|
|
|
|
|
|
if (Symbol.isConstType())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::start(const PDBSymbolFunc &Symbol, PointerType Pointer) {
|
2015-05-02 04:24:26 +08:00
|
|
|
uint64_t FuncStart = Symbol.getVirtualAddress();
|
|
|
|
uint64_t FuncEnd = FuncStart + Symbol.getLength();
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2015-03-02 12:39:56 +08:00
|
|
|
Printer << "func [";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(FuncStart, 10);
|
2015-02-27 17:15:59 +08:00
|
|
|
if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>()) {
|
2015-05-02 04:24:26 +08:00
|
|
|
uint64_t Prologue = DebugStart->getVirtualAddress() - FuncStart;
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get() << "+" << Prologue;
|
|
|
|
}
|
2015-03-02 12:39:56 +08:00
|
|
|
Printer << " - ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(FuncEnd, 10);
|
2015-02-27 17:15:59 +08:00
|
|
|
if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>()) {
|
2015-05-02 04:24:26 +08:00
|
|
|
uint64_t Epilogue = FuncEnd - DebugEnd->getVirtualAddress();
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get() << "-" << Epilogue;
|
|
|
|
}
|
2015-03-02 12:39:56 +08:00
|
|
|
Printer << "] (";
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2015-03-02 12:39:56 +08:00
|
|
|
if (Symbol.hasFramePointer()) {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Register).get()
|
|
|
|
<< Symbol.getLocalBasePointerRegisterId();
|
|
|
|
} else {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Register).get() << "FPO";
|
|
|
|
}
|
|
|
|
Printer << ") ";
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Symbol.isVirtual() || Symbol.isPureVirtual())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "virtual ";
|
2015-02-23 06:03:38 +08:00
|
|
|
|
|
|
|
auto Signature = Symbol.getSignature();
|
|
|
|
if (!Signature) {
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
if (Pointer == PointerType::Pointer)
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "*";
|
2015-02-23 13:58:34 +08:00
|
|
|
else if (Pointer == FunctionDumper::PointerType::Reference)
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "&";
|
2015-02-23 06:03:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ReturnType = Signature->getReturnType();
|
2015-03-01 14:51:29 +08:00
|
|
|
ReturnType->dump(*this);
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << " ";
|
2015-02-23 13:58:34 +08:00
|
|
|
|
|
|
|
auto ClassParent = Symbol.getClassParent();
|
2016-01-14 03:32:35 +08:00
|
|
|
CallingConvention CC = Signature->getCallingConvention();
|
2015-02-23 13:58:34 +08:00
|
|
|
if (Pointer != FunctionDumper::PointerType::None)
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "(";
|
2015-02-23 06:03:38 +08:00
|
|
|
|
2016-01-14 03:32:35 +08:00
|
|
|
if ((ClassParent && CC != CallingConvention::ThisCall) ||
|
|
|
|
(!ClassParent && CC != CallingConvention::NearStdCall)) {
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get()
|
|
|
|
<< Signature->getCallingConvention() << " ";
|
|
|
|
}
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
if (Pointer != FunctionDumper::PointerType::None) {
|
|
|
|
if (Pointer == PointerType::Pointer)
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "*";
|
2015-02-23 13:58:34 +08:00
|
|
|
else if (Pointer == FunctionDumper::PointerType::Reference)
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "&";
|
|
|
|
Printer << ")";
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|
2015-02-23 06:03:38 +08:00
|
|
|
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "(";
|
2015-02-23 13:58:34 +08:00
|
|
|
if (auto Arguments = Symbol.getArguments()) {
|
2015-02-23 06:03:38 +08:00
|
|
|
uint32_t Index = 0;
|
2015-02-23 13:58:34 +08:00
|
|
|
while (auto Arg = Arguments->getNext()) {
|
|
|
|
auto ArgType = Arg->getType();
|
2015-03-01 14:51:29 +08:00
|
|
|
ArgType->dump(*this);
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << " "
|
|
|
|
<< Arg->getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
if (++Index < Arguments->getChildCount())
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << ", ";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
}
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << ")";
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Symbol.isConstType())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Symbol.isPureVirtual())
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << " = 0";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol) {
|
2015-02-23 06:03:38 +08:00
|
|
|
uint32_t ElementTypeId = Symbol.getTypeId();
|
|
|
|
auto ElementType = Symbol.getSession().getSymbolById(ElementTypeId);
|
|
|
|
if (!ElementType)
|
|
|
|
return;
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
ElementType->dump(*this);
|
2015-02-27 17:15:59 +08:00
|
|
|
Printer << "[";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Symbol.getLength();
|
|
|
|
Printer << "]";
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
BuiltinDumper Dumper(Printer);
|
2015-03-01 14:51:29 +08:00
|
|
|
Dumper.start(Symbol);
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
dumpClassParentWithScopeOperator(Symbol, Printer, *this);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeFunctionArg &Symbol) {
|
2015-02-23 06:03:38 +08:00
|
|
|
// PDBSymbolTypeFunctionArg is just a shim over the real argument. Just drill
|
2015-02-23 13:58:34 +08:00
|
|
|
// through to the real thing and dump it.
|
2015-02-23 06:03:38 +08:00
|
|
|
uint32_t TypeId = Symbol.getTypeId();
|
|
|
|
auto Type = Symbol.getSession().getSymbolById(TypeId);
|
|
|
|
if (!Type)
|
|
|
|
return;
|
2015-03-01 14:51:29 +08:00
|
|
|
Type->dump(*this);
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
dumpClassParentWithScopeOperator(Symbol, Printer, *this);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol) {
|
2015-02-23 06:03:38 +08:00
|
|
|
uint32_t PointeeId = Symbol.getTypeId();
|
|
|
|
auto PointeeType = Symbol.getSession().getSymbolById(PointeeId);
|
|
|
|
if (!PointeeType)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (auto FuncSig = dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
|
2015-02-27 17:15:59 +08:00
|
|
|
FunctionDumper NestedDumper(Printer);
|
2015-02-23 06:03:38 +08:00
|
|
|
PointerType Pointer =
|
|
|
|
Symbol.isReference() ? PointerType::Reference : PointerType::Pointer;
|
2015-03-01 14:51:29 +08:00
|
|
|
NestedDumper.start(*FuncSig, nullptr, Pointer);
|
2015-02-23 06:03:38 +08:00
|
|
|
} else {
|
|
|
|
if (Symbol.isConstType())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
|
2015-02-23 06:03:38 +08:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
|
2015-03-01 14:51:29 +08:00
|
|
|
PointeeType->dump(*this);
|
|
|
|
Printer << (Symbol.isReference() ? "&" : "*");
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 06:03:38 +08:00
|
|
|
}
|