LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo/DWARF - DWARFDebugRnglists.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 5 7 71.4 %
Date: 2018-07-13 00:08:38 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DWARFDebugRnglists.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_DWARFDEBUGRNGLISTS_H
      11             : #define LLVM_DEBUGINFO_DWARFDEBUGRNGLISTS_H
      12             : 
      13             : #include "llvm/BinaryFormat/Dwarf.h"
      14             : #include "llvm/DebugInfo/DIContext.h"
      15             : #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
      16             : #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
      17             : #include <cstdint>
      18             : #include <map>
      19             : #include <vector>
      20             : 
      21             : namespace llvm {
      22             : 
      23             : class Error;
      24             : class raw_ostream;
      25             : 
      26             : /// A class representing a single rangelist.
      27          24 : class DWARFDebugRnglist {
      28             : public:
      29             :   struct RangeListEntry {
      30             :     /// The offset at which the entry is located in the section.
      31             :     uint32_t Offset;
      32             :     /// The DWARF encoding (DW_RLE_*).
      33             :     uint8_t EntryKind;
      34             :     /// The index of the section this range belongs to.
      35             :     uint64_t SectionIndex;
      36             :     /// The values making up the range list entry. Most represent a range with
      37             :     /// a start and end address or a start address and a length. Others are
      38             :     /// single value base addresses or end-of-list with no values. The unneeded
      39             :     /// values are semantically undefined, but initialized to 0.
      40             :     uint64_t Value0;
      41             :     uint64_t Value1;
      42             : 
      43             :     Error extract(DWARFDataExtractor Data, uint32_t End, uint32_t *OffsetPtr);
      44             :   };
      45             : 
      46             :   using RngListEntries = std::vector<RangeListEntry>;
      47             : 
      48             : private:
      49             :   RngListEntries Entries;
      50             : 
      51             : public:
      52             :   const RngListEntries &getEntries() const { return Entries; }
      53             :   bool empty() const { return Entries.empty(); }
      54             :   void clear() { Entries.clear(); }
      55             :   Error extract(DWARFDataExtractor Data, uint32_t HeaderOffset, uint32_t End,
      56             :                 uint32_t *OffsetPtr);
      57             :   /// Build a DWARFAddressRangesVector from a rangelist.
      58             :   DWARFAddressRangesVector
      59             :   getAbsoluteRanges(llvm::Optional<BaseAddress> BaseAddr) const;
      60             : };
      61             : 
      62             : /// A class representing a table of range lists as specified in DWARF v5.
      63             : /// The table consists of a header followed by an array of offsets into the
      64             : /// .debug_rnglists section, followed by one or more rangelists. The rangelists
      65             : /// are kept in a map where the keys are the lists' section offsets.
      66         270 : class DWARFDebugRnglistTable {
      67             : public:
      68         107 :   struct Header {
      69             :     /// The total length of the entries for this table, not including the length
      70             :     /// field itself.
      71             :     uint32_t Length = 0;
      72             :     /// The DWARF version number.
      73             :     uint16_t Version;
      74             :     /// The size in bytes of an address on the target architecture. For
      75             :     /// segmented addressing, this is the size of the offset portion of the
      76             :     /// address.
      77             :     uint8_t AddrSize;
      78             :     /// The size in bytes of a segment selector on the target architecture.
      79             :     /// If the target system uses a flat address space, this value is 0.
      80             :     uint8_t SegSize;
      81             :     /// The number of offsets that follow the header before the range lists.
      82             :     uint32_t OffsetEntryCount;
      83             :   };
      84             : 
      85             : private:
      86             :   dwarf::DwarfFormat Format;
      87             :   uint32_t HeaderOffset;
      88             :   Header HeaderData;
      89             :   std::vector<uint32_t> Offsets;
      90             :   std::map<uint32_t, DWARFDebugRnglist> Ranges;
      91             : 
      92             : public:
      93             :   void clear();
      94             :   /// Extract the table header and the array of offsets.
      95             :   Error extractHeaderAndOffsets(DWARFDataExtractor Data, uint32_t *OffsetPtr);
      96             :   /// Extract an entire table, including all rangelists.
      97             :   Error extract(DWARFDataExtractor Data, uint32_t *OffsetPtr);
      98             :   /// Look up a rangelist based on a given offset. Extract it and enter it into
      99             :   /// the ranges map if necessary.
     100             :   Expected<DWARFDebugRnglist> findRangeList(DWARFDataExtractor Data,
     101             :                                             uint32_t Offset);
     102             :   uint32_t getHeaderOffset() const { return HeaderOffset; }
     103             :   uint8_t getAddrSize() const { return HeaderData.AddrSize; }
     104             :   void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const;
     105             :   /// Return the contents of the offset entry designated by a given index.
     106             :   Optional<uint32_t> getOffsetEntry(uint32_t Index) const {
     107          10 :     if (Index < Offsets.size())
     108             :       return Offsets[Index];
     109             :     return None;
     110             :   }
     111             :   /// Return the size of the table header including the length but not including
     112             :   /// the offsets. This is dependent on the table format, which is unambiguously
     113             :   /// derived from parsing the table.
     114             :   uint8_t getHeaderSize() const {
     115           1 :     switch (Format) {
     116             :     case dwarf::DwarfFormat::DWARF32:
     117             :       return 12;
     118           0 :     case dwarf::DwarfFormat::DWARF64:
     119             :       return 20;
     120             :     }
     121           0 :     llvm_unreachable("Invalid DWARF format (expected DWARF32 or DWARF64");
     122             :   }
     123             : 
     124             :   /// Returns the length of this table, including the length field, or 0 if the
     125             :   /// length has not been determined (e.g. because the table has not yet been
     126             :   /// parsed, or there was a problem in parsing).
     127             :   uint32_t length() const;
     128             : };
     129             : 
     130             : } // end namespace llvm
     131             : 
     132             : #endif // LLVM_DEBUGINFO_DWARFDEBUGRNGLISTS_H

Generated by: LCOV version 1.13