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 raw_ostream &OS, int Indent) {
36 std::string Name = Class.getName();
37 WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
38 WithColor(Printer, PDB_ColorItem::Type).get() << Class.getName();
40 auto Children = Class.findAllChildren();
41 if (Children->getChildCount() == 0) {
46 // Try to dump symbols organized by member access level. Public members
47 // first, then protected, then private. This might be slow, so it's worth
48 // reconsidering the value of this if performance of large PDBs is a problem.
49 // NOTE: Access level of nested types is not recorded in the PDB, so we have
50 // a special case for them.
51 SymbolGroupByAccess Groups;
52 Groups.insert(std::make_pair(0, SymbolGroup()));
53 Groups.insert(std::make_pair((int)PDB_MemberAccess::Private, SymbolGroup()));
55 std::make_pair((int)PDB_MemberAccess::Protected, SymbolGroup()));
56 Groups.insert(std::make_pair((int)PDB_MemberAccess::Public, SymbolGroup()));
58 while (auto Child = Children->getNext()) {
59 PDB_MemberAccess Access = Child->getRawSymbol().getAccess();
60 if (isa<PDBSymbolTypeBaseClass>(*Child))
63 auto &AccessGroup = Groups.find((int)Access)->second;
65 if (auto Func = dyn_cast<PDBSymbolFunc>(Child.get())) {
66 if (Func->isCompilerGenerated())
68 if (Func->getLength() == 0 && !Func->isPureVirtual())
71 AccessGroup.Functions.push_back(std::unique_ptr<PDBSymbolFunc>(Func));
72 } else if (auto Data = dyn_cast<PDBSymbolData>(Child.get())) {
74 AccessGroup.Data.push_back(std::unique_ptr<PDBSymbolData>(Data));
76 AccessGroup.Unknown.push_back(std::move(Child));
81 Count += dumpAccessGroup((PDB_MemberAccess)0, Groups[0], OS, Indent);
82 Count += dumpAccessGroup(PDB_MemberAccess::Public,
83 Groups[(int)PDB_MemberAccess::Public], OS, Indent);
85 dumpAccessGroup(PDB_MemberAccess::Protected,
86 Groups[(int)PDB_MemberAccess::Protected], OS, Indent);
87 Count += dumpAccessGroup(PDB_MemberAccess::Private,
88 Groups[(int)PDB_MemberAccess::Private], OS, Indent);
94 int ClassDefinitionDumper::dumpAccessGroup(PDB_MemberAccess Access,
95 const SymbolGroup &Group,
96 raw_ostream &OS, int Indent) {
97 if (Group.Functions.empty() && Group.Data.empty() && Group.Unknown.empty())
101 if (Access == PDB_MemberAccess::Private) {
103 WithColor(Printer, PDB_ColorItem::Keyword).get() << "private";
105 } else if (Access == PDB_MemberAccess::Protected) {
107 WithColor(Printer, PDB_ColorItem::Keyword).get() << "protected";
109 } else if (Access == PDB_MemberAccess::Public) {
111 WithColor(Printer, PDB_ColorItem::Keyword).get() << "public";
115 for (auto iter = Group.Functions.begin(), end = Group.Functions.end();
116 iter != end; ++iter) {
118 (*iter)->dump(OS, Indent + 2, *this);
120 for (auto iter = Group.Data.begin(), end = Group.Data.end(); iter != end;
123 (*iter)->dump(OS, Indent + 2, *this);
125 for (auto iter = Group.Unknown.begin(), end = Group.Unknown.end();
126 iter != end; ++iter) {
128 (*iter)->dump(OS, Indent + 2, *this);
134 void ClassDefinitionDumper::dump(const PDBSymbolTypeBaseClass &Symbol,
135 raw_ostream &OS, int Indent) {}
137 void ClassDefinitionDumper::dump(const PDBSymbolData &Symbol, raw_ostream &OS,
139 VariableDumper Dumper(Printer);
140 Dumper.start(Symbol, OS, Indent);
143 void ClassDefinitionDumper::dump(const PDBSymbolFunc &Symbol, raw_ostream &OS,
146 FunctionDumper Dumper(Printer);
147 Dumper.start(Symbol, FunctionDumper::PointerType::None, OS, Indent);
150 void ClassDefinitionDumper::dump(const PDBSymbolTypeVTable &Symbol,
151 raw_ostream &OS, int Indent) {}
153 void ClassDefinitionDumper::dump(const PDBSymbolTypeEnum &Symbol,
154 raw_ostream &OS, int Indent) {
156 WithColor(Printer, PDB_ColorItem::Keyword).get() << "enum ";
157 WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
160 void ClassDefinitionDumper::dump(const PDBSymbolTypeTypedef &Symbol,
161 raw_ostream &OS, int Indent) {
163 TypedefDumper Dumper(Printer);
164 Dumper.start(Symbol, OS, Indent);
167 void ClassDefinitionDumper::dump(const PDBSymbolTypeUDT &Symbol,
168 raw_ostream &OS, int Indent) {}