2
0

DWARFDebugInfoEntry.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //===-- DWARFDebugInfoEntry.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. #ifndef LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
  10. #define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
  11. #include "llvm/ADT/SmallVector.h"
  12. #include "llvm/DebugInfo/DIContext.h"
  13. #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
  14. #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
  15. #include "llvm/Support/DataTypes.h"
  16. namespace llvm {
  17. class DWARFDebugAranges;
  18. class DWARFCompileUnit;
  19. class DWARFUnit;
  20. class DWARFContext;
  21. class DWARFFormValue;
  22. struct DWARFDebugInfoEntryInlinedChain;
  23. /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
  24. class DWARFDebugInfoEntryMinimal {
  25. /// Offset within the .debug_info of the start of this entry.
  26. uint32_t Offset;
  27. /// How many to add to "this" to get the sibling.
  28. uint32_t SiblingIdx;
  29. const DWARFAbbreviationDeclaration *AbbrevDecl;
  30. public:
  31. DWARFDebugInfoEntryMinimal()
  32. : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
  33. void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth,
  34. unsigned indent = 0) const;
  35. void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr,
  36. uint16_t attr, uint16_t form, unsigned indent = 0) const;
  37. /// Extracts a debug info entry, which is a child of a given unit,
  38. /// starting at a given offset. If DIE can't be extracted, returns false and
  39. /// doesn't change OffsetPtr.
  40. bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
  41. uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
  42. bool isNULL() const { return AbbrevDecl == nullptr; }
  43. /// Returns true if DIE represents a subprogram (not inlined).
  44. bool isSubprogramDIE() const;
  45. /// Returns true if DIE represents a subprogram or an inlined
  46. /// subroutine.
  47. bool isSubroutineDIE() const;
  48. uint32_t getOffset() const { return Offset; }
  49. bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
  50. // We know we are kept in a vector of contiguous entries, so we know
  51. // our sibling will be some index after "this".
  52. const DWARFDebugInfoEntryMinimal *getSibling() const {
  53. return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
  54. }
  55. // We know we are kept in a vector of contiguous entries, so we know
  56. // we don't need to store our child pointer, if we have a child it will
  57. // be the next entry in the list...
  58. const DWARFDebugInfoEntryMinimal *getFirstChild() const {
  59. return hasChildren() ? this + 1 : nullptr;
  60. }
  61. void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
  62. if (Sibling) {
  63. // We know we are kept in a vector of contiguous entries, so we know
  64. // our sibling will be some index after "this".
  65. SiblingIdx = Sibling - this;
  66. } else
  67. SiblingIdx = 0;
  68. }
  69. const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
  70. return AbbrevDecl;
  71. }
  72. bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
  73. DWARFFormValue &FormValue) const;
  74. const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
  75. const char *FailValue) const;
  76. uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
  77. uint64_t FailValue) const;
  78. uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
  79. const uint16_t Attr,
  80. uint64_t FailValue) const;
  81. uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
  82. uint64_t FailValue) const;
  83. uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
  84. const uint16_t Attr,
  85. uint64_t FailValue) const;
  86. uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
  87. /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
  88. /// Returns true if both attributes are present.
  89. bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
  90. uint64_t &HighPC) const;
  91. DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
  92. void collectChildrenAddressRanges(const DWARFUnit *U,
  93. DWARFAddressRangesVector &Ranges) const;
  94. bool addressRangeContainsAddress(const DWARFUnit *U,
  95. const uint64_t Address) const;
  96. /// If a DIE represents a subprogram (or inlined subroutine),
  97. /// returns its mangled name (or short name, if mangled is missing).
  98. /// This name may be fetched from specification or abstract origin
  99. /// for this subprogram. Returns null if no name is found.
  100. const char *getSubroutineName(const DWARFUnit *U, DINameKind Kind) const;
  101. /// Return the DIE name resolving DW_AT_sepcification or
  102. /// DW_AT_abstract_origin references if necessary.
  103. /// Returns null if no name is found.
  104. const char *getName(const DWARFUnit *U, DINameKind Kind) const;
  105. /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
  106. /// DW_AT_call_column from DIE (or zeroes if they are missing).
  107. void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
  108. uint32_t &CallLine, uint32_t &CallColumn) const;
  109. /// Get inlined chain for a given address, rooted at the current DIE.
  110. /// Returns empty chain if address is not contained in address range
  111. /// of current DIE.
  112. DWARFDebugInfoEntryInlinedChain
  113. getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
  114. };
  115. /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
  116. /// DIEs, (possibly ending with subprogram DIE), all of which are contained
  117. /// in some concrete inlined instance tree. Address range for each DIE
  118. /// (except the last DIE) in this chain is contained in address
  119. /// range for next DIE in the chain.
  120. struct DWARFDebugInfoEntryInlinedChain {
  121. DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
  122. SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;
  123. const DWARFUnit *U;
  124. };
  125. }
  126. #endif