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

          Line data    Source code
       1             : //===- DebugSubsectionRecord.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/DebugSubsectionRecord.h"
      11             : #include "llvm/DebugInfo/CodeView/CodeView.h"
      12             : #include "llvm/DebugInfo/CodeView/DebugSubsection.h"
      13             : #include "llvm/Support/BinaryStreamReader.h"
      14             : #include "llvm/Support/BinaryStreamWriter.h"
      15             : #include "llvm/Support/Error.h"
      16             : #include "llvm/Support/MathExtras.h"
      17             : #include <algorithm>
      18             : #include <cassert>
      19             : #include <cstdint>
      20             : 
      21             : using namespace llvm;
      22             : using namespace llvm::codeview;
      23             : 
      24             : DebugSubsectionRecord::DebugSubsectionRecord() = default;
      25             : 
      26           0 : DebugSubsectionRecord::DebugSubsectionRecord(DebugSubsectionKind Kind,
      27             :                                              BinaryStreamRef Data,
      28           0 :                                              CodeViewContainer Container)
      29           0 :     : Container(Container), Kind(Kind), Data(Data) {}
      30             : 
      31         613 : Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream,
      32             :                                         DebugSubsectionRecord &Info,
      33             :                                         CodeViewContainer Container) {
      34             :   const DebugSubsectionHeader *Header;
      35        1839 :   BinaryStreamReader Reader(Stream);
      36        1839 :   if (auto EC = Reader.readObject(Header))
      37           0 :     return EC;
      38             : 
      39             :   DebugSubsectionKind Kind =
      40        1226 :       static_cast<DebugSubsectionKind>(uint32_t(Header->Kind));
      41        2452 :   if (auto EC = Reader.readStreamRef(Info.Data, Header->Length))
      42           0 :     return EC;
      43         613 :   Info.Container = Container;
      44         613 :   Info.Kind = Kind;
      45        1839 :   return Error::success();
      46             : }
      47             : 
      48         623 : uint32_t DebugSubsectionRecord::getRecordLength() const {
      49         623 :   return sizeof(DebugSubsectionHeader) + Data.getLength();
      50             : }
      51             : 
      52         637 : DebugSubsectionKind DebugSubsectionRecord::kind() const { return Kind; }
      53             : 
      54        1036 : BinaryStreamRef DebugSubsectionRecord::getRecordData() const { return Data; }
      55             : 
      56         198 : DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder(
      57         198 :     std::shared_ptr<DebugSubsection> Subsection, CodeViewContainer Container)
      58         396 :     : Subsection(std::move(Subsection)), Container(Container) {}
      59             : 
      60          37 : DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder(
      61          37 :     const DebugSubsectionRecord &Contents, CodeViewContainer Container)
      62         111 :     : Contents(Contents), Container(Container) {}
      63             : 
      64         311 : uint32_t DebugSubsectionRecordBuilder::calculateSerializedLength() {
      65         622 :   uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
      66         933 :                                  : Contents.getRecordData().getLength();
      67             :   // The length of the entire subsection is always padded to 4 bytes,
      68             :   // regardless of the container kind.
      69         622 :   return sizeof(DebugSubsectionHeader) + alignTo(DataSize, 4);
      70             : }
      71             : 
      72         235 : Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) const {
      73             :   assert(Writer.getOffset() % alignOf(Container) == 0 &&
      74             :          "Debug Subsection not properly aligned");
      75             : 
      76             :   DebugSubsectionHeader Header;
      77         668 :   Header.Kind = uint32_t(Subsection ? Subsection->kind() : Contents.kind());
      78             :   // The value written into the Header's Length field is only padded to the
      79             :   // container's alignment
      80         470 :   uint32_t DataSize = Subsection ? Subsection->calculateSerializedSize()
      81         705 :                                  : Contents.getRecordData().getLength();
      82         940 :   Header.Length = alignTo(DataSize, alignOf(Container));
      83             : 
      84         705 :   if (auto EC = Writer.writeObject(Header))
      85           0 :     return EC;
      86         235 :   if (Subsection) {
      87         792 :     if (auto EC = Subsection->commit(Writer))
      88           0 :       return EC;
      89             :   } else {
      90         148 :     if (auto EC = Writer.writeStreamRef(Contents.getRecordData()))
      91           0 :       return EC;
      92             :   }
      93         705 :   if (auto EC = Writer.padToAlignment(4))
      94           0 :     return EC;
      95             : 
      96         705 :   return Error::success();
      97             : }

Generated by: LCOV version 1.13