• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ModStream.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 
10 #include "llvm/DebugInfo/PDB/Raw/ModStream.h"
11 
12 #include "llvm/DebugInfo/CodeView/StreamReader.h"
13 #include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h"
14 #include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
15 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
16 #include "llvm/DebugInfo/PDB/Raw/RawError.h"
17 #include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
18 
19 using namespace llvm;
20 using namespace llvm::pdb;
21 
ModStream(const ModInfo & Module,std::unique_ptr<MappedBlockStream> Stream)22 ModStream::ModStream(const ModInfo &Module,
23                      std::unique_ptr<MappedBlockStream> Stream)
24     : Mod(Module), Stream(std::move(Stream)) {}
25 
~ModStream()26 ModStream::~ModStream() {}
27 
reload()28 Error ModStream::reload() {
29   codeview::StreamReader Reader(*Stream);
30 
31   uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
32   uint32_t C11Size = Mod.getLineInfoByteSize();
33   uint32_t C13Size = Mod.getC13LineInfoByteSize();
34 
35   if (C11Size > 0 && C13Size > 0)
36     return llvm::make_error<RawError>(raw_error_code::corrupt_file,
37                                       "Module has both C11 and C13 line info");
38 
39   codeview::StreamRef S;
40 
41   uint32_t SymbolSubstreamSig = 0;
42   if (auto EC = Reader.readInteger(SymbolSubstreamSig))
43     return EC;
44   if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
45     return EC;
46 
47   if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size))
48     return EC;
49   if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
50     return EC;
51 
52   codeview::StreamReader LineReader(C13LinesSubstream);
53   if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining()))
54     return EC;
55 
56   uint32_t GlobalRefsSize;
57   if (auto EC = Reader.readInteger(GlobalRefsSize))
58     return EC;
59   if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
60     return EC;
61   if (Reader.bytesRemaining() > 0)
62     return llvm::make_error<RawError>(raw_error_code::corrupt_file,
63                                       "Unexpected bytes in module stream.");
64 
65   return Error::success();
66 }
67 
68 iterator_range<codeview::CVSymbolArray::Iterator>
symbols(bool * HadError) const69 ModStream::symbols(bool *HadError) const {
70   // It's OK if the stream is empty.
71   if (SymbolsSubstream.getUnderlyingStream().getLength() == 0)
72     return llvm::make_range(SymbolsSubstream.end(), SymbolsSubstream.end());
73   return llvm::make_range(SymbolsSubstream.begin(HadError),
74                           SymbolsSubstream.end());
75 }
76 
77 iterator_range<codeview::ModuleSubstreamArray::Iterator>
lines(bool * HadError) const78 ModStream::lines(bool *HadError) const {
79   return llvm::make_range(LineInfo.begin(HadError), LineInfo.end());
80 }
81 
commit()82 Error ModStream::commit() { return Error::success(); }
83