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/ArchSpec.h" 30 #include "lldb/Core/Module.h" 31 #include "lldb/Core/ModuleList.h" 32 #include "lldb/Core/ModuleSpec.h" 33 #include "lldb/Core/PluginManager.h" 34 #include "lldb/Core/RegularExpression.h" 35 #include "lldb/Core/Scalar.h" 36 #include "lldb/Core/Section.h" 37 #include "lldb/Core/StreamFile.h" 38 #include "lldb/Core/StreamString.h" 39 #include "lldb/Core/Timer.h" 40 #include "lldb/Core/Value.h" 41 42 #include "lldb/Expression/ClangModulesDeclVendor.h" 43 44 #include "lldb/Host/Host.h" 45 46 #include "lldb/Symbol/Block.h" 47 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h" 48 #include "lldb/Symbol/CompileUnit.h" 49 #include "lldb/Symbol/LineTable.h" 50 #include "lldb/Symbol/ObjectFile.h" 51 #include "lldb/Symbol/SymbolVendor.h" 52 #include "lldb/Symbol/VariableList.h" 53 54 #include "lldb/Target/ObjCLanguageRuntime.h" 55 #include "lldb/Target/CPPLanguageRuntime.h" 56 57 #include "DWARFCompileUnit.h" 58 #include "DWARFDebugAbbrev.h" 59 #include "DWARFDebugAranges.h" 60 #include "DWARFDebugInfo.h" 61 #include "DWARFDebugInfoEntry.h" 62 #include "DWARFDebugLine.h" 63 #include "DWARFDebugPubnames.h" 64 #include "DWARFDebugRanges.h" 65 #include "DWARFDeclContext.h" 66 #include "DWARFDIECollection.h" 67 #include "DWARFFormValue.h" 68 #include "DWARFLocationList.h" 69 #include "LogChannelDWARF.h" 70 #include "SymbolFileDWARFDebugMap.h" 71 72 #include <map> 73 74 #include <ctype.h> 75 #include <string.h> 76 77 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN 78 79 #ifdef ENABLE_DEBUG_PRINTF 80 #include <stdio.h> 81 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) 82 #else 83 #define DEBUG_PRINTF(fmt, ...) 84 #endif 85 86 #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) 87 88 using namespace lldb; 89 using namespace lldb_private; 90 91 //static inline bool 92 //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag) 93 //{ 94 // switch (tag) 95 // { 96 // default: 97 // break; 98 // case DW_TAG_subprogram: 99 // case DW_TAG_inlined_subroutine: 100 // case DW_TAG_class_type: 101 // case DW_TAG_structure_type: 102 // case DW_TAG_union_type: 103 // return true; 104 // } 105 // return false; 106 //} 107 // 108 static AccessType 109 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) 110 { 111 switch (dwarf_accessibility) 112 { 113 case DW_ACCESS_public: return eAccessPublic; 114 case DW_ACCESS_private: return eAccessPrivate; 115 case DW_ACCESS_protected: return eAccessProtected; 116 default: break; 117 } 118 return eAccessNone; 119 } 120 121 static const char* 122 removeHostnameFromPathname(const char* path_from_dwarf) 123 { 124 if (!path_from_dwarf || !path_from_dwarf[0]) 125 { 126 return path_from_dwarf; 127 } 128 129 const char *colon_pos = strchr(path_from_dwarf, ':'); 130 if (!colon_pos) 131 { 132 return path_from_dwarf; 133 } 134 135 // check whether we have a windows path, and so the first character 136 // is a drive-letter not a hostname. 137 if ( 138 colon_pos == path_from_dwarf + 1 && 139 isalpha(*path_from_dwarf) && 140 strlen(path_from_dwarf) > 2 && 141 '\\' == path_from_dwarf[2]) 142 { 143 return path_from_dwarf; 144 } 145 146 return colon_pos + 1; 147 } 148 149 #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) 150 151 class DIEStack 152 { 153 public: 154 155 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 156 { 157 m_dies.push_back (DIEInfo(cu, die)); 158 } 159 160 161 void LogDIEs (Log *log, SymbolFileDWARF *dwarf) 162 { 163 StreamString log_strm; 164 const size_t n = m_dies.size(); 165 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); 166 for (size_t i=0; i<n; i++) 167 { 168 DWARFCompileUnit *cu = m_dies[i].cu; 169 const DWARFDebugInfoEntry *die = m_dies[i].die; 170 std::string qualified_name; 171 die->GetQualifiedName(dwarf, cu, qualified_name); 172 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", 173 (uint64_t)i, 174 die->GetOffset(), 175 DW_TAG_value_to_name(die->Tag()), 176 qualified_name.c_str()); 177 } 178 log->PutCString(log_strm.GetData()); 179 } 180 void Pop () 181 { 182 m_dies.pop_back(); 183 } 184 185 class ScopedPopper 186 { 187 public: 188 ScopedPopper (DIEStack &die_stack) : 189 m_die_stack (die_stack), 190 m_valid (false) 191 { 192 } 193 194 void 195 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 196 { 197 m_valid = true; 198 m_die_stack.Push (cu, die); 199 } 200 201 ~ScopedPopper () 202 { 203 if (m_valid) 204 m_die_stack.Pop(); 205 } 206 207 208 209 protected: 210 DIEStack &m_die_stack; 211 bool m_valid; 212 }; 213 214 protected: 215 struct DIEInfo { 216 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) : 217 cu(c), 218 die(d) 219 { 220 } 221 DWARFCompileUnit *cu; 222 const DWARFDebugInfoEntry *die; 223 }; 224 typedef std::vector<DIEInfo> Stack; 225 Stack m_dies; 226 }; 227 #endif 228 229 void 230 SymbolFileDWARF::Initialize() 231 { 232 LogChannelDWARF::Initialize(); 233 PluginManager::RegisterPlugin (GetPluginNameStatic(), 234 GetPluginDescriptionStatic(), 235 CreateInstance); 236 } 237 238 void 239 SymbolFileDWARF::Terminate() 240 { 241 PluginManager::UnregisterPlugin (CreateInstance); 242 LogChannelDWARF::Initialize(); 243 } 244 245 246 lldb_private::ConstString 247 SymbolFileDWARF::GetPluginNameStatic() 248 { 249 static ConstString g_name("dwarf"); 250 return g_name; 251 } 252 253 const char * 254 SymbolFileDWARF::GetPluginDescriptionStatic() 255 { 256 return "DWARF and DWARF3 debug symbol file reader."; 257 } 258 259 260 SymbolFile* 261 SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) 262 { 263 return new SymbolFileDWARF(obj_file); 264 } 265 266 TypeList * 267 SymbolFileDWARF::GetTypeList () 268 { 269 if (GetDebugMapSymfile ()) 270 return m_debug_map_symfile->GetTypeList(); 271 return m_obj_file->GetModule()->GetTypeList(); 272 273 } 274 void 275 SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu, 276 const DWARFDebugInfoEntry *die, 277 dw_offset_t min_die_offset, 278 dw_offset_t max_die_offset, 279 uint32_t type_mask, 280 TypeSet &type_set) 281 { 282 if (cu) 283 { 284 if (die) 285 { 286 const dw_offset_t die_offset = die->GetOffset(); 287 288 if (die_offset >= max_die_offset) 289 return; 290 291 if (die_offset >= min_die_offset) 292 { 293 const dw_tag_t tag = die->Tag(); 294 295 bool add_type = false; 296 297 switch (tag) 298 { 299 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break; 300 case DW_TAG_unspecified_type: 301 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break; 302 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break; 303 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break; 304 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break; 305 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break; 306 case DW_TAG_subroutine_type: 307 case DW_TAG_subprogram: 308 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break; 309 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break; 310 case DW_TAG_rvalue_reference_type: 311 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break; 312 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break; 313 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break; 314 } 315 316 if (add_type) 317 { 318 const bool assert_not_being_parsed = true; 319 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed); 320 if (type) 321 { 322 if (type_set.find(type) == type_set.end()) 323 type_set.insert(type); 324 } 325 } 326 } 327 328 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); 329 child_die != NULL; 330 child_die = child_die->GetSibling()) 331 { 332 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set); 333 } 334 } 335 } 336 } 337 338 size_t 339 SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope, 340 uint32_t type_mask, 341 TypeList &type_list) 342 343 { 344 TypeSet type_set; 345 346 CompileUnit *comp_unit = NULL; 347 DWARFCompileUnit* dwarf_cu = NULL; 348 if (sc_scope) 349 comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); 350 351 if (comp_unit) 352 { 353 dwarf_cu = GetDWARFCompileUnit(comp_unit); 354 if (dwarf_cu == 0) 355 return 0; 356 GetTypes (dwarf_cu, 357 dwarf_cu->DIE(), 358 dwarf_cu->GetOffset(), 359 dwarf_cu->GetNextCompileUnitOffset(), 360 type_mask, 361 type_set); 362 } 363 else 364 { 365 DWARFDebugInfo* info = DebugInfo(); 366 if (info) 367 { 368 const size_t num_cus = info->GetNumCompileUnits(); 369 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx) 370 { 371 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); 372 if (dwarf_cu) 373 { 374 GetTypes (dwarf_cu, 375 dwarf_cu->DIE(), 376 0, 377 UINT32_MAX, 378 type_mask, 379 type_set); 380 } 381 } 382 } 383 } 384 // if (m_using_apple_tables) 385 // { 386 // DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get(); 387 // if (apple_types) 388 // { 389 // apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool { 390 // 391 // for (auto die_info: die_info_array) 392 // { 393 // bool add_type = TagMatchesTypeMask (type_mask, 0); 394 // if (!add_type) 395 // { 396 // dw_tag_t tag = die_info.tag; 397 // if (tag == 0) 398 // { 399 // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL); 400 // tag = die->Tag(); 401 // } 402 // add_type = TagMatchesTypeMask (type_mask, tag); 403 // } 404 // if (add_type) 405 // { 406 // Type *type = ResolveTypeUID(die_info.offset); 407 // 408 // if (type_set.find(type) == type_set.end()) 409 // type_set.insert(type); 410 // } 411 // } 412 // return true; // Keep iterating 413 // }); 414 // } 415 // } 416 // else 417 // { 418 // if (!m_indexed) 419 // Index (); 420 // 421 // m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool { 422 // 423 // bool add_type = TagMatchesTypeMask (type_mask, 0); 424 // 425 // if (!add_type) 426 // { 427 // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL); 428 // if (die) 429 // { 430 // const dw_tag_t tag = die->Tag(); 431 // add_type = TagMatchesTypeMask (type_mask, tag); 432 // } 433 // } 434 // 435 // if (add_type) 436 // { 437 // Type *type = ResolveTypeUID(die_offset); 438 // 439 // if (type_set.find(type) == type_set.end()) 440 // type_set.insert(type); 441 // } 442 // return true; // Keep iterating 443 // }); 444 // } 445 446 std::set<ClangASTType> clang_type_set; 447 size_t num_types_added = 0; 448 for (Type *type : type_set) 449 { 450 ClangASTType clang_type = type->GetClangForwardType(); 451 if (clang_type_set.find(clang_type) == clang_type_set.end()) 452 { 453 clang_type_set.insert(clang_type); 454 type_list.Insert (type->shared_from_this()); 455 ++num_types_added; 456 } 457 } 458 return num_types_added; 459 } 460 461 462 //---------------------------------------------------------------------- 463 // Gets the first parent that is a lexical block, function or inlined 464 // subroutine, or compile unit. 465 //---------------------------------------------------------------------- 466 static const DWARFDebugInfoEntry * 467 GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) 468 { 469 const DWARFDebugInfoEntry *die; 470 for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) 471 { 472 dw_tag_t tag = die->Tag(); 473 474 switch (tag) 475 { 476 case DW_TAG_compile_unit: 477 case DW_TAG_subprogram: 478 case DW_TAG_inlined_subroutine: 479 case DW_TAG_lexical_block: 480 return die; 481 } 482 } 483 return NULL; 484 } 485 486 487 SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : 488 SymbolFile (objfile), 489 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID 490 m_debug_map_module_wp (), 491 m_debug_map_symfile (NULL), 492 m_clang_tu_decl (NULL), 493 m_flags(), 494 m_data_debug_abbrev (), 495 m_data_debug_aranges (), 496 m_data_debug_frame (), 497 m_data_debug_info (), 498 m_data_debug_line (), 499 m_data_debug_loc (), 500 m_data_debug_ranges (), 501 m_data_debug_str (), 502 m_data_apple_names (), 503 m_data_apple_types (), 504 m_data_apple_namespaces (), 505 m_abbr(), 506 m_info(), 507 m_line(), 508 m_apple_names_ap (), 509 m_apple_types_ap (), 510 m_apple_namespaces_ap (), 511 m_apple_objc_ap (), 512 m_function_basename_index(), 513 m_function_fullname_index(), 514 m_function_method_index(), 515 m_function_selector_index(), 516 m_objc_class_selectors_index(), 517 m_global_index(), 518 m_type_index(), 519 m_namespace_index(), 520 m_indexed (false), 521 m_is_external_ast_source (false), 522 m_using_apple_tables (false), 523 m_fetched_external_modules (false), 524 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate), 525 m_ranges(), 526 m_unique_ast_type_map () 527 { 528 } 529 530 SymbolFileDWARF::~SymbolFileDWARF() 531 { 532 if (m_is_external_ast_source) 533 { 534 ModuleSP module_sp (m_obj_file->GetModule()); 535 if (module_sp) 536 module_sp->GetClangASTContext().RemoveExternalSource (); 537 } 538 } 539 540 static const ConstString & 541 GetDWARFMachOSegmentName () 542 { 543 static ConstString g_dwarf_section_name ("__DWARF"); 544 return g_dwarf_section_name; 545 } 546 547 UniqueDWARFASTTypeMap & 548 SymbolFileDWARF::GetUniqueDWARFASTTypeMap () 549 { 550 if (GetDebugMapSymfile ()) 551 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap (); 552 return m_unique_ast_type_map; 553 } 554 555 ClangASTContext & 556 SymbolFileDWARF::GetClangASTContext () 557 { 558 if (GetDebugMapSymfile ()) 559 return m_debug_map_symfile->GetClangASTContext (); 560 561 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext(); 562 if (!m_is_external_ast_source) 563 { 564 m_is_external_ast_source = true; 565 llvm::IntrusiveRefCntPtr<clang::ExternalASTSource> ast_source_ap ( 566 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl, 567 SymbolFileDWARF::CompleteObjCInterfaceDecl, 568 SymbolFileDWARF::FindExternalVisibleDeclsByName, 569 SymbolFileDWARF::LayoutRecordType, 570 this)); 571 ast.SetExternalSource (ast_source_ap); 572 } 573 return ast; 574 } 575 576 void 577 SymbolFileDWARF::InitializeObject() 578 { 579 // Install our external AST source callbacks so we can complete Clang types. 580 ModuleSP module_sp (m_obj_file->GetModule()); 581 if (module_sp) 582 { 583 const SectionList *section_list = module_sp->GetSectionList(); 584 585 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); 586 587 // Memory map the DWARF mach-o segment so we have everything mmap'ed 588 // to keep our heap memory usage down. 589 if (section) 590 m_obj_file->MemoryMapSectionData(section, m_dwarf_data); 591 } 592 get_apple_names_data(); 593 if (m_data_apple_names.GetByteSize() > 0) 594 { 595 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names")); 596 if (m_apple_names_ap->IsValid()) 597 m_using_apple_tables = true; 598 else 599 m_apple_names_ap.reset(); 600 } 601 get_apple_types_data(); 602 if (m_data_apple_types.GetByteSize() > 0) 603 { 604 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types")); 605 if (m_apple_types_ap->IsValid()) 606 m_using_apple_tables = true; 607 else 608 m_apple_types_ap.reset(); 609 } 610 611 get_apple_namespaces_data(); 612 if (m_data_apple_namespaces.GetByteSize() > 0) 613 { 614 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces")); 615 if (m_apple_namespaces_ap->IsValid()) 616 m_using_apple_tables = true; 617 else 618 m_apple_namespaces_ap.reset(); 619 } 620 621 get_apple_objc_data(); 622 if (m_data_apple_objc.GetByteSize() > 0) 623 { 624 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc")); 625 if (m_apple_objc_ap->IsValid()) 626 m_using_apple_tables = true; 627 else 628 m_apple_objc_ap.reset(); 629 } 630 } 631 632 bool 633 SymbolFileDWARF::SupportedVersion(uint16_t version) 634 { 635 return version == 2 || version == 3 || version == 4; 636 } 637 638 uint32_t 639 SymbolFileDWARF::CalculateAbilities () 640 { 641 uint32_t abilities = 0; 642 if (m_obj_file != NULL) 643 { 644 const Section* section = NULL; 645 const SectionList *section_list = m_obj_file->GetSectionList(); 646 if (section_list == NULL) 647 return 0; 648 649 uint64_t debug_abbrev_file_size = 0; 650 uint64_t debug_info_file_size = 0; 651 uint64_t debug_line_file_size = 0; 652 653 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get(); 654 655 if (section) 656 section_list = §ion->GetChildren (); 657 658 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); 659 if (section != NULL) 660 { 661 debug_info_file_size = section->GetFileSize(); 662 663 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); 664 if (section) 665 debug_abbrev_file_size = section->GetFileSize(); 666 else 667 m_flags.Set (flagsGotDebugAbbrevData); 668 669 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); 670 if (!section) 671 m_flags.Set (flagsGotDebugArangesData); 672 673 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); 674 if (!section) 675 m_flags.Set (flagsGotDebugFrameData); 676 677 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); 678 if (section) 679 debug_line_file_size = section->GetFileSize(); 680 else 681 m_flags.Set (flagsGotDebugLineData); 682 683 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); 684 if (!section) 685 m_flags.Set (flagsGotDebugLocData); 686 687 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); 688 if (!section) 689 m_flags.Set (flagsGotDebugMacInfoData); 690 691 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); 692 if (!section) 693 m_flags.Set (flagsGotDebugPubNamesData); 694 695 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); 696 if (!section) 697 m_flags.Set (flagsGotDebugPubTypesData); 698 699 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); 700 if (!section) 701 m_flags.Set (flagsGotDebugRangesData); 702 703 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); 704 if (!section) 705 m_flags.Set (flagsGotDebugStrData); 706 } 707 else 708 { 709 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString(); 710 if (symfile_dir_cstr) 711 { 712 if (strcasestr(symfile_dir_cstr, ".dsym")) 713 { 714 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) 715 { 716 // We have a dSYM file that didn't have a any debug info. 717 // If the string table has a size of 1, then it was made from 718 // an executable with no debug info, or from an executable that 719 // was stripped. 720 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); 721 if (section && section->GetFileSize() == 1) 722 { 723 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info."); 724 } 725 } 726 } 727 } 728 } 729 730 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) 731 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; 732 733 if (debug_line_file_size > 0) 734 abilities |= LineTables; 735 } 736 return abilities; 737 } 738 739 const DWARFDataExtractor& 740 SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data) 741 { 742 if (m_flags.IsClear (got_flag)) 743 { 744 ModuleSP module_sp (m_obj_file->GetModule()); 745 m_flags.Set (got_flag); 746 const SectionList *section_list = module_sp->GetSectionList(); 747 if (section_list) 748 { 749 SectionSP section_sp (section_list->FindSectionByType(sect_type, true)); 750 if (section_sp) 751 { 752 // See if we memory mapped the DWARF segment? 753 if (m_dwarf_data.GetByteSize()) 754 { 755 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize()); 756 } 757 else 758 { 759 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0) 760 data.Clear(); 761 } 762 } 763 } 764 } 765 return data; 766 } 767 768 const DWARFDataExtractor& 769 SymbolFileDWARF::get_debug_abbrev_data() 770 { 771 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); 772 } 773 774 const DWARFDataExtractor& 775 SymbolFileDWARF::get_debug_aranges_data() 776 { 777 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges); 778 } 779 780 const DWARFDataExtractor& 781 SymbolFileDWARF::get_debug_frame_data() 782 { 783 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); 784 } 785 786 const DWARFDataExtractor& 787 SymbolFileDWARF::get_debug_info_data() 788 { 789 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); 790 } 791 792 const DWARFDataExtractor& 793 SymbolFileDWARF::get_debug_line_data() 794 { 795 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); 796 } 797 798 const DWARFDataExtractor& 799 SymbolFileDWARF::get_debug_loc_data() 800 { 801 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); 802 } 803 804 const DWARFDataExtractor& 805 SymbolFileDWARF::get_debug_ranges_data() 806 { 807 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); 808 } 809 810 const DWARFDataExtractor& 811 SymbolFileDWARF::get_debug_str_data() 812 { 813 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); 814 } 815 816 const DWARFDataExtractor& 817 SymbolFileDWARF::get_apple_names_data() 818 { 819 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names); 820 } 821 822 const DWARFDataExtractor& 823 SymbolFileDWARF::get_apple_types_data() 824 { 825 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types); 826 } 827 828 const DWARFDataExtractor& 829 SymbolFileDWARF::get_apple_namespaces_data() 830 { 831 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces); 832 } 833 834 const DWARFDataExtractor& 835 SymbolFileDWARF::get_apple_objc_data() 836 { 837 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc); 838 } 839 840 841 DWARFDebugAbbrev* 842 SymbolFileDWARF::DebugAbbrev() 843 { 844 if (m_abbr.get() == NULL) 845 { 846 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data(); 847 if (debug_abbrev_data.GetByteSize() > 0) 848 { 849 m_abbr.reset(new DWARFDebugAbbrev()); 850 if (m_abbr.get()) 851 m_abbr->Parse(debug_abbrev_data); 852 } 853 } 854 return m_abbr.get(); 855 } 856 857 const DWARFDebugAbbrev* 858 SymbolFileDWARF::DebugAbbrev() const 859 { 860 return m_abbr.get(); 861 } 862 863 864 DWARFDebugInfo* 865 SymbolFileDWARF::DebugInfo() 866 { 867 if (m_info.get() == NULL) 868 { 869 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", 870 __PRETTY_FUNCTION__, static_cast<void*>(this)); 871 if (get_debug_info_data().GetByteSize() > 0) 872 { 873 m_info.reset(new DWARFDebugInfo()); 874 if (m_info.get()) 875 { 876 m_info->SetDwarfData(this); 877 } 878 } 879 } 880 return m_info.get(); 881 } 882 883 const DWARFDebugInfo* 884 SymbolFileDWARF::DebugInfo() const 885 { 886 return m_info.get(); 887 } 888 889 DWARFCompileUnit* 890 SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) 891 { 892 DWARFDebugInfo* info = DebugInfo(); 893 if (info) 894 { 895 if (GetDebugMapSymfile ()) 896 { 897 // The debug map symbol file made the compile units for this DWARF 898 // file which is .o file with DWARF in it, and we should have 899 // only 1 compile unit which is at offset zero in the DWARF. 900 // TODO: modify to support LTO .o files where each .o file might 901 // have multiple DW_TAG_compile_unit tags. 902 903 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0).get(); 904 if (dwarf_cu && dwarf_cu->GetUserData() == NULL) 905 dwarf_cu->SetUserData(comp_unit); 906 return dwarf_cu; 907 } 908 else 909 { 910 // Just a normal DWARF file whose user ID for the compile unit is 911 // the DWARF offset itself 912 913 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get(); 914 if (dwarf_cu && dwarf_cu->GetUserData() == NULL) 915 dwarf_cu->SetUserData(comp_unit); 916 return dwarf_cu; 917 918 } 919 } 920 return NULL; 921 } 922 923 924 DWARFDebugRanges* 925 SymbolFileDWARF::DebugRanges() 926 { 927 if (m_ranges.get() == NULL) 928 { 929 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", 930 __PRETTY_FUNCTION__, static_cast<void*>(this)); 931 if (get_debug_ranges_data().GetByteSize() > 0) 932 { 933 m_ranges.reset(new DWARFDebugRanges()); 934 if (m_ranges.get()) 935 m_ranges->Extract(this); 936 } 937 } 938 return m_ranges.get(); 939 } 940 941 const DWARFDebugRanges* 942 SymbolFileDWARF::DebugRanges() const 943 { 944 return m_ranges.get(); 945 } 946 947 lldb::CompUnitSP 948 SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) 949 { 950 CompUnitSP cu_sp; 951 if (dwarf_cu) 952 { 953 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData(); 954 if (comp_unit) 955 { 956 // We already parsed this compile unit, had out a shared pointer to it 957 cu_sp = comp_unit->shared_from_this(); 958 } 959 else 960 { 961 if (GetDebugMapSymfile ()) 962 { 963 // Let the debug map create the compile unit 964 cu_sp = m_debug_map_symfile->GetCompileUnit(this); 965 dwarf_cu->SetUserData(cu_sp.get()); 966 } 967 else 968 { 969 ModuleSP module_sp (m_obj_file->GetModule()); 970 if (module_sp) 971 { 972 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly (); 973 if (cu_die) 974 { 975 const char * cu_die_name = cu_die->GetName(this, dwarf_cu); 976 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); 977 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); 978 if (cu_die_name) 979 { 980 std::string ramapped_file; 981 FileSpec cu_file_spec; 982 983 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0') 984 { 985 // If we have a full path to the compile unit, we don't need to resolve 986 // the file. This can be expensive e.g. when the source files are NFS mounted. 987 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file)) 988 cu_file_spec.SetFile (ramapped_file.c_str(), false); 989 else 990 cu_file_spec.SetFile (cu_die_name, false); 991 } 992 else 993 { 994 // DWARF2/3 suggests the form hostname:pathname for compilation directory. 995 // Remove the host part if present. 996 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); 997 std::string fullpath(cu_comp_dir); 998 999 if (*fullpath.rbegin() != '/') 1000 fullpath += '/'; 1001 fullpath += cu_die_name; 1002 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file)) 1003 cu_file_spec.SetFile (ramapped_file.c_str(), false); 1004 else 1005 cu_file_spec.SetFile (fullpath.c_str(), false); 1006 } 1007 1008 cu_sp.reset(new CompileUnit (module_sp, 1009 dwarf_cu, 1010 cu_file_spec, 1011 MakeUserID(dwarf_cu->GetOffset()), 1012 cu_language)); 1013 if (cu_sp) 1014 { 1015 dwarf_cu->SetUserData(cu_sp.get()); 1016 1017 // Figure out the compile unit index if we weren't given one 1018 if (cu_idx == UINT32_MAX) 1019 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx); 1020 1021 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp); 1022 } 1023 } 1024 } 1025 } 1026 } 1027 } 1028 } 1029 return cu_sp; 1030 } 1031 1032 uint32_t 1033 SymbolFileDWARF::GetNumCompileUnits() 1034 { 1035 DWARFDebugInfo* info = DebugInfo(); 1036 if (info) 1037 return info->GetNumCompileUnits(); 1038 return 0; 1039 } 1040 1041 CompUnitSP 1042 SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) 1043 { 1044 CompUnitSP cu_sp; 1045 DWARFDebugInfo* info = DebugInfo(); 1046 if (info) 1047 { 1048 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx); 1049 if (dwarf_cu) 1050 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx); 1051 } 1052 return cu_sp; 1053 } 1054 1055 Function * 1056 SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) 1057 { 1058 DWARFDebugRanges::RangeList func_ranges; 1059 const char *name = NULL; 1060 const char *mangled = NULL; 1061 int decl_file = 0; 1062 int decl_line = 0; 1063 int decl_column = 0; 1064 int call_file = 0; 1065 int call_line = 0; 1066 int call_column = 0; 1067 DWARFExpression frame_base; 1068 1069 assert (die->Tag() == DW_TAG_subprogram); 1070 1071 if (die->Tag() != DW_TAG_subprogram) 1072 return NULL; 1073 1074 if (die->GetDIENamesAndRanges (this, 1075 dwarf_cu, 1076 name, 1077 mangled, 1078 func_ranges, 1079 decl_file, 1080 decl_line, 1081 decl_column, 1082 call_file, 1083 call_line, 1084 call_column, 1085 &frame_base)) 1086 { 1087 // Union of all ranges in the function DIE (if the function is discontiguous) 1088 AddressRange func_range; 1089 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); 1090 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); 1091 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) 1092 { 1093 ModuleSP module_sp (m_obj_file->GetModule()); 1094 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); 1095 if (func_range.GetBaseAddress().IsValid()) 1096 func_range.SetByteSize(highest_func_addr - lowest_func_addr); 1097 } 1098 1099 if (func_range.GetBaseAddress().IsValid()) 1100 { 1101 Mangled func_name; 1102 if (mangled) 1103 func_name.SetValue(ConstString(mangled), true); 1104 else if (die->GetParent()->Tag() == DW_TAG_compile_unit && 1105 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) && 1106 name && strcmp(name, "main") != 0) 1107 { 1108 // If the mangled name is not present in the DWARF, generate the demangled name 1109 // using the decl context. We skip if the function is "main" as its name is 1110 // never mangled. 1111 bool is_static = false; 1112 bool is_variadic = false; 1113 unsigned type_quals = 0; 1114 std::vector<ClangASTType> param_types; 1115 std::vector<clang::ParmVarDecl*> param_decls; 1116 const DWARFDebugInfoEntry *decl_ctx_die = NULL; 1117 DWARFDeclContext decl_ctx; 1118 StreamString sstr; 1119 1120 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); 1121 sstr << decl_ctx.GetQualifiedName(); 1122 1123 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu, 1124 die, 1125 &decl_ctx_die); 1126 ParseChildParameters(sc, 1127 containing_decl_ctx, 1128 dwarf_cu, 1129 die, 1130 true, 1131 is_static, 1132 is_variadic, 1133 param_types, 1134 param_decls, 1135 type_quals); 1136 sstr << "("; 1137 for (size_t i = 0; i < param_types.size(); i++) 1138 { 1139 if (i > 0) 1140 sstr << ", "; 1141 sstr << param_types[i].GetTypeName(); 1142 } 1143 if (is_variadic) 1144 sstr << ", ..."; 1145 sstr << ")"; 1146 if (type_quals & clang::Qualifiers::Const) 1147 sstr << " const"; 1148 1149 func_name.SetValue(ConstString(sstr.GetData()), false); 1150 } 1151 else 1152 func_name.SetValue(ConstString(name), false); 1153 1154 FunctionSP func_sp; 1155 std::unique_ptr<Declaration> decl_ap; 1156 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 1157 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), 1158 decl_line, 1159 decl_column)); 1160 1161 // Supply the type _only_ if it has already been parsed 1162 Type *func_type = m_die_to_type.lookup (die); 1163 1164 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); 1165 1166 if (FixupAddress (func_range.GetBaseAddress())) 1167 { 1168 const user_id_t func_user_id = MakeUserID(die->GetOffset()); 1169 func_sp.reset(new Function (sc.comp_unit, 1170 MakeUserID(func_user_id), // UserID is the DIE offset 1171 MakeUserID(func_user_id), 1172 func_name, 1173 func_type, 1174 func_range)); // first address range 1175 1176 if (func_sp.get() != NULL) 1177 { 1178 if (frame_base.IsValid()) 1179 func_sp->GetFrameBaseExpression() = frame_base; 1180 sc.comp_unit->AddFunction(func_sp); 1181 return func_sp.get(); 1182 } 1183 } 1184 } 1185 } 1186 return NULL; 1187 } 1188 1189 bool 1190 SymbolFileDWARF::FixupAddress (Address &addr) 1191 { 1192 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile (); 1193 if (debug_map_symfile) 1194 { 1195 return debug_map_symfile->LinkOSOAddress(addr); 1196 } 1197 // This is a normal DWARF file, no address fixups need to happen 1198 return true; 1199 } 1200 lldb::LanguageType 1201 SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc) 1202 { 1203 assert (sc.comp_unit); 1204 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1205 if (dwarf_cu) 1206 { 1207 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); 1208 if (die) 1209 { 1210 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0); 1211 if (language) 1212 return (lldb::LanguageType)language; 1213 } 1214 } 1215 return eLanguageTypeUnknown; 1216 } 1217 1218 size_t 1219 SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) 1220 { 1221 assert (sc.comp_unit); 1222 size_t functions_added = 0; 1223 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1224 if (dwarf_cu) 1225 { 1226 DWARFDIECollection function_dies; 1227 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); 1228 size_t func_idx; 1229 for (func_idx = 0; func_idx < num_functions; ++func_idx) 1230 { 1231 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); 1232 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL) 1233 { 1234 if (ParseCompileUnitFunction(sc, dwarf_cu, die)) 1235 ++functions_added; 1236 } 1237 } 1238 //FixupTypes(); 1239 } 1240 return functions_added; 1241 } 1242 1243 bool 1244 SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) 1245 { 1246 assert (sc.comp_unit); 1247 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1248 if (dwarf_cu) 1249 { 1250 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly(); 1251 1252 if (cu_die) 1253 { 1254 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL); 1255 1256 // DWARF2/3 suggests the form hostname:pathname for compilation directory. 1257 // Remove the host part if present. 1258 cu_comp_dir = removeHostnameFromPathname(cu_comp_dir); 1259 1260 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); 1261 1262 // All file indexes in DWARF are one based and a file of index zero is 1263 // supposed to be the compile unit itself. 1264 support_files.Append (*sc.comp_unit); 1265 1266 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files); 1267 } 1268 } 1269 return false; 1270 } 1271 1272 bool 1273 SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) 1274 { 1275 assert (sc.comp_unit); 1276 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1277 if (dwarf_cu) 1278 { 1279 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage())) 1280 { 1281 UpdateExternalModuleListIfNeeded(); 1282 for (const std::pair<uint64_t, const ClangModuleInfo> &external_type_module : m_external_type_modules) 1283 { 1284 imported_modules.push_back(external_type_module.second.m_name); 1285 } 1286 } 1287 } 1288 return false; 1289 } 1290 1291 struct ParseDWARFLineTableCallbackInfo 1292 { 1293 LineTable* line_table; 1294 std::unique_ptr<LineSequence> sequence_ap; 1295 }; 1296 1297 //---------------------------------------------------------------------- 1298 // ParseStatementTableCallback 1299 //---------------------------------------------------------------------- 1300 static void 1301 ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) 1302 { 1303 if (state.row == DWARFDebugLine::State::StartParsingLineTable) 1304 { 1305 // Just started parsing the line table 1306 } 1307 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) 1308 { 1309 // Done parsing line table, nothing to do for the cleanup 1310 } 1311 else 1312 { 1313 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; 1314 LineTable* line_table = info->line_table; 1315 1316 // If this is our first time here, we need to create a 1317 // sequence container. 1318 if (!info->sequence_ap.get()) 1319 { 1320 info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); 1321 assert(info->sequence_ap.get()); 1322 } 1323 line_table->AppendLineEntryToSequence (info->sequence_ap.get(), 1324 state.address, 1325 state.line, 1326 state.column, 1327 state.file, 1328 state.is_stmt, 1329 state.basic_block, 1330 state.prologue_end, 1331 state.epilogue_begin, 1332 state.end_sequence); 1333 if (state.end_sequence) 1334 { 1335 // First, put the current sequence into the line table. 1336 line_table->InsertSequence(info->sequence_ap.get()); 1337 // Then, empty it to prepare for the next sequence. 1338 info->sequence_ap->Clear(); 1339 } 1340 } 1341 } 1342 1343 bool 1344 SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) 1345 { 1346 assert (sc.comp_unit); 1347 if (sc.comp_unit->GetLineTable() != NULL) 1348 return true; 1349 1350 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 1351 if (dwarf_cu) 1352 { 1353 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); 1354 if (dwarf_cu_die) 1355 { 1356 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); 1357 if (cu_line_offset != DW_INVALID_OFFSET) 1358 { 1359 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); 1360 if (line_table_ap.get()) 1361 { 1362 ParseDWARFLineTableCallbackInfo info; 1363 info.line_table = line_table_ap.get(); 1364 lldb::offset_t offset = cu_line_offset; 1365 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); 1366 if (m_debug_map_symfile) 1367 { 1368 // We have an object file that has a line table with addresses 1369 // that are not linked. We need to link the line table and convert 1370 // the addresses that are relative to the .o file into addresses 1371 // for the main executable. 1372 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get())); 1373 } 1374 else 1375 { 1376 sc.comp_unit->SetLineTable(line_table_ap.release()); 1377 return true; 1378 } 1379 } 1380 } 1381 } 1382 } 1383 return false; 1384 } 1385 1386 size_t 1387 SymbolFileDWARF::ParseFunctionBlocks 1388 ( 1389 const SymbolContext& sc, 1390 Block *parent_block, 1391 DWARFCompileUnit* dwarf_cu, 1392 const DWARFDebugInfoEntry *die, 1393 addr_t subprogram_low_pc, 1394 uint32_t depth 1395 ) 1396 { 1397 size_t blocks_added = 0; 1398 while (die != NULL) 1399 { 1400 dw_tag_t tag = die->Tag(); 1401 1402 switch (tag) 1403 { 1404 case DW_TAG_inlined_subroutine: 1405 case DW_TAG_subprogram: 1406 case DW_TAG_lexical_block: 1407 { 1408 Block *block = NULL; 1409 if (tag == DW_TAG_subprogram) 1410 { 1411 // Skip any DW_TAG_subprogram DIEs that are inside 1412 // of a normal or inlined functions. These will be 1413 // parsed on their own as separate entities. 1414 1415 if (depth > 0) 1416 break; 1417 1418 block = parent_block; 1419 } 1420 else 1421 { 1422 BlockSP block_sp(new Block (MakeUserID(die->GetOffset()))); 1423 parent_block->AddChild(block_sp); 1424 block = block_sp.get(); 1425 } 1426 DWARFDebugRanges::RangeList ranges; 1427 const char *name = NULL; 1428 const char *mangled_name = NULL; 1429 1430 int decl_file = 0; 1431 int decl_line = 0; 1432 int decl_column = 0; 1433 int call_file = 0; 1434 int call_line = 0; 1435 int call_column = 0; 1436 if (die->GetDIENamesAndRanges (this, 1437 dwarf_cu, 1438 name, 1439 mangled_name, 1440 ranges, 1441 decl_file, decl_line, decl_column, 1442 call_file, call_line, call_column)) 1443 { 1444 if (tag == DW_TAG_subprogram) 1445 { 1446 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); 1447 subprogram_low_pc = ranges.GetMinRangeBase(0); 1448 } 1449 else if (tag == DW_TAG_inlined_subroutine) 1450 { 1451 // We get called here for inlined subroutines in two ways. 1452 // The first time is when we are making the Function object 1453 // for this inlined concrete instance. Since we're creating a top level block at 1454 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to 1455 // adjust the containing address. 1456 // The second time is when we are parsing the blocks inside the function that contains 1457 // the inlined concrete instance. Since these will be blocks inside the containing "real" 1458 // function the offset will be for that function. 1459 if (subprogram_low_pc == LLDB_INVALID_ADDRESS) 1460 { 1461 subprogram_low_pc = ranges.GetMinRangeBase(0); 1462 } 1463 } 1464 1465 const size_t num_ranges = ranges.GetSize(); 1466 for (size_t i = 0; i<num_ranges; ++i) 1467 { 1468 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i); 1469 const addr_t range_base = range.GetRangeBase(); 1470 if (range_base >= subprogram_low_pc) 1471 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize())); 1472 else 1473 { 1474 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message", 1475 block->GetID(), 1476 range_base, 1477 range.GetRangeEnd(), 1478 subprogram_low_pc); 1479 } 1480 } 1481 block->FinalizeRanges (); 1482 1483 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) 1484 { 1485 std::unique_ptr<Declaration> decl_ap; 1486 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 1487 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), 1488 decl_line, decl_column)); 1489 1490 std::unique_ptr<Declaration> call_ap; 1491 if (call_file != 0 || call_line != 0 || call_column != 0) 1492 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), 1493 call_line, call_column)); 1494 1495 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); 1496 } 1497 1498 ++blocks_added; 1499 1500 if (die->HasChildren()) 1501 { 1502 blocks_added += ParseFunctionBlocks (sc, 1503 block, 1504 dwarf_cu, 1505 die->GetFirstChild(), 1506 subprogram_low_pc, 1507 depth + 1); 1508 } 1509 } 1510 } 1511 break; 1512 default: 1513 break; 1514 } 1515 1516 // Only parse siblings of the block if we are not at depth zero. A depth 1517 // of zero indicates we are currently parsing the top level 1518 // DW_TAG_subprogram DIE 1519 1520 if (depth == 0) 1521 die = NULL; 1522 else 1523 die = die->GetSibling(); 1524 } 1525 return blocks_added; 1526 } 1527 1528 bool 1529 SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu, 1530 const DWARFDebugInfoEntry *die, 1531 ClangASTContext::TemplateParameterInfos &template_param_infos) 1532 { 1533 const dw_tag_t tag = die->Tag(); 1534 1535 switch (tag) 1536 { 1537 case DW_TAG_template_type_parameter: 1538 case DW_TAG_template_value_parameter: 1539 { 1540 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); 1541 1542 DWARFDebugInfoEntry::Attributes attributes; 1543 const size_t num_attributes = die->GetAttributes (this, 1544 dwarf_cu, 1545 fixed_form_sizes, 1546 attributes); 1547 const char *name = NULL; 1548 Type *lldb_type = NULL; 1549 ClangASTType clang_type; 1550 uint64_t uval64 = 0; 1551 bool uval64_valid = false; 1552 if (num_attributes > 0) 1553 { 1554 DWARFFormValue form_value; 1555 for (size_t i=0; i<num_attributes; ++i) 1556 { 1557 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1558 1559 switch (attr) 1560 { 1561 case DW_AT_name: 1562 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1563 name = form_value.AsCString(&get_debug_str_data()); 1564 break; 1565 1566 case DW_AT_type: 1567 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1568 { 1569 const dw_offset_t type_die_offset = form_value.Reference(); 1570 lldb_type = ResolveTypeUID(type_die_offset); 1571 if (lldb_type) 1572 clang_type = lldb_type->GetClangForwardType(); 1573 } 1574 break; 1575 1576 case DW_AT_const_value: 1577 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1578 { 1579 uval64_valid = true; 1580 uval64 = form_value.Unsigned(); 1581 } 1582 break; 1583 default: 1584 break; 1585 } 1586 } 1587 1588 clang::ASTContext *ast = GetClangASTContext().getASTContext(); 1589 if (!clang_type) 1590 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid); 1591 1592 if (clang_type) 1593 { 1594 bool is_signed = false; 1595 if (name && name[0]) 1596 template_param_infos.names.push_back(name); 1597 else 1598 template_param_infos.names.push_back(NULL); 1599 1600 if (tag == DW_TAG_template_value_parameter && 1601 lldb_type != NULL && 1602 clang_type.IsIntegerType (is_signed) && 1603 uval64_valid) 1604 { 1605 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); 1606 template_param_infos.args.push_back (clang::TemplateArgument (*ast, 1607 llvm::APSInt(apint), 1608 clang_type.GetQualType())); 1609 } 1610 else 1611 { 1612 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType())); 1613 } 1614 } 1615 else 1616 { 1617 return false; 1618 } 1619 1620 } 1621 } 1622 return true; 1623 1624 default: 1625 break; 1626 } 1627 return false; 1628 } 1629 1630 bool 1631 SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu, 1632 const DWARFDebugInfoEntry *parent_die, 1633 ClangASTContext::TemplateParameterInfos &template_param_infos) 1634 { 1635 1636 if (parent_die == NULL) 1637 return false; 1638 1639 Args template_parameter_names; 1640 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); 1641 die != NULL; 1642 die = die->GetSibling()) 1643 { 1644 const dw_tag_t tag = die->Tag(); 1645 1646 switch (tag) 1647 { 1648 case DW_TAG_template_type_parameter: 1649 case DW_TAG_template_value_parameter: 1650 ParseTemplateDIE (dwarf_cu, die, template_param_infos); 1651 break; 1652 1653 default: 1654 break; 1655 } 1656 } 1657 if (template_param_infos.args.empty()) 1658 return false; 1659 return template_param_infos.args.size() == template_param_infos.names.size(); 1660 } 1661 1662 clang::ClassTemplateDecl * 1663 SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx, 1664 lldb::AccessType access_type, 1665 const char *parent_name, 1666 int tag_decl_kind, 1667 const ClangASTContext::TemplateParameterInfos &template_param_infos) 1668 { 1669 if (template_param_infos.IsValid()) 1670 { 1671 std::string template_basename(parent_name); 1672 template_basename.erase (template_basename.find('<')); 1673 ClangASTContext &ast = GetClangASTContext(); 1674 1675 return ast.CreateClassTemplateDecl (decl_ctx, 1676 access_type, 1677 template_basename.c_str(), 1678 tag_decl_kind, 1679 template_param_infos); 1680 } 1681 return NULL; 1682 } 1683 1684 class SymbolFileDWARF::DelayedAddObjCClassProperty 1685 { 1686 public: 1687 DelayedAddObjCClassProperty 1688 ( 1689 const ClangASTType &class_opaque_type, 1690 const char *property_name, 1691 const ClangASTType &property_opaque_type, // The property type is only required if you don't have an ivar decl 1692 clang::ObjCIvarDecl *ivar_decl, 1693 const char *property_setter_name, 1694 const char *property_getter_name, 1695 uint32_t property_attributes, 1696 const ClangASTMetadata *metadata 1697 ) : 1698 m_class_opaque_type (class_opaque_type), 1699 m_property_name (property_name), 1700 m_property_opaque_type (property_opaque_type), 1701 m_ivar_decl (ivar_decl), 1702 m_property_setter_name (property_setter_name), 1703 m_property_getter_name (property_getter_name), 1704 m_property_attributes (property_attributes) 1705 { 1706 if (metadata != NULL) 1707 { 1708 m_metadata_ap.reset(new ClangASTMetadata()); 1709 *m_metadata_ap = *metadata; 1710 } 1711 } 1712 1713 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) 1714 { 1715 *this = rhs; 1716 } 1717 1718 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) 1719 { 1720 m_class_opaque_type = rhs.m_class_opaque_type; 1721 m_property_name = rhs.m_property_name; 1722 m_property_opaque_type = rhs.m_property_opaque_type; 1723 m_ivar_decl = rhs.m_ivar_decl; 1724 m_property_setter_name = rhs.m_property_setter_name; 1725 m_property_getter_name = rhs.m_property_getter_name; 1726 m_property_attributes = rhs.m_property_attributes; 1727 1728 if (rhs.m_metadata_ap.get()) 1729 { 1730 m_metadata_ap.reset (new ClangASTMetadata()); 1731 *m_metadata_ap = *rhs.m_metadata_ap; 1732 } 1733 return *this; 1734 } 1735 1736 bool 1737 Finalize() 1738 { 1739 return m_class_opaque_type.AddObjCClassProperty (m_property_name, 1740 m_property_opaque_type, 1741 m_ivar_decl, 1742 m_property_setter_name, 1743 m_property_getter_name, 1744 m_property_attributes, 1745 m_metadata_ap.get()); 1746 } 1747 private: 1748 ClangASTType m_class_opaque_type; 1749 const char *m_property_name; 1750 ClangASTType m_property_opaque_type; 1751 clang::ObjCIvarDecl *m_ivar_decl; 1752 const char *m_property_setter_name; 1753 const char *m_property_getter_name; 1754 uint32_t m_property_attributes; 1755 std::unique_ptr<ClangASTMetadata> m_metadata_ap; 1756 }; 1757 1758 struct BitfieldInfo 1759 { 1760 uint64_t bit_size; 1761 uint64_t bit_offset; 1762 1763 BitfieldInfo () : 1764 bit_size (LLDB_INVALID_ADDRESS), 1765 bit_offset (LLDB_INVALID_ADDRESS) 1766 { 1767 } 1768 1769 void 1770 Clear() 1771 { 1772 bit_size = LLDB_INVALID_ADDRESS; 1773 bit_offset = LLDB_INVALID_ADDRESS; 1774 } 1775 1776 bool IsValid () 1777 { 1778 return (bit_size != LLDB_INVALID_ADDRESS) && 1779 (bit_offset != LLDB_INVALID_ADDRESS); 1780 } 1781 }; 1782 1783 1784 bool 1785 SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu, 1786 const DWARFDebugInfoEntry *parent_die) 1787 { 1788 if (parent_die) 1789 { 1790 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 1791 { 1792 dw_tag_t tag = die->Tag(); 1793 bool check_virtuality = false; 1794 switch (tag) 1795 { 1796 case DW_TAG_inheritance: 1797 case DW_TAG_subprogram: 1798 check_virtuality = true; 1799 break; 1800 default: 1801 break; 1802 } 1803 if (check_virtuality) 1804 { 1805 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0) 1806 return true; 1807 } 1808 } 1809 } 1810 return false; 1811 } 1812 1813 size_t 1814 SymbolFileDWARF::ParseChildMembers 1815 ( 1816 const SymbolContext& sc, 1817 DWARFCompileUnit* dwarf_cu, 1818 const DWARFDebugInfoEntry *parent_die, 1819 ClangASTType &class_clang_type, 1820 const LanguageType class_language, 1821 std::vector<clang::CXXBaseSpecifier *>& base_classes, 1822 std::vector<int>& member_accessibilities, 1823 DWARFDIECollection& member_function_dies, 1824 DelayedPropertyList& delayed_properties, 1825 AccessType& default_accessibility, 1826 bool &is_a_class, 1827 LayoutInfo &layout_info 1828 ) 1829 { 1830 if (parent_die == NULL) 1831 return 0; 1832 1833 size_t count = 0; 1834 const DWARFDebugInfoEntry *die; 1835 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); 1836 uint32_t member_idx = 0; 1837 BitfieldInfo last_field_info; 1838 ModuleSP module = GetObjectFile()->GetModule(); 1839 1840 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 1841 { 1842 dw_tag_t tag = die->Tag(); 1843 1844 switch (tag) 1845 { 1846 case DW_TAG_member: 1847 case DW_TAG_APPLE_property: 1848 { 1849 DWARFDebugInfoEntry::Attributes attributes; 1850 const size_t num_attributes = die->GetAttributes (this, 1851 dwarf_cu, 1852 fixed_form_sizes, 1853 attributes); 1854 if (num_attributes > 0) 1855 { 1856 Declaration decl; 1857 //DWARFExpression location; 1858 const char *name = NULL; 1859 const char *prop_name = NULL; 1860 const char *prop_getter_name = NULL; 1861 const char *prop_setter_name = NULL; 1862 uint32_t prop_attributes = 0; 1863 1864 1865 bool is_artificial = false; 1866 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 1867 AccessType accessibility = eAccessNone; 1868 uint32_t member_byte_offset = UINT32_MAX; 1869 size_t byte_size = 0; 1870 size_t bit_offset = 0; 1871 size_t bit_size = 0; 1872 bool is_external = false; // On DW_TAG_members, this means the member is static 1873 uint32_t i; 1874 for (i=0; i<num_attributes && !is_artificial; ++i) 1875 { 1876 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1877 DWARFFormValue form_value; 1878 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1879 { 1880 switch (attr) 1881 { 1882 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 1883 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 1884 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 1885 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 1886 case DW_AT_type: encoding_uid = form_value.Reference(); break; 1887 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; 1888 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; 1889 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 1890 case DW_AT_data_member_location: 1891 if (form_value.BlockData()) 1892 { 1893 Value initialValue(0); 1894 Value memberOffset(0); 1895 const DWARFDataExtractor& debug_info_data = get_debug_info_data(); 1896 uint32_t block_length = form_value.Unsigned(); 1897 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 1898 if (DWARFExpression::Evaluate(NULL, // ExecutionContext * 1899 NULL, // ClangExpressionVariableList * 1900 NULL, // ClangExpressionDeclMap * 1901 NULL, // RegisterContext * 1902 module, 1903 debug_info_data, 1904 block_offset, 1905 block_length, 1906 eRegisterKindDWARF, 1907 &initialValue, 1908 memberOffset, 1909 NULL)) 1910 { 1911 member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); 1912 } 1913 } 1914 else 1915 { 1916 // With DWARF 3 and later, if the value is an integer constant, 1917 // this form value is the offset in bytes from the beginning 1918 // of the containing entity. 1919 member_byte_offset = form_value.Unsigned(); 1920 } 1921 break; 1922 1923 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; 1924 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 1925 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break; 1926 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break; 1927 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break; 1928 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; 1929 case DW_AT_external: is_external = form_value.Boolean(); break; 1930 1931 default: 1932 case DW_AT_declaration: 1933 case DW_AT_description: 1934 case DW_AT_mutable: 1935 case DW_AT_visibility: 1936 case DW_AT_sibling: 1937 break; 1938 } 1939 } 1940 } 1941 1942 if (prop_name) 1943 { 1944 ConstString fixed_getter; 1945 ConstString fixed_setter; 1946 1947 // Check if the property getter/setter were provided as full 1948 // names. We want basenames, so we extract them. 1949 1950 if (prop_getter_name && prop_getter_name[0] == '-') 1951 { 1952 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true); 1953 prop_getter_name = prop_getter_method.GetSelector().GetCString(); 1954 } 1955 1956 if (prop_setter_name && prop_setter_name[0] == '-') 1957 { 1958 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true); 1959 prop_setter_name = prop_setter_method.GetSelector().GetCString(); 1960 } 1961 1962 // If the names haven't been provided, they need to be 1963 // filled in. 1964 1965 if (!prop_getter_name) 1966 { 1967 prop_getter_name = prop_name; 1968 } 1969 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) 1970 { 1971 StreamString ss; 1972 1973 ss.Printf("set%c%s:", 1974 toupper(prop_name[0]), 1975 &prop_name[1]); 1976 1977 fixed_setter.SetCString(ss.GetData()); 1978 prop_setter_name = fixed_setter.GetCString(); 1979 } 1980 } 1981 1982 // Clang has a DWARF generation bug where sometimes it 1983 // represents fields that are references with bad byte size 1984 // and bit size/offset information such as: 1985 // 1986 // DW_AT_byte_size( 0x00 ) 1987 // DW_AT_bit_size( 0x40 ) 1988 // DW_AT_bit_offset( 0xffffffffffffffc0 ) 1989 // 1990 // So check the bit offset to make sure it is sane, and if 1991 // the values are not sane, remove them. If we don't do this 1992 // then we will end up with a crash if we try to use this 1993 // type in an expression when clang becomes unhappy with its 1994 // recycled debug info. 1995 1996 if (bit_offset > 128) 1997 { 1998 bit_size = 0; 1999 bit_offset = 0; 2000 } 2001 2002 // FIXME: Make Clang ignore Objective-C accessibility for expressions 2003 if (class_language == eLanguageTypeObjC || 2004 class_language == eLanguageTypeObjC_plus_plus) 2005 accessibility = eAccessNone; 2006 2007 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) 2008 { 2009 // Not all compilers will mark the vtable pointer 2010 // member as artificial (llvm-gcc). We can't have 2011 // the virtual members in our classes otherwise it 2012 // throws off all child offsets since we end up 2013 // having and extra pointer sized member in our 2014 // class layouts. 2015 is_artificial = true; 2016 } 2017 2018 // Handle static members 2019 if (is_external && member_byte_offset == UINT32_MAX) 2020 { 2021 Type *var_type = ResolveTypeUID(encoding_uid); 2022 2023 if (var_type) 2024 { 2025 if (accessibility == eAccessNone) 2026 accessibility = eAccessPublic; 2027 class_clang_type.AddVariableToRecordType (name, 2028 var_type->GetClangLayoutType(), 2029 accessibility); 2030 } 2031 break; 2032 } 2033 2034 if (is_artificial == false) 2035 { 2036 Type *member_type = ResolveTypeUID(encoding_uid); 2037 2038 clang::FieldDecl *field_decl = NULL; 2039 if (tag == DW_TAG_member) 2040 { 2041 if (member_type) 2042 { 2043 if (accessibility == eAccessNone) 2044 accessibility = default_accessibility; 2045 member_accessibilities.push_back(accessibility); 2046 2047 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); 2048 if (bit_size > 0) 2049 { 2050 2051 BitfieldInfo this_field_info; 2052 this_field_info.bit_offset = field_bit_offset; 2053 this_field_info.bit_size = bit_size; 2054 2055 ///////////////////////////////////////////////////////////// 2056 // How to locate a field given the DWARF debug information 2057 // 2058 // AT_byte_size indicates the size of the word in which the 2059 // bit offset must be interpreted. 2060 // 2061 // AT_data_member_location indicates the byte offset of the 2062 // word from the base address of the structure. 2063 // 2064 // AT_bit_offset indicates how many bits into the word 2065 // (according to the host endianness) the low-order bit of 2066 // the field starts. AT_bit_offset can be negative. 2067 // 2068 // AT_bit_size indicates the size of the field in bits. 2069 ///////////////////////////////////////////////////////////// 2070 2071 if (byte_size == 0) 2072 byte_size = member_type->GetByteSize(); 2073 2074 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle) 2075 { 2076 this_field_info.bit_offset += byte_size * 8; 2077 this_field_info.bit_offset -= (bit_offset + bit_size); 2078 } 2079 else 2080 { 2081 this_field_info.bit_offset += bit_offset; 2082 } 2083 2084 // Update the field bit offset we will report for layout 2085 field_bit_offset = this_field_info.bit_offset; 2086 2087 // If the member to be emitted did not start on a character boundary and there is 2088 // empty space between the last field and this one, then we need to emit an 2089 // anonymous member filling up the space up to its start. There are three cases 2090 // here: 2091 // 2092 // 1 If the previous member ended on a character boundary, then we can emit an 2093 // anonymous member starting at the most recent character boundary. 2094 // 2095 // 2 If the previous member did not end on a character boundary and the distance 2096 // from the end of the previous member to the current member is less than a 2097 // word width, then we can emit an anonymous member starting right after the 2098 // previous member and right before this member. 2099 // 2100 // 3 If the previous member did not end on a character boundary and the distance 2101 // from the end of the previous member to the current member is greater than 2102 // or equal a word width, then we act as in Case 1. 2103 2104 const uint64_t character_width = 8; 2105 const uint64_t word_width = 32; 2106 2107 // Objective-C has invalid DW_AT_bit_offset values in older versions 2108 // of clang, so we have to be careful and only insert unnamed bitfields 2109 // if we have a new enough clang. 2110 bool detect_unnamed_bitfields = true; 2111 2112 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) 2113 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields (); 2114 2115 if (detect_unnamed_bitfields) 2116 { 2117 BitfieldInfo anon_field_info; 2118 2119 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned 2120 { 2121 uint64_t last_field_end = 0; 2122 2123 if (last_field_info.IsValid()) 2124 last_field_end = last_field_info.bit_offset + last_field_info.bit_size; 2125 2126 if (this_field_info.bit_offset != last_field_end) 2127 { 2128 if (((last_field_end % character_width) == 0) || // case 1 2129 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 2130 { 2131 anon_field_info.bit_size = this_field_info.bit_offset % character_width; 2132 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; 2133 } 2134 else // case 2 2135 { 2136 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; 2137 anon_field_info.bit_offset = last_field_end; 2138 } 2139 } 2140 } 2141 2142 if (anon_field_info.IsValid()) 2143 { 2144 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL, 2145 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), 2146 accessibility, 2147 anon_field_info.bit_size); 2148 2149 layout_info.field_offsets.insert( 2150 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); 2151 } 2152 } 2153 last_field_info = this_field_info; 2154 } 2155 else 2156 { 2157 last_field_info.Clear(); 2158 } 2159 2160 ClangASTType member_clang_type = member_type->GetClangLayoutType(); 2161 2162 { 2163 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). 2164 // If the current field is at the end of the structure, then there is definitely no room for extra 2165 // elements and we override the type to array[0]. 2166 2167 ClangASTType member_array_element_type; 2168 uint64_t member_array_size; 2169 bool member_array_is_incomplete; 2170 2171 if (member_clang_type.IsArrayType(&member_array_element_type, 2172 &member_array_size, 2173 &member_array_is_incomplete) && 2174 !member_array_is_incomplete) 2175 { 2176 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX); 2177 2178 if (member_byte_offset >= parent_byte_size) 2179 { 2180 if (member_array_size != 1) 2181 { 2182 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, 2183 MakeUserID(die->GetOffset()), 2184 name, 2185 encoding_uid, 2186 MakeUserID(parent_die->GetOffset())); 2187 } 2188 2189 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false); 2190 } 2191 } 2192 } 2193 2194 field_decl = class_clang_type.AddFieldToRecordType (name, 2195 member_clang_type, 2196 accessibility, 2197 bit_size); 2198 2199 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); 2200 2201 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); 2202 } 2203 else 2204 { 2205 if (name) 2206 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed", 2207 MakeUserID(die->GetOffset()), 2208 name, 2209 encoding_uid); 2210 else 2211 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed", 2212 MakeUserID(die->GetOffset()), 2213 encoding_uid); 2214 } 2215 } 2216 2217 if (prop_name != NULL) 2218 { 2219 clang::ObjCIvarDecl *ivar_decl = NULL; 2220 2221 if (field_decl) 2222 { 2223 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); 2224 assert (ivar_decl != NULL); 2225 } 2226 2227 ClangASTMetadata metadata; 2228 metadata.SetUserID (MakeUserID(die->GetOffset())); 2229 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, 2230 prop_name, 2231 member_type->GetClangLayoutType(), 2232 ivar_decl, 2233 prop_setter_name, 2234 prop_getter_name, 2235 prop_attributes, 2236 &metadata)); 2237 2238 if (ivar_decl) 2239 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset())); 2240 } 2241 } 2242 } 2243 ++member_idx; 2244 } 2245 break; 2246 2247 case DW_TAG_subprogram: 2248 // Let the type parsing code handle this one for us. 2249 member_function_dies.Append (die); 2250 break; 2251 2252 case DW_TAG_inheritance: 2253 { 2254 is_a_class = true; 2255 if (default_accessibility == eAccessNone) 2256 default_accessibility = eAccessPrivate; 2257 // TODO: implement DW_TAG_inheritance type parsing 2258 DWARFDebugInfoEntry::Attributes attributes; 2259 const size_t num_attributes = die->GetAttributes (this, 2260 dwarf_cu, 2261 fixed_form_sizes, 2262 attributes); 2263 if (num_attributes > 0) 2264 { 2265 Declaration decl; 2266 DWARFExpression location; 2267 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 2268 AccessType accessibility = default_accessibility; 2269 bool is_virtual = false; 2270 bool is_base_of_class = true; 2271 off_t member_byte_offset = 0; 2272 uint32_t i; 2273 for (i=0; i<num_attributes; ++i) 2274 { 2275 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2276 DWARFFormValue form_value; 2277 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2278 { 2279 switch (attr) 2280 { 2281 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2282 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2283 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2284 case DW_AT_type: encoding_uid = form_value.Reference(); break; 2285 case DW_AT_data_member_location: 2286 if (form_value.BlockData()) 2287 { 2288 Value initialValue(0); 2289 Value memberOffset(0); 2290 const DWARFDataExtractor& debug_info_data = get_debug_info_data(); 2291 uint32_t block_length = form_value.Unsigned(); 2292 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 2293 if (DWARFExpression::Evaluate (NULL, 2294 NULL, 2295 NULL, 2296 NULL, 2297 module, 2298 debug_info_data, 2299 block_offset, 2300 block_length, 2301 eRegisterKindDWARF, 2302 &initialValue, 2303 memberOffset, 2304 NULL)) 2305 { 2306 member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); 2307 } 2308 } 2309 else 2310 { 2311 // With DWARF 3 and later, if the value is an integer constant, 2312 // this form value is the offset in bytes from the beginning 2313 // of the containing entity. 2314 member_byte_offset = form_value.Unsigned(); 2315 } 2316 break; 2317 2318 case DW_AT_accessibility: 2319 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 2320 break; 2321 2322 case DW_AT_virtuality: 2323 is_virtual = form_value.Boolean(); 2324 break; 2325 2326 case DW_AT_sibling: 2327 break; 2328 2329 default: 2330 break; 2331 } 2332 } 2333 } 2334 2335 Type *base_class_type = ResolveTypeUID(encoding_uid); 2336 if (base_class_type == NULL) 2337 { 2338 GetObjectFile()->GetModule()->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve a the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message", 2339 die->GetOffset(), 2340 encoding_uid, 2341 parent_die->GetOffset()); 2342 break; 2343 } 2344 2345 ClangASTType base_class_clang_type = base_class_type->GetClangFullType(); 2346 assert (base_class_clang_type); 2347 if (class_language == eLanguageTypeObjC) 2348 { 2349 class_clang_type.SetObjCSuperClass(base_class_clang_type); 2350 } 2351 else 2352 { 2353 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility, 2354 is_virtual, 2355 is_base_of_class)); 2356 2357 if (is_virtual) 2358 { 2359 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't 2360 // give us a constant offset, but gives us a DWARF expressions that requires an actual object 2361 // in memory. the DW_AT_data_member_location for a virtual base class looks like: 2362 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) 2363 // Given this, there is really no valid response we can give to clang for virtual base 2364 // class offsets, and this should eventually be removed from LayoutRecordType() in the external 2365 // AST source in clang. 2366 } 2367 else 2368 { 2369 layout_info.base_offsets.insert( 2370 std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), 2371 clang::CharUnits::fromQuantity(member_byte_offset))); 2372 } 2373 } 2374 } 2375 } 2376 break; 2377 2378 default: 2379 break; 2380 } 2381 } 2382 2383 return count; 2384 } 2385 2386 2387 clang::DeclContext* 2388 SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) 2389 { 2390 DWARFDebugInfo* debug_info = DebugInfo(); 2391 if (debug_info && UserIDMatches(type_uid)) 2392 { 2393 DWARFCompileUnitSP cu_sp; 2394 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); 2395 if (die) 2396 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); 2397 } 2398 return NULL; 2399 } 2400 2401 clang::DeclContext* 2402 SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) 2403 { 2404 if (UserIDMatches(type_uid)) 2405 return GetClangDeclContextForDIEOffset (sc, type_uid); 2406 return NULL; 2407 } 2408 2409 Type* 2410 SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) 2411 { 2412 if (UserIDMatches(type_uid)) 2413 { 2414 DWARFDebugInfo* debug_info = DebugInfo(); 2415 if (debug_info) 2416 { 2417 DWARFCompileUnitSP cu_sp; 2418 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); 2419 const bool assert_not_being_parsed = true; 2420 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed); 2421 } 2422 } 2423 return NULL; 2424 } 2425 2426 Type* 2427 SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed) 2428 { 2429 if (die != NULL) 2430 { 2431 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 2432 if (log) 2433 GetObjectFile()->GetModule()->LogMessage (log, 2434 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'", 2435 die->GetOffset(), 2436 DW_TAG_value_to_name(die->Tag()), 2437 die->GetName(this, cu)); 2438 2439 // We might be coming in in the middle of a type tree (a class 2440 // withing a class, an enum within a class), so parse any needed 2441 // parent DIEs before we get to this one... 2442 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); 2443 switch (decl_ctx_die->Tag()) 2444 { 2445 case DW_TAG_structure_type: 2446 case DW_TAG_union_type: 2447 case DW_TAG_class_type: 2448 { 2449 // Get the type, which could be a forward declaration 2450 if (log) 2451 GetObjectFile()->GetModule()->LogMessage (log, 2452 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x", 2453 die->GetOffset(), 2454 DW_TAG_value_to_name(die->Tag()), 2455 die->GetName(this, cu), 2456 decl_ctx_die->GetOffset()); 2457 // 2458 // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed); 2459 // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag())) 2460 // { 2461 // if (log) 2462 // GetObjectFile()->GetModule()->LogMessage (log, 2463 // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function", 2464 // die->GetOffset(), 2465 // DW_TAG_value_to_name(die->Tag()), 2466 // die->GetName(this, cu), 2467 // decl_ctx_die->GetOffset()); 2468 // // Ask the type to complete itself if it already hasn't since if we 2469 // // want a function (method or static) from a class, the class must 2470 // // create itself and add it's own methods and class functions. 2471 // if (parent_type) 2472 // parent_type->GetClangFullType(); 2473 // } 2474 } 2475 break; 2476 2477 default: 2478 break; 2479 } 2480 return ResolveType (cu, die); 2481 } 2482 return NULL; 2483 } 2484 2485 // This function is used when SymbolFileDWARFDebugMap owns a bunch of 2486 // SymbolFileDWARF objects to detect if this DWARF file is the one that 2487 // can resolve a clang_type. 2488 bool 2489 SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type) 2490 { 2491 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); 2492 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); 2493 return die != NULL; 2494 } 2495 2496 2497 bool 2498 SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) 2499 { 2500 // We have a struct/union/class/enum that needs to be fully resolved. 2501 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers(); 2502 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType()); 2503 if (die == NULL) 2504 { 2505 // We have already resolved this type... 2506 return true; 2507 } 2508 // Once we start resolving this type, remove it from the forward declaration 2509 // map in case anyone child members or other types require this type to get resolved. 2510 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition 2511 // are done. 2512 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType()); 2513 2514 // Disable external storage for this type so we don't get anymore 2515 // clang::ExternalASTSource queries for this type. 2516 clang_type.SetHasExternalStorage (false); 2517 2518 DWARFDebugInfo* debug_info = DebugInfo(); 2519 2520 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); 2521 Type *type = m_die_to_type.lookup (die); 2522 2523 const dw_tag_t tag = die->Tag(); 2524 2525 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); 2526 if (log) 2527 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, 2528 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", 2529 MakeUserID(die->GetOffset()), 2530 DW_TAG_value_to_name(tag), 2531 type->GetName().AsCString()); 2532 assert (clang_type); 2533 DWARFDebugInfoEntry::Attributes attributes; 2534 2535 switch (tag) 2536 { 2537 case DW_TAG_structure_type: 2538 case DW_TAG_union_type: 2539 case DW_TAG_class_type: 2540 { 2541 LayoutInfo layout_info; 2542 2543 { 2544 if (die->HasChildren()) 2545 { 2546 LanguageType class_language = eLanguageTypeUnknown; 2547 if (clang_type.IsObjCObjectOrInterfaceType()) 2548 { 2549 class_language = eLanguageTypeObjC; 2550 // For objective C we don't start the definition when 2551 // the class is created. 2552 clang_type.StartTagDeclarationDefinition (); 2553 } 2554 2555 int tag_decl_kind = -1; 2556 AccessType default_accessibility = eAccessNone; 2557 if (tag == DW_TAG_structure_type) 2558 { 2559 tag_decl_kind = clang::TTK_Struct; 2560 default_accessibility = eAccessPublic; 2561 } 2562 else if (tag == DW_TAG_union_type) 2563 { 2564 tag_decl_kind = clang::TTK_Union; 2565 default_accessibility = eAccessPublic; 2566 } 2567 else if (tag == DW_TAG_class_type) 2568 { 2569 tag_decl_kind = clang::TTK_Class; 2570 default_accessibility = eAccessPrivate; 2571 } 2572 2573 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); 2574 std::vector<clang::CXXBaseSpecifier *> base_classes; 2575 std::vector<int> member_accessibilities; 2576 bool is_a_class = false; 2577 // Parse members and base classes first 2578 DWARFDIECollection member_function_dies; 2579 2580 DelayedPropertyList delayed_properties; 2581 ParseChildMembers (sc, 2582 dwarf_cu, 2583 die, 2584 clang_type, 2585 class_language, 2586 base_classes, 2587 member_accessibilities, 2588 member_function_dies, 2589 delayed_properties, 2590 default_accessibility, 2591 is_a_class, 2592 layout_info); 2593 2594 // Now parse any methods if there were any... 2595 size_t num_functions = member_function_dies.Size(); 2596 if (num_functions > 0) 2597 { 2598 for (size_t i=0; i<num_functions; ++i) 2599 { 2600 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i)); 2601 } 2602 } 2603 2604 if (class_language == eLanguageTypeObjC) 2605 { 2606 ConstString class_name (clang_type.GetTypeName()); 2607 if (class_name) 2608 { 2609 DIEArray method_die_offsets; 2610 if (m_using_apple_tables) 2611 { 2612 if (m_apple_objc_ap.get()) 2613 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets); 2614 } 2615 else 2616 { 2617 if (!m_indexed) 2618 Index (); 2619 2620 m_objc_class_selectors_index.Find (class_name, method_die_offsets); 2621 } 2622 2623 if (!method_die_offsets.empty()) 2624 { 2625 DWARFDebugInfo* debug_info = DebugInfo(); 2626 2627 DWARFCompileUnit* method_cu = NULL; 2628 const size_t num_matches = method_die_offsets.size(); 2629 for (size_t i=0; i<num_matches; ++i) 2630 { 2631 const dw_offset_t die_offset = method_die_offsets[i]; 2632 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu); 2633 2634 if (method_die) 2635 ResolveType (method_cu, method_die); 2636 else 2637 { 2638 if (m_using_apple_tables) 2639 { 2640 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n", 2641 die_offset, class_name.GetCString()); 2642 } 2643 } 2644 } 2645 } 2646 2647 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); 2648 pi != pe; 2649 ++pi) 2650 pi->Finalize(); 2651 } 2652 } 2653 2654 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we 2655 // need to tell the clang type it is actually a class. 2656 if (class_language != eLanguageTypeObjC) 2657 { 2658 if (is_a_class && tag_decl_kind != clang::TTK_Class) 2659 clang_type.SetTagTypeKind (clang::TTK_Class); 2660 } 2661 2662 // Since DW_TAG_structure_type gets used for both classes 2663 // and structures, we may need to set any DW_TAG_member 2664 // fields to have a "private" access if none was specified. 2665 // When we parsed the child members we tracked that actual 2666 // accessibility value for each DW_TAG_member in the 2667 // "member_accessibilities" array. If the value for the 2668 // member is zero, then it was set to the "default_accessibility" 2669 // which for structs was "public". Below we correct this 2670 // by setting any fields to "private" that weren't correctly 2671 // set. 2672 if (is_a_class && !member_accessibilities.empty()) 2673 { 2674 // This is a class and all members that didn't have 2675 // their access specified are private. 2676 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate, 2677 &member_accessibilities.front(), 2678 member_accessibilities.size()); 2679 } 2680 2681 if (!base_classes.empty()) 2682 { 2683 // Make sure all base classes refer to complete types and not 2684 // forward declarations. If we don't do this, clang will crash 2685 // with an assertion in the call to clang_type.SetBaseClassesForClassType() 2686 bool base_class_error = false; 2687 for (auto &base_class : base_classes) 2688 { 2689 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); 2690 if (type_source_info) 2691 { 2692 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType()); 2693 if (base_class_type.GetCompleteType() == false) 2694 { 2695 if (!base_class_error) 2696 { 2697 GetObjectFile()->GetModule()->ReportError ("DWARF DIE at 0x%8.8x for class '%s' has a base class '%s' that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s", 2698 die->GetOffset(), 2699 die->GetName(this, dwarf_cu), 2700 base_class_type.GetTypeName().GetCString(), 2701 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); 2702 } 2703 // We have no choice other than to pretend that the base class 2704 // is complete. If we don't do this, clang will crash when we 2705 // call setBases() inside of "clang_type.SetBaseClassesForClassType()" 2706 // below. Since we provide layout assistance, all ivars in this 2707 // class and other classes will be fine, this is the best we can do 2708 // short of crashing. 2709 base_class_type.StartTagDeclarationDefinition (); 2710 base_class_type.CompleteTagDeclarationDefinition (); 2711 } 2712 } 2713 } 2714 clang_type.SetBaseClassesForClassType (&base_classes.front(), 2715 base_classes.size()); 2716 2717 // Clang will copy each CXXBaseSpecifier in "base_classes" 2718 // so we have to free them all. 2719 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(), 2720 base_classes.size()); 2721 } 2722 } 2723 } 2724 2725 clang_type.BuildIndirectFields (); 2726 clang_type.CompleteTagDeclarationDefinition (); 2727 2728 if (!layout_info.field_offsets.empty() || 2729 !layout_info.base_offsets.empty() || 2730 !layout_info.vbase_offsets.empty() ) 2731 { 2732 if (type) 2733 layout_info.bit_size = type->GetByteSize() * 8; 2734 if (layout_info.bit_size == 0) 2735 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8; 2736 2737 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl(); 2738 if (record_decl) 2739 { 2740 if (log) 2741 { 2742 GetObjectFile()->GetModule()->LogMessage (log, 2743 "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])", 2744 static_cast<void*>(clang_type.GetOpaqueQualType()), 2745 static_cast<void*>(record_decl), 2746 layout_info.bit_size, 2747 layout_info.alignment, 2748 static_cast<uint32_t>(layout_info.field_offsets.size()), 2749 static_cast<uint32_t>(layout_info.base_offsets.size()), 2750 static_cast<uint32_t>(layout_info.vbase_offsets.size())); 2751 2752 uint32_t idx; 2753 { 2754 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos, 2755 end = layout_info.field_offsets.end(); 2756 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) 2757 { 2758 GetObjectFile()->GetModule()->LogMessage( 2759 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = " 2760 "{ bit_offset=%u, name='%s' }", 2761 static_cast<void *>(clang_type.GetOpaqueQualType()), idx, 2762 static_cast<uint32_t>(pos->second), pos->first->getNameAsString().c_str()); 2763 } 2764 } 2765 2766 { 2767 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, 2768 base_end = layout_info.base_offsets.end(); 2769 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; 2770 ++base_pos, ++idx) 2771 { 2772 GetObjectFile()->GetModule()->LogMessage( 2773 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] " 2774 "= { byte_offset=%u, name='%s' }", 2775 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(), 2776 base_pos->first->getNameAsString().c_str()); 2777 } 2778 } 2779 { 2780 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, 2781 vbase_end = layout_info.vbase_offsets.end(); 2782 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; 2783 ++vbase_pos, ++idx) 2784 { 2785 GetObjectFile()->GetModule()->LogMessage( 2786 log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) " 2787 "vbase[%u] = { byte_offset=%u, name='%s' }", 2788 static_cast<void *>(clang_type.GetOpaqueQualType()), idx, 2789 static_cast<uint32_t>(vbase_pos->second.getQuantity()), 2790 vbase_pos->first->getNameAsString().c_str()); 2791 } 2792 } 2793 } 2794 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); 2795 } 2796 } 2797 } 2798 2799 return (bool)clang_type; 2800 2801 case DW_TAG_enumeration_type: 2802 clang_type.StartTagDeclarationDefinition (); 2803 if (die->HasChildren()) 2804 { 2805 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); 2806 bool is_signed = false; 2807 clang_type.IsIntegerType(is_signed); 2808 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die); 2809 } 2810 clang_type.CompleteTagDeclarationDefinition (); 2811 return (bool)clang_type; 2812 2813 default: 2814 assert(false && "not a forward clang type decl!"); 2815 break; 2816 } 2817 return false; 2818 } 2819 2820 Type* 2821 SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) 2822 { 2823 if (type_die != NULL) 2824 { 2825 Type *type = m_die_to_type.lookup (type_die); 2826 2827 if (type == NULL) 2828 type = GetTypeForDIE (dwarf_cu, type_die).get(); 2829 2830 if (assert_not_being_parsed) 2831 { 2832 if (type != DIE_IS_BEING_PARSED) 2833 return type; 2834 2835 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s", 2836 type_die->GetOffset(), 2837 DW_TAG_value_to_name(type_die->Tag()), 2838 type_die->GetName(this, dwarf_cu)); 2839 2840 } 2841 else 2842 return type; 2843 } 2844 return NULL; 2845 } 2846 2847 CompileUnit* 2848 SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx) 2849 { 2850 // Check if the symbol vendor already knows about this compile unit? 2851 if (dwarf_cu->GetUserData() == NULL) 2852 { 2853 // The symbol vendor doesn't know about this compile unit, we 2854 // need to parse and add it to the symbol vendor object. 2855 return ParseCompileUnit(dwarf_cu, cu_idx).get(); 2856 } 2857 return (CompileUnit*)dwarf_cu->GetUserData(); 2858 } 2859 2860 bool 2861 SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) 2862 { 2863 sc.Clear(false); 2864 // Check if the symbol vendor already knows about this compile unit? 2865 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 2866 2867 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get(); 2868 if (sc.function == NULL) 2869 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die); 2870 2871 if (sc.function) 2872 { 2873 sc.module_sp = sc.function->CalculateSymbolContextModule(); 2874 return true; 2875 } 2876 2877 return false; 2878 } 2879 2880 void 2881 SymbolFileDWARF::UpdateExternalModuleListIfNeeded() 2882 { 2883 if (m_fetched_external_modules) 2884 return; 2885 m_fetched_external_modules = true; 2886 2887 DWARFDebugInfo * debug_info = DebugInfo(); 2888 debug_info->GetNumCompileUnits(); 2889 2890 const uint32_t num_compile_units = GetNumCompileUnits(); 2891 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) 2892 { 2893 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); 2894 2895 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly(); 2896 if (die && die->HasChildren() == false) 2897 { 2898 const uint64_t name_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_name, UINT64_MAX); 2899 const uint64_t dwo_path_strp = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_GNU_dwo_name, UINT64_MAX); 2900 2901 if (name_strp != UINT64_MAX) 2902 { 2903 if (m_external_type_modules.find(dwo_path_strp) == m_external_type_modules.end()) 2904 { 2905 const char *name = get_debug_str_data().PeekCStr(name_strp); 2906 const char *dwo_path = get_debug_str_data().PeekCStr(dwo_path_strp); 2907 if (name || dwo_path) 2908 { 2909 ModuleSP module_sp; 2910 if (dwo_path) 2911 { 2912 ModuleSpec dwo_module_spec; 2913 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false); 2914 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture(); 2915 //printf ("Loading dwo = '%s'\n", dwo_path); 2916 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL); 2917 } 2918 2919 if (dwo_path_strp != LLDB_INVALID_UID) 2920 { 2921 m_external_type_modules[dwo_path_strp] = ClangModuleInfo { ConstString(name), module_sp }; 2922 } 2923 else 2924 { 2925 // This hack should be removed promptly once clang emits both. 2926 m_external_type_modules[name_strp] = ClangModuleInfo { ConstString(name), module_sp }; 2927 } 2928 } 2929 } 2930 } 2931 } 2932 } 2933 } 2934 2935 SymbolFileDWARF::GlobalVariableMap & 2936 SymbolFileDWARF::GetGlobalAranges() 2937 { 2938 if (!m_global_aranges_ap) 2939 { 2940 m_global_aranges_ap.reset (new GlobalVariableMap()); 2941 2942 ModuleSP module_sp = GetObjectFile()->GetModule(); 2943 if (module_sp) 2944 { 2945 const size_t num_cus = module_sp->GetNumCompileUnits(); 2946 for (size_t i = 0; i < num_cus; ++i) 2947 { 2948 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i); 2949 if (cu_sp) 2950 { 2951 VariableListSP globals_sp = cu_sp->GetVariableList(true); 2952 if (globals_sp) 2953 { 2954 const size_t num_globals = globals_sp->GetSize(); 2955 for (size_t g = 0; g < num_globals; ++g) 2956 { 2957 VariableSP var_sp = globals_sp->GetVariableAtIndex(g); 2958 if (var_sp && !var_sp->GetLocationIsConstantValueData()) 2959 { 2960 const DWARFExpression &location = var_sp->LocationExpression(); 2961 Value location_result; 2962 Error error; 2963 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error)) 2964 { 2965 if (location_result.GetValueType() == Value::eValueTypeFileAddress) 2966 { 2967 lldb::addr_t file_addr = location_result.GetScalar().ULongLong(); 2968 lldb::addr_t byte_size = 1; 2969 if (var_sp->GetType()) 2970 byte_size = var_sp->GetType()->GetByteSize(); 2971 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get())); 2972 } 2973 } 2974 } 2975 } 2976 } 2977 } 2978 } 2979 } 2980 m_global_aranges_ap->Sort(); 2981 } 2982 return *m_global_aranges_ap; 2983 } 2984 2985 2986 uint32_t 2987 SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) 2988 { 2989 Timer scoped_timer(__PRETTY_FUNCTION__, 2990 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)", 2991 static_cast<void*>(so_addr.GetSection().get()), 2992 so_addr.GetOffset(), resolve_scope); 2993 uint32_t resolved = 0; 2994 if (resolve_scope & ( eSymbolContextCompUnit | 2995 eSymbolContextFunction | 2996 eSymbolContextBlock | 2997 eSymbolContextLineEntry | 2998 eSymbolContextVariable )) 2999 { 3000 lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); 3001 3002 DWARFDebugInfo* debug_info = DebugInfo(); 3003 if (debug_info) 3004 { 3005 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr); 3006 if (cu_offset == DW_INVALID_OFFSET) 3007 { 3008 // Global variables are not in the compile unit address ranges. The only way to 3009 // currently find global variables is to iterate over the .debug_pubnames or the 3010 // __apple_names table and find all items in there that point to DW_TAG_variable 3011 // DIEs and then find the address that matches. 3012 if (resolve_scope & eSymbolContextVariable) 3013 { 3014 GlobalVariableMap &map = GetGlobalAranges(); 3015 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr); 3016 if (entry && entry->data) 3017 { 3018 Variable *variable = entry->data; 3019 SymbolContextScope *scc = variable->GetSymbolContextScope(); 3020 if (scc) 3021 { 3022 scc->CalculateSymbolContext(&sc); 3023 sc.variable = variable; 3024 } 3025 return sc.GetResolvedMask(); 3026 } 3027 } 3028 } 3029 else 3030 { 3031 uint32_t cu_idx = DW_INVALID_INDEX; 3032 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); 3033 if (dwarf_cu) 3034 { 3035 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); 3036 if (sc.comp_unit) 3037 { 3038 resolved |= eSymbolContextCompUnit; 3039 3040 bool force_check_line_table = false; 3041 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) 3042 { 3043 DWARFDebugInfoEntry *function_die = NULL; 3044 DWARFDebugInfoEntry *block_die = NULL; 3045 if (resolve_scope & eSymbolContextBlock) 3046 { 3047 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die); 3048 } 3049 else 3050 { 3051 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL); 3052 } 3053 3054 if (function_die != NULL) 3055 { 3056 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); 3057 if (sc.function == NULL) 3058 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); 3059 } 3060 else 3061 { 3062 // We might have had a compile unit that had discontiguous 3063 // address ranges where the gaps are symbols that don't have 3064 // any debug info. Discontiguous compile unit address ranges 3065 // should only happen when there aren't other functions from 3066 // other compile units in these gaps. This helps keep the size 3067 // of the aranges down. 3068 force_check_line_table = true; 3069 } 3070 3071 if (sc.function != NULL) 3072 { 3073 resolved |= eSymbolContextFunction; 3074 3075 if (resolve_scope & eSymbolContextBlock) 3076 { 3077 Block& block = sc.function->GetBlock (true); 3078 3079 if (block_die != NULL) 3080 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); 3081 else 3082 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); 3083 if (sc.block) 3084 resolved |= eSymbolContextBlock; 3085 } 3086 } 3087 } 3088 3089 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table) 3090 { 3091 LineTable *line_table = sc.comp_unit->GetLineTable(); 3092 if (line_table != NULL) 3093 { 3094 // And address that makes it into this function should be in terms 3095 // of this debug file if there is no debug map, or it will be an 3096 // address in the .o file which needs to be fixed up to be in terms 3097 // of the debug map executable. Either way, calling FixupAddress() 3098 // will work for us. 3099 Address exe_so_addr (so_addr); 3100 if (FixupAddress(exe_so_addr)) 3101 { 3102 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry)) 3103 { 3104 resolved |= eSymbolContextLineEntry; 3105 } 3106 } 3107 } 3108 } 3109 3110 if (force_check_line_table && !(resolved & eSymbolContextLineEntry)) 3111 { 3112 // We might have had a compile unit that had discontiguous 3113 // address ranges where the gaps are symbols that don't have 3114 // any debug info. Discontiguous compile unit address ranges 3115 // should only happen when there aren't other functions from 3116 // other compile units in these gaps. This helps keep the size 3117 // of the aranges down. 3118 sc.comp_unit = NULL; 3119 resolved &= ~eSymbolContextCompUnit; 3120 } 3121 } 3122 else 3123 { 3124 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.", 3125 cu_offset, 3126 cu_idx); 3127 } 3128 } 3129 } 3130 } 3131 } 3132 return resolved; 3133 } 3134 3135 3136 3137 uint32_t 3138 SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 3139 { 3140 const uint32_t prev_size = sc_list.GetSize(); 3141 if (resolve_scope & eSymbolContextCompUnit) 3142 { 3143 DWARFDebugInfo* debug_info = DebugInfo(); 3144 if (debug_info) 3145 { 3146 uint32_t cu_idx; 3147 DWARFCompileUnit* dwarf_cu = NULL; 3148 3149 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) 3150 { 3151 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); 3152 const bool full_match = (bool)file_spec.GetDirectory(); 3153 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match); 3154 if (check_inlines || file_spec_matches_cu_file_spec) 3155 { 3156 SymbolContext sc (m_obj_file->GetModule()); 3157 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx); 3158 if (sc.comp_unit) 3159 { 3160 uint32_t file_idx = UINT32_MAX; 3161 3162 // If we are looking for inline functions only and we don't 3163 // find it in the support files, we are done. 3164 if (check_inlines) 3165 { 3166 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); 3167 if (file_idx == UINT32_MAX) 3168 continue; 3169 } 3170 3171 if (line != 0) 3172 { 3173 LineTable *line_table = sc.comp_unit->GetLineTable(); 3174 3175 if (line_table != NULL && line != 0) 3176 { 3177 // We will have already looked up the file index if 3178 // we are searching for inline entries. 3179 if (!check_inlines) 3180 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true); 3181 3182 if (file_idx != UINT32_MAX) 3183 { 3184 uint32_t found_line; 3185 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); 3186 found_line = sc.line_entry.line; 3187 3188 while (line_idx != UINT32_MAX) 3189 { 3190 sc.function = NULL; 3191 sc.block = NULL; 3192 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) 3193 { 3194 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); 3195 if (file_vm_addr != LLDB_INVALID_ADDRESS) 3196 { 3197 DWARFDebugInfoEntry *function_die = NULL; 3198 DWARFDebugInfoEntry *block_die = NULL; 3199 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); 3200 3201 if (function_die != NULL) 3202 { 3203 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get(); 3204 if (sc.function == NULL) 3205 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die); 3206 } 3207 3208 if (sc.function != NULL) 3209 { 3210 Block& block = sc.function->GetBlock (true); 3211 3212 if (block_die != NULL) 3213 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset())); 3214 else if (function_die != NULL) 3215 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset())); 3216 } 3217 } 3218 } 3219 3220 sc_list.Append(sc); 3221 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); 3222 } 3223 } 3224 } 3225 else if (file_spec_matches_cu_file_spec && !check_inlines) 3226 { 3227 // only append the context if we aren't looking for inline call sites 3228 // by file and line and if the file spec matches that of the compile unit 3229 sc_list.Append(sc); 3230 } 3231 } 3232 else if (file_spec_matches_cu_file_spec && !check_inlines) 3233 { 3234 // only append the context if we aren't looking for inline call sites 3235 // by file and line and if the file spec matches that of the compile unit 3236 sc_list.Append(sc); 3237 } 3238 3239 if (!check_inlines) 3240 break; 3241 } 3242 } 3243 } 3244 } 3245 } 3246 return sc_list.GetSize() - prev_size; 3247 } 3248 3249 void 3250 SymbolFileDWARF::Index () 3251 { 3252 if (m_indexed) 3253 return; 3254 m_indexed = true; 3255 Timer scoped_timer (__PRETTY_FUNCTION__, 3256 "SymbolFileDWARF::Index (%s)", 3257 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>")); 3258 3259 DWARFDebugInfo* debug_info = DebugInfo(); 3260 if (debug_info) 3261 { 3262 uint32_t cu_idx = 0; 3263 const uint32_t num_compile_units = GetNumCompileUnits(); 3264 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) 3265 { 3266 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); 3267 3268 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1; 3269 3270 dwarf_cu->Index (cu_idx, 3271 m_function_basename_index, 3272 m_function_fullname_index, 3273 m_function_method_index, 3274 m_function_selector_index, 3275 m_objc_class_selectors_index, 3276 m_global_index, 3277 m_type_index, 3278 m_namespace_index); 3279 3280 // Keep memory down by clearing DIEs if this generate function 3281 // caused them to be parsed 3282 if (clear_dies) 3283 dwarf_cu->ClearDIEs (true); 3284 } 3285 3286 m_function_basename_index.Finalize(); 3287 m_function_fullname_index.Finalize(); 3288 m_function_method_index.Finalize(); 3289 m_function_selector_index.Finalize(); 3290 m_objc_class_selectors_index.Finalize(); 3291 m_global_index.Finalize(); 3292 m_type_index.Finalize(); 3293 m_namespace_index.Finalize(); 3294 3295 #if defined (ENABLE_DEBUG_PRINTF) 3296 StreamFile s(stdout, false); 3297 s.Printf ("DWARF index for '%s':", 3298 GetObjectFile()->GetFileSpec().GetPath().c_str()); 3299 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); 3300 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); 3301 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); 3302 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); 3303 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); 3304 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); 3305 s.Printf("\nTypes:\n"); m_type_index.Dump (&s); 3306 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); 3307 #endif 3308 } 3309 } 3310 3311 bool 3312 SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl) 3313 { 3314 if (namespace_decl == NULL) 3315 { 3316 // Invalid namespace decl which means we aren't matching only things 3317 // in this symbol file, so return true to indicate it matches this 3318 // symbol file. 3319 return true; 3320 } 3321 3322 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext(); 3323 3324 if (namespace_ast == NULL) 3325 return true; // No AST in the "namespace_decl", return true since it 3326 // could then match any symbol file, including this one 3327 3328 if (namespace_ast == GetClangASTContext().getASTContext()) 3329 return true; // The ASTs match, return true 3330 3331 // The namespace AST was valid, and it does not match... 3332 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3333 3334 if (log) 3335 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file"); 3336 3337 return false; 3338 } 3339 3340 bool 3341 SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl, 3342 DWARFCompileUnit* cu, 3343 const DWARFDebugInfoEntry* die) 3344 { 3345 // No namespace specified, so the answer is 3346 if (namespace_decl == NULL) 3347 return true; 3348 3349 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3350 3351 const DWARFDebugInfoEntry *decl_ctx_die = NULL; 3352 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die); 3353 if (decl_ctx_die) 3354 { 3355 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl(); 3356 3357 if (clang_namespace_decl) 3358 { 3359 if (decl_ctx_die->Tag() != DW_TAG_namespace) 3360 { 3361 if (log) 3362 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace"); 3363 return false; 3364 } 3365 3366 if (clang_namespace_decl == die_clang_decl_ctx) 3367 return true; 3368 else 3369 return false; 3370 } 3371 else 3372 { 3373 // We have a namespace_decl that was not NULL but it contained 3374 // a NULL "clang::NamespaceDecl", so this means the global namespace 3375 // So as long the contained decl context DIE isn't a namespace 3376 // we should be ok. 3377 if (decl_ctx_die->Tag() != DW_TAG_namespace) 3378 return true; 3379 } 3380 } 3381 3382 if (log) 3383 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist"); 3384 3385 return false; 3386 } 3387 uint32_t 3388 SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) 3389 { 3390 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3391 3392 if (log) 3393 GetObjectFile()->GetModule()->LogMessage (log, 3394 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", 3395 name.GetCString(), 3396 static_cast<const void*>(namespace_decl), 3397 append, max_matches); 3398 3399 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) 3400 return 0; 3401 3402 DWARFDebugInfo* info = DebugInfo(); 3403 if (info == NULL) 3404 return 0; 3405 3406 // If we aren't appending the results to this list, then clear the list 3407 if (!append) 3408 variables.Clear(); 3409 3410 // Remember how many variables are in the list before we search in case 3411 // we are appending the results to a variable list. 3412 const uint32_t original_size = variables.GetSize(); 3413 3414 DIEArray die_offsets; 3415 3416 if (m_using_apple_tables) 3417 { 3418 if (m_apple_names_ap.get()) 3419 { 3420 const char *name_cstr = name.GetCString(); 3421 llvm::StringRef basename; 3422 llvm::StringRef context; 3423 3424 if (!CPPLanguageRuntime::ExtractContextAndIdentifier(name_cstr, context, basename)) 3425 basename = name_cstr; 3426 3427 m_apple_names_ap->FindByName (basename.data(), die_offsets); 3428 } 3429 } 3430 else 3431 { 3432 // Index the DWARF if we haven't already 3433 if (!m_indexed) 3434 Index (); 3435 3436 m_global_index.Find (name, die_offsets); 3437 } 3438 3439 const size_t num_die_matches = die_offsets.size(); 3440 if (num_die_matches) 3441 { 3442 SymbolContext sc; 3443 sc.module_sp = m_obj_file->GetModule(); 3444 assert (sc.module_sp); 3445 3446 DWARFDebugInfo* debug_info = DebugInfo(); 3447 DWARFCompileUnit* dwarf_cu = NULL; 3448 const DWARFDebugInfoEntry* die = NULL; 3449 bool done = false; 3450 for (size_t i=0; i<num_die_matches && !done; ++i) 3451 { 3452 const dw_offset_t die_offset = die_offsets[i]; 3453 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3454 3455 if (die) 3456 { 3457 switch (die->Tag()) 3458 { 3459 default: 3460 case DW_TAG_subprogram: 3461 case DW_TAG_inlined_subroutine: 3462 case DW_TAG_try_block: 3463 case DW_TAG_catch_block: 3464 break; 3465 3466 case DW_TAG_variable: 3467 { 3468 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 3469 3470 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3471 continue; 3472 3473 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); 3474 3475 if (variables.GetSize() - original_size >= max_matches) 3476 done = true; 3477 } 3478 break; 3479 } 3480 } 3481 else 3482 { 3483 if (m_using_apple_tables) 3484 { 3485 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n", 3486 die_offset, name.GetCString()); 3487 } 3488 } 3489 } 3490 } 3491 3492 // Return the number of variable that were appended to the list 3493 const uint32_t num_matches = variables.GetSize() - original_size; 3494 if (log && num_matches > 0) 3495 { 3496 GetObjectFile()->GetModule()->LogMessage (log, 3497 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u", 3498 name.GetCString(), 3499 static_cast<const void*>(namespace_decl), 3500 append, max_matches, 3501 num_matches); 3502 } 3503 return num_matches; 3504 } 3505 3506 uint32_t 3507 SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) 3508 { 3509 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3510 3511 if (log) 3512 { 3513 GetObjectFile()->GetModule()->LogMessage (log, 3514 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", 3515 regex.GetText(), append, 3516 max_matches); 3517 } 3518 3519 DWARFDebugInfo* info = DebugInfo(); 3520 if (info == NULL) 3521 return 0; 3522 3523 // If we aren't appending the results to this list, then clear the list 3524 if (!append) 3525 variables.Clear(); 3526 3527 // Remember how many variables are in the list before we search in case 3528 // we are appending the results to a variable list. 3529 const uint32_t original_size = variables.GetSize(); 3530 3531 DIEArray die_offsets; 3532 3533 if (m_using_apple_tables) 3534 { 3535 if (m_apple_names_ap.get()) 3536 { 3537 DWARFMappedHash::DIEInfoArray hash_data_array; 3538 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) 3539 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); 3540 } 3541 } 3542 else 3543 { 3544 // Index the DWARF if we haven't already 3545 if (!m_indexed) 3546 Index (); 3547 3548 m_global_index.Find (regex, die_offsets); 3549 } 3550 3551 SymbolContext sc; 3552 sc.module_sp = m_obj_file->GetModule(); 3553 assert (sc.module_sp); 3554 3555 DWARFCompileUnit* dwarf_cu = NULL; 3556 const DWARFDebugInfoEntry* die = NULL; 3557 const size_t num_matches = die_offsets.size(); 3558 if (num_matches) 3559 { 3560 DWARFDebugInfo* debug_info = DebugInfo(); 3561 for (size_t i=0; i<num_matches; ++i) 3562 { 3563 const dw_offset_t die_offset = die_offsets[i]; 3564 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3565 3566 if (die) 3567 { 3568 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 3569 3570 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); 3571 3572 if (variables.GetSize() - original_size >= max_matches) 3573 break; 3574 } 3575 else 3576 { 3577 if (m_using_apple_tables) 3578 { 3579 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n", 3580 die_offset, regex.GetText()); 3581 } 3582 } 3583 } 3584 } 3585 3586 // Return the number of variable that were appended to the list 3587 return variables.GetSize() - original_size; 3588 } 3589 3590 3591 bool 3592 SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset, 3593 DWARFCompileUnit *&dwarf_cu, 3594 bool include_inlines, 3595 SymbolContextList& sc_list) 3596 { 3597 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3598 return ResolveFunction (dwarf_cu, die, include_inlines, sc_list); 3599 } 3600 3601 3602 bool 3603 SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu, 3604 const DWARFDebugInfoEntry *die, 3605 bool include_inlines, 3606 SymbolContextList& sc_list) 3607 { 3608 SymbolContext sc; 3609 3610 if (die == NULL) 3611 return false; 3612 3613 // If we were passed a die that is not a function, just return false... 3614 if (! (die->Tag() == DW_TAG_subprogram || (include_inlines && die->Tag() == DW_TAG_inlined_subroutine))) 3615 return false; 3616 3617 const DWARFDebugInfoEntry* inlined_die = NULL; 3618 if (die->Tag() == DW_TAG_inlined_subroutine) 3619 { 3620 inlined_die = die; 3621 3622 while ((die = die->GetParent()) != NULL) 3623 { 3624 if (die->Tag() == DW_TAG_subprogram) 3625 break; 3626 } 3627 } 3628 assert (die && die->Tag() == DW_TAG_subprogram); 3629 if (GetFunction (cu, die, sc)) 3630 { 3631 Address addr; 3632 // Parse all blocks if needed 3633 if (inlined_die) 3634 { 3635 Block &function_block = sc.function->GetBlock (true); 3636 sc.block = function_block.FindBlockByID (MakeUserID(inlined_die->GetOffset())); 3637 if (sc.block == NULL) 3638 sc.block = function_block.FindBlockByID (inlined_die->GetOffset()); 3639 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false) 3640 addr.Clear(); 3641 } 3642 else 3643 { 3644 sc.block = NULL; 3645 addr = sc.function->GetAddressRange().GetBaseAddress(); 3646 } 3647 3648 if (addr.IsValid()) 3649 { 3650 sc_list.Append(sc); 3651 return true; 3652 } 3653 } 3654 3655 return false; 3656 } 3657 3658 void 3659 SymbolFileDWARF::FindFunctions (const ConstString &name, 3660 const NameToDIE &name_to_die, 3661 bool include_inlines, 3662 SymbolContextList& sc_list) 3663 { 3664 DIEArray die_offsets; 3665 if (name_to_die.Find (name, die_offsets)) 3666 { 3667 ParseFunctions (die_offsets, include_inlines, sc_list); 3668 } 3669 } 3670 3671 3672 void 3673 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, 3674 const NameToDIE &name_to_die, 3675 bool include_inlines, 3676 SymbolContextList& sc_list) 3677 { 3678 DIEArray die_offsets; 3679 if (name_to_die.Find (regex, die_offsets)) 3680 { 3681 ParseFunctions (die_offsets, include_inlines, sc_list); 3682 } 3683 } 3684 3685 3686 void 3687 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex, 3688 const DWARFMappedHash::MemoryTable &memory_table, 3689 bool include_inlines, 3690 SymbolContextList& sc_list) 3691 { 3692 DIEArray die_offsets; 3693 DWARFMappedHash::DIEInfoArray hash_data_array; 3694 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array)) 3695 { 3696 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); 3697 ParseFunctions (die_offsets, include_inlines, sc_list); 3698 } 3699 } 3700 3701 void 3702 SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets, 3703 bool include_inlines, 3704 SymbolContextList& sc_list) 3705 { 3706 const size_t num_matches = die_offsets.size(); 3707 if (num_matches) 3708 { 3709 DWARFCompileUnit* dwarf_cu = NULL; 3710 for (size_t i=0; i<num_matches; ++i) 3711 { 3712 const dw_offset_t die_offset = die_offsets[i]; 3713 ResolveFunction (die_offset, dwarf_cu, include_inlines, sc_list); 3714 } 3715 } 3716 } 3717 3718 bool 3719 SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die, 3720 const DWARFCompileUnit *dwarf_cu, 3721 uint32_t name_type_mask, 3722 const char *partial_name, 3723 const char *base_name_start, 3724 const char *base_name_end) 3725 { 3726 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes: 3727 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase) 3728 { 3729 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset()); 3730 if (!containing_decl_ctx) 3731 return false; 3732 3733 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()); 3734 3735 if (name_type_mask == eFunctionNameTypeMethod) 3736 { 3737 if (is_cxx_method == false) 3738 return false; 3739 } 3740 3741 if (name_type_mask == eFunctionNameTypeBase) 3742 { 3743 if (is_cxx_method == true) 3744 return false; 3745 } 3746 } 3747 3748 // Now we need to check whether the name we got back for this type matches the extra specifications 3749 // that were in the name we're looking up: 3750 if (base_name_start != partial_name || *base_name_end != '\0') 3751 { 3752 // First see if the stuff to the left matches the full name. To do that let's see if 3753 // we can pull out the mips linkage name attribute: 3754 3755 Mangled best_name; 3756 DWARFDebugInfoEntry::Attributes attributes; 3757 DWARFFormValue form_value; 3758 die->GetAttributes(this, dwarf_cu, NULL, attributes); 3759 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name); 3760 if (idx == UINT32_MAX) 3761 idx = attributes.FindAttributeIndex(DW_AT_linkage_name); 3762 if (idx != UINT32_MAX) 3763 { 3764 if (attributes.ExtractFormValueAtIndex(this, idx, form_value)) 3765 { 3766 const char *mangled_name = form_value.AsCString(&get_debug_str_data()); 3767 if (mangled_name) 3768 best_name.SetValue (ConstString(mangled_name), true); 3769 } 3770 } 3771 3772 if (!best_name) 3773 { 3774 idx = attributes.FindAttributeIndex(DW_AT_name); 3775 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value)) 3776 { 3777 const char *name = form_value.AsCString(&get_debug_str_data()); 3778 best_name.SetValue (ConstString(name), false); 3779 } 3780 } 3781 3782 if (best_name.GetDemangledName()) 3783 { 3784 const char *demangled = best_name.GetDemangledName().GetCString(); 3785 if (demangled) 3786 { 3787 std::string name_no_parens(partial_name, base_name_end - partial_name); 3788 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str()); 3789 if (partial_in_demangled == NULL) 3790 return false; 3791 else 3792 { 3793 // Sort out the case where our name is something like "Process::Destroy" and the match is 3794 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on 3795 // namespace boundaries... 3796 3797 if (partial_name[0] == ':' && partial_name[1] == ':') 3798 { 3799 // The partial name was already on a namespace boundary so all matches are good. 3800 return true; 3801 } 3802 else if (partial_in_demangled == demangled) 3803 { 3804 // They both start the same, so this is an good match. 3805 return true; 3806 } 3807 else 3808 { 3809 if (partial_in_demangled - demangled == 1) 3810 { 3811 // Only one character difference, can't be a namespace boundary... 3812 return false; 3813 } 3814 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':') 3815 { 3816 // We are on a namespace boundary, so this is also good. 3817 return true; 3818 } 3819 else 3820 return false; 3821 } 3822 } 3823 } 3824 } 3825 } 3826 3827 return true; 3828 } 3829 3830 uint32_t 3831 SymbolFileDWARF::FindFunctions (const ConstString &name, 3832 const lldb_private::ClangNamespaceDecl *namespace_decl, 3833 uint32_t name_type_mask, 3834 bool include_inlines, 3835 bool append, 3836 SymbolContextList& sc_list) 3837 { 3838 Timer scoped_timer (__PRETTY_FUNCTION__, 3839 "SymbolFileDWARF::FindFunctions (name = '%s')", 3840 name.AsCString()); 3841 3842 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() 3843 assert ((name_type_mask & eFunctionNameTypeAuto) == 0); 3844 3845 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 3846 3847 if (log) 3848 { 3849 GetObjectFile()->GetModule()->LogMessage (log, 3850 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", 3851 name.GetCString(), 3852 name_type_mask, 3853 append); 3854 } 3855 3856 // If we aren't appending the results to this list, then clear the list 3857 if (!append) 3858 sc_list.Clear(); 3859 3860 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) 3861 return 0; 3862 3863 // If name is empty then we won't find anything. 3864 if (name.IsEmpty()) 3865 return 0; 3866 3867 // Remember how many sc_list are in the list before we search in case 3868 // we are appending the results to a variable list. 3869 3870 const char *name_cstr = name.GetCString(); 3871 3872 const uint32_t original_size = sc_list.GetSize(); 3873 3874 DWARFDebugInfo* info = DebugInfo(); 3875 if (info == NULL) 3876 return 0; 3877 3878 DWARFCompileUnit *dwarf_cu = NULL; 3879 std::set<const DWARFDebugInfoEntry *> resolved_dies; 3880 if (m_using_apple_tables) 3881 { 3882 if (m_apple_names_ap.get()) 3883 { 3884 3885 DIEArray die_offsets; 3886 3887 uint32_t num_matches = 0; 3888 3889 if (name_type_mask & eFunctionNameTypeFull) 3890 { 3891 // If they asked for the full name, match what they typed. At some point we may 3892 // want to canonicalize this (strip double spaces, etc. For now, we just add all the 3893 // dies that we find by exact match. 3894 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); 3895 for (uint32_t i = 0; i < num_matches; i++) 3896 { 3897 const dw_offset_t die_offset = die_offsets[i]; 3898 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3899 if (die) 3900 { 3901 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3902 continue; 3903 3904 if (resolved_dies.find(die) == resolved_dies.end()) 3905 { 3906 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) 3907 resolved_dies.insert(die); 3908 } 3909 } 3910 else 3911 { 3912 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", 3913 die_offset, name_cstr); 3914 } 3915 } 3916 } 3917 3918 if (name_type_mask & eFunctionNameTypeSelector) 3919 { 3920 if (namespace_decl && *namespace_decl) 3921 return 0; // no selectors in namespaces 3922 3923 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); 3924 // Now make sure these are actually ObjC methods. In this case we can simply look up the name, 3925 // and if it is an ObjC method name, we're good. 3926 3927 for (uint32_t i = 0; i < num_matches; i++) 3928 { 3929 const dw_offset_t die_offset = die_offsets[i]; 3930 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3931 if (die) 3932 { 3933 const char *die_name = die->GetName(this, dwarf_cu); 3934 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name)) 3935 { 3936 if (resolved_dies.find(die) == resolved_dies.end()) 3937 { 3938 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) 3939 resolved_dies.insert(die); 3940 } 3941 } 3942 } 3943 else 3944 { 3945 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", 3946 die_offset, name_cstr); 3947 } 3948 } 3949 die_offsets.clear(); 3950 } 3951 3952 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase) 3953 { 3954 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to 3955 // extract the base name, look that up, and if there is any other information in the name we were 3956 // passed in we have to post-filter based on that. 3957 3958 // FIXME: Arrange the logic above so that we don't calculate the base name twice: 3959 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets); 3960 3961 for (uint32_t i = 0; i < num_matches; i++) 3962 { 3963 const dw_offset_t die_offset = die_offsets[i]; 3964 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 3965 if (die) 3966 { 3967 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 3968 continue; 3969 3970 // If we get to here, the die is good, and we should add it: 3971 if (resolved_dies.find(die) == resolved_dies.end()) 3972 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) 3973 { 3974 bool keep_die = true; 3975 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod)) 3976 { 3977 // We are looking for either basenames or methods, so we need to 3978 // trim out the ones we won't want by looking at the type 3979 SymbolContext sc; 3980 if (sc_list.GetLastContext(sc)) 3981 { 3982 if (sc.block) 3983 { 3984 // We have an inlined function 3985 } 3986 else if (sc.function) 3987 { 3988 Type *type = sc.function->GetType(); 3989 3990 if (type) 3991 { 3992 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID()); 3993 if (decl_ctx->isRecord()) 3994 { 3995 if (name_type_mask & eFunctionNameTypeBase) 3996 { 3997 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); 3998 keep_die = false; 3999 } 4000 } 4001 else 4002 { 4003 if (name_type_mask & eFunctionNameTypeMethod) 4004 { 4005 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1); 4006 keep_die = false; 4007 } 4008 } 4009 } 4010 else 4011 { 4012 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type", 4013 die_offset); 4014 } 4015 } 4016 } 4017 } 4018 if (keep_die) 4019 resolved_dies.insert(die); 4020 } 4021 } 4022 else 4023 { 4024 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')", 4025 die_offset, name_cstr); 4026 } 4027 } 4028 die_offsets.clear(); 4029 } 4030 } 4031 } 4032 else 4033 { 4034 4035 // Index the DWARF if we haven't already 4036 if (!m_indexed) 4037 Index (); 4038 4039 if (name_type_mask & eFunctionNameTypeFull) 4040 { 4041 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list); 4042 4043 // FIXME Temporary workaround for global/anonymous namespace 4044 // functions debugging FreeBSD and Linux binaries. 4045 // If we didn't find any functions in the global namespace try 4046 // looking in the basename index but ignore any returned 4047 // functions that have a namespace but keep functions which 4048 // have an anonymous namespace 4049 // TODO: The arch in the object file isn't correct for MSVC 4050 // binaries on windows, we should find a way to make it 4051 // correct and handle those symbols as well. 4052 if (sc_list.GetSize() == 0) 4053 { 4054 ArchSpec arch; 4055 if (!namespace_decl && 4056 GetObjectFile()->GetArchitecture(arch) && 4057 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() || 4058 arch.GetMachine() == llvm::Triple::hexagon)) 4059 { 4060 SymbolContextList temp_sc_list; 4061 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list); 4062 SymbolContext sc; 4063 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) 4064 { 4065 if (temp_sc_list.GetContextAtIndex(i, sc)) 4066 { 4067 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled); 4068 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled); 4069 // Mangled names on Linux and FreeBSD are of the form: 4070 // _ZN18function_namespace13function_nameEv. 4071 if (strncmp(mangled_name.GetCString(), "_ZN", 3) || 4072 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21)) 4073 { 4074 sc_list.Append(sc); 4075 } 4076 } 4077 } 4078 } 4079 } 4080 } 4081 DIEArray die_offsets; 4082 DWARFCompileUnit *dwarf_cu = NULL; 4083 4084 if (name_type_mask & eFunctionNameTypeBase) 4085 { 4086 uint32_t num_base = m_function_basename_index.Find(name, die_offsets); 4087 for (uint32_t i = 0; i < num_base; i++) 4088 { 4089 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); 4090 if (die) 4091 { 4092 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 4093 continue; 4094 4095 // If we get to here, the die is good, and we should add it: 4096 if (resolved_dies.find(die) == resolved_dies.end()) 4097 { 4098 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) 4099 resolved_dies.insert(die); 4100 } 4101 } 4102 } 4103 die_offsets.clear(); 4104 } 4105 4106 if (name_type_mask & eFunctionNameTypeMethod) 4107 { 4108 if (namespace_decl && *namespace_decl) 4109 return 0; // no methods in namespaces 4110 4111 uint32_t num_base = m_function_method_index.Find(name, die_offsets); 4112 { 4113 for (uint32_t i = 0; i < num_base; i++) 4114 { 4115 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu); 4116 if (die) 4117 { 4118 // If we get to here, the die is good, and we should add it: 4119 if (resolved_dies.find(die) == resolved_dies.end()) 4120 { 4121 if (ResolveFunction (dwarf_cu, die, include_inlines, sc_list)) 4122 resolved_dies.insert(die); 4123 } 4124 } 4125 } 4126 } 4127 die_offsets.clear(); 4128 } 4129 4130 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl)) 4131 { 4132 FindFunctions (name, m_function_selector_index, include_inlines, sc_list); 4133 } 4134 4135 } 4136 4137 // Return the number of variable that were appended to the list 4138 const uint32_t num_matches = sc_list.GetSize() - original_size; 4139 4140 if (log && num_matches > 0) 4141 { 4142 GetObjectFile()->GetModule()->LogMessage (log, 4143 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u", 4144 name.GetCString(), 4145 name_type_mask, 4146 include_inlines, 4147 append, 4148 num_matches); 4149 } 4150 return num_matches; 4151 } 4152 4153 uint32_t 4154 SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) 4155 { 4156 Timer scoped_timer (__PRETTY_FUNCTION__, 4157 "SymbolFileDWARF::FindFunctions (regex = '%s')", 4158 regex.GetText()); 4159 4160 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 4161 4162 if (log) 4163 { 4164 GetObjectFile()->GetModule()->LogMessage (log, 4165 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", 4166 regex.GetText(), 4167 append); 4168 } 4169 4170 4171 // If we aren't appending the results to this list, then clear the list 4172 if (!append) 4173 sc_list.Clear(); 4174 4175 // Remember how many sc_list are in the list before we search in case 4176 // we are appending the results to a variable list. 4177 uint32_t original_size = sc_list.GetSize(); 4178 4179 if (m_using_apple_tables) 4180 { 4181 if (m_apple_names_ap.get()) 4182 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list); 4183 } 4184 else 4185 { 4186 // Index the DWARF if we haven't already 4187 if (!m_indexed) 4188 Index (); 4189 4190 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list); 4191 4192 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list); 4193 } 4194 4195 // Return the number of variable that were appended to the list 4196 return sc_list.GetSize() - original_size; 4197 } 4198 4199 uint32_t 4200 SymbolFileDWARF::FindTypes (const SymbolContext& sc, 4201 const ConstString &name, 4202 const lldb_private::ClangNamespaceDecl *namespace_decl, 4203 bool append, 4204 uint32_t max_matches, 4205 TypeList& types) 4206 { 4207 DWARFDebugInfo* info = DebugInfo(); 4208 if (info == NULL) 4209 return 0; 4210 4211 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 4212 4213 if (log) 4214 { 4215 if (namespace_decl) 4216 GetObjectFile()->GetModule()->LogMessage (log, 4217 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)", 4218 name.GetCString(), 4219 static_cast<void*>(namespace_decl->GetNamespaceDecl()), 4220 namespace_decl->GetQualifiedName().c_str(), 4221 append, max_matches); 4222 else 4223 GetObjectFile()->GetModule()->LogMessage (log, 4224 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)", 4225 name.GetCString(), append, 4226 max_matches); 4227 } 4228 4229 // If we aren't appending the results to this list, then clear the list 4230 if (!append) 4231 types.Clear(); 4232 4233 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl)) 4234 return 0; 4235 4236 DIEArray die_offsets; 4237 4238 if (m_using_apple_tables) 4239 { 4240 if (m_apple_types_ap.get()) 4241 { 4242 const char *name_cstr = name.GetCString(); 4243 m_apple_types_ap->FindByName (name_cstr, die_offsets); 4244 } 4245 } 4246 else 4247 { 4248 if (!m_indexed) 4249 Index (); 4250 4251 m_type_index.Find (name, die_offsets); 4252 } 4253 4254 const size_t num_die_matches = die_offsets.size(); 4255 4256 if (num_die_matches) 4257 { 4258 const uint32_t initial_types_size = types.GetSize(); 4259 DWARFCompileUnit* dwarf_cu = NULL; 4260 const DWARFDebugInfoEntry* die = NULL; 4261 DWARFDebugInfo* debug_info = DebugInfo(); 4262 for (size_t i=0; i<num_die_matches; ++i) 4263 { 4264 const dw_offset_t die_offset = die_offsets[i]; 4265 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 4266 4267 if (die) 4268 { 4269 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die)) 4270 continue; 4271 4272 Type *matching_type = ResolveType (dwarf_cu, die); 4273 if (matching_type) 4274 { 4275 // We found a type pointer, now find the shared pointer form our type list 4276 types.InsertUnique (matching_type->shared_from_this()); 4277 if (types.GetSize() >= max_matches) 4278 break; 4279 } 4280 } 4281 else 4282 { 4283 if (m_using_apple_tables) 4284 { 4285 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", 4286 die_offset, name.GetCString()); 4287 } 4288 } 4289 4290 } 4291 const uint32_t num_matches = types.GetSize() - initial_types_size; 4292 if (log && num_matches) 4293 { 4294 if (namespace_decl) 4295 { 4296 GetObjectFile()->GetModule()->LogMessage (log, 4297 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u", 4298 name.GetCString(), 4299 static_cast<void*>(namespace_decl->GetNamespaceDecl()), 4300 namespace_decl->GetQualifiedName().c_str(), 4301 append, max_matches, 4302 num_matches); 4303 } 4304 else 4305 { 4306 GetObjectFile()->GetModule()->LogMessage (log, 4307 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u", 4308 name.GetCString(), 4309 append, max_matches, 4310 num_matches); 4311 } 4312 } 4313 return num_matches; 4314 } 4315 return 0; 4316 } 4317 4318 4319 ClangNamespaceDecl 4320 SymbolFileDWARF::FindNamespace (const SymbolContext& sc, 4321 const ConstString &name, 4322 const lldb_private::ClangNamespaceDecl *parent_namespace_decl) 4323 { 4324 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS)); 4325 4326 if (log) 4327 { 4328 GetObjectFile()->GetModule()->LogMessage (log, 4329 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", 4330 name.GetCString()); 4331 } 4332 4333 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl)) 4334 return ClangNamespaceDecl(); 4335 4336 ClangNamespaceDecl namespace_decl; 4337 DWARFDebugInfo* info = DebugInfo(); 4338 if (info) 4339 { 4340 DIEArray die_offsets; 4341 4342 // Index if we already haven't to make sure the compile units 4343 // get indexed and make their global DIE index list 4344 if (m_using_apple_tables) 4345 { 4346 if (m_apple_namespaces_ap.get()) 4347 { 4348 const char *name_cstr = name.GetCString(); 4349 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets); 4350 } 4351 } 4352 else 4353 { 4354 if (!m_indexed) 4355 Index (); 4356 4357 m_namespace_index.Find (name, die_offsets); 4358 } 4359 4360 DWARFCompileUnit* dwarf_cu = NULL; 4361 const DWARFDebugInfoEntry* die = NULL; 4362 const size_t num_matches = die_offsets.size(); 4363 if (num_matches) 4364 { 4365 DWARFDebugInfo* debug_info = DebugInfo(); 4366 for (size_t i=0; i<num_matches; ++i) 4367 { 4368 const dw_offset_t die_offset = die_offsets[i]; 4369 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 4370 4371 if (die) 4372 { 4373 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die)) 4374 continue; 4375 4376 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die); 4377 if (clang_namespace_decl) 4378 { 4379 namespace_decl.SetASTContext (GetClangASTContext().getASTContext()); 4380 namespace_decl.SetNamespaceDecl (clang_namespace_decl); 4381 break; 4382 } 4383 } 4384 else 4385 { 4386 if (m_using_apple_tables) 4387 { 4388 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n", 4389 die_offset, name.GetCString()); 4390 } 4391 } 4392 4393 } 4394 } 4395 } 4396 if (log && namespace_decl.GetNamespaceDecl()) 4397 { 4398 GetObjectFile()->GetModule()->LogMessage (log, 4399 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"", 4400 name.GetCString(), 4401 static_cast<const void*>(namespace_decl.GetNamespaceDecl()), 4402 namespace_decl.GetQualifiedName().c_str()); 4403 } 4404 4405 return namespace_decl; 4406 } 4407 4408 uint32_t 4409 SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) 4410 { 4411 // Remember how many sc_list are in the list before we search in case 4412 // we are appending the results to a variable list. 4413 uint32_t original_size = types.GetSize(); 4414 4415 const uint32_t num_die_offsets = die_offsets.size(); 4416 // Parse all of the types we found from the pubtypes matches 4417 uint32_t i; 4418 uint32_t num_matches = 0; 4419 for (i = 0; i < num_die_offsets; ++i) 4420 { 4421 Type *matching_type = ResolveTypeUID (die_offsets[i]); 4422 if (matching_type) 4423 { 4424 // We found a type pointer, now find the shared pointer form our type list 4425 types.InsertUnique (matching_type->shared_from_this()); 4426 ++num_matches; 4427 if (num_matches >= max_matches) 4428 break; 4429 } 4430 } 4431 4432 // Return the number of variable that were appended to the list 4433 return types.GetSize() - original_size; 4434 } 4435 4436 4437 size_t 4438 SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc, 4439 clang::DeclContext *containing_decl_ctx, 4440 DWARFCompileUnit* dwarf_cu, 4441 const DWARFDebugInfoEntry *parent_die, 4442 bool skip_artificial, 4443 bool &is_static, 4444 bool &is_variadic, 4445 std::vector<ClangASTType>& function_param_types, 4446 std::vector<clang::ParmVarDecl*>& function_param_decls, 4447 unsigned &type_quals) // , 4448 // ClangASTContext::TemplateParameterInfos &template_param_infos)) 4449 { 4450 if (parent_die == NULL) 4451 return 0; 4452 4453 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); 4454 4455 size_t arg_idx = 0; 4456 const DWARFDebugInfoEntry *die; 4457 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 4458 { 4459 dw_tag_t tag = die->Tag(); 4460 switch (tag) 4461 { 4462 case DW_TAG_formal_parameter: 4463 { 4464 DWARFDebugInfoEntry::Attributes attributes; 4465 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 4466 if (num_attributes > 0) 4467 { 4468 const char *name = NULL; 4469 Declaration decl; 4470 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; 4471 bool is_artificial = false; 4472 // one of None, Auto, Register, Extern, Static, PrivateExtern 4473 4474 clang::StorageClass storage = clang::SC_None; 4475 uint32_t i; 4476 for (i=0; i<num_attributes; ++i) 4477 { 4478 const dw_attr_t attr = attributes.AttributeAtIndex(i); 4479 DWARFFormValue form_value; 4480 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 4481 { 4482 switch (attr) 4483 { 4484 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 4485 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 4486 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 4487 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 4488 case DW_AT_type: param_type_die_offset = form_value.Reference(); break; 4489 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 4490 case DW_AT_location: 4491 // if (form_value.BlockData()) 4492 // { 4493 // const DWARFDataExtractor& debug_info_data = debug_info(); 4494 // uint32_t block_length = form_value.Unsigned(); 4495 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); 4496 // } 4497 // else 4498 // { 4499 // } 4500 // break; 4501 case DW_AT_const_value: 4502 case DW_AT_default_value: 4503 case DW_AT_description: 4504 case DW_AT_endianity: 4505 case DW_AT_is_optional: 4506 case DW_AT_segment: 4507 case DW_AT_variable_parameter: 4508 default: 4509 case DW_AT_abstract_origin: 4510 case DW_AT_sibling: 4511 break; 4512 } 4513 } 4514 } 4515 4516 bool skip = false; 4517 if (skip_artificial) 4518 { 4519 if (is_artificial) 4520 { 4521 // In order to determine if a C++ member function is 4522 // "const" we have to look at the const-ness of "this"... 4523 // Ugly, but that 4524 if (arg_idx == 0) 4525 { 4526 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) 4527 { 4528 // Often times compilers omit the "this" name for the 4529 // specification DIEs, so we can't rely upon the name 4530 // being in the formal parameter DIE... 4531 if (name == NULL || ::strcmp(name, "this")==0) 4532 { 4533 Type *this_type = ResolveTypeUID (param_type_die_offset); 4534 if (this_type) 4535 { 4536 uint32_t encoding_mask = this_type->GetEncodingMask(); 4537 if (encoding_mask & Type::eEncodingIsPointerUID) 4538 { 4539 is_static = false; 4540 4541 if (encoding_mask & (1u << Type::eEncodingIsConstUID)) 4542 type_quals |= clang::Qualifiers::Const; 4543 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) 4544 type_quals |= clang::Qualifiers::Volatile; 4545 } 4546 } 4547 } 4548 } 4549 } 4550 skip = true; 4551 } 4552 else 4553 { 4554 4555 // HACK: Objective C formal parameters "self" and "_cmd" 4556 // are not marked as artificial in the DWARF... 4557 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 4558 if (comp_unit) 4559 { 4560 switch (comp_unit->GetLanguage()) 4561 { 4562 case eLanguageTypeObjC: 4563 case eLanguageTypeObjC_plus_plus: 4564 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) 4565 skip = true; 4566 break; 4567 default: 4568 break; 4569 } 4570 } 4571 } 4572 } 4573 4574 if (!skip) 4575 { 4576 Type *type = ResolveTypeUID(param_type_die_offset); 4577 if (type) 4578 { 4579 function_param_types.push_back (type->GetClangForwardType()); 4580 4581 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name, 4582 type->GetClangForwardType(), 4583 storage); 4584 assert(param_var_decl); 4585 function_param_decls.push_back(param_var_decl); 4586 4587 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset())); 4588 } 4589 } 4590 } 4591 arg_idx++; 4592 } 4593 break; 4594 4595 case DW_TAG_unspecified_parameters: 4596 is_variadic = true; 4597 break; 4598 4599 case DW_TAG_template_type_parameter: 4600 case DW_TAG_template_value_parameter: 4601 // The one caller of this was never using the template_param_infos, 4602 // and the local variable was taking up a large amount of stack space 4603 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need 4604 // the template params back, we can add them back. 4605 // ParseTemplateDIE (dwarf_cu, die, template_param_infos); 4606 break; 4607 4608 default: 4609 break; 4610 } 4611 } 4612 return arg_idx; 4613 } 4614 4615 size_t 4616 SymbolFileDWARF::ParseChildEnumerators 4617 ( 4618 const SymbolContext& sc, 4619 lldb_private::ClangASTType &clang_type, 4620 bool is_signed, 4621 uint32_t enumerator_byte_size, 4622 DWARFCompileUnit* dwarf_cu, 4623 const DWARFDebugInfoEntry *parent_die 4624 ) 4625 { 4626 if (parent_die == NULL) 4627 return 0; 4628 4629 size_t enumerators_added = 0; 4630 const DWARFDebugInfoEntry *die; 4631 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); 4632 4633 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 4634 { 4635 const dw_tag_t tag = die->Tag(); 4636 if (tag == DW_TAG_enumerator) 4637 { 4638 DWARFDebugInfoEntry::Attributes attributes; 4639 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 4640 if (num_child_attributes > 0) 4641 { 4642 const char *name = NULL; 4643 bool got_value = false; 4644 int64_t enum_value = 0; 4645 Declaration decl; 4646 4647 uint32_t i; 4648 for (i=0; i<num_child_attributes; ++i) 4649 { 4650 const dw_attr_t attr = attributes.AttributeAtIndex(i); 4651 DWARFFormValue form_value; 4652 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 4653 { 4654 switch (attr) 4655 { 4656 case DW_AT_const_value: 4657 got_value = true; 4658 if (is_signed) 4659 enum_value = form_value.Signed(); 4660 else 4661 enum_value = form_value.Unsigned(); 4662 break; 4663 4664 case DW_AT_name: 4665 name = form_value.AsCString(&get_debug_str_data()); 4666 break; 4667 4668 case DW_AT_description: 4669 default: 4670 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 4671 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 4672 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 4673 case DW_AT_sibling: 4674 break; 4675 } 4676 } 4677 } 4678 4679 if (name && name[0] && got_value) 4680 { 4681 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(), 4682 decl, 4683 name, 4684 enum_value, 4685 enumerator_byte_size * 8); 4686 ++enumerators_added; 4687 } 4688 } 4689 } 4690 } 4691 return enumerators_added; 4692 } 4693 4694 void 4695 SymbolFileDWARF::ParseChildArrayInfo 4696 ( 4697 const SymbolContext& sc, 4698 DWARFCompileUnit* dwarf_cu, 4699 const DWARFDebugInfoEntry *parent_die, 4700 int64_t& first_index, 4701 std::vector<uint64_t>& element_orders, 4702 uint32_t& byte_stride, 4703 uint32_t& bit_stride 4704 ) 4705 { 4706 if (parent_die == NULL) 4707 return; 4708 4709 const DWARFDebugInfoEntry *die; 4710 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize(), dwarf_cu->IsDWARF64()); 4711 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 4712 { 4713 const dw_tag_t tag = die->Tag(); 4714 switch (tag) 4715 { 4716 case DW_TAG_subrange_type: 4717 { 4718 DWARFDebugInfoEntry::Attributes attributes; 4719 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 4720 if (num_child_attributes > 0) 4721 { 4722 uint64_t num_elements = 0; 4723 uint64_t lower_bound = 0; 4724 uint64_t upper_bound = 0; 4725 bool upper_bound_valid = false; 4726 uint32_t i; 4727 for (i=0; i<num_child_attributes; ++i) 4728 { 4729 const dw_attr_t attr = attributes.AttributeAtIndex(i); 4730 DWARFFormValue form_value; 4731 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 4732 { 4733 switch (attr) 4734 { 4735 case DW_AT_name: 4736 break; 4737 4738 case DW_AT_count: 4739 num_elements = form_value.Unsigned(); 4740 break; 4741 4742 case DW_AT_bit_stride: 4743 bit_stride = form_value.Unsigned(); 4744 break; 4745 4746 case DW_AT_byte_stride: 4747 byte_stride = form_value.Unsigned(); 4748 break; 4749 4750 case DW_AT_lower_bound: 4751 lower_bound = form_value.Unsigned(); 4752 break; 4753 4754 case DW_AT_upper_bound: 4755 upper_bound_valid = true; 4756 upper_bound = form_value.Unsigned(); 4757 break; 4758 4759 default: 4760 case DW_AT_abstract_origin: 4761 case DW_AT_accessibility: 4762 case DW_AT_allocated: 4763 case DW_AT_associated: 4764 case DW_AT_data_location: 4765 case DW_AT_declaration: 4766 case DW_AT_description: 4767 case DW_AT_sibling: 4768 case DW_AT_threads_scaled: 4769 case DW_AT_type: 4770 case DW_AT_visibility: 4771 break; 4772 } 4773 } 4774 } 4775 4776 if (num_elements == 0) 4777 { 4778 if (upper_bound_valid && upper_bound >= lower_bound) 4779 num_elements = upper_bound - lower_bound + 1; 4780 } 4781 4782 element_orders.push_back (num_elements); 4783 } 4784 } 4785 break; 4786 } 4787 } 4788 } 4789 4790 TypeSP 4791 SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die) 4792 { 4793 TypeSP type_sp; 4794 if (die != NULL) 4795 { 4796 assert(dwarf_cu != NULL); 4797 Type *type_ptr = m_die_to_type.lookup (die); 4798 if (type_ptr == NULL) 4799 { 4800 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu); 4801 assert (lldb_cu); 4802 SymbolContext sc(lldb_cu); 4803 type_sp = ParseType(sc, dwarf_cu, die, NULL); 4804 } 4805 else if (type_ptr != DIE_IS_BEING_PARSED) 4806 { 4807 // Grab the existing type from the master types lists 4808 type_sp = type_ptr->shared_from_this(); 4809 } 4810 4811 } 4812 return type_sp; 4813 } 4814 4815 clang::DeclContext * 4816 SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset) 4817 { 4818 if (die_offset != DW_INVALID_OFFSET) 4819 { 4820 DWARFCompileUnitSP cu_sp; 4821 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); 4822 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL); 4823 } 4824 return NULL; 4825 } 4826 4827 clang::DeclContext * 4828 SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset) 4829 { 4830 if (die_offset != DW_INVALID_OFFSET) 4831 { 4832 DWARFDebugInfo* debug_info = DebugInfo(); 4833 if (debug_info) 4834 { 4835 DWARFCompileUnitSP cu_sp; 4836 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp); 4837 if (die) 4838 return GetClangDeclContextForDIE (sc, cu_sp.get(), die); 4839 } 4840 } 4841 return NULL; 4842 } 4843 4844 clang::NamespaceDecl * 4845 SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die) 4846 { 4847 if (die && die->Tag() == DW_TAG_namespace) 4848 { 4849 // See if we already parsed this namespace DIE and associated it with a 4850 // uniqued namespace declaration 4851 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]); 4852 if (namespace_decl) 4853 return namespace_decl; 4854 else 4855 { 4856 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL); 4857 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL); 4858 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); 4859 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 4860 if (log) 4861 { 4862 if (namespace_name) 4863 { 4864 GetObjectFile()->GetModule()->LogMessage (log, 4865 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", 4866 static_cast<void*>(GetClangASTContext().getASTContext()), 4867 MakeUserID(die->GetOffset()), 4868 namespace_name, 4869 static_cast<void*>(namespace_decl), 4870 static_cast<void*>(namespace_decl->getOriginalNamespace())); 4871 } 4872 else 4873 { 4874 GetObjectFile()->GetModule()->LogMessage (log, 4875 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", 4876 static_cast<void*>(GetClangASTContext().getASTContext()), 4877 MakeUserID(die->GetOffset()), 4878 static_cast<void*>(namespace_decl), 4879 static_cast<void*>(namespace_decl->getOriginalNamespace())); 4880 } 4881 } 4882 4883 if (namespace_decl) 4884 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); 4885 return namespace_decl; 4886 } 4887 } 4888 return NULL; 4889 } 4890 4891 clang::DeclContext * 4892 SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 4893 { 4894 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die); 4895 if (clang_decl_ctx) 4896 return clang_decl_ctx; 4897 // If this DIE has a specification, or an abstract origin, then trace to those. 4898 4899 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); 4900 if (die_offset != DW_INVALID_OFFSET) 4901 return GetClangDeclContextForDIEOffset (sc, die_offset); 4902 4903 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); 4904 if (die_offset != DW_INVALID_OFFSET) 4905 return GetClangDeclContextForDIEOffset (sc, die_offset); 4906 4907 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 4908 if (log) 4909 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)); 4910 // This is the DIE we want. Parse it, then query our map. 4911 bool assert_not_being_parsed = true; 4912 ResolveTypeUID (cu, die, assert_not_being_parsed); 4913 4914 clang_decl_ctx = GetCachedClangDeclContextForDIE (die); 4915 4916 return clang_decl_ctx; 4917 } 4918 4919 clang::DeclContext * 4920 SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy) 4921 { 4922 if (m_clang_tu_decl == NULL) 4923 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl(); 4924 4925 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die); 4926 4927 if (decl_ctx_die_copy) 4928 *decl_ctx_die_copy = decl_ctx_die; 4929 4930 if (decl_ctx_die) 4931 { 4932 4933 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die); 4934 if (pos != m_die_to_decl_ctx.end()) 4935 return pos->second; 4936 4937 switch (decl_ctx_die->Tag()) 4938 { 4939 case DW_TAG_compile_unit: 4940 return m_clang_tu_decl; 4941 4942 case DW_TAG_namespace: 4943 return ResolveNamespaceDIE (cu, decl_ctx_die); 4944 break; 4945 4946 case DW_TAG_structure_type: 4947 case DW_TAG_union_type: 4948 case DW_TAG_class_type: 4949 { 4950 Type* type = ResolveType (cu, decl_ctx_die); 4951 if (type) 4952 { 4953 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType (); 4954 if (decl_ctx) 4955 { 4956 LinkDeclContextToDIE (decl_ctx, decl_ctx_die); 4957 if (decl_ctx) 4958 return decl_ctx; 4959 } 4960 } 4961 } 4962 break; 4963 4964 default: 4965 break; 4966 } 4967 } 4968 return m_clang_tu_decl; 4969 } 4970 4971 4972 const DWARFDebugInfoEntry * 4973 SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 4974 { 4975 if (cu && die) 4976 { 4977 const DWARFDebugInfoEntry * const decl_die = die; 4978 4979 while (die != NULL) 4980 { 4981 // If this is the original DIE that we are searching for a declaration 4982 // for, then don't look in the cache as we don't want our own decl 4983 // context to be our decl context... 4984 if (decl_die != die) 4985 { 4986 switch (die->Tag()) 4987 { 4988 case DW_TAG_compile_unit: 4989 case DW_TAG_namespace: 4990 case DW_TAG_structure_type: 4991 case DW_TAG_union_type: 4992 case DW_TAG_class_type: 4993 return die; 4994 4995 default: 4996 break; 4997 } 4998 } 4999 5000 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET); 5001 if (die_offset != DW_INVALID_OFFSET) 5002 { 5003 DWARFCompileUnit *spec_cu = cu; 5004 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu); 5005 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die); 5006 if (spec_die_decl_ctx_die) 5007 return spec_die_decl_ctx_die; 5008 } 5009 5010 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET); 5011 if (die_offset != DW_INVALID_OFFSET) 5012 { 5013 DWARFCompileUnit *abs_cu = cu; 5014 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu); 5015 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die); 5016 if (abs_die_decl_ctx_die) 5017 return abs_die_decl_ctx_die; 5018 } 5019 5020 die = die->GetParent(); 5021 } 5022 } 5023 return NULL; 5024 } 5025 5026 5027 Symbol * 5028 SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name) 5029 { 5030 Symbol *objc_class_symbol = NULL; 5031 if (m_obj_file) 5032 { 5033 Symtab *symtab = m_obj_file->GetSymtab (); 5034 if (symtab) 5035 { 5036 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name, 5037 eSymbolTypeObjCClass, 5038 Symtab::eDebugNo, 5039 Symtab::eVisibilityAny); 5040 } 5041 } 5042 return objc_class_symbol; 5043 } 5044 5045 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't 5046 // then we can end up looking through all class types for a complete type and never find 5047 // the full definition. We need to know if this attribute is supported, so we determine 5048 // this here and cache th result. We also need to worry about the debug map DWARF file 5049 // if we are doing darwin DWARF in .o file debugging. 5050 bool 5051 SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu) 5052 { 5053 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) 5054 { 5055 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo; 5056 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type()) 5057 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; 5058 else 5059 { 5060 DWARFDebugInfo* debug_info = DebugInfo(); 5061 const uint32_t num_compile_units = GetNumCompileUnits(); 5062 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) 5063 { 5064 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx); 5065 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) 5066 { 5067 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes; 5068 break; 5069 } 5070 } 5071 } 5072 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ()) 5073 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this); 5074 } 5075 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes; 5076 } 5077 5078 // This function can be used when a DIE is found that is a forward declaration 5079 // DIE and we want to try and find a type that has the complete definition. 5080 TypeSP 5081 SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, 5082 const ConstString &type_name, 5083 bool must_be_implementation) 5084 { 5085 5086 TypeSP type_sp; 5087 5088 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name))) 5089 return type_sp; 5090 5091 DIEArray die_offsets; 5092 5093 if (m_using_apple_tables) 5094 { 5095 if (m_apple_types_ap.get()) 5096 { 5097 const char *name_cstr = type_name.GetCString(); 5098 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation); 5099 } 5100 } 5101 else 5102 { 5103 if (!m_indexed) 5104 Index (); 5105 5106 m_type_index.Find (type_name, die_offsets); 5107 } 5108 5109 const size_t num_matches = die_offsets.size(); 5110 5111 DWARFCompileUnit* type_cu = NULL; 5112 const DWARFDebugInfoEntry* type_die = NULL; 5113 if (num_matches) 5114 { 5115 DWARFDebugInfo* debug_info = DebugInfo(); 5116 for (size_t i=0; i<num_matches; ++i) 5117 { 5118 const dw_offset_t die_offset = die_offsets[i]; 5119 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); 5120 5121 if (type_die) 5122 { 5123 bool try_resolving_type = false; 5124 5125 // Don't try and resolve the DIE we are looking for with the DIE itself! 5126 if (type_die != die) 5127 { 5128 switch (type_die->Tag()) 5129 { 5130 case DW_TAG_class_type: 5131 case DW_TAG_structure_type: 5132 try_resolving_type = true; 5133 break; 5134 default: 5135 break; 5136 } 5137 } 5138 5139 if (try_resolving_type) 5140 { 5141 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type()) 5142 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0); 5143 5144 if (try_resolving_type) 5145 { 5146 Type *resolved_type = ResolveType (type_cu, type_die, false); 5147 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) 5148 { 5149 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", 5150 MakeUserID(die->GetOffset()), 5151 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"), 5152 MakeUserID(type_die->GetOffset()), 5153 MakeUserID(type_cu->GetOffset())); 5154 5155 if (die) 5156 m_die_to_type[die] = resolved_type; 5157 type_sp = resolved_type->shared_from_this(); 5158 break; 5159 } 5160 } 5161 } 5162 } 5163 else 5164 { 5165 if (m_using_apple_tables) 5166 { 5167 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", 5168 die_offset, type_name.GetCString()); 5169 } 5170 } 5171 5172 } 5173 } 5174 return type_sp; 5175 } 5176 5177 5178 //---------------------------------------------------------------------- 5179 // This function helps to ensure that the declaration contexts match for 5180 // two different DIEs. Often times debug information will refer to a 5181 // forward declaration of a type (the equivalent of "struct my_struct;". 5182 // There will often be a declaration of that type elsewhere that has the 5183 // full definition. When we go looking for the full type "my_struct", we 5184 // will find one or more matches in the accelerator tables and we will 5185 // then need to make sure the type was in the same declaration context 5186 // as the original DIE. This function can efficiently compare two DIEs 5187 // and will return true when the declaration context matches, and false 5188 // when they don't. 5189 //---------------------------------------------------------------------- 5190 bool 5191 SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1, 5192 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2) 5193 { 5194 if (die1 == die2) 5195 return true; 5196 5197 #if defined (LLDB_CONFIGURATION_DEBUG) 5198 // You can't and shouldn't call this function with a compile unit from 5199 // two different SymbolFileDWARF instances. 5200 assert (DebugInfo()->ContainsCompileUnit (cu1)); 5201 assert (DebugInfo()->ContainsCompileUnit (cu2)); 5202 #endif 5203 5204 DWARFDIECollection decl_ctx_1; 5205 DWARFDIECollection decl_ctx_2; 5206 //The declaration DIE stack is a stack of the declaration context 5207 // DIEs all the way back to the compile unit. If a type "T" is 5208 // declared inside a class "B", and class "B" is declared inside 5209 // a class "A" and class "A" is in a namespace "lldb", and the 5210 // namespace is in a compile unit, there will be a stack of DIEs: 5211 // 5212 // [0] DW_TAG_class_type for "B" 5213 // [1] DW_TAG_class_type for "A" 5214 // [2] DW_TAG_namespace for "lldb" 5215 // [3] DW_TAG_compile_unit for the source file. 5216 // 5217 // We grab both contexts and make sure that everything matches 5218 // all the way back to the compiler unit. 5219 5220 // First lets grab the decl contexts for both DIEs 5221 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1); 5222 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2); 5223 // Make sure the context arrays have the same size, otherwise 5224 // we are done 5225 const size_t count1 = decl_ctx_1.Size(); 5226 const size_t count2 = decl_ctx_2.Size(); 5227 if (count1 != count2) 5228 return false; 5229 5230 // Make sure the DW_TAG values match all the way back up the 5231 // compile unit. If they don't, then we are done. 5232 const DWARFDebugInfoEntry *decl_ctx_die1; 5233 const DWARFDebugInfoEntry *decl_ctx_die2; 5234 size_t i; 5235 for (i=0; i<count1; i++) 5236 { 5237 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); 5238 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); 5239 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag()) 5240 return false; 5241 } 5242 #if defined LLDB_CONFIGURATION_DEBUG 5243 5244 // Make sure the top item in the decl context die array is always 5245 // DW_TAG_compile_unit. If it isn't then something went wrong in 5246 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function... 5247 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit); 5248 5249 #endif 5250 // Always skip the compile unit when comparing by only iterating up to 5251 // "count - 1". Here we compare the names as we go. 5252 for (i=0; i<count1 - 1; i++) 5253 { 5254 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i); 5255 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i); 5256 const char *name1 = decl_ctx_die1->GetName(this, cu1); 5257 const char *name2 = decl_ctx_die2->GetName(this, cu2); 5258 // If the string was from a DW_FORM_strp, then the pointer will often 5259 // be the same! 5260 if (name1 == name2) 5261 continue; 5262 5263 // Name pointers are not equal, so only compare the strings 5264 // if both are not NULL. 5265 if (name1 && name2) 5266 { 5267 // If the strings don't compare, we are done... 5268 if (strcmp(name1, name2) != 0) 5269 return false; 5270 } 5271 else 5272 { 5273 // One name was NULL while the other wasn't 5274 return false; 5275 } 5276 } 5277 // We made it through all of the checks and the declaration contexts 5278 // are equal. 5279 return true; 5280 } 5281 5282 5283 TypeSP 5284 SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx) 5285 { 5286 TypeSP type_sp; 5287 5288 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize(); 5289 if (dwarf_decl_ctx_count > 0) 5290 { 5291 const ConstString type_name(dwarf_decl_ctx[0].name); 5292 const dw_tag_t tag = dwarf_decl_ctx[0].tag; 5293 5294 if (type_name) 5295 { 5296 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS)); 5297 if (log) 5298 { 5299 GetObjectFile()->GetModule()->LogMessage (log, 5300 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')", 5301 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), 5302 dwarf_decl_ctx.GetQualifiedName()); 5303 } 5304 5305 DIEArray die_offsets; 5306 5307 if (m_using_apple_tables) 5308 { 5309 if (m_apple_types_ap.get()) 5310 { 5311 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag); 5312 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash); 5313 if (has_tag && has_qualified_name_hash) 5314 { 5315 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName(); 5316 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name); 5317 if (log) 5318 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()"); 5319 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets); 5320 } 5321 else if (has_tag) 5322 { 5323 if (log) 5324 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()"); 5325 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets); 5326 } 5327 else 5328 { 5329 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets); 5330 } 5331 } 5332 } 5333 else 5334 { 5335 if (!m_indexed) 5336 Index (); 5337 5338 m_type_index.Find (type_name, die_offsets); 5339 } 5340 5341 const size_t num_matches = die_offsets.size(); 5342 5343 5344 DWARFCompileUnit* type_cu = NULL; 5345 const DWARFDebugInfoEntry* type_die = NULL; 5346 if (num_matches) 5347 { 5348 DWARFDebugInfo* debug_info = DebugInfo(); 5349 for (size_t i=0; i<num_matches; ++i) 5350 { 5351 const dw_offset_t die_offset = die_offsets[i]; 5352 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu); 5353 5354 if (type_die) 5355 { 5356 bool try_resolving_type = false; 5357 5358 // Don't try and resolve the DIE we are looking for with the DIE itself! 5359 const dw_tag_t type_tag = type_die->Tag(); 5360 // Make sure the tags match 5361 if (type_tag == tag) 5362 { 5363 // The tags match, lets try resolving this type 5364 try_resolving_type = true; 5365 } 5366 else 5367 { 5368 // The tags don't match, but we need to watch our for a 5369 // forward declaration for a struct and ("struct foo") 5370 // ends up being a class ("class foo { ... };") or 5371 // vice versa. 5372 switch (type_tag) 5373 { 5374 case DW_TAG_class_type: 5375 // We had a "class foo", see if we ended up with a "struct foo { ... };" 5376 try_resolving_type = (tag == DW_TAG_structure_type); 5377 break; 5378 case DW_TAG_structure_type: 5379 // We had a "struct foo", see if we ended up with a "class foo { ... };" 5380 try_resolving_type = (tag == DW_TAG_class_type); 5381 break; 5382 default: 5383 // Tags don't match, don't event try to resolve 5384 // using this type whose name matches.... 5385 break; 5386 } 5387 } 5388 5389 if (try_resolving_type) 5390 { 5391 DWARFDeclContext type_dwarf_decl_ctx; 5392 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx); 5393 5394 if (log) 5395 { 5396 GetObjectFile()->GetModule()->LogMessage (log, 5397 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)", 5398 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), 5399 dwarf_decl_ctx.GetQualifiedName(), 5400 type_die->GetOffset(), 5401 type_dwarf_decl_ctx.GetQualifiedName()); 5402 } 5403 5404 // Make sure the decl contexts match all the way up 5405 if (dwarf_decl_ctx == type_dwarf_decl_ctx) 5406 { 5407 Type *resolved_type = ResolveType (type_cu, type_die, false); 5408 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) 5409 { 5410 type_sp = resolved_type->shared_from_this(); 5411 break; 5412 } 5413 } 5414 } 5415 else 5416 { 5417 if (log) 5418 { 5419 std::string qualified_name; 5420 type_die->GetQualifiedName(this, type_cu, qualified_name); 5421 GetObjectFile()->GetModule()->LogMessage (log, 5422 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)", 5423 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag), 5424 dwarf_decl_ctx.GetQualifiedName(), 5425 type_die->GetOffset(), 5426 qualified_name.c_str()); 5427 } 5428 } 5429 } 5430 else 5431 { 5432 if (m_using_apple_tables) 5433 { 5434 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n", 5435 die_offset, type_name.GetCString()); 5436 } 5437 } 5438 5439 } 5440 } 5441 } 5442 } 5443 return type_sp; 5444 } 5445 5446 bool 5447 SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile, 5448 Type *class_type, 5449 DWARFCompileUnit* src_cu, 5450 const DWARFDebugInfoEntry *src_class_die, 5451 DWARFCompileUnit* dst_cu, 5452 const DWARFDebugInfoEntry *dst_class_die, 5453 DWARFDIECollection &failures) 5454 { 5455 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die) 5456 return false; 5457 if (src_class_die->Tag() != dst_class_die->Tag()) 5458 return false; 5459 5460 // We need to complete the class type so we can get all of the method types 5461 // parsed so we can then unique those types to their equivalent counterparts 5462 // in "dst_cu" and "dst_class_die" 5463 class_type->GetClangFullType(); 5464 5465 const DWARFDebugInfoEntry *src_die; 5466 const DWARFDebugInfoEntry *dst_die; 5467 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die; 5468 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die; 5469 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial; 5470 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial; 5471 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling()) 5472 { 5473 if (src_die->Tag() == DW_TAG_subprogram) 5474 { 5475 // Make sure this is a declaration and not a concrete instance by looking 5476 // for DW_AT_declaration set to 1. Sometimes concrete function instances 5477 // are placed inside the class definitions and shouldn't be included in 5478 // the list of things are are tracking here. 5479 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1) 5480 { 5481 const char *src_name = src_die->GetMangledName (src_symfile, src_cu); 5482 if (src_name) 5483 { 5484 ConstString src_const_name(src_name); 5485 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0)) 5486 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); 5487 else 5488 src_name_to_die.Append(src_const_name.GetCString(), src_die); 5489 } 5490 } 5491 } 5492 } 5493 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling()) 5494 { 5495 if (dst_die->Tag() == DW_TAG_subprogram) 5496 { 5497 // Make sure this is a declaration and not a concrete instance by looking 5498 // for DW_AT_declaration set to 1. Sometimes concrete function instances 5499 // are placed inside the class definitions and shouldn't be included in 5500 // the list of things are are tracking here. 5501 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1) 5502 { 5503 const char *dst_name = dst_die->GetMangledName (this, dst_cu); 5504 if (dst_name) 5505 { 5506 ConstString dst_const_name(dst_name); 5507 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0)) 5508 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); 5509 else 5510 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); 5511 } 5512 } 5513 } 5514 } 5515 const uint32_t src_size = src_name_to_die.GetSize (); 5516 const uint32_t dst_size = dst_name_to_die.GetSize (); 5517 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); 5518 5519 // Is everything kosher so we can go through the members at top speed? 5520 bool fast_path = true; 5521 5522 if (src_size != dst_size) 5523 { 5524 if (src_size != 0 && dst_size != 0) 5525 { 5526 if (log) 5527 log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)", 5528 src_class_die->GetOffset(), 5529 dst_class_die->GetOffset(), 5530 src_size, 5531 dst_size); 5532 } 5533 5534 fast_path = false; 5535 } 5536 5537 uint32_t idx; 5538 5539 if (fast_path) 5540 { 5541 for (idx = 0; idx < src_size; ++idx) 5542 { 5543 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); 5544 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); 5545 5546 if (src_die->Tag() != dst_die->Tag()) 5547 { 5548 if (log) 5549 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)", 5550 src_class_die->GetOffset(), 5551 dst_class_die->GetOffset(), 5552 src_die->GetOffset(), 5553 DW_TAG_value_to_name(src_die->Tag()), 5554 dst_die->GetOffset(), 5555 DW_TAG_value_to_name(src_die->Tag())); 5556 fast_path = false; 5557 } 5558 5559 const char *src_name = src_die->GetMangledName (src_symfile, src_cu); 5560 const char *dst_name = dst_die->GetMangledName (this, dst_cu); 5561 5562 // Make sure the names match 5563 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) 5564 continue; 5565 5566 if (log) 5567 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)", 5568 src_class_die->GetOffset(), 5569 dst_class_die->GetOffset(), 5570 src_die->GetOffset(), 5571 src_name, 5572 dst_die->GetOffset(), 5573 dst_name); 5574 5575 fast_path = false; 5576 } 5577 } 5578 5579 // Now do the work of linking the DeclContexts and Types. 5580 if (fast_path) 5581 { 5582 // We can do this quickly. Just run across the tables index-for-index since 5583 // we know each node has matching names and tags. 5584 for (idx = 0; idx < src_size; ++idx) 5585 { 5586 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); 5587 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); 5588 5589 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die]; 5590 if (src_decl_ctx) 5591 { 5592 if (log) 5593 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", 5594 static_cast<void*>(src_decl_ctx), 5595 src_die->GetOffset(), dst_die->GetOffset()); 5596 LinkDeclContextToDIE (src_decl_ctx, dst_die); 5597 } 5598 else 5599 { 5600 if (log) 5601 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", 5602 src_die->GetOffset(), dst_die->GetOffset()); 5603 } 5604 5605 Type *src_child_type = m_die_to_type[src_die]; 5606 if (src_child_type) 5607 { 5608 if (log) 5609 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", 5610 static_cast<void*>(src_child_type), 5611 src_child_type->GetID(), 5612 src_die->GetOffset(), dst_die->GetOffset()); 5613 m_die_to_type[dst_die] = src_child_type; 5614 } 5615 else 5616 { 5617 if (log) 5618 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); 5619 } 5620 } 5621 } 5622 else 5623 { 5624 // We must do this slowly. For each member of the destination, look 5625 // up a member in the source with the same name, check its tag, and 5626 // unique them if everything matches up. Report failures. 5627 5628 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) 5629 { 5630 src_name_to_die.Sort(); 5631 5632 for (idx = 0; idx < dst_size; ++idx) 5633 { 5634 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); 5635 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); 5636 src_die = src_name_to_die.Find(dst_name, NULL); 5637 5638 if (src_die && (src_die->Tag() == dst_die->Tag())) 5639 { 5640 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die]; 5641 if (src_decl_ctx) 5642 { 5643 if (log) 5644 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", 5645 static_cast<void*>(src_decl_ctx), 5646 src_die->GetOffset(), 5647 dst_die->GetOffset()); 5648 LinkDeclContextToDIE (src_decl_ctx, dst_die); 5649 } 5650 else 5651 { 5652 if (log) 5653 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); 5654 } 5655 5656 Type *src_child_type = m_die_to_type[src_die]; 5657 if (src_child_type) 5658 { 5659 if (log) 5660 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", 5661 static_cast<void*>(src_child_type), 5662 src_child_type->GetID(), 5663 src_die->GetOffset(), 5664 dst_die->GetOffset()); 5665 m_die_to_type[dst_die] = src_child_type; 5666 } 5667 else 5668 { 5669 if (log) 5670 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); 5671 } 5672 } 5673 else 5674 { 5675 if (log) 5676 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset()); 5677 5678 failures.Append(dst_die); 5679 } 5680 } 5681 } 5682 } 5683 5684 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); 5685 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); 5686 5687 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src; 5688 5689 if (src_size_artificial && dst_size_artificial) 5690 { 5691 dst_name_to_die_artificial.Sort(); 5692 5693 for (idx = 0; idx < src_size_artificial; ++idx) 5694 { 5695 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); 5696 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); 5697 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL); 5698 5699 if (dst_die) 5700 { 5701 // Both classes have the artificial types, link them 5702 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die]; 5703 if (src_decl_ctx) 5704 { 5705 if (log) 5706 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", 5707 static_cast<void*>(src_decl_ctx), 5708 src_die->GetOffset(), dst_die->GetOffset()); 5709 LinkDeclContextToDIE (src_decl_ctx, dst_die); 5710 } 5711 else 5712 { 5713 if (log) 5714 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); 5715 } 5716 5717 Type *src_child_type = m_die_to_type[src_die]; 5718 if (src_child_type) 5719 { 5720 if (log) 5721 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", 5722 static_cast<void*>(src_child_type), 5723 src_child_type->GetID(), 5724 src_die->GetOffset(), dst_die->GetOffset()); 5725 m_die_to_type[dst_die] = src_child_type; 5726 } 5727 else 5728 { 5729 if (log) 5730 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset()); 5731 } 5732 } 5733 } 5734 } 5735 5736 if (dst_size_artificial) 5737 { 5738 for (idx = 0; idx < dst_size_artificial; ++idx) 5739 { 5740 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); 5741 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); 5742 if (log) 5743 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial); 5744 5745 failures.Append(dst_die); 5746 } 5747 } 5748 5749 return (failures.Size() != 0); 5750 } 5751 5752 TypeSP 5753 SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) 5754 { 5755 TypeSP type_sp; 5756 5757 if (type_is_new_ptr) 5758 *type_is_new_ptr = false; 5759 5760 #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) 5761 static DIEStack g_die_stack; 5762 DIEStack::ScopedPopper scoped_die_logger(g_die_stack); 5763 #endif 5764 5765 AccessType accessibility = eAccessNone; 5766 if (die != NULL) 5767 { 5768 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 5769 if (log) 5770 { 5771 const DWARFDebugInfoEntry *context_die; 5772 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die); 5773 5774 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", 5775 die->GetOffset(), 5776 static_cast<void*>(context), 5777 context_die->GetOffset(), 5778 DW_TAG_value_to_name(die->Tag()), 5779 die->GetName(this, dwarf_cu)); 5780 5781 #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) 5782 scoped_die_logger.Push (dwarf_cu, die); 5783 g_die_stack.LogDIEs(log, this); 5784 #endif 5785 } 5786 // 5787 // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 5788 // if (log && dwarf_cu) 5789 // { 5790 // StreamString s; 5791 // die->DumpLocation (this, dwarf_cu, s); 5792 // GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); 5793 // 5794 // } 5795 5796 Type *type_ptr = m_die_to_type.lookup (die); 5797 TypeList* type_list = GetTypeList(); 5798 if (type_ptr == NULL) 5799 { 5800 ClangASTContext &ast = GetClangASTContext(); 5801 if (type_is_new_ptr) 5802 *type_is_new_ptr = true; 5803 5804 const dw_tag_t tag = die->Tag(); 5805 5806 bool is_forward_declaration = false; 5807 DWARFDebugInfoEntry::Attributes attributes; 5808 const char *type_name_cstr = NULL; 5809 ConstString type_name_const_str; 5810 Type::ResolveState resolve_state = Type::eResolveStateUnresolved; 5811 uint64_t byte_size = 0; 5812 Declaration decl; 5813 5814 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; 5815 ClangASTType clang_type; 5816 DWARFFormValue form_value; 5817 5818 dw_attr_t attr; 5819 5820 switch (tag) 5821 { 5822 case DW_TAG_base_type: 5823 case DW_TAG_pointer_type: 5824 case DW_TAG_reference_type: 5825 case DW_TAG_rvalue_reference_type: 5826 case DW_TAG_typedef: 5827 case DW_TAG_const_type: 5828 case DW_TAG_restrict_type: 5829 case DW_TAG_volatile_type: 5830 case DW_TAG_unspecified_type: 5831 { 5832 // Set a bit that lets us know that we are currently parsing this 5833 m_die_to_type[die] = DIE_IS_BEING_PARSED; 5834 5835 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 5836 uint32_t encoding = 0; 5837 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 5838 5839 if (num_attributes > 0) 5840 { 5841 uint32_t i; 5842 for (i=0; i<num_attributes; ++i) 5843 { 5844 attr = attributes.AttributeAtIndex(i); 5845 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 5846 { 5847 switch (attr) 5848 { 5849 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 5850 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 5851 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 5852 case DW_AT_name: 5853 5854 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 5855 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't 5856 // include the "&"... 5857 if (tag == DW_TAG_reference_type) 5858 { 5859 if (strchr (type_name_cstr, '&') == NULL) 5860 type_name_cstr = NULL; 5861 } 5862 if (type_name_cstr) 5863 type_name_const_str.SetCString(type_name_cstr); 5864 break; 5865 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 5866 case DW_AT_encoding: encoding = form_value.Unsigned(); break; 5867 case DW_AT_type: encoding_uid = form_value.Reference(); break; 5868 default: 5869 case DW_AT_sibling: 5870 break; 5871 } 5872 } 5873 } 5874 } 5875 5876 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid); 5877 5878 switch (tag) 5879 { 5880 default: 5881 break; 5882 5883 case DW_TAG_unspecified_type: 5884 if (strcmp(type_name_cstr, "nullptr_t") == 0 || 5885 strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) 5886 { 5887 resolve_state = Type::eResolveStateFull; 5888 clang_type = ast.GetBasicType(eBasicTypeNullPtr); 5889 break; 5890 } 5891 // Fall through to base type below in case we can handle the type there... 5892 5893 case DW_TAG_base_type: 5894 resolve_state = Type::eResolveStateFull; 5895 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, 5896 encoding, 5897 byte_size * 8); 5898 break; 5899 5900 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; 5901 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; 5902 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; 5903 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; 5904 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; 5905 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; 5906 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; 5907 } 5908 5909 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL) 5910 { 5911 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); 5912 5913 if (translation_unit_is_objc) 5914 { 5915 if (type_name_cstr != NULL) 5916 { 5917 static ConstString g_objc_type_name_id("id"); 5918 static ConstString g_objc_type_name_Class("Class"); 5919 static ConstString g_objc_type_name_selector("SEL"); 5920 5921 if (type_name_const_str == g_objc_type_name_id) 5922 { 5923 if (log) 5924 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", 5925 die->GetOffset(), 5926 DW_TAG_value_to_name(die->Tag()), 5927 die->GetName(this, dwarf_cu)); 5928 clang_type = ast.GetBasicType(eBasicTypeObjCID); 5929 encoding_data_type = Type::eEncodingIsUID; 5930 encoding_uid = LLDB_INVALID_UID; 5931 resolve_state = Type::eResolveStateFull; 5932 5933 } 5934 else if (type_name_const_str == g_objc_type_name_Class) 5935 { 5936 if (log) 5937 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", 5938 die->GetOffset(), 5939 DW_TAG_value_to_name(die->Tag()), 5940 die->GetName(this, dwarf_cu)); 5941 clang_type = ast.GetBasicType(eBasicTypeObjCClass); 5942 encoding_data_type = Type::eEncodingIsUID; 5943 encoding_uid = LLDB_INVALID_UID; 5944 resolve_state = Type::eResolveStateFull; 5945 } 5946 else if (type_name_const_str == g_objc_type_name_selector) 5947 { 5948 if (log) 5949 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", 5950 die->GetOffset(), 5951 DW_TAG_value_to_name(die->Tag()), 5952 die->GetName(this, dwarf_cu)); 5953 clang_type = ast.GetBasicType(eBasicTypeObjCSel); 5954 encoding_data_type = Type::eEncodingIsUID; 5955 encoding_uid = LLDB_INVALID_UID; 5956 resolve_state = Type::eResolveStateFull; 5957 } 5958 } 5959 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID) 5960 { 5961 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id". 5962 5963 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid); 5964 5965 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type) 5966 { 5967 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL)) 5968 { 5969 if (!strcmp(struct_name, "objc_object")) 5970 { 5971 if (log) 5972 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.", 5973 die->GetOffset(), 5974 DW_TAG_value_to_name(die->Tag()), 5975 die->GetName(this, dwarf_cu)); 5976 clang_type = ast.GetBasicType(eBasicTypeObjCID); 5977 encoding_data_type = Type::eEncodingIsUID; 5978 encoding_uid = LLDB_INVALID_UID; 5979 resolve_state = Type::eResolveStateFull; 5980 } 5981 } 5982 } 5983 } 5984 } 5985 } 5986 5987 type_sp.reset( new Type (MakeUserID(die->GetOffset()), 5988 this, 5989 type_name_const_str, 5990 byte_size, 5991 NULL, 5992 encoding_uid, 5993 encoding_data_type, 5994 &decl, 5995 clang_type, 5996 resolve_state)); 5997 5998 m_die_to_type[die] = type_sp.get(); 5999 6000 // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); 6001 // if (encoding_type != NULL) 6002 // { 6003 // if (encoding_type != DIE_IS_BEING_PARSED) 6004 // type_sp->SetEncodingType(encoding_type); 6005 // else 6006 // m_indirect_fixups.push_back(type_sp.get()); 6007 // } 6008 } 6009 break; 6010 6011 case DW_TAG_structure_type: 6012 case DW_TAG_union_type: 6013 case DW_TAG_class_type: 6014 { 6015 // Set a bit that lets us know that we are currently parsing this 6016 m_die_to_type[die] = DIE_IS_BEING_PARSED; 6017 bool byte_size_valid = false; 6018 6019 LanguageType class_language = eLanguageTypeUnknown; 6020 bool is_complete_objc_class = false; 6021 //bool struct_is_class = false; 6022 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 6023 if (num_attributes > 0) 6024 { 6025 uint32_t i; 6026 for (i=0; i<num_attributes; ++i) 6027 { 6028 attr = attributes.AttributeAtIndex(i); 6029 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 6030 { 6031 switch (attr) 6032 { 6033 case DW_AT_decl_file: 6034 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid()) 6035 { 6036 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always 6037 // point to the compile unit file, so we clear this invalid value 6038 // so that we can still unique types efficiently. 6039 decl.SetFile(FileSpec ("<invalid>", false)); 6040 } 6041 else 6042 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); 6043 break; 6044 6045 case DW_AT_decl_line: 6046 decl.SetLine(form_value.Unsigned()); 6047 break; 6048 6049 case DW_AT_decl_column: 6050 decl.SetColumn(form_value.Unsigned()); 6051 break; 6052 6053 case DW_AT_name: 6054 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 6055 type_name_const_str.SetCString(type_name_cstr); 6056 break; 6057 6058 case DW_AT_byte_size: 6059 byte_size = form_value.Unsigned(); 6060 byte_size_valid = true; 6061 break; 6062 6063 case DW_AT_accessibility: 6064 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 6065 break; 6066 6067 case DW_AT_declaration: 6068 is_forward_declaration = form_value.Boolean(); 6069 break; 6070 6071 case DW_AT_APPLE_runtime_class: 6072 class_language = (LanguageType)form_value.Signed(); 6073 break; 6074 6075 case DW_AT_APPLE_objc_complete_type: 6076 is_complete_objc_class = form_value.Signed(); 6077 break; 6078 6079 case DW_AT_allocated: 6080 case DW_AT_associated: 6081 case DW_AT_data_location: 6082 case DW_AT_description: 6083 case DW_AT_start_scope: 6084 case DW_AT_visibility: 6085 default: 6086 case DW_AT_sibling: 6087 break; 6088 } 6089 } 6090 } 6091 } 6092 6093 // UniqueDWARFASTType is large, so don't create a local variables on the 6094 // stack, put it on the heap. This function is often called recursively 6095 // and clang isn't good and sharing the stack space for variables in different blocks. 6096 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); 6097 6098 // Only try and unique the type if it has a name. 6099 if (type_name_const_str && 6100 GetUniqueDWARFASTTypeMap().Find (type_name_const_str, 6101 this, 6102 dwarf_cu, 6103 die, 6104 decl, 6105 byte_size_valid ? byte_size : -1, 6106 *unique_ast_entry_ap)) 6107 { 6108 // We have already parsed this type or from another 6109 // compile unit. GCC loves to use the "one definition 6110 // rule" which can result in multiple definitions 6111 // of the same class over and over in each compile 6112 // unit. 6113 type_sp = unique_ast_entry_ap->m_type_sp; 6114 if (type_sp) 6115 { 6116 m_die_to_type[die] = type_sp.get(); 6117 return type_sp; 6118 } 6119 } 6120 6121 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); 6122 6123 int tag_decl_kind = -1; 6124 AccessType default_accessibility = eAccessNone; 6125 if (tag == DW_TAG_structure_type) 6126 { 6127 tag_decl_kind = clang::TTK_Struct; 6128 default_accessibility = eAccessPublic; 6129 } 6130 else if (tag == DW_TAG_union_type) 6131 { 6132 tag_decl_kind = clang::TTK_Union; 6133 default_accessibility = eAccessPublic; 6134 } 6135 else if (tag == DW_TAG_class_type) 6136 { 6137 tag_decl_kind = clang::TTK_Class; 6138 default_accessibility = eAccessPrivate; 6139 } 6140 6141 if (byte_size_valid && byte_size == 0 && type_name_cstr && 6142 die->HasChildren() == false && 6143 sc.comp_unit->GetLanguage() == eLanguageTypeObjC) 6144 { 6145 // Work around an issue with clang at the moment where 6146 // forward declarations for objective C classes are emitted 6147 // as: 6148 // DW_TAG_structure_type [2] 6149 // DW_AT_name( "ForwardObjcClass" ) 6150 // DW_AT_byte_size( 0x00 ) 6151 // DW_AT_decl_file( "..." ) 6152 // DW_AT_decl_line( 1 ) 6153 // 6154 // Note that there is no DW_AT_declaration and there are 6155 // no children, and the byte size is zero. 6156 is_forward_declaration = true; 6157 } 6158 6159 if (class_language == eLanguageTypeObjC || 6160 class_language == eLanguageTypeObjC_plus_plus) 6161 { 6162 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu)) 6163 { 6164 // We have a valid eSymbolTypeObjCClass class symbol whose 6165 // name matches the current objective C class that we 6166 // are trying to find and this DIE isn't the complete 6167 // definition (we checked is_complete_objc_class above and 6168 // know it is false), so the real definition is in here somewhere 6169 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); 6170 6171 if (!type_sp && GetDebugMapSymfile ()) 6172 { 6173 // We weren't able to find a full declaration in 6174 // this DWARF, see if we have a declaration anywhere 6175 // else... 6176 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); 6177 } 6178 6179 if (type_sp) 6180 { 6181 if (log) 6182 { 6183 GetObjectFile()->GetModule()->LogMessage (log, 6184 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, 6185 static_cast<void*>(this), 6186 die->GetOffset(), 6187 DW_TAG_value_to_name(tag), 6188 type_name_cstr, 6189 type_sp->GetID()); 6190 } 6191 6192 // We found a real definition for this type elsewhere 6193 // so lets use it and cache the fact that we found 6194 // a complete type for this die 6195 m_die_to_type[die] = type_sp.get(); 6196 return type_sp; 6197 } 6198 } 6199 } 6200 6201 6202 if (is_forward_declaration) 6203 { 6204 // We have a forward declaration to a type and we need 6205 // to try and find a full declaration. We look in the 6206 // current type index just in case we have a forward 6207 // declaration followed by an actual declarations in the 6208 // DWARF. If this fails, we need to look elsewhere... 6209 if (log) 6210 { 6211 GetObjectFile()->GetModule()->LogMessage (log, 6212 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", 6213 static_cast<void*>(this), 6214 die->GetOffset(), 6215 DW_TAG_value_to_name(tag), 6216 type_name_cstr); 6217 } 6218 6219 DWARFDeclContext die_decl_ctx; 6220 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx); 6221 6222 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); 6223 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 6224 6225 if (!type_sp && GetDebugMapSymfile ()) 6226 { 6227 // We weren't able to find a full declaration in 6228 // this DWARF, see if we have a declaration anywhere 6229 // else... 6230 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 6231 } 6232 6233 if (type_sp) 6234 { 6235 if (log) 6236 { 6237 GetObjectFile()->GetModule()->LogMessage (log, 6238 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, 6239 static_cast<void*>(this), 6240 die->GetOffset(), 6241 DW_TAG_value_to_name(tag), 6242 type_name_cstr, 6243 type_sp->GetID()); 6244 } 6245 6246 // We found a real definition for this type elsewhere 6247 // so lets use it and cache the fact that we found 6248 // a complete type for this die 6249 m_die_to_type[die] = type_sp.get(); 6250 return type_sp; 6251 } 6252 } 6253 assert (tag_decl_kind != -1); 6254 bool clang_type_was_created = false; 6255 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); 6256 if (!clang_type) 6257 { 6258 const DWARFDebugInfoEntry *decl_ctx_die; 6259 6260 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); 6261 if (accessibility == eAccessNone && decl_ctx) 6262 { 6263 // Check the decl context that contains this class/struct/union. 6264 // If it is a class we must give it an accessibility. 6265 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); 6266 if (DeclKindIsCXXClass (containing_decl_kind)) 6267 accessibility = default_accessibility; 6268 } 6269 6270 ClangASTMetadata metadata; 6271 metadata.SetUserID(MakeUserID(die->GetOffset())); 6272 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die)); 6273 6274 if (type_name_cstr && strchr (type_name_cstr, '<')) 6275 { 6276 ClangASTContext::TemplateParameterInfos template_param_infos; 6277 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos)) 6278 { 6279 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx, 6280 accessibility, 6281 type_name_cstr, 6282 tag_decl_kind, 6283 template_param_infos); 6284 6285 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx, 6286 class_template_decl, 6287 tag_decl_kind, 6288 template_param_infos); 6289 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl); 6290 clang_type_was_created = true; 6291 6292 GetClangASTContext().SetMetadata (class_template_decl, metadata); 6293 GetClangASTContext().SetMetadata (class_specialization_decl, metadata); 6294 } 6295 } 6296 6297 if (!clang_type_was_created) 6298 { 6299 clang_type_was_created = true; 6300 clang_type = ast.CreateRecordType (decl_ctx, 6301 accessibility, 6302 type_name_cstr, 6303 tag_decl_kind, 6304 class_language, 6305 &metadata); 6306 } 6307 } 6308 6309 // Store a forward declaration to this class type in case any 6310 // parameters in any class methods need it for the clang 6311 // types for function prototypes. 6312 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); 6313 type_sp.reset (new Type (MakeUserID(die->GetOffset()), 6314 this, 6315 type_name_const_str, 6316 byte_size, 6317 NULL, 6318 LLDB_INVALID_UID, 6319 Type::eEncodingIsUID, 6320 &decl, 6321 clang_type, 6322 Type::eResolveStateForward)); 6323 6324 type_sp->SetIsCompleteObjCClass(is_complete_objc_class); 6325 6326 6327 // Add our type to the unique type map so we don't 6328 // end up creating many copies of the same type over 6329 // and over in the ASTContext for our module 6330 unique_ast_entry_ap->m_type_sp = type_sp; 6331 unique_ast_entry_ap->m_symfile = this; 6332 unique_ast_entry_ap->m_cu = dwarf_cu; 6333 unique_ast_entry_ap->m_die = die; 6334 unique_ast_entry_ap->m_declaration = decl; 6335 unique_ast_entry_ap->m_byte_size = byte_size; 6336 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str, 6337 *unique_ast_entry_ap); 6338 6339 if (is_forward_declaration && die->HasChildren()) 6340 { 6341 // Check to see if the DIE actually has a definition, some version of GCC will 6342 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, 6343 // members, or inheritance, so we can't trust it 6344 const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); 6345 while (child_die) 6346 { 6347 switch (child_die->Tag()) 6348 { 6349 case DW_TAG_inheritance: 6350 case DW_TAG_subprogram: 6351 case DW_TAG_member: 6352 case DW_TAG_APPLE_property: 6353 case DW_TAG_class_type: 6354 case DW_TAG_structure_type: 6355 case DW_TAG_enumeration_type: 6356 case DW_TAG_typedef: 6357 case DW_TAG_union_type: 6358 child_die = NULL; 6359 is_forward_declaration = false; 6360 break; 6361 default: 6362 child_die = child_die->GetSibling(); 6363 break; 6364 } 6365 } 6366 } 6367 6368 if (!is_forward_declaration) 6369 { 6370 // Always start the definition for a class type so that 6371 // if the class has child classes or types that require 6372 // the class to be created for use as their decl contexts 6373 // the class will be ready to accept these child definitions. 6374 if (die->HasChildren() == false) 6375 { 6376 // No children for this struct/union/class, lets finish it 6377 clang_type.StartTagDeclarationDefinition (); 6378 clang_type.CompleteTagDeclarationDefinition (); 6379 6380 if (tag == DW_TAG_structure_type) // this only applies in C 6381 { 6382 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl(); 6383 6384 if (record_decl) 6385 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo())); 6386 } 6387 } 6388 else if (clang_type_was_created) 6389 { 6390 // Start the definition if the class is not objective C since 6391 // the underlying decls respond to isCompleteDefinition(). Objective 6392 // C decls don't respond to isCompleteDefinition() so we can't 6393 // start the declaration definition right away. For C++ class/union/structs 6394 // we want to start the definition in case the class is needed as the 6395 // declaration context for a contained class or type without the need 6396 // to complete that type.. 6397 6398 if (class_language != eLanguageTypeObjC && 6399 class_language != eLanguageTypeObjC_plus_plus) 6400 clang_type.StartTagDeclarationDefinition (); 6401 6402 // Leave this as a forward declaration until we need 6403 // to know the details of the type. lldb_private::Type 6404 // will automatically call the SymbolFile virtual function 6405 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" 6406 // When the definition needs to be defined. 6407 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType(); 6408 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die; 6409 clang_type.SetHasExternalStorage (true); 6410 } 6411 } 6412 6413 } 6414 break; 6415 6416 case DW_TAG_enumeration_type: 6417 { 6418 // Set a bit that lets us know that we are currently parsing this 6419 m_die_to_type[die] = DIE_IS_BEING_PARSED; 6420 6421 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; 6422 6423 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 6424 if (num_attributes > 0) 6425 { 6426 uint32_t i; 6427 6428 for (i=0; i<num_attributes; ++i) 6429 { 6430 attr = attributes.AttributeAtIndex(i); 6431 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 6432 { 6433 switch (attr) 6434 { 6435 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 6436 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 6437 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 6438 case DW_AT_name: 6439 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 6440 type_name_const_str.SetCString(type_name_cstr); 6441 break; 6442 case DW_AT_type: encoding_uid = form_value.Reference(); break; 6443 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 6444 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 6445 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break; 6446 case DW_AT_allocated: 6447 case DW_AT_associated: 6448 case DW_AT_bit_stride: 6449 case DW_AT_byte_stride: 6450 case DW_AT_data_location: 6451 case DW_AT_description: 6452 case DW_AT_start_scope: 6453 case DW_AT_visibility: 6454 case DW_AT_specification: 6455 case DW_AT_abstract_origin: 6456 case DW_AT_sibling: 6457 break; 6458 } 6459 } 6460 } 6461 6462 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); 6463 6464 ClangASTType enumerator_clang_type; 6465 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die)); 6466 if (!clang_type) 6467 { 6468 if (encoding_uid != DW_INVALID_OFFSET) 6469 { 6470 Type *enumerator_type = ResolveTypeUID(encoding_uid); 6471 if (enumerator_type) 6472 enumerator_clang_type = enumerator_type->GetClangFullType(); 6473 } 6474 6475 if (!enumerator_clang_type) 6476 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, 6477 DW_ATE_signed, 6478 byte_size * 8); 6479 6480 clang_type = ast.CreateEnumerationType (type_name_cstr, 6481 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL), 6482 decl, 6483 enumerator_clang_type); 6484 } 6485 else 6486 { 6487 enumerator_clang_type = clang_type.GetEnumerationIntegerType (); 6488 } 6489 6490 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die); 6491 6492 type_sp.reset( new Type (MakeUserID(die->GetOffset()), 6493 this, 6494 type_name_const_str, 6495 byte_size, 6496 NULL, 6497 encoding_uid, 6498 Type::eEncodingIsUID, 6499 &decl, 6500 clang_type, 6501 Type::eResolveStateForward)); 6502 6503 clang_type.StartTagDeclarationDefinition (); 6504 if (die->HasChildren()) 6505 { 6506 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu)); 6507 bool is_signed = false; 6508 enumerator_clang_type.IsIntegerType(is_signed); 6509 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die); 6510 } 6511 clang_type.CompleteTagDeclarationDefinition (); 6512 } 6513 } 6514 break; 6515 6516 case DW_TAG_inlined_subroutine: 6517 case DW_TAG_subprogram: 6518 case DW_TAG_subroutine_type: 6519 { 6520 // Set a bit that lets us know that we are currently parsing this 6521 m_die_to_type[die] = DIE_IS_BEING_PARSED; 6522 6523 //const char *mangled = NULL; 6524 dw_offset_t type_die_offset = DW_INVALID_OFFSET; 6525 bool is_variadic = false; 6526 bool is_inline = false; 6527 bool is_static = false; 6528 bool is_virtual = false; 6529 bool is_explicit = false; 6530 bool is_artificial = false; 6531 dw_offset_t specification_die_offset = DW_INVALID_OFFSET; 6532 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET; 6533 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; 6534 6535 unsigned type_quals = 0; 6536 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern 6537 6538 6539 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 6540 if (num_attributes > 0) 6541 { 6542 uint32_t i; 6543 for (i=0; i<num_attributes; ++i) 6544 { 6545 attr = attributes.AttributeAtIndex(i); 6546 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 6547 { 6548 switch (attr) 6549 { 6550 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 6551 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 6552 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 6553 case DW_AT_name: 6554 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 6555 type_name_const_str.SetCString(type_name_cstr); 6556 break; 6557 6558 case DW_AT_linkage_name: 6559 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break; 6560 case DW_AT_type: type_die_offset = form_value.Reference(); break; 6561 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 6562 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; 6563 case DW_AT_inline: is_inline = form_value.Boolean(); break; 6564 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; 6565 case DW_AT_explicit: is_explicit = form_value.Boolean(); break; 6566 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 6567 6568 6569 case DW_AT_external: 6570 if (form_value.Unsigned()) 6571 { 6572 if (storage == clang::SC_None) 6573 storage = clang::SC_Extern; 6574 else 6575 storage = clang::SC_PrivateExtern; 6576 } 6577 break; 6578 6579 case DW_AT_specification: 6580 specification_die_offset = form_value.Reference(); 6581 break; 6582 6583 case DW_AT_abstract_origin: 6584 abstract_origin_die_offset = form_value.Reference(); 6585 break; 6586 6587 case DW_AT_object_pointer: 6588 object_pointer_die_offset = form_value.Reference(); 6589 break; 6590 6591 case DW_AT_allocated: 6592 case DW_AT_associated: 6593 case DW_AT_address_class: 6594 case DW_AT_calling_convention: 6595 case DW_AT_data_location: 6596 case DW_AT_elemental: 6597 case DW_AT_entry_pc: 6598 case DW_AT_frame_base: 6599 case DW_AT_high_pc: 6600 case DW_AT_low_pc: 6601 case DW_AT_prototyped: 6602 case DW_AT_pure: 6603 case DW_AT_ranges: 6604 case DW_AT_recursive: 6605 case DW_AT_return_addr: 6606 case DW_AT_segment: 6607 case DW_AT_start_scope: 6608 case DW_AT_static_link: 6609 case DW_AT_trampoline: 6610 case DW_AT_visibility: 6611 case DW_AT_vtable_elem_location: 6612 case DW_AT_description: 6613 case DW_AT_sibling: 6614 break; 6615 } 6616 } 6617 } 6618 } 6619 6620 std::string object_pointer_name; 6621 if (object_pointer_die_offset != DW_INVALID_OFFSET) 6622 { 6623 // Get the name from the object pointer die 6624 StreamString s; 6625 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s)) 6626 { 6627 object_pointer_name.assign(s.GetData()); 6628 } 6629 } 6630 6631 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); 6632 6633 ClangASTType return_clang_type; 6634 Type *func_type = NULL; 6635 6636 if (type_die_offset != DW_INVALID_OFFSET) 6637 func_type = ResolveTypeUID(type_die_offset); 6638 6639 if (func_type) 6640 return_clang_type = func_type->GetClangForwardType(); 6641 else 6642 return_clang_type = ast.GetBasicType(eBasicTypeVoid); 6643 6644 6645 std::vector<ClangASTType> function_param_types; 6646 std::vector<clang::ParmVarDecl*> function_param_decls; 6647 6648 // Parse the function children for the parameters 6649 6650 const DWARFDebugInfoEntry *decl_ctx_die = NULL; 6651 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die); 6652 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); 6653 6654 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); 6655 // Start off static. This will be set to false in ParseChildParameters(...) 6656 // if we find a "this" parameters as the first parameter 6657 if (is_cxx_method) 6658 is_static = true; 6659 6660 if (die->HasChildren()) 6661 { 6662 bool skip_artificial = true; 6663 ParseChildParameters (sc, 6664 containing_decl_ctx, 6665 dwarf_cu, 6666 die, 6667 skip_artificial, 6668 is_static, 6669 is_variadic, 6670 function_param_types, 6671 function_param_decls, 6672 type_quals); 6673 } 6674 6675 // clang_type will get the function prototype clang type after this call 6676 clang_type = ast.CreateFunctionType (return_clang_type, 6677 function_param_types.data(), 6678 function_param_types.size(), 6679 is_variadic, 6680 type_quals); 6681 6682 bool ignore_containing_context = false; 6683 6684 if (type_name_cstr) 6685 { 6686 bool type_handled = false; 6687 if (tag == DW_TAG_subprogram) 6688 { 6689 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true); 6690 if (objc_method.IsValid(true)) 6691 { 6692 ClangASTType class_opaque_type; 6693 ConstString class_name(objc_method.GetClassName()); 6694 if (class_name) 6695 { 6696 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false)); 6697 6698 if (complete_objc_class_type_sp) 6699 { 6700 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType(); 6701 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ()) 6702 class_opaque_type = type_clang_forward_type; 6703 } 6704 } 6705 6706 if (class_opaque_type) 6707 { 6708 // If accessibility isn't set to anything valid, assume public for 6709 // now... 6710 if (accessibility == eAccessNone) 6711 accessibility = eAccessPublic; 6712 6713 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr, 6714 clang_type, 6715 accessibility, 6716 is_artificial); 6717 type_handled = objc_method_decl != NULL; 6718 if (type_handled) 6719 { 6720 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); 6721 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset())); 6722 } 6723 else 6724 { 6725 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", 6726 die->GetOffset(), 6727 tag, 6728 DW_TAG_value_to_name(tag)); 6729 } 6730 } 6731 } 6732 else if (is_cxx_method) 6733 { 6734 // Look at the parent of this DIE and see if is is 6735 // a class or struct and see if this is actually a 6736 // C++ method 6737 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die); 6738 if (class_type) 6739 { 6740 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset())) 6741 { 6742 // We uniqued the parent class of this function to another class 6743 // so we now need to associate all dies under "decl_ctx_die" to 6744 // DIEs in the DIE for "class_type"... 6745 SymbolFileDWARF *class_symfile = NULL; 6746 DWARFCompileUnitSP class_type_cu_sp; 6747 const DWARFDebugInfoEntry *class_type_die = NULL; 6748 6749 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); 6750 if (debug_map_symfile) 6751 { 6752 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); 6753 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); 6754 } 6755 else 6756 { 6757 class_symfile = this; 6758 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp); 6759 } 6760 if (class_type_die) 6761 { 6762 DWARFDIECollection failures; 6763 6764 CopyUniqueClassMethodTypes (class_symfile, 6765 class_type, 6766 class_type_cu_sp.get(), 6767 class_type_die, 6768 dwarf_cu, 6769 decl_ctx_die, 6770 failures); 6771 6772 // FIXME do something with these failures that's smarter than 6773 // just dropping them on the ground. Unfortunately classes don't 6774 // like having stuff added to them after their definitions are 6775 // complete... 6776 6777 type_ptr = m_die_to_type[die]; 6778 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) 6779 { 6780 type_sp = type_ptr->shared_from_this(); 6781 break; 6782 } 6783 } 6784 } 6785 6786 if (specification_die_offset != DW_INVALID_OFFSET) 6787 { 6788 // We have a specification which we are going to base our function 6789 // prototype off of, so we need this type to be completed so that the 6790 // m_die_to_decl_ctx for the method in the specification has a valid 6791 // clang decl context. 6792 class_type->GetClangForwardType(); 6793 // If we have a specification, then the function type should have been 6794 // made with the specification and not with this die. 6795 DWARFCompileUnitSP spec_cu_sp; 6796 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp); 6797 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die); 6798 if (spec_clang_decl_ctx) 6799 { 6800 LinkDeclContextToDIE(spec_clang_decl_ctx, die); 6801 } 6802 else 6803 { 6804 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n", 6805 MakeUserID(die->GetOffset()), 6806 specification_die_offset); 6807 } 6808 type_handled = true; 6809 } 6810 else if (abstract_origin_die_offset != DW_INVALID_OFFSET) 6811 { 6812 // We have a specification which we are going to base our function 6813 // prototype off of, so we need this type to be completed so that the 6814 // m_die_to_decl_ctx for the method in the abstract origin has a valid 6815 // clang decl context. 6816 class_type->GetClangForwardType(); 6817 6818 DWARFCompileUnitSP abs_cu_sp; 6819 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp); 6820 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die); 6821 if (abs_clang_decl_ctx) 6822 { 6823 LinkDeclContextToDIE (abs_clang_decl_ctx, die); 6824 } 6825 else 6826 { 6827 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x) has no decl\n", 6828 MakeUserID(die->GetOffset()), 6829 abstract_origin_die_offset); 6830 } 6831 type_handled = true; 6832 } 6833 else 6834 { 6835 ClangASTType class_opaque_type = class_type->GetClangForwardType(); 6836 if (class_opaque_type.IsCXXClassType ()) 6837 { 6838 if (class_opaque_type.IsBeingDefined ()) 6839 { 6840 // Neither GCC 4.2 nor clang++ currently set a valid accessibility 6841 // in the DWARF for C++ methods... Default to public for now... 6842 if (accessibility == eAccessNone) 6843 accessibility = eAccessPublic; 6844 6845 if (!is_static && !die->HasChildren()) 6846 { 6847 // We have a C++ member function with no children (this pointer!) 6848 // and clang will get mad if we try and make a function that isn't 6849 // well formed in the DWARF, so we will just skip it... 6850 type_handled = true; 6851 } 6852 else 6853 { 6854 clang::CXXMethodDecl *cxx_method_decl; 6855 // REMOVE THE CRASH DESCRIPTION BELOW 6856 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s", 6857 type_name_cstr, 6858 class_type->GetName().GetCString(), 6859 MakeUserID(die->GetOffset()), 6860 m_obj_file->GetFileSpec().GetPath().c_str()); 6861 6862 const bool is_attr_used = false; 6863 6864 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr, 6865 clang_type, 6866 accessibility, 6867 is_virtual, 6868 is_static, 6869 is_inline, 6870 is_explicit, 6871 is_attr_used, 6872 is_artificial); 6873 6874 type_handled = cxx_method_decl != NULL; 6875 6876 if (type_handled) 6877 { 6878 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); 6879 6880 Host::SetCrashDescription (NULL); 6881 6882 6883 ClangASTMetadata metadata; 6884 metadata.SetUserID(MakeUserID(die->GetOffset())); 6885 6886 if (!object_pointer_name.empty()) 6887 { 6888 metadata.SetObjectPtrName(object_pointer_name.c_str()); 6889 if (log) 6890 log->Printf ("Setting object pointer name: %s on method object %p.\n", 6891 object_pointer_name.c_str(), 6892 static_cast<void*>(cxx_method_decl)); 6893 } 6894 GetClangASTContext().SetMetadata (cxx_method_decl, metadata); 6895 } 6896 else 6897 { 6898 ignore_containing_context = true; 6899 } 6900 } 6901 } 6902 else 6903 { 6904 // We were asked to parse the type for a method in a class, yet the 6905 // class hasn't been asked to complete itself through the 6906 // clang::ExternalASTSource protocol, so we need to just have the 6907 // class complete itself and do things the right way, then our 6908 // DIE should then have an entry in the m_die_to_type map. First 6909 // we need to modify the m_die_to_type so it doesn't think we are 6910 // trying to parse this DIE anymore... 6911 m_die_to_type[die] = NULL; 6912 6913 // Now we get the full type to force our class type to complete itself 6914 // using the clang::ExternalASTSource protocol which will parse all 6915 // base classes and all methods (including the method for this DIE). 6916 class_type->GetClangFullType(); 6917 6918 // The type for this DIE should have been filled in the function call above 6919 type_ptr = m_die_to_type[die]; 6920 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) 6921 { 6922 type_sp = type_ptr->shared_from_this(); 6923 break; 6924 } 6925 6926 // FIXME This is fixing some even uglier behavior but we really need to 6927 // uniq the methods of each class as well as the class itself. 6928 // <rdar://problem/11240464> 6929 type_handled = true; 6930 } 6931 } 6932 } 6933 } 6934 } 6935 } 6936 6937 if (!type_handled) 6938 { 6939 // We just have a function that isn't part of a class 6940 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx, 6941 type_name_cstr, 6942 clang_type, 6943 storage, 6944 is_inline); 6945 6946 // if (template_param_infos.GetSize() > 0) 6947 // { 6948 // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx, 6949 // function_decl, 6950 // type_name_cstr, 6951 // template_param_infos); 6952 // 6953 // ast.CreateFunctionTemplateSpecializationInfo (function_decl, 6954 // func_template_decl, 6955 // template_param_infos); 6956 // } 6957 // Add the decl to our DIE to decl context map 6958 assert (function_decl); 6959 LinkDeclContextToDIE(function_decl, die); 6960 if (!function_param_decls.empty()) 6961 ast.SetFunctionParameters (function_decl, 6962 &function_param_decls.front(), 6963 function_param_decls.size()); 6964 6965 ClangASTMetadata metadata; 6966 metadata.SetUserID(MakeUserID(die->GetOffset())); 6967 6968 if (!object_pointer_name.empty()) 6969 { 6970 metadata.SetObjectPtrName(object_pointer_name.c_str()); 6971 if (log) 6972 log->Printf ("Setting object pointer name: %s on function object %p.", 6973 object_pointer_name.c_str(), 6974 static_cast<void*>(function_decl)); 6975 } 6976 GetClangASTContext().SetMetadata (function_decl, metadata); 6977 } 6978 } 6979 type_sp.reset( new Type (MakeUserID(die->GetOffset()), 6980 this, 6981 type_name_const_str, 6982 0, 6983 NULL, 6984 LLDB_INVALID_UID, 6985 Type::eEncodingIsUID, 6986 &decl, 6987 clang_type, 6988 Type::eResolveStateFull)); 6989 assert(type_sp.get()); 6990 } 6991 break; 6992 6993 case DW_TAG_array_type: 6994 { 6995 // Set a bit that lets us know that we are currently parsing this 6996 m_die_to_type[die] = DIE_IS_BEING_PARSED; 6997 6998 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; 6999 int64_t first_index = 0; 7000 uint32_t byte_stride = 0; 7001 uint32_t bit_stride = 0; 7002 bool is_vector = false; 7003 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 7004 7005 if (num_attributes > 0) 7006 { 7007 uint32_t i; 7008 for (i=0; i<num_attributes; ++i) 7009 { 7010 attr = attributes.AttributeAtIndex(i); 7011 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 7012 { 7013 switch (attr) 7014 { 7015 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 7016 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 7017 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 7018 case DW_AT_name: 7019 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 7020 type_name_const_str.SetCString(type_name_cstr); 7021 break; 7022 7023 case DW_AT_type: type_die_offset = form_value.Reference(); break; 7024 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; 7025 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; 7026 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; 7027 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break; 7028 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 7029 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; 7030 case DW_AT_allocated: 7031 case DW_AT_associated: 7032 case DW_AT_data_location: 7033 case DW_AT_description: 7034 case DW_AT_ordering: 7035 case DW_AT_start_scope: 7036 case DW_AT_visibility: 7037 case DW_AT_specification: 7038 case DW_AT_abstract_origin: 7039 case DW_AT_sibling: 7040 break; 7041 } 7042 } 7043 } 7044 7045 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr); 7046 7047 Type *element_type = ResolveTypeUID(type_die_offset); 7048 7049 if (element_type) 7050 { 7051 std::vector<uint64_t> element_orders; 7052 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); 7053 if (byte_stride == 0 && bit_stride == 0) 7054 byte_stride = element_type->GetByteSize(); 7055 ClangASTType array_element_type = element_type->GetClangForwardType(); 7056 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; 7057 if (element_orders.size() > 0) 7058 { 7059 uint64_t num_elements = 0; 7060 std::vector<uint64_t>::const_reverse_iterator pos; 7061 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); 7062 for (pos = element_orders.rbegin(); pos != end; ++pos) 7063 { 7064 num_elements = *pos; 7065 clang_type = ast.CreateArrayType (array_element_type, 7066 num_elements, 7067 is_vector); 7068 array_element_type = clang_type; 7069 array_element_bit_stride = num_elements ? 7070 array_element_bit_stride * num_elements : 7071 array_element_bit_stride; 7072 } 7073 } 7074 else 7075 { 7076 clang_type = ast.CreateArrayType (array_element_type, 0, is_vector); 7077 } 7078 ConstString empty_name; 7079 type_sp.reset( new Type (MakeUserID(die->GetOffset()), 7080 this, 7081 empty_name, 7082 array_element_bit_stride / 8, 7083 NULL, 7084 type_die_offset, 7085 Type::eEncodingIsUID, 7086 &decl, 7087 clang_type, 7088 Type::eResolveStateFull)); 7089 type_sp->SetEncodingType (element_type); 7090 } 7091 } 7092 } 7093 break; 7094 7095 case DW_TAG_ptr_to_member_type: 7096 { 7097 dw_offset_t type_die_offset = DW_INVALID_OFFSET; 7098 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; 7099 7100 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 7101 7102 if (num_attributes > 0) { 7103 uint32_t i; 7104 for (i=0; i<num_attributes; ++i) 7105 { 7106 attr = attributes.AttributeAtIndex(i); 7107 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 7108 { 7109 switch (attr) 7110 { 7111 case DW_AT_type: 7112 type_die_offset = form_value.Reference(); break; 7113 case DW_AT_containing_type: 7114 containing_type_die_offset = form_value.Reference(); break; 7115 } 7116 } 7117 } 7118 7119 Type *pointee_type = ResolveTypeUID(type_die_offset); 7120 Type *class_type = ResolveTypeUID(containing_type_die_offset); 7121 7122 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType(); 7123 ClangASTType class_clang_type = class_type->GetClangLayoutType(); 7124 7125 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type); 7126 7127 byte_size = clang_type.GetByteSize(nullptr); 7128 7129 type_sp.reset( new Type (MakeUserID(die->GetOffset()), 7130 this, 7131 type_name_const_str, 7132 byte_size, 7133 NULL, 7134 LLDB_INVALID_UID, 7135 Type::eEncodingIsUID, 7136 NULL, 7137 clang_type, 7138 Type::eResolveStateForward)); 7139 } 7140 7141 break; 7142 } 7143 default: 7144 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", 7145 die->GetOffset(), 7146 tag, 7147 DW_TAG_value_to_name(tag)); 7148 break; 7149 } 7150 7151 if (type_sp.get()) 7152 { 7153 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); 7154 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; 7155 7156 SymbolContextScope * symbol_context_scope = NULL; 7157 if (sc_parent_tag == DW_TAG_compile_unit) 7158 { 7159 symbol_context_scope = sc.comp_unit; 7160 } 7161 else if (sc.function != NULL && sc_parent_die) 7162 { 7163 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); 7164 if (symbol_context_scope == NULL) 7165 symbol_context_scope = sc.function; 7166 } 7167 7168 if (symbol_context_scope != NULL) 7169 { 7170 type_sp->SetSymbolContextScope(symbol_context_scope); 7171 } 7172 7173 // We are ready to put this type into the uniqued list up at the module level 7174 type_list->Insert (type_sp); 7175 7176 m_die_to_type[die] = type_sp.get(); 7177 } 7178 } 7179 else if (type_ptr != DIE_IS_BEING_PARSED) 7180 { 7181 type_sp = type_ptr->shared_from_this(); 7182 } 7183 } 7184 return type_sp; 7185 } 7186 7187 size_t 7188 SymbolFileDWARF::ParseTypes 7189 ( 7190 const SymbolContext& sc, 7191 DWARFCompileUnit* dwarf_cu, 7192 const DWARFDebugInfoEntry *die, 7193 bool parse_siblings, 7194 bool parse_children 7195 ) 7196 { 7197 size_t types_added = 0; 7198 while (die != NULL) 7199 { 7200 bool type_is_new = false; 7201 if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) 7202 { 7203 if (type_is_new) 7204 ++types_added; 7205 } 7206 7207 if (parse_children && die->HasChildren()) 7208 { 7209 if (die->Tag() == DW_TAG_subprogram) 7210 { 7211 SymbolContext child_sc(sc); 7212 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get(); 7213 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); 7214 } 7215 else 7216 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); 7217 } 7218 7219 if (parse_siblings) 7220 die = die->GetSibling(); 7221 else 7222 die = NULL; 7223 } 7224 return types_added; 7225 } 7226 7227 7228 size_t 7229 SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) 7230 { 7231 assert(sc.comp_unit && sc.function); 7232 size_t functions_added = 0; 7233 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 7234 if (dwarf_cu) 7235 { 7236 dw_offset_t function_die_offset = sc.function->GetID(); 7237 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); 7238 if (function_die) 7239 { 7240 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0); 7241 } 7242 } 7243 7244 return functions_added; 7245 } 7246 7247 7248 size_t 7249 SymbolFileDWARF::ParseTypes (const SymbolContext &sc) 7250 { 7251 // At least a compile unit must be valid 7252 assert(sc.comp_unit); 7253 size_t types_added = 0; 7254 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); 7255 if (dwarf_cu) 7256 { 7257 if (sc.function) 7258 { 7259 dw_offset_t function_die_offset = sc.function->GetID(); 7260 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); 7261 if (func_die && func_die->HasChildren()) 7262 { 7263 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); 7264 } 7265 } 7266 else 7267 { 7268 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); 7269 if (dwarf_cu_die && dwarf_cu_die->HasChildren()) 7270 { 7271 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); 7272 } 7273 } 7274 } 7275 7276 return types_added; 7277 } 7278 7279 size_t 7280 SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) 7281 { 7282 if (sc.comp_unit != NULL) 7283 { 7284 DWARFDebugInfo* info = DebugInfo(); 7285 if (info == NULL) 7286 return 0; 7287 7288 if (sc.function) 7289 { 7290 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get(); 7291 7292 if (dwarf_cu == NULL) 7293 return 0; 7294 7295 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); 7296 7297 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS); 7298 if (func_lo_pc != LLDB_INVALID_ADDRESS) 7299 { 7300 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); 7301 7302 // Let all blocks know they have parse all their variables 7303 sc.function->GetBlock (false).SetDidParseVariables (true, true); 7304 return num_variables; 7305 } 7306 } 7307 else if (sc.comp_unit) 7308 { 7309 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get(); 7310 7311 if (dwarf_cu == NULL) 7312 return 0; 7313 7314 uint32_t vars_added = 0; 7315 VariableListSP variables (sc.comp_unit->GetVariableList(false)); 7316 7317 if (variables.get() == NULL) 7318 { 7319 variables.reset(new VariableList()); 7320 sc.comp_unit->SetVariableList(variables); 7321 7322 DWARFCompileUnit* match_dwarf_cu = NULL; 7323 const DWARFDebugInfoEntry* die = NULL; 7324 DIEArray die_offsets; 7325 if (m_using_apple_tables) 7326 { 7327 if (m_apple_names_ap.get()) 7328 { 7329 DWARFMappedHash::DIEInfoArray hash_data_array; 7330 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(), 7331 dwarf_cu->GetNextCompileUnitOffset(), 7332 hash_data_array)) 7333 { 7334 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets); 7335 } 7336 } 7337 } 7338 else 7339 { 7340 // Index if we already haven't to make sure the compile units 7341 // get indexed and make their global DIE index list 7342 if (!m_indexed) 7343 Index (); 7344 7345 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(), 7346 dwarf_cu->GetNextCompileUnitOffset(), 7347 die_offsets); 7348 } 7349 7350 const size_t num_matches = die_offsets.size(); 7351 if (num_matches) 7352 { 7353 DWARFDebugInfo* debug_info = DebugInfo(); 7354 for (size_t i=0; i<num_matches; ++i) 7355 { 7356 const dw_offset_t die_offset = die_offsets[i]; 7357 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu); 7358 if (die) 7359 { 7360 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS)); 7361 if (var_sp) 7362 { 7363 variables->AddVariableIfUnique (var_sp); 7364 ++vars_added; 7365 } 7366 } 7367 else 7368 { 7369 if (m_using_apple_tables) 7370 { 7371 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset); 7372 } 7373 } 7374 7375 } 7376 } 7377 } 7378 return vars_added; 7379 } 7380 } 7381 return 0; 7382 } 7383 7384 7385 VariableSP 7386 SymbolFileDWARF::ParseVariableDIE 7387 ( 7388 const SymbolContext& sc, 7389 DWARFCompileUnit* dwarf_cu, 7390 const DWARFDebugInfoEntry *die, 7391 const lldb::addr_t func_low_pc 7392 ) 7393 { 7394 VariableSP var_sp (m_die_to_variable_sp[die]); 7395 if (var_sp) 7396 return var_sp; // Already been parsed! 7397 7398 const dw_tag_t tag = die->Tag(); 7399 ModuleSP module = GetObjectFile()->GetModule(); 7400 7401 if ((tag == DW_TAG_variable) || 7402 (tag == DW_TAG_constant) || 7403 (tag == DW_TAG_formal_parameter && sc.function)) 7404 { 7405 DWARFDebugInfoEntry::Attributes attributes; 7406 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 7407 if (num_attributes > 0) 7408 { 7409 const char *name = NULL; 7410 const char *mangled = NULL; 7411 Declaration decl; 7412 uint32_t i; 7413 lldb::user_id_t type_uid = LLDB_INVALID_UID; 7414 DWARFExpression location; 7415 bool is_external = false; 7416 bool is_artificial = false; 7417 bool location_is_const_value_data = false; 7418 bool has_explicit_location = false; 7419 DWARFFormValue const_value; 7420 //AccessType accessibility = eAccessNone; 7421 7422 for (i=0; i<num_attributes; ++i) 7423 { 7424 dw_attr_t attr = attributes.AttributeAtIndex(i); 7425 DWARFFormValue form_value; 7426 7427 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 7428 { 7429 switch (attr) 7430 { 7431 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 7432 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 7433 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 7434 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 7435 case DW_AT_linkage_name: 7436 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; 7437 case DW_AT_type: type_uid = form_value.Reference(); break; 7438 case DW_AT_external: is_external = form_value.Boolean(); break; 7439 case DW_AT_const_value: 7440 // If we have already found a DW_AT_location attribute, ignore this attribute. 7441 if (!has_explicit_location) 7442 { 7443 location_is_const_value_data = true; 7444 // The constant value will be either a block, a data value or a string. 7445 const DWARFDataExtractor& debug_info_data = get_debug_info_data(); 7446 if (DWARFFormValue::IsBlockForm(form_value.Form())) 7447 { 7448 // Retrieve the value as a block expression. 7449 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 7450 uint32_t block_length = form_value.Unsigned(); 7451 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length); 7452 } 7453 else if (DWARFFormValue::IsDataForm(form_value.Form())) 7454 { 7455 // Retrieve the value as a data expression. 7456 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); 7457 uint32_t data_offset = attributes.DIEOffsetAtIndex(i); 7458 uint32_t data_length = fixed_form_sizes[form_value.Form()]; 7459 if (data_length == 0) 7460 { 7461 const uint8_t *data_pointer = form_value.BlockData(); 7462 if (data_pointer) 7463 { 7464 form_value.Unsigned(); 7465 } 7466 else if (DWARFFormValue::IsDataForm(form_value.Form())) 7467 { 7468 // we need to get the byte size of the type later after we create the variable 7469 const_value = form_value; 7470 } 7471 } 7472 else 7473 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); 7474 } 7475 else 7476 { 7477 // Retrieve the value as a string expression. 7478 if (form_value.Form() == DW_FORM_strp) 7479 { 7480 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (attributes.CompileUnitAtIndex(i)->GetAddressByteSize(), attributes.CompileUnitAtIndex(i)->IsDWARF64()); 7481 uint32_t data_offset = attributes.DIEOffsetAtIndex(i); 7482 uint32_t data_length = fixed_form_sizes[form_value.Form()]; 7483 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length); 7484 } 7485 else 7486 { 7487 const char *str = form_value.AsCString(&debug_info_data); 7488 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart(); 7489 uint32_t string_length = strlen(str) + 1; 7490 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length); 7491 } 7492 } 7493 } 7494 break; 7495 case DW_AT_location: 7496 { 7497 location_is_const_value_data = false; 7498 has_explicit_location = true; 7499 if (form_value.BlockData()) 7500 { 7501 const DWARFDataExtractor& debug_info_data = get_debug_info_data(); 7502 7503 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 7504 uint32_t block_length = form_value.Unsigned(); 7505 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length); 7506 } 7507 else 7508 { 7509 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data(); 7510 const dw_offset_t debug_loc_offset = form_value.Unsigned(); 7511 7512 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); 7513 if (loc_list_length > 0) 7514 { 7515 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length); 7516 assert (func_low_pc != LLDB_INVALID_ADDRESS); 7517 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress()); 7518 } 7519 } 7520 } 7521 break; 7522 7523 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 7524 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 7525 case DW_AT_declaration: 7526 case DW_AT_description: 7527 case DW_AT_endianity: 7528 case DW_AT_segment: 7529 case DW_AT_start_scope: 7530 case DW_AT_visibility: 7531 default: 7532 case DW_AT_abstract_origin: 7533 case DW_AT_sibling: 7534 case DW_AT_specification: 7535 break; 7536 } 7537 } 7538 } 7539 7540 ValueType scope = eValueTypeInvalid; 7541 7542 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); 7543 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; 7544 SymbolContextScope * symbol_context_scope = NULL; 7545 7546 if (!mangled) 7547 { 7548 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to 7549 // generate fully qualified names of global variables with commands like "frame var j". 7550 // For example, if j were an int variable holding a value 4 and declared in a namespace 7551 // B which in turn is contained in a namespace A, the command "frame var j" returns 7552 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able 7553 // to generate a fully qualified name from the declaration context. 7554 if (die->GetParent()->Tag() == DW_TAG_compile_unit && 7555 LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType())) 7556 { 7557 DWARFDeclContext decl_ctx; 7558 7559 die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx); 7560 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); 7561 } 7562 } 7563 7564 // DWARF doesn't specify if a DW_TAG_variable is a local, global 7565 // or static variable, so we have to do a little digging by 7566 // looking at the location of a variable to see if it contains 7567 // a DW_OP_addr opcode _somewhere_ in the definition. I say 7568 // somewhere because clang likes to combine small global variables 7569 // into the same symbol and have locations like: 7570 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus 7571 // So if we don't have a DW_TAG_formal_parameter, we can look at 7572 // the location to see if it contains a DW_OP_addr opcode, and 7573 // then we can correctly classify our variables. 7574 if (tag == DW_TAG_formal_parameter) 7575 scope = eValueTypeVariableArgument; 7576 else 7577 { 7578 bool op_error = false; 7579 // Check if the location has a DW_OP_addr with any address value... 7580 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS; 7581 if (!location_is_const_value_data) 7582 { 7583 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error); 7584 if (op_error) 7585 { 7586 StreamString strm; 7587 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL); 7588 GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str()); 7589 } 7590 } 7591 7592 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS) 7593 { 7594 if (is_external) 7595 scope = eValueTypeVariableGlobal; 7596 else 7597 scope = eValueTypeVariableStatic; 7598 7599 7600 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile (); 7601 7602 if (debug_map_symfile) 7603 { 7604 // When leaving the DWARF in the .o files on darwin, 7605 // when we have a global variable that wasn't initialized, 7606 // the .o file might not have allocated a virtual 7607 // address for the global variable. In this case it will 7608 // have created a symbol for the global variable 7609 // that is undefined/data and external and the value will 7610 // be the byte size of the variable. When we do the 7611 // address map in SymbolFileDWARFDebugMap we rely on 7612 // having an address, we need to do some magic here 7613 // so we can get the correct address for our global 7614 // variable. The address for all of these entries 7615 // will be zero, and there will be an undefined symbol 7616 // in this object file, and the executable will have 7617 // a matching symbol with a good address. So here we 7618 // dig up the correct address and replace it in the 7619 // location for the variable, and set the variable's 7620 // symbol context scope to be that of the main executable 7621 // so the file address will resolve correctly. 7622 bool linked_oso_file_addr = false; 7623 if (is_external && location_DW_OP_addr == 0) 7624 { 7625 // we have a possible uninitialized extern global 7626 ConstString const_name(mangled ? mangled : name); 7627 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile(); 7628 if (debug_map_objfile) 7629 { 7630 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab(); 7631 if (debug_map_symtab) 7632 { 7633 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name, 7634 eSymbolTypeData, 7635 Symtab::eDebugYes, 7636 Symtab::eVisibilityExtern); 7637 if (exe_symbol) 7638 { 7639 if (exe_symbol->ValueIsAddress()) 7640 { 7641 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress(); 7642 if (exe_file_addr != LLDB_INVALID_ADDRESS) 7643 { 7644 if (location.Update_DW_OP_addr (exe_file_addr)) 7645 { 7646 linked_oso_file_addr = true; 7647 symbol_context_scope = exe_symbol; 7648 } 7649 } 7650 } 7651 } 7652 } 7653 } 7654 } 7655 7656 if (!linked_oso_file_addr) 7657 { 7658 // The DW_OP_addr is not zero, but it contains a .o file address which 7659 // needs to be linked up correctly. 7660 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr); 7661 if (exe_file_addr != LLDB_INVALID_ADDRESS) 7662 { 7663 // Update the file address for this variable 7664 location.Update_DW_OP_addr (exe_file_addr); 7665 } 7666 else 7667 { 7668 // Variable didn't make it into the final executable 7669 return var_sp; 7670 } 7671 } 7672 } 7673 } 7674 else 7675 { 7676 scope = eValueTypeVariableLocal; 7677 } 7678 } 7679 7680 if (symbol_context_scope == NULL) 7681 { 7682 switch (parent_tag) 7683 { 7684 case DW_TAG_subprogram: 7685 case DW_TAG_inlined_subroutine: 7686 case DW_TAG_lexical_block: 7687 if (sc.function) 7688 { 7689 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); 7690 if (symbol_context_scope == NULL) 7691 symbol_context_scope = sc.function; 7692 } 7693 break; 7694 7695 default: 7696 symbol_context_scope = sc.comp_unit; 7697 break; 7698 } 7699 } 7700 7701 if (symbol_context_scope) 7702 { 7703 SymbolFileTypeSP type_sp(new SymbolFileType(*this, type_uid)); 7704 7705 if (const_value.Form() && type_sp && type_sp->GetType()) 7706 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), dwarf_cu->GetAddressByteSize()); 7707 7708 var_sp.reset (new Variable (MakeUserID(die->GetOffset()), 7709 name, 7710 mangled, 7711 type_sp, 7712 scope, 7713 symbol_context_scope, 7714 &decl, 7715 location, 7716 is_external, 7717 is_artificial)); 7718 7719 var_sp->SetLocationIsConstantValueData (location_is_const_value_data); 7720 } 7721 else 7722 { 7723 // Not ready to parse this variable yet. It might be a global 7724 // or static variable that is in a function scope and the function 7725 // in the symbol context wasn't filled in yet 7726 return var_sp; 7727 } 7728 } 7729 // Cache var_sp even if NULL (the variable was just a specification or 7730 // was missing vital information to be able to be displayed in the debugger 7731 // (missing location due to optimization, etc)) so we don't re-parse 7732 // this DIE over and over later... 7733 m_die_to_variable_sp[die] = var_sp; 7734 } 7735 return var_sp; 7736 } 7737 7738 7739 const DWARFDebugInfoEntry * 7740 SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset, 7741 dw_offset_t spec_block_die_offset, 7742 DWARFCompileUnit **result_die_cu_handle) 7743 { 7744 // Give the concrete function die specified by "func_die_offset", find the 7745 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points 7746 // to "spec_block_die_offset" 7747 DWARFDebugInfo* info = DebugInfo(); 7748 7749 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle); 7750 if (die) 7751 { 7752 assert (*result_die_cu_handle); 7753 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle); 7754 } 7755 return NULL; 7756 } 7757 7758 7759 const DWARFDebugInfoEntry * 7760 SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu, 7761 const DWARFDebugInfoEntry *die, 7762 dw_offset_t spec_block_die_offset, 7763 DWARFCompileUnit **result_die_cu_handle) 7764 { 7765 if (die) 7766 { 7767 switch (die->Tag()) 7768 { 7769 case DW_TAG_subprogram: 7770 case DW_TAG_inlined_subroutine: 7771 case DW_TAG_lexical_block: 7772 { 7773 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset) 7774 { 7775 *result_die_cu_handle = dwarf_cu; 7776 return die; 7777 } 7778 7779 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset) 7780 { 7781 *result_die_cu_handle = dwarf_cu; 7782 return die; 7783 } 7784 } 7785 break; 7786 } 7787 7788 // Give the concrete function die specified by "func_die_offset", find the 7789 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points 7790 // to "spec_block_die_offset" 7791 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling()) 7792 { 7793 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu, 7794 child_die, 7795 spec_block_die_offset, 7796 result_die_cu_handle); 7797 if (result_die) 7798 return result_die; 7799 } 7800 } 7801 7802 *result_die_cu_handle = NULL; 7803 return NULL; 7804 } 7805 7806 size_t 7807 SymbolFileDWARF::ParseVariables 7808 ( 7809 const SymbolContext& sc, 7810 DWARFCompileUnit* dwarf_cu, 7811 const lldb::addr_t func_low_pc, 7812 const DWARFDebugInfoEntry *orig_die, 7813 bool parse_siblings, 7814 bool parse_children, 7815 VariableList* cc_variable_list 7816 ) 7817 { 7818 if (orig_die == NULL) 7819 return 0; 7820 7821 VariableListSP variable_list_sp; 7822 7823 size_t vars_added = 0; 7824 const DWARFDebugInfoEntry *die = orig_die; 7825 while (die != NULL) 7826 { 7827 dw_tag_t tag = die->Tag(); 7828 7829 // Check to see if we have already parsed this variable or constant? 7830 if (m_die_to_variable_sp[die]) 7831 { 7832 if (cc_variable_list) 7833 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]); 7834 } 7835 else 7836 { 7837 // We haven't already parsed it, lets do that now. 7838 if ((tag == DW_TAG_variable) || 7839 (tag == DW_TAG_constant) || 7840 (tag == DW_TAG_formal_parameter && sc.function)) 7841 { 7842 if (variable_list_sp.get() == NULL) 7843 { 7844 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); 7845 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; 7846 switch (parent_tag) 7847 { 7848 case DW_TAG_compile_unit: 7849 if (sc.comp_unit != NULL) 7850 { 7851 variable_list_sp = sc.comp_unit->GetVariableList(false); 7852 if (variable_list_sp.get() == NULL) 7853 { 7854 variable_list_sp.reset(new VariableList()); 7855 sc.comp_unit->SetVariableList(variable_list_sp); 7856 } 7857 } 7858 else 7859 { 7860 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n", 7861 MakeUserID(sc_parent_die->GetOffset()), 7862 DW_TAG_value_to_name (parent_tag), 7863 MakeUserID(orig_die->GetOffset()), 7864 DW_TAG_value_to_name (orig_die->Tag())); 7865 } 7866 break; 7867 7868 case DW_TAG_subprogram: 7869 case DW_TAG_inlined_subroutine: 7870 case DW_TAG_lexical_block: 7871 if (sc.function != NULL) 7872 { 7873 // Check to see if we already have parsed the variables for the given scope 7874 7875 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset())); 7876 if (block == NULL) 7877 { 7878 // This must be a specification or abstract origin with 7879 // a concrete block counterpart in the current function. We need 7880 // to find the concrete block so we can correctly add the 7881 // variable to it 7882 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu; 7883 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(), 7884 sc_parent_die->GetOffset(), 7885 &concrete_block_die_cu); 7886 if (concrete_block_die) 7887 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset())); 7888 } 7889 7890 if (block != NULL) 7891 { 7892 const bool can_create = false; 7893 variable_list_sp = block->GetBlockVariableList (can_create); 7894 if (variable_list_sp.get() == NULL) 7895 { 7896 variable_list_sp.reset(new VariableList()); 7897 block->SetVariableList(variable_list_sp); 7898 } 7899 } 7900 } 7901 break; 7902 7903 default: 7904 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n", 7905 MakeUserID(orig_die->GetOffset()), 7906 DW_TAG_value_to_name (orig_die->Tag())); 7907 break; 7908 } 7909 } 7910 7911 if (variable_list_sp) 7912 { 7913 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); 7914 if (var_sp) 7915 { 7916 variable_list_sp->AddVariableIfUnique (var_sp); 7917 if (cc_variable_list) 7918 cc_variable_list->AddVariableIfUnique (var_sp); 7919 ++vars_added; 7920 } 7921 } 7922 } 7923 } 7924 7925 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); 7926 7927 if (!skip_children && parse_children && die->HasChildren()) 7928 { 7929 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); 7930 } 7931 7932 if (parse_siblings) 7933 die = die->GetSibling(); 7934 else 7935 die = NULL; 7936 } 7937 return vars_added; 7938 } 7939 7940 //------------------------------------------------------------------ 7941 // PluginInterface protocol 7942 //------------------------------------------------------------------ 7943 ConstString 7944 SymbolFileDWARF::GetPluginName() 7945 { 7946 return GetPluginNameStatic(); 7947 } 7948 7949 uint32_t 7950 SymbolFileDWARF::GetPluginVersion() 7951 { 7952 return 1; 7953 } 7954 7955 void 7956 SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl) 7957 { 7958 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; 7959 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); 7960 if (clang_type) 7961 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); 7962 } 7963 7964 void 7965 SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl) 7966 { 7967 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; 7968 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl); 7969 if (clang_type) 7970 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type); 7971 } 7972 7973 void 7974 SymbolFileDWARF::DumpIndexes () 7975 { 7976 StreamFile s(stdout, false); 7977 7978 s.Printf ("DWARF index for (%s) '%s':", 7979 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(), 7980 GetObjectFile()->GetFileSpec().GetPath().c_str()); 7981 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); 7982 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); 7983 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); 7984 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); 7985 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); 7986 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); 7987 s.Printf("\nTypes:\n"); m_type_index.Dump (&s); 7988 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); 7989 } 7990 7991 void 7992 SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context, 7993 const char *name, 7994 llvm::SmallVectorImpl <clang::NamedDecl *> *results) 7995 { 7996 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context); 7997 7998 if (iter == m_decl_ctx_to_die.end()) 7999 return; 8000 8001 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos) 8002 { 8003 const DWARFDebugInfoEntry *context_die = *pos; 8004 8005 if (!results) 8006 return; 8007 8008 DWARFDebugInfo* info = DebugInfo(); 8009 8010 DIEArray die_offsets; 8011 8012 DWARFCompileUnit* dwarf_cu = NULL; 8013 const DWARFDebugInfoEntry* die = NULL; 8014 8015 if (m_using_apple_tables) 8016 { 8017 if (m_apple_types_ap.get()) 8018 m_apple_types_ap->FindByName (name, die_offsets); 8019 } 8020 else 8021 { 8022 if (!m_indexed) 8023 Index (); 8024 8025 m_type_index.Find (ConstString(name), die_offsets); 8026 } 8027 8028 const size_t num_matches = die_offsets.size(); 8029 8030 if (num_matches) 8031 { 8032 for (size_t i = 0; i < num_matches; ++i) 8033 { 8034 const dw_offset_t die_offset = die_offsets[i]; 8035 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); 8036 8037 if (die->GetParent() != context_die) 8038 continue; 8039 8040 Type *matching_type = ResolveType (dwarf_cu, die); 8041 8042 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType(); 8043 8044 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr())) 8045 { 8046 clang::TagDecl *tag_decl = tag_type->getDecl(); 8047 results->push_back(tag_decl); 8048 } 8049 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr())) 8050 { 8051 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl(); 8052 results->push_back(typedef_decl); 8053 } 8054 } 8055 } 8056 } 8057 } 8058 8059 void 8060 SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, 8061 const clang::DeclContext *decl_context, 8062 clang::DeclarationName decl_name, 8063 llvm::SmallVectorImpl <clang::NamedDecl *> *results) 8064 { 8065 8066 switch (decl_context->getDeclKind()) 8067 { 8068 case clang::Decl::Namespace: 8069 case clang::Decl::TranslationUnit: 8070 { 8071 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; 8072 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results); 8073 } 8074 break; 8075 default: 8076 break; 8077 } 8078 } 8079 8080 bool 8081 SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, 8082 uint64_t &alignment, 8083 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, 8084 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, 8085 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) 8086 { 8087 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; 8088 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); 8089 } 8090 8091 bool 8092 SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, 8093 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, 8094 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, 8095 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) 8096 { 8097 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 8098 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); 8099 bool success = false; 8100 base_offsets.clear(); 8101 vbase_offsets.clear(); 8102 if (pos != m_record_decl_to_layout_map.end()) 8103 { 8104 bit_size = pos->second.bit_size; 8105 alignment = pos->second.alignment; 8106 field_offsets.swap(pos->second.field_offsets); 8107 base_offsets.swap (pos->second.base_offsets); 8108 vbase_offsets.swap (pos->second.vbase_offsets); 8109 m_record_decl_to_layout_map.erase(pos); 8110 success = true; 8111 } 8112 else 8113 { 8114 bit_size = 0; 8115 alignment = 0; 8116 field_offsets.clear(); 8117 } 8118 8119 if (log) 8120 GetObjectFile()->GetModule()->LogMessage (log, 8121 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i", 8122 static_cast<const void*>(record_decl), 8123 bit_size, alignment, 8124 static_cast<uint32_t>(field_offsets.size()), 8125 static_cast<uint32_t>(base_offsets.size()), 8126 static_cast<uint32_t>(vbase_offsets.size()), 8127 success); 8128 return success; 8129 } 8130 8131 8132 SymbolFileDWARFDebugMap * 8133 SymbolFileDWARF::GetDebugMapSymfile () 8134 { 8135 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) 8136 { 8137 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock()); 8138 if (module_sp) 8139 { 8140 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor(); 8141 if (sym_vendor) 8142 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile(); 8143 } 8144 } 8145 return m_debug_map_symfile; 8146 } 8147 8148 8149