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