summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-pdbdump/PrettyClassLayoutTextDumper.cpp
blob: 02f31108b0dfe3905d95d7796cd0c150a79610e9 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//===- PrettyClassLayoutTextDumper.cpp --------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "PrettyClassLayoutTextDumper.h"

#include "LinePrinter.h"
#include "PrettyEnumDumper.h"
#include "PrettyFunctionDumper.h"
#include "PrettyTypedefDumper.h"
#include "PrettyVariableDumper.h"
#include "llvm-pdbdump.h"

#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDBExtras.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
#include "llvm/DebugInfo/PDB/UDTLayout.h"

#include "llvm/Support/Format.h"

using namespace llvm;
using namespace llvm::pdb;

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

bool PrettyClassLayoutTextDumper::start(const ClassLayout &Layout) {
  if (opts::pretty::ClassFormat ==
      opts::pretty::ClassDefinitionFormat::Standard) {
    for (auto &Other : Layout.other_items())
      Other->dump(*this);
    for (auto &Func : Layout.funcs())
      Func->dump(*this);
  }

  const BitVector &UseMap = Layout.usedBytes();
  int NextUnusedByte = Layout.usedBytes().find_first_unset();
  // Next dump items which affect class layout.
  for (auto &LayoutItem : Layout.layout_items()) {
    if (NextUnusedByte >= 0) {
      // If there are padding bytes remaining, see if this field is the first to
      // cross a padding boundary, and print a padding field indicator if so.
      int Off = LayoutItem->getOffsetInParent();
      if (Off > NextUnusedByte) {
        uint32_t Amount = Off - NextUnusedByte;
        Printer.NewLine();
        WithColor(Printer, PDB_ColorItem::Padding).get() << "<padding> ("
                                                         << Amount << " bytes)";
        assert(UseMap.find_next(NextUnusedByte) == Off);
        NextUnusedByte = UseMap.find_next_unset(Off);
      }
    }
    LayoutItem->getSymbol().dump(*this);
  }

  if (NextUnusedByte >= 0 && Layout.getClassSize() > 1) {
    uint32_t Amount = Layout.getClassSize() - NextUnusedByte;
    Printer.NewLine();
    WithColor(Printer, PDB_ColorItem::Padding).get() << "<padding> (" << Amount
                                                     << " bytes)";
    DumpedAnything = true;
  }

  return DumpedAnything;
}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolTypeBaseClass &Symbol) {}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolData &Symbol) {
  VariableDumper Dumper(Printer);
  Dumper.start(Symbol);
  DumpedAnything = true;
}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolFunc &Symbol) {
  if (Printer.IsSymbolExcluded(Symbol.getName()))
    return;
  if (Symbol.isCompilerGenerated() && opts::pretty::ExcludeCompilerGenerated)
    return;
  if (Symbol.getLength() == 0 && !Symbol.isPureVirtual() &&
      !Symbol.isIntroVirtualFunction())
    return;

  DumpedAnything = true;
  Printer.NewLine();
  FunctionDumper Dumper(Printer);
  Dumper.start(Symbol, FunctionDumper::PointerType::None);
}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolTypeVTable &Symbol) {
  VariableDumper Dumper(Printer);
  Dumper.start(Symbol);
  DumpedAnything = true;
}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolTypeEnum &Symbol) {
  DumpedAnything = true;
  Printer.NewLine();
  EnumDumper Dumper(Printer);
  Dumper.start(Symbol);
}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolTypeTypedef &Symbol) {
  DumpedAnything = true;
  Printer.NewLine();
  TypedefDumper Dumper(Printer);
  Dumper.start(Symbol);
}

void PrettyClassLayoutTextDumper::dump(const PDBSymbolTypeUDT &Symbol) {}
OpenPOWER on IntegriCloud