LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo/CodeView - SymbolDeserializer.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 28 33 84.8 %
Date: 2017-09-14 15:23:50 Functions: 45 84 53.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- SymbolDeserializer.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_SYMBOLDESERIALIZER_H
      11             : #define LLVM_DEBUGINFO_CODEVIEW_SYMBOLDESERIALIZER_H
      12             : 
      13             : #include "llvm/ADT/ArrayRef.h"
      14             : #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
      15             : #include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
      16             : #include "llvm/DebugInfo/CodeView/SymbolVisitorCallbacks.h"
      17             : #include "llvm/DebugInfo/CodeView/SymbolVisitorDelegate.h"
      18             : #include "llvm/Support/BinaryByteStream.h"
      19             : #include "llvm/Support/BinaryStreamReader.h"
      20             : #include "llvm/Support/Error.h"
      21             : 
      22             : namespace llvm {
      23             : namespace codeview {
      24             : class SymbolVisitorDelegate;
      25         599 : class SymbolDeserializer : public SymbolVisitorCallbacks {
      26        5652 :   struct MappingInfo {
      27             :     MappingInfo(ArrayRef<uint8_t> RecordData, CodeViewContainer Container)
      28        1413 :         : Stream(RecordData, llvm::support::little), Reader(Stream),
      29        4239 :           Mapping(Reader, Container) {}
      30             : 
      31             :     BinaryByteStream Stream;
      32             :     BinaryStreamReader Reader;
      33             :     SymbolRecordMapping Mapping;
      34             :   };
      35             : 
      36             : public:
      37         286 :   template <typename T> static Error deserializeAs(CVSymbol Symbol, T &Record) {
      38             :     // If we're just deserializing one record, then don't worry about alignment
      39             :     // as there's nothing that comes after.
      40         572 :     SymbolDeserializer S(nullptr, CodeViewContainer::ObjectFile);
      41         858 :     if (auto EC = S.visitSymbolBegin(Symbol))
      42           0 :       return EC;
      43         858 :     if (auto EC = S.visitKnownRecord(Symbol, Record))
      44           0 :       return EC;
      45         858 :     if (auto EC = S.visitSymbolEnd(Symbol))
      46           0 :       return EC;
      47         858 :     return Error::success();
      48             :   }
      49         203 :   template <typename T> static Expected<T> deserializeAs(CVSymbol Symbol) {
      50         406 :     T Record(Symbol.kind());
      51         812 :     if (auto EC = deserializeAs<T>(Symbol, Record))
      52           0 :       return std::move(EC);
      53             :     return Record;
      54             :   }
      55             : 
      56             :   explicit SymbolDeserializer(SymbolVisitorDelegate *Delegate,
      57             :                               CodeViewContainer Container)
      58        1198 :       : Delegate(Delegate), Container(Container) {}
      59             : 
      60         218 :   Error visitSymbolBegin(CVSymbol &Record, uint32_t Offset) override {
      61         218 :     return visitSymbolBegin(Record);
      62             :   }
      63             : 
      64        1413 :   Error visitSymbolBegin(CVSymbol &Record) override {
      65             :     assert(!Mapping && "Already in a symbol mapping!");
      66        2826 :     Mapping = llvm::make_unique<MappingInfo>(Record.content(), Container);
      67        2826 :     return Mapping->Mapping.visitSymbolBegin(Record);
      68             :   }
      69        1413 :   Error visitSymbolEnd(CVSymbol &Record) override {
      70             :     assert(Mapping && "Not in a symbol mapping!");
      71        2826 :     auto EC = Mapping->Mapping.visitSymbolEnd(Record);
      72        2826 :     Mapping.reset();
      73        1413 :     return EC;
      74             :   }
      75             : 
      76             : #define SYMBOL_RECORD(EnumName, EnumVal, Name)                                 \
      77             :   Error visitKnownRecord(CVSymbol &CVR, Name &Record) override {               \
      78             :     return visitKnownRecordImpl(CVR, Record);                                  \
      79             :   }
      80             : #define SYMBOL_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
      81             : #include "llvm/DebugInfo/CodeView/CodeViewSymbols.def"
      82             : 
      83             : private:
      84        1413 :   template <typename T> Error visitKnownRecordImpl(CVSymbol &CVR, T &Record) {
      85             : 
      86        2302 :     Record.RecordOffset =
      87        6906 :         Delegate ? Delegate->getRecordOffset(Mapping->Reader) : 0;
      88        5652 :     if (auto EC = Mapping->Mapping.visitKnownRecord(CVR, Record))
      89           0 :       return EC;
      90        4239 :     return Error::success();
      91             :   }
      92             : 
      93             :   SymbolVisitorDelegate *Delegate;
      94             :   CodeViewContainer Container;
      95             :   std::unique_ptr<MappingInfo> Mapping;
      96             : };
      97             : }
      98             : }
      99             : 
     100             : #endif

Generated by: LCOV version 1.13