LLVM  9.0.0svn
InfoStream.cpp
Go to the documentation of this file.
1 //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- 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 
10 #include "llvm/ADT/BitVector.h"
11 #include "llvm/ADT/SmallVector.h"
16 
17 using namespace llvm;
18 using namespace llvm::codeview;
19 using namespace llvm::msf;
20 using namespace llvm::pdb;
21 
22 InfoStream::InfoStream(std::unique_ptr<BinaryStream> Stream)
23  : Stream(std::move(Stream)), Header(nullptr) {}
24 
26  BinaryStreamReader Reader(*Stream);
27 
28  if (auto EC = Reader.readObject(Header))
29  return joinErrors(
30  std::move(EC),
31  make_error<RawError>(raw_error_code::corrupt_file,
32  "PDB Stream does not contain a header."));
33 
34  switch (Header->Version) {
35  case PdbImplVC70:
36  case PdbImplVC80:
37  case PdbImplVC110:
38  case PdbImplVC140:
39  break;
40  default:
41  return make_error<RawError>(raw_error_code::corrupt_file,
42  "Unsupported PDB stream version.");
43  }
44 
45  uint32_t Offset = Reader.getOffset();
46  if (auto EC = NamedStreams.load(Reader))
47  return EC;
48  uint32_t NewOffset = Reader.getOffset();
49  NamedStreamMapByteSize = NewOffset - Offset;
50 
51  Reader.setOffset(Offset);
52  if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
53  return EC;
54 
55  bool Stop = false;
56  while (!Stop && !Reader.empty()) {
58  if (auto EC = Reader.readEnum(Sig))
59  return EC;
60  // Since this value comes from a file, it's possible we have some strange
61  // value which doesn't correspond to any value. We don't want to warn on
62  // -Wcovered-switch-default in this case, so switch on the integral value
63  // instead of the enumeration value.
64  switch (uint32_t(Sig)) {
66  // No other flags for VC110 PDB.
67  Stop = true;
70  Features |= PdbFeatureContainsIdStream;
71  break;
73  Features |= PdbFeatureNoTypeMerging;
74  break;
76  Features |= PdbFeatureMinimalDebugInfo;
77  break;
78  default:
79  continue;
80  }
81  FeatureSignatures.push_back(Sig);
82  }
83  return Error::success();
84 }
85 
86 uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
87 
89  uint32_t Result;
90  if (!NamedStreams.get(Name, Result))
91  return make_error<RawError>(raw_error_code::no_stream);
92  return Result;
93 }
94 
96  return NamedStreams.entries();
97 }
98 
100  return !!(Features & PdbFeatureContainsIdStream);
101 }
102 
104  return static_cast<PdbRaw_ImplVer>(uint32_t(Header->Version));
105 }
106 
108  return uint32_t(Header->Signature);
109 }
110 
111 uint32_t InfoStream::getAge() const { return uint32_t(Header->Age); }
112 
113 GUID InfoStream::getGuid() const { return Header->Guid; }
114 
116  return NamedStreamMapByteSize;
117 }
118 
119 PdbRaw_Features InfoStream::getFeatures() const { return Features; }
120 
122  return FeatureSignatures;
123 }
124 
126  return NamedStreams;
127 }
128 
130  return SubNamedStreams;
131 }
Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size)
Read Length bytes from the underlying stream into Stream.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:129
support::ulittle32_t Version
Definition: RawTypes.h:305
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...
StringMap< uint32_t > named_streams() const
Definition: InfoStream.cpp:95
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:119
Definition: BitVector.h:937
support::ulittle32_t Signature
Definition: RawTypes.h:306
uint32_t getStreamSize() const
Definition: InfoStream.cpp:86
This represents the &#39;GUID&#39; type from windows.h.
Definition: GUID.h:21
Tagged union holding either a T or a Error.
Definition: CachePruning.h:22
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
ArrayRef< PdbRaw_FeatureSig > getFeatureSignatures() const
Definition: InfoStream.cpp:121
Error load(BinaryStreamReader &Stream)
StringMap< uint32_t > entries() const
support::ulittle32_t Age
Definition: RawTypes.h:307
PdbRaw_ImplVer getVersion() const
Definition: InfoStream.cpp:103
uint32_t getAge() const
Definition: InfoStream.cpp:111
uint32_t getSignature() const
Definition: InfoStream.cpp:107
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:423
codeview::GUID getGuid() const
Definition: InfoStream.cpp:113
Expected< uint32_t > getNamedStreamIndex(llvm::StringRef Name) const
Definition: InfoStream.cpp:88
bool get(StringRef Stream, uint32_t &StreamNo) const
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:125
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:250
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
bool containsIdStream() const
Definition: InfoStream.cpp:99
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Error readEnum(T &Dest)
Similar to readInteger.
uint32_t getNamedStreamMapByteSize() const
Definition: InfoStream.cpp:115