Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/PDB/Native/InjectedSourceStream.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- InjectedSourceStream.cpp - PDB Headerblock Stream Access -----------===//
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/InjectedSourceStream.h"
10
11
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
12
#include "llvm/DebugInfo/PDB/Native/Hash.h"
13
#include "llvm/DebugInfo/PDB/Native/PDBStringTable.h"
14
#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
15
#include "llvm/DebugInfo/PDB/Native/RawTypes.h"
16
#include "llvm/Support/BinaryStreamReader.h"
17
#include "llvm/Support/Endian.h"
18
19
using namespace llvm;
20
using namespace llvm::msf;
21
using namespace llvm::support;
22
using namespace llvm::pdb;
23
24
InjectedSourceStream::InjectedSourceStream(
25
    std::unique_ptr<MappedBlockStream> Stream)
26
5
    : Stream(std::move(Stream)) {}
27
28
5
Error InjectedSourceStream::reload(const PDBStringTable &Strings) {
29
5
  BinaryStreamReader Reader(*Stream);
30
5
31
5
  if (auto EC = Reader.readObject(Header))
32
1
    return EC;
33
4
34
4
  if (Header->Version !=
35
4
      static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne))
36
0
    return make_error<RawError>(raw_error_code::corrupt_file,
37
0
                                "Invalid headerblock header version");
38
4
39
4
  if (auto EC = InjectedSourceTable.load(Reader))
40
0
    return EC;
41
4
42
6
  
for (const auto& Entry : *this)4
{
43
6
    if (Entry.second.Size != sizeof(SrcHeaderBlockEntry))
44
0
      return make_error<RawError>(raw_error_code::corrupt_file,
45
0
                                  "Invalid headerbock entry size");
46
6
    if (Entry.second.Version !=
47
6
        static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne))
48
0
      return make_error<RawError>(raw_error_code::corrupt_file,
49
0
                                  "Invalid headerbock entry version");
50
6
51
6
    // Check that all name references are valid.
52
6
    auto Name = Strings.getStringForID(Entry.second.FileNI);
53
6
    if (!Name)
54
0
      return Name.takeError();
55
6
    auto ObjName = Strings.getStringForID(Entry.second.ObjNI);
56
6
    if (!ObjName)
57
0
      return ObjName.takeError();
58
6
    auto VName = Strings.getStringForID(Entry.second.VFileNI);
59
6
    if (!VName)
60
0
      return VName.takeError();
61
6
  }
62
4
63
4
  assert(Reader.bytesRemaining() == 0);
64
4
  return Error::success();
65
4
}