LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB/Native - InfoStreamBuilder.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 26 100.0 %
Date: 2018-07-13 00:08:38 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- InfoStreamBuilder.cpp - PDB Info Stream Creation ---------*- C++ -*-===//
       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/InfoStreamBuilder.h"
      11             : 
      12             : #include "llvm/DebugInfo/MSF/MSFBuilder.h"
      13             : #include "llvm/DebugInfo/MSF/MappedBlockStream.h"
      14             : #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
      15             : #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h"
      16             : #include "llvm/DebugInfo/PDB/Native/PDBFileBuilder.h"
      17             : #include "llvm/DebugInfo/PDB/Native/RawError.h"
      18             : #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
      19             : #include "llvm/Support/BinaryStreamWriter.h"
      20             : 
      21             : using namespace llvm;
      22             : using namespace llvm::codeview;
      23             : using namespace llvm::msf;
      24             : using namespace llvm::pdb;
      25             : 
      26          90 : InfoStreamBuilder::InfoStreamBuilder(msf::MSFBuilder &Msf,
      27          90 :                                      NamedStreamMap &NamedStreams)
      28             :     : Msf(Msf), Ver(PdbRaw_ImplVer::PdbImplVC70), Age(0),
      29         270 :       NamedStreams(NamedStreams) {
      30          90 :   ::memset(&Guid, 0, sizeof(Guid));
      31          90 : }
      32             : 
      33          87 : void InfoStreamBuilder::setVersion(PdbRaw_ImplVer V) { Ver = V; }
      34             : 
      35          87 : void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
      36             : 
      37          36 : void InfoStreamBuilder::setSignature(uint32_t S) { Signature = S; }
      38             : 
      39          87 : void InfoStreamBuilder::setGuid(GUID G) { Guid = G; }
      40             : 
      41          42 : void InfoStreamBuilder::addFeature(PdbRaw_FeatureSig Sig) {
      42          42 :   Features.push_back(Sig);
      43          42 : }
      44             : 
      45         180 : Error InfoStreamBuilder::finalizeMsfLayout() {
      46             :   uint32_t Length = sizeof(InfoStreamHeader) +
      47         360 :                     NamedStreams.calculateSerializedLength() +
      48         360 :                     (Features.size() + 1) * sizeof(uint32_t);
      49         360 :   if (auto EC = Msf.setStreamSize(StreamPDB, Length))
      50             :     return EC;
      51             :   return Error::success();
      52             : }
      53             : 
      54          90 : Error InfoStreamBuilder::commit(const msf::MSFLayout &Layout,
      55             :                                 WritableBinaryStreamRef Buffer) const {
      56             :   auto InfoS = WritableMappedBlockStream::createIndexedStream(
      57         270 :       Layout, Buffer, StreamPDB, Msf.getAllocator());
      58          90 :   BinaryStreamWriter Writer(*InfoS);
      59             : 
      60             :   InfoStreamHeader H;
      61             :   // Leave the build id fields 0 so they can be set as the last step before
      62             :   // committing the file to disk.
      63          90 :   ::memset(&H, 0, sizeof(H));
      64          90 :   H.Version = Ver;
      65          90 :   if (auto EC = Writer.writeObject(H))
      66             :     return EC;
      67             : 
      68         180 :   if (auto EC = NamedStreams.commit(Writer))
      69             :     return EC;
      70         180 :   if (auto EC = Writer.writeInteger(0))
      71             :     return EC;
      72          90 :   for (auto E : Features) {
      73          42 :     if (auto EC = Writer.writeEnum(E))
      74             :       return EC;
      75             :   }
      76             :   assert(Writer.bytesRemaining() == 0);
      77             :   return Error::success();
      78             : }

Generated by: LCOV version 1.13