LLVM  6.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"
19 
20 using namespace llvm;
21 using namespace llvm::codeview;
22 using namespace llvm::msf;
23 using namespace llvm::pdb;
24 
25 InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
26  : Stream(std::move(Stream)) {}
27 
29  BinaryStreamReader Reader(*Stream);
30 
31  const InfoStreamHeader *H;
32  if (auto EC = Reader.readObject(H))
33  return joinErrors(
34  std::move(EC),
35  make_error<RawError>(raw_error_code::corrupt_file,
36  "PDB Stream does not contain a header."));
37 
38  switch (H->Version) {
39  case PdbImplVC70:
40  case PdbImplVC80:
41  case PdbImplVC110:
42  case PdbImplVC140:
43  break;
44  default:
45  return make_error<RawError>(raw_error_code::corrupt_file,
46  "Unsupported PDB stream version.");
47  }
48 
49  Version = H->Version;
50  Signature = H->Signature;
51  Age = H->Age;
52  Guid = H->Guid;
53 
54  uint32_t Offset = Reader.getOffset();
55  if (auto EC = NamedStreams.load(Reader))
56  return EC;
57  uint32_t NewOffset = Reader.getOffset();
58  NamedStreamMapByteSize = NewOffset - Offset;
59 
60  Reader.setOffset(Offset);
61  if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
62  return EC;
63 
64  bool Stop = false;
65  while (!Stop && !Reader.empty()) {
67  if (auto EC = Reader.readEnum(Sig))
68  return EC;
69  // Since this value comes from a file, it's possible we have some strange
70  // value which doesn't correspond to any value. We don't want to warn on
71  // -Wcovered-switch-default in this case, so switch on the integral value
72  // instead of the enumeration value.
73  switch (uint32_t(Sig)) {
75  // No other flags for VC110 PDB.
76  Stop = true;
79  Features |= PdbFeatureContainsIdStream;
80  break;
82  Features |= PdbFeatureNoTypeMerging;
83  break;
85  Features |= PdbFeatureMinimalDebugInfo;
86  break;
87  default:
88  continue;
89  }
90  FeatureSignatures.push_back(Sig);
91  }
92  return Error::success();
93 }
94 
95 uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
96 
98  uint32_t Result;
99  if (!NamedStreams.get(Name, Result))
100  return 0;
101  return Result;
102 }
103 
106  return NamedStreams.entries();
107 }
108 
110  return !!(Features & PdbFeatureContainsIdStream);
111 }
112 
114  return static_cast<PdbRaw_ImplVer>(Version);
115 }
116 
117 uint32_t InfoStream::getSignature() const { return Signature; }
118 
119 uint32_t InfoStream::getAge() const { return Age; }
120 
121 GUID InfoStream::getGuid() const { return Guid; }
122 
124  return NamedStreamMapByteSize;
125 }
126 
127 PdbRaw_Features InfoStream::getFeatures() const { return Features; }
128 
130  return FeatureSignatures;
131 }
132 
134  return NamedStreams;
135 }
136 
138  return SubNamedStreams;
139 }
iterator_range< StringMapConstIterator< uint32_t > > entries() const
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:97
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:137
iterator_range< StringMapConstIterator< uint32_t > > named_streams() const
Definition: InfoStream.cpp:105
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...
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:127
Definition: BitVector.h:920
support::ulittle32_t Signature
Definition: RawTypes.h:317
uint32_t getStreamSize() const
Definition: InfoStream.cpp:95
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:129
Error load(BinaryStreamReader &Stream)
support::ulittle32_t Age
Definition: RawTypes.h:318
#define H(x, y, z)
Definition: MD5.cpp:57
PdbRaw_ImplVer getVersion() const
Definition: InfoStream.cpp:113
uint32_t getAge() const
Definition: InfoStream.cpp:119
uint32_t getSignature() const
Definition: InfoStream.cpp:117
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
A range adaptor for a pair of iterators.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:408
codeview::GUID getGuid() const
Definition: InfoStream.cpp:121
bool get(StringRef Stream, uint32_t &StreamNo) const
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:133
#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:109
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:123