LLVM  10.0.0svn
InjectedSourceStream.cpp
Go to the documentation of this file.
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 
10 
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  : Stream(std::move(Stream)) {}
27 
29  BinaryStreamReader Reader(*Stream);
30 
31  if (auto EC = Reader.readObject(Header))
32  return EC;
33 
34  if (Header->Version !=
35  static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne))
36  return make_error<RawError>(raw_error_code::corrupt_file,
37  "Invalid headerblock header version");
38 
39  if (auto EC = InjectedSourceTable.load(Reader))
40  return EC;
41 
42  for (const auto& Entry : *this) {
43  if (Entry.second.Size != sizeof(SrcHeaderBlockEntry))
44  return make_error<RawError>(raw_error_code::corrupt_file,
45  "Invalid headerbock entry size");
46  if (Entry.second.Version !=
47  static_cast<uint32_t>(PdbRaw_SrcHeaderBlockVer::SrcVerOne))
48  return make_error<RawError>(raw_error_code::corrupt_file,
49  "Invalid headerbock entry version");
50 
51  // Check that all name references are valid.
52  auto Name = Strings.getStringForID(Entry.second.FileNI);
53  if (!Name)
54  return Name.takeError();
55  auto ObjName = Strings.getStringForID(Entry.second.ObjNI);
56  if (!ObjName)
57  return ObjName.takeError();
58  auto VName = Strings.getStringForID(Entry.second.VFileNI);
59  if (!VName)
60  return VName.takeError();
61  }
62 
63  assert(Reader.bytesRemaining() == 0);
64  return Error::success();
65 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
Error reload(const PDBStringTable &Strings)
Definition: BitVector.h:937
Expected< StringRef > getStringForID(uint32_t ID) const
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
support::ulittle32_t Version
Definition: RawTypes.h:322
Error load(BinaryStreamReader &Stream)
Definition: HashTable.h:119
A single file record entry within the /src/headerblock stream.
Definition: RawTypes.h:331
uint32_t bytesRemaining() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
Provides read only access to a subclass of BinaryStream.