aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm-pdbdump/TypeDumper.cpp
blob: 3131e9f00ccc54df19f44fb206e96c8a710cbdce (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
//===- 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 "ClassDefinitionDumper.h"
#include "FunctionDumper.h"
#include "llvm-pdbdump.h"
#include "TypedefDumper.h"

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

using namespace llvm;

TypeDumper::TypeDumper(bool Inline, bool ClassDefs)
    : PDBSymDumper(true), InlineDump(Inline), FullClassDefs(ClassDefs) {}

void TypeDumper::start(const PDBSymbolExe &Exe, raw_ostream &OS, int Indent) {
  auto Enums = Exe.findAllChildren<PDBSymbolTypeEnum>();
  OS << newline(Indent) << "Enums: (" << Enums->getChildCount() << " items)";
  while (auto Enum = Enums->getNext())
    Enum->dump(OS, Indent + 2, *this);

  auto FuncSigs = Exe.findAllChildren<PDBSymbolTypeFunctionSig>();
  OS << newline(Indent);
  OS << "Function Signatures: (" << FuncSigs->getChildCount() << " items)";
  while (auto Sig = FuncSigs->getNext())
    Sig->dump(OS, Indent + 2, *this);

  auto Typedefs = Exe.findAllChildren<PDBSymbolTypeTypedef>();
  OS << newline(Indent) << "Typedefs: (" << Typedefs->getChildCount()
     << " items)";
  while (auto Typedef = Typedefs->getNext())
    Typedef->dump(OS, Indent + 2, *this);

  auto Classes = Exe.findAllChildren<PDBSymbolTypeUDT>();
  OS << newline(Indent) << "Classes: (" << Classes->getChildCount()
     << " items)";
  while (auto Class = Classes->getNext())
    Class->dump(OS, Indent + 2, *this);
}

void TypeDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
                      int Indent) {
  if (Symbol.getUnmodifiedTypeId() != 0)
    return;

  if (!InlineDump)
    OS << newline(Indent);

  OS << "enum " << Symbol.getName();
}

void TypeDumper::dump(const PDBSymbolTypeFunctionSig &Symbol, raw_ostream &OS,
                      int Indent) {
  if (!InlineDump)
    OS << newline(Indent);

  FunctionDumper Dumper;
  Dumper.start(Symbol, FunctionDumper::PointerType::None, OS);
}

void TypeDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
                      int Indent) {
  if (!InlineDump)
    OS << newline(Indent);

  TypedefDumper Dumper;
  Dumper.start(Symbol, OS, Indent);
}

void TypeDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
                      int Indent) {
  if (Symbol.getUnmodifiedTypeId() != 0)
    return;
  if (!InlineDump)
    OS << newline(Indent);

  if (FullClassDefs) {
    ClassDefinitionDumper Dumper;
    Dumper.start(Symbol, OS, Indent);
  } else {
    OS << "class " << Symbol.getName();
  }
}