1 //===- ClassDefinitionDumper.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 "ClassDefinitionDumper.h"
11 #include "FunctionDumper.h"
12 #include "LinePrinter.h"
13 #include "llvm-pdbdump.h"
14 #include "TypedefDumper.h"
15 #include "VariableDumper.h"
17 #include "llvm/DebugInfo/PDB/IPDBSession.h"
18 #include "llvm/DebugInfo/PDB/PDBExtras.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
27 #include "llvm/Support/Format.h"
31 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
32 : PDBSymDumper(true), Printer(P) {}
34 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
35 std::string Name = Class.getName();
36 WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
37 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
39 auto Bases = Class.findAllChildren<PDBSymbolTypeBaseClass>();
40 if (Bases->getChildCount() > 0) {
44 uint32_t BaseIndex = 0;
45 while (auto Base = Bases->getNext()) {
47 WithColor(Printer, PDB_ColorItem::Keyword).get() << Base->getAccess();
48 if (Base->isVirtualBaseClass())
49 WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
50 WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base->getName();
51 if (++BaseIndex < Bases->getChildCount()) {
60 auto Children = Class.findAllChildren();
61 if (Children->getChildCount() == 0) {
66 // Try to dump symbols organized by member access level. Public members
67 // first, then protected, then private. This might be slow, so it's worth
68 // reconsidering the value of this if performance of large PDBs is a problem.
69 // NOTE: Access level of nested types is not recorded in the PDB, so we have
70 // a special case for them.
71 SymbolGroupByAccess Groups;
72 Groups.insert(std::make_pair(0, SymbolGroup()));
73 Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
75 std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
76 Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
78 while (auto Child = Children->getNext()) {
79 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
80 if (isa<PDBSymbolTypeBaseClass>(*Child))
83 auto &AccessGroup = Groups.find((int)Access)->second;
85 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
86 if (Func->isCompilerGenerated() && opts::ExcludeCompilerGenerated)
88 if (Func->getLength() == 0 && !Func->isPureVirtual() &&
89 !Func->isIntroVirtualFunction())
92 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
93 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
95 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
97 AccessGroup.Unknown.push_back(std::move(Child));
102 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0]);
103 Count += dumpAccessGroup(PDB_MemberAccess::Public,
104 Groups[(int)PDB_MemberAccess::Public]);
105 Count += dumpAccessGroup(PDB_MemberAccess::Protected,
106 Groups[(int)PDB_MemberAccess::Protected]);
107 Count += dumpAccessGroup(PDB_MemberAccess::Private,
108 Groups[(int)PDB_MemberAccess::Private]);
114 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
115 const SymbolGroup &Group) {
116 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
120 if (Access == PDB_MemberAccess::Private) {
122 WithColor(Printer, PDB_ColorItem::Keyword).get() << "private";
124 } else if (Access == PDB_MemberAccess::Protected) {
126 WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected";
128 } else if (Access == PDB_MemberAccess::Public) {
130 WithColor(Printer, PDB_ColorItem::Keyword).get() << "public";
134 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
135 iter != end; ++iter) {
137 (*iter)->dump(*this);
139 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
142 (*iter)->dump(*this);
144 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
145 iter != end; ++iter) {
147 (*iter)->dump(*this);
153 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}
155 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) {
156 VariableDumper Dumper(Printer);
157 Dumper.start(Symbol);
160 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) {
161 if (Printer.IsSymbolExcluded(Symbol.getName()))
165 FunctionDumper Dumper(Printer);
166 Dumper.start(Symbol, FunctionDumper::PointerType::None);
169 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {}
171 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
172 if (Printer.IsTypeExcluded(Symbol.getName()))
176 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
177 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
180 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
181 if (Printer.IsTypeExcluded(Symbol.getName()))
185 TypedefDumper Dumper(Printer);
186 Dumper.start(Symbol);
189 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {}