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 "DWARFDebugAbbrev.h" 17 #include "DWARFAbbreviationDeclaration.h" 18 #include "DWARFDebugRanges.h" 19 #include <vector> 20 #include <map> 21 #include <set> 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 32 typedef std::map<dw_offset_t, dw_offset_t> DIEToDIEMap; 33 typedef DIEToDIEMap::iterator DIEToDIEMapIter; 34 typedef DIEToDIEMap::const_iterator DIEToDIEMapConstIter; 35 36 typedef std::map<uint32_t, const DWARFDebugInfoEntry*> UInt32ToDIEMap; 37 typedef UInt32ToDIEMap::iterator UInt32ToDIEMapIter; 38 typedef UInt32ToDIEMap::const_iterator UInt32ToDIEMapConstIter; 39 40 typedef std::multimap<uint32_t, const DWARFDebugInfoEntry*> UInt32ToDIEMMap; 41 typedef UInt32ToDIEMMap::iterator UInt32ToDIEMMapIter; 42 typedef UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter; 43 44 class DWARFDeclContext; 45 46 #define DIE_SIBLING_IDX_BITSIZE 31 47 #define DIE_ABBR_IDX_BITSIZE 15 48 49 class DWARFDebugInfoEntry 50 { 51 public: 52 typedef std::vector<DWARFDebugInfoEntry> collection; 53 typedef collection::iterator iterator; 54 typedef collection::const_iterator const_iterator; 55 56 typedef std::vector<dw_offset_t> offset_collection; 57 typedef offset_collection::iterator offset_collection_iterator; 58 typedef offset_collection::const_iterator offset_collection_const_iterator; 59 60 DWARFDebugInfoEntry(): 61 m_offset (DW_INVALID_OFFSET), 62 m_parent_idx (0), 63 m_sibling_idx (0), 64 m_empty_children(false), 65 m_abbr_idx (0), 66 m_has_children (false), 67 m_tag (0) 68 { 69 } 70 71 void Clear () 72 { 73 m_offset = DW_INVALID_OFFSET; 74 m_parent_idx = 0; 75 m_sibling_idx = 0; 76 m_empty_children = false; 77 m_abbr_idx = 0; 78 m_has_children = false; 79 m_tag = 0; 80 } 81 82 bool Contains (const DWARFDebugInfoEntry *die) const; 83 84 void BuildAddressRangeTable( 85 SymbolFileDWARF* dwarf2Data, 86 const DWARFCompileUnit* cu, 87 DWARFDebugAranges* debug_aranges) const; 88 89 void BuildFunctionAddressRangeTable( 90 SymbolFileDWARF* dwarf2Data, 91 const DWARFCompileUnit* cu, 92 DWARFDebugAranges* debug_aranges) const; 93 94 bool FastExtract( 95 const lldb_private::DWARFDataExtractor& debug_info_data, 96 const DWARFCompileUnit* cu, 97 const DWARFFormValue::FixedFormSizes& fixed_form_sizes, 98 lldb::offset_t* offset_ptr); 99 100 bool Extract( 101 SymbolFileDWARF* dwarf2Data, 102 const DWARFCompileUnit* cu, 103 lldb::offset_t* offset_ptr); 104 105 bool LookupAddress( 106 const dw_addr_t address, 107 SymbolFileDWARF* dwarf2Data, 108 const DWARFCompileUnit* cu, 109 DWARFDebugInfoEntry** function_die, 110 DWARFDebugInfoEntry** block_die); 111 112 size_t GetAttributes( 113 const DWARFCompileUnit* cu, 114 DWARFFormValue::FixedFormSizes fixed_form_sizes, 115 DWARFAttributes& attrs, 116 uint32_t curr_depth = 0) const; // "curr_depth" for internal use only, don't set this yourself!!! 117 118 dw_offset_t GetAttributeValue(SymbolFileDWARF* dwarf2Data, 119 const DWARFCompileUnit* cu, 120 const dw_attr_t attr, 121 DWARFFormValue& formValue, 122 dw_offset_t* end_attr_offset_ptr = nullptr, 123 bool check_specification_or_abstract_origin = false) const; 124 125 const char* GetAttributeValueAsString( 126 SymbolFileDWARF* dwarf2Data, 127 const DWARFCompileUnit* cu, 128 const dw_attr_t attr, 129 const char* fail_value, 130 bool check_specification_or_abstract_origin = false) const; 131 132 uint64_t GetAttributeValueAsUnsigned( 133 SymbolFileDWARF* dwarf2Data, 134 const DWARFCompileUnit* cu, 135 const dw_attr_t attr, 136 uint64_t fail_value, 137 bool check_specification_or_abstract_origin = false) const; 138 139 uint64_t GetAttributeValueAsReference( 140 SymbolFileDWARF* dwarf2Data, 141 const DWARFCompileUnit* cu, 142 const dw_attr_t attr, 143 uint64_t fail_value, 144 bool check_specification_or_abstract_origin = false) const; 145 146 int64_t GetAttributeValueAsSigned( 147 SymbolFileDWARF* dwarf2Data, 148 const DWARFCompileUnit* cu, 149 const dw_attr_t attr, 150 int64_t fail_value, 151 bool check_specification_or_abstract_origin = false) const; 152 153 uint64_t GetAttributeValueAsAddress( 154 SymbolFileDWARF* dwarf2Data, 155 const DWARFCompileUnit* cu, 156 const dw_attr_t attr, 157 uint64_t fail_value, 158 bool check_specification_or_abstract_origin = false) const; 159 160 dw_addr_t GetAttributeHighPC( 161 SymbolFileDWARF* dwarf2Data, 162 const DWARFCompileUnit* cu, 163 dw_addr_t lo_pc, 164 uint64_t fail_value, 165 bool check_specification_or_abstract_origin = false) const; 166 167 bool GetAttributeAddressRange( 168 SymbolFileDWARF* dwarf2Data, 169 const DWARFCompileUnit* cu, 170 dw_addr_t& lo_pc, 171 dw_addr_t& hi_pc, 172 uint64_t fail_value, 173 bool check_specification_or_abstract_origin = false) const; 174 175 size_t GetAttributeAddressRanges ( 176 SymbolFileDWARF* dwarf2Data, 177 const DWARFCompileUnit* cu, 178 DWARFRangeList &ranges, 179 bool check_hi_lo_pc, 180 bool check_specification_or_abstract_origin = false) const; 181 182 const char* GetName( 183 SymbolFileDWARF* dwarf2Data, 184 const DWARFCompileUnit* cu) const; 185 186 const char* GetMangledName( 187 SymbolFileDWARF* dwarf2Data, 188 const DWARFCompileUnit* cu, 189 bool substitute_name_allowed = true) const; 190 191 const char* GetPubname( 192 SymbolFileDWARF* dwarf2Data, 193 const DWARFCompileUnit* cu) const; 194 195 static bool GetName( 196 SymbolFileDWARF* dwarf2Data, 197 const DWARFCompileUnit* cu, 198 const dw_offset_t die_offset, 199 lldb_private::Stream &s); 200 201 static bool AppendTypeName( 202 SymbolFileDWARF* dwarf2Data, 203 const DWARFCompileUnit* cu, 204 const dw_offset_t die_offset, 205 lldb_private::Stream &s); 206 207 const char * GetQualifiedName ( 208 SymbolFileDWARF* dwarf2Data, 209 DWARFCompileUnit* cu, 210 std::string &storage) const; 211 212 const char * GetQualifiedName ( 213 SymbolFileDWARF* dwarf2Data, 214 DWARFCompileUnit* cu, 215 const DWARFAttributes& attributes, 216 std::string &storage) const; 217 218 static bool OffsetLessThan ( 219 const DWARFDebugInfoEntry& a, 220 const DWARFDebugInfoEntry& b); 221 222 void Dump( 223 SymbolFileDWARF* dwarf2Data, 224 const DWARFCompileUnit* cu, 225 lldb_private::Stream &s, 226 uint32_t recurse_depth) const; 227 228 void DumpAncestry( 229 SymbolFileDWARF* dwarf2Data, 230 const DWARFCompileUnit* cu, 231 const DWARFDebugInfoEntry* oldest, 232 lldb_private::Stream &s, 233 uint32_t recurse_depth) const; 234 235 static void DumpAttribute( 236 SymbolFileDWARF* dwarf2Data, 237 const DWARFCompileUnit* cu, 238 const lldb_private::DWARFDataExtractor& debug_info_data, 239 lldb::offset_t *offset_ptr, 240 lldb_private::Stream &s, 241 dw_attr_t attr, 242 dw_form_t form); 243 // This one dumps the comp unit name, objfile name and die offset for this die so the stream S. 244 void DumpLocation( 245 SymbolFileDWARF* dwarf2Data, 246 DWARFCompileUnit* cu, 247 lldb_private::Stream &s) const; 248 249 bool GetDIENamesAndRanges( 250 SymbolFileDWARF* dwarf2Data, 251 const DWARFCompileUnit* cu, 252 const char * &name, 253 const char * &mangled, 254 DWARFRangeList& rangeList, 255 int& decl_file, 256 int& decl_line, 257 int& decl_column, 258 int& call_file, 259 int& call_line, 260 int& call_column, 261 lldb_private::DWARFExpression *frame_base = NULL) const; 262 263 const DWARFAbbreviationDeclaration* 264 GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data, 265 const DWARFCompileUnit *cu, 266 lldb::offset_t &offset) const; 267 268 dw_tag_t 269 Tag () const 270 { 271 return m_tag; 272 } 273 274 bool 275 IsNULL() const 276 { 277 return m_abbr_idx == 0; 278 } 279 280 dw_offset_t 281 GetOffset () const 282 { 283 return m_offset; 284 } 285 286 void 287 SetOffset (dw_offset_t offset) 288 { 289 m_offset = offset; 290 } 291 292 bool 293 HasChildren () const 294 { 295 return m_has_children; 296 } 297 298 void 299 SetHasChildren (bool b) 300 { 301 m_has_children = b; 302 } 303 304 // We know we are kept in a vector of contiguous entries, so we know 305 // our parent will be some index behind "this". 306 DWARFDebugInfoEntry* GetParent() { return m_parent_idx > 0 ? this - m_parent_idx : NULL; } 307 const DWARFDebugInfoEntry* GetParent() const { return m_parent_idx > 0 ? this - m_parent_idx : NULL; } 308 // We know we are kept in a vector of contiguous entries, so we know 309 // our sibling will be some index after "this". 310 DWARFDebugInfoEntry* GetSibling() { return m_sibling_idx > 0 ? this + m_sibling_idx : NULL; } 311 const DWARFDebugInfoEntry* GetSibling() const { return m_sibling_idx > 0 ? this + m_sibling_idx : NULL; } 312 // We know we are kept in a vector of contiguous entries, so we know 313 // we don't need to store our child pointer, if we have a child it will 314 // be the next entry in the list... 315 DWARFDebugInfoEntry* GetFirstChild() { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; } 316 const DWARFDebugInfoEntry* GetFirstChild() const { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; } 317 318 319 void GetDeclContextDIEs (DWARFCompileUnit* cu, 320 DWARFDIECollection &decl_context_dies) const; 321 322 void GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data, 323 DWARFCompileUnit* cu, 324 DWARFDeclContext &dwarf_decl_ctx) const; 325 326 327 bool MatchesDWARFDeclContext(SymbolFileDWARF* dwarf2Data, 328 DWARFCompileUnit* cu, 329 const DWARFDeclContext &dwarf_decl_ctx) const; 330 331 DWARFDIE GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, 332 DWARFCompileUnit* cu) const; 333 DWARFDIE GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, 334 DWARFCompileUnit* cu, 335 const DWARFAttributes& attributes) const; 336 337 void 338 SetParent (DWARFDebugInfoEntry* parent) 339 { 340 if (parent) 341 { 342 // We know we are kept in a vector of contiguous entries, so we know 343 // our parent will be some index behind "this". 344 m_parent_idx = this - parent; 345 } 346 else 347 m_parent_idx = 0; 348 } 349 void 350 SetSibling (DWARFDebugInfoEntry* sibling) 351 { 352 if (sibling) 353 { 354 // We know we are kept in a vector of contiguous entries, so we know 355 // our sibling will be some index after "this". 356 m_sibling_idx = sibling - this; 357 sibling->SetParent(GetParent()); 358 } 359 else 360 m_sibling_idx = 0; 361 } 362 363 void 364 SetSiblingIndex (uint32_t idx) 365 { 366 m_sibling_idx = idx; 367 } 368 369 void 370 SetParentIndex (uint32_t idx) 371 { 372 m_parent_idx = idx; 373 } 374 375 bool 376 GetEmptyChildren () const 377 { 378 return m_empty_children; 379 } 380 381 void 382 SetEmptyChildren (bool b) 383 { 384 m_empty_children = b; 385 } 386 387 static void 388 DumpDIECollection (lldb_private::Stream &strm, 389 DWARFDebugInfoEntry::collection &die_collection); 390 391 protected: 392 393 dw_offset_t m_offset; // Offset within the .debug_info of the start of this entry 394 uint32_t m_parent_idx; // How many to subtract from "this" to get the parent. If zero this die has no parent 395 uint32_t m_sibling_idx:31, // How many to add to "this" to get the sibling. 396 m_empty_children:1; // If a DIE says it had children, yet it just contained a NULL tag, this will be set. 397 uint32_t m_abbr_idx:DIE_ABBR_IDX_BITSIZE, 398 m_has_children:1, // Set to 1 if this DIE has children 399 m_tag:16; // A copy of the DW_TAG value so we don't have to go through the compile unit abbrev table 400 }; 401 402 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_ 403