LLVM 20.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),
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]];
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))
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
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}
std::string Name
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...
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Error readEnum(T &Dest)
Similar to readInteger.
void setOffset(uint64_t Off)
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
codeview::GUID getGuid() const
Definition: InfoStream.cpp:111
Expected< uint32_t > getNamedStreamIndex(llvm::StringRef Name) const
Definition: InfoStream.cpp:86
ArrayRef< PdbRaw_FeatureSig > getFeatureSignatures() const
Definition: InfoStream.cpp:119
uint32_t getStreamSize() const
Definition: InfoStream.cpp:84
const NamedStreamMap & getNamedStreams() const
Definition: InfoStream.cpp:123
InfoStream(std::unique_ptr< BinaryStream > Stream)
Definition: InfoStream.cpp:20
PdbRaw_Features getFeatures() const
Definition: InfoStream.cpp:117
bool containsIdStream() const
Definition: InfoStream.cpp:97
uint32_t getAge() const
Definition: InfoStream.cpp:109
StringMap< uint32_t > named_streams() const
Definition: InfoStream.cpp:93
uint32_t getNamedStreamMapByteSize() const
Definition: InfoStream.cpp:113
PdbRaw_ImplVer getVersion() const
Definition: InfoStream.cpp:101
uint32_t getSignature() const
Definition: InfoStream.cpp:105
BinarySubstreamRef getNamedStreamsBuffer() const
Definition: InfoStream.cpp:127
Error load(BinaryStreamReader &Stream)
StringMap< uint32_t > entries() const
bool get(StringRef Stream, uint32_t &StreamNo) const
@ PdbFeatureMinimalDebugInfo
Definition: RawConstants.h:46
@ PdbFeatureNoTypeMerging
Definition: RawConstants.h:47
@ PdbFeatureContainsIdStream
Definition: RawConstants.h:45
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:438
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:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This represents the 'GUID' type from windows.h.
Definition: GUID.h:21
support::ulittle32_t Version
Definition: RawTypes.h:305
support::ulittle32_t Signature
Definition: RawTypes.h:306
support::ulittle32_t Age
Definition: RawTypes.h:307