LLVM  14.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 
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 }
llvm::pdb::raw_error_code::no_stream
@ no_stream
BinaryStreamReader.h
llvm::BinaryStreamReader::empty
bool empty() const
Definition: BinaryStreamReader.h:253
llvm::BinaryStreamReader::setOffset
void setOffset(uint64_t Off)
Definition: BinaryStreamReader.h:254
RawConstants.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
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:331
llvm::pdb::NamedStreamMap::entries
StringMap< uint32_t > entries() const
Definition: NamedStreamMap.cpp:108
llvm::codeview::GUID
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::InfoStream::getAge
uint32_t getAge() const
Definition: InfoStream.cpp:111
RawError.h
llvm::msf
Definition: IMSFFile.h:18
llvm::pdb::PdbRaw_FeatureSig
PdbRaw_FeatureSig
Definition: RawConstants.h:36
llvm::pdb::InfoStream::getNamedStreamMapByteSize
uint32_t getNamedStreamMapByteSize() const
Definition: InfoStream.cpp:115
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:103
llvm::BinaryStreamReader::getOffset
uint64_t getOffset() const
Definition: BinaryStreamReader.h:255
llvm::pdb::InfoStream::getFeatureSignatures
ArrayRef< PdbRaw_FeatureSig > getFeatureSignatures() const
Definition: InfoStream.cpp:121
llvm::BinarySubstreamRef
Definition: BinaryStreamRef.h:200
llvm::pdb::InfoStream::reload
Error reload()
Definition: InfoStream.cpp:25
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:95
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:107
BitVector.h
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:31
llvm::pdb::InfoStream::getNamedStreams
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:125
llvm::pdb::PdbRaw_FeatureSig::MinimalDebugInfo
@ MinimalDebugInfo
llvm::pdb::PdbRaw_FeatureSig::NoTypeMerge
@ NoTypeMerge
llvm::pdb::InfoStream::getGuid
codeview::GUID getGuid() const
Definition: InfoStream.cpp:113
llvm::pdb::InfoStream::getFeatures
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:119
llvm::pdb::NamedStreamMap::load
Error load(BinaryStreamReader &Stream)
Definition: NamedStreamMap.cpp:51
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:100
llvm::pdb::PdbRaw_FeatureSig::VC140
@ VC140
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:428
llvm::pdb::NamedStreamMap
Definition: NamedStreamMap.h:37
llvm::pdb::InfoStream::getStreamSize
uint32_t getStreamSize() const
Definition: InfoStream.cpp:86
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:1609
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:169
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::pdb::InfoStream::containsIdStream
bool containsIdStream() const
Definition: InfoStream.cpp:99
llvm::pdb::InfoStream::getNamedStreamsBuffer
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:129
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::pdb::PdbRaw_ImplVer
PdbRaw_ImplVer
Definition: RawConstants.h:21
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:286
llvm::pdb::PdbImplVC140
@ PdbImplVC140
Definition: RawConstants.h:31
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::BinaryStreamReader::readEnum
Error readEnum(T &Dest)
Similar to readInteger.
Definition: BinaryStreamReader.h:89
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:88
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::PdbFeatureNoTypeMerging
@ PdbFeatureNoTypeMerging
Definition: RawConstants.h:47
SmallVector.h
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