LLVM  16.0.0git
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 
14 
15 using namespace llvm;
16 using namespace llvm::codeview;
17 // using namespace llvm::msf;
18 using namespace llvm::pdb;
19 
20 InfoStream::InfoStream(std::unique_ptr<BinaryStream> Stream)
21  : Stream(std::move(Stream)), Header(nullptr) {}
22 
24  BinaryStreamReader Reader(*Stream);
25 
26  if (auto EC = Reader.readObject(Header))
27  return joinErrors(
28  std::move(EC),
29  make_error<RawError>(raw_error_code::corrupt_file,
30  "PDB Stream does not contain a header."));
31 
32  switch (Header->Version) {
33  case PdbImplVC70:
34  case PdbImplVC80:
35  case PdbImplVC110:
36  case PdbImplVC140:
37  break;
38  default:
39  return make_error<RawError>(raw_error_code::corrupt_file,
40  "Unsupported PDB stream version.");
41  }
42 
43  uint32_t Offset = Reader.getOffset();
44  if (auto EC = NamedStreams.load(Reader))
45  return EC;
46  uint32_t NewOffset = Reader.getOffset();
47  NamedStreamMapByteSize = NewOffset - Offset;
48 
49  Reader.setOffset(Offset);
50  if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
51  return EC;
52 
53  bool Stop = false;
54  while (!Stop && !Reader.empty()) {
56  if (auto EC = Reader.readEnum(Sig))
57  return EC;
58  // Since this value comes from a file, it's possible we have some strange
59  // value which doesn't correspond to any value. We don't want to warn on
60  // -Wcovered-switch-default in this case, so switch on the integral value
61  // instead of the enumeration value.
62  switch (uint32_t(Sig)) {
64  // No other flags for VC110 PDB.
65  Stop = true;
66  [[fallthrough]];
68  Features |= PdbFeatureContainsIdStream;
69  break;
71  Features |= PdbFeatureNoTypeMerging;
72  break;
74  Features |= PdbFeatureMinimalDebugInfo;
75  break;
76  default:
77  continue;
78  }
79  FeatureSignatures.push_back(Sig);
80  }
81  return Error::success();
82 }
83 
84 uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
85 
87  uint32_t Result;
88  if (!NamedStreams.get(Name, Result))
89  return make_error<RawError>(raw_error_code::no_stream);
90  return Result;
91 }
92 
94  return NamedStreams.entries();
95 }
96 
98  return !!(Features & PdbFeatureContainsIdStream);
99 }
100 
102  return static_cast<PdbRaw_ImplVer>(uint32_t(Header->Version));
103 }
104 
106  return uint32_t(Header->Signature);
107 }
108 
109 uint32_t InfoStream::getAge() const { return uint32_t(Header->Age); }
110 
111 GUID InfoStream::getGuid() const { return Header->Guid; }
112 
114  return NamedStreamMapByteSize;
115 }
116 
117 PdbRaw_Features InfoStream::getFeatures() const { return Features; }
118 
120  return FeatureSignatures;
121 }
122 
124  return NamedStreams;
125 }
126 
128  return SubNamedStreams;
129 }
llvm::pdb::raw_error_code::no_stream
@ no_stream
BinaryStreamReader.h
llvm::BinaryStreamReader::empty
bool empty() const
Definition: BinaryStreamReader.h:246
llvm::BinaryStreamReader::setOffset
void setOffset(uint64_t Off)
Definition: BinaryStreamReader.h:247
RawConstants.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::pdb::InfoStreamHeader::Version
support::ulittle32_t Version
Definition: RawTypes.h:305
RawTypes.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::pdb::NamedStreamMap::entries
StringMap< uint32_t > entries() const
Definition: NamedStreamMap.cpp:106
llvm::codeview::GUID
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::InfoStream::getAge
uint32_t getAge() const
Definition: InfoStream.cpp:109
RawError.h
llvm::pdb::PdbRaw_FeatureSig
PdbRaw_FeatureSig
Definition: RawConstants.h:36
llvm::pdb::InfoStream::getNamedStreamMapByteSize
uint32_t getNamedStreamMapByteSize() const
Definition: InfoStream.cpp:113
llvm::pdb::PdbRaw_Features
PdbRaw_Features
Definition: RawConstants.h:43
llvm::pdb::raw_error_code::corrupt_file
@ corrupt_file
llvm::pdb::InfoStream::getVersion
PdbRaw_ImplVer getVersion() const
Definition: InfoStream.cpp:101
llvm::BinaryStreamReader::getOffset
uint64_t getOffset() const
Definition: BinaryStreamReader.h:248
llvm::pdb::InfoStream::getFeatureSignatures
ArrayRef< PdbRaw_FeatureSig > getFeatureSignatures() const
Definition: InfoStream.cpp:119
llvm::BinarySubstreamRef
Definition: BinaryStreamRef.h:199
llvm::pdb::InfoStream::reload
Error reload()
Definition: InfoStream.cpp:23
llvm::pdb::PdbFeatureContainsIdStream
@ PdbFeatureContainsIdStream
Definition: RawConstants.h:45
llvm::pdb::PdbImplVC80
@ PdbImplVC80
Definition: RawConstants.h:29
llvm::pdb::InfoStream::named_streams
StringMap< uint32_t > named_streams() const
Definition: InfoStream.cpp:93
llvm::BinaryStreamReader::readSubstream
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Definition: BinaryStreamReader.cpp:142
llvm::pdb::InfoStream::getSignature
uint32_t getSignature() const
Definition: InfoStream.cpp:105
llvm::pdb::InfoStreamHeader::Age
support::ulittle32_t Age
Definition: RawTypes.h:307
llvm::StringMap< uint32_t >
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
llvm::pdb::InfoStream::getNamedStreams
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:123
llvm::pdb::PdbRaw_FeatureSig::MinimalDebugInfo
@ MinimalDebugInfo
llvm::pdb::PdbRaw_FeatureSig::NoTypeMerge
@ NoTypeMerge
llvm::pdb::InfoStream::getGuid
codeview::GUID getGuid() const
Definition: InfoStream.cpp:111
llvm::pdb::InfoStream::getFeatures
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:117
llvm::pdb::NamedStreamMap::load
Error load(BinaryStreamReader &Stream)
Definition: NamedStreamMap.cpp:49
llvm::pdb::PdbRaw_FeatureSig::VC110
@ VC110
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::InfoStreamHeader::Guid
codeview::GUID Guid
Definition: RawTypes.h:308
llvm::pdb::NamedStreamMap::get
bool get(StringRef Stream, uint32_t &StreamNo) const
Definition: NamedStreamMap.cpp:98
llvm::pdb::PdbRaw_FeatureSig::VC140
@ VC140
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:426
llvm::pdb::NamedStreamMap
Definition: NamedStreamMap.h:36
llvm::pdb::InfoStream::getStreamSize
uint32_t getStreamSize() const
Definition: InfoStream.cpp:84
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:1861
llvm::codeview::CompileSym2Flags::EC
@ EC
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:162
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
llvm::pdb::InfoStream::containsIdStream
bool containsIdStream() const
Definition: InfoStream.cpp:97
llvm::pdb::InfoStream::getNamedStreamsBuffer
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:127
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
uint32_t
llvm::pdb::PdbRaw_ImplVer
PdbRaw_ImplVer
Definition: RawConstants.h:21
llvm::pdb::PdbImplVC140
@ PdbImplVC140
Definition: RawConstants.h:31
std
Definition: BitVector.h:851
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::BinaryStreamReader::readEnum
Error readEnum(T &Dest)
Similar to readInteger.
Definition: BinaryStreamReader.h:82
llvm::pdb::InfoStreamHeader::Signature
support::ulittle32_t Signature
Definition: RawTypes.h:306
llvm::pdb::InfoStream::getNamedStreamIndex
Expected< uint32_t > getNamedStreamIndex(llvm::StringRef Name) const
Definition: InfoStream.cpp:86
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbFeatureNoTypeMerging
@ PdbFeatureNoTypeMerging
Definition: RawConstants.h:47
InfoStream.h
llvm::pdb::PdbImplVC110
@ PdbImplVC110
Definition: RawConstants.h:30
llvm::pdb::PdbFeatureMinimalDebugInfo
@ PdbFeatureMinimalDebugInfo
Definition: RawConstants.h:46
llvm::pdb::PdbImplVC70
@ PdbImplVC70
Definition: RawConstants.h:28