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

          Line data    Source code
       1             : //===- DWARFAbbreviationDeclaration.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_DWARFABBREVIATIONDECLARATION_H
      11             : #define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
      12             : 
      13             : #include "llvm/ADT/Optional.h"
      14             : #include "llvm/ADT/SmallVector.h"
      15             : #include "llvm/ADT/iterator_range.h"
      16             : #include "llvm/BinaryFormat/Dwarf.h"
      17             : #include "llvm/Support/DataExtractor.h"
      18             : #include <cassert>
      19             : #include <cstddef>
      20             : #include <cstdint>
      21             : 
      22             : namespace llvm {
      23             : 
      24             : class DWARFFormValue;
      25             : class DWARFUnit;
      26             : class raw_ostream;
      27             : 
      28   118107624 : class DWARFAbbreviationDeclaration {
      29             : public:
      30   231816006 :   struct AttributeSpec {
      31             :     AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<int64_t> V)
      32    92434020 :         : Attr(A), Form(F), ByteSizeOrValue(V) {}
      33             : 
      34             :     dwarf::Attribute Attr;
      35             :     dwarf::Form Form;
      36             : 
      37             :     /// The following field is used for ByteSize for non-implicit_const
      38             :     /// attributes and as value for implicit_const ones, indicated by
      39             :     /// Form == DW_FORM_implicit_const.
      40             :     /// The following cases are distinguished:
      41             :     /// * Form != DW_FORM_implicit_const and ByteSizeOrValue has a value:
      42             :     ///     ByteSizeOrValue contains the fixed size in bytes
      43             :     ///     for the Form in this object.
      44             :     /// * Form != DW_FORM_implicit_const and ByteSizeOrValue is None:
      45             :     ///     byte size of Form either varies according to the DWARFUnit
      46             :     ///     that it is contained in or the value size varies and must be
      47             :     ///     decoded from the debug information in order to determine its size.
      48             :     /// * Form == DW_FORM_implicit_const:
      49             :     ///     ByteSizeOrValue contains value for the implicit_const attribute.
      50             :     Optional<int64_t> ByteSizeOrValue;
      51             : 
      52             :     bool isImplicitConst() const {
      53             :       return Form == dwarf::DW_FORM_implicit_const;
      54             :     }
      55             : 
      56             :     /// Get the fixed byte size of this Form if possible. This function might
      57             :     /// use the DWARFUnit to calculate the size of the Form, like for
      58             :     /// DW_AT_address and DW_AT_ref_addr, so this isn't just an accessor for
      59             :     /// the ByteSize member.
      60             :     Optional<int64_t> getByteSize(const DWARFUnit &U) const;
      61             :   };
      62             :   using AttributeSpecVector = SmallVector<AttributeSpec, 8>;
      63             : 
      64             :   DWARFAbbreviationDeclaration();
      65             : 
      66             :   uint32_t getCode() const { return Code; }
      67             :   uint8_t getCodeByteSize() const { return CodeByteSize; }
      68             :   dwarf::Tag getTag() const { return Tag; }
      69             :   bool hasChildren() const { return HasChildren; }
      70             : 
      71             :   using attr_iterator_range =
      72             :       iterator_range<AttributeSpecVector::const_iterator>;
      73             : 
      74             :   attr_iterator_range attributes() const {
      75     2978904 :     return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
      76             :   }
      77             : 
      78             :   dwarf::Form getFormByIndex(uint32_t idx) const {
      79             :     assert(idx < AttributeSpecs.size());
      80        4862 :     return AttributeSpecs[idx].Form;
      81             :   }
      82             : 
      83             :   size_t getNumAttributes() const {
      84        1826 :     return AttributeSpecs.size();
      85             :   }
      86             : 
      87             :   dwarf::Attribute getAttrByIndex(uint32_t idx) const {
      88             :     assert(idx < AttributeSpecs.size());
      89        1280 :     return AttributeSpecs[idx].Attr;
      90             :   }
      91             : 
      92             :   /// Get the index of the specified attribute.
      93             :   ///
      94             :   /// Searches the this abbreviation declaration for the index of the specified
      95             :   /// attribute.
      96             :   ///
      97             :   /// \param attr DWARF attribute to search for.
      98             :   /// \returns Optional index of the attribute if found, None otherwise.
      99             :   Optional<uint32_t> findAttributeIndex(dwarf::Attribute attr) const;
     100             : 
     101             :   /// Extract a DWARF form value from a DIE specified by DIE offset.
     102             :   ///
     103             :   /// Extract an attribute value for a DWARFUnit given the DIE offset and the
     104             :   /// attribute.
     105             :   ///
     106             :   /// \param DIEOffset the DIE offset that points to the ULEB128 abbreviation
     107             :   /// code in the .debug_info data.
     108             :   /// \param Attr DWARF attribute to search for.
     109             :   /// \param U the DWARFUnit the contains the DIE.
     110             :   /// \returns Optional DWARF form value if the attribute was extracted.
     111             :   Optional<DWARFFormValue> getAttributeValue(const uint32_t DIEOffset,
     112             :                                              const dwarf::Attribute Attr,
     113             :                                              const DWARFUnit &U) const;
     114             : 
     115             :   bool extract(DataExtractor Data, uint32_t* OffsetPtr);
     116             :   void dump(raw_ostream &OS) const;
     117             : 
     118             :   // Return an optional byte size of all attribute data in this abbreviation
     119             :   // if a constant byte size can be calculated given a DWARFUnit. This allows
     120             :   // DWARF parsing to be faster as many DWARF DIEs have a fixed byte size.
     121             :   Optional<size_t> getFixedAttributesByteSize(const DWARFUnit &U) const;
     122             : 
     123             : private:
     124             :   void clear();
     125             : 
     126             :   /// A helper structure that can quickly determine the size in bytes of an
     127             :   /// abbreviation declaration.
     128             :   struct FixedSizeInfo {
     129             :     /// The fixed byte size for fixed size forms.
     130             :     uint16_t NumBytes = 0;
     131             :     /// Number of DW_FORM_address forms in this abbrevation declaration.
     132             :     uint8_t NumAddrs = 0;
     133             :     /// Number of DW_FORM_ref_addr forms in this abbrevation declaration.
     134             :     uint8_t NumRefAddrs = 0;
     135             :     /// Number of 4 byte in DWARF32 and 8 byte in DWARF64 forms.
     136             :     uint8_t NumDwarfOffsets = 0;
     137             : 
     138             :     FixedSizeInfo() = default;
     139             : 
     140             :     /// Calculate the fixed size in bytes given a DWARFUnit.
     141             :     ///
     142             :     /// \param U the DWARFUnit to use when determing the byte size.
     143             :     /// \returns the size in bytes for all attribute data in this abbreviation.
     144             :     /// The returned size does not include bytes for the  ULEB128 abbreviation
     145             :     /// code
     146             :     size_t getByteSize(const DWARFUnit &U) const;
     147             :   };
     148             : 
     149             :   uint32_t Code;
     150             :   dwarf::Tag Tag;
     151             :   uint8_t CodeByteSize;
     152             :   bool HasChildren;
     153             :   AttributeSpecVector AttributeSpecs;
     154             :   /// If this abbreviation has a fixed byte size then FixedAttributeSize member
     155             :   /// variable below will have a value.
     156             :   Optional<FixedSizeInfo> FixedAttributeSize;
     157             : };
     158             : 
     159             : } // end namespace llvm
     160             : 
     161             : #endif // LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H

Generated by: LCOV version 1.13