LLVM 24.0.0git
ModuleDebugStream.cpp
Go to the documentation of this file.
1//===- ModuleDebugStream.cpp - PDB Module Info Stream Access --------------===//
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
21#include "llvm/Support/Error.h"
22#include <cstdint>
23
24using namespace llvm;
25using namespace llvm::codeview;
26using namespace llvm::msf;
27using namespace llvm::pdb;
28
31 std::unique_ptr<MappedBlockStream> Stream)
32 : Mod(Module), Stream(std::move(Stream)) {}
33
35
37 BinaryStreamReader Reader(*Stream);
38
39 if (Mod.getModuleStreamIndex() != llvm::pdb::kInvalidStreamIndex) {
40 if (Error E = reloadSerialize(Reader))
41 return E;
42 }
43 if (Reader.bytesRemaining() > 0)
45 "Unexpected bytes in module stream.");
46 return Error::success();
47}
48
49Error ModuleDebugStreamRef::reloadSerialize(BinaryStreamReader &Reader) {
50 uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
51 uint32_t C11Size = Mod.getC11LineInfoByteSize();
52 uint32_t C13Size = Mod.getC13LineInfoByteSize();
53
54 if (C11Size > 0 && C13Size > 0)
56 "Module has both C11 and C13 line info");
57
58 if (auto EC = Reader.readInteger(Signature))
59 return EC;
60 Reader.setOffset(0);
61 if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize))
62 return EC;
63 if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
64 return EC;
65 if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
66 return EC;
67
68 BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
69 if (auto EC = SymbolReader.readArray(
70 SymbolArray, SymbolReader.bytesRemaining(), sizeof(uint32_t)))
71 return EC;
72
73 BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
74 if (auto EC = SubsectionsReader.readArray(Subsections,
75 SubsectionsReader.bytesRemaining()))
76 return EC;
77
78 uint32_t GlobalRefsSize;
79 if (auto EC = Reader.readInteger(GlobalRefsSize))
80 return EC;
81 if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
82 return EC;
83 return Error::success();
84}
85
88 return limitSymbolArrayToScope(SymbolArray, ScopeBegin);
89}
90
92 return SymbolsSubstream;
93}
94
96 return C11LinesSubstream;
97}
98
100 return C13LinesSubstream;
101}
102
104 return GlobalRefsSubstream;
105}
106
108ModuleDebugStreamRef::symbols(bool *HadError) const {
109 return make_range(SymbolArray.begin(HadError), SymbolArray.end());
110}
111
113 auto Iter = SymbolArray.at(Offset);
114 assert(Iter != SymbolArray.end());
115 return *Iter;
116}
117
120 return make_range(Subsections.begin(), Subsections.end());
121}
122
124 return !C13LinesSubstream.empty();
125}
126
128
132 for (const auto &SS : subsections()) {
133 if (SS.kind() != DebugSubsectionKind::FileChecksums)
134 continue;
135
136 if (auto EC = Result.initialize(SS.getRecordData()))
137 return std::move(EC);
138 return Result;
139 }
140 return Result;
141}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight arrays that are backed by an arbitrary BinaryStream.
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
Provides read only access to a subclass of BinaryStream.
LLVM_ABI Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
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
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A range adaptor for a pair of iterators.
LLVM_ABI iterator_range< codeview::CVSymbolArray::Iterator > symbols(bool *HadError) const
LLVM_ABI codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const
LLVM_ABI ModuleDebugStreamRef(const DbiModuleDescriptor &Module, std::unique_ptr< msf::MappedBlockStream > Stream)
LLVM_ABI bool hasDebugSubsections() const
LLVM_ABI BinarySubstreamRef getSymbolsSubstream() const
LLVM_ABI BinarySubstreamRef getGlobalRefsSubstream() const
LLVM_ABI Expected< codeview::DebugChecksumsSubsectionRef > findChecksumsSubsection() const
LLVM_ABI BinarySubstreamRef getC11LinesSubstream() const
LLVM_ABI BinarySubstreamRef getC13LinesSubstream() const
LLVM_ABI const codeview::CVSymbolArray getSymbolArrayForScope(uint32_t ScopeBegin) const
LLVM_ABI iterator_range< DebugSubsectionIterator > subsections() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
VarStreamArray< CVSymbol > CVSymbolArray
Definition CVRecord.h:126
CVRecord< SymbolKind > CVSymbol
Definition CVRecord.h:65
LLVM_ABI CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin)
const uint16_t kInvalidStreamIndex
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
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:1933
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878