2017-01-11 01:35:43 +01:00
|
|
|
//===- PrettyFunctionDumper.cpp --------------------------------- *- C++ *-===//
|
2015-02-22 23:03:38 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "PrettyFunctionDumper.h"
|
2015-02-27 10:15:59 +01:00
|
|
|
#include "LinePrinter.h"
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "PrettyBuiltinDumper.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2016-05-04 22:32:13 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBExtras.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
|
2015-02-22 23:03:38 +01: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 06:58:34 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
2017-05-14 03:13:40 +02:00
|
|
|
#include "llvm/Support/FormatVariadic.h"
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-02-22 23:20:26 +01:00
|
|
|
using namespace llvm;
|
2016-01-13 20:32:35 +01:00
|
|
|
using namespace llvm::codeview;
|
2016-05-04 22:32:13 +02:00
|
|
|
using namespace llvm::pdb;
|
2015-02-22 23:20:26 +01:00
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
namespace {
|
|
|
|
template <class T>
|
2015-02-27 10:15:59 +01:00
|
|
|
void dumpClassParentWithScopeOperator(const T &Symbol, LinePrinter &Printer,
|
2016-05-04 22:32:13 +02:00
|
|
|
FunctionDumper &Dumper) {
|
2015-02-22 23:03:38 +01:00
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
2015-02-22 23:33:57 +01:00
|
|
|
Symbol.getSession().template getConcreteSymbolById<PDBSymbolTypeUDT>(
|
2015-02-22 23:03:38 +01:00
|
|
|
ClassParentId);
|
|
|
|
if (!ClassParent)
|
|
|
|
return;
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << ClassParent->getName();
|
|
|
|
Printer << "::";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
FunctionDumper::FunctionDumper(LinePrinter &P)
|
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-22 23:03:38 +01:00
|
|
|
|
|
|
|
void FunctionDumper::start(const PDBSymbolTypeFunctionSig &Symbol,
|
2015-03-01 07:51:29 +01:00
|
|
|
const char *Name, PointerType Pointer) {
|
2015-02-22 23:03:38 +01:00
|
|
|
auto ReturnType = Symbol.getReturnType();
|
2015-03-01 07:51:29 +01:00
|
|
|
ReturnType->dump(*this);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << " ";
|
2015-02-22 23:03:38 +01:00
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
|
|
|
Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
|
|
|
|
ClassParentId);
|
|
|
|
|
2016-05-04 22:32:13 +02:00
|
|
|
PDB_CallingConv CC = Symbol.getCallingConvention();
|
2015-02-23 06:58:34 +01:00
|
|
|
bool ShouldDumpCallingConvention = true;
|
2016-01-13 20:32:35 +01:00
|
|
|
if ((ClassParent && CC == CallingConvention::ThisCall) ||
|
|
|
|
(!ClassParent && CC == CallingConvention::NearStdCall)) {
|
2015-02-23 06:58:34 +01:00
|
|
|
ShouldDumpCallingConvention = false;
|
|
|
|
}
|
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Pointer == PointerType::None) {
|
2015-02-23 06:58:34 +01:00
|
|
|
if (ShouldDumpCallingConvention)
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
|
|
|
|
if (ClassParent) {
|
|
|
|
Printer << "(";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get()
|
|
|
|
<< ClassParent->getName();
|
|
|
|
Printer << "::)";
|
|
|
|
}
|
2015-02-22 23:03:38 +01:00
|
|
|
} else {
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "(";
|
2015-02-23 06:58:34 +01:00
|
|
|
if (ShouldDumpCallingConvention)
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
|
|
|
|
if (ClassParent) {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get()
|
|
|
|
<< ClassParent->getName();
|
|
|
|
Printer << "::";
|
|
|
|
}
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Pointer == PointerType::Reference)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "&";
|
2015-02-22 23:03:38 +01:00
|
|
|
else
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "*";
|
2015-02-27 00:49:23 +01:00
|
|
|
if (Name)
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Name;
|
|
|
|
Printer << ")";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "(";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (auto ChildEnum = Symbol.getArguments()) {
|
|
|
|
uint32_t Index = 0;
|
|
|
|
while (auto Arg = ChildEnum->getNext()) {
|
2015-03-01 07:51:29 +01:00
|
|
|
Arg->dump(*this);
|
2015-02-22 23:03:38 +01:00
|
|
|
if (++Index < ChildEnum->getChildCount())
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << ", ";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << ")";
|
2015-02-22 23:03:38 +01:00
|
|
|
|
|
|
|
if (Symbol.isConstType())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::start(const PDBSymbolFunc &Symbol, PointerType Pointer) {
|
2015-05-01 22:24:26 +02:00
|
|
|
uint64_t FuncStart = Symbol.getVirtualAddress();
|
|
|
|
uint64_t FuncEnd = FuncStart + Symbol.getLength();
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer << "func [";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(FuncStart, 10);
|
2015-02-27 10:15:59 +01:00
|
|
|
if (auto DebugStart = Symbol.findOneChild<PDBSymbolFuncDebugStart>()) {
|
2015-05-01 22:24:26 +02:00
|
|
|
uint64_t Prologue = DebugStart->getVirtualAddress() - FuncStart;
|
2017-05-14 03:13:40 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< formatv("+{0,2}", Prologue);
|
2015-02-27 10:15:59 +01:00
|
|
|
}
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer << " - ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get() << format_hex(FuncEnd, 10);
|
2015-02-27 10:15:59 +01:00
|
|
|
if (auto DebugEnd = Symbol.findOneChild<PDBSymbolFuncDebugEnd>()) {
|
2015-05-01 22:24:26 +02:00
|
|
|
uint64_t Epilogue = FuncEnd - DebugEnd->getVirtualAddress();
|
2017-05-14 03:13:40 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< formatv("-{0,2}", Epilogue);
|
2015-02-27 10:15:59 +01:00
|
|
|
}
|
2017-05-14 03:13:40 +02:00
|
|
|
|
|
|
|
WithColor(Printer, PDB_ColorItem::Comment).get()
|
|
|
|
<< formatv(" | sizeof={0,3}", Symbol.getLength());
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer << "] (";
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-03-02 05:39:56 +01:00
|
|
|
if (Symbol.hasFramePointer()) {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Register).get()
|
|
|
|
<< Symbol.getLocalBasePointerRegisterId();
|
|
|
|
} else {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Register).get() << "FPO";
|
|
|
|
}
|
|
|
|
Printer << ") ";
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Symbol.isVirtual() || Symbol.isPureVirtual())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "virtual ";
|
2015-02-22 23:03:38 +01:00
|
|
|
|
|
|
|
auto Signature = Symbol.getSignature();
|
|
|
|
if (!Signature) {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
if (Pointer == PointerType::Pointer)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "*";
|
2015-02-23 06:58:34 +01:00
|
|
|
else if (Pointer == FunctionDumper::PointerType::Reference)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "&";
|
2015-02-22 23:03:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ReturnType = Signature->getReturnType();
|
2015-03-01 07:51:29 +01:00
|
|
|
ReturnType->dump(*this);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << " ";
|
2015-02-23 06:58:34 +01:00
|
|
|
|
|
|
|
auto ClassParent = Symbol.getClassParent();
|
2016-01-13 20:32:35 +01:00
|
|
|
CallingConvention CC = Signature->getCallingConvention();
|
2015-02-23 06:58:34 +01:00
|
|
|
if (Pointer != FunctionDumper::PointerType::None)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "(";
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2016-01-13 20:32:35 +01:00
|
|
|
if ((ClassParent && CC != CallingConvention::ThisCall) ||
|
|
|
|
(!ClassParent && CC != CallingConvention::NearStdCall)) {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get()
|
|
|
|
<< Signature->getCallingConvention() << " ";
|
|
|
|
}
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
if (Pointer != FunctionDumper::PointerType::None) {
|
|
|
|
if (Pointer == PointerType::Pointer)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "*";
|
2015-02-23 06:58:34 +01:00
|
|
|
else if (Pointer == FunctionDumper::PointerType::Reference)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "&";
|
|
|
|
Printer << ")";
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "(";
|
2015-02-23 06:58:34 +01:00
|
|
|
if (auto Arguments = Symbol.getArguments()) {
|
2015-02-22 23:03:38 +01:00
|
|
|
uint32_t Index = 0;
|
2015-02-23 06:58:34 +01:00
|
|
|
while (auto Arg = Arguments->getNext()) {
|
|
|
|
auto ArgType = Arg->getType();
|
2015-03-01 07:51:29 +01:00
|
|
|
ArgType->dump(*this);
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << " "
|
|
|
|
<< Arg->getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
if (++Index < Arguments->getChildCount())
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << ", ";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
2018-01-17 02:22:03 +01:00
|
|
|
if (Signature->isCVarArgs())
|
|
|
|
Printer << ", ...";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << ")";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Symbol.isConstType())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Symbol.isPureVirtual())
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << " = 0";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeArray &Symbol) {
|
2017-04-10 08:14:09 +02:00
|
|
|
auto ElementType = Symbol.getElementType();
|
2015-02-22 23:03:38 +01:00
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
ElementType->dump(*this);
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << "[";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Symbol.getLength();
|
|
|
|
Printer << "]";
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeBuiltin &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
BuiltinDumper Dumper(Printer);
|
2015-03-01 07:51:29 +01:00
|
|
|
Dumper.start(Symbol);
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
dumpClassParentWithScopeOperator(Symbol, Printer, *this);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeFunctionArg &Symbol) {
|
2015-02-22 23:03:38 +01:00
|
|
|
// PDBSymbolTypeFunctionArg is just a shim over the real argument. Just drill
|
2015-02-23 06:58:34 +01:00
|
|
|
// through to the real thing and dump it.
|
2015-02-22 23:03:38 +01:00
|
|
|
uint32_t TypeId = Symbol.getTypeId();
|
|
|
|
auto Type = Symbol.getSession().getSymbolById(TypeId);
|
|
|
|
if (!Type)
|
|
|
|
return;
|
2015-03-01 07:51:29 +01:00
|
|
|
Type->dump(*this);
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
dumpClassParentWithScopeOperator(Symbol, Printer, *this);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypePointer &Symbol) {
|
2017-04-10 08:14:09 +02:00
|
|
|
auto PointeeType = Symbol.getPointeeType();
|
2015-02-22 23:03:38 +01:00
|
|
|
if (!PointeeType)
|
|
|
|
return;
|
|
|
|
|
[llvm-pdbdump] More advanced class definition dumping.
Previously the dumping of class definitions was very primitive,
and it made it hard to do more than the most trivial of output
formats when dumping. As such, we would only dump one line for
each field, and then dump non-layout items like nested types
and enums.
With this patch, we do a complete analysis of the object
hierarchy including aggregate types, bases, virtual bases,
vftable analysis, etc. The only immediately visible effects
of this are that a) we can now dump a line for the vfptr where
before we would treat that as padding, and b) we now don't
treat virtual bases that come at the end of a class as padding
since we have a more detailed analysis of the class's storage
usage.
In subsequent patches, we should be able to use this analysis
to display a complete graphical view of a class's layout including
recursing arbitrarily deep into an object's base class / aggregate
member hierarchy.
llvm-svn: 300133
2017-04-13 01:18:21 +02:00
|
|
|
if (auto FuncSig = unique_dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType)) {
|
2015-02-27 10:15:59 +01:00
|
|
|
FunctionDumper NestedDumper(Printer);
|
2015-02-22 23:03:38 +01:00
|
|
|
PointerType Pointer =
|
|
|
|
Symbol.isReference() ? PointerType::Reference : PointerType::Pointer;
|
2015-03-01 07:51:29 +01:00
|
|
|
NestedDumper.start(*FuncSig, nullptr, Pointer);
|
2015-02-22 23:03:38 +01:00
|
|
|
} else {
|
|
|
|
if (Symbol.isConstType())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
|
2015-02-22 23:03:38 +01:00
|
|
|
if (Symbol.isVolatileType())
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
|
2015-03-01 07:51:29 +01:00
|
|
|
PointeeType->dump(*this);
|
|
|
|
Printer << (Symbol.isReference() ? "&" : "*");
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void FunctionDumper::dump(const PDBSymbolTypeUDT &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-22 23:03:38 +01:00
|
|
|
}
|