aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-pdbdump/TypeDumper.cpp
blob: 88c0bd65697ede96444d642076599aa037ee1550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===- TypeDumper.cpp - PDBSymDumper implementation for types *----- C++ *-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "TypeDumper.h"

#include "BuiltinDumper.h"
#include "ClassDefinitionDumper.h"
#include "EnumDumper.h"
#include "LinePrinter.h"
#include "llvm-pdbdump.h"
#include "TypedefDumper.h"

#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"

using namespace llvm;

TypeDumper::TypeDumper(LinePrinter &P) : PDBSymDumper(true), Printer(P) {}

void TypeDumper::start(const PDBSymbolExe &Exe) {
  auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
  Printer.NewLine();
  WithColor(Printer, PDB_ColorItem::Identifier).get() << "Enums";
  Printer << ": (" << Enums->getChildCount() << " items)";
  Printer.Indent();
  while (auto Enum = Enums->getNext())
    Enum->dump(*this);
  Printer.Unindent();

  auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
  Printer.NewLine();
  WithColor(Printer, PDB_ColorItem::Identifier).get() << "Typedefs";
  Printer << ": (" << Typedefs->getChildCount() << " items)";
  Printer.Indent();
  while (auto Typedef = Typedefs->getNext())
    Typedef->dump(*this);
  Printer.Unindent();

  auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
  Printer.NewLine();
  WithColor(Printer, PDB_ColorItem::Identifier).get() << "Classes";
  Printer << ": (" << Classes->getChildCount() << " items)";
  Printer.Indent();
  while (auto Class = Classes->getNext())
    Class->dump(*this);
  Printer.Unindent();
}

void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol) {
  if (Symbol.getUnmodifiedTypeId() != 0)
    return;
  if (Printer.IsTypeExcluded(Symbol.getName()))
    return;
  // Dump member enums when dumping their class definition.
  if (Symbol.isNested())
    return;

  Printer.NewLine();
  EnumDumper Dumper(Printer);
  Dumper.start(Symbol);
}

void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
  if (Printer.IsTypeExcluded(Symbol.getName()))
    return;

  Printer.NewLine();
  TypedefDumper Dumper(Printer);
  Dumper.start(Symbol);
}

void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol) {
  if (Symbol.getUnmodifiedTypeId() != 0)
    return;
  if (Printer.IsTypeExcluded(Symbol.getName()))
    return;

  Printer.NewLine();

  if (opts::NoClassDefs) {
    WithColor(Printer, PDB_ColorItem::Keyword).get() << "class ";
    WithColor(Printer, PDB_ColorItem::Identifier).get() << Symbol.getName();
  } else {
    ClassDefinitionDumper Dumper(Printer);
    Dumper.start(Symbol);
  }
}