• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- TypeDumper.cpp - PDBSymDumper implementation for types *----- C++ *-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "TypeDumper.h"
11 
12 #include "BuiltinDumper.h"
13 #include "ClassDefinitionDumper.h"
14 #include "EnumDumper.h"
15 #include "LinePrinter.h"
16 #include "llvm-pdbdump.h"
17 #include "TypedefDumper.h"
18 
19 #include "llvm/DebugInfo/PDB/IPDBSession.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
25 
26 using namespace llvm;
27 
TypeDumper(LinePrinter & P)28 TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}
29 
start(const PDBSymbolExe & Exe)30 void TypeDumper::start(const PDBSymbolExe &Exe) {
31   auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
32   Printer.NewLine();
33   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
34   Printer << ": (" << Enums->getChildCount() << " items)";
35   Printer.Indent();
36   while (auto Enum = Enums->getNext())
37     Enum->dump(*this);
38   Printer.Unindent();
39 
40   auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
41   Printer.NewLine();
42   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
43   Printer << ": (" << Typedefs->getChildCount() << " items)";
44   Printer.Indent();
45   while (auto Typedef = Typedefs->getNext())
46     Typedef->dump(*this);
47   Printer.Unindent();
48 
49   auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
50   Printer.NewLine();
51   WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
52   Printer << ": (" << Classes->getChildCount() << " items)";
53   Printer.Indent();
54   while (auto Class = Classes->getNext())
55     Class->dump(*this);
56   Printer.Unindent();
57 }
58 
dump(const PDBSymbolTypeEnum & Symbol)59 void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol) {
60   if (Symbol.getUnmodifiedTypeId() != 0)
61     return;
62   if (Printer.IsTypeExcluded(Symbol.getName()))
63     return;
64   // Dump member enums when dumping their class definition.
65   if (Symbol.isNested())
66     return;
67 
68   Printer.NewLine();
69   EnumDumper Dumper(Printer);
70   Dumper.start(Symbol);
71 }
72 
dump(const PDBSymbolTypeTypedef & Symbol)73 void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
74   if (Printer.IsTypeExcluded(Symbol.getName()))
75     return;
76 
77   Printer.NewLine();
78   TypedefDumper Dumper(Printer);
79   Dumper.start(Symbol);
80 }
81 
dump(const PDBSymbolTypeUDT & Symbol)82 void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol) {
83   if (Symbol.getUnmodifiedTypeId() != 0)
84     return;
85   if (Printer.IsTypeExcluded(Symbol.getName()))
86     return;
87 
88   Printer.NewLine();
89 
90   if (opts::NoClassDefs) {
91     WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
92     WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
93   } else {
94     ClassDefinitionDumper Dumper(Printer);
95     Dumper.start(Symbol);
96   }
97 }
98