[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / tools / llvm-pdbutil / PrettyClassDefinitionDumper.cpp
blobb7eccac5988caa4aded952d16427ae35a2f466c3
1 //===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "PrettyClassDefinitionDumper.h"
11 #include "LinePrinter.h"
12 #include "PrettyClassLayoutGraphicalDumper.h"
13 #include "llvm-pdbutil.h"
15 #include "llvm/ADT/APFloat.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
19 #include "llvm/DebugInfo/PDB/UDTLayout.h"
21 #include "llvm/Support/Format.h"
23 using namespace llvm;
24 using namespace llvm::pdb;
26 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
27 : PDBSymDumper(true), Printer(P) {}
29 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
30 assert(opts::pretty::ClassFormat !=
31 opts::pretty::ClassDefinitionFormat::None);
33 ClassLayout Layout(Class);
34 start(Layout);
37 void ClassDefinitionDumper::start(const ClassLayout &Layout) {
38 prettyPrintClassIntro(Layout);
40 PrettyClassLayoutGraphicalDumper Dumper(Printer, 1, 0);
41 DumpedAnything |= Dumper.start(Layout);
43 prettyPrintClassOutro(Layout);
46 void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) {
47 DumpedAnything = false;
48 Printer.NewLine();
50 uint32_t Size = Layout.getSize();
51 const PDBSymbolTypeUDT &Class = Layout.getClass();
53 if (Layout.getClass().isConstType())
54 WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
55 if (Layout.getClass().isVolatileType())
56 WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
57 if (Layout.getClass().isUnalignedType())
58 WithColor(Printer, PDB_ColorItem::Keyword).get() << "unaligned ";
60 WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
61 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
62 WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size
63 << "]";
64 uint32_t BaseCount = Layout.bases().size();
65 if (BaseCount > 0) {
66 Printer.Indent();
67 char NextSeparator = ':';
68 for (auto BC : Layout.bases()) {
69 const auto &Base = BC->getBase();
70 if (Base.isIndirectVirtualBaseClass())
71 continue;
73 Printer.NewLine();
74 Printer << NextSeparator << " ";
75 WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess();
76 if (BC->isVirtualBase())
77 WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
79 WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName();
80 NextSeparator = ',';
83 Printer.Unindent();
86 Printer << " {";
87 Printer.Indent();
90 void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) {
91 Printer.Unindent();
92 if (DumpedAnything)
93 Printer.NewLine();
94 Printer << "}";
95 Printer.NewLine();
96 if (Layout.deepPaddingSize() > 0) {
97 APFloat Pct(100.0 * (double)Layout.deepPaddingSize() /
98 (double)Layout.getSize());
99 SmallString<8> PctStr;
100 Pct.toString(PctStr, 4);
101 WithColor(Printer, PDB_ColorItem::Padding).get()
102 << "Total padding " << Layout.deepPaddingSize() << " bytes (" << PctStr
103 << "% of class size)";
104 Printer.NewLine();
105 APFloat Pct2(100.0 * (double)Layout.immediatePadding() /
106 (double)Layout.getSize());
107 PctStr.clear();
108 Pct2.toString(PctStr, 4);
109 WithColor(Printer, PDB_ColorItem::Padding).get()
110 << "Immediate padding " << Layout.immediatePadding() << " bytes ("
111 << PctStr << "% of class size)";
112 Printer.NewLine();