1 //===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "PrettyClassDefinitionDumper.h"
12 #include "LinePrinter.h"
13 #include "PrettyEnumDumper.h"
14 #include "PrettyFunctionDumper.h"
15 #include "PrettyTypedefDumper.h"
16 #include "PrettyVariableDumper.h"
17 #include "llvm-pdbdump.h"
19 #include "llvm/DebugInfo/PDB/IPDBSession.h"
20 #include "llvm/DebugInfo/PDB/PDBExtras.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
29 #include "llvm/Support/Format.h"
32 using namespace llvm::pdb;
34 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
35 : PDBSymDumper(true), Printer(P) {}
37 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
38 std::string Name = Class.getName();
39 WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
40 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
42 auto Bases = Class.findAllChildren<PDBSymbolTypeBaseClass>();
43 if (Bases->getChildCount() > 0) {
47 uint32_t BaseIndex = 0;
48 while (auto Base = Bases->getNext()) {
50 WithColor(Printer, PDB_ColorItem::Keyword).get() << Base->getAccess();
51 if (Base->isVirtualBaseClass())
52 WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
53 WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base->getName();
54 if (++BaseIndex < Bases->getChildCount()) {
63 auto Children = Class.findAllChildren();
64 if (Children->getChildCount() == 0) {
69 // Try to dump symbols organized by member access level. Public members
70 // first, then protected, then private. This might be slow, so it's worth
71 // reconsidering the value of this if performance of large PDBs is a problem.
72 // NOTE: Access level of nested types is not recorded in the PDB, so we have
73 // a special case for them.
74 SymbolGroupByAccess Groups;
75 Groups.insert(std::make_pair(0, SymbolGroup()));
76 Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
78 std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
79 Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
81 while (auto Child = Children->getNext()) {
82 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
83 if (isa<PDBSymbolTypeBaseClass>(*Child))
86 auto &AccessGroup = Groups.find((int)Access)->second;
88 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
89 if (Func->isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
91 if (Func->getLength() == 0 && !Func->isPureVirtual() &&
92 !Func->isIntroVirtualFunction())
95 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
96 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
98 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
100 AccessGroup.Unknown.push_back(std::move(Child));
105 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0]);
106 Count += dumpAccessGroup(PDB_MemberAccess::Public,
107 Groups[(int)PDB_MemberAccess::Public]);
108 Count += dumpAccessGroup(PDB_MemberAccess::Protected,
109 Groups[(int)PDB_MemberAccess::Protected]);
110 Count += dumpAccessGroup(PDB_MemberAccess::Private,
111 Groups[(int)PDB_MemberAccess::Private]);
117 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
118 const SymbolGroup &Group) {
119 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
123 if (Access == PDB_MemberAccess::Private) {
125 WithColor(Printer, PDB_ColorItem::Keyword).get() << "private";
127 } else if (Access == PDB_MemberAccess::Protected) {
129 WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected";
131 } else if (Access == PDB_MemberAccess::Public) {
133 WithColor(Printer, PDB_ColorItem::Keyword).get() << "public";
137 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
138 iter != end; ++iter) {
140 (*iter)->dump(*this);
142 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
145 (*iter)->dump(*this);
147 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
148 iter != end; ++iter) {
150 (*iter)->dump(*this);
156 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}
158 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) {
159 VariableDumper Dumper(Printer);
160 Dumper.start(Symbol);
163 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) {
164 if (Printer.IsSymbolExcluded(Symbol.getName()))
168 FunctionDumper Dumper(Printer);
169 Dumper.start(Symbol, FunctionDumper::PointerType::None);
172 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {}
174 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
175 if (Printer.IsTypeExcluded(Symbol.getName()))
179 EnumDumper Dumper(Printer);
180 Dumper.start(Symbol);
183 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
184 if (Printer.IsTypeExcluded(Symbol.getName()))
188 TypedefDumper Dumper(Printer);
189 Dumper.start(Symbol);
192 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {}