Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/PDB/Native/InfoStreamBuilder.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/DebugInfo/PDB/Native/InfoStreamBuilder.h"
10
11
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
12
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
13
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
14
#include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
15
#include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
16
#include "llvm/DebugInfo/PDB/Native/RawError.h"
17
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
18
#include "llvm/Support/BinaryStreamWriter.h"
19
20
using namespace llvm;
21
using namespace llvm::codeview;
22
using namespace llvm::msf;
23
using namespace llvm::pdb;
24
25
InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf,
26
                                     NamedStreamMap &NamedStreams)
27
    : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Age(0),
28
134
      NamedStreams(NamedStreams) {
29
134
  ::memset(&Guid, 0, sizeof(Guid));
30
134
}
31
32
131
void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
33
34
58
void InfoStreamBuilder::addFeature(PdbRaw_FeatureSig Sig) {
35
58
  Features.push_back(Sig);
36
58
}
37
38
110
void InfoStreamBuilder::setHashPDBContentsToGUID(bool B) {
39
110
  HashPDBContentsToGUID = B;
40
110
}
41
42
21
void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
43
44
21
void InfoStreamBuilder::setSignature(uint32_t S) { Signature = S; }
45
46
21
void InfoStreamBuilder::setGuid(GUID G) { Guid = G; }
47
48
49
268
Error InfoStreamBuilder::finalizeMsfLayout() {
50
268
  uint32_t Length = sizeof(InfoStreamHeader) +
51
268
                    NamedStreams.calculateSerializedLength() +
52
268
                    (Features.size() + 1) * sizeof(uint32_t);
53
268
  if (auto EC = Msf.setStreamSize(StreamPDB, Length))
54
0
    return EC;
55
268
  return Error::success();
56
268
}
57
58
Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout,
59
134
                                WritableBinaryStreamRef Buffer) const {
60
134
  auto InfoS = WritableMappedBlockStream::createIndexedStream(
61
134
      Layout, Buffer, StreamPDB, Msf.getAllocator());
62
134
  BinaryStreamWriter Writer(*InfoS);
63
134
64
134
  InfoStreamHeader H;
65
134
  // Leave the build id fields 0 so they can be set as the last step before
66
134
  // committing the file to disk.
67
134
  ::memset(&H, 0, sizeof(H));
68
134
  H.Version = Ver;
69
134
  if (auto EC = Writer.writeObject(H))
70
0
    return EC;
71
134
72
134
  if (auto EC = NamedStreams.commit(Writer))
73
0
    return EC;
74
134
  if (auto EC = Writer.writeInteger(0))
75
0
    return EC;
76
134
  for (auto E : Features) {
77
58
    if (auto EC = Writer.writeEnum(E))
78
0
      return EC;
79
58
  }
80
134
  assert(Writer.bytesRemaining() == 0);
81
134
  return Error::success();
82
134
}