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 "llvm-pdbdump.h"
13 #include "TypedefDumper.h"
14 #include "VariableDumper.h"
16 #include "llvm/DebugInfo/PDB/IPDBSession.h"
17 #include "llvm/DebugInfo/PDB/PDBExtras.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
26 #include "llvm/Support/Format.h"
30 ClassDefinitionDumper::ClassDefinitionDumper() : PDBSymDumper(true) {}
32 void ClassDefinitionDumper::start(const PDBSymbolTypeUDT &Class,
33 raw_ostream &OS, int Indent) {
34 OS << "class " << Class.getName() << " {";
35 auto Children = Class.findAllChildren();
36 if (Children->getChildCount() == 0) {
41 // Try to dump symbols organized by member access level. Public members
42 // first, then protected, then private. This might be slow, so it's worth
43 // reconsidering the value of this if performance of large PDBs is a problem.
44 // NOTE: Access level of nested types is not recorded in the PDB, so we have
45 // a special case for them.
46 SymbolGroupByAccess Groups;
47 Groups.insert(std::make_pair(0, SymbolGroup()));
48 Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
50 std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
51 Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
53 while (auto Child = Children->getNext()) {
54 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
55 if (isa<PDBSymbolTypeBaseClass>(*Child))
58 SymbolGroup *InsertGroup = nullptr;
59 auto &AccessGroup = Groups.find((int)Access)->second;
61 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
62 if (Func->isCompilerGenerated())
64 if (Func->getLength() == 0 && !Func->isPureVirtual())
67 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
68 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
70 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
72 AccessGroup.Unknown.push_back(std::move(Child));
77 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0], OS, Indent);
78 Count += dumpAccessGroup(PDB_MemberAccess::Public,
79 Groups[(int)PDB_MemberAccess::Public], OS, Indent);
81 dumpAccessGroup(PDB_MemberAccess::Protected,
82 Groups[(int)PDB_MemberAccess::Protected], OS, Indent);
83 Count += dumpAccessGroup(PDB_MemberAccess::Private,
84 Groups[(int)PDB_MemberAccess::Private], OS, Indent);
87 OS << newline(Indent);
91 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
92 const SymbolGroup &Group,
93 raw_ostream &OS, int Indent) {
94 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
98 if (Access == PDB_MemberAccess::Private)
99 OS << newline(Indent) << "private:";
100 else if (Access == PDB_MemberAccess::Protected)
101 OS << newline(Indent) << "protected:";
102 else if (Access == PDB_MemberAccess::Public)
103 OS << newline(Indent) << "public:";
104 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
105 iter != end; ++iter) {
107 (*iter)->dump(OS, Indent + 2, *this);
109 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
112 (*iter)->dump(OS, Indent + 2, *this);
114 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
115 iter != end; ++iter) {
117 (*iter)->dump(OS, Indent + 2, *this);
122 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol,
123 raw_ostream &OS, int Indent) {}
125 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
127 VariableDumper Dumper;
128 Dumper.start(Symbol, OS, Indent);
131 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
133 FunctionDumper Dumper;
134 Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
137 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol,
138 raw_ostream &OS, int Indent) {}
140 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol,
141 raw_ostream &OS, int Indent) {
142 OS << newline(Indent) << "enum " << Symbol.getName();
145 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol,
146 raw_ostream &OS, int Indent) {
147 OS << newline(Indent);
148 TypedefDumper Dumper;
149 Dumper.start(Symbol, OS, Indent);
152 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol,
153 raw_ostream &OS, int Indent) {}