diff options
Diffstat (limited to 'contrib/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp')
-rw-r--r-- | contrib/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp | 229 |
1 files changed, 81 insertions, 148 deletions
diff --git a/contrib/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp b/contrib/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp index b0c534f7c5b1..9f213a4b4d96 100644 --- a/contrib/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp +++ b/contrib/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp @@ -10,22 +10,16 @@ #include "PrettyClassDefinitionDumper.h" #include "LinePrinter.h" -#include "PrettyEnumDumper.h" -#include "PrettyFunctionDumper.h" -#include "PrettyTypedefDumper.h" -#include "PrettyVariableDumper.h" +#include "PrettyClassLayoutGraphicalDumper.h" +#include "PrettyClassLayoutTextDumper.h" #include "llvm-pdbdump.h" -#include "llvm/DebugInfo/PDB/IPDBSession.h" -#include "llvm/DebugInfo/PDB/PDBExtras.h" -#include "llvm/DebugInfo/PDB/PDBSymbolData.h" -#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/SmallString.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" -#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h" +#include "llvm/DebugInfo/PDB/UDTLayout.h" + #include "llvm/Support/Format.h" using namespace llvm; @@ -35,158 +29,97 @@ ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {} void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) { - std::string Name = Class.getName(); - WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " "; - WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName(); - - auto Bases = Class.findAllChildren<PDBSymbolTypeBaseClass>(); - if (Bases->getChildCount() > 0) { - Printer.Indent(); - Printer.NewLine(); - Printer << ":"; - uint32_t BaseIndex = 0; - while (auto Base = Bases->getNext()) { - Printer << " "; - WithColor(Printer, PDB_ColorItem::Keyword).get() << Base->getAccess(); - if (Base->isVirtualBaseClass()) - WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual"; - WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base->getName(); - if (++BaseIndex < Bases->getChildCount()) { - Printer.NewLine(); - Printer << ","; - } - } - Printer.Unindent(); - } - - Printer << " {"; - auto Children = Class.findAllChildren(); - if (Children->getChildCount() == 0) { - Printer << "}"; - return; - } + assert(opts::pretty::ClassFormat != + opts::pretty::ClassDefinitionFormat::None); - // Try to dump symbols organized by member access level. Public members - // first, then protected, then private. This might be slow, so it's worth - // reconsidering the value of this if performance of large PDBs is a problem. - // NOTE: Access level of nested types is not recorded in the PDB, so we have - // a special case for them. - SymbolGroupByAccess Groups; - Groups.insert(std::make_pair(0, SymbolGroup())); - Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup())); - Groups.insert( - std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup())); - Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup())); - - while (auto Child = Children->getNext()) { - PDB_MemberAccess Access = Child->getRawSymbol().getAccess(); - if (isa<PDBSymbolTypeBaseClass>(*Child)) - continue; - - auto &AccessGroup = Groups.find((int)Access)->second; - - if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) { - if (Func->isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated) - continue; - if (Func->getLength() == 0 && !Func->isPureVirtual() && - !Func->isIntroVirtualFunction()) - continue; - Child.release(); - AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func)); - } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) { - Child.release(); - AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data)); - } else { - AccessGroup.Unknown.push_back(std::move(Child)); - } - } - - int Count = 0; - Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0]); - Count += dumpAccessGroup(PDB_MemberAccess::Public, - Groups[(int)PDB_MemberAccess::Public]); - Count += dumpAccessGroup(PDB_MemberAccess::Protected, - Groups[(int)PDB_MemberAccess::Protected]); - Count += dumpAccessGroup(PDB_MemberAccess::Private, - Groups[(int)PDB_MemberAccess::Private]); - if (Count > 0) - Printer.NewLine(); - Printer << "}"; + ClassLayout Layout(Class); + start(Layout); } -int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access, - const SymbolGroup &Group) { - if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty()) - return 0; +void ClassDefinitionDumper::start(const ClassLayout &Layout) { + prettyPrintClassIntro(Layout); - int Count = 0; - if (Access == PDB_MemberAccess::Private) { - Printer.NewLine(); - WithColor(Printer, PDB_ColorItem::Keyword).get() << "private"; - Printer << ":"; - } else if (Access == PDB_MemberAccess::Protected) { - Printer.NewLine(); - WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected"; - Printer << ":"; - } else if (Access == PDB_MemberAccess::Public) { - Printer.NewLine(); - WithColor(Printer, PDB_ColorItem::Keyword).get() << "public"; - Printer << ":"; + switch (opts::pretty::ClassFormat) { + case opts::pretty::ClassDefinitionFormat::Graphical: { + PrettyClassLayoutGraphicalDumper Dumper(Printer, 0); + DumpedAnything = Dumper.start(Layout); + break; } - Printer.Indent(); - for (auto iter = Group.Functions.begin(), end = Group.Functions.end(); - iter != end; ++iter) { - ++Count; - (*iter)->dump(*this); - } - for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end; - ++iter) { - ++Count; - (*iter)->dump(*this); + case opts::pretty::ClassDefinitionFormat::Standard: + case opts::pretty::ClassDefinitionFormat::Layout: { + PrettyClassLayoutTextDumper Dumper(Printer); + DumpedAnything |= Dumper.start(Layout); + break; } - for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end(); - iter != end; ++iter) { - ++Count; - (*iter)->dump(*this); + default: + llvm_unreachable("Unreachable!"); } - Printer.Unindent(); - return Count; -} - -void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {} -void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) { - VariableDumper Dumper(Printer); - Dumper.start(Symbol); + prettyPrintClassOutro(Layout); } -void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) { - if (Printer.IsSymbolExcluded(Symbol.getName())) - return; +static void printBase(LinePrinter &Printer, const PDBSymbolTypeBaseClass &Base, + uint32_t &CurIndex, uint32_t TotalBaseCount, + bool IsVirtual) { + Printer << " "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess(); + if (IsVirtual) + WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual"; + WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName(); + if (++CurIndex < TotalBaseCount) { + Printer.NewLine(); + Printer << ","; + } +} +void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) { + DumpedAnything = false; Printer.NewLine(); - FunctionDumper Dumper(Printer); - Dumper.start(Symbol, FunctionDumper::PointerType::None); -} -void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {} + uint32_t Size = Layout.getClassSize(); + const PDBSymbolTypeUDT &Class = Layout.getClass(); -void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) { - if (Printer.IsTypeExcluded(Symbol.getName())) - return; + WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " "; + WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName(); + WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size + << "]"; + uint32_t BaseCount = Layout.bases().size(); + uint32_t VBaseCount = Layout.vbases().size(); + uint32_t TotalBaseCount = BaseCount + VBaseCount; + if (TotalBaseCount > 0) { + Printer.Indent(); + Printer.NewLine(); + Printer << ":"; + uint32_t BaseIndex = 0; + for (auto BC : Layout.bases()) { + const auto &Base = BC->getBase(); + printBase(Printer, Base, BaseIndex, TotalBaseCount, false); + } + for (auto &BC : Layout.vbases()) { + printBase(Printer, *BC, BaseIndex, TotalBaseCount, true); + } - Printer.NewLine(); - EnumDumper Dumper(Printer); - Dumper.start(Symbol); -} + Printer.Unindent(); + } -void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) { - if (Printer.IsTypeExcluded(Symbol.getName())) - return; + Printer << " {"; + Printer.Indent(); +} +void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) { + Printer.Unindent(); + if (DumpedAnything) + Printer.NewLine(); + Printer << "}"; Printer.NewLine(); - TypedefDumper Dumper(Printer); - Dumper.start(Symbol); + if (Layout.deepPaddingSize() > 0) { + APFloat Pct(100.0 * (double)Layout.deepPaddingSize() / + (double)Layout.getClassSize()); + SmallString<8> PctStr; + Pct.toString(PctStr, 4); + WithColor(Printer, PDB_ColorItem::Padding).get() + << "Total padding " << Layout.deepPaddingSize() << " bytes (" << PctStr + << "% of class size)"; + Printer.NewLine(); + } } - -void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {} |