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 ";
37 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
39 auto Children = Class.findAllChildren();
40 if (Children->getChildCount() == 0) {
45 // Try to dump symbols organized by member access level. Public members
46 // first, then protected, then private. This might be slow, so it's worth
47 // reconsidering the value of this if performance of large PDBs is a problem.
48 // NOTE: Access level of nested types is not recorded in the PDB, so we have
49 // a special case for them.
50 SymbolGroupByAccess Groups;
51 Groups.insert(std::make_pair(0, SymbolGroup()));
52 Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
54 std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
55 Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
57 while (auto Child = Children->getNext()) {
58 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
59 if (isa<PDBSymbolTypeBaseClass>(*Child))
62 auto &AccessGroup = Groups.find((int)Access)->second;
64 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
65 if (Func->isCompilerGenerated())
67 if (Func->getLength() == 0 && !Func->isPureVirtual())
70 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
71 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
73 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
75 AccessGroup.Unknown.push_back(std::move(Child));
80 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0]);
81 Count += dumpAccessGroup(PDB_MemberAccess::Public,
82 Groups[(int)PDB_MemberAccess::Public]);
83 Count += dumpAccessGroup(PDB_MemberAccess::Protected,
84 Groups[(int)PDB_MemberAccess::Protected]);
85 Count += dumpAccessGroup(PDB_MemberAccess::Private,
86 Groups[(int)PDB_MemberAccess::Private]);
92 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
93 const SymbolGroup &Group) {
94 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
98 if (Access == PDB_MemberAccess::Private) {
100 WithColor(Printer, PDB_ColorItem::Keyword).get() << "private";
102 } else if (Access == PDB_MemberAccess::Protected) {
104 WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected";
106 } else if (Access == PDB_MemberAccess::Public) {
108 WithColor(Printer, PDB_ColorItem::Keyword).get() << "public";
112 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
113 iter != end; ++iter) {
115 (*iter)->dump(*this);
117 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
120 (*iter)->dump(*this);
122 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
123 iter != end; ++iter) {
125 (*iter)->dump(*this);
131 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}
133 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol) {
134 VariableDumper Dumper(Printer);
135 Dumper.start(Symbol);
138 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol) {
139 if (Printer.IsSymbolExcluded(Symbol.getName()))
143 FunctionDumper Dumper(Printer);
144 Dumper.start(Symbol, FunctionDumper::PointerType::None);
147 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol) {}
149 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol) {
150 if (Printer.IsTypeExcluded(Symbol.getName()))
154 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
155 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
158 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
159 if (Printer.IsTypeExcluded(Symbol.getName()))
163 TypedefDumper Dumper(Printer);
164 Dumper.start(Symbol);
167 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol) {}