Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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
9#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
10#include "llvm/ADT/iterator_range.h"
11#include "llvm/DebugInfo/CodeView/CodeView.h"
12#include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
13#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
14#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
15#include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
16#include "llvm/DebugInfo/PDB/Native/RawConstants.h"
17#include "llvm/DebugInfo/PDB/Native/RawError.h"
18#include "llvm/Support/BinaryStreamArray.h"
19#include "llvm/Support/BinaryStreamReader.h"
20#include "llvm/Support/BinaryStreamRef.h"
21#include "llvm/Support/Error.h"
22#include <cstdint>
23
24using namespacellvm;
25using namespacellvm::codeview;
26using namespacellvm::msf;
27using namespacellvm::pdb;
28
29ModuleDebugStreamRef::ModuleDebugStreamRef(
30constDbiModuleDescriptor &Module,
31 std::unique_ptr<MappedBlockStream> Stream)
32 :Mod(Module), Stream(std::move(Stream)) {}
33
34ModuleDebugStreamRef::~ModuleDebugStreamRef() =default;
35
36ErrorModuleDebugStreamRef::reload() {
37BinaryStreamReader Reader(*Stream);
38
39if (Mod.getModuleStreamIndex() !=llvm::pdb::kInvalidStreamIndex) {
40if (Error E = reloadSerialize(Reader))
41return E;
42 }
43if (Reader.bytesRemaining() > 0)
44return make_error<RawError>(raw_error_code::corrupt_file,
45"Unexpected bytes in module stream.");
46returnError::success();
47}
48
49Error ModuleDebugStreamRef::reloadSerialize(BinaryStreamReader &Reader) {
50uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
51uint32_t C11Size = Mod.getC11LineInfoByteSize();
52uint32_t C13Size = Mod.getC13LineInfoByteSize();
53
54if (C11Size > 0 && C13Size > 0)
55return make_error<RawError>(raw_error_code::corrupt_file,
56"Module has both C11 and C13 line info");
57
58BinaryStreamRef S;
59
60if (autoEC = Reader.readInteger(Signature))
61returnEC;
62 Reader.setOffset(0);
63if (autoEC = Reader.readSubstream(SymbolsSubstream, SymbolSize))
64returnEC;
65if (autoEC = Reader.readSubstream(C11LinesSubstream, C11Size))
66returnEC;
67if (autoEC = Reader.readSubstream(C13LinesSubstream, C13Size))
68returnEC;
69
70BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
71if (autoEC = SymbolReader.readArray(
72 SymbolArray, SymbolReader.bytesRemaining(),sizeof(uint32_t)))
73returnEC;
74
75BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
76if (autoEC = SubsectionsReader.readArray(Subsections,
77 SubsectionsReader.bytesRemaining()))
78returnEC;
79
80uint32_t GlobalRefsSize;
81if (autoEC = Reader.readInteger(GlobalRefsSize))
82returnEC;
83if (autoEC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
84returnEC;
85returnError::success();
86}
87
88constcodeview::CVSymbolArray
89ModuleDebugStreamRef::getSymbolArrayForScope(uint32_t ScopeBegin) const{
90returnlimitSymbolArrayToScope(SymbolArray, ScopeBegin);
91}
92
93BinarySubstreamRefModuleDebugStreamRef::getSymbolsSubstream() const{
94return SymbolsSubstream;
95}
96
97BinarySubstreamRefModuleDebugStreamRef::getC11LinesSubstream() const{
98return C11LinesSubstream;
99}
100
101BinarySubstreamRefModuleDebugStreamRef::getC13LinesSubstream() const{
102return C13LinesSubstream;
103}
104
105BinarySubstreamRefModuleDebugStreamRef::getGlobalRefsSubstream() const{
106return GlobalRefsSubstream;
107}
108
109iterator_range<codeview::CVSymbolArray::Iterator>
110ModuleDebugStreamRef::symbols(bool *HadError) const{
111returnmake_range(SymbolArray.begin(HadError), SymbolArray.end());
112}
113
114CVSymbolModuleDebugStreamRef::readSymbolAtOffset(uint32_tOffset) const{
115auto Iter = SymbolArray.at(Offset);
116assert(Iter != SymbolArray.end());
117return *Iter;
118}
119
120iterator_range<ModuleDebugStreamRef::DebugSubsectionIterator>
121ModuleDebugStreamRef::subsections() const{
122returnmake_range(Subsections.begin(), Subsections.end());
123}
124
125boolModuleDebugStreamRef::hasDebugSubsections() const{
126return !C13LinesSubstream.empty();
127}
128
129ErrorModuleDebugStreamRef::commit() {returnError::success(); }
130
131Expected<codeview::DebugChecksumsSubsectionRef>
132ModuleDebugStreamRef::findChecksumsSubsection() const{
133codeview::DebugChecksumsSubsectionRef Result;
134for (constauto &SS :subsections()) {
135if (SS.kind() != DebugSubsectionKind::FileChecksums)
136continue;
137
138if (autoEC = Result.initialize(SS.getRecordData()))
139return std::move(EC);
140return Result;
141 }
142return Result;
143}
BinaryStreamArray.h
Lightweight arrays that are backed by an arbitrary BinaryStream.
BinaryStreamReader.h
BinaryStreamRef.h
CodeView.h
DbiModuleDescriptor.h
DebugChecksumsSubsection.h
MappedBlockStream.h
ModuleDebugStream.h
Mod
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
Definition:PassBuilderBindings.cpp:95
RawConstants.h
RawError.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SymbolRecordHelpers.h
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition:BinaryStreamReader.h:29
llvm::BinaryStreamReader::readSubstream
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Definition:BinaryStreamReader.cpp:141
llvm::BinaryStreamReader::readInteger
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
Definition:BinaryStreamReader.h:67
llvm::BinaryStreamReader::bytesRemaining
uint64_t bytesRemaining() const
Definition:BinaryStreamReader.h:248
llvm::BinaryStreamReader::setOffset
void setOffset(uint64_t Off)
Definition:BinaryStreamReader.h:245
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition:BinaryStreamRef.h:154
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::VarStreamArray< CVSymbol >
llvm::VarStreamArray::at
Iterator at(uint32_t Offset) const
given an offset into the array's underlying stream, return an iterator to the record at that offset.
Definition:BinaryStreamArray.h:134
llvm::VarStreamArray::end
Iterator end() const
Definition:BinaryStreamArray.h:117
llvm::VarStreamArray::begin
Iterator begin(bool *HadError=nullptr) const
Definition:BinaryStreamArray.h:108
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition:CVRecord.h:29
llvm::codeview::DebugChecksumsSubsectionRef
Definition:DebugChecksumsSubsection.h:51
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition:iterator_range.h:42
llvm::pdb::DbiModuleDescriptor
Definition:DbiModuleDescriptor.h:23
llvm::pdb::DbiModuleDescriptor::getSymbolDebugInfoByteSize
uint32_t getSymbolDebugInfoByteSize() const
Definition:DbiModuleDescriptor.cpp:51
llvm::pdb::DbiModuleDescriptor::getC13LineInfoByteSize
uint32_t getC13LineInfoByteSize() const
Definition:DbiModuleDescriptor.cpp:59
llvm::pdb::DbiModuleDescriptor::getModuleStreamIndex
uint16_t getModuleStreamIndex() const
Definition:DbiModuleDescriptor.cpp:47
llvm::pdb::DbiModuleDescriptor::getC11LineInfoByteSize
uint32_t getC11LineInfoByteSize() const
Definition:DbiModuleDescriptor.cpp:55
llvm::pdb::ModuleDebugStreamRef::reload
Error reload()
Definition:ModuleDebugStream.cpp:36
llvm::pdb::ModuleDebugStreamRef::symbols
iterator_range< codeview::CVSymbolArray::Iterator > symbols(bool *HadError) const
Definition:ModuleDebugStream.cpp:110
llvm::pdb::ModuleDebugStreamRef::readSymbolAtOffset
codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const
Definition:ModuleDebugStream.cpp:114
llvm::pdb::ModuleDebugStreamRef::hasDebugSubsections
bool hasDebugSubsections() const
Definition:ModuleDebugStream.cpp:125
llvm::pdb::ModuleDebugStreamRef::getSymbolsSubstream
BinarySubstreamRef getSymbolsSubstream() const
Definition:ModuleDebugStream.cpp:93
llvm::pdb::ModuleDebugStreamRef::commit
Error commit()
Definition:ModuleDebugStream.cpp:129
llvm::pdb::ModuleDebugStreamRef::getGlobalRefsSubstream
BinarySubstreamRef getGlobalRefsSubstream() const
Definition:ModuleDebugStream.cpp:105
llvm::pdb::ModuleDebugStreamRef::findChecksumsSubsection
Expected< codeview::DebugChecksumsSubsectionRef > findChecksumsSubsection() const
Definition:ModuleDebugStream.cpp:132
llvm::pdb::ModuleDebugStreamRef::ModuleDebugStreamRef
ModuleDebugStreamRef(const DbiModuleDescriptor &Module, std::unique_ptr< msf::MappedBlockStream > Stream)
llvm::pdb::ModuleDebugStreamRef::getC11LinesSubstream
BinarySubstreamRef getC11LinesSubstream() const
Definition:ModuleDebugStream.cpp:97
llvm::pdb::ModuleDebugStreamRef::getC13LinesSubstream
BinarySubstreamRef getC13LinesSubstream() const
Definition:ModuleDebugStream.cpp:101
llvm::pdb::ModuleDebugStreamRef::getSymbolArrayForScope
const codeview::CVSymbolArray getSymbolArrayForScope(uint32_t ScopeBegin) const
Definition:ModuleDebugStream.cpp:89
llvm::pdb::ModuleDebugStreamRef::~ModuleDebugStreamRef
~ModuleDebugStreamRef()
llvm::pdb::ModuleDebugStreamRef::subsections
iterator_range< DebugSubsectionIterator > subsections() const
Definition:ModuleDebugStream.cpp:121
uint32_t
iterator_range.h
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Error.h
llvm::codeview
Definition:AppendingTypeTableBuilder.h:22
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::codeview::limitSymbolArrayToScope
CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin)
Definition:SymbolRecordHelpers.cpp:85
llvm::msf
Definition:IMSFFile.h:18
llvm::pdb
Definition:LVCodeViewReader.h:44
llvm::pdb::kInvalidStreamIndex
const uint16_t kInvalidStreamIndex
Definition:RawConstants.h:19
llvm::pdb::raw_error_code::corrupt_file
@ corrupt_file
llvm::pdb::PDB_ColorItem::Offset
@ Offset
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition:iterator_range.h:77
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:1873
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
llvm::BinarySubstreamRef
Definition:BinaryStreamRef.h:196
llvm::BinarySubstreamRef::empty
bool empty() const
Definition:BinaryStreamRef.h:214
llvm::BinarySubstreamRef::StreamData
BinaryStreamRef StreamData
Definition:BinaryStreamRef.h:198

Generated on Fri Jul 18 2025 11:16:54 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp