2017-01-11 01:35:43 +01:00
|
|
|
//===- PrettyVariableDumper.cpp ---------------------------------*- C++ -*-===//
|
2015-02-23 06:58:34 +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 "PrettyVariableDumper.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
#include "LinePrinter.h"
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "PrettyBuiltinDumper.h"
|
|
|
|
#include "PrettyFunctionDumper.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm-pdbdump.h"
|
|
|
|
|
2017-04-10 18:43:09 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
|
2015-03-04 07:09:53 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
2015-02-27 00:49:23 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
|
2017-04-10 18:43:09 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBTypes.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2017-04-10 18:43:09 +02:00
|
|
|
using namespace llvm::codeview;
|
2016-05-04 22:32:13 +02:00
|
|
|
using namespace llvm::pdb;
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
VariableDumper::VariableDumper(LinePrinter &P)
|
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
void VariableDumper::start(const PDBSymbolData &Var, uint32_t Offset) {
|
2016-06-30 19:42:48 +02:00
|
|
|
if (Var.isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
|
2015-03-02 05:39:56 +01:00
|
|
|
return;
|
2015-03-01 07:49:49 +01:00
|
|
|
if (Printer.IsSymbolExcluded(Var.getName()))
|
|
|
|
return;
|
|
|
|
|
2015-02-23 06:58:34 +01:00
|
|
|
auto VarType = Var.getType();
|
|
|
|
|
2017-04-10 21:33:29 +02:00
|
|
|
uint64_t Length = VarType->getRawSymbol().getLength();
|
|
|
|
|
2015-02-23 06:58:34 +01:00
|
|
|
switch (auto LocType = Var.getLocationType()) {
|
|
|
|
case PDB_LocType::Static:
|
2015-03-04 07:09:53 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data [";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2015-05-01 22:24:26 +02:00
|
|
|
<< format_hex(Var.getVirtualAddress(), 10);
|
2017-04-10 21:33:29 +02:00
|
|
|
Printer << ", sizeof=" << Length << "] ";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "static ";
|
2015-03-01 07:51:29 +01:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-02-23 06:58:34 +01:00
|
|
|
break;
|
|
|
|
case PDB_LocType::Constant:
|
2015-03-04 07:09:53 +01:00
|
|
|
if (isa<PDBSymbolTypeEnum>(*VarType))
|
|
|
|
break;
|
|
|
|
Printer.NewLine();
|
2017-04-10 21:33:29 +02:00
|
|
|
Printer << "data [sizeof=" << Length << "] ";
|
2015-03-01 07:51:29 +01:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer << " = ";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getValue();
|
2015-02-23 06:58:34 +01:00
|
|
|
break;
|
2015-02-23 12:33:54 +01:00
|
|
|
case PDB_LocType::ThisRel:
|
2015-03-04 07:09:53 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-13 23:11:00 +02:00
|
|
|
<< "+" << format_hex(Offset + Var.getOffset(), 4)
|
|
|
|
<< " [sizeof=" << Length << "] ";
|
2015-03-01 07:51:29 +01:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-02-23 06:58:34 +01:00
|
|
|
break;
|
2015-03-02 05:39:56 +01:00
|
|
|
case PDB_LocType::BitField:
|
2015-03-04 07:09:53 +01:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-03-02 05:39:56 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-13 23:11:00 +02:00
|
|
|
<< "+" << format_hex(Offset + Var.getOffset(), 4)
|
|
|
|
<< " [sizeof=" << Length << "] ";
|
2015-03-02 05:39:56 +01:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
|
|
|
Printer << " : ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getLength();
|
|
|
|
break;
|
2015-02-23 06:58:34 +01:00
|
|
|
default:
|
2015-03-04 07:09:53 +01:00
|
|
|
Printer.NewLine();
|
2017-04-10 21:33:29 +02:00
|
|
|
Printer << "data [sizeof=" << Length << "] ";
|
2015-03-01 07:51:29 +01:00
|
|
|
Printer << "unknown(" << LocType << ") ";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Var.getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 19:47:24 +02:00
|
|
|
void VariableDumper::startVbptr(uint32_t Offset, uint32_t Size) {
|
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "vbptr ";
|
|
|
|
|
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
|
|
|
<< "+" << format_hex(Offset, 4) << " [sizeof=" << Size << "] ";
|
|
|
|
}
|
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
void VariableDumper::start(const PDBSymbolTypeVTable &Var, uint32_t Offset) {
|
[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
|
|
|
Printer.NewLine();
|
2017-04-13 23:11:00 +02:00
|
|
|
Printer << "vfptr ";
|
[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
|
|
|
auto VTableType = cast<PDBSymbolTypePointer>(Var.getType());
|
|
|
|
uint32_t PointerSize = VTableType->getLength();
|
|
|
|
|
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-13 23:11:00 +02:00
|
|
|
<< "+" << format_hex(Offset + Var.getOffset(), 4)
|
|
|
|
<< " [sizeof=" << PointerSize << "] ";
|
[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
|
|
|
}
|
|
|
|
|
2017-04-10 18:43:09 +02:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeArray &Symbol) {
|
|
|
|
auto ElementType = Symbol.getElementType();
|
|
|
|
assert(ElementType);
|
|
|
|
if (!ElementType)
|
|
|
|
return;
|
|
|
|
ElementType->dump(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VariableDumper::dumpRight(const PDBSymbolTypeArray &Symbol) {
|
|
|
|
auto ElementType = Symbol.getElementType();
|
|
|
|
assert(ElementType);
|
|
|
|
if (!ElementType)
|
|
|
|
return;
|
|
|
|
Printer << '[' << Symbol.getCount() << ']';
|
|
|
|
ElementType->dumpRight(*this);
|
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void VariableDumper::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-23 06:58:34 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeEnum &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|
|
|
|
|
2017-04-10 18:43:09 +02:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeFunctionSig &Symbol) {
|
|
|
|
auto ReturnType = Symbol.getReturnType();
|
|
|
|
ReturnType->dump(*this);
|
|
|
|
Printer << " ";
|
|
|
|
|
|
|
|
uint32_t ClassParentId = Symbol.getClassParentId();
|
|
|
|
auto ClassParent =
|
|
|
|
Symbol.getSession().getConcreteSymbolById<PDBSymbolTypeUDT>(
|
|
|
|
ClassParentId);
|
|
|
|
|
|
|
|
if (ClassParent) {
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get()
|
|
|
|
<< ClassParent->getName();
|
|
|
|
Printer << "::";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VariableDumper::dumpRight(const PDBSymbolTypeFunctionSig &Symbol) {
|
|
|
|
Printer << "(";
|
|
|
|
if (auto Arguments = Symbol.getArguments()) {
|
|
|
|
uint32_t Index = 0;
|
|
|
|
while (auto Arg = Arguments->getNext()) {
|
|
|
|
Arg->dump(*this);
|
|
|
|
if (++Index < Arguments->getChildCount())
|
|
|
|
Printer << ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Printer << ")";
|
|
|
|
|
|
|
|
if (Symbol.isConstType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " const";
|
|
|
|
if (Symbol.isVolatileType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile";
|
|
|
|
}
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypePointer &Symbol) {
|
2015-02-23 06:58:34 +01:00
|
|
|
auto PointeeType = Symbol.getPointeeType();
|
|
|
|
if (!PointeeType)
|
|
|
|
return;
|
2017-04-10 18:43:09 +02:00
|
|
|
PointeeType->dump(*this);
|
[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)) {
|
2017-04-10 18:43:09 +02:00
|
|
|
// A hack to get the calling convention in the right spot.
|
|
|
|
Printer << " (";
|
[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
|
|
|
PDB_CallingConv CC = FuncSig->getCallingConvention();
|
2017-04-10 18:43:09 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << CC << " ";
|
[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
|
|
|
} else if (isa<PDBSymbolTypeArray>(PointeeType)) {
|
2017-04-10 18:43:09 +02:00
|
|
|
Printer << " (";
|
|
|
|
}
|
|
|
|
Printer << (Symbol.isReference() ? "&" : "*");
|
|
|
|
if (Symbol.isConstType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " const ";
|
|
|
|
if (Symbol.isVolatileType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " volatile ";
|
|
|
|
}
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2017-04-10 18:43:09 +02:00
|
|
|
void VariableDumper::dumpRight(const PDBSymbolTypePointer &Symbol) {
|
|
|
|
auto PointeeType = Symbol.getPointeeType();
|
|
|
|
assert(PointeeType);
|
|
|
|
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 (isa<PDBSymbolTypeFunctionSig>(PointeeType) ||
|
|
|
|
isa<PDBSymbolTypeArray>(PointeeType)) {
|
2017-04-10 18:43:09 +02:00
|
|
|
Printer << ")";
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|
2017-04-10 18:43:09 +02:00
|
|
|
PointeeType->dumpRight(*this);
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeUDT &Symbol) {
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type,
|
2015-03-01 07:51:29 +01:00
|
|
|
StringRef Name) {
|
2017-04-10 18:43:09 +02:00
|
|
|
Type.dump(*this);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name;
|
|
|
|
Type.dumpRight(*this);
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|