2017-01-11 01:35:43 +01:00
|
|
|
//===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//
|
2015-02-23 06:58:34 +01:00
|
|
|
//
|
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
|
2015-02-23 06:58:34 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-11 01:35:43 +01:00
|
|
|
#include "PrettyClassDefinitionDumper.h"
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
#include "LinePrinter.h"
|
2017-04-13 01:18:51 +02:00
|
|
|
#include "PrettyClassLayoutGraphicalDumper.h"
|
2017-06-09 22:46:17 +02:00
|
|
|
#include "llvm-pdbutil.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2017-04-10 21:33:29 +02:00
|
|
|
#include "llvm/ADT/APFloat.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
|
|
|
|
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
|
[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 01:18:21 +02:00
|
|
|
#include "llvm/DebugInfo/PDB/UDTLayout.h"
|
|
|
|
|
2015-02-23 06:58:34 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2016-05-04 22:32:13 +02:00
|
|
|
using namespace llvm::pdb;
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
|
|
|
|
: PDBSymDumper(true), Printer(P) {}
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2015-03-01 07:51:29 +01:00
|
|
|
void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
|
2017-04-07 01:43:39 +02:00
|
|
|
assert(opts::pretty::ClassFormat !=
|
|
|
|
opts::pretty::ClassDefinitionFormat::None);
|
|
|
|
|
2017-04-13 01:18:51 +02:00
|
|
|
ClassLayout Layout(Class);
|
2017-04-13 23:11:00 +02:00
|
|
|
start(Layout);
|
|
|
|
}
|
[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 01:18:21 +02:00
|
|
|
|
2017-04-13 23:11:00 +02:00
|
|
|
void ClassDefinitionDumper::start(const ClassLayout &Layout) {
|
2017-04-13 01:18:51 +02:00
|
|
|
prettyPrintClassIntro(Layout);
|
|
|
|
|
2017-04-24 19:47:52 +02:00
|
|
|
PrettyClassLayoutGraphicalDumper Dumper(Printer, 1, 0);
|
|
|
|
DumpedAnything |= Dumper.start(Layout);
|
2017-04-13 01:18:51 +02:00
|
|
|
|
|
|
|
prettyPrintClassOutro(Layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) {
|
|
|
|
DumpedAnything = false;
|
2017-04-10 21:33:29 +02:00
|
|
|
Printer.NewLine();
|
|
|
|
|
2017-04-24 19:47:24 +02:00
|
|
|
uint32_t Size = Layout.getSize();
|
2017-04-13 01:18:51 +02:00
|
|
|
const PDBSymbolTypeUDT &Class = Layout.getClass();
|
|
|
|
|
2018-09-15 00:29:19 +02:00
|
|
|
if (Layout.getClass().isConstType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
|
|
|
|
if (Layout.getClass().isVolatileType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
|
|
|
|
if (Layout.getClass().isUnalignedType())
|
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
|
|
|
|
|
2015-03-02 05:39:56 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
|
[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 01:18:21 +02:00
|
|
|
WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size
|
|
|
|
<< "]";
|
2017-04-13 23:11:00 +02:00
|
|
|
uint32_t BaseCount = Layout.bases().size();
|
2017-04-24 19:47:24 +02:00
|
|
|
if (BaseCount > 0) {
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer.Indent();
|
2017-04-24 19:47:24 +02:00
|
|
|
char NextSeparator = ':';
|
2017-04-13 23:11:00 +02:00
|
|
|
for (auto BC : Layout.bases()) {
|
2017-04-13 01:18:51 +02:00
|
|
|
const auto &Base = BC->getBase();
|
2017-04-24 19:47:24 +02:00
|
|
|
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 = ',';
|
2017-04-13 23:11:00 +02:00
|
|
|
}
|
|
|
|
|
2015-03-02 05:39:56 +01:00
|
|
|
Printer.Unindent();
|
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer << " {";
|
2017-04-07 01:43:39 +02:00
|
|
|
Printer.Indent();
|
2017-04-13 01:18:51 +02:00
|
|
|
}
|
2015-02-23 06:58:34 +01:00
|
|
|
|
2017-04-13 01:18:51 +02:00
|
|
|
void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) {
|
2017-04-07 01:43:39 +02:00
|
|
|
Printer.Unindent();
|
[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 01:18:21 +02:00
|
|
|
if (DumpedAnything)
|
2015-02-27 10:15:59 +01:00
|
|
|
Printer.NewLine();
|
2015-03-01 07:51:29 +01:00
|
|
|
Printer << "}";
|
2017-04-10 21:33:29 +02:00
|
|
|
Printer.NewLine();
|
[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 01:18:21 +02:00
|
|
|
if (Layout.deepPaddingSize() > 0) {
|
2017-04-13 01:18:51 +02:00
|
|
|
APFloat Pct(100.0 * (double)Layout.deepPaddingSize() /
|
2017-04-24 19:47:24 +02:00
|
|
|
(double)Layout.getSize());
|
2017-04-10 21:33:29 +02:00
|
|
|
SmallString<8> PctStr;
|
|
|
|
Pct.toString(PctStr, 4);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Padding).get()
|
[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 01:18:21 +02:00
|
|
|
<< "Total padding " << Layout.deepPaddingSize() << " bytes (" << PctStr
|
2017-04-10 21:33:29 +02:00
|
|
|
<< "% of class size)";
|
|
|
|
Printer.NewLine();
|
2017-04-25 22:22:29 +02:00
|
|
|
APFloat Pct2(100.0 * (double)Layout.immediatePadding() /
|
|
|
|
(double)Layout.getSize());
|
|
|
|
PctStr.clear();
|
|
|
|
Pct2.toString(PctStr, 4);
|
|
|
|
WithColor(Printer, PDB_ColorItem::Padding).get()
|
|
|
|
<< "Immediate padding " << Layout.immediatePadding() << " bytes ("
|
|
|
|
<< PctStr << "% of class size)";
|
|
|
|
Printer.NewLine();
|
2017-04-10 21:33:29 +02:00
|
|
|
}
|
2015-02-23 06:58:34 +01:00
|
|
|
}
|