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 10 #ifndef SymbolFileDWARF_DWARFDebugInfoEntry_h_ 11 #define SymbolFileDWARF_DWARFDebugInfoEntry_h_ 12 13 #include "SymbolFileDWARF.h" 14 #include "llvm/ADT/SmallVector.h" 15 16 #include "DWARFAbbreviationDeclaration.h" 17 #include "DWARFDebugAbbrev.h" 18 #include "DWARFDebugRanges.h" 19 #include <map> 20 #include <set> 21 #include <vector> 22 23 typedef std::map<const DWARFDebugInfoEntry *, dw_addr_t> DIEToAddressMap; 24 typedef DIEToAddressMap::iterator DIEToAddressMapIter; 25 typedef DIEToAddressMap::const_iterator DIEToAddressMapConstIter; 26 27 typedef std::map<dw_addr_t, const DWARFDebugInfoEntry *> AddressToDIEMap; 28 typedef AddressToDIEMap::iterator AddressToDIEMapIter; 29 typedef AddressToDIEMap::const_iterator AddressToDIEMapConstIter; 30 31 typedef std::map<dw_offset_t, dw_offset_t> DIEToDIEMap; 32 typedef DIEToDIEMap::iterator DIEToDIEMapIter; 33 typedef DIEToDIEMap::const_iterator DIEToDIEMapConstIter; 34 35 typedef std::map<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMap; 36 typedef UInt32ToDIEMap::iterator UInt32ToDIEMapIter; 37 typedef UInt32ToDIEMap::const_iterator UInt32ToDIEMapConstIter; 38 39 typedef std::multimap<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMMap; 40 typedef UInt32ToDIEMMap::iterator UInt32ToDIEMMapIter; 41 typedef UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter; 42 43 class DWARFDeclContext; 44 45 #define DIE_SIBLING_IDX_BITSIZE 31 46 47 class DWARFDebugInfoEntry { 48 public: 49 typedef std::vector<DWARFDebugInfoEntry> collection; 50 typedef collection::iterator iterator; 51 typedef collection::const_iterator const_iterator; 52 53 typedef std::vector<dw_offset_t> offset_collection; 54 typedef offset_collection::iterator offset_collection_iterator; 55 typedef offset_collection::const_iterator offset_collection_const_iterator; 56 57 DWARFDebugInfoEntry() 58 : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0), 59 m_has_children(false), m_abbr_idx(0), m_tag(0) {} 60 61 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; } 62 bool operator==(const DWARFDebugInfoEntry &rhs) const; 63 bool operator!=(const DWARFDebugInfoEntry &rhs) const; 64 65 void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data, 66 const DWARFUnit *cu, 67 DWARFDebugAranges *debug_aranges) const; 68 69 void BuildFunctionAddressRangeTable(SymbolFileDWARF *dwarf2Data, 70 const DWARFUnit *cu, 71 DWARFDebugAranges *debug_aranges) const; 72 73 bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data, 74 const DWARFUnit *cu, 75 const DWARFFormValue::FixedFormSizes &fixed_form_sizes, 76 lldb::offset_t *offset_ptr); 77 78 bool Extract(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 79 lldb::offset_t *offset_ptr); 80 81 bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data, 82 const DWARFUnit *cu, 83 DWARFDebugInfoEntry **function_die, 84 DWARFDebugInfoEntry **block_die); 85 86 size_t GetAttributes(const DWARFUnit *cu, 87 DWARFFormValue::FixedFormSizes fixed_form_sizes, 88 DWARFAttributes &attrs, 89 uint32_t curr_depth = 0) 90 const; // "curr_depth" for internal use only, don't set this yourself!!! 91 92 dw_offset_t 93 GetAttributeValue(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 94 const dw_attr_t attr, DWARFFormValue &formValue, 95 dw_offset_t *end_attr_offset_ptr = nullptr, 96 bool check_specification_or_abstract_origin = false) const; 97 98 const char *GetAttributeValueAsString( 99 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 100 const dw_attr_t attr, const char *fail_value, 101 bool check_specification_or_abstract_origin = false) const; 102 103 uint64_t GetAttributeValueAsUnsigned( 104 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 105 const dw_attr_t attr, uint64_t fail_value, 106 bool check_specification_or_abstract_origin = false) const; 107 108 uint64_t GetAttributeValueAsReference( 109 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 110 const dw_attr_t attr, uint64_t fail_value, 111 bool check_specification_or_abstract_origin = false) const; 112 113 int64_t GetAttributeValueAsSigned( 114 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 115 const dw_attr_t attr, int64_t fail_value, 116 bool check_specification_or_abstract_origin = false) const; 117 118 uint64_t GetAttributeValueAsAddress( 119 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 120 const dw_attr_t attr, uint64_t fail_value, 121 bool check_specification_or_abstract_origin = false) const; 122 123 dw_addr_t 124 GetAttributeHighPC(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 125 dw_addr_t lo_pc, uint64_t fail_value, 126 bool check_specification_or_abstract_origin = false) const; 127 128 bool GetAttributeAddressRange( 129 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc, 130 dw_addr_t &hi_pc, uint64_t fail_value, 131 bool check_specification_or_abstract_origin = false) const; 132 133 size_t GetAttributeAddressRanges( 134 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 135 DWARFRangeList &ranges, bool check_hi_lo_pc, 136 bool check_specification_or_abstract_origin = false) const; 137 138 const char *GetName(SymbolFileDWARF *dwarf2Data, 139 const DWARFUnit *cu) const; 140 141 const char *GetMangledName(SymbolFileDWARF *dwarf2Data, 142 const DWARFUnit *cu, 143 bool substitute_name_allowed = true) const; 144 145 const char *GetPubname(SymbolFileDWARF *dwarf2Data, 146 const DWARFUnit *cu) const; 147 148 static bool GetName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 149 const dw_offset_t die_offset, lldb_private::Stream &s); 150 151 static bool AppendTypeName(SymbolFileDWARF *dwarf2Data, 152 const DWARFUnit *cu, 153 const dw_offset_t die_offset, 154 lldb_private::Stream &s); 155 156 const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data, 157 DWARFUnit *cu, 158 std::string &storage) const; 159 160 const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data, 161 DWARFUnit *cu, 162 const DWARFAttributes &attributes, 163 std::string &storage) const; 164 165 static bool OffsetLessThan(const DWARFDebugInfoEntry &a, 166 const DWARFDebugInfoEntry &b); 167 168 void Dump(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 169 lldb_private::Stream &s, uint32_t recurse_depth) const; 170 171 void DumpAncestry(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 172 const DWARFDebugInfoEntry *oldest, lldb_private::Stream &s, 173 uint32_t recurse_depth) const; 174 175 static void 176 DumpAttribute(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 177 const lldb_private::DWARFDataExtractor &debug_info_data, 178 lldb::offset_t *offset_ptr, lldb_private::Stream &s, 179 dw_attr_t attr, DWARFFormValue &form_value); 180 // This one dumps the comp unit name, objfile name and die offset for this die 181 // so the stream S. 182 void DumpLocation(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, 183 lldb_private::Stream &s) const; 184 185 bool 186 GetDIENamesAndRanges(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, 187 const char *&name, const char *&mangled, 188 DWARFRangeList &rangeList, int &decl_file, 189 int &decl_line, int &decl_column, int &call_file, 190 int &call_line, int &call_column, 191 lldb_private::DWARFExpression *frame_base = NULL) const; 192 193 const DWARFAbbreviationDeclaration * 194 GetAbbreviationDeclarationPtr(SymbolFileDWARF *dwarf2Data, 195 const DWARFUnit *cu, 196 lldb::offset_t &offset) const; 197 198 dw_tag_t Tag() const { return m_tag; } 199 200 bool IsNULL() const { return m_abbr_idx == 0; } 201 202 dw_offset_t GetOffset() const { return m_offset; } 203 204 bool HasChildren() const { return m_has_children; } 205 206 void SetHasChildren(bool b) { m_has_children = b; } 207 208 // We know we are kept in a vector of contiguous entries, so we know 209 // our parent will be some index behind "this". 210 DWARFDebugInfoEntry *GetParent() { 211 return m_parent_idx > 0 ? this - m_parent_idx : NULL; 212 } 213 const DWARFDebugInfoEntry *GetParent() const { 214 return m_parent_idx > 0 ? this - m_parent_idx : NULL; 215 } 216 // We know we are kept in a vector of contiguous entries, so we know 217 // our sibling will be some index after "this". 218 DWARFDebugInfoEntry *GetSibling() { 219 return m_sibling_idx > 0 ? this + m_sibling_idx : NULL; 220 } 221 const DWARFDebugInfoEntry *GetSibling() const { 222 return m_sibling_idx > 0 ? this + m_sibling_idx : NULL; 223 } 224 // We know we are kept in a vector of contiguous entries, so we know 225 // we don't need to store our child pointer, if we have a child it will 226 // be the next entry in the list... 227 DWARFDebugInfoEntry *GetFirstChild() { 228 return HasChildren() ? this + 1 : NULL; 229 } 230 const DWARFDebugInfoEntry *GetFirstChild() const { 231 return HasChildren() ? this + 1 : NULL; 232 } 233 234 void GetDeclContextDIEs(DWARFUnit *cu, 235 DWARFDIECollection &decl_context_dies) const; 236 237 void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, 238 DWARFDeclContext &dwarf_decl_ctx) const; 239 240 bool MatchesDWARFDeclContext(SymbolFileDWARF *dwarf2Data, 241 DWARFUnit *cu, 242 const DWARFDeclContext &dwarf_decl_ctx) const; 243 244 DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data, 245 DWARFUnit *cu) const; 246 DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data, 247 DWARFUnit *cu, 248 const DWARFAttributes &attributes) const; 249 250 void SetParent(DWARFDebugInfoEntry *parent) { 251 if (parent) { 252 // We know we are kept in a vector of contiguous entries, so we know 253 // our parent will be some index behind "this". 254 m_parent_idx = this - parent; 255 } else 256 m_parent_idx = 0; 257 } 258 void SetSibling(DWARFDebugInfoEntry *sibling) { 259 if (sibling) { 260 // We know we are kept in a vector of contiguous entries, so we know 261 // our sibling will be some index after "this". 262 m_sibling_idx = sibling - this; 263 sibling->SetParent(GetParent()); 264 } else 265 m_sibling_idx = 0; 266 } 267 268 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; } 269 270 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; } 271 272 static void 273 DumpDIECollection(lldb_private::Stream &strm, 274 DWARFDebugInfoEntry::collection &die_collection); 275 276 protected: 277 dw_offset_t 278 m_offset; // Offset within the .debug_info of the start of this entry 279 uint32_t m_parent_idx; // How many to subtract from "this" to get the parent. 280 // If zero this die has no parent 281 uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling. 282 // If it is zero, then the DIE doesn't have children, or the 283 // DWARF claimed it had children but the DIE only contained 284 // a single NULL terminating child. 285 m_has_children : 1; 286 uint16_t m_abbr_idx; 287 uint16_t m_tag; // A copy of the DW_TAG value so we don't have to go through 288 // the compile unit abbrev table 289 }; 290 291 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_ 292