LLVM  15.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 
26 using namespace llvm;
27 using namespace llvm::codeview;
28 using namespace llvm::msf;
29 using namespace llvm::pdb;
30 
31 ModuleDebugStreamRef::ModuleDebugStreamRef(
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 
51 Error 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 
112 ModuleDebugStreamRef::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 }
llvm::pdb::ModuleDebugStreamRef::getGlobalRefsSubstream
BinarySubstreamRef getGlobalRefsSubstream() const
Definition: ModuleDebugStream.cpp:107
BinaryStreamReader.h
llvm::pdb::ModuleDebugStreamRef::subsections
iterator_range< DebugSubsectionIterator > subsections() const
Definition: ModuleDebugStream.cpp:123
llvm::BinaryStreamReader::setOffset
void setOffset(uint64_t Off)
Definition: BinaryStreamReader.h:247
RawConstants.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::pdb::ModuleDebugStreamRef::getSymbolArrayForScope
const codeview::CVSymbolArray getSymbolArrayForScope(uint32_t ScopeBegin) const
Definition: ModuleDebugStream.cpp:91
llvm::pdb::ModuleDebugStreamRef::commit
Error commit()
Definition: ModuleDebugStream.cpp:131
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::pdb::ModuleDebugStreamRef::readSymbolAtOffset
codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const
Definition: ModuleDebugStream.cpp:116
llvm::pdb::ModuleDebugStreamRef::getC13LinesSubstream
BinarySubstreamRef getC13LinesSubstream() const
Definition: ModuleDebugStream.cpp:103
RawTypes.h
llvm::X86AS::SS
@ SS
Definition: X86.h:189
DbiModuleDescriptor.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::pdb::kInvalidStreamIndex
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
Error.h
llvm::BinaryStreamReader::bytesRemaining
uint64_t bytesRemaining() const
Definition: BinaryStreamReader.h:250
llvm::VarStreamArray::end
Iterator end() const
Definition: BinaryStreamArray.h:115
llvm::pdb::ModuleDebugStreamRef::findChecksumsSubsection
Expected< codeview::DebugChecksumsSubsectionRef > findChecksumsSubsection() const
Definition: ModuleDebugStream.cpp:134
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::pdb::ModuleDebugStreamRef::symbols
iterator_range< codeview::CVSymbolArray::Iterator > symbols(bool *HadError) const
Definition: ModuleDebugStream.cpp:112
RawError.h
llvm::pdb::ModuleDebugStreamRef::~ModuleDebugStreamRef
~ModuleDebugStreamRef()
llvm::msf
Definition: IMSFFile.h:18
DebugChecksumsSubsection.h
llvm::pdb::raw_error_code::corrupt_file
@ corrupt_file
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::BinarySubstreamRef
Definition: BinaryStreamRef.h:199
llvm::VarStreamArray< CVSymbol >
llvm::BinarySubstreamRef::StreamData
BinaryStreamRef StreamData
Definition: BinaryStreamRef.h:201
llvm::BinaryStreamReader::readSubstream
Error readSubstream(BinarySubstreamRef &Ref, uint32_t Length)
Read Length bytes from the underlying stream into Ref.
Definition: BinaryStreamReader.cpp:142
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:68
llvm::pdb::ModuleDebugStreamRef::getSymbolsSubstream
BinarySubstreamRef getSymbolsSubstream() const
Definition: ModuleDebugStream.cpp:95
CodeView.h
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:29
llvm::pdb::ModuleDebugStreamRef::reload
Error reload()
Definition: ModuleDebugStream.cpp:38
llvm::pdb::DbiModuleDescriptor::getSymbolDebugInfoByteSize
uint32_t getSymbolDebugInfoByteSize() const
Definition: DbiModuleDescriptor.cpp:52
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::DbiModuleDescriptor::getC11LineInfoByteSize
uint32_t getC11LineInfoByteSize() const
Definition: DbiModuleDescriptor.cpp:56
BinaryStreamArray.h
MappedBlockStream.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:1663
llvm::SPIRV::Decoration::Stream
@ Stream
llvm::codeview::CompileSym2Flags::EC
@ EC
iterator_range.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
BinaryStreamRef.h
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:29
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
MSFCommon.h
llvm::VarStreamArray::begin
Iterator begin(bool *HadError=nullptr) const
Definition: BinaryStreamArray.h:108
std
Definition: BitVector.h:851
llvm::codeview::limitSymbolArrayToScope
CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin)
Definition: SymbolRecordHelpers.cpp:85
llvm::pdb::ModuleDebugStreamRef::hasDebugSubsections
bool hasDebugSubsections() const
Definition: ModuleDebugStream.cpp:127
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::pdb::DbiModuleDescriptor::getModuleStreamIndex
uint16_t getModuleStreamIndex() const
Definition: DbiModuleDescriptor.cpp:48
ModuleDebugStream.h
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::pdb::DbiModuleDescriptor::getC13LineInfoByteSize
uint32_t getC13LineInfoByteSize() const
Definition: DbiModuleDescriptor.cpp:60
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
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:132
llvm::pdb::ModuleDebugStreamRef::getC11LinesSubstream
BinarySubstreamRef getC11LinesSubstream() const
Definition: ModuleDebugStream.cpp:99
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
llvm::pdb::DbiModuleDescriptor
Definition: DbiModuleDescriptor.h:23
llvm::BinarySubstreamRef::empty
bool empty() const
Definition: BinaryStreamRef.h:217
llvm::codeview::DebugChecksumsSubsectionRef
Definition: DebugChecksumsSubsection.h:51
SymbolRecordHelpers.h
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:155