LLVM 19.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
23#include "llvm/Support/Error.h"
24#include <cstdint>
25
26using namespace llvm;
27using namespace llvm::codeview;
28using namespace llvm::msf;
29using namespace llvm::pdb;
30
33 std::unique_ptr<MappedBlockStream> Stream)
34 : Mod(Module), Stream(std::move(Stream)) {}
35
37
39 BinaryStreamReader Reader(*Stream);
40
42 if (Error E = reloadSerialize(Reader))
43 return E;
44 }
45 if (Reader.bytesRemaining() > 0)
46 return make_error<RawError>(raw_error_code::corrupt_file,
47 "Unexpected bytes in module stream.");
48 return Error::success();
49}
50
51Error ModuleDebugStreamRef::reloadSerialize(BinaryStreamReader &Reader) {
52 uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
53 uint32_t C11Size = Mod.getC11LineInfoByteSize();
54 uint32_t C13Size = Mod.getC13LineInfoByteSize();
55
56 if (C11Size > 0 && C13Size > 0)
57 return make_error<RawError>(raw_error_code::corrupt_file,
58 "Module has both C11 and C13 line info");
59
61
62 if (auto EC = Reader.readInteger(Signature))
63 return EC;
64 Reader.setOffset(0);
65 if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize))
66 return EC;
67 if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
68 return EC;
69 if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
70 return EC;
71
72 BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
73 if (auto EC = SymbolReader.readArray(
74 SymbolArray, SymbolReader.bytesRemaining(), sizeof(uint32_t)))
75 return EC;
76
77 BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
78 if (auto EC = SubsectionsReader.readArray(Subsections,
79 SubsectionsReader.bytesRemaining()))
80 return EC;
81
82 uint32_t GlobalRefsSize;
83 if (auto EC = Reader.readInteger(GlobalRefsSize))
84 return EC;
85 if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
86 return EC;
87 return Error::success();
88}
89
92 return limitSymbolArrayToScope(SymbolArray, ScopeBegin);
93}
94
96 return SymbolsSubstream;
97}
98
100 return C11LinesSubstream;
101}
102
104 return C13LinesSubstream;
105}
106
108 return GlobalRefsSubstream;
109}
110
112ModuleDebugStreamRef::symbols(bool *HadError) const {
113 return make_range(SymbolArray.begin(HadError), SymbolArray.end());
114}
115
117 auto Iter = SymbolArray.at(Offset);
118 assert(Iter != SymbolArray.end());
119 return *Iter;
120}
121
124 return make_range(Subsections.begin(), Subsections.end());
125}
126
128 return !C13LinesSubstream.empty();
129}
130
132
136 for (const auto &SS : subsections()) {
137 if (SS.kind() != DebugSubsectionKind::FileChecksums)
138 continue;
139
140 if (auto EC = Result.initialize(SS.getRecordData()))
141 return std::move(EC);
142 return Result;
143 }
144 return Result;
145}
Lightweight arrays that are backed by an arbitrary BinaryStream.
Module * Mod
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Provides read only access to a subclass of BinaryStream.
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.
uint64_t bytesRemaining() const
void setOffset(uint64_t Off)
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
Iterator end() const
Iterator begin(bool *HadError=nullptr) const
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
A range adaptor for a pair of iterators.
iterator_range< codeview::CVSymbolArray::Iterator > symbols(bool *HadError) const
codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const
BinarySubstreamRef getSymbolsSubstream() const
BinarySubstreamRef getGlobalRefsSubstream() const
Expected< codeview::DebugChecksumsSubsectionRef > findChecksumsSubsection() const
ModuleDebugStreamRef(const DbiModuleDescriptor &Module, std::unique_ptr< msf::MappedBlockStream > Stream)
BinarySubstreamRef getC11LinesSubstream() const
BinarySubstreamRef getC13LinesSubstream() const
const codeview::CVSymbolArray getSymbolArrayForScope(uint32_t ScopeBegin) const
iterator_range< DebugSubsectionIterator > subsections() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin)
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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:1858
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
BinaryStreamRef StreamData