LLVM 22.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
15using namespace llvm;
16using namespace llvm::codeview;
17// using namespace llvm::msf;
18using namespace llvm::pdb;
19
20InfoStream::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),
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:
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]];
69 break;
71 Features |= PdbFeatureNoTypeMerging;
72 break;
75 break;
76 default:
77 continue;
78 }
79 FeatureSignatures.push_back(Sig);
80 }
81 return Error::success();
82}
83
84uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
85
87 uint32_t Result;
88 if (!NamedStreams.get(Name, Result))
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
109uint32_t InfoStream::getAge() const { return uint32_t(Header->Age); }
110
111GUID InfoStream::getGuid() const { return Header->Guid; }
112
114 return NamedStreamMapByteSize;
115}
116
117PdbRaw_Features InfoStream::getFeatures() const { return Features; }
118
120 return FeatureSignatures;
121}
122
124 return NamedStreams;
125}
126
128 return SubNamedStreams;
129}
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Provides read only access to a subclass of BinaryStream.
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...
LLVM_ABI Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Error readEnum(T &Dest)
Similar to readInteger.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM_ABI codeview::GUID getGuid() const
LLVM_ABI Expected< uint32_t > getNamedStreamIndex(llvm::StringRef Name) const
LLVM_ABI ArrayRef< PdbRaw_FeatureSig > getFeatureSignatures() const
LLVM_ABI Error reload()
LLVM_ABI uint32_t getStreamSize() const
LLVM_ABI const NamedStreamMap & getNamedStreams() const
LLVM_ABI InfoStream(std::unique_ptr< BinaryStream > Stream)
LLVM_ABI PdbRaw_Features getFeatures() const
LLVM_ABI bool containsIdStream() const
LLVM_ABI uint32_t getAge() const
LLVM_ABI StringMap< uint32_t > named_streams() const
LLVM_ABI uint32_t getNamedStreamMapByteSize() const
LLVM_ABI PdbRaw_ImplVer getVersion() const
LLVM_ABI uint32_t getSignature() const
LLVM_ABI BinarySubstreamRef getNamedStreamsBuffer() const
@ PdbFeatureMinimalDebugInfo
@ PdbFeatureNoTypeMerging
@ PdbFeatureContainsIdStream
This is an optimization pass for GlobalISel generic memory operations.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition Error.h:442
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
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:1847
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
This represents the 'GUID' type from windows.h.
Definition GUID.h:22
uint8_t Guid[16]
Definition GUID.h:23