LLVM  6.0.0svn
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 
19 #include "llvm/Support/Error.h"
20 #include <algorithm>
21 #include <cstdint>
22 
23 using namespace llvm;
24 using namespace llvm::codeview;
25 using namespace llvm::msf;
26 using namespace llvm::pdb;
27 
28 ModuleDebugStreamRef::ModuleDebugStreamRef(
30  std::unique_ptr<MappedBlockStream> Stream)
31  : Mod(Module), Stream(std::move(Stream)) {}
32 
34 
36  BinaryStreamReader Reader(*Stream);
37 
38  uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
39  uint32_t C11Size = Mod.getC11LineInfoByteSize();
40  uint32_t C13Size = Mod.getC13LineInfoByteSize();
41 
42  if (C11Size > 0 && C13Size > 0)
43  return make_error<RawError>(raw_error_code::corrupt_file,
44  "Module has both C11 and C13 line info");
45 
47 
48  if (auto EC = Reader.readInteger(Signature))
49  return EC;
50  if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize - 4))
51  return EC;
52  if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
53  return EC;
54  if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
55  return EC;
56 
57  BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
58  if (auto EC =
59  SymbolReader.readArray(SymbolArray, SymbolReader.bytesRemaining()))
60  return EC;
61 
62  BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
63  if (auto EC = SubsectionsReader.readArray(Subsections,
64  SubsectionsReader.bytesRemaining()))
65  return EC;
66 
67  uint32_t GlobalRefsSize;
68  if (auto EC = Reader.readInteger(GlobalRefsSize))
69  return EC;
70  if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
71  return EC;
72  if (Reader.bytesRemaining() > 0)
73  return make_error<RawError>(raw_error_code::corrupt_file,
74  "Unexpected bytes in module stream.");
75 
76  return Error::success();
77 }
78 
80  return SymbolsSubstream;
81 }
82 
84  return C11LinesSubstream;
85 }
86 
88  return C13LinesSubstream;
89 }
90 
92  return GlobalRefsSubstream;
93 }
94 
96 ModuleDebugStreamRef::symbols(bool *HadError) const {
97  return make_range(SymbolArray.begin(HadError), SymbolArray.end());
98 }
99 
102  return make_range(Subsections.begin(), Subsections.end());
103 }
104 
106  return !C13LinesSubstream.empty();
107 }
108 
110 
114  for (const auto &SS : subsections()) {
115  if (SS.kind() != DebugSubsectionKind::FileChecksums)
116  continue;
117 
118  if (auto EC = Result.initialize(SS.getRecordData()))
119  return std::move(EC);
120  return Result;
121  }
122  return Result;
123 }
Error readSubstream(BinarySubstreamRef &Stream, uint32_t Size)
Read Length bytes from the underlying stream into Stream.
Compute iterated dominance frontiers using a linear time algorithm.
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:63
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
Definition: BitVector.h:920
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.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:313
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
BinarySubstreamRef getC11LinesSubstream() const
BinarySubstreamRef getSymbolsSubstream() const
A range adaptor for a pair of iterators.
BinarySubstreamRef getGlobalRefsSubstream() const
uint32_t bytesRemaining() const
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
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 ...