LLVM  7.0.0svn
InfoStream.cpp
Go to the documentation of this file.
1 //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/BitVector.h"
12 #include "llvm/ADT/SmallVector.h"
17 
18 using namespace llvm;
19 using namespace llvm::codeview;
20 using namespace llvm::msf;
21 using namespace llvm::pdb;
22 
23 InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
24  : Stream(std::move(Stream)) {}
25 
27  BinaryStreamReader Reader(*Stream);
28 
29  const InfoStreamHeader *H;
30  if (auto EC = Reader.readObject(H))
31  return joinErrors(
32  std::move(EC),
33  make_error<RawError>(raw_error_code::corrupt_file,
34  "PDB Stream does not contain a header."));
35 
36  switch (H->Version) {
37  case PdbImplVC70:
38  case PdbImplVC80:
39  case PdbImplVC110:
40  case PdbImplVC140:
41  break;
42  default:
43  return make_error<RawError>(raw_error_code::corrupt_file,
44  "Unsupported PDB stream version.");
45  }
46 
47  Version = H->Version;
48  Signature = H->Signature;
49  Age = H->Age;
50  Guid = H->Guid;
51 
52  uint32_t Offset = Reader.getOffset();
53  if (auto EC = NamedStreams.load(Reader))
54  return EC;
55  uint32_t NewOffset = Reader.getOffset();
56  NamedStreamMapByteSize = NewOffset - Offset;
57 
58  Reader.setOffset(Offset);
59  if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
60  return EC;
61 
62  bool Stop = false;
63  while (!Stop && !Reader.empty()) {
65  if (auto EC = Reader.readEnum(Sig))
66  return EC;
67  // Since this value comes from a file, it's possible we have some strange
68  // value which doesn't correspond to any value. We don't want to warn on
69  // -Wcovered-switch-default in this case, so switch on the integral value
70  // instead of the enumeration value.
71  switch (uint32_t(Sig)) {
73  // No other flags for VC110 PDB.
74  Stop = true;
77  Features |= PdbFeatureContainsIdStream;
78  break;
80  Features |= PdbFeatureNoTypeMerging;
81  break;
83  Features |= PdbFeatureMinimalDebugInfo;
84  break;
85  default:
86  continue;
87  }
88  FeatureSignatures.push_back(Sig);
89  }
90  return Error::success();
91 }
92 
93 uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
94 
96  uint32_t Result;
97  if (!NamedStreams.get(Name, Result))
98  return 0;
99  return Result;
100 }
101 
103  return NamedStreams.entries();
104 }
105 
107  return !!(Features & PdbFeatureContainsIdStream);
108 }
109 
111  return static_cast<PdbRaw_ImplVer>(Version);
112 }
113 
114 uint32_t InfoStream::getSignature() const { return Signature; }
115 
116 uint32_t InfoStream::getAge() const { return Age; }
117 
118 GUID InfoStream::getGuid() const { return Guid; }
119 
121  return NamedStreamMapByteSize;
122 }
123 
124 PdbRaw_Features InfoStream::getFeatures() const { return Features; }
125 
127  return FeatureSignatures;
128 }
129 
131  return NamedStreams;
132 }
133 
135  return SubNamedStreams;
136 }
Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size)
Read Length bytes from the underlying stream into Stream.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
uint32_t getNamedStreamIndex(llvm::StringRef Name) const
Definition: InfoStream.cpp:95
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:134
support::ulittle32_t Version
Definition: RawTypes.h:316
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:102
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:124
Definition: BitVector.h:921
support::ulittle32_t Signature
Definition: RawTypes.h:317
uint32_t getStreamSize() const
Definition: InfoStream.cpp:93
This represents the &#39;GUID&#39; type from windows.h.
Definition: GUID.h:22
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
ArrayRef< PdbRaw_FeatureSig > getFeatureSignatures() const
Definition: InfoStream.cpp:126
Error load(BinaryStreamReader &Stream)
StringMap< uint32_t > entries() const
support::ulittle32_t Age
Definition: RawTypes.h:318
#define H(x, y, z)
Definition: MD5.cpp:57
PdbRaw_ImplVer getVersion() const
Definition: InfoStream.cpp:110
uint32_t getAge() const
Definition: InfoStream.cpp:116
uint32_t getSignature() const
Definition: InfoStream.cpp:114
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
The header preceeding the global PDB Stream (Stream 1)
Definition: RawTypes.h:315
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:408
codeview::GUID getGuid() const
Definition: InfoStream.cpp:118
bool get(StringRef Stream, uint32_t &StreamNo) const
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:130
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
bool containsIdStream() const
Definition: InfoStream.cpp:106
Provides read only access to a subclass of BinaryStream.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Error readEnum(T &Dest)
Similar to readInteger.
uint32_t getNamedStreamMapByteSize() const
Definition: InfoStream.cpp:120