LLVM  14.0.0git
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 !=
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 !=
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 }
BinaryStreamReader.h
RawConstants.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::pdb::SrcHeaderBlockEntry::VFileNI
support::ulittle32_t VFileNI
Definition: RawTypes.h:338
llvm::pdb::InjectedSourceStream::reload
Error reload(const PDBStringTable &Strings)
Definition: InjectedSourceStream.cpp:28
RawTypes.h
llvm::pdb::HashTable::load
Error load(BinaryStreamReader &Stream)
Definition: HashTable.h:120
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::BinaryStreamReader::bytesRemaining
uint64_t bytesRemaining() const
Definition: BinaryStreamReader.h:257
llvm::pdb::PdbRaw_SrcHeaderBlockVer::SrcVerOne
@ SrcVerOne
llvm::msf
Definition: IMSFFile.h:18
llvm::pdb::raw_error_code::corrupt_file
@ corrupt_file
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::pdb::PDBStringTable::getStringForID
Expected< StringRef > getStringForID(uint32_t ID) const
Definition: PDBStringTable.cpp:109
MappedBlockStream.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::pdb::SrcHeaderBlockEntry::ObjNI
support::ulittle32_t ObjNI
Definition: RawTypes.h:337
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1609
llvm::pdb::PDBStringTable
Definition: PDBStringTable.h:32
llvm::BinaryStreamReader::readObject
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...
Definition: BinaryStreamReader.h:169
InjectedSourceStream.h
uint32_t
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::support
Definition: Endian.h:25
llvm::pdb::SrcHeaderBlockEntry
A single file record entry within the /src/headerblock stream.
Definition: RawTypes.h:331
PDBStringTable.h
llvm::pdb::SrcHeaderBlockHeader::Version
support::ulittle32_t Version
Definition: RawTypes.h:322
Hash.h
llvm::pdb::SrcHeaderBlockEntry::FileNI
support::ulittle32_t FileNI
Definition: RawTypes.h:336
Endian.h
llvm::pdb::SrcHeaderBlockEntry::Size
support::ulittle32_t Size
Definition: RawTypes.h:332
llvm::pdb::SrcHeaderBlockEntry::Version
support::ulittle32_t Version
Definition: RawTypes.h:333