annotate tools/llvm-pdbutil/PrettyClassDefinitionDumper.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #include "PrettyClassDefinitionDumper.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "LinePrinter.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "PrettyClassLayoutGraphicalDumper.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm-pdbutil.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/ADT/APFloat.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/ADT/SmallString.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include "llvm/DebugInfo/PDB/UDTLayout.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 #include "llvm/Support/Format.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 using namespace llvm::pdb;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 : PDBSymDumper(true), Printer(P) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 assert(opts::pretty::ClassFormat !=
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 opts::pretty::ClassDefinitionFormat::None);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 ClassLayout Layout(Class);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 start(Layout);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 void ClassDefinitionDumper::start(const ClassLayout &Layout) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 prettyPrintClassIntro(Layout);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 PrettyClassLayoutGraphicalDumper Dumper(Printer, 1, 0);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 DumpedAnything |= Dumper.start(Layout);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 prettyPrintClassOutro(Layout);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 void ClassDefinitionDumper::prettyPrintClassIntro(const ClassLayout &Layout) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 DumpedAnything = false;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 uint32_t Size = Layout.getSize();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 const PDBSymbolTypeUDT &Class = Layout.getClass();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 WithColor(Printer, PDB_ColorItem::Comment).get() << " [sizeof = " << Size
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 << "]";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 uint32_t BaseCount = Layout.bases().size();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 if (BaseCount > 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 Printer.Indent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 char NextSeparator = ':';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 for (auto BC : Layout.bases()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 const auto &Base = BC->getBase();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 if (Base.isIndirectVirtualBaseClass())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 Printer << NextSeparator << " ";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 WithColor(Printer, PDB_ColorItem::Keyword).get() << Base.getAccess();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 if (BC->isVirtualBase())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base.getName();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 NextSeparator = ',';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 Printer.Unindent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 Printer << " {";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 Printer.Indent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 void ClassDefinitionDumper::prettyPrintClassOutro(const ClassLayout &Layout) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 Printer.Unindent();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 if (DumpedAnything)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 Printer << "}";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 if (Layout.deepPaddingSize() > 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 APFloat Pct(100.0 * (double)Layout.deepPaddingSize() /
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 (double)Layout.getSize());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 SmallString<8> PctStr;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 Pct.toString(PctStr, 4);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 WithColor(Printer, PDB_ColorItem::Padding).get()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 << "Total padding " << Layout.deepPaddingSize() << " bytes (" << PctStr
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 << "% of class size)";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 APFloat Pct2(100.0 * (double)Layout.immediatePadding() /
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 (double)Layout.getSize());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 PctStr.clear();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 Pct2.toString(PctStr, 4);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 WithColor(Printer, PDB_ColorItem::Padding).get()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 << "Immediate padding " << Layout.immediatePadding() << " bytes ("
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 << PctStr << "% of class size)";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 Printer.NewLine();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 }