llvm/tools/llvm-pdbdump/PrettyTypeDumper.cpp
Zachary Turner e98c913509 [llvm-pdbdump] Display padding bytes on record layout
When dumping classes, show where padding occurs, and at the end of the
class print statistics about how many bytes total of padding exist in a
class.

Since PDB doesn't specifically contain information about padding, we have
to mimic this by sort of reversing a small portion of the record layout
algorithm (e.g. looking at offsets and sizes and trying to determine
whether something is part of the same field or a new field).

Differential Revision: https://reviews.llvm.org/D31800

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299869 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-10 19:33:29 +00:00

108 lines
3.2 KiB
C++

//===- PrettyTypeDumper.cpp - PDBSymDumper type dumper *------------ C++ *-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PrettyTypeDumper.h"
#include "LinePrinter.h"
#include "PrettyBuiltinDumper.h"
#include "PrettyClassDefinitionDumper.h"
#include "PrettyEnumDumper.h"
#include "PrettyTypedefDumper.h"
#include "llvm-pdbdump.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
using namespace llvm;
using namespace llvm::pdb;
TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
void TypeDumper::start(const PDBSymbolExe &Exe) {
if (opts::pretty::Enums) {
auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
Printer << ": (" << Enums->getChildCount() << " items)";
Printer.Indent();
while (auto Enum = Enums->getNext())
Enum->dump(*this);
Printer.Unindent();
}
if (opts::pretty::Typedefs) {
auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
Printer << ": (" << Typedefs->getChildCount() << " items)";
Printer.Indent();
while (auto Typedef = Typedefs->getNext())
Typedef->dump(*this);
Printer.Unindent();
}
if (opts::pretty::Classes) {
auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
Printer << ": (" << Classes->getChildCount() << " items)";
Printer.Indent();
while (auto Class = Classes->getNext())
Class->dump(*this);
Printer.Unindent();
}
}
void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol) {
assert(opts::pretty::Enums);
if (Printer.IsTypeExcluded(Symbol.getName()))
return;
// Dump member enums when dumping their class definition.
if (nullptr != Symbol.getClassParent())
return;
Printer.NewLine();
EnumDumper Dumper(Printer);
Dumper.start(Symbol);
}
void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
assert(opts::pretty::Typedefs);
if (Printer.IsTypeExcluded(Symbol.getName()))
return;
Printer.NewLine();
TypedefDumper Dumper(Printer);
Dumper.start(Symbol);
}
void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol) {
assert(opts::pretty::Classes);
if (Symbol.getUnmodifiedTypeId() != 0)
return;
if (Printer.IsTypeExcluded(Symbol.getName()))
return;
if (opts::pretty::ClassFormat == opts::pretty::ClassDefinitionFormat::None) {
Printer.NewLine();
WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
} else {
ClassDefinitionDumper Dumper(Printer);
Dumper.start(Symbol);
}
}