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<BinaryStream> Stream)
24  : Stream(std::move(Stream)), Header(nullptr) {}
25 
27  BinaryStreamReader Reader(*Stream);
28 
29  if (auto EC = Reader.readObject(Header))
30  return joinErrors(
31  std::move(EC),
32  make_error<RawError>(raw_error_code::corrupt_file,
33  "PDB Stream does not contain a header."));
34 
35  switch (Header->Version) {
36  case PdbImplVC70:
37  case PdbImplVC80:
38  case PdbImplVC110:
39  case PdbImplVC140:
40  break;
41  default:
42  return make_error<RawError>(raw_error_code::corrupt_file,
43  "Unsupported PDB stream version.");
44  }
45 
46  uint32_t Offset = Reader.getOffset();
47  if (auto EC = NamedStreams.load(Reader))
48  return EC;
49  uint32_t NewOffset = Reader.getOffset();
50  NamedStreamMapByteSize = NewOffset - Offset;
51 
52  Reader.setOffset(Offset);
53  if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
54  return EC;
55 
56  bool Stop = false;
57  while (!Stop && !Reader.empty()) {
59  if (auto EC = Reader.readEnum(Sig))
60  return EC;
61  // Since this value comes from a file, it's possible we have some strange
62  // value which doesn't correspond to any value. We don't want to warn on
63  // -Wcovered-switch-default in this case, so switch on the integral value
64  // instead of the enumeration value.
65  switch (uint32_t(Sig)) {
67  // No other flags for VC110 PDB.
68  Stop = true;
71  Features |= PdbFeatureContainsIdStream;
72  break;
74  Features |= PdbFeatureNoTypeMerging;
75  break;
77  Features |= PdbFeatureMinimalDebugInfo;
78  break;
79  default:
80  continue;
81  }
82  FeatureSignatures.push_back(Sig);
83  }
84  return Error::success();
85 }
86 
87 uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
88 
90  uint32_t Result;
91  if (!NamedStreams.get(Name, Result))
92  return make_error<RawError>(raw_error_code::no_stream);
93  return Result;
94 }
95 
97  return NamedStreams.entries();
98 }
99 
101  return !!(Features & PdbFeatureContainsIdStream);
102 }
103 
105  return static_cast<PdbRaw_ImplVer>(uint32_t(Header->Version));
106 }
107 
109  return uint32_t(Header->Signature);
110 }
111 
112 uint32_t InfoStream::getAge() const { return uint32_t(Header->Age); }
113 
114 GUID InfoStream::getGuid() const { return Header->Guid; }
115 
117  return NamedStreamMapByteSize;
118 }
119 
120 PdbRaw_Features InfoStream::getFeatures() const { return Features; }
121 
123  return FeatureSignatures;
124 }
125 
127  return NamedStreams;
128 }
129 
131  return SubNamedStreams;
132 }
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
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:130
support::ulittle32_t Version
Definition: RawTypes.h:306
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:96
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:120
Definition: BitVector.h:921
support::ulittle32_t Signature
Definition: RawTypes.h:307
uint32_t getStreamSize() const
Definition: InfoStream.cpp:87
This represents the &#39;GUID&#39; type from windows.h.
Definition: GUID.h:22
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
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:122
Error load(BinaryStreamReader &Stream)
StringMap< uint32_t > entries() const
support::ulittle32_t Age
Definition: RawTypes.h:308
PdbRaw_ImplVer getVersion() const
Definition: InfoStream.cpp:104
uint32_t getAge() const
Definition: InfoStream.cpp:112
uint32_t getSignature() const
Definition: InfoStream.cpp:108
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:408
codeview::GUID getGuid() const
Definition: InfoStream.cpp:114
Expected< uint32_t > getNamedStreamIndex(llvm::StringRef Name) const
Definition: InfoStream.cpp:89
bool get(StringRef Stream, uint32_t &StreamNo) const
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:126
#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:100
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:116