2017-01-11 08:35:43 +08:00
|
|
|
//===- PrettyFunctionDumper.cpp --------------------------------- *- C++ *-===//
|
2015-02-23 06:03:38 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-23 06:03:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "PrettyFunctionDumper.h"
|
2015-02-27 17:15:59 +08:00
|
|
|
#include "LinePrinter.h"
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "PrettyBuiltinDumper.h"
|
2015-02-23 06:03:38 +08:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2016-05-05 04:32:13 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBExtras.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"
|
2017-05-14 09:13:40 +08:00
|
|
|
#include "llvm/Support/FormatVariadic.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;
|
2016-05-05 04:32:13 +08:00
|
|
|
using namespace llvm::pdb;
|
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,
|
2016-05-05 04:32:13 +08:00
|
|
|
FunctionDumper &Dumper) {
|
2015-02-23 06:03:38 +08:00
|
|
|
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();
|
2018-10-02 01:55:16 +08:00
|
|
|
if (!ReturnType)
|
|
|
|
Printer << "<unknown-type>";
|
|
|
|
else
|
|
|
|
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-05-05 04:32:13 +08:00
|
|
|
PDB_CallingConv 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;
|
2017-05-14 09:13:40 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< formatv("+{0,2}", Prologue);
|
2015-02-27 17:15:59 +08:00
|
|
|
}
|
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();
|
2017-05-14 09:13:40 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< formatv("-{0,2}", Epilogue);
|
2015-02-27 17:15:59 +08:00
|
|
|
}
|
2017-05-14 09:13:40 +08:00
|
|
|
|
|
|
|
WithColor(Printer, PDB_ColorItem::Comment).get()
|
|
|
|
<< formatv(" | sizeof={0,3}", Symbol.getLength());
|
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
|
|
|
}
|
2018-01-17 09:22:03 +08:00
|
|
|
if (Signature->isCVarArgs())
|
|
|
|
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) {
|
2017-04-10 14:14:09 +08:00
|
|
|
auto ElementType = Symbol.getElementType();
|
2015-02-23 06:03:38 +08:00
|
|
|
|
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);
|
2018-10-02 01:55:16 +08:00
|
|
|
if (Type)
|
|
|
|
Printer << "<unknown-type>";
|
|
|
|
else
|
|
|
|
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) {
|
2017-04-10 14:14:09 +08:00
|
|
|
auto PointeeType = Symbol.getPointeeType();
|
2015-02-23 06:03:38 +08: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 07:18:21 +08:00
|
|
|
if (auto FuncSig = unique_dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType)) {
|
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() ? "&" : "*");
|
2018-03-06 02:29:43 +08:00
|
|
|
|
|
|
|
if (Symbol.getRawSymbol().isRestrictedType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict";
|
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
|
|
|
}
|