LLVM API Documentation

DWARFDebugInfoEntry.h
Go to the documentation of this file.
00001 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
00011 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
00012 
00013 #include "DWARFAbbreviationDeclaration.h"
00014 #include "DWARFDebugRangeList.h"
00015 #include "llvm/ADT/SmallVector.h"
00016 #include "llvm/DebugInfo/DIContext.h"
00017 #include "llvm/Support/DataTypes.h"
00018 
00019 namespace llvm {
00020 
00021 class DWARFDebugAranges;
00022 class DWARFCompileUnit;
00023 class DWARFUnit;
00024 class DWARFContext;
00025 class DWARFFormValue;
00026 struct DWARFDebugInfoEntryInlinedChain;
00027 
00028 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
00029 class DWARFDebugInfoEntryMinimal {
00030   /// Offset within the .debug_info of the start of this entry.
00031   uint32_t Offset;
00032 
00033   /// How many to add to "this" to get the sibling.
00034   uint32_t SiblingIdx;
00035 
00036   const DWARFAbbreviationDeclaration *AbbrevDecl;
00037 public:
00038   DWARFDebugInfoEntryMinimal()
00039     : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
00040 
00041   void dump(raw_ostream &OS, const DWARFUnit *u, unsigned recurseDepth,
00042             unsigned indent = 0) const;
00043   void dumpAttribute(raw_ostream &OS, const DWARFUnit *u, uint32_t *offset_ptr,
00044                      uint16_t attr, uint16_t form, unsigned indent = 0) const;
00045 
00046   /// Extracts a debug info entry, which is a child of a given unit,
00047   /// starting at a given offset. If DIE can't be extracted, returns false and
00048   /// doesn't change OffsetPtr.
00049   bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
00050 
00051   uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
00052   bool isNULL() const { return AbbrevDecl == nullptr; }
00053 
00054   /// Returns true if DIE represents a subprogram (not inlined).
00055   bool isSubprogramDIE() const;
00056   /// Returns true if DIE represents a subprogram or an inlined
00057   /// subroutine.
00058   bool isSubroutineDIE() const;
00059 
00060   uint32_t getOffset() const { return Offset; }
00061   bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
00062 
00063   // We know we are kept in a vector of contiguous entries, so we know
00064   // our sibling will be some index after "this".
00065   const DWARFDebugInfoEntryMinimal *getSibling() const {
00066     return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
00067   }
00068 
00069   // We know we are kept in a vector of contiguous entries, so we know
00070   // we don't need to store our child pointer, if we have a child it will
00071   // be the next entry in the list...
00072   const DWARFDebugInfoEntryMinimal *getFirstChild() const {
00073     return hasChildren() ? this + 1 : nullptr;
00074   }
00075 
00076   void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
00077     if (Sibling) {
00078       // We know we are kept in a vector of contiguous entries, so we know
00079       // our sibling will be some index after "this".
00080       SiblingIdx = Sibling - this;
00081     } else
00082       SiblingIdx = 0;
00083   }
00084 
00085   const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
00086     return AbbrevDecl;
00087   }
00088 
00089   bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
00090                          DWARFFormValue &FormValue) const;
00091 
00092   const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
00093                                         const char *FailValue) const;
00094 
00095   uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
00096                                       uint64_t FailValue) const;
00097 
00098   uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
00099                                                const uint16_t Attr,
00100                                                uint64_t FailValue) const;
00101 
00102   uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
00103                                         uint64_t FailValue) const;
00104 
00105   uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
00106                                             const uint16_t Attr,
00107                                             uint64_t FailValue) const;
00108 
00109   uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
00110 
00111   /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
00112   /// Returns true if both attributes are present.
00113   bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
00114                        uint64_t &HighPC) const;
00115 
00116   DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
00117 
00118   void collectChildrenAddressRanges(const DWARFUnit *U,
00119                                     DWARFAddressRangesVector &Ranges) const;
00120 
00121   bool addressRangeContainsAddress(const DWARFUnit *U,
00122                                    const uint64_t Address) const;
00123 
00124   /// If a DIE represents a subprogram (or inlined subroutine),
00125   /// returns its mangled name (or short name, if mangled is missing).
00126   /// This name may be fetched from specification or abstract origin
00127   /// for this subprogram. Returns null if no name is found.
00128   const char *
00129   getSubroutineName(const DWARFUnit *U,
00130                     DILineInfoSpecifier::FunctionNameKind Kind) const;
00131 
00132   /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
00133   /// DW_AT_call_column from DIE (or zeroes if they are missing).
00134   void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
00135                       uint32_t &CallLine, uint32_t &CallColumn) const;
00136 
00137   /// Get inlined chain for a given address, rooted at the current DIE.
00138   /// Returns empty chain if address is not contained in address range
00139   /// of current DIE.
00140   DWARFDebugInfoEntryInlinedChain
00141   getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
00142 };
00143 
00144 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
00145 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
00146 /// in some concrete inlined instance tree. Address range for each DIE
00147 /// (except the last DIE) in this chain is contained in address
00148 /// range for next DIE in the chain.
00149 struct DWARFDebugInfoEntryInlinedChain {
00150   DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
00151   SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;
00152   const DWARFUnit *U;
00153 };
00154 
00155 }
00156 
00157 #endif