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