LLVM  13.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 <algorithm>
23 #include <cstdint>
24 
25 using namespace llvm;
26 using namespace llvm::codeview;
27 using namespace llvm::msf;
28 using namespace llvm::pdb;
29 
30 ModuleDebugStreamRef::ModuleDebugStreamRef(
32  std::unique_ptr<MappedBlockStream> Stream)
33  : Mod(Module), Stream(std::move(Stream)) {}
34 
36 
38  BinaryStreamReader Reader(*Stream);
39 
41  if (Error E = reloadSerialize(Reader))
42  return E;
43  }
44  if (Reader.bytesRemaining() > 0)
45  return make_error<RawError>(raw_error_code::corrupt_file,
46  "Unexpected bytes in module stream.");
47  return Error::success();
48 }
49 
50 Error ModuleDebugStreamRef::reloadSerialize(BinaryStreamReader &Reader) {
51  uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
52  uint32_t C11Size = Mod.getC11LineInfoByteSize();
53  uint32_t C13Size = Mod.getC13LineInfoByteSize();
54 
55  if (C11Size > 0 && C13Size > 0)
56  return make_error<RawError>(raw_error_code::corrupt_file,
57  "Module has both C11 and C13 line info");
58 
60 
61  if (auto EC = Reader.readInteger(Signature))
62  return EC;
63  Reader.setOffset(0);
64  if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize))
65  return EC;
66  if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
67  return EC;
68  if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
69  return EC;
70 
71  BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
72  if (auto EC = SymbolReader.readArray(
73  SymbolArray, SymbolReader.bytesRemaining(), sizeof(uint32_t)))
74  return EC;
75 
76  BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
77  if (auto EC = SubsectionsReader.readArray(Subsections,
78  SubsectionsReader.bytesRemaining()))
79  return EC;
80 
81  uint32_t GlobalRefsSize;
82  if (auto EC = Reader.readInteger(GlobalRefsSize))
83  return EC;
84  if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
85  return EC;
86  return Error::success();
87 }
88 
91  return limitSymbolArrayToScope(SymbolArray, ScopeBegin);
92 }
93 
95  return SymbolsSubstream;
96 }
97 
99  return C11LinesSubstream;
100 }
101 
103  return C13LinesSubstream;
104 }
105 
107  return GlobalRefsSubstream;
108 }
109 
111 ModuleDebugStreamRef::symbols(bool *HadError) const {
112  return make_range(SymbolArray.begin(HadError), SymbolArray.end());
113 }
114 
116  auto Iter = SymbolArray.at(Offset);
117  assert(Iter != SymbolArray.end());
118  return *Iter;
119 }
120 
123  return make_range(Subsections.begin(), Subsections.end());
124 }
125 
127  return !C13LinesSubstream.empty();
128 }
129 
131 
135  for (const auto &SS : subsections()) {
136  if (SS.kind() != DebugSubsectionKind::FileChecksums)
137  continue;
138 
139  if (auto EC = Result.initialize(SS.getRecordData()))
140  return std::move(EC);
141  return Result;
142  }
143  return Result;
144 }
llvm::pdb::ModuleDebugStreamRef::getGlobalRefsSubstream
BinarySubstreamRef getGlobalRefsSubstream() const
Definition: ModuleDebugStream.cpp:106
BinaryStreamReader.h
llvm::pdb::ModuleDebugStreamRef::subsections
iterator_range< DebugSubsectionIterator > subsections() const
Definition: ModuleDebugStream.cpp:122
llvm::BinaryStreamReader::bytesRemaining
uint32_t bytesRemaining() const
Definition: BinaryStreamReader.h:257
RawConstants.h
llvm
Definition: AllocatorList.h:23
llvm::pdb::ModuleDebugStreamRef::getSymbolArrayForScope
const codeview::CVSymbolArray getSymbolArrayForScope(uint32_t ScopeBegin) const
Definition: ModuleDebugStream.cpp:90
llvm::pdb::ModuleDebugStreamRef::commit
Error commit()
Definition: ModuleDebugStream.cpp:130
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:115
llvm::pdb::ModuleDebugStreamRef::getC13LinesSubstream
BinarySubstreamRef getC13LinesSubstream() const
Definition: ModuleDebugStream.cpp:102
SymbolRecord.h
DbiModuleDescriptor.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::BinaryStreamReader::setOffset
void setOffset(uint32_t Off)
Definition: BinaryStreamReader.h:254
llvm::pdb::kInvalidStreamIndex
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
Error.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::VarStreamArray::end
Iterator end() const
Definition: BinaryStreamArray.h:115
llvm::pdb::ModuleDebugStreamRef::findChecksumsSubsection
Expected< codeview::DebugChecksumsSubsectionRef > findChecksumsSubsection() const
Definition: ModuleDebugStream.cpp:133
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::pdb::ModuleDebugStreamRef::symbols
iterator_range< codeview::CVSymbolArray::Iterator > symbols(bool *HadError) const
Definition: ModuleDebugStream.cpp:111
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:200
SymbolDeserializer.h
llvm::VarStreamArray< CVSymbol >
llvm::BinarySubstreamRef::StreamData
BinaryStreamRef StreamData
Definition: BinaryStreamRef.h:202
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:75
llvm::pdb::ModuleDebugStreamRef::getSymbolsSubstream
BinarySubstreamRef getSymbolsSubstream() const
Definition: ModuleDebugStream.cpp:94
CodeView.h
llvm::pdb
Definition: ConcreteSymbolEnumerator.h:20
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::pdb::ModuleDebugStreamRef::reload
Error reload()
Definition: ModuleDebugStream.cpp:37
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
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:1540
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:67
BinaryStreamRef.h
llvm::codeview::CVRecord
CVRecord is a fat pointer (base + size pair) to a symbol or type record.
Definition: CVRecord.h:30
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
llvm::X86AS::SS
@ SS
Definition: X86.h:189
llvm::VarStreamArray::begin
Iterator begin(bool *HadError=nullptr) const
Definition: BinaryStreamArray.h:108
std
Definition: BitVector.h:838
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:126
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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:98
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
llvm::pdb::DbiModuleDescriptor
Definition: DbiModuleDescriptor.h:23
llvm::BinarySubstreamRef::empty
bool empty() const
Definition: BinaryStreamRef.h:219
llvm::codeview::DebugChecksumsSubsectionRef
Definition: DebugChecksumsSubsection.h:49
SymbolRecordHelpers.h
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156