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((PDB_MemberAccess)0, SymbolGroup()));
48 Groups.insert(std::make_pair(PDB_MemberAccess::Private, SymbolGroup()));
49 Groups.insert(std::make_pair(PDB_MemberAccess::Protected, SymbolGroup()));
50 Groups.insert(std::make_pair(PDB_MemberAccess::Public, SymbolGroup()));
52 while (auto Child = Children->getNext()) {
53 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
54 if (isa<PDBSymbolTypeBaseClass>(*Child))
57 SymbolGroup *InsertGroup = nullptr;
58 auto &AccessGroup = Groups.find(Access)->second;
60 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
61 if (Func->isCompilerGenerated())
63 if (Func->getLength() == 0 && !Func->isPureVirtual())
66 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
67 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
69 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
71 AccessGroup.Unknown.push_back(std::move(Child));
76 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[(PDB_MemberAccess)0], OS,
78 Count += dumpAccessGroup(PDB_MemberAccess::Public,
79 Groups[PDB_MemberAccess::Public], OS, Indent);
80 Count += dumpAccessGroup(PDB_MemberAccess::Protected,
81 Groups[PDB_MemberAccess::Protected], OS, Indent);
82 Count += dumpAccessGroup(PDB_MemberAccess::Private,
83 Groups[PDB_MemberAccess::Private], OS, Indent);
86 OS << newline(Indent);
90 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
91 const SymbolGroup &Group,
92 raw_ostream &OS, int Indent) {
93 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
97 if (Access == PDB_MemberAccess::Private)
98 OS << newline(Indent) << "private:";
99 else if (Access == PDB_MemberAccess::Protected)
100 OS << newline(Indent) << "protected:";
101 else if (Access == PDB_MemberAccess::Public)
102 OS << newline(Indent) << "public:";
103 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
104 iter != end; ++iter) {
106 (*iter)->dump(OS, Indent + 2, *this);
108 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
111 (*iter)->dump(OS, Indent + 2, *this);
113 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
114 iter != end; ++iter) {
116 (*iter)->dump(OS, Indent + 2, *this);
121 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol,
122 raw_ostream &OS, int Indent) {}
124 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
126 VariableDumper Dumper;
127 Dumper.start(Symbol, OS, Indent);
130 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
132 FunctionDumper Dumper;
133 Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
136 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol,
137 raw_ostream &OS, int Indent) {}
139 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol,
140 raw_ostream &OS, int Indent) {
141 OS << newline(Indent) << "enum " << Symbol.getName();
144 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol,
145 raw_ostream &OS, int Indent) {
146 OS << newline(Indent);
147 TypedefDumper Dumper;
148 Dumper.start(Symbol, OS, Indent);
151 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol,
152 raw_ostream &OS, int Indent) {}