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

          Line data    Source code
       1             : //===- DWARFContext.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_DWARF_DWARFCONTEXT_H
      11             : #define LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H
      12             : 
      13             : #include "llvm/ADT/MapVector.h"
      14             : #include "llvm/ADT/SmallString.h"
      15             : #include "llvm/ADT/SmallVector.h"
      16             : #include "llvm/ADT/StringMap.h"
      17             : #include "llvm/ADT/StringRef.h"
      18             : #include "llvm/ADT/iterator_range.h"
      19             : #include "llvm/DebugInfo/DIContext.h"
      20             : #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
      21             : #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
      22             : #include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"
      23             : #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
      24             : #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
      25             : #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
      26             : #include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
      27             : #include "llvm/DebugInfo/DWARF/DWARFDie.h"
      28             : #include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
      29             : #include "llvm/DebugInfo/DWARF/DWARFObject.h"
      30             : #include "llvm/DebugInfo/DWARF/DWARFSection.h"
      31             : #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
      32             : #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
      33             : #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
      34             : #include "llvm/Object/Binary.h"
      35             : #include "llvm/Object/ObjectFile.h"
      36             : #include "llvm/Support/Error.h"
      37             : #include "llvm/Support/Host.h"
      38             : #include <cstdint>
      39             : #include <deque>
      40             : #include <map>
      41             : #include <memory>
      42             : 
      43             : namespace llvm {
      44             : 
      45             : class DataExtractor;
      46             : class MCRegisterInfo;
      47             : class MemoryBuffer;
      48             : class raw_ostream;
      49             : 
      50             : /// Used as a return value for a error callback passed to DWARF context.
      51             : /// Callback should return Halt if client application wants to stop
      52             : /// object parsing, or should return Continue otherwise.
      53             : enum class ErrorPolicy { Halt, Continue };
      54             : 
      55             : /// DWARFContext
      56             : /// This data structure is the top level entity that deals with dwarf debug
      57             : /// information parsing. The actual data is supplied through DWARFObj.
      58       11967 : class DWARFContext : public DIContext {
      59             :   DWARFUnitSection<DWARFCompileUnit> CUs;
      60             :   std::deque<DWARFUnitSection<DWARFTypeUnit>> TUs;
      61             :   std::unique_ptr<DWARFUnitIndex> CUIndex;
      62             :   std::unique_ptr<DWARFGdbIndex> GdbIndex;
      63             :   std::unique_ptr<DWARFUnitIndex> TUIndex;
      64             :   std::unique_ptr<DWARFDebugAbbrev> Abbrev;
      65             :   std::unique_ptr<DWARFDebugLoc> Loc;
      66             :   std::unique_ptr<DWARFDebugAranges> Aranges;
      67             :   std::unique_ptr<DWARFDebugLine> Line;
      68             :   std::unique_ptr<DWARFDebugFrame> DebugFrame;
      69             :   std::unique_ptr<DWARFDebugFrame> EHFrame;
      70             :   std::unique_ptr<DWARFDebugMacro> Macro;
      71             : 
      72             :   DWARFUnitSection<DWARFCompileUnit> DWOCUs;
      73             :   std::deque<DWARFUnitSection<DWARFTypeUnit>> DWOTUs;
      74             :   std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
      75             :   std::unique_ptr<DWARFDebugLocDWO> LocDWO;
      76             : 
      77             :   /// The maximum DWARF version of all units.
      78             :   unsigned MaxVersion = 0;
      79             : 
      80          85 :   struct DWOFile {
      81             :     object::OwningBinary<object::ObjectFile> File;
      82             :     std::unique_ptr<DWARFContext> Context;
      83             :   };
      84             :   StringMap<std::weak_ptr<DWOFile>> DWOFiles;
      85             :   std::weak_ptr<DWOFile> DWP;
      86             :   bool CheckedForDWP = false;
      87             :   std::string DWPName;
      88             : 
      89             :   std::unique_ptr<MCRegisterInfo> RegInfo;
      90             : 
      91             :   /// Read compile units from the debug_info section (if necessary)
      92             :   /// and store them in CUs.
      93             :   void parseCompileUnits();
      94             : 
      95             :   /// Read type units from the debug_types sections (if necessary)
      96             :   /// and store them in TUs.
      97             :   void parseTypeUnits();
      98             : 
      99             :   /// Read compile units from the debug_info.dwo section (if necessary)
     100             :   /// and store them in DWOCUs.
     101             :   void parseDWOCompileUnits();
     102             : 
     103             :   /// Read type units from the debug_types.dwo section (if necessary)
     104             :   /// and store them in DWOTUs.
     105             :   void parseDWOTypeUnits();
     106             : 
     107             : protected:
     108             :   std::unique_ptr<const DWARFObject> DObj;
     109             : 
     110             : public:
     111             :   DWARFContext(std::unique_ptr<const DWARFObject> DObj,
     112             :                std::string DWPName = "");
     113             :   ~DWARFContext();
     114             : 
     115             :   DWARFContext(DWARFContext &) = delete;
     116             :   DWARFContext &operator=(DWARFContext &) = delete;
     117             : 
     118     1463190 :   const DWARFObject &getDWARFObj() const { return *DObj; }
     119             : 
     120             :   static bool classof(const DIContext *DICtx) {
     121         838 :     return DICtx->getKind() == CK_DWARF;
     122             :   }
     123             : 
     124             :   void dump(raw_ostream &OS, DIDumpOptions DumpOpts) override;
     125             : 
     126             :   bool verify(raw_ostream &OS, uint64_t DumpType = DIDT_All,
     127             :               DIDumpOptions DumpOpts = {}) override;
     128             : 
     129             :   using cu_iterator_range = DWARFUnitSection<DWARFCompileUnit>::iterator_range;
     130             :   using tu_iterator_range = DWARFUnitSection<DWARFTypeUnit>::iterator_range;
     131             :   using tu_section_iterator_range = iterator_range<decltype(TUs)::iterator>;
     132             : 
     133             :   /// Get compile units in this context.
     134             :   cu_iterator_range compile_units() {
     135         995 :     parseCompileUnits();
     136        3980 :     return cu_iterator_range(CUs.begin(), CUs.end());
     137             :   }
     138             : 
     139             :   /// Get type units in this context.
     140             :   tu_section_iterator_range type_unit_sections() {
     141          12 :     parseTypeUnits();
     142          48 :     return tu_section_iterator_range(TUs.begin(), TUs.end());
     143             :   }
     144             : 
     145             :   /// Get compile units in the DWO context.
     146             :   cu_iterator_range dwo_compile_units() {
     147          37 :     parseDWOCompileUnits();
     148         148 :     return cu_iterator_range(DWOCUs.begin(), DWOCUs.end());
     149             :   }
     150             : 
     151             :   /// Get type units in the DWO context.
     152             :   tu_section_iterator_range dwo_type_unit_sections() {
     153          12 :     parseDWOTypeUnits();
     154          48 :     return tu_section_iterator_range(DWOTUs.begin(), DWOTUs.end());
     155             :   }
     156             : 
     157             :   /// Get the number of compile units in this context.
     158             :   unsigned getNumCompileUnits() {
     159         206 :     parseCompileUnits();
     160         412 :     return CUs.size();
     161             :   }
     162             : 
     163             :   /// Get the number of compile units in this context.
     164         168 :   unsigned getNumTypeUnits() {
     165         168 :     parseTypeUnits();
     166         336 :     return TUs.size();
     167             :   }
     168             : 
     169             :   /// Get the number of compile units in the DWO context.
     170             :   unsigned getNumDWOCompileUnits() {
     171         168 :     parseDWOCompileUnits();
     172         336 :     return DWOCUs.size();
     173             :   }
     174             : 
     175             :   /// Get the number of compile units in the DWO context.
     176         166 :   unsigned getNumDWOTypeUnits() {
     177         166 :     parseDWOTypeUnits();
     178         332 :     return DWOTUs.size();
     179             :   }
     180             : 
     181             :   /// Get the compile unit at the specified index for this compile unit.
     182             :   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
     183         196 :     parseCompileUnits();
     184         588 :     return CUs[index].get();
     185             :   }
     186             : 
     187             :   /// Get the compile unit at the specified index for the DWO compile units.
     188             :   DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
     189             :     parseDWOCompileUnits();
     190             :     return DWOCUs[index].get();
     191             :   }
     192             : 
     193             :   DWARFCompileUnit *getDWOCompileUnitForHash(uint64_t Hash);
     194             : 
     195             :   /// Get a DIE given an exact offset.
     196             :   DWARFDie getDIEForOffset(uint32_t Offset);
     197             : 
     198             :   unsigned getMaxVersion() const { return MaxVersion; }
     199             : 
     200             :   void setMaxVersionIfGreater(unsigned Version) {
     201       27506 :     if (Version > MaxVersion)
     202         746 :       MaxVersion = Version;
     203             :   }
     204             : 
     205             :   const DWARFUnitIndex &getCUIndex();
     206             :   DWARFGdbIndex &getGdbIndex();
     207             :   const DWARFUnitIndex &getTUIndex();
     208             : 
     209             :   /// Get a pointer to the parsed DebugAbbrev object.
     210             :   const DWARFDebugAbbrev *getDebugAbbrev();
     211             : 
     212             :   /// Get a pointer to the parsed DebugLoc object.
     213             :   const DWARFDebugLoc *getDebugLoc();
     214             : 
     215             :   /// Get a pointer to the parsed dwo abbreviations object.
     216             :   const DWARFDebugAbbrev *getDebugAbbrevDWO();
     217             : 
     218             :   /// Get a pointer to the parsed DebugLoc object.
     219             :   const DWARFDebugLocDWO *getDebugLocDWO();
     220             : 
     221             :   /// Get a pointer to the parsed DebugAranges object.
     222             :   const DWARFDebugAranges *getDebugAranges();
     223             : 
     224             :   /// Get a pointer to the parsed frame information object.
     225             :   const DWARFDebugFrame *getDebugFrame();
     226             : 
     227             :   /// Get a pointer to the parsed eh frame information object.
     228             :   const DWARFDebugFrame *getEHFrame();
     229             : 
     230             :   /// Get a pointer to the parsed DebugMacro object.
     231             :   const DWARFDebugMacro *getDebugMacro();
     232             : 
     233             :   /// Get a pointer to a parsed line table corresponding to a compile unit.
     234             :   const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu);
     235             : 
     236             :   DILineInfo getLineInfoForAddress(uint64_t Address,
     237             :       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
     238             :   DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
     239             :       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
     240             :   DIInliningInfo getInliningInfoForAddress(uint64_t Address,
     241             :       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
     242             : 
     243       17570 :   bool isLittleEndian() const { return DObj->isLittleEndian(); }
     244             :   static bool isSupportedVersion(unsigned version) {
     245       27544 :     return version == 2 || version == 3 || version == 4 || version == 5;
     246             :   }
     247             : 
     248             :   std::shared_ptr<DWARFContext> getDWOContext(StringRef AbsolutePath);
     249             : 
     250        4524 :   const MCRegisterInfo *getRegisterInfo() const { return RegInfo.get(); }
     251             : 
     252             :   /// Function used to handle default error reporting policy. Prints a error
     253             :   /// message and returns Continue, so DWARF context ignores the error.
     254             :   static ErrorPolicy defaultErrorHandler(Error E);
     255             :   static std::unique_ptr<DWARFContext>
     256             :   create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
     257             :          function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler,
     258             :          std::string DWPName = "");
     259             : 
     260             :   static std::unique_ptr<DWARFContext>
     261             :   create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
     262             :          uint8_t AddrSize, bool isLittleEndian = sys::IsLittleEndianHost);
     263             : 
     264             :   /// Loads register info for the architecture of the provided object file.
     265             :   /// Improves readability of dumped DWARF expressions. Requires the caller to
     266             :   /// have initialized the relevant target descriptions.
     267             :   Error loadRegisterInfo(const object::ObjectFile &Obj);
     268             : 
     269             : private:
     270             :   /// Return the compile unit that includes an offset (relative to .debug_info).
     271             :   DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
     272             : 
     273             :   /// Return the compile unit which contains instruction with provided
     274             :   /// address.
     275             :   DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
     276             : };
     277             : 
     278             : } // end namespace llvm
     279             : 
     280             : #endif // LLVM_DEBUGINFO_DWARF_DWARFCONTEXT_H

Generated by: LCOV version 1.13