LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo/CodeView - CVRecord.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 27 29 93.1 %
Date: 2017-09-14 15:23:50 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- RecordIterator.h -----------------------------------------*- 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             : #ifndef LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H
      11             : #define LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H
      12             : 
      13             : #include "llvm/ADT/ArrayRef.h"
      14             : #include "llvm/ADT/Optional.h"
      15             : #include "llvm/DebugInfo/CodeView/CodeViewError.h"
      16             : #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
      17             : #include "llvm/DebugInfo/CodeView/TypeIndex.h"
      18             : #include "llvm/Support/BinaryStreamReader.h"
      19             : #include "llvm/Support/BinaryStreamRef.h"
      20             : #include "llvm/Support/Endian.h"
      21             : #include "llvm/Support/Error.h"
      22             : #include <cstdint>
      23             : 
      24             : namespace llvm {
      25             : 
      26             : namespace codeview {
      27             : 
      28      110556 : template <typename Kind> class CVRecord {
      29             : public:
      30      164286 :   CVRecord() : Type(static_cast<Kind>(0)) {}
      31             : 
      32       12818 :   CVRecord(Kind K, ArrayRef<uint8_t> Data) : Type(K), RecordData(Data) {}
      33             : 
      34             :   bool valid() const { return Type != static_cast<Kind>(0); }
      35             : 
      36       10799 :   uint32_t length() const { return RecordData.size(); }
      37             :   Kind kind() const { return Type; }
      38             :   ArrayRef<uint8_t> data() const { return RecordData; }
      39             :   StringRef str_data() const {
      40         809 :     return StringRef(reinterpret_cast<const char *>(RecordData.data()),
      41        1618 :                      RecordData.size());
      42             :   }
      43             : 
      44             :   ArrayRef<uint8_t> content() const {
      45       16066 :     return RecordData.drop_front(sizeof(RecordPrefix));
      46             :   }
      47             : 
      48             :   Optional<uint32_t> hash() const { return Hash; }
      49             : 
      50             :   void setHash(uint32_t Value) { Hash = Value; }
      51             : 
      52             :   Kind Type;
      53             :   ArrayRef<uint8_t> RecordData;
      54             :   Optional<uint32_t> Hash;
      55             : };
      56             : 
      57        3051 : template <typename Kind> struct RemappedRecord {
      58        3051 :   explicit RemappedRecord(const CVRecord<Kind> &R) : OriginalRecord(R) {}
      59             : 
      60             :   CVRecord<Kind> OriginalRecord;
      61             :   SmallVector<std::pair<uint32_t, TypeIndex>, 8> Mappings;
      62             : };
      63             : 
      64             : /// Read a complete record from a stream at a random offset.
      65             : template <typename Kind>
      66        6963 : inline Expected<CVRecord<Kind>> readCVRecordFromStream(BinaryStreamRef Stream,
      67             :                                                        uint32_t Offset) {
      68        6963 :   const RecordPrefix *Prefix = nullptr;
      69       20889 :   BinaryStreamReader Reader(Stream);
      70       13926 :   Reader.setOffset(Offset);
      71             : 
      72       20888 :   if (auto EC = Reader.readObject(Prefix))
      73           4 :     return std::move(EC);
      74       13924 :   if (Prefix->RecordLen < 2)
      75           0 :     return make_error<CodeViewError>(cv_error_code::corrupt_record);
      76       13924 :   Kind K = static_cast<Kind>(uint16_t(Prefix->RecordKind));
      77             : 
      78       13924 :   Reader.setOffset(Offset);
      79        6962 :   ArrayRef<uint8_t> RawData;
      80       27848 :   if (auto EC = Reader.readBytes(RawData, Prefix->RecordLen + sizeof(uint16_t)))
      81           0 :     return std::move(EC);
      82       27848 :   return codeview::CVRecord<Kind>(K, RawData);
      83             : }
      84             : 
      85             : } // end namespace codeview
      86             : 
      87             : template <typename Kind>
      88             : struct VarStreamArrayExtractor<codeview::CVRecord<Kind>> {
      89        6932 :   Error operator()(BinaryStreamRef Stream, uint32_t &Len,
      90             :                    codeview::CVRecord<Kind> &Item) {
      91       20796 :     auto ExpectedRec = codeview::readCVRecordFromStream<Kind>(Stream, 0);
      92        6932 :     if (!ExpectedRec)
      93             :       return ExpectedRec.takeError();
      94       13862 :     Item = *ExpectedRec;
      95       13862 :     Len = ExpectedRec->length();
      96       20793 :     return Error::success();
      97             :   }
      98             : };
      99             : 
     100             : } // end namespace llvm
     101             : 
     102             : #endif // LLVM_DEBUGINFO_CODEVIEW_RECORDITERATOR_H

Generated by: LCOV version 1.13