LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo/DWARF - DWARFDebugLine.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 14 14 100.0 %
Date: 2018-02-19 03:08:00 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DWARFDebugLine.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_DWARFDEBUGLINE_H
      11             : #define LLVM_DEBUGINFO_DWARFDEBUGLINE_H
      12             : 
      13             : #include "llvm/ADT/StringRef.h"
      14             : #include "llvm/DebugInfo/DIContext.h"
      15             : #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
      16             : #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
      17             : #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
      18             : #include "llvm/Support/MD5.h"
      19             : #include <cstdint>
      20             : #include <map>
      21             : #include <string>
      22             : #include <vector>
      23             : 
      24             : namespace llvm {
      25             : 
      26             : class DWARFUnit;
      27             : class raw_ostream;
      28             : 
      29         782 : class DWARFDebugLine {
      30             : public:
      31             :   struct FileNameEntry {
      32        1749 :     FileNameEntry() = default;
      33             : 
      34             :     DWARFFormValue Name;
      35             :     uint64_t DirIdx = 0;
      36             :     uint64_t ModTime = 0;
      37             :     uint64_t Length = 0;
      38             :     MD5::MD5Result Checksum;
      39             :   };
      40             : 
      41        9992 :   struct Prologue {
      42             :     Prologue();
      43             : 
      44             :     /// The size in bytes of the statement information for this compilation unit
      45             :     /// (not including the total_length field itself).
      46             :     uint64_t TotalLength;
      47             :     /// Version, address size (starting in v5), and DWARF32/64 format; these
      48             :     /// parameters affect interpretation of forms (used in the directory and
      49             :     /// file tables starting with v5).
      50             :     DWARFFormParams FormParams;
      51             :     /// The number of bytes following the prologue_length field to the beginning
      52             :     /// of the first byte of the statement program itself.
      53             :     uint64_t PrologueLength;
      54             :     /// In v5, size in bytes of a segment selector.
      55             :     uint8_t SegSelectorSize;
      56             :     /// The size in bytes of the smallest target machine instruction. Statement
      57             :     /// program opcodes that alter the address register first multiply their
      58             :     /// operands by this value.
      59             :     uint8_t MinInstLength;
      60             :     /// The maximum number of individual operations that may be encoded in an
      61             :     /// instruction.
      62             :     uint8_t MaxOpsPerInst;
      63             :     /// The initial value of theis_stmtregister.
      64             :     uint8_t DefaultIsStmt;
      65             :     /// This parameter affects the meaning of the special opcodes. See below.
      66             :     int8_t LineBase;
      67             :     /// This parameter affects the meaning of the special opcodes. See below.
      68             :     uint8_t LineRange;
      69             :     /// The number assigned to the first special opcode.
      70             :     uint8_t OpcodeBase;
      71             :     /// For v5, whether filename entries provide an MD5 checksum.
      72             :     bool HasMD5;
      73             :     std::vector<uint8_t> StandardOpcodeLengths;
      74             :     std::vector<DWARFFormValue> IncludeDirectories;
      75             :     std::vector<FileNameEntry> FileNames;
      76             : 
      77             :     const DWARFFormParams getFormParams() const { return FormParams; }
      78             :     uint16_t getVersion() const { return FormParams.Version; }
      79             :     uint8_t getAddressSize() const { return FormParams.AddrSize; }
      80             :     bool isDWARF64() const { return FormParams.Format == dwarf::DWARF64; }
      81             : 
      82        1206 :     uint32_t sizeofTotalLength() const { return isDWARF64() ? 12 : 4; }
      83             : 
      84        1244 :     uint32_t sizeofPrologueLength() const { return isDWARF64() ? 8 : 4; }
      85             : 
      86             :     /// Length of the prologue in bytes.
      87             :     uint32_t getLength() const {
      88             :       return PrologueLength + sizeofTotalLength() + sizeof(getVersion()) +
      89             :              sizeofPrologueLength();
      90             :     }
      91             : 
      92             :     /// Length of the line table data in bytes (not including the prologue).
      93             :     uint32_t getStatementTableLength() const {
      94             :       return TotalLength + sizeofTotalLength() - getLength();
      95             :     }
      96             : 
      97             :     int32_t getMaxLineIncrementForSpecialOpcode() const {
      98             :       return LineBase + (int8_t)LineRange - 1;
      99             :     }
     100             : 
     101             :     void clear();
     102             :     void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const;
     103             :     bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
     104             :                const DWARFContext &Ctx, const DWARFUnit *U = nullptr);
     105             :   };
     106             : 
     107             :   /// Standard .debug_line state machine structure.
     108             :   struct Row {
     109             :     explicit Row(bool DefaultIsStmt = false);
     110             : 
     111             :     /// Called after a row is appended to the matrix.
     112             :     void postAppend();
     113             :     void reset(bool DefaultIsStmt);
     114             :     void dump(raw_ostream &OS) const;
     115             : 
     116             :     static void dumpTableHeader(raw_ostream &OS);
     117             : 
     118        3099 :     static bool orderByAddress(const Row &LHS, const Row &RHS) {
     119        3099 :       return LHS.Address < RHS.Address;
     120             :     }
     121             : 
     122             :     /// The program-counter value corresponding to a machine instruction
     123             :     /// generated by the compiler.
     124             :     uint64_t Address;
     125             :     /// An unsigned integer indicating a source line number. Lines are numbered
     126             :     /// beginning at 1. The compiler may emit the value 0 in cases where an
     127             :     /// instruction cannot be attributed to any source line.
     128             :     uint32_t Line;
     129             :     /// An unsigned integer indicating a column number within a source line.
     130             :     /// Columns are numbered beginning at 1. The value 0 is reserved to indicate
     131             :     /// that a statement begins at the 'left edge' of the line.
     132             :     uint16_t Column;
     133             :     /// An unsigned integer indicating the identity of the source file
     134             :     /// corresponding to a machine instruction.
     135             :     uint16_t File;
     136             :     /// An unsigned integer representing the DWARF path discriminator value
     137             :     /// for this location.
     138             :     uint32_t Discriminator;
     139             :     /// An unsigned integer whose value encodes the applicable instruction set
     140             :     /// architecture for the current instruction.
     141             :     uint8_t Isa;
     142             :     /// A boolean indicating that the current instruction is the beginning of a
     143             :     /// statement.
     144             :     uint8_t IsStmt : 1,
     145             :         /// A boolean indicating that the current instruction is the
     146             :         /// beginning of a basic block.
     147             :         BasicBlock : 1,
     148             :         /// A boolean indicating that the current address is that of the
     149             :         /// first byte after the end of a sequence of target machine
     150             :         /// instructions.
     151             :         EndSequence : 1,
     152             :         /// A boolean indicating that the current address is one (of possibly
     153             :         /// many) where execution should be suspended for an entry breakpoint
     154             :         /// of a function.
     155             :         PrologueEnd : 1,
     156             :         /// A boolean indicating that the current address is one (of possibly
     157             :         /// many) where execution should be suspended for an exit breakpoint
     158             :         /// of a function.
     159             :         EpilogueBegin : 1;
     160             :   };
     161             : 
     162             :   /// Represents a series of contiguous machine instructions. Line table for
     163             :   /// each compilation unit may consist of multiple sequences, which are not
     164             :   /// guaranteed to be in the order of ascending instruction address.
     165             :   struct Sequence {
     166             :     Sequence();
     167             : 
     168             :     /// Sequence describes instructions at address range [LowPC, HighPC)
     169             :     /// and is described by line table rows [FirstRowIndex, LastRowIndex).
     170             :     uint64_t LowPC;
     171             :     uint64_t HighPC;
     172             :     unsigned FirstRowIndex;
     173             :     unsigned LastRowIndex;
     174             :     bool Empty;
     175             : 
     176             :     void reset();
     177             : 
     178        1137 :     static bool orderByLowPC(const Sequence &LHS, const Sequence &RHS) {
     179        1137 :       return LHS.LowPC < RHS.LowPC;
     180             :     }
     181             : 
     182             :     bool isValid() const {
     183        1212 :       return !Empty && (LowPC < HighPC) && (FirstRowIndex < LastRowIndex);
     184             :     }
     185             : 
     186         767 :     bool containsPC(uint64_t PC) const { return (LowPC <= PC && PC < HighPC); }
     187             :   };
     188             : 
     189        9992 :   struct LineTable {
     190             :     LineTable();
     191             : 
     192             :     /// Represents an invalid row
     193             :     const uint32_t UnknownRowIndex = UINT32_MAX;
     194             : 
     195        7432 :     void appendRow(const DWARFDebugLine::Row &R) { Rows.push_back(R); }
     196             : 
     197             :     void appendSequence(const DWARFDebugLine::Sequence &S) {
     198        1195 :       Sequences.push_back(S);
     199             :     }
     200             : 
     201             :     /// Returns the index of the row with file/line info for a given address,
     202             :     /// or UnknownRowIndex if there is no such row.
     203             :     uint32_t lookupAddress(uint64_t Address) const;
     204             : 
     205             :     bool lookupAddressRange(uint64_t Address, uint64_t Size,
     206             :                             std::vector<uint32_t> &Result) const;
     207             : 
     208             :     bool hasFileAtIndex(uint64_t FileIndex) const;
     209             : 
     210             :     /// Extracts filename by its index in filename table in prologue.
     211             :     /// Returns true on success.
     212             :     bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
     213             :                             DILineInfoSpecifier::FileLineInfoKind Kind,
     214             :                             std::string &Result) const;
     215             : 
     216             :     /// Fills the Result argument with the file and line information
     217             :     /// corresponding to Address. Returns true on success.
     218             :     bool getFileLineInfoForAddress(uint64_t Address, const char *CompDir,
     219             :                                    DILineInfoSpecifier::FileLineInfoKind Kind,
     220             :                                    DILineInfo &Result) const;
     221             : 
     222             :     void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const;
     223             :     void clear();
     224             : 
     225             :     /// Parse prologue and all rows.
     226             :     bool parse(DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
     227             :                const DWARFContext &Ctx, const DWARFUnit *U,
     228             :                raw_ostream *OS = nullptr);
     229             : 
     230             :     using RowVector = std::vector<Row>;
     231             :     using RowIter = RowVector::const_iterator;
     232             :     using SequenceVector = std::vector<Sequence>;
     233             :     using SequenceIter = SequenceVector::const_iterator;
     234             : 
     235             :     struct Prologue Prologue;
     236             :     RowVector Rows;
     237             :     SequenceVector Sequences;
     238             : 
     239             :   private:
     240             :     uint32_t findRowInSeq(const DWARFDebugLine::Sequence &Seq,
     241             :                           uint64_t Address) const;
     242             :   };
     243             : 
     244             :   const LineTable *getLineTable(uint32_t Offset) const;
     245             :   const LineTable *getOrParseLineTable(DWARFDataExtractor &DebugLineData,
     246             :                                        uint32_t Offset, const DWARFContext &C,
     247             :                                        const DWARFUnit *U);
     248             : 
     249             : private:
     250             :   struct ParsingState {
     251             :     ParsingState(struct LineTable *LT);
     252             : 
     253             :     void resetRowAndSequence();
     254             :     void appendRowToMatrix(uint32_t Offset);
     255             : 
     256             :     /// Line table we're currently parsing.
     257             :     struct LineTable *LineTable;
     258             :     /// The row number that starts at zero for the prologue, and increases for
     259             :     /// each row added to the matrix.
     260             :     unsigned RowNumber = 0;
     261             :     struct Row Row;
     262             :     struct Sequence Sequence;
     263             :   };
     264             : 
     265             :   using LineTableMapTy = std::map<uint32_t, LineTable>;
     266             :   using LineTableIter = LineTableMapTy::iterator;
     267             :   using LineTableConstIter = LineTableMapTy::const_iterator;
     268             : 
     269             :   LineTableMapTy LineTableMap;
     270             : };
     271             : 
     272             : } // end namespace llvm
     273             : 
     274             : #endif // LLVM_DEBUGINFO_DWARFDEBUGLINE_H

Generated by: LCOV version 1.13