summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-pdbdump/YAMLOutputStyle.cpp
blob: cf386bf5486993db0859bcea6f234f6d32e7920a (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
//===- YAMLOutputStyle.cpp ------------------------------------ *- C++ --*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "YAMLOutputStyle.h"

#include "PdbYaml.h"
#include "llvm-pdbdump.h"

#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"

using namespace llvm;
using namespace llvm::pdb;

YAMLOutputStyle::YAMLOutputStyle(PDBFile &File) : File(File), Out(outs()) {}

Error YAMLOutputStyle::dump() {
  if (auto EC = dumpFileHeaders())
    return EC;

  if (auto EC = dumpStreamMetadata())
    return EC;

  if (auto EC = dumpStreamDirectory())
    return EC;

  flush();
  return Error::success();
}

Error YAMLOutputStyle::dumpFileHeaders() {
  yaml::MsfHeaders Headers;
  Obj.Headers.SuperBlock.NumBlocks = File.getBlockCount();
  Obj.Headers.SuperBlock.BlockMapAddr = File.getBlockMapIndex();
  Obj.Headers.BlockMapOffset = File.getBlockMapOffset();
  Obj.Headers.SuperBlock.BlockSize = File.getBlockSize();
  auto Blocks = File.getDirectoryBlockArray();
  Obj.Headers.DirectoryBlocks.assign(Blocks.begin(), Blocks.end());
  Obj.Headers.NumDirectoryBlocks = File.getNumDirectoryBlocks();
  Obj.Headers.SuperBlock.NumDirectoryBytes = File.getNumDirectoryBytes();
  Obj.Headers.NumStreams = opts::pdb2yaml::StreamMetadata ? File.getNumStreams() : 0;
  Obj.Headers.SuperBlock.Unknown0 = File.getUnknown0();
  Obj.Headers.SuperBlock.Unknown1 = File.getUnknown1();
  Obj.Headers.FileSize = File.getFileSize();

  return Error::success();
}

Error YAMLOutputStyle::dumpStreamMetadata() {
  if (!opts::pdb2yaml::StreamMetadata)
    return Error::success();

  Obj.StreamSizes = File.getStreamSizes();
  return Error::success();
}

Error YAMLOutputStyle::dumpStreamDirectory() {
  if (!opts::pdb2yaml::StreamDirectory)
    return Error::success();

  auto StreamMap = File.getStreamMap();
  Obj.StreamMap.emplace();
  for (auto &Stream : StreamMap) {
    pdb::yaml::StreamBlockList BlockList;
    BlockList.Blocks = Stream;
    Obj.StreamMap->push_back(BlockList);
  }

  return Error::success();
}

void YAMLOutputStyle::flush() {
  Out << Obj;
  outs().flush();
}
OpenPOWER on IntegriCloud