From 1690164cac96cf3670f380a74b27443c71b6a32e Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 24 Apr 2017 17:47:24 +0000 Subject: [llvm-pdbdump] Re-write the record layout code to be more resilient. This reworks the way virtual bases are handled, and also the way padding is detected across multiple levels of aggregates, producing a much more accurate result. llvm-svn: 301203 --- .../llvm-pdbdump/PrettyClassDefinitionDumper.cpp | 41 ++++++++-------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp') diff --git a/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp b/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp index 9f213a4b4d9..81ef26167a2 100644 --- a/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp +++ b/llvm/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp @@ -58,25 +58,11 @@ void ClassDefinitionDumper::start(const ClassLayout &Layout) { prettyPrintClassOutro(Layout); } -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(); - uint32_t Size = Layout.getClassSize(); + uint32_t Size = Layout.getSize(); const PDBSymbolTypeUDT &Class = Layout.getClass(); WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " "; @@ -84,19 +70,22 @@ void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) { 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) { + if (BaseCount > 0) { Printer.Indent(); - Printer.NewLine(); - Printer << ":"; - uint32_t BaseIndex = 0; + char NextSeparator = ':'; 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); + if (Base.isIndirectVirtualBaseClass()) + continue; + + Printer.NewLine(); + Printer << NextSeparator << " "; + WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess(); + if (BC->isVirtualBase()) + WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual"; + + WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName(); + NextSeparator = ','; } Printer.Unindent(); @@ -114,7 +103,7 @@ void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) { Printer.NewLine(); if (Layout.deepPaddingSize() > 0) { APFloat Pct(100.0 * (double)Layout.deepPaddingSize() / - (double)Layout.getClassSize()); + (double)Layout.getSize()); SmallString<8> PctStr; Pct.toString(PctStr, 4); WithColor(Printer, PDB_ColorItem::Padding).get() -- cgit v1.2.3