LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB/Native - ModStream.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 27 38 71.1 %
Date: 2017-04-27 17:53:54 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13