LLVM  8.0.1
ModuleDebugStream.cpp
Go to the documentation of this file.
1 //===- ModuleDebugStream.cpp - PDB Module Info Stream Access --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
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 
40  uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
41  uint32_t C11Size = Mod.getC11LineInfoByteSize();
42  uint32_t C13Size = Mod.getC13LineInfoByteSize();
43 
44  if (C11Size > 0 && C13Size > 0)
45  return make_error<RawError>(raw_error_code::corrupt_file,
46  "Module has both C11 and C13 line info");
47 
49 
50  if (auto EC = Reader.readInteger(Signature))
51  return EC;
52  Reader.setOffset(0);
53  if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize))
54  return EC;
55  if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
56  return EC;
57  if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
58  return EC;
59 
60  BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
61  if (auto EC = SymbolReader.readArray(
62  SymbolArray, SymbolReader.bytesRemaining(), sizeof(uint32_t)))
63  return EC;
64 
65  BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
66  if (auto EC = SubsectionsReader.readArray(Subsections,
67  SubsectionsReader.bytesRemaining()))
68  return EC;
69 
70  uint32_t GlobalRefsSize;
71  if (auto EC = Reader.readInteger(GlobalRefsSize))
72  return EC;
73  if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
74  return EC;
75  if (Reader.bytesRemaining() > 0)
76  return make_error<RawError>(raw_error_code::corrupt_file,
77  "Unexpected bytes in module stream.");
78 
79  return Error::success();
80 }
81 
84  return limitSymbolArrayToScope(SymbolArray, ScopeBegin);
85 }
86 
88  return SymbolsSubstream;
89 }
90 
92  return C11LinesSubstream;
93 }
94 
96  return C13LinesSubstream;
97 }
98 
100  return GlobalRefsSubstream;
101 }
102 
104 ModuleDebugStreamRef::symbols(bool *HadError) const {
105  return make_range(SymbolArray.begin(HadError), SymbolArray.end());
106 }
107 
109  auto Iter = SymbolArray.at(Offset);
110  assert(Iter != SymbolArray.end());
111  return *Iter;
112 }
113 
116  return make_range(Subsections.begin(), Subsections.end());
117 }
118 
120  return !C13LinesSubstream.empty();
121 }
122 
124 
128  for (const auto &SS : subsections()) {
129  if (SS.kind() != DebugSubsectionKind::FileChecksums)
130  continue;
131 
132  if (auto EC = Result.initialize(SS.getRecordData()))
133  return std::move(EC);
134  return Result;
135  }
136  return Result;
137 }
const codeview::CVSymbolArray getSymbolArrayForScope(uint32_t ScopeBegin) const
Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size)
Read Length bytes from the underlying stream into Stream.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream&#39;s offset.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
Expected< codeview::DebugChecksumsSubsectionRef > findChecksumsSubsection() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
BinarySubstreamRef getC13LinesSubstream() const
iterator_range< DebugSubsectionIterator > subsections() const
codeview::CVSymbol readSymbolAtOffset(uint32_t Offset) const
Definition: BitVector.h:938
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
iterator_range< codeview::CVSymbolArray::Iterator > symbols(bool *HadError) const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void setOffset(uint32_t Off)
static ErrorSuccess success()
Create a success value.
Definition: Error.h:327
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
BinarySubstreamRef getC11LinesSubstream() const
BinarySubstreamRef getSymbolsSubstream() const
The access may modify the value stored in memory.
A range adaptor for a pair of iterators.
CVSymbolArray limitSymbolArrayToScope(const CVSymbolArray &Symbols, uint32_t ScopeBegin)
BinarySubstreamRef getGlobalRefsSubstream() const
uint32_t bytesRemaining() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Provides read only access to a subclass of BinaryStream.
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...