LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB/Native - ModuleDebugStream.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 39 55 70.9 %
Date: 2017-09-14 15:23:50 Functions: 8 11 72.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      10             : #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
      11             : #include "llvm/ADT/iterator_range.h"
      12             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      13             : #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
      14             : #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
      15             : #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h"
      16             : #include "llvm/DebugInfo/PDB/Native/RawError.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::codeview;
      25             : using namespace llvm::msf;
      26             : using namespace llvm::pdb;
      27             : 
      28         308 : ModuleDebugStreamRef::ModuleDebugStreamRef(
      29             :     const DbiModuleDescriptor &Module,
      30         308 :     std::unique_ptr<MappedBlockStream> Stream)
      31        2464 :     : Mod(Module), Stream(std::move(Stream)) {}
      32             : 
      33             : ModuleDebugStreamRef::~ModuleDebugStreamRef() = default;
      34             : 
      35         308 : Error ModuleDebugStreamRef::reload() {
      36         924 :   BinaryStreamReader Reader(*Stream);
      37             : 
      38         308 :   uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
      39         308 :   uint32_t C11Size = Mod.getC11LineInfoByteSize();
      40         308 :   uint32_t C13Size = Mod.getC13LineInfoByteSize();
      41             : 
      42         308 :   if (C11Size > 0 && C13Size > 0)
      43             :     return make_error<RawError>(raw_error_code::corrupt_file,
      44           0 :                                 "Module has both C11 and C13 line info");
      45             : 
      46         308 :   BinaryStreamRef S;
      47             : 
      48         924 :   if (auto EC = Reader.readInteger(Signature))
      49           0 :     return EC;
      50         924 :   if (auto EC = Reader.readSubstream(SymbolsSubstream, SymbolSize - 4))
      51           0 :     return EC;
      52         924 :   if (auto EC = Reader.readSubstream(C11LinesSubstream, C11Size))
      53           0 :     return EC;
      54         924 :   if (auto EC = Reader.readSubstream(C13LinesSubstream, C13Size))
      55           0 :     return EC;
      56             : 
      57         924 :   BinaryStreamReader SymbolReader(SymbolsSubstream.StreamData);
      58         308 :   if (auto EC =
      59         924 :           SymbolReader.readArray(SymbolArray, SymbolReader.bytesRemaining()))
      60           0 :     return EC;
      61             : 
      62         924 :   BinaryStreamReader SubsectionsReader(C13LinesSubstream.StreamData);
      63         308 :   if (auto EC = SubsectionsReader.readArray(Subsections,
      64         924 :                                             SubsectionsReader.bytesRemaining()))
      65           0 :     return EC;
      66             : 
      67             :   uint32_t GlobalRefsSize;
      68         924 :   if (auto EC = Reader.readInteger(GlobalRefsSize))
      69           0 :     return EC;
      70         924 :   if (auto EC = Reader.readSubstream(GlobalRefsSubstream, GlobalRefsSize))
      71           0 :     return EC;
      72         308 :   if (Reader.bytesRemaining() > 0)
      73             :     return make_error<RawError>(raw_error_code::corrupt_file,
      74           0 :                                 "Unexpected bytes in module stream.");
      75             : 
      76         924 :   return Error::success();
      77             : }
      78             : 
      79          30 : BinarySubstreamRef ModuleDebugStreamRef::getSymbolsSubstream() const {
      80          60 :   return SymbolsSubstream;
      81             : }
      82             : 
      83           0 : BinarySubstreamRef ModuleDebugStreamRef::getC11LinesSubstream() const {
      84           0 :   return C11LinesSubstream;
      85             : }
      86             : 
      87           4 : BinarySubstreamRef ModuleDebugStreamRef::getC13LinesSubstream() const {
      88           8 :   return C13LinesSubstream;
      89             : }
      90             : 
      91           0 : BinarySubstreamRef ModuleDebugStreamRef::getGlobalRefsSubstream() const {
      92           0 :   return GlobalRefsSubstream;
      93             : }
      94             : 
      95             : iterator_range<codeview::CVSymbolArray::Iterator>
      96          19 : ModuleDebugStreamRef::symbols(bool *HadError) const {
      97          95 :   return make_range(SymbolArray.begin(HadError), SymbolArray.end());
      98             : }
      99             : 
     100             : iterator_range<ModuleDebugStreamRef::DebugSubsectionIterator>
     101          13 : ModuleDebugStreamRef::subsections() const {
     102          39 :   return make_range(Subsections.begin(), Subsections.end());
     103             : }
     104             : 
     105           7 : bool ModuleDebugStreamRef::hasDebugSubsections() const {
     106          14 :   return !C13LinesSubstream.empty();
     107             : }
     108             : 
     109           0 : Error ModuleDebugStreamRef::commit() { return Error::success(); }
     110             : 
     111             : Expected<codeview::DebugChecksumsSubsectionRef>
     112           6 : ModuleDebugStreamRef::findChecksumsSubsection() const {
     113          12 :   codeview::DebugChecksumsSubsectionRef Result;
     114          32 :   for (const auto &SS : subsections()) {
     115          11 :     if (SS.kind() != DebugSubsectionKind::FileChecksums)
     116             :       continue;
     117             : 
     118          12 :     if (auto EC = Result.initialize(SS.getRecordData()))
     119           0 :       return std::move(EC);
     120             :     return Result;
     121             :   }
     122             :   return Result;
     123             : }

Generated by: LCOV version 1.13