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