2017-04-13 01:18:51 +02:00
|
|
|
//===- PrettyClassLayoutGraphicalDumper.h -----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01: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
|
2017-04-13 01:18:51 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "PrettyClassLayoutGraphicalDumper.h"
|
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
#include "LinePrinter.h"
|
|
|
|
#include "PrettyClassDefinitionDumper.h"
|
2017-04-24 19:47:52 +02:00
|
|
|
#include "PrettyEnumDumper.h"
|
|
|
|
#include "PrettyFunctionDumper.h"
|
|
|
|
#include "PrettyTypedefDumper.h"
|
2017-04-13 23:11:00 +02:00
|
|
|
#include "PrettyVariableDumper.h"
|
2017-04-24 19:47:52 +02:00
|
|
|
#include "PrettyVariableDumper.h"
|
2017-06-09 22:46:17 +02:00
|
|
|
#include "llvm-pdbutil.h"
|
2017-04-13 23:11:00 +02:00
|
|
|
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/UDTLayout.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
2017-04-13 01:18:51 +02:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::pdb;
|
|
|
|
|
|
|
|
PrettyClassLayoutGraphicalDumper::PrettyClassLayoutGraphicalDumper(
|
2017-04-24 19:47:52 +02:00
|
|
|
LinePrinter &P, uint32_t RecurseLevel, uint32_t InitialOffset)
|
|
|
|
: PDBSymDumper(true), Printer(P), RecursionLevel(RecurseLevel),
|
|
|
|
ClassOffsetZero(InitialOffset), CurrentAbsoluteOffset(InitialOffset) {}
|
2017-04-13 23:11:00 +02:00
|
|
|
|
|
|
|
bool PrettyClassLayoutGraphicalDumper::start(const UDTLayoutBase &Layout) {
|
2017-04-24 19:47:52 +02:00
|
|
|
|
|
|
|
if (RecursionLevel == 1 &&
|
|
|
|
opts::pretty::ClassFormat == opts::pretty::ClassDefinitionFormat::All) {
|
|
|
|
for (auto &Other : Layout.other_items())
|
|
|
|
Other->dump(*this);
|
|
|
|
for (auto &Func : Layout.funcs())
|
|
|
|
Func->dump(*this);
|
|
|
|
}
|
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
const BitVector &UseMap = Layout.usedBytes();
|
|
|
|
int NextPaddingByte = UseMap.find_first_unset();
|
|
|
|
|
|
|
|
for (auto &Item : Layout.layout_items()) {
|
|
|
|
// Calculate the absolute offset of the first byte of the next field.
|
|
|
|
uint32_t RelativeOffset = Item->getOffsetInParent();
|
|
|
|
CurrentAbsoluteOffset = ClassOffsetZero + RelativeOffset;
|
|
|
|
|
2018-04-16 19:01:18 +02:00
|
|
|
// This might be an empty base, in which case it could extend outside the
|
|
|
|
// bounds of the parent class.
|
2017-04-13 23:11:00 +02:00
|
|
|
if (RelativeOffset < UseMap.size() && (Item->getSize() > 0)) {
|
|
|
|
// If there is any remaining padding in this class, and the offset of the
|
|
|
|
// new item is after the padding, then we must have just jumped over some
|
|
|
|
// padding. Print a padding row and then look for where the next block
|
|
|
|
// of padding begins.
|
|
|
|
if ((NextPaddingByte >= 0) &&
|
|
|
|
(RelativeOffset > uint32_t(NextPaddingByte))) {
|
|
|
|
printPaddingRow(RelativeOffset - NextPaddingByte);
|
|
|
|
NextPaddingByte = UseMap.find_next_unset(RelativeOffset);
|
|
|
|
}
|
|
|
|
}
|
2017-04-13 01:18:51 +02:00
|
|
|
|
2017-04-24 19:47:24 +02:00
|
|
|
CurrentItem = Item;
|
|
|
|
if (Item->isVBPtr()) {
|
|
|
|
VTableLayoutItem &Layout = static_cast<VTableLayoutItem &>(*CurrentItem);
|
|
|
|
|
|
|
|
VariableDumper VarDumper(Printer);
|
|
|
|
VarDumper.startVbptr(CurrentAbsoluteOffset, Layout.getSize());
|
|
|
|
} else {
|
|
|
|
if (auto Sym = Item->getSymbol())
|
|
|
|
Sym->dump(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Item->getLayoutSize() > 0) {
|
|
|
|
uint32_t Prev = RelativeOffset + Item->getLayoutSize() - 1;
|
2017-05-26 02:15:15 +02:00
|
|
|
if (Prev < UseMap.size())
|
|
|
|
NextPaddingByte = UseMap.find_next_unset(Prev);
|
2017-04-24 19:47:24 +02:00
|
|
|
}
|
2017-04-13 23:11:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-24 19:47:24 +02:00
|
|
|
auto TailPadding = Layout.tailPadding();
|
|
|
|
if (TailPadding > 0) {
|
2017-04-24 19:47:52 +02:00
|
|
|
if (TailPadding != 1 || Layout.getSize() != 1) {
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Padding).get()
|
|
|
|
<< "<padding> (" << TailPadding << " bytes)";
|
|
|
|
DumpedAnything = true;
|
|
|
|
}
|
2017-04-13 23:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return DumpedAnything;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::printPaddingRow(uint32_t Amount) {
|
|
|
|
if (Amount == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Printer.NewLine();
|
|
|
|
WithColor(Printer, PDB_ColorItem::Padding).get() << "<padding> (" << Amount
|
|
|
|
<< " bytes)";
|
|
|
|
DumpedAnything = true;
|
2017-04-13 01:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(
|
2017-04-13 23:11:00 +02:00
|
|
|
const PDBSymbolTypeBaseClass &Symbol) {
|
|
|
|
assert(CurrentItem != nullptr);
|
2017-04-13 01:18:51 +02:00
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
Printer.NewLine();
|
|
|
|
BaseClassLayout &Layout = static_cast<BaseClassLayout &>(*CurrentItem);
|
2017-04-13 01:18:51 +02:00
|
|
|
|
2017-04-24 19:47:24 +02:00
|
|
|
std::string Label = "base";
|
|
|
|
if (Layout.isVirtualBase()) {
|
|
|
|
Label.insert(Label.begin(), 'v');
|
|
|
|
if (Layout.getBase().isIndirectVirtualBaseClass())
|
|
|
|
Label.insert(Label.begin(), 'i');
|
|
|
|
}
|
2017-04-13 23:11:00 +02:00
|
|
|
Printer << Label << " ";
|
2017-04-13 01:18:51 +02:00
|
|
|
|
2017-04-24 19:47:24 +02:00
|
|
|
uint32_t Size = Layout.isEmptyBase() ? 1 : Layout.getLayoutSize();
|
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Offset).get()
|
2017-04-24 19:47:24 +02:00
|
|
|
<< "+" << format_hex(CurrentAbsoluteOffset, 4) << " [sizeof=" << Size
|
|
|
|
<< "] ";
|
2017-04-13 01:18:51 +02:00
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Identifier).get() << Layout.getName();
|
2017-04-13 01:18:51 +02:00
|
|
|
|
2017-04-24 19:47:52 +02:00
|
|
|
if (shouldRecurse()) {
|
|
|
|
Printer.Indent();
|
|
|
|
uint32_t ChildOffsetZero = ClassOffsetZero + Layout.getOffsetInParent();
|
|
|
|
PrettyClassLayoutGraphicalDumper BaseDumper(Printer, RecursionLevel + 1,
|
|
|
|
ChildOffsetZero);
|
|
|
|
DumpedAnything |= BaseDumper.start(Layout);
|
|
|
|
Printer.Unindent();
|
|
|
|
}
|
2017-04-13 23:11:00 +02:00
|
|
|
|
|
|
|
DumpedAnything = true;
|
|
|
|
}
|
|
|
|
|
2017-04-24 19:47:52 +02:00
|
|
|
bool PrettyClassLayoutGraphicalDumper::shouldRecurse() const {
|
|
|
|
uint32_t Limit = opts::pretty::ClassRecursionDepth;
|
|
|
|
if (Limit == 0)
|
|
|
|
return true;
|
|
|
|
return RecursionLevel < Limit;
|
|
|
|
}
|
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(const PDBSymbolData &Symbol) {
|
|
|
|
VariableDumper VarDumper(Printer);
|
|
|
|
VarDumper.start(Symbol, ClassOffsetZero);
|
|
|
|
|
2017-06-12 22:46:35 +02:00
|
|
|
if (CurrentItem != nullptr) {
|
|
|
|
DataMemberLayoutItem &Layout =
|
|
|
|
static_cast<DataMemberLayoutItem &>(*CurrentItem);
|
|
|
|
|
|
|
|
if (Layout.hasUDTLayout() && shouldRecurse()) {
|
|
|
|
uint32_t ChildOffsetZero = ClassOffsetZero + Layout.getOffsetInParent();
|
|
|
|
Printer.Indent();
|
|
|
|
PrettyClassLayoutGraphicalDumper TypeDumper(Printer, RecursionLevel + 1,
|
|
|
|
ChildOffsetZero);
|
|
|
|
TypeDumper.start(Layout.getUDTLayout());
|
|
|
|
Printer.Unindent();
|
|
|
|
}
|
2017-04-13 23:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DumpedAnything = true;
|
|
|
|
}
|
2017-04-13 01:18:51 +02:00
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(const PDBSymbolTypeVTable &Symbol) {
|
2017-04-13 23:11:00 +02:00
|
|
|
assert(CurrentItem != nullptr);
|
|
|
|
|
|
|
|
VariableDumper VarDumper(Printer);
|
|
|
|
VarDumper.start(Symbol, ClassOffsetZero);
|
|
|
|
|
|
|
|
DumpedAnything = true;
|
2017-04-13 01:18:51 +02:00
|
|
|
}
|
2017-04-24 19:47:52 +02:00
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(const PDBSymbolTypeEnum &Symbol) {
|
|
|
|
DumpedAnything = true;
|
|
|
|
Printer.NewLine();
|
|
|
|
EnumDumper Dumper(Printer);
|
|
|
|
Dumper.start(Symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(
|
|
|
|
const PDBSymbolTypeTypedef &Symbol) {
|
|
|
|
DumpedAnything = true;
|
|
|
|
Printer.NewLine();
|
|
|
|
TypedefDumper Dumper(Printer);
|
|
|
|
Dumper.start(Symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(
|
|
|
|
const PDBSymbolTypeBuiltin &Symbol) {}
|
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(const PDBSymbolTypeUDT &Symbol) {}
|
|
|
|
|
|
|
|
void PrettyClassLayoutGraphicalDumper::dump(const PDBSymbolFunc &Symbol) {
|
|
|
|
if (Printer.IsSymbolExcluded(Symbol.getName()))
|
|
|
|
return;
|
|
|
|
if (Symbol.isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
|
|
|
|
return;
|
|
|
|
if (Symbol.getLength() == 0 && !Symbol.isPureVirtual() &&
|
|
|
|
!Symbol.isIntroVirtualFunction())
|
|
|
|
return;
|
|
|
|
|
|
|
|
DumpedAnything = true;
|
|
|
|
Printer.NewLine();
|
|
|
|
FunctionDumper Dumper(Printer);
|
|
|
|
Dumper.start(Symbol, FunctionDumper::PointerType::None);
|
|
|
|
}
|