1 //===-- SymbolFileDWARF.cpp ------------------------------------*- 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 #include "SymbolFileDWARF.h" 11 12 // Other libraries and framework includes 13 #include "clang/AST/ASTConsumer.h" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/Decl.h" 16 #include "clang/AST/DeclGroup.h" 17 #include "clang/AST/DeclObjC.h" 18 #include "clang/AST/DeclTemplate.h" 19 #include "clang/Basic/Builtins.h" 20 #include "clang/Basic/IdentifierTable.h" 21 #include "clang/Basic/LangOptions.h" 22 #include "clang/Basic/SourceManager.h" 23 #include "clang/Basic/TargetInfo.h" 24 #include "clang/Basic/Specifiers.h" 25 #include "clang/Sema/DeclSpec.h" 26 27 #include "llvm/Support/Casting.h" 28 29 #include "lldb/Core/Module.h" 30 #include "lldb/Core/PluginManager.h" 31 #include "lldb/Core/RegularExpression.h" 32 #include "lldb/Core/Scalar.h" 33 #include "lldb/Core/Section.h" 34 #include "lldb/Core/StreamFile.h" 35 #include "lldb/Core/StreamString.h" 36 #include "lldb/Core/Timer.h" 37 #include "lldb/Core/Value.h" 38 39 #include "lldb/Host/Host.h" 40 41 #include "lldb/Symbol/Block.h" 42 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" 43 #include "lldb/Symbol/CompileUnit.h" 44 #include "lldb/Symbol/LineTable.h" 45 #include "lldb/Symbol/ObjectFile.h" 46 #include "lldb/Symbol/SymbolVendor.h" 47 #include "lldb/Symbol/VariableList.h" 48 49 #include "lldb/Target/ObjCLanguageRuntime.h" 50 #include "lldb/Target/CPPLanguageRuntime.h" 51 52 #include "DWARFCompileUnit.h" 53 #include "DWARFDebugAbbrev.h" 54 #include "DWARFDebugAranges.h" 55 #include "DWARFDebugInfo.h" 56 #include "DWARFDebugInfoEntry.h" 57 #include "DWARFDebugLine.h" 58 #include "DWARFDebugPubnames.h" 59 #include "DWARFDebugRanges.h" 60 #include "DWARFDeclContext.h" 61 #include "DWARFDIECollection.h" 62 #include "DWARFFormValue.h" 63 #include "DWARFLocationList.h" 64 #include "LogChannelDWARF.h" 65 #include "SymbolFileDWARFDebugMap.h" 66 67 #include <map> 68 69 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN 70 71 #ifdef ENABLE_DEBUG_PRINTF 72 #include <stdio.h> 73 #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) 74 #else 75 #define DEBUG_PRINTF(fmt, ...) 76 #endif 77 78 #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) 79 80 using namespace lldb; 81 using namespace lldb_private; 82 83 //static inline bool 84 //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) 85 //{ 86 // switch (tag) 87 // { 88 // default: 89 // break; 90 // case DW_TAG_subprogram: 91 // case DW_TAG_inlined_subroutine: 92 // case DW_TAG_class_type: 93 // case DW_TAG_structure_type: 94 // case DW_TAG_union_type: 95 // return true; 96 // } 97 // return false; 98 //} 99 // 100 static AccessType 101 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) 102 { 103 switch (dwarf_accessibility) 104 { 105 case DW_ACCESS_public: return eAccessPublic; 106 case DW_ACCESS_private: return eAccessPrivate; 107 case DW_ACCESS_protected: return eAccessProtected; 108 default: break; 109 } 110 return eAccessNone; 111 } 112 113 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE) 114 115 class DIEStack 116 { 117 public: 118 119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 120 { 121 m_dies.push_back (DIEInfo(cu, die)); 122 } 123 124 125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf) 126 { 127 StreamString log_strm; 128 const size_t n = m_dies.size(); 129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); 130 for (size_t i=0; i<n; i++) 131 { 132 DWARFCompileUnit *cu = m_dies[i].cu; 133 const DWARFDebugInfoEntry *die = m_dies[i].die; 134 std::string qualified_name; 135 die->GetQualifiedName(dwarf, cu, qualified_name); 136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", 137 (uint64_t)i, 138 die->GetOffset(), 139 DW_TAG_value_to_name(die->Tag()), 140 qualified_name.c_str()); 141 } 142 log->PutCString(log_strm.GetData()); 143 } 144 void Pop () 145 { 146 m_dies.pop_back(); 147 } 148 149 class ScopedPopper 150 { 151 public: 152 ScopedPopper (DIEStack &die_stack) : 153 m_die_stack (die_stack), 154 m_valid (false) 155 { 156 } 157 158 void 159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 160 { 161 m_valid = true; 162 m_die_stack.Push (cu, die); 163 } 164 165 ~ScopedPopper () 166 { 167 if (m_valid) 168 m_die_stack.Pop(); 169 } 170 171 172 173 protected: 174 DIEStack &m_die_stack; 175 bool m_valid; 176 }; 177 178 protected: 179 struct DIEInfo { 180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : 181 cu(c), 182 die(d) 183 { 184 } 185 DWARFCompileUnit *cu; 186 const DWARFDebugInfoEntry *die; 187 }; 188 typedef std::vector<DIEInfo> Stack; 189 Stack m_dies; 190 }; 191 #endif 192 193 void 194 SymbolFileDWARF::Initialize() 195 { 196 LogChannelDWARF::Initialize(); 197 PluginManager::RegisterPlugin (GetPluginNameStatic(), 198 GetPluginDescriptionStatic(), 199 CreateInstance); 200 } 201 202 void 203 SymbolFileDWARF::Terminate() 204 { 205 PluginManager::UnregisterPlugin (CreateInstance); 206 LogChannelDWARF::Initialize(); 207 } 208 209 210 lldb_private::ConstString 211 SymbolFileDWARF::GetPluginNameStatic() 212 { 213 static ConstString g_name("dwarf"); 214 return g_name; 215 } 216 217 const char * 218 SymbolFileDWARF::GetPluginDescriptionStatic() 219 { 220 return "DWARF and DWARF3 debug symbol file reader."; 221 } 222 223 224 SymbolFile* 225 SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) 226 { 227 return new SymbolFileDWARF(obj_file); 228 } 229 230 TypeList * 231 SymbolFileDWARF::GetTypeList () 232 { 233 if (GetDebugMapSymfile ()) 234 return m_debug_map_symfile->GetTypeList(); 235 return m_obj_file->GetModule()->GetTypeList(); 236 237 } 238 void 239 SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, 240 const DWARFDebugInfoEntry *die, 241 dw_offset_t min_die_offset, 242 dw_offset_t max_die_offset, 243 uint32_t type_mask, 244 TypeSet &type_set) 245 { 246 if (cu) 247 { 248 if (die) 249 { 250 const dw_offset_t die_offset = die->GetOffset(); 251 252 if (die_offset >= max_die_offset) 253 return; 254 255 if (die_offset >= min_die_offset) 256 { 257 const dw_tag_t tag = die->Tag(); 258 259 bool add_type = false; 260 261 switch (tag) 262 { 263 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; 264 case DW_TAG_unspecified_type: 265 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; 266 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; 267 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; 268 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; 269 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; 270 case DW_TAG_subroutine_type: 271 case DW_TAG_subprogram: 272 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; 273 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; 274 case DW_TAG_rvalue_reference_type: 275 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; 276 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; 277 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; 278 } 279 280 if (add_type) 281 { 282 const bool assert_not_being_parsed = true; 283 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); 284 if (type) 285 { 286 if (type_set.find(type) == type_set.end()) 287 type_set.insert(type); 288 } 289 } 290 } 291 292 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); 293 child_die != NULL; 294 child_die = child_die->GetSibling()) 295 { 296 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); 297 } 298 } 299 } 300 } 301 302 size_t 303 SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, 304 uint32_t type_mask, 305 TypeList &type_list) 306 307 { 308 TypeSet type_set; 309 310 CompileUnit *comp_unit = NULL; 311 DWARFCompileUnit* dwarf_cu = NULL; 312 if (sc_scope) 313 comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); 314 315 if (comp_unit) 316 { 317 dwarf_cu = GetDWARFCompileUnit(comp_unit); 318 if (dwarf_cu == 0) 319 return 0; 320 GetTypes (dwarf_cu, 321 dwarf_cu->DIE(), 322 dwarf_cu->GetOffset(), 323 dwarf_cu->GetNextCompileUnitOffset(), 324 type_mask, 325 type_set); 326 } 327 else 328 { 329 DWARFDebugInfo* info = DebugInfo(); 330 if (info) 331 { 332 const size_t num_cus = info->GetNumCompileUnits(); 333 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) 334 { 335 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); 336 if (dwarf_cu) 337 { 338 GetTypes (dwarf_cu, 339 dwarf_cu->DIE(), 340 0, 341 UINT32_MAX, 342 type_mask, 343 type_set); 344 } 345 } 346 } 347 } 348 // if (m_using_apple_tables) 349 // { 350 // DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); 351 // if (apple_types) 352 // { 353 // apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { 354 // 355 // for (auto die_info: die_info_array) 356 // { 357 // bool add_type = TagMatchesTypeMask (type_mask, 0); 358 // if (!add_type) 359 // { 360 // dw_tag_t tag = die_info.tag; 361 // if (tag == 0) 362 // { 363 // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); 364 // tag = die->Tag(); 365 // } 366 // add_type = TagMatchesTypeMask (type_mask, tag); 367 // } 368 // if (add_type) 369 // { 370 // Type *type = ResolveTypeUID(die_info.offset); 371 // 372 // if (type_set.find(type) == type_set.end()) 373 // type_set.insert(type); 374 // } 375 // } 376 // return true; // Keep iterating 377 // }); 378 // } 379 // } 380 // else 381 // { 382 // if (!m_indexed) 383 // Index (); 384 // 385 // m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { 386 // 387 // bool add_type = TagMatchesTypeMask (type_mask, 0); 388 // 389 // if (!add_type) 390 // { 391 // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); 392 // if (die) 393 // { 394 // const dw_tag_t tag = die->Tag(); 395 // add_type = TagMatchesTypeMask (type_mask, tag); 396 // } 397 // } 398 // 399 // if (add_type) 400 // { 401 // Type *type = ResolveTypeUID(die_offset); 402 // 403 // if (type_set.find(type) == type_set.end()) 404 // type_set.insert(type); 405 // } 406 // return true; // Keep iterating 407 // }); 408 // } 409 410 std::set<ClangASTType> clang_type_set; 411 size_t num_types_added = 0; 412 for (Type *type : type_set) 413 { 414 ClangASTType clang_type = type->GetClangForwardType(); 415 if (clang_type_set.find(clang_type) == clang_type_set.end()) 416 { 417 clang_type_set.insert(clang_type); 418 type_list.Insert (type->shared_from_this()); 419 ++num_types_added; 420 } 421 } 422 return num_types_added; 423 } 424 425 426 //---------------------------------------------------------------------- 427 // Gets the first parent that is a lexical block, function or inlined 428 // subroutine, or compile unit. 429 //---------------------------------------------------------------------- 430 static const DWARFDebugInfoEntry * 431 GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) 432 { 433 const DWARFDebugInfoEntry *die; 434 for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) 435 { 436 dw_tag_t tag = die->Tag(); 437 438 switch (tag) 439 { 440 case DW_TAG_compile_unit: 441 case DW_TAG_subprogram: 442 case DW_TAG_inlined_subroutine: 443 case DW_TAG_lexical_block: 444 return die; 445 } 446 } 447 return NULL; 448 } 449 450 451 SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : 452 SymbolFile (objfile), 453 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID 454 m_debug_map_module_wp (), 455 m_debug_map_symfile (NULL), 456 m_clang_tu_decl (NULL), 457 m_flags(), 458 m_data_debug_abbrev (), 459 m_data_debug_aranges (), 460 m_data_debug_frame (), 461 m_data_debug_info (), 462 m_data_debug_line (), 463 m_data_debug_loc (), 464 m_data_debug_ranges (), 465 m_data_debug_str (), 466 m_data_apple_names (), 467 m_data_apple_types (), 468 m_data_apple_namespaces (), 469 m_abbr(), 470 m_info(), 471 m_line(), 472 m_apple_names_ap (), 473 m_apple_types_ap (), 474 m_apple_namespaces_ap (), 475 m_apple_objc_ap (), 476 m_function_basename_index(), 477 m_function_fullname_index(), 478 m_function_method_index(), 479 m_function_selector_index(), 480 m_objc_class_selectors_index(), 481 m_global_index(), 482 m_type_index(), 483 m_namespace_index(), 484 m_indexed (false), 485 m_is_external_ast_source (false), 486 m_using_apple_tables (false), 487 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), 488 m_ranges(), 489 m_unique_ast_type_map () 490 { 491 } 492 493 SymbolFileDWARF::~SymbolFileDWARF() 494 { 495 if (m_is_external_ast_source) 496 { 497 ModuleSP module_sp (m_obj_file->GetModule()); 498 if (module_sp) 499 module_sp->GetClangASTContext().RemoveExternalSource (); 500 } 501 } 502 503 static const ConstString & 504 GetDWARFMachOSegmentName () 505 { 506 static ConstString g_dwarf_section_name ("__DWARF"); 507 return g_dwarf_section_name; 508 } 509 510 UniqueDWARFASTTypeMap & 511 SymbolFileDWARF::GetUniqueDWARFASTTypeMap () 512 { 513 if (GetDebugMapSymfile ()) 514 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); 515 return m_unique_ast_type_map; 516 } 517 518 ClangASTContext & 519 SymbolFileDWARF::GetClangASTContext () 520 { 521 if (GetDebugMapSymfile ()) 522 return m_debug_map_symfile->GetClangASTContext (); 523 524 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); 525 if (!m_is_external_ast_source) 526 { 527 m_is_external_ast_source = true; 528 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap ( 529 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, 530 SymbolFileDWARF::CompleteObjCInterfaceDecl, 531 SymbolFileDWARF::FindExternalVisibleDeclsByName, 532 SymbolFileDWARF::LayoutRecordType, 533 this)); 534 ast.SetExternalSource (ast_source_ap); 535 } 536 return ast; 537 } 538 539 void 540 SymbolFileDWARF::InitializeObject() 541 { 542 // Install our external AST source callbacks so we can complete Clang types. 543 ModuleSP module_sp (m_obj_file->GetModule()); 544 if (module_sp) 545 { 546 const SectionList *section_list = module_sp->GetSectionList(); 547 548 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); 549 550 // Memory map the DWARF mach-o segment so we have everything mmap'ed 551 // to keep our heap memory usage down. 552 if (section) 553 m_obj_file->MemoryMapSectionData(section, m_dwarf_data); 554 } 555 get_apple_names_data(); 556 if (m_data_apple_names.GetByteSize() > 0) 557 { 558 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); 559 if (m_apple_names_ap->IsValid()) 560 m_using_apple_tables = true; 561 else 562 m_apple_names_ap.reset(); 563 } 564 get_apple_types_data(); 565 if (m_data_apple_types.GetByteSize() > 0) 566 { 567 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); 568 if (m_apple_types_ap->IsValid()) 569 m_using_apple_tables = true; 570 else 571 m_apple_types_ap.reset(); 572 } 573 574 get_apple_namespaces_data(); 575 if (m_data_apple_namespaces.GetByteSize() > 0) 576 { 577 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); 578 if (m_apple_namespaces_ap->IsValid()) 579 m_using_apple_tables = true; 580 else 581 m_apple_namespaces_ap.reset(); 582 } 583 584 get_apple_objc_data(); 585 if (m_data_apple_objc.GetByteSize() > 0) 586 { 587 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); 588 if (m_apple_objc_ap->IsValid()) 589 m_using_apple_tables = true; 590 else 591 m_apple_objc_ap.reset(); 592 } 593 } 594 595 bool 596 SymbolFileDWARF::SupportedVersion(uint16_t version) 597 { 598 return version == 2 || version == 3 || version == 4; 599 } 600 601 uint32_t 602 SymbolFileDWARF::CalculateAbilities () 603 { 604 uint32_t abilities = 0; 605 if (m_obj_file != NULL) 606 { 607 const Section* section = NULL; 608 const SectionList *section_list = m_obj_file->GetSectionList(); 609 if (section_list == NULL) 610 return 0; 611 612 uint64_t debug_abbrev_file_size = 0; 613 uint64_t debug_info_file_size = 0; 614 uint64_t debug_line_file_size = 0; 615 616 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); 617 618 if (section) 619 section_list = §ion->GetChildren (); 620 621 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); 622 if (section != NULL) 623 { 624 debug_info_file_size = section->GetFileSize(); 625 626 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); 627 if (section) 628 debug_abbrev_file_size = section->GetFileSize(); 629 else 630 m_flags.Set (flagsGotDebugAbbrevData); 631 632 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); 633 if (!section) 634 m_flags.Set (flagsGotDebugArangesData); 635 636 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); 637 if (!section) 638 m_flags.Set (flagsGotDebugFrameData); 639 640 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); 641 if (section) 642 debug_line_file_size = section->GetFileSize(); 643 else 644 m_flags.Set (flagsGotDebugLineData); 645 646 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); 647 if (!section) 648 m_flags.Set (flagsGotDebugLocData); 649 650 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); 651 if (!section) 652 m_flags.Set (flagsGotDebugMacInfoData); 653 654 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); 655 if (!section) 656 m_flags.Set (flagsGotDebugPubNamesData); 657 658 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); 659 if (!section) 660 m_flags.Set (flagsGotDebugPubTypesData); 661 662 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); 663 if (!section) 664 m_flags.Set (flagsGotDebugRangesData); 665 666 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); 667 if (!section) 668 m_flags.Set (flagsGotDebugStrData); 669 } 670 else 671 { 672 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); 673 if (symfile_dir_cstr) 674 { 675 if (strcasestr(symfile_dir_cstr, ".dsym")) 676 { 677 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) 678 { 679 // We have a dSYM file that didn't have a any debug info. 680 // If the string table has a size of 1, then it was made from 681 // an executable with no debug info, or from an executable that 682 // was stripped. 683 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); 684 if (section && section->GetFileSize() == 1) 685 { 686 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); 687 } 688 } 689 } 690 } 691 } 692 693 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) 694 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; 695 696 if (debug_line_file_size > 0) 697 abilities |= LineTables; 698 } 699 return abilities; 700 } 701 702 const DataExtractor& 703 SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) 704 { 705 if (m_flags.IsClear (got_flag)) 706 { 707 ModuleSP module_sp (m_obj_file->GetModule()); 708 m_flags.Set (got_flag); 709 const SectionList *section_list = module_sp->GetSectionList(); 710 if (section_list) 711 { 712 SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); 713 if (section_sp) 714 { 715 // See if we memory mapped the DWARF segment? 716 if (m_dwarf_data.GetByteSize()) 717 { 718 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); 719 } 720 else 721 { 722 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) 723 data.Clear(); 724 } 725 } 726 } 727 } 728 return data; 729 } 730 731 const DataExtractor& 732 SymbolFileDWARF::get_debug_abbrev_data() 733 { 734 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); 735 } 736 737 const DataExtractor& 738 SymbolFileDWARF::get_debug_aranges_data() 739 { 740 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); 741 } 742 743 const DataExtractor& 744 SymbolFileDWARF::get_debug_frame_data() 745 { 746 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); 747 } 748 749 const DataExtractor& 750 SymbolFileDWARF::get_debug_info_data() 751 { 752 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); 753 } 754 755 const DataExtractor& 756 SymbolFileDWARF::get_debug_line_data() 757 { 758 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); 759 } 760 761 const DataExtractor& 762 SymbolFileDWARF::get_debug_loc_data() 763 { 764 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); 765 } 766 767 const DataExtractor& 768 SymbolFileDWARF::get_debug_ranges_data() 769 { 770 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); 771 } 772 773 const DataExtractor& 774 SymbolFileDWARF::get_debug_str_data() 775 { 776 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); 777 } 778 779 const DataExtractor& 780 SymbolFileDWARF::get_apple_names_data() 781 { 782 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); 783 } 784 785 const DataExtractor& 786 SymbolFileDWARF::get_apple_types_data() 787 { 788 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); 789 } 790 791 const DataExtractor& 792 SymbolFileDWARF::get_apple_namespaces_data() 793 { 794 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); 795 } 796 797 const DataExtractor& 798 SymbolFileDWARF::get_apple_objc_data() 799 { 800 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); 801 } 802 803 804 DWARFDebugAbbrev* 805 SymbolFileDWARF::DebugAbbrev() 806 { 807 if (m_abbr.get() == NULL) 808 { 809 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); 810 if (debug_abbrev_data.GetByteSize() > 0) 811 { 812 m_abbr.reset(new DWARFDebugAbbrev()); 813 if (m_abbr.get()) 814 m_abbr->Parse(debug_abbrev_data); 815 } 816 } 817 return m_abbr.get(); 818 } 819 820 const DWARFDebugAbbrev* 821 SymbolFileDWARF::DebugAbbrev() const 822 { 823 return m_abbr.get(); 824 } 825 826 827 DWARFDebugInfo* 828 SymbolFileDWARF::DebugInfo() 829 { 830 if (m_info.get() == NULL) 831 { 832 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); 833 if (get_debug_info_data().GetByteSize() > 0) 834 { 835 m_info.reset(new DWARFDebugInfo()); 836 if (m_info.get()) 837 { 838 m_info->SetDwarfData(this); 839 } 840 } 841 } 842 return m_info.get(); 843 } 844 845 const DWARFDebugInfo* 846 SymbolFileDWARF::DebugInfo() const 847 { 848 return m_info.get(); 849 } 850 851 DWARFCompileUnit* 852 SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) 853 { 854 DWARFDebugInfo* info = DebugInfo(); 855 if (info) 856 { 857 if (GetDebugMapSymfile ()) 858 { 859 // The debug map symbol file made the compile units for this DWARF 860 // file which is .o file with DWARF in it, and we should have 861 // only 1 compile unit which is at offset zero in the DWARF. 862 // TODO: modify to support LTO .o files where each .o file might 863 // have multiple DW_TAG_compile_unit tags. 864 return info->GetCompileUnit(0).get(); 865 } 866 else 867 { 868 // Just a normal DWARF file whose user ID for the compile unit is 869 // the DWARF offset itself 870 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); 871 } 872 } 873 return NULL; 874 } 875 876 877 DWARFDebugRanges* 878 SymbolFileDWARF::DebugRanges() 879 { 880 if (m_ranges.get() == NULL) 881 { 882 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); 883 if (get_debug_ranges_data().GetByteSize() > 0) 884 { 885 m_ranges.reset(new DWARFDebugRanges()); 886 if (m_ranges.get()) 887 m_ranges->Extract(this); 888 } 889 } 890 return m_ranges.get(); 891 } 892 893 const DWARFDebugRanges* 894 SymbolFileDWARF::DebugRanges() const 895 { 896 return m_ranges.get(); 897 } 898 899 lldb::CompUnitSP 900 SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) 901 { 902 CompUnitSP cu_sp; 903 if (dwarf_cu) 904 { 905 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); 906 if (comp_unit) 907 { 908 // We already parsed this compile unit, had out a shared pointer to it 909 cu_sp = comp_unit->shared_from_this(); 910 } 911 else 912 { 913 if (GetDebugMapSymfile ()) 914 { 915 // Let the debug map create the compile unit 916 cu_sp = m_debug_map_symfile->GetCompileUnit(this); 917 dwarf_cu->SetUserData(cu_sp.get()); 918 } 919 else 920 { 921 ModuleSP module_sp (m_obj_file->GetModule()); 922 if (module_sp) 923 { 924 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); 925 if (cu_die) 926 { 927 const char * cu_die_name = cu_die->GetName(this, dwarf_cu); 928 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); 929 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); 930 if (cu_die_name) 931 { 932 std::string ramapped_file; 933 FileSpec cu_file_spec; 934 935 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') 936 { 937 // If we have a full path to the compile unit, we don't need to resolve 938 // the file. This can be expensive e.g. when the source files are NFS mounted. 939 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) 940 cu_file_spec.SetFile (ramapped_file.c_str(), false); 941 else 942 cu_file_spec.SetFile (cu_die_name, false); 943 } 944 else 945 { 946 std::string fullpath(cu_comp_dir); 947 if (*fullpath.rbegin() != '/') 948 fullpath += '/'; 949 fullpath += cu_die_name; 950 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) 951 cu_file_spec.SetFile (ramapped_file.c_str(), false); 952 else 953 cu_file_spec.SetFile (fullpath.c_str(), false); 954 } 955 956 cu_sp.reset(new CompileUnit (module_sp, 957 dwarf_cu, 958 cu_file_spec, 959 MakeUserID(dwarf_cu->GetOffset()), 960 cu_language)); 961 if (cu_sp) 962 { 963 dwarf_cu->SetUserData(cu_sp.get()); 964 965 // Figure out the compile unit index if we weren't given one 966 if (cu_idx == UINT32_MAX) 967 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); 968 969 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); 970 } 971 } 972 } 973 } 974 } 975 } 976 } 977 return cu_sp; 978 } 979 980 uint32_t 981 SymbolFileDWARF::GetNumCompileUnits() 982 { 983 DWARFDebugInfo* info = DebugInfo(); 984 if (info) 985 return info->GetNumCompileUnits(); 986 return 0; 987 } 988 989 CompUnitSP 990 SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) 991 { 992 CompUnitSP cu_sp; 993 DWARFDebugInfo* info = DebugInfo(); 994 if (info) 995 { 996 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); 997 if (dwarf_cu) 998 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); 999 } 1000 return cu_sp; 1001 } 1002 1003 static void 1004 AddRangesToBlock (Block& block, 1005 DWARFDebugRanges::RangeList& ranges, 1006 addr_t block_base_addr) 1007 { 1008 const size_t num_ranges = ranges.GetSize(); 1009 for (size_t i = 0; i<num_ranges; ++i) 1010 { 1011 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); 1012 const addr_t range_base = range.GetRangeBase(); 1013 assert (range_base >= block_base_addr); 1014 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));; 1015 } 1016 block.FinalizeRanges (); 1017 } 1018 1019 1020 Function * 1021 SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) 1022 { 1023 DWARFDebugRanges::RangeList func_ranges; 1024 const char *name = NULL; 1025 const char *mangled = NULL; 1026 int decl_file = 0; 1027 int decl_line = 0; 1028 int decl_column = 0; 1029 int call_file = 0; 1030 int call_line = 0; 1031 int call_column = 0; 1032 DWARFExpression frame_base; 1033 1034 assert (die->Tag() == DW_TAG_subprogram); 1035 1036 if (die->Tag() != DW_TAG_subprogram) 1037 return NULL; 1038 1039 if (die->GetDIENamesAndRanges (this, 1040 dwarf_cu, 1041 name, 1042 mangled, 1043 func_ranges, 1044 decl_file, 1045 decl_line, 1046 decl_column, 1047 call_file, 1048 call_line, 1049 call_column, 1050 &frame_base)) 1051 { 1052 // Union of all ranges in the function DIE (if the function is discontiguous) 1053 AddressRange func_range; 1054 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); 1055 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); 1056 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) 1057 { 1058 ModuleSP module_sp (m_obj_file->GetModule()); 1059 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); 1060 if (func_range.GetBaseAddress().IsValid()) 1061 func_range.SetByteSize(highest_func_addr - lowest_func_addr); 1062 } 1063 1064 if (func_range.GetBaseAddress().IsValid()) 1065 { 1066 Mangled func_name; 1067 if (mangled) 1068 func_name.SetValue(ConstString(mangled), true); 1069 else if (name) 1070 func_name.SetValue(ConstString(name), false); 1071 1072 FunctionSP func_sp; 1073 std::unique_ptr<Declaration> decl_ap; 1074 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 1075 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), 1076 decl_line, 1077 decl_column)); 1078 1079 // Supply the type _only_ if it has already been parsed 1080 Type *func_type = m_die_to_type.lookup (die); 1081 1082 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); 1083 1084 if (FixupAddress (func_range.GetBaseAddress())) 1085 { 1086 const user_id_t func_user_id = MakeUserID(die->GetOffset()); 1087 func_sp.reset(new Function (sc.comp_unit, 1088 MakeUserID(func_user_id), // UserID is the DIE offset 1089 MakeUserID(func_user_id), 1090 func_name, 1091 func_type, 1092 func_range)); // first address range 1093 1094 if (func_sp.get() != NULL) 1095 { 1096 if (frame_base.IsValid()) 1097 func_sp->GetFrameBaseExpression() = frame_base; 1098 sc.comp_unit->AddFunction(func_sp); 1099 return func_sp.get(); 1100 } 1101 } 1102 } 1103 } 1104 return NULL; 1105 } 1106 1107 bool 1108 SymbolFileDWARF::FixupAddress (Address &addr) 1109 { 1110 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); 1111 if (debug_map_symfile) 1112 { 1113 return debug_map_symfile->LinkOSOAddress(addr); 1114 } 1115 // This is a normal DWARF file, no address fixups need to happen 1116 return true; 1117 } 1118 lldb::LanguageType 1119 SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) 1120 { 1121 assert (sc.comp_unit); 1122 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1123 if (dwarf_cu) 1124 { 1125 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); 1126 if (die) 1127 { 1128 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); 1129 if (language) 1130 return (lldb::LanguageType)language; 1131 } 1132 } 1133 return eLanguageTypeUnknown; 1134 } 1135 1136 size_t 1137 SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) 1138 { 1139 assert (sc.comp_unit); 1140 size_t functions_added = 0; 1141 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1142 if (dwarf_cu) 1143 { 1144 DWARFDIECollection function_dies; 1145 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); 1146 size_t func_idx; 1147 for (func_idx = 0; func_idx < num_functions; ++func_idx) 1148 { 1149 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); 1150 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) 1151 { 1152 if (ParseCompileUnitFunction(sc, dwarf_cu, die)) 1153 ++functions_added; 1154 } 1155 } 1156 //FixupTypes(); 1157 } 1158 return functions_added; 1159 } 1160 1161 bool 1162 SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) 1163 { 1164 assert (sc.comp_unit); 1165 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1166 if (dwarf_cu) 1167 { 1168 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); 1169 1170 if (cu_die) 1171 { 1172 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); 1173 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); 1174 1175 // All file indexes in DWARF are one based and a file of index zero is 1176 // supposed to be the compile unit itself. 1177 support_files.Append (*sc.comp_unit); 1178 1179 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); 1180 } 1181 } 1182 return false; 1183 } 1184 1185 struct ParseDWARFLineTableCallbackInfo 1186 { 1187 LineTable* line_table; 1188 std::unique_ptr<LineSequence> sequence_ap; 1189 }; 1190 1191 //---------------------------------------------------------------------- 1192 // ParseStatementTableCallback 1193 //---------------------------------------------------------------------- 1194 static void 1195 ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) 1196 { 1197 if (state.row == DWARFDebugLine::State::StartParsingLineTable) 1198 { 1199 // Just started parsing the line table 1200 } 1201 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) 1202 { 1203 // Done parsing line table, nothing to do for the cleanup 1204 } 1205 else 1206 { 1207 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; 1208 LineTable* line_table = info->line_table; 1209 1210 // If this is our first time here, we need to create a 1211 // sequence container. 1212 if (!info->sequence_ap.get()) 1213 { 1214 info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); 1215 assert(info->sequence_ap.get()); 1216 } 1217 line_table->AppendLineEntryToSequence (info->sequence_ap.get(), 1218 state.address, 1219 state.line, 1220 state.column, 1221 state.file, 1222 state.is_stmt, 1223 state.basic_block, 1224 state.prologue_end, 1225 state.epilogue_begin, 1226 state.end_sequence); 1227 if (state.end_sequence) 1228 { 1229 // First, put the current sequence into the line table. 1230 line_table->InsertSequence(info->sequence_ap.get()); 1231 // Then, empty it to prepare for the next sequence. 1232 info->sequence_ap->Clear(); 1233 } 1234 } 1235 } 1236 1237 bool 1238 SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) 1239 { 1240 assert (sc.comp_unit); 1241 if (sc.comp_unit->GetLineTable() != NULL) 1242 return true; 1243 1244 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1245 if (dwarf_cu) 1246 { 1247 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); 1248 if (dwarf_cu_die) 1249 { 1250 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); 1251 if (cu_line_offset != DW_INVALID_OFFSET) 1252 { 1253 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); 1254 if (line_table_ap.get()) 1255 { 1256 ParseDWARFLineTableCallbackInfo info; 1257 info.line_table = line_table_ap.get(); 1258 lldb::offset_t offset = cu_line_offset; 1259 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); 1260 if (m_debug_map_symfile) 1261 { 1262 // We have an object file that has a line table with addresses 1263 // that are not linked. We need to link the line table and convert 1264 // the addresses that are relative to the .o file into addresses 1265 // for the main executable. 1266 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); 1267 } 1268 else 1269 { 1270 sc.comp_unit->SetLineTable(line_table_ap.release()); 1271 return true; 1272 } 1273 } 1274 } 1275 } 1276 } 1277 return false; 1278 } 1279 1280 size_t 1281 SymbolFileDWARF::ParseFunctionBlocks 1282 ( 1283 const SymbolContext& sc, 1284 Block *parent_block, 1285 DWARFCompileUnit* dwarf_cu, 1286 const DWARFDebugInfoEntry *die, 1287 addr_t subprogram_low_pc, 1288 uint32_t depth 1289 ) 1290 { 1291 size_t blocks_added = 0; 1292 while (die != NULL) 1293 { 1294 dw_tag_t tag = die->Tag(); 1295 1296 switch (tag) 1297 { 1298 case DW_TAG_inlined_subroutine: 1299 case DW_TAG_subprogram: 1300 case DW_TAG_lexical_block: 1301 { 1302 Block *block = NULL; 1303 if (tag == DW_TAG_subprogram) 1304 { 1305 // Skip any DW_TAG_subprogram DIEs that are inside 1306 // of a normal or inlined functions. These will be 1307 // parsed on their own as separate entities. 1308 1309 if (depth > 0) 1310 break; 1311 1312 block = parent_block; 1313 } 1314 else 1315 { 1316 BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); 1317 parent_block->AddChild(block_sp); 1318 block = block_sp.get(); 1319 } 1320 DWARFDebugRanges::RangeList ranges; 1321 const char *name = NULL; 1322 const char *mangled_name = NULL; 1323 1324 int decl_file = 0; 1325 int decl_line = 0; 1326 int decl_column = 0; 1327 int call_file = 0; 1328 int call_line = 0; 1329 int call_column = 0; 1330 if (die->GetDIENamesAndRanges (this, 1331 dwarf_cu, 1332 name, 1333 mangled_name, 1334 ranges, 1335 decl_file, decl_line, decl_column, 1336 call_file, call_line, call_column)) 1337 { 1338 if (tag == DW_TAG_subprogram) 1339 { 1340 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); 1341 subprogram_low_pc = ranges.GetMinRangeBase(0); 1342 } 1343 else if (tag == DW_TAG_inlined_subroutine) 1344 { 1345 // We get called here for inlined subroutines in two ways. 1346 // The first time is when we are making the Function object 1347 // for this inlined concrete instance. Since we're creating a top level block at 1348 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to 1349 // adjust the containing address. 1350 // The second time is when we are parsing the blocks inside the function that contains 1351 // the inlined concrete instance. Since these will be blocks inside the containing "real" 1352 // function the offset will be for that function. 1353 if (subprogram_low_pc == LLDB_INVALID_ADDRESS) 1354 { 1355 subprogram_low_pc = ranges.GetMinRangeBase(0); 1356 } 1357 } 1358 1359 AddRangesToBlock (*block, ranges, subprogram_low_pc); 1360 1361 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) 1362 { 1363 std::unique_ptr<Declaration> decl_ap; 1364 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 1365 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), 1366 decl_line, decl_column)); 1367 1368 std::unique_ptr<Declaration> call_ap; 1369 if (call_file != 0 || call_line != 0 || call_column != 0) 1370 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), 1371 call_line, call_column)); 1372 1373 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); 1374 } 1375 1376 ++blocks_added; 1377 1378 if (die->HasChildren()) 1379 { 1380 blocks_added += ParseFunctionBlocks (sc, 1381 block, 1382 dwarf_cu, 1383 die->GetFirstChild(), 1384 subprogram_low_pc, 1385 depth + 1); 1386 } 1387 } 1388 } 1389 break; 1390 default: 1391 break; 1392 } 1393 1394 // Only parse siblings of the block if we are not at depth zero. A depth 1395 // of zero indicates we are currently parsing the top level 1396 // DW_TAG_subprogram DIE 1397 1398 if (depth == 0) 1399 die = NULL; 1400 else 1401 die = die->GetSibling(); 1402 } 1403 return blocks_added; 1404 } 1405 1406 bool 1407 SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, 1408 const DWARFDebugInfoEntry *die, 1409 ClangASTContext::TemplateParameterInfos &template_param_infos) 1410 { 1411 const dw_tag_t tag = die->Tag(); 1412 1413 switch (tag) 1414 { 1415 case DW_TAG_template_type_parameter: 1416 case DW_TAG_template_value_parameter: 1417 { 1418 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 1419 1420 DWARFDebugInfoEntry::Attributes attributes; 1421 const size_t num_attributes = die->GetAttributes (this, 1422 dwarf_cu, 1423 fixed_form_sizes, 1424 attributes); 1425 const char *name = NULL; 1426 Type *lldb_type = NULL; 1427 ClangASTType clang_type; 1428 uint64_t uval64 = 0; 1429 bool uval64_valid = false; 1430 if (num_attributes > 0) 1431 { 1432 DWARFFormValue form_value; 1433 for (size_t i=0; i<num_attributes; ++i) 1434 { 1435 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1436 1437 switch (attr) 1438 { 1439 case DW_AT_name: 1440 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1441 name = form_value.AsCString(&get_debug_str_data()); 1442 break; 1443 1444 case DW_AT_type: 1445 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1446 { 1447 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu); 1448 lldb_type = ResolveTypeUID(type_die_offset); 1449 if (lldb_type) 1450 clang_type = lldb_type->GetClangForwardType(); 1451 } 1452 break; 1453 1454 case DW_AT_const_value: 1455 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1456 { 1457 uval64_valid = true; 1458 uval64 = form_value.Unsigned(); 1459 } 1460 break; 1461 default: 1462 break; 1463 } 1464 } 1465 1466 clang::ASTContext *ast = GetClangASTContext().getASTContext(); 1467 if (!clang_type) 1468 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); 1469 1470 if (clang_type) 1471 { 1472 bool is_signed = false; 1473 if (name && name[0]) 1474 template_param_infos.names.push_back(name); 1475 else 1476 template_param_infos.names.push_back(NULL); 1477 1478 if (tag == DW_TAG_template_value_parameter && 1479 lldb_type != NULL && 1480 clang_type.IsIntegerType (is_signed) && 1481 uval64_valid) 1482 { 1483 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); 1484 template_param_infos.args.push_back (clang::TemplateArgument (*ast, 1485 llvm::APSInt(apint), 1486 clang_type.GetQualType())); 1487 } 1488 else 1489 { 1490 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); 1491 } 1492 } 1493 else 1494 { 1495 return false; 1496 } 1497 1498 } 1499 } 1500 return true; 1501 1502 default: 1503 break; 1504 } 1505 return false; 1506 } 1507 1508 bool 1509 SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, 1510 const DWARFDebugInfoEntry *parent_die, 1511 ClangASTContext::TemplateParameterInfos &template_param_infos) 1512 { 1513 1514 if (parent_die == NULL) 1515 return false; 1516 1517 Args template_parameter_names; 1518 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); 1519 die != NULL; 1520 die = die->GetSibling()) 1521 { 1522 const dw_tag_t tag = die->Tag(); 1523 1524 switch (tag) 1525 { 1526 case DW_TAG_template_type_parameter: 1527 case DW_TAG_template_value_parameter: 1528 ParseTemplateDIE (dwarf_cu, die, template_param_infos); 1529 break; 1530 1531 default: 1532 break; 1533 } 1534 } 1535 if (template_param_infos.args.empty()) 1536 return false; 1537 return template_param_infos.args.size() == template_param_infos.names.size(); 1538 } 1539 1540 clang::ClassTemplateDecl * 1541 SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, 1542 lldb::AccessType access_type, 1543 const char *parent_name, 1544 int tag_decl_kind, 1545 const ClangASTContext::TemplateParameterInfos &template_param_infos) 1546 { 1547 if (template_param_infos.IsValid()) 1548 { 1549 std::string template_basename(parent_name); 1550 template_basename.erase (template_basename.find('<')); 1551 ClangASTContext &ast = GetClangASTContext(); 1552 1553 return ast.CreateClassTemplateDecl (decl_ctx, 1554 access_type, 1555 template_basename.c_str(), 1556 tag_decl_kind, 1557 template_param_infos); 1558 } 1559 return NULL; 1560 } 1561 1562 class SymbolFileDWARF::DelayedAddObjCClassProperty 1563 { 1564 public: 1565 DelayedAddObjCClassProperty 1566 ( 1567 const ClangASTType &class_opaque_type, 1568 const char *property_name, 1569 const ClangASTType &property_opaque_type, // The property type is only required if you don't have an ivar decl 1570 clang::ObjCIvarDecl *ivar_decl, 1571 const char *property_setter_name, 1572 const char *property_getter_name, 1573 uint32_t property_attributes, 1574 const ClangASTMetadata *metadata 1575 ) : 1576 m_class_opaque_type (class_opaque_type), 1577 m_property_name (property_name), 1578 m_property_opaque_type (property_opaque_type), 1579 m_ivar_decl (ivar_decl), 1580 m_property_setter_name (property_setter_name), 1581 m_property_getter_name (property_getter_name), 1582 m_property_attributes (property_attributes) 1583 { 1584 if (metadata != NULL) 1585 { 1586 m_metadata_ap.reset(new ClangASTMetadata()); 1587 *m_metadata_ap = *metadata; 1588 } 1589 } 1590 1591 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) 1592 { 1593 *this = rhs; 1594 } 1595 1596 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) 1597 { 1598 m_class_opaque_type = rhs.m_class_opaque_type; 1599 m_property_name = rhs.m_property_name; 1600 m_property_opaque_type = rhs.m_property_opaque_type; 1601 m_ivar_decl = rhs.m_ivar_decl; 1602 m_property_setter_name = rhs.m_property_setter_name; 1603 m_property_getter_name = rhs.m_property_getter_name; 1604 m_property_attributes = rhs.m_property_attributes; 1605 1606 if (rhs.m_metadata_ap.get()) 1607 { 1608 m_metadata_ap.reset (new ClangASTMetadata()); 1609 *m_metadata_ap = *rhs.m_metadata_ap; 1610 } 1611 return *this; 1612 } 1613 1614 bool 1615 Finalize() 1616 { 1617 return m_class_opaque_type.AddObjCClassProperty (m_property_name, 1618 m_property_opaque_type, 1619 m_ivar_decl, 1620 m_property_setter_name, 1621 m_property_getter_name, 1622 m_property_attributes, 1623 m_metadata_ap.get()); 1624 } 1625 private: 1626 ClangASTType m_class_opaque_type; 1627 const char *m_property_name; 1628 ClangASTType m_property_opaque_type; 1629 clang::ObjCIvarDecl *m_ivar_decl; 1630 const char *m_property_setter_name; 1631 const char *m_property_getter_name; 1632 uint32_t m_property_attributes; 1633 std::unique_ptr<ClangASTMetadata> m_metadata_ap; 1634 }; 1635 1636 struct BitfieldInfo 1637 { 1638 uint64_t bit_size; 1639 uint64_t bit_offset; 1640 1641 BitfieldInfo () : 1642 bit_size (LLDB_INVALID_ADDRESS), 1643 bit_offset (LLDB_INVALID_ADDRESS) 1644 { 1645 } 1646 1647 bool IsValid () 1648 { 1649 return (bit_size != LLDB_INVALID_ADDRESS) && 1650 (bit_offset != LLDB_INVALID_ADDRESS); 1651 } 1652 }; 1653 1654 1655 bool 1656 SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, 1657 const DWARFDebugInfoEntry *parent_die) 1658 { 1659 if (parent_die) 1660 { 1661 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 1662 { 1663 dw_tag_t tag = die->Tag(); 1664 bool check_virtuality = false; 1665 switch (tag) 1666 { 1667 case DW_TAG_inheritance: 1668 case DW_TAG_subprogram: 1669 check_virtuality = true; 1670 break; 1671 default: 1672 break; 1673 } 1674 if (check_virtuality) 1675 { 1676 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) 1677 return true; 1678 } 1679 } 1680 } 1681 return false; 1682 } 1683 1684 size_t 1685 SymbolFileDWARF::ParseChildMembers 1686 ( 1687 const SymbolContext& sc, 1688 DWARFCompileUnit* dwarf_cu, 1689 const DWARFDebugInfoEntry *parent_die, 1690 ClangASTType &class_clang_type, 1691 const LanguageType class_language, 1692 std::vector<clang::CXXBaseSpecifier *>& base_classes, 1693 std::vector<int>& member_accessibilities, 1694 DWARFDIECollection& member_function_dies, 1695 DelayedPropertyList& delayed_properties, 1696 AccessType& default_accessibility, 1697 bool &is_a_class, 1698 LayoutInfo &layout_info 1699 ) 1700 { 1701 if (parent_die == NULL) 1702 return 0; 1703 1704 size_t count = 0; 1705 const DWARFDebugInfoEntry *die; 1706 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 1707 uint32_t member_idx = 0; 1708 BitfieldInfo last_field_info; 1709 1710 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 1711 { 1712 dw_tag_t tag = die->Tag(); 1713 1714 switch (tag) 1715 { 1716 case DW_TAG_member: 1717 case DW_TAG_APPLE_property: 1718 { 1719 DWARFDebugInfoEntry::Attributes attributes; 1720 const size_t num_attributes = die->GetAttributes (this, 1721 dwarf_cu, 1722 fixed_form_sizes, 1723 attributes); 1724 if (num_attributes > 0) 1725 { 1726 Declaration decl; 1727 //DWARFExpression location; 1728 const char *name = NULL; 1729 const char *prop_name = NULL; 1730 const char *prop_getter_name = NULL; 1731 const char *prop_setter_name = NULL; 1732 uint32_t prop_attributes = 0; 1733 1734 1735 bool is_artificial = false; 1736 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 1737 AccessType accessibility = eAccessNone; 1738 uint32_t member_byte_offset = UINT32_MAX; 1739 size_t byte_size = 0; 1740 size_t bit_offset = 0; 1741 size_t bit_size = 0; 1742 bool is_external = false; // On DW_TAG_members, this means the member is static 1743 uint32_t i; 1744 for (i=0; i<num_attributes && !is_artificial; ++i) 1745 { 1746 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1747 DWARFFormValue form_value; 1748 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1749 { 1750 switch (attr) 1751 { 1752 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 1753 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 1754 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 1755 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 1756 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; 1757 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; 1758 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; 1759 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 1760 case DW_AT_data_member_location: 1761 if (form_value.BlockData()) 1762 { 1763 Value initialValue(0); 1764 Value memberOffset(0); 1765 const DataExtractor& debug_info_data = get_debug_info_data(); 1766 uint32_t block_length = form_value.Unsigned(); 1767 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 1768 if (DWARFExpression::Evaluate(NULL, // ExecutionContext * 1769 NULL, // ClangExpressionVariableList * 1770 NULL, // ClangExpressionDeclMap * 1771 NULL, // RegisterContext * 1772 debug_info_data, 1773 block_offset, 1774 block_length, 1775 eRegisterKindDWARF, 1776 &initialValue, 1777 memberOffset, 1778 NULL)) 1779 { 1780 member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); 1781 } 1782 } 1783 else 1784 { 1785 // With DWARF 3 and later, if the value is an integer constant, 1786 // this form value is the offset in bytes from the beginning 1787 // of the containing entity. 1788 member_byte_offset = form_value.Unsigned(); 1789 } 1790 break; 1791 1792 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; 1793 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 1794 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; 1795 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; 1796 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; 1797 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; 1798 case DW_AT_external: is_external = form_value.Boolean(); break; 1799 1800 default: 1801 case DW_AT_declaration: 1802 case DW_AT_description: 1803 case DW_AT_mutable: 1804 case DW_AT_visibility: 1805 case DW_AT_sibling: 1806 break; 1807 } 1808 } 1809 } 1810 1811 if (prop_name) 1812 { 1813 ConstString fixed_getter; 1814 ConstString fixed_setter; 1815 1816 // Check if the property getter/setter were provided as full 1817 // names. We want basenames, so we extract them. 1818 1819 if (prop_getter_name && prop_getter_name[0] == '-') 1820 { 1821 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); 1822 prop_getter_name = prop_getter_method.GetSelector().GetCString(); 1823 } 1824 1825 if (prop_setter_name && prop_setter_name[0] == '-') 1826 { 1827 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); 1828 prop_setter_name = prop_setter_method.GetSelector().GetCString(); 1829 } 1830 1831 // If the names haven't been provided, they need to be 1832 // filled in. 1833 1834 if (!prop_getter_name) 1835 { 1836 prop_getter_name = prop_name; 1837 } 1838 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) 1839 { 1840 StreamString ss; 1841 1842 ss.Printf("set%c%s:", 1843 toupper(prop_name[0]), 1844 &prop_name[1]); 1845 1846 fixed_setter.SetCString(ss.GetData()); 1847 prop_setter_name = fixed_setter.GetCString(); 1848 } 1849 } 1850 1851 // Clang has a DWARF generation bug where sometimes it 1852 // represents fields that are references with bad byte size 1853 // and bit size/offset information such as: 1854 // 1855 // DW_AT_byte_size( 0x00 ) 1856 // DW_AT_bit_size( 0x40 ) 1857 // DW_AT_bit_offset( 0xffffffffffffffc0 ) 1858 // 1859 // So check the bit offset to make sure it is sane, and if 1860 // the values are not sane, remove them. If we don't do this 1861 // then we will end up with a crash if we try to use this 1862 // type in an expression when clang becomes unhappy with its 1863 // recycled debug info. 1864 1865 if (bit_offset > 128) 1866 { 1867 bit_size = 0; 1868 bit_offset = 0; 1869 } 1870 1871 // FIXME: Make Clang ignore Objective-C accessibility for expressions 1872 if (class_language == eLanguageTypeObjC || 1873 class_language == eLanguageTypeObjC_plus_plus) 1874 accessibility = eAccessNone; 1875 1876 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) 1877 { 1878 // Not all compilers will mark the vtable pointer 1879 // member as artificial (llvm-gcc). We can't have 1880 // the virtual members in our classes otherwise it 1881 // throws off all child offsets since we end up 1882 // having and extra pointer sized member in our 1883 // class layouts. 1884 is_artificial = true; 1885 } 1886 1887 // Handle static members 1888 if (is_external && member_byte_offset == UINT32_MAX) 1889 { 1890 Type *var_type = ResolveTypeUID(encoding_uid); 1891 1892 if (var_type) 1893 { 1894 if (accessibility == eAccessNone) 1895 accessibility = eAccessPublic; 1896 class_clang_type.AddVariableToRecordType (name, 1897 var_type->GetClangLayoutType(), 1898 accessibility); 1899 } 1900 break; 1901 } 1902 1903 if (is_artificial == false) 1904 { 1905 Type *member_type = ResolveTypeUID(encoding_uid); 1906 1907 clang::FieldDecl *field_decl = NULL; 1908 if (tag == DW_TAG_member) 1909 { 1910 if (member_type) 1911 { 1912 if (accessibility == eAccessNone) 1913 accessibility = default_accessibility; 1914 member_accessibilities.push_back(accessibility); 1915 1916 BitfieldInfo this_field_info; 1917 1918 this_field_info.bit_size = bit_size; 1919 1920 if (member_byte_offset != UINT32_MAX || bit_size != 0) 1921 { 1922 ///////////////////////////////////////////////////////////// 1923 // How to locate a field given the DWARF debug information 1924 // 1925 // AT_byte_size indicates the size of the word in which the 1926 // bit offset must be interpreted. 1927 // 1928 // AT_data_member_location indicates the byte offset of the 1929 // word from the base address of the structure. 1930 // 1931 // AT_bit_offset indicates how many bits into the word 1932 // (according to the host endianness) the low-order bit of 1933 // the field starts. AT_bit_offset can be negative. 1934 // 1935 // AT_bit_size indicates the size of the field in bits. 1936 ///////////////////////////////////////////////////////////// 1937 1938 this_field_info.bit_offset = 0; 1939 1940 this_field_info.bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); 1941 1942 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) 1943 { 1944 this_field_info.bit_offset += byte_size * 8; 1945 this_field_info.bit_offset -= (bit_offset + bit_size); 1946 } 1947 else 1948 { 1949 this_field_info.bit_offset += bit_offset; 1950 } 1951 } 1952 1953 // If the member to be emitted did not start on a character boundary and there is 1954 // empty space between the last field and this one, then we need to emit an 1955 // anonymous member filling up the space up to its start. There are three cases 1956 // here: 1957 // 1958 // 1 If the previous member ended on a character boundary, then we can emit an 1959 // anonymous member starting at the most recent character boundary. 1960 // 1961 // 2 If the previous member did not end on a character boundary and the distance 1962 // from the end of the previous member to the current member is less than a 1963 // word width, then we can emit an anonymous member starting right after the 1964 // previous member and right before this member. 1965 // 1966 // 3 If the previous member did not end on a character boundary and the distance 1967 // from the end of the previous member to the current member is greater than 1968 // or equal a word width, then we act as in Case 1. 1969 1970 const uint64_t character_width = 8; 1971 const uint64_t word_width = 32; 1972 1973 if (this_field_info.IsValid()) 1974 { 1975 // Objective-C has invalid DW_AT_bit_offset values in older versions 1976 // of clang, so we have to be careful and only insert unnammed bitfields 1977 // if we have a new enough clang. 1978 bool detect_unnamed_bitfields = true; 1979 1980 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) 1981 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); 1982 1983 if (detect_unnamed_bitfields) 1984 { 1985 BitfieldInfo anon_field_info; 1986 1987 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned 1988 { 1989 uint64_t last_field_end = 0; 1990 1991 if (last_field_info.IsValid()) 1992 last_field_end = last_field_info.bit_offset + last_field_info.bit_size; 1993 1994 if (this_field_info.bit_offset != last_field_end) 1995 { 1996 if (((last_field_end % character_width) == 0) || // case 1 1997 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 1998 { 1999 anon_field_info.bit_size = this_field_info.bit_offset % character_width; 2000 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; 2001 } 2002 else // case 2 2003 { 2004 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; 2005 anon_field_info.bit_offset = last_field_end; 2006 } 2007 } 2008 } 2009 2010 if (anon_field_info.IsValid()) 2011 { 2012 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, 2013 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), 2014 accessibility, 2015 anon_field_info.bit_size); 2016 2017 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); 2018 } 2019 } 2020 } 2021 2022 ClangASTType member_clang_type = member_type->GetClangLayoutType(); 2023 2024 { 2025 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). 2026 // If the current field is at the end of the structure, then there is definitely no room for extra 2027 // elements and we override the type to array[0]. 2028 2029 ClangASTType member_array_element_type; 2030 uint64_t member_array_size; 2031 bool member_array_is_incomplete; 2032 2033 if (member_clang_type.IsArrayType(&member_array_element_type, 2034 &member_array_size, 2035 &member_array_is_incomplete) && 2036 !member_array_is_incomplete) 2037 { 2038 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); 2039 2040 if (member_byte_offset >= parent_byte_size) 2041 { 2042 if (member_array_size != 1) 2043 { 2044 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64, 2045 MakeUserID(die->GetOffset()), 2046 name, 2047 encoding_uid, 2048 MakeUserID(parent_die->GetOffset())); 2049 } 2050 2051 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); 2052 } 2053 } 2054 } 2055 2056 field_decl = class_clang_type.AddFieldToRecordType (name, 2057 member_clang_type, 2058 accessibility, 2059 bit_size); 2060 2061 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); 2062 2063 if (this_field_info.IsValid()) 2064 { 2065 layout_info.field_offsets.insert(std::make_pair(field_decl, this_field_info.bit_offset)); 2066 last_field_info = this_field_info; 2067 } 2068 } 2069 else 2070 { 2071 if (name) 2072 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed", 2073 MakeUserID(die->GetOffset()), 2074 name, 2075 encoding_uid); 2076 else 2077 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed", 2078 MakeUserID(die->GetOffset()), 2079 encoding_uid); 2080 } 2081 } 2082 2083 if (prop_name != NULL) 2084 { 2085 clang::ObjCIvarDecl *ivar_decl = NULL; 2086 2087 if (field_decl) 2088 { 2089 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); 2090 assert (ivar_decl != NULL); 2091 } 2092 2093 ClangASTMetadata metadata; 2094 metadata.SetUserID (MakeUserID(die->GetOffset())); 2095 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, 2096 prop_name, 2097 member_type->GetClangLayoutType(), 2098 ivar_decl, 2099 prop_setter_name, 2100 prop_getter_name, 2101 prop_attributes, 2102 &metadata)); 2103 2104 if (ivar_decl) 2105 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); 2106 } 2107 } 2108 } 2109 ++member_idx; 2110 } 2111 break; 2112 2113 case DW_TAG_subprogram: 2114 // Let the type parsing code handle this one for us. 2115 member_function_dies.Append (die); 2116 break; 2117 2118 case DW_TAG_inheritance: 2119 { 2120 is_a_class = true; 2121 if (default_accessibility == eAccessNone) 2122 default_accessibility = eAccessPrivate; 2123 // TODO: implement DW_TAG_inheritance type parsing 2124 DWARFDebugInfoEntry::Attributes attributes; 2125 const size_t num_attributes = die->GetAttributes (this, 2126 dwarf_cu, 2127 fixed_form_sizes, 2128 attributes); 2129 if (num_attributes > 0) 2130 { 2131 Declaration decl; 2132 DWARFExpression location; 2133 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 2134 AccessType accessibility = default_accessibility; 2135 bool is_virtual = false; 2136 bool is_base_of_class = true; 2137 off_t member_byte_offset = 0; 2138 uint32_t i; 2139 for (i=0; i<num_attributes; ++i) 2140 { 2141 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2142 DWARFFormValue form_value; 2143 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2144 { 2145 switch (attr) 2146 { 2147 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2148 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2149 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2150 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; 2151 case DW_AT_data_member_location: 2152 if (form_value.BlockData()) 2153 { 2154 Value initialValue(0); 2155 Value memberOffset(0); 2156 const DataExtractor& debug_info_data = get_debug_info_data(); 2157 uint32_t block_length = form_value.Unsigned(); 2158 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 2159 if (DWARFExpression::Evaluate (NULL, 2160 NULL, 2161 NULL, 2162 NULL, 2163 debug_info_data, 2164 block_offset, 2165 block_length, 2166 eRegisterKindDWARF, 2167 &initialValue, 2168 memberOffset, 2169 NULL)) 2170 { 2171 member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); 2172 } 2173 } 2174 else 2175 { 2176 // With DWARF 3 and later, if the value is an integer constant, 2177 // this form value is the offset in bytes from the beginning 2178 // of the containing entity. 2179 member_byte_offset = form_value.Unsigned(); 2180 } 2181 break; 2182 2183 case DW_AT_accessibility: 2184 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 2185 break; 2186 2187 case DW_AT_virtuality: 2188 is_virtual = form_value.Boolean(); 2189 break; 2190 2191 case DW_AT_sibling: 2192 break; 2193 2194 default: 2195 break; 2196 } 2197 } 2198 } 2199 2200 Type *base_class_type = ResolveTypeUID(encoding_uid); 2201 assert(base_class_type); 2202 2203 ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); 2204 assert (base_class_clang_type); 2205 if (class_language == eLanguageTypeObjC) 2206 { 2207 class_clang_type.SetObjCSuperClass(base_class_clang_type); 2208 } 2209 else 2210 { 2211 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, 2212 is_virtual, 2213 is_base_of_class)); 2214 2215 if (is_virtual) 2216 { 2217 layout_info.vbase_offsets.insert(std::make_pair(class_clang_type.GetAsCXXRecordDecl(), 2218 clang::CharUnits::fromQuantity(member_byte_offset))); 2219 } 2220 else 2221 { 2222 layout_info.base_offsets.insert(std::make_pair(class_clang_type.GetAsCXXRecordDecl(), 2223 clang::CharUnits::fromQuantity(member_byte_offset))); 2224 } 2225 } 2226 } 2227 } 2228 break; 2229 2230 default: 2231 break; 2232 } 2233 } 2234 2235 return count; 2236 } 2237 2238 2239 clang::DeclContext* 2240 SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) 2241 { 2242 DWARFDebugInfo* debug_info = DebugInfo(); 2243 if (debug_info && UserIDMatches(type_uid)) 2244 { 2245 DWARFCompileUnitSP cu_sp; 2246 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); 2247 if (die) 2248 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); 2249 } 2250 return NULL; 2251 } 2252 2253 clang::DeclContext* 2254 SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) 2255 { 2256 if (UserIDMatches(type_uid)) 2257 return GetClangDeclContextForDIEOffset (sc, type_uid); 2258 return NULL; 2259 } 2260 2261 Type* 2262 SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) 2263 { 2264 if (UserIDMatches(type_uid)) 2265 { 2266 DWARFDebugInfo* debug_info = DebugInfo(); 2267 if (debug_info) 2268 { 2269 DWARFCompileUnitSP cu_sp; 2270 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); 2271 const bool assert_not_being_parsed = true; 2272 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); 2273 } 2274 } 2275 return NULL; 2276 } 2277 2278 Type* 2279 SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) 2280 { 2281 if (die != NULL) 2282 { 2283 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 2284 if (log) 2285 GetObjectFile()->GetModule()->LogMessage (log, 2286 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", 2287 die->GetOffset(), 2288 DW_TAG_value_to_name(die->Tag()), 2289 die->GetName(this, cu)); 2290 2291 // We might be coming in in the middle of a type tree (a class 2292 // withing a class, an enum within a class), so parse any needed 2293 // parent DIEs before we get to this one... 2294 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); 2295 switch (decl_ctx_die->Tag()) 2296 { 2297 case DW_TAG_structure_type: 2298 case DW_TAG_union_type: 2299 case DW_TAG_class_type: 2300 { 2301 // Get the type, which could be a forward declaration 2302 if (log) 2303 GetObjectFile()->GetModule()->LogMessage (log, 2304 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", 2305 die->GetOffset(), 2306 DW_TAG_value_to_name(die->Tag()), 2307 die->GetName(this, cu), 2308 decl_ctx_die->GetOffset()); 2309 // 2310 // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); 2311 // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) 2312 // { 2313 // if (log) 2314 // GetObjectFile()->GetModule()->LogMessage (log, 2315 // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", 2316 // die->GetOffset(), 2317 // DW_TAG_value_to_name(die->Tag()), 2318 // die->GetName(this, cu), 2319 // decl_ctx_die->GetOffset()); 2320 // // Ask the type to complete itself if it already hasn't since if we 2321 // // want a function (method or static) from a class, the class must 2322 // // create itself and add it's own methods and class functions. 2323 // if (parent_type) 2324 // parent_type->GetClangFullType(); 2325 // } 2326 } 2327 break; 2328 2329 default: 2330 break; 2331 } 2332 return ResolveType (cu, die); 2333 } 2334 return NULL; 2335 } 2336 2337 // This function is used when SymbolFileDWARFDebugMap owns a bunch of 2338 // SymbolFileDWARF objects to detect if this DWARF file is the one that 2339 // can resolve a clang_type. 2340 bool 2341 SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) 2342 { 2343 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); 2344 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); 2345 return die != NULL; 2346 } 2347 2348 2349 bool 2350 SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) 2351 { 2352 // We have a struct/union/class/enum that needs to be fully resolved. 2353 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); 2354 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); 2355 if (die == NULL) 2356 { 2357 // We have already resolved this type... 2358 return true; 2359 } 2360 // Once we start resolving this type, remove it from the forward declaration 2361 // map in case anyone child members or other types require this type to get resolved. 2362 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition 2363 // are done. 2364 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); 2365 2366 2367 // Disable external storage for this type so we don't get anymore 2368 // clang::ExternalASTSource queries for this type. 2369 clang_type.SetHasExternalStorage (false); 2370 2371 DWARFDebugInfo* debug_info = DebugInfo(); 2372 2373 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); 2374 Type *type = m_die_to_type.lookup (die); 2375 2376 const dw_tag_t tag = die->Tag(); 2377 2378 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); 2379 if (log) 2380 { 2381 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, 2382 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", 2383 MakeUserID(die->GetOffset()), 2384 DW_TAG_value_to_name(tag), 2385 type->GetName().AsCString()); 2386 2387 } 2388 assert (clang_type); 2389 DWARFDebugInfoEntry::Attributes attributes; 2390 2391 switch (tag) 2392 { 2393 case DW_TAG_structure_type: 2394 case DW_TAG_union_type: 2395 case DW_TAG_class_type: 2396 { 2397 LayoutInfo layout_info; 2398 2399 { 2400 if (die->HasChildren()) 2401 { 2402 2403 LanguageType class_language = eLanguageTypeUnknown; 2404 if (clang_type.IsObjCObjectOrInterfaceType()) 2405 { 2406 class_language = eLanguageTypeObjC; 2407 // For objective C we don't start the definition when 2408 // the class is created. 2409 clang_type.StartTagDeclarationDefinition (); 2410 } 2411 2412 int tag_decl_kind = -1; 2413 AccessType default_accessibility = eAccessNone; 2414 if (tag == DW_TAG_structure_type) 2415 { 2416 tag_decl_kind = clang::TTK_Struct; 2417 default_accessibility = eAccessPublic; 2418 } 2419 else if (tag == DW_TAG_union_type) 2420 { 2421 tag_decl_kind = clang::TTK_Union; 2422 default_accessibility = eAccessPublic; 2423 } 2424 else if (tag == DW_TAG_class_type) 2425 { 2426 tag_decl_kind = clang::TTK_Class; 2427 default_accessibility = eAccessPrivate; 2428 } 2429 2430 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); 2431 std::vector<clang::CXXBaseSpecifier *> base_classes; 2432 std::vector<int> member_accessibilities; 2433 bool is_a_class = false; 2434 // Parse members and base classes first 2435 DWARFDIECollection member_function_dies; 2436 2437 DelayedPropertyList delayed_properties; 2438 ParseChildMembers (sc, 2439 dwarf_cu, 2440 die, 2441 clang_type, 2442 class_language, 2443 base_classes, 2444 member_accessibilities, 2445 member_function_dies, 2446 delayed_properties, 2447 default_accessibility, 2448 is_a_class, 2449 layout_info); 2450 2451 // Now parse any methods if there were any... 2452 size_t num_functions = member_function_dies.Size(); 2453 if (num_functions > 0) 2454 { 2455 for (size_t i=0; i<num_functions; ++i) 2456 { 2457 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); 2458 } 2459 } 2460 2461 if (class_language == eLanguageTypeObjC) 2462 { 2463 std::string class_str (clang_type.GetTypeName()); 2464 if (!class_str.empty()) 2465 { 2466 2467 DIEArray method_die_offsets; 2468 if (m_using_apple_tables) 2469 { 2470 if (m_apple_objc_ap.get()) 2471 m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets); 2472 } 2473 else 2474 { 2475 if (!m_indexed) 2476 Index (); 2477 2478 ConstString class_name (class_str.c_str()); 2479 m_objc_class_selectors_index.Find (class_name, method_die_offsets); 2480 } 2481 2482 if (!method_die_offsets.empty()) 2483 { 2484 DWARFDebugInfo* debug_info = DebugInfo(); 2485 2486 DWARFCompileUnit* method_cu = NULL; 2487 const size_t num_matches = method_die_offsets.size(); 2488 for (size_t i=0; i<num_matches; ++i) 2489 { 2490 const dw_offset_t die_offset = method_die_offsets[i]; 2491 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); 2492 2493 if (method_die) 2494 ResolveType (method_cu, method_die); 2495 else 2496 { 2497 if (m_using_apple_tables) 2498 { 2499 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", 2500 die_offset, class_str.c_str()); 2501 } 2502 } 2503 } 2504 } 2505 2506 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); 2507 pi != pe; 2508 ++pi) 2509 pi->Finalize(); 2510 } 2511 } 2512 2513 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we 2514 // need to tell the clang type it is actually a class. 2515 if (class_language != eLanguageTypeObjC) 2516 { 2517 if (is_a_class && tag_decl_kind != clang::TTK_Class) 2518 clang_type.SetTagTypeKind (clang::TTK_Class); 2519 } 2520 2521 // Since DW_TAG_structure_type gets used for both classes 2522 // and structures, we may need to set any DW_TAG_member 2523 // fields to have a "private" access if none was specified. 2524 // When we parsed the child members we tracked that actual 2525 // accessibility value for each DW_TAG_member in the 2526 // "member_accessibilities" array. If the value for the 2527 // member is zero, then it was set to the "default_accessibility" 2528 // which for structs was "public". Below we correct this 2529 // by setting any fields to "private" that weren't correctly 2530 // set. 2531 if (is_a_class && !member_accessibilities.empty()) 2532 { 2533 // This is a class and all members that didn't have 2534 // their access specified are private. 2535 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, 2536 &member_accessibilities.front(), 2537 member_accessibilities.size()); 2538 } 2539 2540 if (!base_classes.empty()) 2541 { 2542 clang_type.SetBaseClassesForClassType (&base_classes.front(), 2543 base_classes.size()); 2544 2545 // Clang will copy each CXXBaseSpecifier in "base_classes" 2546 // so we have to free them all. 2547 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), 2548 base_classes.size()); 2549 } 2550 } 2551 } 2552 2553 clang_type.BuildIndirectFields (); 2554 clang_type.CompleteTagDeclarationDefinition (); 2555 2556 if (!layout_info.field_offsets.empty() || 2557 !layout_info.base_offsets.empty() || 2558 !layout_info.vbase_offsets.empty() ) 2559 { 2560 if (type) 2561 layout_info.bit_size = type->GetByteSize() * 8; 2562 if (layout_info.bit_size == 0) 2563 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; 2564 2565 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); 2566 if (record_decl) 2567 { 2568 if (log) 2569 { 2570 GetObjectFile()->GetModule()->LogMessage (log, 2571 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", 2572 clang_type.GetOpaqueQualType(), 2573 record_decl, 2574 layout_info.bit_size, 2575 layout_info.alignment, 2576 (uint32_t)layout_info.field_offsets.size(), 2577 (uint32_t)layout_info.base_offsets.size(), 2578 (uint32_t)layout_info.vbase_offsets.size()); 2579 2580 uint32_t idx; 2581 { 2582 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); 2583 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) 2584 { 2585 GetObjectFile()->GetModule()->LogMessage (log, 2586 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", 2587 clang_type.GetOpaqueQualType(), 2588 idx, 2589 (uint32_t)pos->second, 2590 pos->first->getNameAsString().c_str()); 2591 } 2592 } 2593 2594 { 2595 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); 2596 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) 2597 { 2598 GetObjectFile()->GetModule()->LogMessage (log, 2599 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", 2600 clang_type.GetOpaqueQualType(), 2601 idx, 2602 (uint32_t)base_pos->second.getQuantity(), 2603 base_pos->first->getNameAsString().c_str()); 2604 } 2605 } 2606 { 2607 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); 2608 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) 2609 { 2610 GetObjectFile()->GetModule()->LogMessage (log, 2611 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", 2612 clang_type.GetOpaqueQualType(), 2613 idx, 2614 (uint32_t)vbase_pos->second.getQuantity(), 2615 vbase_pos->first->getNameAsString().c_str()); 2616 } 2617 } 2618 } 2619 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); 2620 } 2621 } 2622 } 2623 2624 return clang_type; 2625 2626 case DW_TAG_enumeration_type: 2627 clang_type.StartTagDeclarationDefinition (); 2628 if (die->HasChildren()) 2629 { 2630 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); 2631 bool is_signed = false; 2632 clang_type.IsIntegerType(is_signed); 2633 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); 2634 } 2635 clang_type.CompleteTagDeclarationDefinition (); 2636 return clang_type; 2637 2638 default: 2639 assert(false && "not a forward clang type decl!"); 2640 break; 2641 } 2642 return false; 2643 } 2644 2645 Type* 2646 SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) 2647 { 2648 if (type_die != NULL) 2649 { 2650 Type *type = m_die_to_type.lookup (type_die); 2651 2652 if (type == NULL) 2653 type = GetTypeForDIE (dwarf_cu, type_die).get(); 2654 2655 if (assert_not_being_parsed) 2656 { 2657 if (type != DIE_IS_BEING_PARSED) 2658 return type; 2659 2660 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", 2661 type_die->GetOffset(), 2662 DW_TAG_value_to_name(type_die->Tag()), 2663 type_die->GetName(this, dwarf_cu)); 2664 2665 } 2666 else 2667 return type; 2668 } 2669 return NULL; 2670 } 2671 2672 CompileUnit* 2673 SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) 2674 { 2675 // Check if the symbol vendor already knows about this compile unit? 2676 if (dwarf_cu->GetUserData() == NULL) 2677 { 2678 // The symbol vendor doesn't know about this compile unit, we 2679 // need to parse and add it to the symbol vendor object. 2680 return ParseCompileUnit(dwarf_cu, cu_idx).get(); 2681 } 2682 return (CompileUnit*)dwarf_cu->GetUserData(); 2683 } 2684 2685 bool 2686 SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) 2687 { 2688 sc.Clear(false); 2689 // Check if the symbol vendor already knows about this compile unit? 2690 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 2691 2692 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); 2693 if (sc.function == NULL) 2694 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); 2695 2696 if (sc.function) 2697 { 2698 sc.module_sp = sc.function->CalculateSymbolContextModule(); 2699 return true; 2700 } 2701 2702 return false; 2703 } 2704 2705 uint32_t 2706 SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) 2707 { 2708 Timer scoped_timer(__PRETTY_FUNCTION__, 2709 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", 2710 so_addr.GetSection().get(), 2711 so_addr.GetOffset(), 2712 resolve_scope); 2713 uint32_t resolved = 0; 2714 if (resolve_scope & ( eSymbolContextCompUnit | 2715 eSymbolContextFunction | 2716 eSymbolContextBlock | 2717 eSymbolContextLineEntry)) 2718 { 2719 lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); 2720 2721 DWARFDebugInfo* debug_info = DebugInfo(); 2722 if (debug_info) 2723 { 2724 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); 2725 if (cu_offset != DW_INVALID_OFFSET) 2726 { 2727 uint32_t cu_idx = DW_INVALID_INDEX; 2728 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); 2729 if (dwarf_cu) 2730 { 2731 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); 2732 if (sc.comp_unit) 2733 { 2734 resolved |= eSymbolContextCompUnit; 2735 2736 bool force_check_line_table = false; 2737 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) 2738 { 2739 DWARFDebugInfoEntry *function_die = NULL; 2740 DWARFDebugInfoEntry *block_die = NULL; 2741 if (resolve_scope & eSymbolContextBlock) 2742 { 2743 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); 2744 } 2745 else 2746 { 2747 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); 2748 } 2749 2750 if (function_die != NULL) 2751 { 2752 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); 2753 if (sc.function == NULL) 2754 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); 2755 } 2756 else 2757 { 2758 // We might have had a compile unit that had discontiguous 2759 // address ranges where the gaps are symbols that don't have 2760 // any debug info. Discontiguous compile unit address ranges 2761 // should only happen when there aren't other functions from 2762 // other compile units in these gaps. This helps keep the size 2763 // of the aranges down. 2764 force_check_line_table = true; 2765 } 2766 2767 if (sc.function != NULL) 2768 { 2769 resolved |= eSymbolContextFunction; 2770 2771 if (resolve_scope & eSymbolContextBlock) 2772 { 2773 Block& block = sc.function->GetBlock (true); 2774 2775 if (block_die != NULL) 2776 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); 2777 else 2778 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); 2779 if (sc.block) 2780 resolved |= eSymbolContextBlock; 2781 } 2782 } 2783 } 2784 2785 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) 2786 { 2787 LineTable *line_table = sc.comp_unit->GetLineTable(); 2788 if (line_table != NULL) 2789 { 2790 // And address that makes it into this function should be in terms 2791 // of this debug file if there is no debug map, or it will be an 2792 // address in the .o file which needs to be fixed up to be in terms 2793 // of the debug map executable. Either way, calling FixupAddress() 2794 // will work for us. 2795 Address exe_so_addr (so_addr); 2796 if (FixupAddress(exe_so_addr)) 2797 { 2798 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) 2799 { 2800 resolved |= eSymbolContextLineEntry; 2801 } 2802 } 2803 } 2804 } 2805 2806 if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) 2807 { 2808 // We might have had a compile unit that had discontiguous 2809 // address ranges where the gaps are symbols that don't have 2810 // any debug info. Discontiguous compile unit address ranges 2811 // should only happen when there aren't other functions from 2812 // other compile units in these gaps. This helps keep the size 2813 // of the aranges down. 2814 sc.comp_unit = NULL; 2815 resolved &= ~eSymbolContextCompUnit; 2816 } 2817 } 2818 else 2819 { 2820 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", 2821 cu_offset, 2822 cu_idx); 2823 } 2824 } 2825 } 2826 } 2827 } 2828 return resolved; 2829 } 2830 2831 2832 2833 uint32_t 2834 SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 2835 { 2836 const uint32_t prev_size = sc_list.GetSize(); 2837 if (resolve_scope & eSymbolContextCompUnit) 2838 { 2839 DWARFDebugInfo* debug_info = DebugInfo(); 2840 if (debug_info) 2841 { 2842 uint32_t cu_idx; 2843 DWARFCompileUnit* dwarf_cu = NULL; 2844 2845 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) 2846 { 2847 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); 2848 const bool full_match = file_spec.GetDirectory(); 2849 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match); 2850 if (check_inlines || file_spec_matches_cu_file_spec) 2851 { 2852 SymbolContext sc (m_obj_file->GetModule()); 2853 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); 2854 if (sc.comp_unit) 2855 { 2856 uint32_t file_idx = UINT32_MAX; 2857 2858 // If we are looking for inline functions only and we don't 2859 // find it in the support files, we are done. 2860 if (check_inlines) 2861 { 2862 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); 2863 if (file_idx == UINT32_MAX) 2864 continue; 2865 } 2866 2867 if (line != 0) 2868 { 2869 LineTable *line_table = sc.comp_unit->GetLineTable(); 2870 2871 if (line_table != NULL && line != 0) 2872 { 2873 // We will have already looked up the file index if 2874 // we are searching for inline entries. 2875 if (!check_inlines) 2876 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); 2877 2878 if (file_idx != UINT32_MAX) 2879 { 2880 uint32_t found_line; 2881 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); 2882 found_line = sc.line_entry.line; 2883 2884 while (line_idx != UINT32_MAX) 2885 { 2886 sc.function = NULL; 2887 sc.block = NULL; 2888 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) 2889 { 2890 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); 2891 if (file_vm_addr != LLDB_INVALID_ADDRESS) 2892 { 2893 DWARFDebugInfoEntry *function_die = NULL; 2894 DWARFDebugInfoEntry *block_die = NULL; 2895 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); 2896 2897 if (function_die != NULL) 2898 { 2899 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); 2900 if (sc.function == NULL) 2901 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); 2902 } 2903 2904 if (sc.function != NULL) 2905 { 2906 Block& block = sc.function->GetBlock (true); 2907 2908 if (block_die != NULL) 2909 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); 2910 else 2911 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); 2912 } 2913 } 2914 } 2915 2916 sc_list.Append(sc); 2917 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); 2918 } 2919 } 2920 } 2921 else if (file_spec_matches_cu_file_spec && !check_inlines) 2922 { 2923 // only append the context if we aren't looking for inline call sites 2924 // by file and line and if the file spec matches that of the compile unit 2925 sc_list.Append(sc); 2926 } 2927 } 2928 else if (file_spec_matches_cu_file_spec && !check_inlines) 2929 { 2930 // only append the context if we aren't looking for inline call sites 2931 // by file and line and if the file spec matches that of the compile unit 2932 sc_list.Append(sc); 2933 } 2934 2935 if (!check_inlines) 2936 break; 2937 } 2938 } 2939 } 2940 } 2941 } 2942 return sc_list.GetSize() - prev_size; 2943 } 2944 2945 void 2946 SymbolFileDWARF::Index () 2947 { 2948 if (m_indexed) 2949 return; 2950 m_indexed = true; 2951 Timer scoped_timer (__PRETTY_FUNCTION__, 2952 "SymbolFileDWARF::Index (%s)", 2953 GetObjectFile()->GetFileSpec().GetFilename().AsCString()); 2954 2955 DWARFDebugInfo* debug_info = DebugInfo(); 2956 if (debug_info) 2957 { 2958 uint32_t cu_idx = 0; 2959 const uint32_t num_compile_units = GetNumCompileUnits(); 2960 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) 2961 { 2962 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); 2963 2964 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; 2965 2966 dwarf_cu->Index (cu_idx, 2967 m_function_basename_index, 2968 m_function_fullname_index, 2969 m_function_method_index, 2970 m_function_selector_index, 2971 m_objc_class_selectors_index, 2972 m_global_index, 2973 m_type_index, 2974 m_namespace_index); 2975 2976 // Keep memory down by clearing DIEs if this generate function 2977 // caused them to be parsed 2978 if (clear_dies) 2979 dwarf_cu->ClearDIEs (true); 2980 } 2981 2982 m_function_basename_index.Finalize(); 2983 m_function_fullname_index.Finalize(); 2984 m_function_method_index.Finalize(); 2985 m_function_selector_index.Finalize(); 2986 m_objc_class_selectors_index.Finalize(); 2987 m_global_index.Finalize(); 2988 m_type_index.Finalize(); 2989 m_namespace_index.Finalize(); 2990 2991 #if defined (ENABLE_DEBUG_PRINTF) 2992 StreamFile s(stdout, false); 2993 s.Printf ("DWARF index for '%s':", 2994 GetObjectFile()->GetFileSpec().GetPath().c_str()); 2995 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); 2996 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); 2997 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); 2998 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); 2999 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); 3000 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); 3001 s.Printf("\nTypes:\n"); m_type_index.Dump (&s); 3002 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); 3003 #endif 3004 } 3005 } 3006 3007 bool 3008 SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) 3009 { 3010 if (namespace_decl == NULL) 3011 { 3012 // Invalid namespace decl which means we aren't matching only things 3013 // in this symbol file, so return true to indicate it matches this 3014 // symbol file. 3015 return true; 3016 } 3017 3018 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); 3019 3020 if (namespace_ast == NULL) 3021 return true; // No AST in the "namespace_decl", return true since it 3022 // could then match any symbol file, including this one 3023 3024 if (namespace_ast == GetClangASTContext().getASTContext()) 3025 return true; // The ASTs match, return true 3026 3027 // The namespace AST was valid, and it does not match... 3028 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3029 3030 if (log) 3031 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); 3032 3033 return false; 3034 } 3035 3036 bool 3037 SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, 3038 DWARFCompileUnit* cu, 3039 const DWARFDebugInfoEntry* die) 3040 { 3041 // No namespace specified, so the answesr i 3042 if (namespace_decl == NULL) 3043 return true; 3044 3045 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3046 3047 const DWARFDebugInfoEntry *decl_ctx_die = NULL; 3048 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); 3049 if (decl_ctx_die) 3050 { 3051 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); 3052 3053 if (clang_namespace_decl) 3054 { 3055 if (decl_ctx_die->Tag() != DW_TAG_namespace) 3056 { 3057 if (log) 3058 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace"); 3059 return false; 3060 } 3061 3062 if (clang_namespace_decl == die_clang_decl_ctx) 3063 return true; 3064 else 3065 return false; 3066 } 3067 else 3068 { 3069 // We have a namespace_decl that was not NULL but it contained 3070 // a NULL "clang::NamespaceDecl", so this means the global namespace 3071 // So as long the the contained decl context DIE isn't a namespace 3072 // we should be ok. 3073 if (decl_ctx_die->Tag() != DW_TAG_namespace) 3074 return true; 3075 } 3076 } 3077 3078 if (log) 3079 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist"); 3080 3081 return false; 3082 } 3083 uint32_t 3084 SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) 3085 { 3086 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3087 3088 if (log) 3089 { 3090 GetObjectFile()->GetModule()->LogMessage (log, 3091 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", 3092 name.GetCString(), 3093 namespace_decl, 3094 append, 3095 max_matches); 3096 } 3097 3098 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) 3099 return 0; 3100 3101 DWARFDebugInfo* info = DebugInfo(); 3102 if (info == NULL) 3103 return 0; 3104 3105 // If we aren't appending the results to this list, then clear the list 3106 if (!append) 3107 variables.Clear(); 3108 3109 // Remember how many variables are in the list before we search in case 3110 // we are appending the results to a variable list. 3111 const uint32_t original_size = variables.GetSize(); 3112 3113 DIEArray die_offsets; 3114 3115 if (m_using_apple_tables) 3116 { 3117 if (m_apple_names_ap.get()) 3118 { 3119 const char *name_cstr = name.GetCString(); 3120 const char *base_name_start; 3121 const char *base_name_end = NULL; 3122 3123 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end)) 3124 base_name_start = name_cstr; 3125 3126 m_apple_names_ap->FindByName (base_name_start, die_offsets); 3127 } 3128 } 3129 else 3130 { 3131 // Index the DWARF if we haven't already 3132 if (!m_indexed) 3133 Index (); 3134 3135 m_global_index.Find (name, die_offsets); 3136 } 3137 3138 const size_t num_die_matches = die_offsets.size(); 3139 if (num_die_matches) 3140 { 3141 SymbolContext sc; 3142 sc.module_sp = m_obj_file->GetModule(); 3143 assert (sc.module_sp); 3144 3145 DWARFDebugInfo* debug_info = DebugInfo(); 3146 DWARFCompileUnit* dwarf_cu = NULL; 3147 const DWARFDebugInfoEntry* die = NULL; 3148 bool done = false; 3149 for (size_t i=0; i<num_die_matches && !done; ++i) 3150 { 3151 const dw_offset_t die_offset = die_offsets[i]; 3152 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3153 3154 if (die) 3155 { 3156 switch (die->Tag()) 3157 { 3158 default: 3159 case DW_TAG_subprogram: 3160 case DW_TAG_inlined_subroutine: 3161 case DW_TAG_try_block: 3162 case DW_TAG_catch_block: 3163 break; 3164 3165 case DW_TAG_variable: 3166 { 3167 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 3168 3169 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3170 continue; 3171 3172 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); 3173 3174 if (variables.GetSize() - original_size >= max_matches) 3175 done = true; 3176 } 3177 break; 3178 } 3179 } 3180 else 3181 { 3182 if (m_using_apple_tables) 3183 { 3184 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", 3185 die_offset, name.GetCString()); 3186 } 3187 } 3188 } 3189 } 3190 3191 // Return the number of variable that were appended to the list 3192 const uint32_t num_matches = variables.GetSize() - original_size; 3193 if (log && num_matches > 0) 3194 { 3195 GetObjectFile()->GetModule()->LogMessage (log, 3196 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", 3197 name.GetCString(), 3198 namespace_decl, 3199 append, 3200 max_matches, 3201 num_matches); 3202 } 3203 return num_matches; 3204 } 3205 3206 uint32_t 3207 SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) 3208 { 3209 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3210 3211 if (log) 3212 { 3213 GetObjectFile()->GetModule()->LogMessage (log, 3214 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", 3215 regex.GetText(), 3216 append, 3217 max_matches); 3218 } 3219 3220 DWARFDebugInfo* info = DebugInfo(); 3221 if (info == NULL) 3222 return 0; 3223 3224 // If we aren't appending the results to this list, then clear the list 3225 if (!append) 3226 variables.Clear(); 3227 3228 // Remember how many variables are in the list before we search in case 3229 // we are appending the results to a variable list. 3230 const uint32_t original_size = variables.GetSize(); 3231 3232 DIEArray die_offsets; 3233 3234 if (m_using_apple_tables) 3235 { 3236 if (m_apple_names_ap.get()) 3237 { 3238 DWARFMappedHash::DIEInfoArray hash_data_array; 3239 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) 3240 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); 3241 } 3242 } 3243 else 3244 { 3245 // Index the DWARF if we haven't already 3246 if (!m_indexed) 3247 Index (); 3248 3249 m_global_index.Find (regex, die_offsets); 3250 } 3251 3252 SymbolContext sc; 3253 sc.module_sp = m_obj_file->GetModule(); 3254 assert (sc.module_sp); 3255 3256 DWARFCompileUnit* dwarf_cu = NULL; 3257 const DWARFDebugInfoEntry* die = NULL; 3258 const size_t num_matches = die_offsets.size(); 3259 if (num_matches) 3260 { 3261 DWARFDebugInfo* debug_info = DebugInfo(); 3262 for (size_t i=0; i<num_matches; ++i) 3263 { 3264 const dw_offset_t die_offset = die_offsets[i]; 3265 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3266 3267 if (die) 3268 { 3269 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 3270 3271 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); 3272 3273 if (variables.GetSize() - original_size >= max_matches) 3274 break; 3275 } 3276 else 3277 { 3278 if (m_using_apple_tables) 3279 { 3280 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", 3281 die_offset, regex.GetText()); 3282 } 3283 } 3284 } 3285 } 3286 3287 // Return the number of variable that were appended to the list 3288 return variables.GetSize() - original_size; 3289 } 3290 3291 3292 bool 3293 SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, 3294 DWARFCompileUnit *&dwarf_cu, 3295 SymbolContextList& sc_list) 3296 { 3297 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3298 return ResolveFunction (dwarf_cu, die, sc_list); 3299 } 3300 3301 3302 bool 3303 SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, 3304 const DWARFDebugInfoEntry *die, 3305 SymbolContextList& sc_list) 3306 { 3307 SymbolContext sc; 3308 3309 if (die == NULL) 3310 return false; 3311 3312 // If we were passed a die that is not a function, just return false... 3313 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine) 3314 return false; 3315 3316 const DWARFDebugInfoEntry* inlined_die = NULL; 3317 if (die->Tag() == DW_TAG_inlined_subroutine) 3318 { 3319 inlined_die = die; 3320 3321 while ((die = die->GetParent()) != NULL) 3322 { 3323 if (die->Tag() == DW_TAG_subprogram) 3324 break; 3325 } 3326 } 3327 assert (die->Tag() == DW_TAG_subprogram); 3328 if (GetFunction (cu, die, sc)) 3329 { 3330 Address addr; 3331 // Parse all blocks if needed 3332 if (inlined_die) 3333 { 3334 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset())); 3335 assert (sc.block != NULL); 3336 if (sc.block->GetStartAddress (addr) == false) 3337 addr.Clear(); 3338 } 3339 else 3340 { 3341 sc.block = NULL; 3342 addr = sc.function->GetAddressRange().GetBaseAddress(); 3343 } 3344 3345 if (addr.IsValid()) 3346 { 3347 sc_list.Append(sc); 3348 return true; 3349 } 3350 } 3351 3352 return false; 3353 } 3354 3355 void 3356 SymbolFileDWARF::FindFunctions (const ConstString &name, 3357 const NameToDIE &name_to_die, 3358 SymbolContextList& sc_list) 3359 { 3360 DIEArray die_offsets; 3361 if (name_to_die.Find (name, die_offsets)) 3362 { 3363 ParseFunctions (die_offsets, sc_list); 3364 } 3365 } 3366 3367 3368 void 3369 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, 3370 const NameToDIE &name_to_die, 3371 SymbolContextList& sc_list) 3372 { 3373 DIEArray die_offsets; 3374 if (name_to_die.Find (regex, die_offsets)) 3375 { 3376 ParseFunctions (die_offsets, sc_list); 3377 } 3378 } 3379 3380 3381 void 3382 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, 3383 const DWARFMappedHash::MemoryTable &memory_table, 3384 SymbolContextList& sc_list) 3385 { 3386 DIEArray die_offsets; 3387 DWARFMappedHash::DIEInfoArray hash_data_array; 3388 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) 3389 { 3390 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); 3391 ParseFunctions (die_offsets, sc_list); 3392 } 3393 } 3394 3395 void 3396 SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, 3397 SymbolContextList& sc_list) 3398 { 3399 const size_t num_matches = die_offsets.size(); 3400 if (num_matches) 3401 { 3402 SymbolContext sc; 3403 3404 DWARFCompileUnit* dwarf_cu = NULL; 3405 for (size_t i=0; i<num_matches; ++i) 3406 { 3407 const dw_offset_t die_offset = die_offsets[i]; 3408 ResolveFunction (die_offset, dwarf_cu, sc_list); 3409 } 3410 } 3411 } 3412 3413 bool 3414 SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, 3415 const DWARFCompileUnit *dwarf_cu, 3416 uint32_t name_type_mask, 3417 const char *partial_name, 3418 const char *base_name_start, 3419 const char *base_name_end) 3420 { 3421 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: 3422 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) 3423 { 3424 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); 3425 if (!containing_decl_ctx) 3426 return false; 3427 3428 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); 3429 3430 if (name_type_mask == eFunctionNameTypeMethod) 3431 { 3432 if (is_cxx_method == false) 3433 return false; 3434 } 3435 3436 if (name_type_mask == eFunctionNameTypeBase) 3437 { 3438 if (is_cxx_method == true) 3439 return false; 3440 } 3441 } 3442 3443 // Now we need to check whether the name we got back for this type matches the extra specifications 3444 // that were in the name we're looking up: 3445 if (base_name_start != partial_name || *base_name_end != '\0') 3446 { 3447 // First see if the stuff to the left matches the full name. To do that let's see if 3448 // we can pull out the mips linkage name attribute: 3449 3450 Mangled best_name; 3451 DWARFDebugInfoEntry::Attributes attributes; 3452 DWARFFormValue form_value; 3453 die->GetAttributes(this, dwarf_cu, NULL, attributes); 3454 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); 3455 if (idx == UINT32_MAX) 3456 idx = attributes.FindAttributeIndex(DW_AT_linkage_name); 3457 if (idx != UINT32_MAX) 3458 { 3459 if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) 3460 { 3461 const char *mangled_name = form_value.AsCString(&get_debug_str_data()); 3462 if (mangled_name) 3463 best_name.SetValue (ConstString(mangled_name), true); 3464 } 3465 } 3466 3467 if (!best_name) 3468 { 3469 idx = attributes.FindAttributeIndex(DW_AT_name); 3470 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) 3471 { 3472 const char *name = form_value.AsCString(&get_debug_str_data()); 3473 best_name.SetValue (ConstString(name), false); 3474 } 3475 } 3476 3477 if (best_name.GetDemangledName()) 3478 { 3479 const char *demangled = best_name.GetDemangledName().GetCString(); 3480 if (demangled) 3481 { 3482 std::string name_no_parens(partial_name, base_name_end - partial_name); 3483 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); 3484 if (partial_in_demangled == NULL) 3485 return false; 3486 else 3487 { 3488 // Sort out the case where our name is something like "Process::Destroy" and the match is 3489 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on 3490 // namespace boundaries... 3491 3492 if (partial_name[0] == ':' && partial_name[1] == ':') 3493 { 3494 // The partial name was already on a namespace boundary so all matches are good. 3495 return true; 3496 } 3497 else if (partial_in_demangled == demangled) 3498 { 3499 // They both start the same, so this is an good match. 3500 return true; 3501 } 3502 else 3503 { 3504 if (partial_in_demangled - demangled == 1) 3505 { 3506 // Only one character difference, can't be a namespace boundary... 3507 return false; 3508 } 3509 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') 3510 { 3511 // We are on a namespace boundary, so this is also good. 3512 return true; 3513 } 3514 else 3515 return false; 3516 } 3517 } 3518 } 3519 } 3520 } 3521 3522 return true; 3523 } 3524 3525 uint32_t 3526 SymbolFileDWARF::FindFunctions (const ConstString &name, 3527 const lldb_private::ClangNamespaceDecl *namespace_decl, 3528 uint32_t name_type_mask, 3529 bool include_inlines, 3530 bool append, 3531 SymbolContextList& sc_list) 3532 { 3533 Timer scoped_timer (__PRETTY_FUNCTION__, 3534 "SymbolFileDWARF::FindFunctions (name = '%s')", 3535 name.AsCString()); 3536 3537 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() 3538 assert ((name_type_mask & eFunctionNameTypeAuto) == 0); 3539 3540 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3541 3542 if (log) 3543 { 3544 GetObjectFile()->GetModule()->LogMessage (log, 3545 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", 3546 name.GetCString(), 3547 name_type_mask, 3548 append); 3549 } 3550 3551 // If we aren't appending the results to this list, then clear the list 3552 if (!append) 3553 sc_list.Clear(); 3554 3555 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) 3556 return 0; 3557 3558 // If name is empty then we won't find anything. 3559 if (name.IsEmpty()) 3560 return 0; 3561 3562 // Remember how many sc_list are in the list before we search in case 3563 // we are appending the results to a variable list. 3564 3565 const char *name_cstr = name.GetCString(); 3566 3567 const uint32_t original_size = sc_list.GetSize(); 3568 3569 DWARFDebugInfo* info = DebugInfo(); 3570 if (info == NULL) 3571 return 0; 3572 3573 DWARFCompileUnit *dwarf_cu = NULL; 3574 std::set<const DWARFDebugInfoEntry *> resolved_dies; 3575 if (m_using_apple_tables) 3576 { 3577 if (m_apple_names_ap.get()) 3578 { 3579 3580 DIEArray die_offsets; 3581 3582 uint32_t num_matches = 0; 3583 3584 if (name_type_mask & eFunctionNameTypeFull) 3585 { 3586 // If they asked for the full name, match what they typed. At some point we may 3587 // want to canonicalize this (strip double spaces, etc. For now, we just add all the 3588 // dies that we find by exact match. 3589 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); 3590 for (uint32_t i = 0; i < num_matches; i++) 3591 { 3592 const dw_offset_t die_offset = die_offsets[i]; 3593 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3594 if (die) 3595 { 3596 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3597 continue; 3598 3599 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) 3600 continue; 3601 3602 if (resolved_dies.find(die) == resolved_dies.end()) 3603 { 3604 if (ResolveFunction (dwarf_cu, die, sc_list)) 3605 resolved_dies.insert(die); 3606 } 3607 } 3608 else 3609 { 3610 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", 3611 die_offset, name_cstr); 3612 } 3613 } 3614 } 3615 3616 if (name_type_mask & eFunctionNameTypeSelector) 3617 { 3618 if (namespace_decl && *namespace_decl) 3619 return 0; // no selectors in namespaces 3620 3621 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); 3622 // Now make sure these are actually ObjC methods. In this case we can simply look up the name, 3623 // and if it is an ObjC method name, we're good. 3624 3625 for (uint32_t i = 0; i < num_matches; i++) 3626 { 3627 const dw_offset_t die_offset = die_offsets[i]; 3628 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3629 if (die) 3630 { 3631 const char *die_name = die->GetName(this, dwarf_cu); 3632 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) 3633 { 3634 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) 3635 continue; 3636 3637 if (resolved_dies.find(die) == resolved_dies.end()) 3638 { 3639 if (ResolveFunction (dwarf_cu, die, sc_list)) 3640 resolved_dies.insert(die); 3641 } 3642 } 3643 } 3644 else 3645 { 3646 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", 3647 die_offset, name_cstr); 3648 } 3649 } 3650 die_offsets.clear(); 3651 } 3652 3653 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) 3654 { 3655 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to 3656 // extract the base name, look that up, and if there is any other information in the name we were 3657 // passed in we have to post-filter based on that. 3658 3659 // FIXME: Arrange the logic above so that we don't calculate the base name twice: 3660 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); 3661 3662 for (uint32_t i = 0; i < num_matches; i++) 3663 { 3664 const dw_offset_t die_offset = die_offsets[i]; 3665 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3666 if (die) 3667 { 3668 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) 3669 continue; 3670 3671 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3672 continue; 3673 3674 // If we get to here, the die is good, and we should add it: 3675 if (resolved_dies.find(die) == resolved_dies.end()) 3676 if (ResolveFunction (dwarf_cu, die, sc_list)) 3677 { 3678 bool keep_die = true; 3679 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) 3680 { 3681 // We are looking for either basenames or methods, so we need to 3682 // trim out the ones we won't want by looking at the type 3683 SymbolContext sc; 3684 if (sc_list.GetLastContext(sc)) 3685 { 3686 if (sc.block) 3687 { 3688 // We have an inlined function 3689 } 3690 else if (sc.function) 3691 { 3692 Type *type = sc.function->GetType(); 3693 3694 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); 3695 if (decl_ctx->isRecord()) 3696 { 3697 if (name_type_mask & eFunctionNameTypeBase) 3698 { 3699 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); 3700 keep_die = false; 3701 } 3702 } 3703 else 3704 { 3705 if (name_type_mask & eFunctionNameTypeMethod) 3706 { 3707 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); 3708 keep_die = false; 3709 } 3710 } 3711 } 3712 } 3713 } 3714 if (keep_die) 3715 resolved_dies.insert(die); 3716 } 3717 } 3718 else 3719 { 3720 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", 3721 die_offset, name_cstr); 3722 } 3723 } 3724 die_offsets.clear(); 3725 } 3726 } 3727 } 3728 else 3729 { 3730 3731 // Index the DWARF if we haven't already 3732 if (!m_indexed) 3733 Index (); 3734 3735 if (name_type_mask & eFunctionNameTypeFull) 3736 { 3737 FindFunctions (name, m_function_fullname_index, sc_list); 3738 3739 // Temporary workaround for global/anonymous namespace functions on linux 3740 #if defined (__linux__) 3741 // If we didn't find any functions in the global namespace try 3742 // looking in the basename index but ignore any returned 3743 // functions that have a namespace (ie. mangled names starting with 3744 // '_ZN') but keep functions which have an anonymous namespace 3745 if (sc_list.GetSize() == 0) 3746 { 3747 SymbolContextList temp_sc_list; 3748 FindFunctions (name, m_function_basename_index, temp_sc_list); 3749 if (!namespace_decl) 3750 { 3751 SymbolContext sc; 3752 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) 3753 { 3754 if (temp_sc_list.GetContextAtIndex(i, sc)) 3755 { 3756 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); 3757 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); 3758 if (strncmp(mangled_name.GetCString(), "_ZN", 3) || 3759 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) 3760 { 3761 sc_list.Append(sc); 3762 } 3763 } 3764 } 3765 } 3766 } 3767 #endif 3768 } 3769 DIEArray die_offsets; 3770 DWARFCompileUnit *dwarf_cu = NULL; 3771 3772 if (name_type_mask & eFunctionNameTypeBase) 3773 { 3774 uint32_t num_base = m_function_basename_index.Find(name, die_offsets); 3775 for (uint32_t i = 0; i < num_base; i++) 3776 { 3777 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); 3778 if (die) 3779 { 3780 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) 3781 continue; 3782 3783 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3784 continue; 3785 3786 // If we get to here, the die is good, and we should add it: 3787 if (resolved_dies.find(die) == resolved_dies.end()) 3788 { 3789 if (ResolveFunction (dwarf_cu, die, sc_list)) 3790 resolved_dies.insert(die); 3791 } 3792 } 3793 } 3794 die_offsets.clear(); 3795 } 3796 3797 if (name_type_mask & eFunctionNameTypeMethod) 3798 { 3799 if (namespace_decl && *namespace_decl) 3800 return 0; // no methods in namespaces 3801 3802 uint32_t num_base = m_function_method_index.Find(name, die_offsets); 3803 { 3804 for (uint32_t i = 0; i < num_base; i++) 3805 { 3806 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); 3807 if (die) 3808 { 3809 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine) 3810 continue; 3811 3812 // If we get to here, the die is good, and we should add it: 3813 if (resolved_dies.find(die) == resolved_dies.end()) 3814 { 3815 if (ResolveFunction (dwarf_cu, die, sc_list)) 3816 resolved_dies.insert(die); 3817 } 3818 } 3819 } 3820 } 3821 die_offsets.clear(); 3822 } 3823 3824 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) 3825 { 3826 FindFunctions (name, m_function_selector_index, sc_list); 3827 } 3828 3829 } 3830 3831 // Return the number of variable that were appended to the list 3832 const uint32_t num_matches = sc_list.GetSize() - original_size; 3833 3834 if (log && num_matches > 0) 3835 { 3836 GetObjectFile()->GetModule()->LogMessage (log, 3837 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u", 3838 name.GetCString(), 3839 name_type_mask, 3840 append, 3841 num_matches); 3842 } 3843 return num_matches; 3844 } 3845 3846 uint32_t 3847 SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) 3848 { 3849 Timer scoped_timer (__PRETTY_FUNCTION__, 3850 "SymbolFileDWARF::FindFunctions (regex = '%s')", 3851 regex.GetText()); 3852 3853 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3854 3855 if (log) 3856 { 3857 GetObjectFile()->GetModule()->LogMessage (log, 3858 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", 3859 regex.GetText(), 3860 append); 3861 } 3862 3863 3864 // If we aren't appending the results to this list, then clear the list 3865 if (!append) 3866 sc_list.Clear(); 3867 3868 // Remember how many sc_list are in the list before we search in case 3869 // we are appending the results to a variable list. 3870 uint32_t original_size = sc_list.GetSize(); 3871 3872 if (m_using_apple_tables) 3873 { 3874 if (m_apple_names_ap.get()) 3875 FindFunctions (regex, *m_apple_names_ap, sc_list); 3876 } 3877 else 3878 { 3879 // Index the DWARF if we haven't already 3880 if (!m_indexed) 3881 Index (); 3882 3883 FindFunctions (regex, m_function_basename_index, sc_list); 3884 3885 FindFunctions (regex, m_function_fullname_index, sc_list); 3886 } 3887 3888 // Return the number of variable that were appended to the list 3889 return sc_list.GetSize() - original_size; 3890 } 3891 3892 uint32_t 3893 SymbolFileDWARF::FindTypes (const SymbolContext& sc, 3894 const ConstString &name, 3895 const lldb_private::ClangNamespaceDecl *namespace_decl, 3896 bool append, 3897 uint32_t max_matches, 3898 TypeList& types) 3899 { 3900 DWARFDebugInfo* info = DebugInfo(); 3901 if (info == NULL) 3902 return 0; 3903 3904 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3905 3906 if (log) 3907 { 3908 if (namespace_decl) 3909 { 3910 GetObjectFile()->GetModule()->LogMessage (log, 3911 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", 3912 name.GetCString(), 3913 namespace_decl->GetNamespaceDecl(), 3914 namespace_decl->GetQualifiedName().c_str(), 3915 append, 3916 max_matches); 3917 } 3918 else 3919 { 3920 GetObjectFile()->GetModule()->LogMessage (log, 3921 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", 3922 name.GetCString(), 3923 append, 3924 max_matches); 3925 } 3926 } 3927 3928 // If we aren't appending the results to this list, then clear the list 3929 if (!append) 3930 types.Clear(); 3931 3932 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) 3933 return 0; 3934 3935 DIEArray die_offsets; 3936 3937 if (m_using_apple_tables) 3938 { 3939 if (m_apple_types_ap.get()) 3940 { 3941 const char *name_cstr = name.GetCString(); 3942 m_apple_types_ap->FindByName (name_cstr, die_offsets); 3943 } 3944 } 3945 else 3946 { 3947 if (!m_indexed) 3948 Index (); 3949 3950 m_type_index.Find (name, die_offsets); 3951 } 3952 3953 const size_t num_die_matches = die_offsets.size(); 3954 3955 if (num_die_matches) 3956 { 3957 const uint32_t initial_types_size = types.GetSize(); 3958 DWARFCompileUnit* dwarf_cu = NULL; 3959 const DWARFDebugInfoEntry* die = NULL; 3960 DWARFDebugInfo* debug_info = DebugInfo(); 3961 for (size_t i=0; i<num_die_matches; ++i) 3962 { 3963 const dw_offset_t die_offset = die_offsets[i]; 3964 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3965 3966 if (die) 3967 { 3968 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3969 continue; 3970 3971 Type *matching_type = ResolveType (dwarf_cu, die); 3972 if (matching_type) 3973 { 3974 // We found a type pointer, now find the shared pointer form our type list 3975 types.InsertUnique (matching_type->shared_from_this()); 3976 if (types.GetSize() >= max_matches) 3977 break; 3978 } 3979 } 3980 else 3981 { 3982 if (m_using_apple_tables) 3983 { 3984 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", 3985 die_offset, name.GetCString()); 3986 } 3987 } 3988 3989 } 3990 const uint32_t num_matches = types.GetSize() - initial_types_size; 3991 if (log && num_matches) 3992 { 3993 if (namespace_decl) 3994 { 3995 GetObjectFile()->GetModule()->LogMessage (log, 3996 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", 3997 name.GetCString(), 3998 namespace_decl->GetNamespaceDecl(), 3999 namespace_decl->GetQualifiedName().c_str(), 4000 append, 4001 max_matches, 4002 num_matches); 4003 } 4004 else 4005 { 4006 GetObjectFile()->GetModule()->LogMessage (log, 4007 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", 4008 name.GetCString(), 4009 append, 4010 max_matches, 4011 num_matches); 4012 } 4013 } 4014 return num_matches; 4015 } 4016 return 0; 4017 } 4018 4019 4020 ClangNamespaceDecl 4021 SymbolFileDWARF::FindNamespace (const SymbolContext& sc, 4022 const ConstString &name, 4023 const lldb_private::ClangNamespaceDecl *parent_namespace_decl) 4024 { 4025 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 4026 4027 if (log) 4028 { 4029 GetObjectFile()->GetModule()->LogMessage (log, 4030 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", 4031 name.GetCString()); 4032 } 4033 4034 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) 4035 return ClangNamespaceDecl(); 4036 4037 ClangNamespaceDecl namespace_decl; 4038 DWARFDebugInfo* info = DebugInfo(); 4039 if (info) 4040 { 4041 DIEArray die_offsets; 4042 4043 // Index if we already haven't to make sure the compile units 4044 // get indexed and make their global DIE index list 4045 if (m_using_apple_tables) 4046 { 4047 if (m_apple_namespaces_ap.get()) 4048 { 4049 const char *name_cstr = name.GetCString(); 4050 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); 4051 } 4052 } 4053 else 4054 { 4055 if (!m_indexed) 4056 Index (); 4057 4058 m_namespace_index.Find (name, die_offsets); 4059 } 4060 4061 DWARFCompileUnit* dwarf_cu = NULL; 4062 const DWARFDebugInfoEntry* die = NULL; 4063 const size_t num_matches = die_offsets.size(); 4064 if (num_matches) 4065 { 4066 DWARFDebugInfo* debug_info = DebugInfo(); 4067 for (size_t i=0; i<num_matches; ++i) 4068 { 4069 const dw_offset_t die_offset = die_offsets[i]; 4070 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 4071 4072 if (die) 4073 { 4074 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) 4075 continue; 4076 4077 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); 4078 if (clang_namespace_decl) 4079 { 4080 namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); 4081 namespace_decl.SetNamespaceDecl (clang_namespace_decl); 4082 break; 4083 } 4084 } 4085 else 4086 { 4087 if (m_using_apple_tables) 4088 { 4089 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", 4090 die_offset, name.GetCString()); 4091 } 4092 } 4093 4094 } 4095 } 4096 } 4097 if (log && namespace_decl.GetNamespaceDecl()) 4098 { 4099 GetObjectFile()->GetModule()->LogMessage (log, 4100 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", 4101 name.GetCString(), 4102 namespace_decl.GetNamespaceDecl(), 4103 namespace_decl.GetQualifiedName().c_str()); 4104 } 4105 4106 return namespace_decl; 4107 } 4108 4109 uint32_t 4110 SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) 4111 { 4112 // Remember how many sc_list are in the list before we search in case 4113 // we are appending the results to a variable list. 4114 uint32_t original_size = types.GetSize(); 4115 4116 const uint32_t num_die_offsets = die_offsets.size(); 4117 // Parse all of the types we found from the pubtypes matches 4118 uint32_t i; 4119 uint32_t num_matches = 0; 4120 for (i = 0; i < num_die_offsets; ++i) 4121 { 4122 Type *matching_type = ResolveTypeUID (die_offsets[i]); 4123 if (matching_type) 4124 { 4125 // We found a type pointer, now find the shared pointer form our type list 4126 types.InsertUnique (matching_type->shared_from_this()); 4127 ++num_matches; 4128 if (num_matches >= max_matches) 4129 break; 4130 } 4131 } 4132 4133 // Return the number of variable that were appended to the list 4134 return types.GetSize() - original_size; 4135 } 4136 4137 4138 size_t 4139 SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, 4140 clang::DeclContext *containing_decl_ctx, 4141 DWARFCompileUnit* dwarf_cu, 4142 const DWARFDebugInfoEntry *parent_die, 4143 bool skip_artificial, 4144 bool &is_static, 4145 TypeList* type_list, 4146 std::vector<ClangASTType>& function_param_types, 4147 std::vector<clang::ParmVarDecl*>& function_param_decls, 4148 unsigned &type_quals, 4149 ClangASTContext::TemplateParameterInfos &template_param_infos) 4150 { 4151 if (parent_die == NULL) 4152 return 0; 4153 4154 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 4155 4156 size_t arg_idx = 0; 4157 const DWARFDebugInfoEntry *die; 4158 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 4159 { 4160 dw_tag_t tag = die->Tag(); 4161 switch (tag) 4162 { 4163 case DW_TAG_formal_parameter: 4164 { 4165 DWARFDebugInfoEntry::Attributes attributes; 4166 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 4167 if (num_attributes > 0) 4168 { 4169 const char *name = NULL; 4170 Declaration decl; 4171 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; 4172 bool is_artificial = false; 4173 // one of None, Auto, Register, Extern, Static, PrivateExtern 4174 4175 clang::StorageClass storage = clang::SC_None; 4176 uint32_t i; 4177 for (i=0; i<num_attributes; ++i) 4178 { 4179 const dw_attr_t attr = attributes.AttributeAtIndex(i); 4180 DWARFFormValue form_value; 4181 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 4182 { 4183 switch (attr) 4184 { 4185 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 4186 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 4187 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 4188 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 4189 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; 4190 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 4191 case DW_AT_location: 4192 // if (form_value.BlockData()) 4193 // { 4194 // const DataExtractor& debug_info_data = debug_info(); 4195 // uint32_t block_length = form_value.Unsigned(); 4196 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); 4197 // } 4198 // else 4199 // { 4200 // } 4201 // break; 4202 case DW_AT_const_value: 4203 case DW_AT_default_value: 4204 case DW_AT_description: 4205 case DW_AT_endianity: 4206 case DW_AT_is_optional: 4207 case DW_AT_segment: 4208 case DW_AT_variable_parameter: 4209 default: 4210 case DW_AT_abstract_origin: 4211 case DW_AT_sibling: 4212 break; 4213 } 4214 } 4215 } 4216 4217 bool skip = false; 4218 if (skip_artificial) 4219 { 4220 if (is_artificial) 4221 { 4222 // In order to determine if a C++ member function is 4223 // "const" we have to look at the const-ness of "this"... 4224 // Ugly, but that 4225 if (arg_idx == 0) 4226 { 4227 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) 4228 { 4229 // Often times compilers omit the "this" name for the 4230 // specification DIEs, so we can't rely upon the name 4231 // being in the formal parameter DIE... 4232 if (name == NULL || ::strcmp(name, "this")==0) 4233 { 4234 Type *this_type = ResolveTypeUID (param_type_die_offset); 4235 if (this_type) 4236 { 4237 uint32_t encoding_mask = this_type->GetEncodingMask(); 4238 if (encoding_mask & Type::eEncodingIsPointerUID) 4239 { 4240 is_static = false; 4241 4242 if (encoding_mask & (1u << Type::eEncodingIsConstUID)) 4243 type_quals |= clang::Qualifiers::Const; 4244 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) 4245 type_quals |= clang::Qualifiers::Volatile; 4246 } 4247 } 4248 } 4249 } 4250 } 4251 skip = true; 4252 } 4253 else 4254 { 4255 4256 // HACK: Objective C formal parameters "self" and "_cmd" 4257 // are not marked as artificial in the DWARF... 4258 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 4259 if (comp_unit) 4260 { 4261 switch (comp_unit->GetLanguage()) 4262 { 4263 case eLanguageTypeObjC: 4264 case eLanguageTypeObjC_plus_plus: 4265 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) 4266 skip = true; 4267 break; 4268 default: 4269 break; 4270 } 4271 } 4272 } 4273 } 4274 4275 if (!skip) 4276 { 4277 Type *type = ResolveTypeUID(param_type_die_offset); 4278 if (type) 4279 { 4280 function_param_types.push_back (type->GetClangForwardType()); 4281 4282 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, 4283 type->GetClangForwardType(), 4284 storage); 4285 assert(param_var_decl); 4286 function_param_decls.push_back(param_var_decl); 4287 4288 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); 4289 } 4290 } 4291 } 4292 arg_idx++; 4293 } 4294 break; 4295 4296 case DW_TAG_template_type_parameter: 4297 case DW_TAG_template_value_parameter: 4298 ParseTemplateDIE (dwarf_cu, die,template_param_infos); 4299 break; 4300 4301 default: 4302 break; 4303 } 4304 } 4305 return arg_idx; 4306 } 4307 4308 size_t 4309 SymbolFileDWARF::ParseChildEnumerators 4310 ( 4311 const SymbolContext& sc, 4312 lldb_private::ClangASTType &clang_type, 4313 bool is_signed, 4314 uint32_t enumerator_byte_size, 4315 DWARFCompileUnit* dwarf_cu, 4316 const DWARFDebugInfoEntry *parent_die 4317 ) 4318 { 4319 if (parent_die == NULL) 4320 return 0; 4321 4322 size_t enumerators_added = 0; 4323 const DWARFDebugInfoEntry *die; 4324 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 4325 4326 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 4327 { 4328 const dw_tag_t tag = die->Tag(); 4329 if (tag == DW_TAG_enumerator) 4330 { 4331 DWARFDebugInfoEntry::Attributes attributes; 4332 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 4333 if (num_child_attributes > 0) 4334 { 4335 const char *name = NULL; 4336 bool got_value = false; 4337 int64_t enum_value = 0; 4338 Declaration decl; 4339 4340 uint32_t i; 4341 for (i=0; i<num_child_attributes; ++i) 4342 { 4343 const dw_attr_t attr = attributes.AttributeAtIndex(i); 4344 DWARFFormValue form_value; 4345 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 4346 { 4347 switch (attr) 4348 { 4349 case DW_AT_const_value: 4350 got_value = true; 4351 if (is_signed) 4352 enum_value = form_value.Signed(); 4353 else 4354 enum_value = form_value.Unsigned(); 4355 break; 4356 4357 case DW_AT_name: 4358 name = form_value.AsCString(&get_debug_str_data()); 4359 break; 4360 4361 case DW_AT_description: 4362 default: 4363 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 4364 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 4365 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 4366 case DW_AT_sibling: 4367 break; 4368 } 4369 } 4370 } 4371 4372 if (name && name[0] && got_value) 4373 { 4374 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), 4375 decl, 4376 name, 4377 enum_value, 4378 enumerator_byte_size * 8); 4379 ++enumerators_added; 4380 } 4381 } 4382 } 4383 } 4384 return enumerators_added; 4385 } 4386 4387 void 4388 SymbolFileDWARF::ParseChildArrayInfo 4389 ( 4390 const SymbolContext& sc, 4391 DWARFCompileUnit* dwarf_cu, 4392 const DWARFDebugInfoEntry *parent_die, 4393 int64_t& first_index, 4394 std::vector<uint64_t>& element_orders, 4395 uint32_t& byte_stride, 4396 uint32_t& bit_stride 4397 ) 4398 { 4399 if (parent_die == NULL) 4400 return; 4401 4402 const DWARFDebugInfoEntry *die; 4403 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 4404 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 4405 { 4406 const dw_tag_t tag = die->Tag(); 4407 switch (tag) 4408 { 4409 case DW_TAG_subrange_type: 4410 { 4411 DWARFDebugInfoEntry::Attributes attributes; 4412 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 4413 if (num_child_attributes > 0) 4414 { 4415 uint64_t num_elements = 0; 4416 uint64_t lower_bound = 0; 4417 uint64_t upper_bound = 0; 4418 bool upper_bound_valid = false; 4419 uint32_t i; 4420 for (i=0; i<num_child_attributes; ++i) 4421 { 4422 const dw_attr_t attr = attributes.AttributeAtIndex(i); 4423 DWARFFormValue form_value; 4424 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 4425 { 4426 switch (attr) 4427 { 4428 case DW_AT_name: 4429 break; 4430 4431 case DW_AT_count: 4432 num_elements = form_value.Unsigned(); 4433 break; 4434 4435 case DW_AT_bit_stride: 4436 bit_stride = form_value.Unsigned(); 4437 break; 4438 4439 case DW_AT_byte_stride: 4440 byte_stride = form_value.Unsigned(); 4441 break; 4442 4443 case DW_AT_lower_bound: 4444 lower_bound = form_value.Unsigned(); 4445 break; 4446 4447 case DW_AT_upper_bound: 4448 upper_bound_valid = true; 4449 upper_bound = form_value.Unsigned(); 4450 break; 4451 4452 default: 4453 case DW_AT_abstract_origin: 4454 case DW_AT_accessibility: 4455 case DW_AT_allocated: 4456 case DW_AT_associated: 4457 case DW_AT_data_location: 4458 case DW_AT_declaration: 4459 case DW_AT_description: 4460 case DW_AT_sibling: 4461 case DW_AT_threads_scaled: 4462 case DW_AT_type: 4463 case DW_AT_visibility: 4464 break; 4465 } 4466 } 4467 } 4468 4469 if (num_elements == 0) 4470 { 4471 if (upper_bound_valid && upper_bound >= lower_bound) 4472 num_elements = upper_bound - lower_bound + 1; 4473 } 4474 4475 element_orders.push_back (num_elements); 4476 } 4477 } 4478 break; 4479 } 4480 } 4481 } 4482 4483 TypeSP 4484 SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) 4485 { 4486 TypeSP type_sp; 4487 if (die != NULL) 4488 { 4489 assert(dwarf_cu != NULL); 4490 Type *type_ptr = m_die_to_type.lookup (die); 4491 if (type_ptr == NULL) 4492 { 4493 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); 4494 assert (lldb_cu); 4495 SymbolContext sc(lldb_cu); 4496 type_sp = ParseType(sc, dwarf_cu, die, NULL); 4497 } 4498 else if (type_ptr != DIE_IS_BEING_PARSED) 4499 { 4500 // Grab the existing type from the master types lists 4501 type_sp = type_ptr->shared_from_this(); 4502 } 4503 4504 } 4505 return type_sp; 4506 } 4507 4508 clang::DeclContext * 4509 SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) 4510 { 4511 if (die_offset != DW_INVALID_OFFSET) 4512 { 4513 DWARFCompileUnitSP cu_sp; 4514 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); 4515 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); 4516 } 4517 return NULL; 4518 } 4519 4520 clang::DeclContext * 4521 SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) 4522 { 4523 if (die_offset != DW_INVALID_OFFSET) 4524 { 4525 DWARFDebugInfo* debug_info = DebugInfo(); 4526 if (debug_info) 4527 { 4528 DWARFCompileUnitSP cu_sp; 4529 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); 4530 if (die) 4531 return GetClangDeclContextForDIE (sc, cu_sp.get(), die); 4532 } 4533 } 4534 return NULL; 4535 } 4536 4537 clang::NamespaceDecl * 4538 SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) 4539 { 4540 if (die && die->Tag() == DW_TAG_namespace) 4541 { 4542 // See if we already parsed this namespace DIE and associated it with a 4543 // uniqued namespace declaration 4544 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); 4545 if (namespace_decl) 4546 return namespace_decl; 4547 else 4548 { 4549 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); 4550 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); 4551 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); 4552 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 4553 if (log) 4554 { 4555 if (namespace_name) 4556 { 4557 GetObjectFile()->GetModule()->LogMessage (log, 4558 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", 4559 GetClangASTContext().getASTContext(), 4560 MakeUserID(die->GetOffset()), 4561 namespace_name, 4562 namespace_decl, 4563 namespace_decl->getOriginalNamespace()); 4564 } 4565 else 4566 { 4567 GetObjectFile()->GetModule()->LogMessage (log, 4568 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", 4569 GetClangASTContext().getASTContext(), 4570 MakeUserID(die->GetOffset()), 4571 namespace_decl, 4572 namespace_decl->getOriginalNamespace()); 4573 } 4574 } 4575 4576 if (namespace_decl) 4577 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); 4578 return namespace_decl; 4579 } 4580 } 4581 return NULL; 4582 } 4583 4584 clang::DeclContext * 4585 SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 4586 { 4587 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); 4588 if (clang_decl_ctx) 4589 return clang_decl_ctx; 4590 // If this DIE has a specification, or an abstract origin, then trace to those. 4591 4592 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); 4593 if (die_offset != DW_INVALID_OFFSET) 4594 return GetClangDeclContextForDIEOffset (sc, die_offset); 4595 4596 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); 4597 if (die_offset != DW_INVALID_OFFSET) 4598 return GetClangDeclContextForDIEOffset (sc, die_offset); 4599 4600 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 4601 if (log) 4602 GetObjectFile()->GetModule()->LogMessage(log, "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu)); 4603 // This is the DIE we want. Parse it, then query our map. 4604 bool assert_not_being_parsed = true; 4605 ResolveTypeUID (cu, die, assert_not_being_parsed); 4606 4607 clang_decl_ctx = GetCachedClangDeclContextForDIE (die); 4608 4609 return clang_decl_ctx; 4610 } 4611 4612 clang::DeclContext * 4613 SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy) 4614 { 4615 if (m_clang_tu_decl == NULL) 4616 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); 4617 4618 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); 4619 4620 if (decl_ctx_die_copy) 4621 *decl_ctx_die_copy = decl_ctx_die; 4622 4623 if (decl_ctx_die) 4624 { 4625 4626 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); 4627 if (pos != m_die_to_decl_ctx.end()) 4628 return pos->second; 4629 4630 switch (decl_ctx_die->Tag()) 4631 { 4632 case DW_TAG_compile_unit: 4633 return m_clang_tu_decl; 4634 4635 case DW_TAG_namespace: 4636 return ResolveNamespaceDIE (cu, decl_ctx_die); 4637 break; 4638 4639 case DW_TAG_structure_type: 4640 case DW_TAG_union_type: 4641 case DW_TAG_class_type: 4642 { 4643 Type* type = ResolveType (cu, decl_ctx_die); 4644 if (type) 4645 { 4646 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); 4647 if (decl_ctx) 4648 { 4649 LinkDeclContextToDIE (decl_ctx, decl_ctx_die); 4650 if (decl_ctx) 4651 return decl_ctx; 4652 } 4653 } 4654 } 4655 break; 4656 4657 default: 4658 break; 4659 } 4660 } 4661 return m_clang_tu_decl; 4662 } 4663 4664 4665 const DWARFDebugInfoEntry * 4666 SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 4667 { 4668 if (cu && die) 4669 { 4670 const DWARFDebugInfoEntry * const decl_die = die; 4671 4672 while (die != NULL) 4673 { 4674 // If this is the original DIE that we are searching for a declaration 4675 // for, then don't look in the cache as we don't want our own decl 4676 // context to be our decl context... 4677 if (decl_die != die) 4678 { 4679 switch (die->Tag()) 4680 { 4681 case DW_TAG_compile_unit: 4682 case DW_TAG_namespace: 4683 case DW_TAG_structure_type: 4684 case DW_TAG_union_type: 4685 case DW_TAG_class_type: 4686 return die; 4687 4688 default: 4689 break; 4690 } 4691 } 4692 4693 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); 4694 if (die_offset != DW_INVALID_OFFSET) 4695 { 4696 DWARFCompileUnit *spec_cu = cu; 4697 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); 4698 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); 4699 if (spec_die_decl_ctx_die) 4700 return spec_die_decl_ctx_die; 4701 } 4702 4703 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); 4704 if (die_offset != DW_INVALID_OFFSET) 4705 { 4706 DWARFCompileUnit *abs_cu = cu; 4707 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); 4708 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); 4709 if (abs_die_decl_ctx_die) 4710 return abs_die_decl_ctx_die; 4711 } 4712 4713 die = die->GetParent(); 4714 } 4715 } 4716 return NULL; 4717 } 4718 4719 4720 Symbol * 4721 SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) 4722 { 4723 Symbol *objc_class_symbol = NULL; 4724 if (m_obj_file) 4725 { 4726 Symtab *symtab = m_obj_file->GetSymtab (); 4727 if (symtab) 4728 { 4729 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, 4730 eSymbolTypeObjCClass, 4731 Symtab::eDebugNo, 4732 Symtab::eVisibilityAny); 4733 } 4734 } 4735 return objc_class_symbol; 4736 } 4737 4738 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't 4739 // then we can end up looking through all class types for a complete type and never find 4740 // the full definition. We need to know if this attribute is supported, so we determine 4741 // this here and cache th result. We also need to worry about the debug map DWARF file 4742 // if we are doing darwin DWARF in .o file debugging. 4743 bool 4744 SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) 4745 { 4746 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) 4747 { 4748 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; 4749 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) 4750 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; 4751 else 4752 { 4753 DWARFDebugInfo* debug_info = DebugInfo(); 4754 const uint32_t num_compile_units = GetNumCompileUnits(); 4755 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) 4756 { 4757 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); 4758 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) 4759 { 4760 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; 4761 break; 4762 } 4763 } 4764 } 4765 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) 4766 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); 4767 } 4768 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; 4769 } 4770 4771 // This function can be used when a DIE is found that is a forward declaration 4772 // DIE and we want to try and find a type that has the complete definition. 4773 TypeSP 4774 SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, 4775 const ConstString &type_name, 4776 bool must_be_implementation) 4777 { 4778 4779 TypeSP type_sp; 4780 4781 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) 4782 return type_sp; 4783 4784 DIEArray die_offsets; 4785 4786 if (m_using_apple_tables) 4787 { 4788 if (m_apple_types_ap.get()) 4789 { 4790 const char *name_cstr = type_name.GetCString(); 4791 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); 4792 } 4793 } 4794 else 4795 { 4796 if (!m_indexed) 4797 Index (); 4798 4799 m_type_index.Find (type_name, die_offsets); 4800 } 4801 4802 const size_t num_matches = die_offsets.size(); 4803 4804 DWARFCompileUnit* type_cu = NULL; 4805 const DWARFDebugInfoEntry* type_die = NULL; 4806 if (num_matches) 4807 { 4808 DWARFDebugInfo* debug_info = DebugInfo(); 4809 for (size_t i=0; i<num_matches; ++i) 4810 { 4811 const dw_offset_t die_offset = die_offsets[i]; 4812 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); 4813 4814 if (type_die) 4815 { 4816 bool try_resolving_type = false; 4817 4818 // Don't try and resolve the DIE we are looking for with the DIE itself! 4819 if (type_die != die) 4820 { 4821 switch (type_die->Tag()) 4822 { 4823 case DW_TAG_class_type: 4824 case DW_TAG_structure_type: 4825 try_resolving_type = true; 4826 break; 4827 default: 4828 break; 4829 } 4830 } 4831 4832 if (try_resolving_type) 4833 { 4834 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) 4835 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); 4836 4837 if (try_resolving_type) 4838 { 4839 Type *resolved_type = ResolveType (type_cu, type_die, false); 4840 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) 4841 { 4842 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", 4843 MakeUserID(die->GetOffset()), 4844 MakeUserID(dwarf_cu->GetOffset()), 4845 m_obj_file->GetFileSpec().GetFilename().AsCString(), 4846 MakeUserID(type_die->GetOffset()), 4847 MakeUserID(type_cu->GetOffset())); 4848 4849 if (die) 4850 m_die_to_type[die] = resolved_type; 4851 type_sp = resolved_type->shared_from_this(); 4852 break; 4853 } 4854 } 4855 } 4856 } 4857 else 4858 { 4859 if (m_using_apple_tables) 4860 { 4861 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", 4862 die_offset, type_name.GetCString()); 4863 } 4864 } 4865 4866 } 4867 } 4868 return type_sp; 4869 } 4870 4871 4872 //---------------------------------------------------------------------- 4873 // This function helps to ensure that the declaration contexts match for 4874 // two different DIEs. Often times debug information will refer to a 4875 // forward declaration of a type (the equivalent of "struct my_struct;". 4876 // There will often be a declaration of that type elsewhere that has the 4877 // full definition. When we go looking for the full type "my_struct", we 4878 // will find one or more matches in the accelerator tables and we will 4879 // then need to make sure the type was in the same declaration context 4880 // as the original DIE. This function can efficiently compare two DIEs 4881 // and will return true when the declaration context matches, and false 4882 // when they don't. 4883 //---------------------------------------------------------------------- 4884 bool 4885 SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, 4886 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) 4887 { 4888 if (die1 == die2) 4889 return true; 4890 4891 #if defined (LLDB_CONFIGURATION_DEBUG) 4892 // You can't and shouldn't call this function with a compile unit from 4893 // two different SymbolFileDWARF instances. 4894 assert (DebugInfo()->ContainsCompileUnit (cu1)); 4895 assert (DebugInfo()->ContainsCompileUnit (cu2)); 4896 #endif 4897 4898 DWARFDIECollection decl_ctx_1; 4899 DWARFDIECollection decl_ctx_2; 4900 //The declaration DIE stack is a stack of the declaration context 4901 // DIEs all the way back to the compile unit. If a type "T" is 4902 // declared inside a class "B", and class "B" is declared inside 4903 // a class "A" and class "A" is in a namespace "lldb", and the 4904 // namespace is in a compile unit, there will be a stack of DIEs: 4905 // 4906 // [0] DW_TAG_class_type for "B" 4907 // [1] DW_TAG_class_type for "A" 4908 // [2] DW_TAG_namespace for "lldb" 4909 // [3] DW_TAG_compile_unit for the source file. 4910 // 4911 // We grab both contexts and make sure that everything matches 4912 // all the way back to the compiler unit. 4913 4914 // First lets grab the decl contexts for both DIEs 4915 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); 4916 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); 4917 // Make sure the context arrays have the same size, otherwise 4918 // we are done 4919 const size_t count1 = decl_ctx_1.Size(); 4920 const size_t count2 = decl_ctx_2.Size(); 4921 if (count1 != count2) 4922 return false; 4923 4924 // Make sure the DW_TAG values match all the way back up the the 4925 // compile unit. If they don't, then we are done. 4926 const DWARFDebugInfoEntry *decl_ctx_die1; 4927 const DWARFDebugInfoEntry *decl_ctx_die2; 4928 size_t i; 4929 for (i=0; i<count1; i++) 4930 { 4931 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); 4932 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); 4933 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) 4934 return false; 4935 } 4936 #if defined LLDB_CONFIGURATION_DEBUG 4937 4938 // Make sure the top item in the decl context die array is always 4939 // DW_TAG_compile_unit. If it isn't then something went wrong in 4940 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... 4941 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); 4942 4943 #endif 4944 // Always skip the compile unit when comparing by only iterating up to 4945 // "count - 1". Here we compare the names as we go. 4946 for (i=0; i<count1 - 1; i++) 4947 { 4948 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); 4949 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); 4950 const char *name1 = decl_ctx_die1->GetName(this, cu1); 4951 const char *name2 = decl_ctx_die2->GetName(this, cu2); 4952 // If the string was from a DW_FORM_strp, then the pointer will often 4953 // be the same! 4954 if (name1 == name2) 4955 continue; 4956 4957 // Name pointers are not equal, so only compare the strings 4958 // if both are not NULL. 4959 if (name1 && name2) 4960 { 4961 // If the strings don't compare, we are done... 4962 if (strcmp(name1, name2) != 0) 4963 return false; 4964 } 4965 else 4966 { 4967 // One name was NULL while the other wasn't 4968 return false; 4969 } 4970 } 4971 // We made it through all of the checks and the declaration contexts 4972 // are equal. 4973 return true; 4974 } 4975 4976 // This function can be used when a DIE is found that is a forward declaration 4977 // DIE and we want to try and find a type that has the complete definition. 4978 // "cu" and "die" must be from this SymbolFileDWARF 4979 TypeSP 4980 SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu, 4981 const DWARFDebugInfoEntry *die, 4982 const ConstString &type_name) 4983 { 4984 TypeSP type_sp; 4985 4986 #if defined (LLDB_CONFIGURATION_DEBUG) 4987 // You can't and shouldn't call this function with a compile unit from 4988 // another SymbolFileDWARF instance. 4989 assert (DebugInfo()->ContainsCompileUnit (cu)); 4990 #endif 4991 4992 if (cu == NULL || die == NULL || !type_name) 4993 return type_sp; 4994 4995 std::string qualified_name; 4996 4997 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); 4998 if (log) 4999 { 5000 die->GetQualifiedName(this, cu, qualified_name); 5001 GetObjectFile()->GetModule()->LogMessage (log, 5002 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')", 5003 die->GetOffset(), 5004 qualified_name.c_str(), 5005 type_name.GetCString()); 5006 } 5007 5008 DIEArray die_offsets; 5009 5010 if (m_using_apple_tables) 5011 { 5012 if (m_apple_types_ap.get()) 5013 { 5014 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); 5015 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); 5016 if (has_tag && has_qualified_name_hash) 5017 { 5018 if (qualified_name.empty()) 5019 die->GetQualifiedName(this, cu, qualified_name); 5020 5021 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str()); 5022 if (log) 5023 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); 5024 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets); 5025 } 5026 else if (has_tag > 1) 5027 { 5028 if (log) 5029 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); 5030 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets); 5031 } 5032 else 5033 { 5034 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); 5035 } 5036 } 5037 } 5038 else 5039 { 5040 if (!m_indexed) 5041 Index (); 5042 5043 m_type_index.Find (type_name, die_offsets); 5044 } 5045 5046 const size_t num_matches = die_offsets.size(); 5047 5048 const dw_tag_t die_tag = die->Tag(); 5049 5050 DWARFCompileUnit* type_cu = NULL; 5051 const DWARFDebugInfoEntry* type_die = NULL; 5052 if (num_matches) 5053 { 5054 DWARFDebugInfo* debug_info = DebugInfo(); 5055 for (size_t i=0; i<num_matches; ++i) 5056 { 5057 const dw_offset_t die_offset = die_offsets[i]; 5058 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); 5059 5060 if (type_die) 5061 { 5062 bool try_resolving_type = false; 5063 5064 // Don't try and resolve the DIE we are looking for with the DIE itself! 5065 if (type_die != die) 5066 { 5067 const dw_tag_t type_die_tag = type_die->Tag(); 5068 // Make sure the tags match 5069 if (type_die_tag == die_tag) 5070 { 5071 // The tags match, lets try resolving this type 5072 try_resolving_type = true; 5073 } 5074 else 5075 { 5076 // The tags don't match, but we need to watch our for a 5077 // forward declaration for a struct and ("struct foo") 5078 // ends up being a class ("class foo { ... };") or 5079 // vice versa. 5080 switch (type_die_tag) 5081 { 5082 case DW_TAG_class_type: 5083 // We had a "class foo", see if we ended up with a "struct foo { ... };" 5084 try_resolving_type = (die_tag == DW_TAG_structure_type); 5085 break; 5086 case DW_TAG_structure_type: 5087 // We had a "struct foo", see if we ended up with a "class foo { ... };" 5088 try_resolving_type = (die_tag == DW_TAG_class_type); 5089 break; 5090 default: 5091 // Tags don't match, don't event try to resolve 5092 // using this type whose name matches.... 5093 break; 5094 } 5095 } 5096 } 5097 5098 if (try_resolving_type) 5099 { 5100 if (log) 5101 { 5102 std::string qualified_name; 5103 type_die->GetQualifiedName(this, cu, qualified_name); 5104 GetObjectFile()->GetModule()->LogMessage (log, 5105 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)", 5106 die->GetOffset(), 5107 type_name.GetCString(), 5108 type_die->GetOffset(), 5109 qualified_name.c_str()); 5110 } 5111 5112 // Make sure the decl contexts match all the way up 5113 if (DIEDeclContextsMatch(cu, die, type_cu, type_die)) 5114 { 5115 Type *resolved_type = ResolveType (type_cu, type_die, false); 5116 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) 5117 { 5118 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", 5119 MakeUserID(die->GetOffset()), 5120 MakeUserID(dwarf_cu->GetOffset()), 5121 m_obj_file->GetFileSpec().GetFilename().AsCString(), 5122 MakeUserID(type_die->GetOffset()), 5123 MakeUserID(type_cu->GetOffset())); 5124 5125 m_die_to_type[die] = resolved_type; 5126 type_sp = resolved_type->shared_from_this(); 5127 break; 5128 } 5129 } 5130 } 5131 else 5132 { 5133 if (log) 5134 { 5135 std::string qualified_name; 5136 type_die->GetQualifiedName(this, cu, qualified_name); 5137 GetObjectFile()->GetModule()->LogMessage (log, 5138 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)", 5139 die->GetOffset(), 5140 type_name.GetCString(), 5141 type_die->GetOffset(), 5142 qualified_name.c_str()); 5143 } 5144 } 5145 } 5146 else 5147 { 5148 if (m_using_apple_tables) 5149 { 5150 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", 5151 die_offset, type_name.GetCString()); 5152 } 5153 } 5154 5155 } 5156 } 5157 return type_sp; 5158 } 5159 5160 TypeSP 5161 SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) 5162 { 5163 TypeSP type_sp; 5164 5165 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); 5166 if (dwarf_decl_ctx_count > 0) 5167 { 5168 const ConstString type_name(dwarf_decl_ctx[0].name); 5169 const dw_tag_t tag = dwarf_decl_ctx[0].tag; 5170 5171 if (type_name) 5172 { 5173 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); 5174 if (log) 5175 { 5176 GetObjectFile()->GetModule()->LogMessage (log, 5177 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", 5178 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), 5179 dwarf_decl_ctx.GetQualifiedName()); 5180 } 5181 5182 DIEArray die_offsets; 5183 5184 if (m_using_apple_tables) 5185 { 5186 if (m_apple_types_ap.get()) 5187 { 5188 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); 5189 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); 5190 if (has_tag && has_qualified_name_hash) 5191 { 5192 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); 5193 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); 5194 if (log) 5195 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); 5196 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); 5197 } 5198 else if (has_tag) 5199 { 5200 if (log) 5201 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); 5202 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); 5203 } 5204 else 5205 { 5206 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); 5207 } 5208 } 5209 } 5210 else 5211 { 5212 if (!m_indexed) 5213 Index (); 5214 5215 m_type_index.Find (type_name, die_offsets); 5216 } 5217 5218 const size_t num_matches = die_offsets.size(); 5219 5220 5221 DWARFCompileUnit* type_cu = NULL; 5222 const DWARFDebugInfoEntry* type_die = NULL; 5223 if (num_matches) 5224 { 5225 DWARFDebugInfo* debug_info = DebugInfo(); 5226 for (size_t i=0; i<num_matches; ++i) 5227 { 5228