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

          Line data    Source code
       1             : //===- InfoStream.cpp - PDB Info Stream (Stream 1) Access -------*- 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/InfoStream.h"
      11             : #include "llvm/ADT/BitVector.h"
      12             : #include "llvm/ADT/SmallVector.h"
      13             : #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
      14             : #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
      15             : #include "llvm/DebugInfo/PDB/Native/RawError.h"
      16             : #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
      17             : #include "llvm/Support/BinaryStreamReader.h"
      18             : #include "llvm/Support/BinaryStreamWriter.h"
      19             : 
      20             : using namespace llvm;
      21             : using namespace llvm::codeview;
      22             : using namespace llvm::msf;
      23             : using namespace llvm::pdb;
      24             : 
      25          68 : InfoStream::InfoStream(std::unique_ptr<MappedBlockStream> Stream)
      26         272 :     : Stream(std::move(Stream)) {}
      27             : 
      28          68 : Error InfoStream::reload() {
      29         204 :   BinaryStreamReader Reader(*Stream);
      30             : 
      31             :   const InfoStreamHeader *H;
      32         204 :   if (auto EC = Reader.readObject(H))
      33             :     return joinErrors(
      34           0 :         std::move(EC),
      35           0 :         make_error<RawError>(raw_error_code::corrupt_file,
      36           0 :                              "PDB Stream does not contain a header."));
      37             : 
      38         136 :   switch (H->Version) {
      39             :   case PdbImplVC70:
      40             :   case PdbImplVC80:
      41             :   case PdbImplVC110:
      42             :   case PdbImplVC140:
      43             :     break;
      44           0 :   default:
      45             :     return make_error<RawError>(raw_error_code::corrupt_file,
      46           0 :                                 "Unsupported PDB stream version.");
      47             :   }
      48             : 
      49         136 :   Version = H->Version;
      50         136 :   Signature = H->Signature;
      51         136 :   Age = H->Age;
      52          68 :   Guid = H->Guid;
      53             : 
      54          68 :   uint32_t Offset = Reader.getOffset();
      55         204 :   if (auto EC = NamedStreams.load(Reader))
      56           0 :     return EC;
      57          68 :   uint32_t NewOffset = Reader.getOffset();
      58          68 :   NamedStreamMapByteSize = NewOffset - Offset;
      59             : 
      60         136 :   Reader.setOffset(Offset);
      61         204 :   if (auto EC = Reader.readSubstream(SubNamedStreams, NamedStreamMapByteSize))
      62           0 :     return EC;
      63             : 
      64          68 :   bool Stop = false;
      65         363 :   while (!Stop && !Reader.empty()) {
      66             :     PdbRaw_FeatureSig Sig;
      67         378 :     if (auto EC = Reader.readEnum(Sig))
      68           0 :       return EC;
      69             :     // Since this value comes from a file, it's possible we have some strange
      70             :     // value which doesn't correspond to any value.  We don't want to warn on
      71             :     // -Wcovered-switch-default in this case, so switch on the integral value
      72             :     // instead of the enumeration value.
      73         194 :     switch (uint32_t(Sig)) {
      74          25 :     case uint32_t(PdbRaw_FeatureSig::VC110):
      75             :       // No other flags for VC110 PDB.
      76          25 :       Stop = true;
      77             :       LLVM_FALLTHROUGH;
      78          58 :     case uint32_t(PdbRaw_FeatureSig::VC140):
      79          58 :       Features |= PdbFeatureContainsIdStream;
      80             :       break;
      81           0 :     case uint32_t(PdbRaw_FeatureSig::NoTypeMerge):
      82           0 :       Features |= PdbFeatureNoTypeMerging;
      83             :       break;
      84           0 :     case uint32_t(PdbRaw_FeatureSig::MinimalDebugInfo):
      85           0 :       Features |= PdbFeatureMinimalDebugInfo;
      86             :       break;
      87          68 :     default:
      88          68 :       continue;
      89             :     }
      90          58 :     FeatureSignatures.push_back(Sig);
      91             :   }
      92         204 :   return Error::success();
      93             : }
      94             : 
      95           4 : uint32_t InfoStream::getStreamSize() const { return Stream->getLength(); }
      96             : 
      97          37 : uint32_t InfoStream::getNamedStreamIndex(llvm::StringRef Name) const {
      98             :   uint32_t Result;
      99          37 :   if (!NamedStreams.get(Name, Result))
     100             :     return 0;
     101          37 :   return Result;
     102             : }
     103             : 
     104             : iterator_range<StringMapConstIterator<uint32_t>>
     105          11 : InfoStream::named_streams() const {
     106          11 :   return NamedStreams.entries();
     107             : }
     108             : 
     109          77 : bool InfoStream::containsIdStream() const {
     110         154 :   return !!(Features & PdbFeatureContainsIdStream);
     111             : }
     112             : 
     113          11 : PdbRaw_ImplVer InfoStream::getVersion() const {
     114          11 :   return static_cast<PdbRaw_ImplVer>(Version);
     115             : }
     116             : 
     117          15 : uint32_t InfoStream::getSignature() const { return Signature; }
     118             : 
     119          19 : uint32_t InfoStream::getAge() const { return Age; }
     120             : 
     121          20 : GUID InfoStream::getGuid() const { return Guid; }
     122             : 
     123           2 : uint32_t InfoStream::getNamedStreamMapByteSize() const {
     124           2 :   return NamedStreamMapByteSize;
     125             : }
     126             : 
     127           4 : PdbRaw_Features InfoStream::getFeatures() const { return Features; }
     128             : 
     129          11 : ArrayRef<PdbRaw_FeatureSig> InfoStream::getFeatureSignatures() const {
     130          22 :   return FeatureSignatures;
     131             : }
     132             : 
     133           2 : const NamedStreamMap &InfoStream::getNamedStreams() const {
     134           2 :   return NamedStreams;
     135             : }
     136             : 
     137           1 : BinarySubstreamRef InfoStream::getNamedStreamsBuffer() const {
     138           2 :   return SubNamedStreams;
     139             : }

Generated by: LCOV version 1.13