2017-01-11 08:35:43 +08:00
|
|
|
//===- PrettyVariableDumper.cpp ---------------------------------*- C++ -*-===//
|
2015-02-23 13:58:34 +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 13:58:34 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "PrettyVariableDumper.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2015-02-27 17:15:59 +08:00
|
|
|
#include "LinePrinter.h"
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "PrettyBuiltinDumper.h"
|
|
|
|
#include "PrettyFunctionDumper.h"
|
2017-06-10 04:46:17 +08:00
|
|
|
#include "llvm-pdbutil.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2017-04-11 00:43:09 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/IPDBSession.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
|
2015-03-04 14:09:53 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
2017-01-11 08:35:43 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
|
2015-02-27 07:49:23 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
|
2017-04-11 00:43:09 +08:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBTypes.h"
|
2015-02-23 13:58:34 +08:00
|
|
|
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2017-04-11 00:43:09 +08:00
|
|
|
using namespace llvm::codeview;
|
2016-05-05 04:32:13 +08:00
|
|
|
using namespace llvm::pdb;
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2015-02-27 17:15:59 +08:00
|
|
|
VariableDumper::VariableDumper(LinePrinter &P)
|
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2017-04-14 05:11:00 +08:00
|
|
|
void VariableDumper::start(const PDBSymbolData &Var, uint32_t Offset) {
|
2016-07-01 01:42:48 +08:00
|
|
|
if (Var.isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
|
2015-03-02 12:39:56 +08:00
|
|
|
return;
|
2015-03-01 14:49:49 +08:00
|
|
|
if (Printer.IsSymbolExcluded(Var.getName()))
|
|
|
|
return;
|
|
|
|
|
2015-02-23 13:58:34 +08:00
|
|
|
auto VarType = Var.getType();
|
|
|
|
|
2017-04-11 03:33:29 +08:00
|
|
|
uint64_t Length = VarType->getRawSymbol().getLength();
|
|
|
|
|
2015-02-23 13:58:34 +08:00
|
|
|
switch (auto LocType = Var.getLocationType()) {
|
|
|
|
case PDB_LocType::Static:
|
2015-03-04 14:09:53 +08:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data [";
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Address).get()
|
2015-05-02 04:24:26 +08:00
|
|
|
<< format_hex(Var.getVirtualAddress(), 10);
|
2017-04-11 03:33:29 +08:00
|
|
|
Printer << ", sizeof=" << Length << "] ";
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "static ";
|
2015-03-01 14:51:29 +08:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-02-23 13:58:34 +08:00
|
|
|
break;
|
|
|
|
case PDB_LocType::Constant:
|
2015-03-04 14:09:53 +08:00
|
|
|
if (isa<PDBSymbolTypeEnum>(*VarType))
|
|
|
|
break;
|
|
|
|
Printer.NewLine();
|
2017-04-11 03:33:29 +08:00
|
|
|
Printer << "data [sizeof=" << Length << "] ";
|
2015-03-01 14:51:29 +08:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-03-02 12:39:56 +08:00
|
|
|
Printer << " = ";
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getValue();
|
2015-02-23 13:58:34 +08:00
|
|
|
break;
|
2015-02-23 19:33:54 +08:00
|
|
|
case PDB_LocType::ThisRel:
|
2015-03-04 14:09:53 +08:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-14 05:11:00 +08:00
|
|
|
<< "+" << format_hex(Offset + Var.getOffset(), 4)
|
|
|
|
<< " [sizeof=" << Length << "] ";
|
2015-03-01 14:51:29 +08:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
2015-02-23 13:58:34 +08:00
|
|
|
break;
|
2015-03-02 12:39:56 +08:00
|
|
|
case PDB_LocType::BitField:
|
2015-03-04 14:09:53 +08:00
|
|
|
Printer.NewLine();
|
|
|
|
Printer << "data ";
|
2015-03-02 12:39:56 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-14 05:11:00 +08:00
|
|
|
<< "+" << format_hex(Offset + Var.getOffset(), 4)
|
|
|
|
<< " [sizeof=" << Length << "] ";
|
2015-03-02 12:39:56 +08:00
|
|
|
dumpSymbolTypeAndName(*VarType, Var.getName());
|
|
|
|
Printer << " : ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getLength();
|
|
|
|
break;
|
2015-02-23 13:58:34 +08:00
|
|
|
default:
|
2015-03-04 14:09:53 +08:00
|
|
|
Printer.NewLine();
|
2017-04-11 03:33:29 +08:00
|
|
|
Printer << "data [sizeof=" << Length << "] ";
|
2015-03-01 14:51:29 +08:00
|
|
|
Printer << "unknown(" << LocType << ") ";
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Var.getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 01:47:24 +08: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-14 05:11:00 +08: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 07:18:21 +08:00
|
|
|
Printer.NewLine();
|
2017-04-14 05:11:00 +08: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 07:18:21 +08:00
|
|
|
auto VTableType = cast<PDBSymbolTypePointer>(Var.getType());
|
|
|
|
uint32_t PointerSize = VTableType->getLength();
|
|
|
|
|
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-14 05:11:00 +08: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 07:18:21 +08:00
|
|
|
}
|
|
|
|
|
2017-04-11 00:43:09 +08: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 14:51:29 +08:00
|
|
|
void VariableDumper::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 13:58:34 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeEnum &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|
|
|
|
|
2017-04-11 00:43:09 +08: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";
|
2018-03-06 02:29:43 +08:00
|
|
|
|
|
|
|
if (Symbol.getRawSymbol().isRestrictedType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict";
|
2017-04-11 00:43:09 +08:00
|
|
|
}
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypePointer &Symbol) {
|
2015-02-23 13:58:34 +08:00
|
|
|
auto PointeeType = Symbol.getPointeeType();
|
|
|
|
if (!PointeeType)
|
|
|
|
return;
|
2017-04-11 00:43:09 +08: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 07:18:21 +08:00
|
|
|
if (auto FuncSig = unique_dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType)) {
|
2017-04-11 00:43:09 +08: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 07:18:21 +08:00
|
|
|
PDB_CallingConv CC = FuncSig->getCallingConvention();
|
2017-04-11 00:43:09 +08: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 07:18:21 +08:00
|
|
|
} else if (isa<PDBSymbolTypeArray>(PointeeType)) {
|
2017-04-11 00:43:09 +08: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 ";
|
2018-03-06 02:29:43 +08:00
|
|
|
|
|
|
|
if (Symbol.getRawSymbol().isRestrictedType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << " __restrict ";
|
2017-04-11 00:43:09 +08:00
|
|
|
}
|
2015-02-23 13:58:34 +08:00
|
|
|
|
2017-04-11 00:43:09 +08: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 07:18:21 +08:00
|
|
|
if (isa<PDBSymbolTypeFunctionSig>(PointeeType) ||
|
|
|
|
isa<PDBSymbolTypeArray>(PointeeType)) {
|
2017-04-11 00:43:09 +08:00
|
|
|
Printer << ")";
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|
2017-04-11 00:43:09 +08:00
|
|
|
PointeeType->dumpRight(*this);
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
|
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|
|
|
|
|
2015-03-01 14:51:29 +08:00
|
|
|
void VariableDumper::dump(const PDBSymbolTypeUDT &Symbol) {
|
2015-02-27 17:15:59 +08:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type,
|
2015-03-01 14:51:29 +08:00
|
|
|
StringRef Name) {
|
2017-04-11 00:43:09 +08:00
|
|
|
Type.dump(*this);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name;
|
|
|
|
Type.dumpRight(*this);
|
2015-02-23 13:58:34 +08:00
|
|
|
}
|