1 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef SymbolFileDWARF_DWARFDebugInfoEntry_h_ 10 #define SymbolFileDWARF_DWARFDebugInfoEntry_h_ 11 12 #include "SymbolFileDWARF.h" 13 #include "llvm/ADT/SmallVector.h" 14 15 #include "DWARFAbbreviationDeclaration.h" 16 #include "DWARFDebugAbbrev.h" 17 #include "DWARFDebugRanges.h" 18 #include <map> 19 #include <set> 20 #include <vector> 21 22 class DWARFDeclContext; 23 24 #define DIE_SIBLING_IDX_BITSIZE 31 25 26 class DWARFDebugInfoEntry { 27 public: 28 typedef std::vector<DWARFDebugInfoEntry> collection; 29 typedef collection::iterator iterator; 30 typedef collection::const_iterator const_iterator; 31 32 DWARFDebugInfoEntry() 33 : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0), 34 m_has_children(false), m_abbr_idx(0), m_tag(0) {} 35 36 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; } 37 bool operator==(const DWARFDebugInfoEntry &rhs) const; 38 bool operator!=(const DWARFDebugInfoEntry &rhs) const; 39 40 void BuildAddressRangeTable(const DWARFUnit *cu, 41 DWARFDebugAranges *debug_aranges) const; 42 43 void BuildFunctionAddressRangeTable(const DWARFUnit *cu, 44 DWARFDebugAranges *debug_aranges) const; 45 46 bool Extract(const lldb_private::DWARFDataExtractor &data, 47 const DWARFUnit *cu, lldb::offset_t *offset_ptr); 48 49 bool LookupAddress(const dw_addr_t address, const DWARFUnit *cu, 50 DWARFDebugInfoEntry **function_die, 51 DWARFDebugInfoEntry **block_die); 52 53 size_t GetAttributes(const DWARFUnit *cu, 54 DWARFAttributes &attrs, 55 uint32_t curr_depth = 0) 56 const; // "curr_depth" for internal use only, don't set this yourself!!! 57 58 dw_offset_t 59 GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr, 60 DWARFFormValue &formValue, 61 dw_offset_t *end_attr_offset_ptr = nullptr, 62 bool check_specification_or_abstract_origin = false) const; 63 64 const char *GetAttributeValueAsString( 65 const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, 66 bool check_specification_or_abstract_origin = false) const; 67 68 uint64_t GetAttributeValueAsUnsigned( 69 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, 70 bool check_specification_or_abstract_origin = false) const; 71 72 DWARFDIE GetAttributeValueAsReference( 73 const DWARFUnit *cu, const dw_attr_t attr, 74 bool check_specification_or_abstract_origin = false) const; 75 76 uint64_t GetAttributeValueAsAddress( 77 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, 78 bool check_specification_or_abstract_origin = false) const; 79 80 dw_addr_t 81 GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value, 82 bool check_specification_or_abstract_origin = false) const; 83 84 bool GetAttributeAddressRange( 85 const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc, 86 uint64_t fail_value, 87 bool check_specification_or_abstract_origin = false) const; 88 89 size_t GetAttributeAddressRanges( 90 const DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, 91 bool check_specification_or_abstract_origin = false) const; 92 93 const char *GetName(const DWARFUnit *cu) const; 94 95 const char *GetMangledName(const DWARFUnit *cu, 96 bool substitute_name_allowed = true) const; 97 98 const char *GetPubname(const DWARFUnit *cu) const; 99 100 const char *GetQualifiedName(DWARFUnit *cu, std::string &storage) const; 101 102 const char *GetQualifiedName(DWARFUnit *cu, const DWARFAttributes &attributes, 103 std::string &storage) const; 104 105 void Dump(const DWARFUnit *cu, lldb_private::Stream &s, 106 uint32_t recurse_depth) const; 107 108 static void 109 DumpAttribute(const DWARFUnit *cu, 110 const lldb_private::DWARFDataExtractor &data, 111 lldb::offset_t *offset_ptr, lldb_private::Stream &s, 112 dw_attr_t attr, DWARFFormValue &form_value); 113 114 bool GetDIENamesAndRanges( 115 const DWARFUnit *cu, const char *&name, const char *&mangled, 116 DWARFRangeList &rangeList, int &decl_file, int &decl_line, 117 int &decl_column, int &call_file, int &call_line, int &call_column, 118 lldb_private::DWARFExpression *frame_base = nullptr) const; 119 120 const DWARFAbbreviationDeclaration * 121 GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const; 122 123 lldb::offset_t GetFirstAttributeOffset() const; 124 125 dw_tag_t Tag() const { return m_tag; } 126 127 bool IsNULL() const { return m_abbr_idx == 0; } 128 129 dw_offset_t GetOffset() const { return m_offset; } 130 131 bool HasChildren() const { return m_has_children; } 132 133 void SetHasChildren(bool b) { m_has_children = b; } 134 135 // We know we are kept in a vector of contiguous entries, so we know 136 // our parent will be some index behind "this". 137 DWARFDebugInfoEntry *GetParent() { 138 return m_parent_idx > 0 ? this - m_parent_idx : nullptr; 139 } 140 const DWARFDebugInfoEntry *GetParent() const { 141 return m_parent_idx > 0 ? this - m_parent_idx : nullptr; 142 } 143 // We know we are kept in a vector of contiguous entries, so we know 144 // our sibling will be some index after "this". 145 DWARFDebugInfoEntry *GetSibling() { 146 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr; 147 } 148 const DWARFDebugInfoEntry *GetSibling() const { 149 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr; 150 } 151 // We know we are kept in a vector of contiguous entries, so we know 152 // we don't need to store our child pointer, if we have a child it will 153 // be the next entry in the list... 154 DWARFDebugInfoEntry *GetFirstChild() { 155 return HasChildren() ? this + 1 : nullptr; 156 } 157 const DWARFDebugInfoEntry *GetFirstChild() const { 158 return HasChildren() ? this + 1 : nullptr; 159 } 160 161 void GetDWARFDeclContext(DWARFUnit *cu, 162 DWARFDeclContext &dwarf_decl_ctx) const; 163 164 DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const; 165 DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu, 166 const DWARFAttributes &attributes) const; 167 168 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; } 169 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; } 170 171 protected: 172 dw_offset_t m_offset; // Offset within the .debug_info/.debug_types 173 uint32_t m_parent_idx; // How many to subtract from "this" to get the parent. 174 // If zero this die has no parent 175 uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling. 176 // If it is zero, then the DIE doesn't have children, or the 177 // DWARF claimed it had children but the DIE only contained 178 // a single NULL terminating child. 179 m_has_children : 1; 180 uint16_t m_abbr_idx; 181 uint16_t m_tag; // A copy of the DW_TAG value so we don't have to go through 182 // the compile unit abbrev table 183 }; 184 185 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_ 186