LCOV - code coverage report
Current view: top level - include/llvm/DebugInfo - DIContext.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 19 34 55.9 %
Date: 2017-09-14 15:23:50 Functions: 11 17 64.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DIContext.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             : // This file defines DIContext, an abstract data structure that holds
      11             : // debug information data.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_DEBUGINFO_DICONTEXT_H
      16             : #define LLVM_DEBUGINFO_DICONTEXT_H
      17             : 
      18             : #include "llvm/ADT/SmallVector.h"
      19             : #include "llvm/Object/ObjectFile.h"
      20             : #include <cassert>
      21             : #include <cstdint>
      22             : #include <memory>
      23             : #include <string>
      24             : #include <tuple>
      25             : #include <utility>
      26             : 
      27             : namespace llvm {
      28             : 
      29             : class raw_ostream;
      30             : 
      31             : /// DILineInfo - a format-neutral container for source line information.
      32       38203 : struct DILineInfo {
      33             :   std::string FileName;
      34             :   std::string FunctionName;
      35             :   uint32_t Line = 0;
      36             :   uint32_t Column = 0;
      37             :   uint32_t StartLine = 0;
      38             : 
      39             :   // DWARF-specific.
      40             :   uint32_t Discriminator = 0;
      41             : 
      42       13355 :   DILineInfo() : FileName("<invalid>"), FunctionName("<invalid>") {}
      43             : 
      44           0 :   bool operator==(const DILineInfo &RHS) const {
      45           0 :     return Line == RHS.Line && Column == RHS.Column &&
      46           0 :            FileName == RHS.FileName && FunctionName == RHS.FunctionName &&
      47           0 :            StartLine == RHS.StartLine && Discriminator == RHS.Discriminator;
      48             :   }
      49             :   bool operator!=(const DILineInfo &RHS) const {
      50           0 :     return !(*this == RHS);
      51             :   }
      52         200 :   bool operator<(const DILineInfo &RHS) const {
      53         600 :     return std::tie(FileName, FunctionName, Line, Column, StartLine,
      54             :                     Discriminator) <
      55         200 :            std::tie(RHS.FileName, RHS.FunctionName, RHS.Line, RHS.Column,
      56         800 :                     RHS.StartLine, RHS.Discriminator);
      57             :   }
      58             : };
      59             : 
      60             : using DILineInfoTable = SmallVector<std::pair<uint64_t, DILineInfo>, 16>;
      61             : 
      62             : /// DIInliningInfo - a format-neutral container for inlined code description.
      63        6678 : class DIInliningInfo {
      64             :   SmallVector<DILineInfo, 4> Frames;
      65             : 
      66             : public:
      67        2208 :   DIInliningInfo() = default;
      68             : 
      69             :   DILineInfo getFrame(unsigned Index) const {
      70             :     assert(Index < Frames.size());
      71        1380 :     return Frames[Index];
      72             :   }
      73             : 
      74             :   DILineInfo *getMutableFrame(unsigned Index) {
      75             :     assert(Index < Frames.size());
      76        2186 :     return &Frames[Index];
      77             :   }
      78             : 
      79             :   uint32_t getNumberOfFrames() const {
      80        4526 :     return Frames.size();
      81             :   }
      82             : 
      83             :   void addFrame(const DILineInfo &Frame) {
      84         690 :     Frames.push_back(Frame);
      85             :   }
      86             : };
      87             : 
      88             : /// DIGlobal - container for description of a global variable.
      89           0 : struct DIGlobal {
      90             :   std::string Name;
      91             :   uint64_t Start = 0;
      92             :   uint64_t Size = 0;
      93             : 
      94           0 :   DIGlobal() : Name("<invalid>") {}
      95             : };
      96             : 
      97             : /// A DINameKind is passed to name search methods to specify a
      98             : /// preference regarding the type of name resolution the caller wants.
      99             : enum class DINameKind { None, ShortName, LinkageName };
     100             : 
     101             : /// DILineInfoSpecifier - controls which fields of DILineInfo container
     102             : /// should be filled with data.
     103             : struct DILineInfoSpecifier {
     104             :   enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
     105             :   using FunctionNameKind = DINameKind;
     106             : 
     107             :   FileLineInfoKind FLIKind;
     108             :   FunctionNameKind FNKind;
     109             : 
     110             :   DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
     111             :                       FunctionNameKind FNKind = FunctionNameKind::None)
     112          26 :       : FLIKind(FLIKind), FNKind(FNKind) {}
     113             : };
     114             : 
     115             : /// This is just a helper to programmatically construct DIDumpType.
     116             : enum DIDumpTypeCounter {
     117             :   DIDT_ID_Null = 0,
     118             : #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
     119             :   DIDT_ID_##ENUM_NAME,
     120             : #include "llvm/BinaryFormat/Dwarf.def"
     121             : #undef HANDLE_DWARF_SECTION
     122             :   DIDT_ID_UUID,
     123             :   DIDT_ID_Count
     124             : };
     125             : static_assert(DIDT_ID_Count <= 64, "section types overflow storage");
     126             : 
     127             : /// Selects which debug sections get dumped.
     128             : enum DIDumpType : uint64_t {
     129             :   DIDT_Null,
     130             :   DIDT_All             = ~0ULL,
     131             : #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
     132             :   DIDT_##ENUM_NAME = 1 << (DIDT_ID_##ENUM_NAME - 1),
     133             : #include "llvm/BinaryFormat/Dwarf.def"
     134             : #undef HANDLE_DWARF_SECTION
     135             :   DIDT_UUID = 1 << (DIDT_ID_UUID - 1),
     136             : };
     137             : 
     138             : /// Container for dump options that control which debug information will be
     139             : /// dumped.
     140         605 : struct DIDumpOptions {
     141             :     uint64_t DumpType = DIDT_All;
     142             :     bool DumpEH = false;
     143             :     bool SummarizeTypes = false;
     144             :     bool Verbose = false;
     145             : };
     146             : 
     147             : class DIContext {
     148             : public:
     149             :   enum DIContextKind {
     150             :     CK_DWARF,
     151             :     CK_PDB
     152             :   };
     153             : 
     154        1008 :   DIContext(DIContextKind K) : Kind(K) {}
     155             :   virtual ~DIContext() = default;
     156             : 
     157             :   DIContextKind getKind() const { return Kind; }
     158             : 
     159             :   virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
     160             : 
     161           0 :   virtual bool verify(raw_ostream &OS, uint64_t DumpType = DIDT_All,
     162             :                       DIDumpOptions DumpOpts = {}) {
     163             :     // No verifier? Just say things went well.
     164           0 :     return true;
     165             :   }
     166             : 
     167             :   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
     168             :       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
     169             :   virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
     170             :       uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
     171             :   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
     172             :       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
     173             : 
     174             : private:
     175             :   const DIContextKind Kind;
     176             : };
     177             : 
     178             : /// An inferface for inquiring the load address of a loaded object file
     179             : /// to be used by the DIContext implementations when applying relocations
     180             : /// on the fly.
     181             : class LoadedObjectInfo {
     182             : protected:
     183             :   LoadedObjectInfo() = default;
     184           0 :   LoadedObjectInfo(const LoadedObjectInfo &) = default;
     185             : 
     186             : public:
     187             :   virtual ~LoadedObjectInfo() = default;
     188             : 
     189             :   /// Obtain the Load Address of a section by SectionRef.
     190             :   ///
     191             :   /// Calculate the address of the given section.
     192             :   /// The section need not be present in the local address space. The addresses
     193             :   /// need to be consistent with the addresses used to query the DIContext and
     194             :   /// the output of this function should be deterministic, i.e. repeated calls with
     195             :   /// the same Sec should give the same address.
     196           0 :   virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const {
     197           0 :     return 0;
     198             :   }
     199             : 
     200             :   /// If conveniently available, return the content of the given Section.
     201             :   ///
     202             :   /// When the section is available in the local address space, in relocated (loaded)
     203             :   /// form, e.g. because it was relocated by a JIT for execution, this function
     204             :   /// should provide the contents of said section in `Data`. If the loaded section
     205             :   /// is not available, or the cost of retrieving it would be prohibitive, this
     206             :   /// function should return false. In that case, relocations will be read from the
     207             :   /// local (unrelocated) object file and applied on the fly. Note that this method
     208             :   /// is used purely for optimzation purposes in the common case of JITting in the
     209             :   /// local address space, so returning false should always be correct.
     210         134 :   virtual bool getLoadedSectionContents(const object::SectionRef &Sec,
     211             :                                         StringRef &Data) const {
     212         134 :     return false;
     213             :   }
     214             : 
     215             :   // FIXME: This is untested and unused anywhere in the LLVM project, it's
     216             :   // used/needed by Julia (an external project). It should have some coverage
     217             :   // (at least tests, but ideally example functionality).
     218             :   /// Obtain a copy of this LoadedObjectInfo.
     219             :   virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;
     220             : };
     221             : 
     222             : template <typename Derived, typename Base = LoadedObjectInfo>
     223         678 : struct LoadedObjectInfoHelper : Base {
     224             : protected:
     225           0 :   LoadedObjectInfoHelper(const LoadedObjectInfoHelper &) = default;
     226             :   LoadedObjectInfoHelper() = default;
     227             : 
     228             : public:
     229             :   template <typename... Ts>
     230        1356 :   LoadedObjectInfoHelper(Ts &&... Args) : Base(std::forward<Ts>(Args)...) {}
     231             : 
     232           0 :   std::unique_ptr<llvm::LoadedObjectInfo> clone() const override {
     233           0 :     return llvm::make_unique<Derived>(static_cast<const Derived &>(*this));
     234             :   }
     235             : };
     236             : 
     237             : } // end namespace llvm
     238             : 
     239             : #endif // LLVM_DEBUGINFO_DICONTEXT_H

Generated by: LCOV version 1.13