LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - DebugInlineeLinesSubsection.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 42 62 67.7 %
Date: 2017-09-14 15:23:50 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DebugInlineeLinesSubsection.cpp ------------------------------------===//
       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/CodeView/DebugInlineeLinesSubsection.h"
      11             : #include "llvm/ADT/ArrayRef.h"
      12             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      13             : #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
      14             : #include "llvm/Support/BinaryStreamReader.h"
      15             : #include "llvm/Support/BinaryStreamWriter.h"
      16             : #include "llvm/Support/Endian.h"
      17             : #include "llvm/Support/Error.h"
      18             : #include <cassert>
      19             : #include <cstdint>
      20             : 
      21             : using namespace llvm;
      22             : using namespace llvm::codeview;
      23             : 
      24          22 : Error VarStreamArrayExtractor<InlineeSourceLine>::
      25             : operator()(BinaryStreamRef Stream, uint32_t &Len, InlineeSourceLine &Item) {
      26          66 :   BinaryStreamReader Reader(Stream);
      27             : 
      28          66 :   if (auto EC = Reader.readObject(Item.Header))
      29           0 :     return EC;
      30             : 
      31          22 :   if (HasExtraFiles) {
      32             :     uint32_t ExtraFileCount;
      33           9 :     if (auto EC = Reader.readInteger(ExtraFileCount))
      34           0 :       return EC;
      35           9 :     if (auto EC = Reader.readArray(Item.ExtraFiles, ExtraFileCount))
      36           0 :       return EC;
      37             :   }
      38             : 
      39          22 :   Len = Reader.getOffset();
      40          66 :   return Error::success();
      41             : }
      42             : 
      43          14 : DebugInlineeLinesSubsectionRef::DebugInlineeLinesSubsectionRef()
      44          42 :     : DebugSubsectionRef(DebugSubsectionKind::InlineeLines) {}
      45             : 
      46          12 : Error DebugInlineeLinesSubsectionRef::initialize(BinaryStreamReader Reader) {
      47          36 :   if (auto EC = Reader.readEnum(Signature))
      48           0 :     return EC;
      49             : 
      50          12 :   Lines.getExtractor().HasExtraFiles = hasExtraFiles();
      51          36 :   if (auto EC = Reader.readArray(Lines, Reader.bytesRemaining()))
      52           0 :     return EC;
      53             : 
      54             :   assert(Reader.bytesRemaining() == 0);
      55          36 :   return Error::success();
      56             : }
      57             : 
      58          35 : bool DebugInlineeLinesSubsectionRef::hasExtraFiles() const {
      59          35 :   return Signature == InlineeLinesSignature::ExtraFiles;
      60             : }
      61             : 
      62           1 : DebugInlineeLinesSubsection::DebugInlineeLinesSubsection(
      63           1 :     DebugChecksumsSubsection &Checksums, bool HasExtraFiles)
      64             :     : DebugSubsection(DebugSubsectionKind::InlineeLines), Checksums(Checksums),
      65           3 :       HasExtraFiles(HasExtraFiles) {}
      66             : 
      67           3 : uint32_t DebugInlineeLinesSubsection::calculateSerializedSize() const {
      68             :   // 4 bytes for the signature
      69           3 :   uint32_t Size = sizeof(InlineeLinesSignature);
      70             : 
      71             :   // one header for each entry.
      72           6 :   Size += Entries.size() * sizeof(InlineeSourceLineHeader);
      73           3 :   if (HasExtraFiles) {
      74             :     // If extra files are enabled, one count for each entry.
      75           0 :     Size += Entries.size() * sizeof(uint32_t);
      76             : 
      77             :     // And one file id for each file.
      78           0 :     Size += ExtraFileCount * sizeof(uint32_t);
      79             :   }
      80             :   assert(Size % 4 == 0);
      81           3 :   return Size;
      82             : }
      83             : 
      84           1 : Error DebugInlineeLinesSubsection::commit(BinaryStreamWriter &Writer) const {
      85           1 :   InlineeLinesSignature Sig = InlineeLinesSignature::Normal;
      86           1 :   if (HasExtraFiles)
      87           0 :     Sig = InlineeLinesSignature::ExtraFiles;
      88             : 
      89           3 :   if (auto EC = Writer.writeEnum(Sig))
      90           0 :     return EC;
      91             : 
      92           5 :   for (const auto &E : Entries) {
      93           4 :     if (auto EC = Writer.writeObject(E.Header))
      94           0 :       return EC;
      95             : 
      96           1 :     if (!HasExtraFiles)
      97           1 :       continue;
      98             : 
      99           0 :     if (auto EC = Writer.writeInteger<uint32_t>(E.ExtraFiles.size()))
     100           0 :       return EC;
     101           0 :     if (auto EC = Writer.writeArray(makeArrayRef(E.ExtraFiles)))
     102           0 :       return EC;
     103             :   }
     104             : 
     105           3 :   return Error::success();
     106             : }
     107             : 
     108           0 : void DebugInlineeLinesSubsection::addExtraFile(StringRef FileName) {
     109           0 :   uint32_t Offset = Checksums.mapChecksumOffset(FileName);
     110             : 
     111           0 :   auto &Entry = Entries.back();
     112           0 :   Entry.ExtraFiles.push_back(ulittle32_t(Offset));
     113           0 :   ++ExtraFileCount;
     114           0 : }
     115             : 
     116           1 : void DebugInlineeLinesSubsection::addInlineSite(TypeIndex FuncId,
     117             :                                                 StringRef FileName,
     118             :                                                 uint32_t SourceLine) {
     119           1 :   uint32_t Offset = Checksums.mapChecksumOffset(FileName);
     120             : 
     121           1 :   Entries.emplace_back();
     122           2 :   auto &Entry = Entries.back();
     123           2 :   Entry.Header.FileID = Offset;
     124           2 :   Entry.Header.SourceLineNum = SourceLine;
     125           1 :   Entry.Header.Inlinee = FuncId;
     126           1 : }

Generated by: LCOV version 1.13