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

Generated by: LCOV version 1.13