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 "EnumDumper.h"
12 #include "FunctionDumper.h"
13 #include "LinePrinter.h"
14 #include "llvm-pdbdump.h"
15 #include "TypedefDumper.h"
16 #include "VariableDumper.h"
18 #include "llvm/DebugInfo/PDB/IPDBSession.h"
19 #include "llvm/DebugInfo/PDB/PDBExtras.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
28 #include "llvm/Support/Format.h"
31 using namespace llvm::pdb;
33 ClassDefinitionDumper::ClassDefinitionDumper(LinePrinter &P)
34 : PDBSymDumper(true), Printer(P) {}
36 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class) {
37 std::string Name = Class.getName();
38 WithColor(Printer, PDB_ColorItem::Keyword).get() << Class.getUdtKind() << " ";
39 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
41 auto Bases = Class.findAllChildren<PDBSymbolTypeBaseClass>();
42 if (Bases->getChildCount() > 0) {
46 uint32_t BaseIndex = 0;
47 while (auto Base = Bases->getNext()) {
49 WithColor(Printer, PDB_ColorItem::Keyword).get() << Base->getAccess();
50 if (Base->isVirtualBaseClass())
51 WithColor(Printer, PDB_ColorItem::Keyword).get() << " virtual";
52 WithColor(Printer, PDB_ColorItem::Type).get() << " " << Base->getName();
53 if (++BaseIndex < Bases->getChildCount()) {
62 auto Children = Class.findAllChildren();
63 if (Children->getChildCount() == 0) {
68 // Try to dump symbols organized by member access level. Public members
69 // first, then protected, then private. This might be slow, so it's worth
70 // reconsidering the value of this if performance of large PDBs is a problem.
71 // NOTE: Access level of nested types is not recorded in the PDB, so we have
72 // a special case for them.
73 SymbolGroupByAccess Groups;
74 Groups.insert(std::make_pair(0, SymbolGroup()));
75 Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
77 std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
78 Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
80 while (auto Child = Children->getNext()) {
81 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
82 if (isa<PDBSymbolTypeBaseClass>(*Child))
85 auto &AccessGroup = Groups.find((int)Access)->second;
87 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
88 if (Func->isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
90 if (Func->getLength() == 0 && !Func->isPureVirtual() &&
91 !Func->isIntroVirtualFunction())
94 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
95 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
97 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
99 AccessGroup.Unknown.push_back(std::move(Child));
104 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0]);
105 Count += dumpAccessGroup(PDB_MemberAccess::Public,
106 Groups[(int)PDB_MemberAccess::Public]);
107 Count += dumpAccessGroup(PDB_MemberAccess::Protected,
108 Groups[(int)PDB_MemberAccess::Protected]);
109 Count += dumpAccessGroup(PDB_MemberAccess::Private,
110 Groups[(int)PDB_MemberAccess::Private]);
116 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
117 const SymbolGroup &Group) {
118 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
122 if (Access == PDB_MemberAccess::Private) {
124 WithColor(Printer, PDB_ColorItem::Keyword).get() << "private";
126 } else if (Access == PDB_MemberAccess::Protected) {
128 WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected";
130 } else if (Access == PDB_MemberAccess::Public) {
132 WithColor(Printer, PDB_ColorItem::Keyword).get() << "public";
136 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
137 iter != end; ++iter) {
139 (*iter)->dump(*this);
141 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
144 (*iter)->dump(*this);
146 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
147 iter != end; ++iter) {
149 (*iter)->dump(*this);
155 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}
157 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) {
158 VariableDumper Dumper(Printer);
159 Dumper.start(Symbol);
162 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) {
163 if (Printer.IsSymbolExcluded(Symbol.getName()))
167 FunctionDumper Dumper(Printer);
168 Dumper.start(Symbol, FunctionDumper::PointerType::None);
171 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {}
173 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
174 if (Printer.IsTypeExcluded(Symbol.getName()))
178 EnumDumper Dumper(Printer);
179 Dumper.start(Symbol);
182 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
183 if (Printer.IsTypeExcluded(Symbol.getName()))
187 TypedefDumper Dumper(Printer);
188 Dumper.start(Symbol);
191 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {}