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