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