LCOV - code coverage report
Current view: top level - lib/DebugInfo/CodeView - DebugLinesSubsection.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 78 89 87.6 %
Date: 2017-09-14 15:23:50 Functions: 14 14 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DebugLinesSubsection.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/DebugLinesSubsection.h"
      11             : #include "llvm/ADT/ArrayRef.h"
      12             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      13             : #include "llvm/DebugInfo/CodeView/CodeViewError.h"
      14             : #include "llvm/DebugInfo/CodeView/DebugChecksumsSubsection.h"
      15             : #include "llvm/Support/BinaryStreamReader.h"
      16             : #include "llvm/Support/BinaryStreamWriter.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         149 : Error LineColumnExtractor::operator()(BinaryStreamRef Stream, uint32_t &Len,
      25             :                                       LineColumnEntry &Item) {
      26             :   const LineBlockFragmentHeader *BlockHeader;
      27         447 :   BinaryStreamReader Reader(Stream);
      28         447 :   if (auto EC = Reader.readObject(BlockHeader))
      29           0 :     return EC;
      30         298 :   bool HasColumn = Header->Flags & uint16_t(LF_HaveColumns);
      31             :   uint32_t LineInfoSize =
      32         149 :       BlockHeader->NumLines *
      33         298 :       (sizeof(LineNumberEntry) + (HasColumn ? sizeof(ColumnNumberEntry) : 0));
      34         298 :   if (BlockHeader->BlockSize < sizeof(LineBlockFragmentHeader))
      35             :     return make_error<CodeViewError>(cv_error_code::corrupt_record,
      36           0 :                                      "Invalid line block record size");
      37         298 :   uint32_t Size = BlockHeader->BlockSize - sizeof(LineBlockFragmentHeader);
      38         149 :   if (LineInfoSize > Size)
      39             :     return make_error<CodeViewError>(cv_error_code::corrupt_record,
      40           0 :                                      "Invalid line block record size");
      41             :   // The value recorded in BlockHeader->BlockSize includes the size of
      42             :   // LineBlockFragmentHeader.
      43         298 :   Len = BlockHeader->BlockSize;
      44         149 :   Item.NameIndex = BlockHeader->NameIndex;
      45         596 :   if (auto EC = Reader.readArray(Item.LineNumbers, BlockHeader->NumLines))
      46           0 :     return EC;
      47         149 :   if (HasColumn) {
      48         296 :     if (auto EC = Reader.readArray(Item.Columns, BlockHeader->NumLines))
      49           0 :       return EC;
      50             :   }
      51         447 :   return Error::success();
      52             : }
      53             : 
      54         137 : DebugLinesSubsectionRef::DebugLinesSubsectionRef()
      55         411 :     : DebugSubsectionRef(DebugSubsectionKind::Lines) {}
      56             : 
      57         132 : Error DebugLinesSubsectionRef::initialize(BinaryStreamReader Reader) {
      58         396 :   if (auto EC = Reader.readObject(Header))
      59           0 :     return EC;
      60             : 
      61         132 :   LinesAndColumns.getExtractor().Header = Header;
      62         396 :   if (auto EC = Reader.readArray(LinesAndColumns, Reader.bytesRemaining()))
      63           0 :     return EC;
      64             : 
      65         396 :   return Error::success();
      66             : }
      67             : 
      68         398 : bool DebugLinesSubsectionRef::hasColumnInfo() const {
      69         796 :   return !!(Header->Flags & LF_HaveColumns);
      70             : }
      71             : 
      72          29 : DebugLinesSubsection::DebugLinesSubsection(DebugChecksumsSubsection &Checksums,
      73          29 :                                            DebugStringTableSubsection &Strings)
      74          87 :     : DebugSubsection(DebugSubsectionKind::Lines), Checksums(Checksums) {}
      75             : 
      76          29 : void DebugLinesSubsection::createBlock(StringRef FileName) {
      77          29 :   uint32_t Offset = Checksums.mapChecksumOffset(FileName);
      78             : 
      79          29 :   Blocks.emplace_back(Offset);
      80          29 : }
      81             : 
      82          66 : void DebugLinesSubsection::addLineInfo(uint32_t Offset, const LineInfo &Line) {
      83         132 :   Block &B = Blocks.back();
      84             :   LineNumberEntry LNE;
      85         132 :   LNE.Flags = Line.getRawData();
      86          66 :   LNE.Offset = Offset;
      87          66 :   B.Lines.push_back(LNE);
      88          66 : }
      89             : 
      90           1 : void DebugLinesSubsection::addLineAndColumnInfo(uint32_t Offset,
      91             :                                                 const LineInfo &Line,
      92             :                                                 uint32_t ColStart,
      93             :                                                 uint32_t ColEnd) {
      94           2 :   Block &B = Blocks.back();
      95             :   assert(B.Lines.size() == B.Columns.size());
      96             : 
      97           1 :   addLineInfo(Offset, Line);
      98             :   ColumnNumberEntry CNE;
      99           2 :   CNE.StartColumn = ColStart;
     100           2 :   CNE.EndColumn = ColEnd;
     101           1 :   B.Columns.push_back(CNE);
     102           1 : }
     103             : 
     104          29 : Error DebugLinesSubsection::commit(BinaryStreamWriter &Writer) const {
     105             :   LineFragmentHeader Header;
     106          58 :   Header.CodeSize = CodeSize;
     107          58 :   Header.Flags = hasColumnInfo() ? LF_HaveColumns : 0;
     108          58 :   Header.RelocOffset = RelocOffset;
     109          58 :   Header.RelocSegment = RelocSegment;
     110             : 
     111          87 :   if (auto EC = Writer.writeObject(Header))
     112           0 :     return EC;
     113             : 
     114         145 :   for (const auto &B : Blocks) {
     115             :     LineBlockFragmentHeader BlockHeader;
     116             :     assert(B.Lines.size() == B.Columns.size() || B.Columns.empty());
     117             : 
     118          87 :     BlockHeader.NumLines = B.Lines.size();
     119          29 :     BlockHeader.BlockSize = sizeof(LineBlockFragmentHeader);
     120          58 :     BlockHeader.BlockSize += BlockHeader.NumLines * sizeof(LineNumberEntry);
     121          29 :     if (hasColumnInfo())
     122           1 :       BlockHeader.BlockSize += BlockHeader.NumLines * sizeof(ColumnNumberEntry);
     123          58 :     BlockHeader.NameIndex = B.ChecksumBufferOffset;
     124          87 :     if (auto EC = Writer.writeObject(BlockHeader))
     125           0 :       return EC;
     126             : 
     127         116 :     if (auto EC = Writer.writeArray(makeArrayRef(B.Lines)))
     128           0 :       return EC;
     129             : 
     130          29 :     if (hasColumnInfo()) {
     131           4 :       if (auto EC = Writer.writeArray(makeArrayRef(B.Columns)))
     132           0 :         return EC;
     133             :     }
     134             :   }
     135          87 :   return Error::success();
     136             : }
     137             : 
     138          59 : uint32_t DebugLinesSubsection::calculateSerializedSize() const {
     139          59 :   uint32_t Size = sizeof(LineFragmentHeader);
     140         295 :   for (const auto &B : Blocks) {
     141          59 :     Size += sizeof(LineBlockFragmentHeader);
     142         118 :     Size += B.Lines.size() * sizeof(LineNumberEntry);
     143          59 :     if (hasColumnInfo())
     144           4 :       Size += B.Columns.size() * sizeof(ColumnNumberEntry);
     145             :   }
     146          59 :   return Size;
     147             : }
     148             : 
     149          29 : void DebugLinesSubsection::setRelocationAddress(uint16_t Segment,
     150             :                                                 uint32_t Offset) {
     151          29 :   RelocOffset = Offset;
     152          29 :   RelocSegment = Segment;
     153          29 : }
     154             : 
     155          29 : void DebugLinesSubsection::setCodeSize(uint32_t Size) { CodeSize = Size; }
     156             : 
     157          29 : void DebugLinesSubsection::setFlags(LineFlags Flags) { this->Flags = Flags; }
     158             : 
     159         175 : bool DebugLinesSubsection::hasColumnInfo() const {
     160         175 :   return Flags & LF_HaveColumns;
     161             : }

Generated by: LCOV version 1.13