SymbolFileDWARF.cpp revision 9bcf31e9821fd303c793525e977b14025bbe3f50
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 24#include "lldb/Core/Module.h" 25#include "lldb/Core/PluginManager.h" 26#include "lldb/Core/RegularExpression.h" 27#include "lldb/Core/Scalar.h" 28#include "lldb/Core/Section.h" 29#include "lldb/Core/StreamFile.h" 30#include "lldb/Core/Timer.h" 31#include "lldb/Core/Value.h" 32 33#include "lldb/Symbol/Block.h" 34#include "lldb/Symbol/CompileUnit.h" 35#include "lldb/Symbol/LineTable.h" 36#include "lldb/Symbol/ObjectFile.h" 37#include "lldb/Symbol/SymbolVendor.h" 38#include "lldb/Symbol/VariableList.h" 39 40#include "DWARFCompileUnit.h" 41#include "DWARFDebugAbbrev.h" 42#include "DWARFDebugAranges.h" 43#include "DWARFDebugInfo.h" 44#include "DWARFDebugInfoEntry.h" 45#include "DWARFDebugLine.h" 46#include "DWARFDebugPubnames.h" 47#include "DWARFDebugRanges.h" 48#include "DWARFDIECollection.h" 49#include "DWARFFormValue.h" 50#include "DWARFLocationList.h" 51#include "LogChannelDWARF.h" 52#include "SymbolFileDWARFDebugMap.h" 53 54#include <map> 55 56//#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN 57 58#ifdef ENABLE_DEBUG_PRINTF 59#include <stdio.h> 60#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) 61#else 62#define DEBUG_PRINTF(fmt, ...) 63#endif 64 65#define DIE_IS_BEING_PARSED ((lldb_private::Type*)1) 66 67using namespace lldb; 68using namespace lldb_private; 69 70 71static AccessType 72DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) 73{ 74 switch (dwarf_accessibility) 75 { 76 case DW_ACCESS_public: return eAccessPublic; 77 case DW_ACCESS_private: return eAccessPrivate; 78 case DW_ACCESS_protected: return eAccessProtected; 79 default: break; 80 } 81 return eAccessNone; 82} 83 84void 85SymbolFileDWARF::Initialize() 86{ 87 LogChannelDWARF::Initialize(); 88 PluginManager::RegisterPlugin (GetPluginNameStatic(), 89 GetPluginDescriptionStatic(), 90 CreateInstance); 91} 92 93void 94SymbolFileDWARF::Terminate() 95{ 96 PluginManager::UnregisterPlugin (CreateInstance); 97 LogChannelDWARF::Initialize(); 98} 99 100 101const char * 102SymbolFileDWARF::GetPluginNameStatic() 103{ 104 return "symbol-file.dwarf2"; 105} 106 107const char * 108SymbolFileDWARF::GetPluginDescriptionStatic() 109{ 110 return "DWARF and DWARF3 debug symbol file reader."; 111} 112 113 114SymbolFile* 115SymbolFileDWARF::CreateInstance (ObjectFile* obj_file) 116{ 117 return new SymbolFileDWARF(obj_file); 118} 119 120//---------------------------------------------------------------------- 121// Gets the first parent that is a lexical block, function or inlined 122// subroutine, or compile unit. 123//---------------------------------------------------------------------- 124static const DWARFDebugInfoEntry * 125GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die) 126{ 127 const DWARFDebugInfoEntry *die; 128 for (die = child_die->GetParent(); die != NULL; die = die->GetParent()) 129 { 130 dw_tag_t tag = die->Tag(); 131 132 switch (tag) 133 { 134 case DW_TAG_compile_unit: 135 case DW_TAG_subprogram: 136 case DW_TAG_inlined_subroutine: 137 case DW_TAG_lexical_block: 138 return die; 139 } 140 } 141 return NULL; 142} 143 144 145SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) : 146 SymbolFile (objfile), 147 m_debug_map_symfile (NULL), 148 m_flags(), 149 m_data_debug_abbrev(), 150 m_data_debug_frame(), 151 m_data_debug_info(), 152 m_data_debug_line(), 153 m_data_debug_loc(), 154 m_data_debug_ranges(), 155 m_data_debug_str(), 156 m_abbr(), 157 m_aranges(), 158 m_info(), 159 m_line(), 160 m_function_basename_index(), 161 m_function_fullname_index(), 162 m_function_method_index(), 163 m_function_selector_index(), 164 m_objc_class_selectors_index(), 165 m_global_index(), 166 m_type_index(), 167 m_namespace_index(), 168 m_indexed(false), 169 m_ranges() 170{ 171} 172 173SymbolFileDWARF::~SymbolFileDWARF() 174{ 175} 176 177bool 178SymbolFileDWARF::SupportedVersion(uint16_t version) 179{ 180 return version == 2 || version == 3; 181} 182 183uint32_t 184SymbolFileDWARF::GetAbilities () 185{ 186 uint32_t abilities = 0; 187 if (m_obj_file != NULL) 188 { 189 const Section* section = NULL; 190 const SectionList *section_list = m_obj_file->GetSectionList(); 191 if (section_list == NULL) 192 return 0; 193 194 uint64_t debug_abbrev_file_size = 0; 195 uint64_t debug_aranges_file_size = 0; 196 uint64_t debug_frame_file_size = 0; 197 uint64_t debug_info_file_size = 0; 198 uint64_t debug_line_file_size = 0; 199 uint64_t debug_loc_file_size = 0; 200 uint64_t debug_macinfo_file_size = 0; 201 uint64_t debug_pubnames_file_size = 0; 202 uint64_t debug_pubtypes_file_size = 0; 203 uint64_t debug_ranges_file_size = 0; 204 uint64_t debug_str_file_size = 0; 205 206 static ConstString g_dwarf_section_name ("__DWARF"); 207 208 section = section_list->FindSectionByName(g_dwarf_section_name).get(); 209 210 if (section) 211 { 212 section->MemoryMapSectionDataFromObjectFile(m_obj_file, m_dwarf_data); 213 section_list = §ion->GetChildren (); 214 } 215 216 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get(); 217 if (section != NULL) 218 { 219 debug_info_file_size = section->GetByteSize(); 220 221 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get(); 222 if (section) 223 debug_abbrev_file_size = section->GetByteSize(); 224 else 225 m_flags.Set (flagsGotDebugAbbrevData); 226 227 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get(); 228 if (section) 229 debug_aranges_file_size = section->GetByteSize(); 230 else 231 m_flags.Set (flagsGotDebugArangesData); 232 233 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get(); 234 if (section) 235 debug_frame_file_size = section->GetByteSize(); 236 else 237 m_flags.Set (flagsGotDebugFrameData); 238 239 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get(); 240 if (section) 241 debug_line_file_size = section->GetByteSize(); 242 else 243 m_flags.Set (flagsGotDebugLineData); 244 245 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get(); 246 if (section) 247 debug_loc_file_size = section->GetByteSize(); 248 else 249 m_flags.Set (flagsGotDebugLocData); 250 251 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get(); 252 if (section) 253 debug_macinfo_file_size = section->GetByteSize(); 254 else 255 m_flags.Set (flagsGotDebugMacInfoData); 256 257 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get(); 258 if (section) 259 debug_pubnames_file_size = section->GetByteSize(); 260 else 261 m_flags.Set (flagsGotDebugPubNamesData); 262 263 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get(); 264 if (section) 265 debug_pubtypes_file_size = section->GetByteSize(); 266 else 267 m_flags.Set (flagsGotDebugPubTypesData); 268 269 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get(); 270 if (section) 271 debug_ranges_file_size = section->GetByteSize(); 272 else 273 m_flags.Set (flagsGotDebugRangesData); 274 275 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get(); 276 if (section) 277 debug_str_file_size = section->GetByteSize(); 278 else 279 m_flags.Set (flagsGotDebugStrData); 280 } 281 282 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0) 283 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes; 284 285 if (debug_line_file_size > 0) 286 abilities |= LineTables; 287 288 if (debug_aranges_file_size > 0) 289 abilities |= AddressAcceleratorTable; 290 291 if (debug_pubnames_file_size > 0) 292 abilities |= FunctionAcceleratorTable; 293 294 if (debug_pubtypes_file_size > 0) 295 abilities |= TypeAcceleratorTable; 296 297 if (debug_macinfo_file_size > 0) 298 abilities |= MacroInformation; 299 300 if (debug_frame_file_size > 0) 301 abilities |= CallFrameInformation; 302 } 303 return abilities; 304} 305 306const DataExtractor& 307SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data) 308{ 309 if (m_flags.IsClear (got_flag)) 310 { 311 m_flags.Set (got_flag); 312 const SectionList *section_list = m_obj_file->GetSectionList(); 313 if (section_list) 314 { 315 Section *section = section_list->FindSectionByType(sect_type, true).get(); 316 if (section) 317 { 318 // See if we memory mapped the DWARF segment? 319 if (m_dwarf_data.GetByteSize()) 320 { 321 data.SetData(m_dwarf_data, section->GetOffset (), section->GetByteSize()); 322 } 323 else 324 { 325 if (section->ReadSectionDataFromObjectFile(m_obj_file, data) == 0) 326 data.Clear(); 327 } 328 } 329 } 330 } 331 return data; 332} 333 334const DataExtractor& 335SymbolFileDWARF::get_debug_abbrev_data() 336{ 337 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev); 338} 339 340const DataExtractor& 341SymbolFileDWARF::get_debug_frame_data() 342{ 343 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame); 344} 345 346const DataExtractor& 347SymbolFileDWARF::get_debug_info_data() 348{ 349 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info); 350} 351 352const DataExtractor& 353SymbolFileDWARF::get_debug_line_data() 354{ 355 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line); 356} 357 358const DataExtractor& 359SymbolFileDWARF::get_debug_loc_data() 360{ 361 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc); 362} 363 364const DataExtractor& 365SymbolFileDWARF::get_debug_ranges_data() 366{ 367 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges); 368} 369 370const DataExtractor& 371SymbolFileDWARF::get_debug_str_data() 372{ 373 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); 374} 375 376 377DWARFDebugAbbrev* 378SymbolFileDWARF::DebugAbbrev() 379{ 380 if (m_abbr.get() == NULL) 381 { 382 const DataExtractor &debug_abbrev_data = get_debug_abbrev_data(); 383 if (debug_abbrev_data.GetByteSize() > 0) 384 { 385 m_abbr.reset(new DWARFDebugAbbrev()); 386 if (m_abbr.get()) 387 m_abbr->Parse(debug_abbrev_data); 388 } 389 } 390 return m_abbr.get(); 391} 392 393const DWARFDebugAbbrev* 394SymbolFileDWARF::DebugAbbrev() const 395{ 396 return m_abbr.get(); 397} 398 399DWARFDebugAranges* 400SymbolFileDWARF::DebugAranges() 401{ 402 // It turns out that llvm-gcc doesn't generate .debug_aranges in .o files 403 // and we are already parsing all of the DWARF because the .debug_pubnames 404 // is useless (it only mentions symbols that are externally visible), so 405 // don't use the .debug_aranges section, we should be using a debug aranges 406 // we got from SymbolFileDWARF::Index(). 407 408 if (!m_indexed) 409 Index(); 410 411 412// if (m_aranges.get() == NULL) 413// { 414// Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); 415// m_aranges.reset(new DWARFDebugAranges()); 416// if (m_aranges.get()) 417// { 418// const DataExtractor &debug_aranges_data = get_debug_aranges_data(); 419// if (debug_aranges_data.GetByteSize() > 0) 420// m_aranges->Extract(debug_aranges_data); 421// else 422// m_aranges->Generate(this); 423// } 424// } 425 return m_aranges.get(); 426} 427 428const DWARFDebugAranges* 429SymbolFileDWARF::DebugAranges() const 430{ 431 return m_aranges.get(); 432} 433 434 435DWARFDebugInfo* 436SymbolFileDWARF::DebugInfo() 437{ 438 if (m_info.get() == NULL) 439 { 440 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); 441 if (get_debug_info_data().GetByteSize() > 0) 442 { 443 m_info.reset(new DWARFDebugInfo()); 444 if (m_info.get()) 445 { 446 m_info->SetDwarfData(this); 447 } 448 } 449 } 450 return m_info.get(); 451} 452 453const DWARFDebugInfo* 454SymbolFileDWARF::DebugInfo() const 455{ 456 return m_info.get(); 457} 458 459DWARFCompileUnit* 460SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid) 461{ 462 DWARFDebugInfo* info = DebugInfo(); 463 if (info) 464 return info->GetCompileUnit(cu_uid).get(); 465 return NULL; 466} 467 468 469DWARFDebugRanges* 470SymbolFileDWARF::DebugRanges() 471{ 472 if (m_ranges.get() == NULL) 473 { 474 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this); 475 if (get_debug_ranges_data().GetByteSize() > 0) 476 { 477 m_ranges.reset(new DWARFDebugRanges()); 478 if (m_ranges.get()) 479 m_ranges->Extract(this); 480 } 481 } 482 return m_ranges.get(); 483} 484 485const DWARFDebugRanges* 486SymbolFileDWARF::DebugRanges() const 487{ 488 return m_ranges.get(); 489} 490 491bool 492SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* cu, CompUnitSP& compile_unit_sp) 493{ 494 if (cu != NULL) 495 { 496 const DWARFDebugInfoEntry * cu_die = cu->GetCompileUnitDIEOnly (); 497 if (cu_die) 498 { 499 const char * cu_die_name = cu_die->GetName(this, cu); 500 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, cu, DW_AT_comp_dir, NULL); 501 LanguageType class_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, cu, DW_AT_language, 0); 502 if (cu_die_name) 503 { 504 FileSpec cu_file_spec; 505 506 if (cu_die_name[0] == '/' || cu_comp_dir == NULL && cu_comp_dir[0]) 507 { 508 // If we have a full path to the compile unit, we don't need to resolve 509 // the file. This can be expensive e.g. when the source files are NFS mounted. 510 cu_file_spec.SetFile (cu_die_name, false); 511 } 512 else 513 { 514 std::string fullpath(cu_comp_dir); 515 if (*fullpath.rbegin() != '/') 516 fullpath += '/'; 517 fullpath += cu_die_name; 518 cu_file_spec.SetFile (fullpath.c_str(), false); 519 } 520 521 compile_unit_sp.reset(new CompileUnit(m_obj_file->GetModule(), cu, cu_file_spec, cu->GetOffset(), class_language)); 522 if (compile_unit_sp.get()) 523 { 524 cu->SetUserData(compile_unit_sp.get()); 525 return true; 526 } 527 } 528 } 529 } 530 return false; 531} 532 533uint32_t 534SymbolFileDWARF::GetNumCompileUnits() 535{ 536 DWARFDebugInfo* info = DebugInfo(); 537 if (info) 538 return info->GetNumCompileUnits(); 539 return 0; 540} 541 542CompUnitSP 543SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) 544{ 545 CompUnitSP comp_unit; 546 DWARFDebugInfo* info = DebugInfo(); 547 if (info) 548 { 549 DWARFCompileUnit* cu = info->GetCompileUnitAtIndex(cu_idx); 550 if (cu != NULL) 551 { 552 // Our symbol vendor shouldn't be asking us to add a compile unit that 553 // has already been added to it, which this DWARF plug-in knows as it 554 // stores the lldb compile unit (CompileUnit) pointer in each 555 // DWARFCompileUnit object when it gets added. 556 assert(cu->GetUserData() == NULL); 557 ParseCompileUnit(cu, comp_unit); 558 } 559 } 560 return comp_unit; 561} 562 563static void 564AddRangesToBlock 565( 566 Block& block, 567 DWARFDebugRanges::RangeList& ranges, 568 addr_t block_base_addr 569) 570{ 571 ranges.SubtractOffset (block_base_addr); 572 size_t range_idx = 0; 573 const DWARFDebugRanges::Range *debug_range; 574 for (range_idx = 0; (debug_range = ranges.RangeAtIndex(range_idx)) != NULL; range_idx++) 575 { 576 block.AddRange(debug_range->begin_offset, debug_range->end_offset); 577 } 578} 579 580 581Function * 582SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die) 583{ 584 DWARFDebugRanges::RangeList func_ranges; 585 const char *name = NULL; 586 const char *mangled = NULL; 587 int decl_file = 0; 588 int decl_line = 0; 589 int decl_column = 0; 590 int call_file = 0; 591 int call_line = 0; 592 int call_column = 0; 593 DWARFExpression frame_base; 594 595 assert (die->Tag() == DW_TAG_subprogram); 596 597 if (die->Tag() != DW_TAG_subprogram) 598 return NULL; 599 600 const DWARFDebugInfoEntry *parent_die = die->GetParent(); 601 switch (parent_die->Tag()) 602 { 603 case DW_TAG_structure_type: 604 case DW_TAG_class_type: 605 // We have methods of a class or struct 606 { 607 Type *class_type = ResolveType (dwarf_cu, parent_die); 608 if (class_type) 609 class_type->GetClangType(); 610 } 611 break; 612 613 default: 614 // Parse the function prototype as a type that can then be added to concrete function instance 615 ParseTypes (sc, dwarf_cu, die, false, false); 616 break; 617 } 618 619 //FixupTypes(); 620 621 if (die->GetDIENamesAndRanges(this, dwarf_cu, name, mangled, func_ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column, &frame_base)) 622 { 623 // Union of all ranges in the function DIE (if the function is discontiguous) 624 AddressRange func_range; 625 lldb::addr_t lowest_func_addr = func_ranges.LowestAddress(0); 626 lldb::addr_t highest_func_addr = func_ranges.HighestAddress(0); 627 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) 628 { 629 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList()); 630 if (func_range.GetBaseAddress().IsValid()) 631 func_range.SetByteSize(highest_func_addr - lowest_func_addr); 632 } 633 634 if (func_range.GetBaseAddress().IsValid()) 635 { 636 Mangled func_name; 637 if (mangled) 638 func_name.SetValue(mangled, true); 639 else if (name) 640 func_name.SetValue(name, false); 641 642 FunctionSP func_sp; 643 std::auto_ptr<Declaration> decl_ap; 644 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 645 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), decl_line, decl_column)); 646 647 Type *func_type = m_die_to_type.lookup (die); 648 649 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); 650 651 func_range.GetBaseAddress().ResolveLinkedAddress(); 652 653 func_sp.reset(new Function (sc.comp_unit, 654 die->GetOffset(), // UserID is the DIE offset 655 die->GetOffset(), 656 func_name, 657 func_type, 658 func_range)); // first address range 659 660 if (func_sp.get() != NULL) 661 { 662 func_sp->GetFrameBaseExpression() = frame_base; 663 sc.comp_unit->AddFunction(func_sp); 664 return func_sp.get(); 665 } 666 } 667 } 668 return NULL; 669} 670 671size_t 672SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) 673{ 674 assert (sc.comp_unit); 675 size_t functions_added = 0; 676 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); 677 if (dwarf_cu) 678 { 679 DWARFDIECollection function_dies; 680 const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies); 681 size_t func_idx; 682 for (func_idx = 0; func_idx < num_funtions; ++func_idx) 683 { 684 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx); 685 if (sc.comp_unit->FindFunctionByUID (die->GetOffset()).get() == NULL) 686 { 687 if (ParseCompileUnitFunction(sc, dwarf_cu, die)) 688 ++functions_added; 689 } 690 } 691 //FixupTypes(); 692 } 693 return functions_added; 694} 695 696bool 697SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) 698{ 699 assert (sc.comp_unit); 700 DWARFCompileUnit* cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); 701 assert (cu); 702 const DWARFDebugInfoEntry * cu_die = cu->GetCompileUnitDIEOnly(); 703 704 if (cu_die) 705 { 706 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, cu, DW_AT_comp_dir, NULL); 707 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, cu, DW_AT_stmt_list, DW_INVALID_OFFSET); 708 709 // All file indexes in DWARF are one based and a file of index zero is 710 // supposed to be the compile unit itself. 711 support_files.Append (*sc.comp_unit); 712 713 return DWARFDebugLine::ParseSupportFiles(get_debug_line_data(), cu_comp_dir, stmt_list, support_files); 714 } 715 return false; 716} 717 718struct ParseDWARFLineTableCallbackInfo 719{ 720 LineTable* line_table; 721 const SectionList *section_list; 722 lldb::addr_t prev_sect_file_base_addr; 723 lldb::addr_t curr_sect_file_base_addr; 724 bool is_oso_for_debug_map; 725 bool prev_in_final_executable; 726 DWARFDebugLine::Row prev_row; 727 SectionSP prev_section_sp; 728 SectionSP curr_section_sp; 729}; 730 731//---------------------------------------------------------------------- 732// ParseStatementTableCallback 733//---------------------------------------------------------------------- 734static void 735ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData) 736{ 737 LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table; 738 if (state.row == DWARFDebugLine::State::StartParsingLineTable) 739 { 740 // Just started parsing the line table 741 } 742 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) 743 { 744 // Done parsing line table, nothing to do for the cleanup 745 } 746 else 747 { 748 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData; 749 // We have a new row, lets append it 750 751 if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false) 752 { 753 info->prev_section_sp = info->curr_section_sp; 754 info->prev_sect_file_base_addr = info->curr_sect_file_base_addr; 755 // If this is an end sequence entry, then we subtract one from the 756 // address to make sure we get an address that is not the end of 757 // a section. 758 if (state.end_sequence && state.address != 0) 759 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1); 760 else 761 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address); 762 763 if (info->curr_section_sp.get()) 764 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress (); 765 else 766 info->curr_sect_file_base_addr = 0; 767 } 768 if (info->curr_section_sp.get()) 769 { 770 lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr; 771 // Check for the fancy section magic to determine if we 772 773 if (info->is_oso_for_debug_map) 774 { 775 // When this is a debug map object file that contains DWARF 776 // (referenced from an N_OSO debug map nlist entry) we will have 777 // a file address in the file range for our section from the 778 // original .o file, and a load address in the executable that 779 // contains the debug map. 780 // 781 // If the sections for the file range and load range are 782 // different, we have a remapped section for the function and 783 // this address is resolved. If they are the same, then the 784 // function for this address didn't make it into the final 785 // executable. 786 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL; 787 788 // If we are doing DWARF with debug map, then we need to carefully 789 // add each line table entry as there may be gaps as functions 790 // get moved around or removed. 791 if (!info->prev_row.end_sequence && info->prev_section_sp.get()) 792 { 793 if (info->prev_in_final_executable) 794 { 795 bool terminate_previous_entry = false; 796 if (!curr_in_final_executable) 797 { 798 // Check for the case where the previous line entry 799 // in a function made it into the final executable, 800 // yet the current line entry falls in a function 801 // that didn't. The line table used to be contiguous 802 // through this address range but now it isn't. We 803 // need to terminate the previous line entry so 804 // that we can reconstruct the line range correctly 805 // for it and to keep the line table correct. 806 terminate_previous_entry = true; 807 } 808 else if (info->curr_section_sp.get() != info->prev_section_sp.get()) 809 { 810 // Check for cases where the line entries used to be 811 // contiguous address ranges, but now they aren't. 812 // This can happen when order files specify the 813 // ordering of the functions. 814 lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr; 815 Section *curr_sect = info->curr_section_sp.get(); 816 Section *prev_sect = info->prev_section_sp.get(); 817 assert (curr_sect->GetLinkedSection()); 818 assert (prev_sect->GetLinkedSection()); 819 lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address; 820 lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset; 821 lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset; 822 lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr; 823 if (object_file_addr_delta != linked_file_addr_delta) 824 terminate_previous_entry = true; 825 } 826 827 if (terminate_previous_entry) 828 { 829 line_table->InsertLineEntry (info->prev_section_sp, 830 state.address - info->prev_sect_file_base_addr, 831 info->prev_row.line, 832 info->prev_row.column, 833 info->prev_row.file, 834 false, // is_stmt 835 false, // basic_block 836 false, // state.prologue_end 837 false, // state.epilogue_begin 838 true); // end_sequence); 839 } 840 } 841 } 842 843 if (curr_in_final_executable) 844 { 845 line_table->InsertLineEntry (info->curr_section_sp, 846 curr_line_section_offset, 847 state.line, 848 state.column, 849 state.file, 850 state.is_stmt, 851 state.basic_block, 852 state.prologue_end, 853 state.epilogue_begin, 854 state.end_sequence); 855 info->prev_section_sp = info->curr_section_sp; 856 } 857 else 858 { 859 // If the current address didn't make it into the final 860 // executable, the current section will be the __text 861 // segment in the .o file, so we need to clear this so 862 // we can catch the next function that did make it into 863 // the final executable. 864 info->prev_section_sp.reset(); 865 info->curr_section_sp.reset(); 866 } 867 868 info->prev_in_final_executable = curr_in_final_executable; 869 } 870 else 871 { 872 // We are not in an object file that contains DWARF for an 873 // N_OSO, this is just a normal DWARF file. The DWARF spec 874 // guarantees that the addresses will be in increasing order 875 // so, since we store line tables in file address order, we 876 // can always just append the line entry without needing to 877 // search for the correct insertion point (we don't need to 878 // use LineEntry::InsertLineEntry()). 879 line_table->AppendLineEntry (info->curr_section_sp, 880 curr_line_section_offset, 881 state.line, 882 state.column, 883 state.file, 884 state.is_stmt, 885 state.basic_block, 886 state.prologue_end, 887 state.epilogue_begin, 888 state.end_sequence); 889 } 890 } 891 892 info->prev_row = state; 893 } 894} 895 896bool 897SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc) 898{ 899 assert (sc.comp_unit); 900 if (sc.comp_unit->GetLineTable() != NULL) 901 return true; 902 903 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); 904 if (dwarf_cu) 905 { 906 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly(); 907 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET); 908 if (cu_line_offset != DW_INVALID_OFFSET) 909 { 910 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit)); 911 if (line_table_ap.get()) 912 { 913 ParseDWARFLineTableCallbackInfo info = { line_table_ap.get(), m_obj_file->GetSectionList(), 0, 0, m_debug_map_symfile != NULL, false}; 914 uint32_t offset = cu_line_offset; 915 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info); 916 sc.comp_unit->SetLineTable(line_table_ap.release()); 917 return true; 918 } 919 } 920 } 921 return false; 922} 923 924size_t 925SymbolFileDWARF::ParseFunctionBlocks 926( 927 const SymbolContext& sc, 928 Block *parent_block, 929 DWARFCompileUnit* dwarf_cu, 930 const DWARFDebugInfoEntry *die, 931 addr_t subprogram_low_pc, 932 bool parse_siblings, 933 bool parse_children 934) 935{ 936 size_t blocks_added = 0; 937 while (die != NULL) 938 { 939 dw_tag_t tag = die->Tag(); 940 941 switch (tag) 942 { 943 case DW_TAG_inlined_subroutine: 944 case DW_TAG_subprogram: 945 case DW_TAG_lexical_block: 946 { 947 DWARFDebugRanges::RangeList ranges; 948 const char *name = NULL; 949 const char *mangled_name = NULL; 950 Block *block = NULL; 951 if (tag != DW_TAG_subprogram) 952 { 953 BlockSP block_sp(new Block (die->GetOffset())); 954 parent_block->AddChild(block_sp); 955 block = block_sp.get(); 956 } 957 else 958 { 959 block = parent_block; 960 } 961 962 int decl_file = 0; 963 int decl_line = 0; 964 int decl_column = 0; 965 int call_file = 0; 966 int call_line = 0; 967 int call_column = 0; 968 if (die->GetDIENamesAndRanges (this, 969 dwarf_cu, 970 name, 971 mangled_name, 972 ranges, 973 decl_file, decl_line, decl_column, 974 call_file, call_line, call_column)) 975 { 976 if (tag == DW_TAG_subprogram) 977 { 978 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS); 979 subprogram_low_pc = ranges.LowestAddress(0); 980 } 981 else if (tag == DW_TAG_inlined_subroutine) 982 { 983 // We get called here for inlined subroutines in two ways. 984 // The first time is when we are making the Function object 985 // for this inlined concrete instance. Since we're creating a top level block at 986 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to 987 // adjust the containing address. 988 // The second time is when we are parsing the blocks inside the function that contains 989 // the inlined concrete instance. Since these will be blocks inside the containing "real" 990 // function the offset will be for that function. 991 if (subprogram_low_pc == LLDB_INVALID_ADDRESS) 992 { 993 subprogram_low_pc = ranges.LowestAddress(0); 994 } 995 } 996 997 AddRangesToBlock (*block, ranges, subprogram_low_pc); 998 999 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL)) 1000 { 1001 std::auto_ptr<Declaration> decl_ap; 1002 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 1003 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), 1004 decl_line, decl_column)); 1005 1006 std::auto_ptr<Declaration> call_ap; 1007 if (call_file != 0 || call_line != 0 || call_column != 0) 1008 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file), 1009 call_line, call_column)); 1010 1011 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get()); 1012 } 1013 1014 ++blocks_added; 1015 1016 if (parse_children && die->HasChildren()) 1017 { 1018 blocks_added += ParseFunctionBlocks (sc, 1019 block, 1020 dwarf_cu, 1021 die->GetFirstChild(), 1022 subprogram_low_pc, 1023 true, 1024 true); 1025 } 1026 } 1027 } 1028 break; 1029 default: 1030 break; 1031 } 1032 1033 if (parse_siblings) 1034 die = die->GetSibling(); 1035 else 1036 die = NULL; 1037 } 1038 return blocks_added; 1039} 1040 1041size_t 1042SymbolFileDWARF::ParseChildMembers 1043( 1044 const SymbolContext& sc, 1045 DWARFCompileUnit* dwarf_cu, 1046 const DWARFDebugInfoEntry *parent_die, 1047 clang_type_t class_clang_type, 1048 const LanguageType class_language, 1049 std::vector<clang::CXXBaseSpecifier *>& base_classes, 1050 std::vector<int>& member_accessibilities, 1051 DWARFDIECollection& member_function_dies, 1052 AccessType& default_accessibility, 1053 bool &is_a_class 1054) 1055{ 1056 if (parent_die == NULL) 1057 return 0; 1058 1059 TypeList* type_list = m_obj_file->GetModule()->GetTypeList(); 1060 1061 size_t count = 0; 1062 const DWARFDebugInfoEntry *die; 1063 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 1064 1065 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 1066 { 1067 dw_tag_t tag = die->Tag(); 1068 1069 switch (tag) 1070 { 1071 case DW_TAG_member: 1072 { 1073 DWARFDebugInfoEntry::Attributes attributes; 1074 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 1075 if (num_attributes > 0) 1076 { 1077 Declaration decl; 1078 //DWARFExpression location; 1079 const char *name = NULL; 1080 bool is_artificial = false; 1081 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 1082 AccessType accessibility = eAccessNone; 1083 //off_t member_offset = 0; 1084 size_t byte_size = 0; 1085 size_t bit_offset = 0; 1086 size_t bit_size = 0; 1087 uint32_t i; 1088 for (i=0; i<num_attributes && !is_artificial; ++i) 1089 { 1090 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1091 DWARFFormValue form_value; 1092 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1093 { 1094 switch (attr) 1095 { 1096 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 1097 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 1098 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 1099 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 1100 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; 1101 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; 1102 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; 1103 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 1104 case DW_AT_data_member_location: 1105// if (form_value.BlockData()) 1106// { 1107// Value initialValue(0); 1108// Value memberOffset(0); 1109// const DataExtractor& debug_info_data = get_debug_info_data(); 1110// uint32_t block_length = form_value.Unsigned(); 1111// uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 1112// if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL)) 1113// { 1114// member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); 1115// } 1116// } 1117 break; 1118 1119 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; 1120 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; 1121 case DW_AT_declaration: 1122 case DW_AT_description: 1123 case DW_AT_mutable: 1124 case DW_AT_visibility: 1125 default: 1126 case DW_AT_sibling: 1127 break; 1128 } 1129 } 1130 } 1131 1132 // FIXME: Make Clang ignore Objective-C accessibility for expressions 1133 1134 if (class_language == eLanguageTypeObjC || 1135 class_language == eLanguageTypeObjC_plus_plus) 1136 accessibility = eAccessNone; 1137 1138 if (is_artificial == false) 1139 { 1140 Type *member_type = ResolveTypeUID(encoding_uid); 1141 assert(member_type); 1142 if (accessibility == eAccessNone) 1143 accessibility = default_accessibility; 1144 member_accessibilities.push_back(accessibility); 1145 1146 type_list->GetClangASTContext().AddFieldToRecordType (class_clang_type, name, member_type->GetClangType(), accessibility, bit_size); 1147 } 1148 } 1149 } 1150 break; 1151 1152 case DW_TAG_subprogram: 1153 // Let the type parsing code handle this one for us. 1154 member_function_dies.Append (die); 1155 break; 1156 1157 case DW_TAG_inheritance: 1158 { 1159 is_a_class = true; 1160 if (default_accessibility == eAccessNone) 1161 default_accessibility = eAccessPrivate; 1162 // TODO: implement DW_TAG_inheritance type parsing 1163 DWARFDebugInfoEntry::Attributes attributes; 1164 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 1165 if (num_attributes > 0) 1166 { 1167 Declaration decl; 1168 DWARFExpression location; 1169 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 1170 AccessType accessibility = default_accessibility; 1171 bool is_virtual = false; 1172 bool is_base_of_class = true; 1173 off_t member_offset = 0; 1174 uint32_t i; 1175 for (i=0; i<num_attributes; ++i) 1176 { 1177 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1178 DWARFFormValue form_value; 1179 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 1180 { 1181 switch (attr) 1182 { 1183 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 1184 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 1185 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 1186 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; 1187 case DW_AT_data_member_location: 1188 if (form_value.BlockData()) 1189 { 1190 Value initialValue(0); 1191 Value memberOffset(0); 1192 const DataExtractor& debug_info_data = get_debug_info_data(); 1193 uint32_t block_length = form_value.Unsigned(); 1194 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 1195 if (DWARFExpression::Evaluate(NULL, NULL, debug_info_data, NULL, NULL, block_offset, block_length, eRegisterKindDWARF, &initialValue, memberOffset, NULL)) 1196 { 1197 member_offset = memberOffset.ResolveValue(NULL, NULL).UInt(); 1198 } 1199 } 1200 break; 1201 1202 case DW_AT_accessibility: 1203 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 1204 break; 1205 1206 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; 1207 default: 1208 case DW_AT_sibling: 1209 break; 1210 } 1211 } 1212 } 1213 1214 Type *base_class_dctype = ResolveTypeUID(encoding_uid); 1215 assert(base_class_dctype); 1216 1217 if (class_language == eLanguageTypeObjC) 1218 { 1219 type_list->GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_dctype->GetClangType()); 1220 } 1221 else 1222 { 1223 base_classes.push_back (type_list->GetClangASTContext().CreateBaseClassSpecifier (base_class_dctype->GetClangType(), accessibility, is_virtual, is_base_of_class)); 1224 assert(base_classes.back()); 1225 } 1226 } 1227 } 1228 break; 1229 1230 default: 1231 break; 1232 } 1233 } 1234 return count; 1235} 1236 1237 1238clang::DeclContext* 1239SymbolFileDWARF::GetClangDeclContextForTypeUID (lldb::user_id_t type_uid) 1240{ 1241 DWARFDebugInfo* debug_info = DebugInfo(); 1242 if (debug_info) 1243 { 1244 DWARFCompileUnitSP cu_sp; 1245 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp); 1246 if (die) 1247 return GetClangDeclContextForDIE (cu_sp.get(), die); 1248 } 1249 return NULL; 1250} 1251 1252Type* 1253SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid) 1254{ 1255 DWARFDebugInfo* debug_info = DebugInfo(); 1256 if (debug_info) 1257 { 1258 DWARFCompileUnitSP cu_sp; 1259 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp); 1260 if (type_die != NULL) 1261 return ResolveType (cu_sp.get(), type_die); 1262 } 1263 return NULL; 1264} 1265 1266lldb::clang_type_t 1267SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) 1268{ 1269 // We have a struct/union/class/enum that needs to be fully resolved. 1270 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (ClangASTType::RemoveFastQualifiers(clang_type)); 1271 if (die == NULL) 1272 { 1273 // We have already resolved this type... 1274 return clang_type; 1275 } 1276 // Once we start resolving this type, remove it from the forward declaration 1277 // map in case anyone child members or other types require this type to get resolved. 1278 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition 1279 // are done. 1280 m_forward_decl_clang_type_to_die.erase (ClangASTType::RemoveFastQualifiers(clang_type)); 1281 1282 1283 DWARFDebugInfo* debug_info = DebugInfo(); 1284 1285 DWARFCompileUnit *cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get(); 1286 Type *type = m_die_to_type.lookup (die); 1287 1288 const dw_tag_t tag = die->Tag(); 1289 1290 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\") - resolve forward declaration...\n", die->GetOffset(), DW_TAG_value_to_name(tag), type->GetName().AsCString()); 1291 assert (clang_type); 1292 DWARFDebugInfoEntry::Attributes attributes; 1293 1294 TypeList* type_list = m_obj_file->GetModule()->GetTypeList(); 1295 1296 switch (tag) 1297 { 1298 case DW_TAG_structure_type: 1299 case DW_TAG_union_type: 1300 case DW_TAG_class_type: 1301 type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type); 1302 if (die->HasChildren()) 1303 { 1304 LanguageType class_language = eLanguageTypeUnknown; 1305 bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type); 1306 if (is_objc_class) 1307 class_language = eLanguageTypeObjC; 1308 1309 int tag_decl_kind = -1; 1310 AccessType default_accessibility = eAccessNone; 1311 if (tag == DW_TAG_structure_type) 1312 { 1313 tag_decl_kind = clang::TTK_Struct; 1314 default_accessibility = eAccessPublic; 1315 } 1316 else if (tag == DW_TAG_union_type) 1317 { 1318 tag_decl_kind = clang::TTK_Union; 1319 default_accessibility = eAccessPublic; 1320 } 1321 else if (tag == DW_TAG_class_type) 1322 { 1323 tag_decl_kind = clang::TTK_Class; 1324 default_accessibility = eAccessPrivate; 1325 } 1326 1327 SymbolContext sc(GetCompUnitForDWARFCompUnit(cu)); 1328 std::vector<clang::CXXBaseSpecifier *> base_classes; 1329 std::vector<int> member_accessibilities; 1330 bool is_a_class = false; 1331 // Parse members and base classes first 1332 DWARFDIECollection member_function_dies; 1333 1334 ParseChildMembers (sc, 1335 cu, 1336 die, 1337 clang_type, 1338 class_language, 1339 base_classes, 1340 member_accessibilities, 1341 member_function_dies, 1342 default_accessibility, 1343 is_a_class); 1344 1345 // Now parse any methods if there were any... 1346 size_t num_functions = member_function_dies.Size(); 1347 if (num_functions > 0) 1348 { 1349 for (size_t i=0; i<num_functions; ++i) 1350 { 1351 ResolveType(cu, member_function_dies.GetDIEPtrAtIndex(i)); 1352 } 1353 } 1354 1355 if (class_language == eLanguageTypeObjC) 1356 { 1357 std::string class_str (ClangASTContext::GetTypeName (clang_type)); 1358 if (!class_str.empty()) 1359 { 1360 1361 ConstString class_name (class_str.c_str()); 1362 std::vector<NameToDIE::Info> method_die_infos; 1363 if (m_objc_class_selectors_index.Find (class_name, method_die_infos)) 1364 { 1365 DWARFCompileUnit* method_cu = NULL; 1366 DWARFCompileUnit* prev_method_cu = NULL; 1367 const size_t num_objc_methods = method_die_infos.size(); 1368 for (size_t i=0;i<num_objc_methods; ++i, prev_method_cu = method_cu) 1369 { 1370 method_cu = debug_info->GetCompileUnitAtIndex(method_die_infos[i].cu_idx); 1371 1372 if (method_cu != prev_method_cu) 1373 method_cu->ExtractDIEsIfNeeded (false); 1374 1375 DWARFDebugInfoEntry *method_die = method_cu->GetDIEAtIndexUnchecked(method_die_infos[i].die_idx); 1376 1377 ResolveType (method_cu, method_die); 1378 } 1379 } 1380 } 1381 } 1382 1383 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we 1384 // need to tell the clang type it is actually a class. 1385 if (class_language != eLanguageTypeObjC) 1386 { 1387 if (is_a_class && tag_decl_kind != clang::TTK_Class) 1388 type_list->GetClangASTContext().SetTagTypeKind (clang_type, clang::TTK_Class); 1389 } 1390 1391 // Since DW_TAG_structure_type gets used for both classes 1392 // and structures, we may need to set any DW_TAG_member 1393 // fields to have a "private" access if none was specified. 1394 // When we parsed the child members we tracked that actual 1395 // accessibility value for each DW_TAG_member in the 1396 // "member_accessibilities" array. If the value for the 1397 // member is zero, then it was set to the "default_accessibility" 1398 // which for structs was "public". Below we correct this 1399 // by setting any fields to "private" that weren't correctly 1400 // set. 1401 if (is_a_class && !member_accessibilities.empty()) 1402 { 1403 // This is a class and all members that didn't have 1404 // their access specified are private. 1405 type_list->GetClangASTContext().SetDefaultAccessForRecordFields (clang_type, eAccessPrivate, &member_accessibilities.front(), member_accessibilities.size()); 1406 } 1407 1408 if (!base_classes.empty()) 1409 { 1410 type_list->GetClangASTContext().SetBaseClassesForClassType (clang_type, &base_classes.front(), base_classes.size()); 1411 1412 // Clang will copy each CXXBaseSpecifier in "base_classes" 1413 // so we have to free them all. 1414 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), base_classes.size()); 1415 } 1416 1417 } 1418 type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type); 1419 return clang_type; 1420 1421 case DW_TAG_enumeration_type: 1422 type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type); 1423 if (die->HasChildren()) 1424 { 1425 SymbolContext sc(GetCompUnitForDWARFCompUnit(cu)); 1426 ParseChildEnumerators(sc, clang_type, type->GetByteSize(), cu, die); 1427 } 1428 type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type); 1429 return clang_type; 1430 1431 default: 1432 assert(false && "not a forward clang type decl!"); 1433 break; 1434 } 1435 return NULL; 1436} 1437 1438Type* 1439SymbolFileDWARF::ResolveType (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed) 1440{ 1441 if (type_die != NULL) 1442 { 1443 Type *type = m_die_to_type.lookup (type_die); 1444 if (type == NULL) 1445 type = GetTypeForDIE (cu, type_die).get(); 1446 if (assert_not_being_parsed) 1447 assert (type != DIE_IS_BEING_PARSED); 1448 return type; 1449 } 1450 return NULL; 1451} 1452 1453CompileUnit* 1454SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* cu, uint32_t cu_idx) 1455{ 1456 // Check if the symbol vendor already knows about this compile unit? 1457 if (cu->GetUserData() == NULL) 1458 { 1459 // The symbol vendor doesn't know about this compile unit, we 1460 // need to parse and add it to the symbol vendor object. 1461 CompUnitSP dc_cu; 1462 ParseCompileUnit(cu, dc_cu); 1463 if (dc_cu.get()) 1464 { 1465 // Figure out the compile unit index if we weren't given one 1466 if (cu_idx == UINT32_MAX) 1467 DebugInfo()->GetCompileUnit(cu->GetOffset(), &cu_idx); 1468 1469 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(dc_cu, cu_idx); 1470 1471 if (m_debug_map_symfile) 1472 m_debug_map_symfile->SetCompileUnit(this, dc_cu); 1473 } 1474 } 1475 return (CompileUnit*)cu->GetUserData(); 1476} 1477 1478bool 1479SymbolFileDWARF::GetFunction (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc) 1480{ 1481 sc.Clear(); 1482 // Check if the symbol vendor already knows about this compile unit? 1483 sc.module_sp = m_obj_file->GetModule()->GetSP(); 1484 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT32_MAX); 1485 1486 sc.function = sc.comp_unit->FindFunctionByUID (func_die->GetOffset()).get(); 1487 if (sc.function == NULL) 1488 sc.function = ParseCompileUnitFunction(sc, cu, func_die); 1489 1490 return sc.function != NULL; 1491} 1492 1493uint32_t 1494SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) 1495{ 1496 Timer scoped_timer(__PRETTY_FUNCTION__, 1497 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)", 1498 so_addr.GetSection(), 1499 so_addr.GetOffset(), 1500 resolve_scope); 1501 uint32_t resolved = 0; 1502 if (resolve_scope & ( eSymbolContextCompUnit | 1503 eSymbolContextFunction | 1504 eSymbolContextBlock | 1505 eSymbolContextLineEntry)) 1506 { 1507 lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); 1508 1509 DWARFDebugAranges* debug_aranges = DebugAranges(); 1510 DWARFDebugInfo* debug_info = DebugInfo(); 1511 if (debug_aranges) 1512 { 1513 dw_offset_t cu_offset = debug_aranges->FindAddress(file_vm_addr); 1514 if (cu_offset != DW_INVALID_OFFSET) 1515 { 1516 uint32_t cu_idx; 1517 DWARFCompileUnit* cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get(); 1518 if (cu) 1519 { 1520 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, cu_idx); 1521 assert(sc.comp_unit != NULL); 1522 resolved |= eSymbolContextCompUnit; 1523 1524 if (resolve_scope & eSymbolContextLineEntry) 1525 { 1526 LineTable *line_table = sc.comp_unit->GetLineTable(); 1527 if (line_table == NULL) 1528 { 1529 if (ParseCompileUnitLineTable(sc)) 1530 line_table = sc.comp_unit->GetLineTable(); 1531 } 1532 if (line_table != NULL) 1533 { 1534 if (so_addr.IsLinkedAddress()) 1535 { 1536 Address linked_addr (so_addr); 1537 linked_addr.ResolveLinkedAddress(); 1538 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry)) 1539 { 1540 resolved |= eSymbolContextLineEntry; 1541 } 1542 } 1543 else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry)) 1544 { 1545 resolved |= eSymbolContextLineEntry; 1546 } 1547 } 1548 } 1549 1550 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) 1551 { 1552 DWARFDebugInfoEntry *function_die = NULL; 1553 DWARFDebugInfoEntry *block_die = NULL; 1554 if (resolve_scope & eSymbolContextBlock) 1555 { 1556 cu->LookupAddress(file_vm_addr, &function_die, &block_die); 1557 } 1558 else 1559 { 1560 cu->LookupAddress(file_vm_addr, &function_die, NULL); 1561 } 1562 1563 if (function_die != NULL) 1564 { 1565 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get(); 1566 if (sc.function == NULL) 1567 sc.function = ParseCompileUnitFunction(sc, cu, function_die); 1568 } 1569 1570 if (sc.function != NULL) 1571 { 1572 resolved |= eSymbolContextFunction; 1573 1574 if (resolve_scope & eSymbolContextBlock) 1575 { 1576 Block& block = sc.function->GetBlock (true); 1577 1578 if (block_die != NULL) 1579 sc.block = block.FindBlockByID (block_die->GetOffset()); 1580 else 1581 sc.block = block.FindBlockByID (function_die->GetOffset()); 1582 if (sc.block) 1583 resolved |= eSymbolContextBlock; 1584 } 1585 } 1586 } 1587 } 1588 } 1589 } 1590 } 1591 return resolved; 1592} 1593 1594 1595 1596uint32_t 1597SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) 1598{ 1599 const uint32_t prev_size = sc_list.GetSize(); 1600 if (resolve_scope & eSymbolContextCompUnit) 1601 { 1602 DWARFDebugInfo* debug_info = DebugInfo(); 1603 if (debug_info) 1604 { 1605 uint32_t cu_idx; 1606 DWARFCompileUnit* cu = NULL; 1607 1608 for (cu_idx = 0; (cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx) 1609 { 1610 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(cu, cu_idx); 1611 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0; 1612 if (check_inlines || file_spec_matches_cu_file_spec) 1613 { 1614 SymbolContext sc (m_obj_file->GetModule()); 1615 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, cu_idx); 1616 assert(sc.comp_unit != NULL); 1617 1618 uint32_t file_idx = UINT32_MAX; 1619 1620 // If we are looking for inline functions only and we don't 1621 // find it in the support files, we are done. 1622 if (check_inlines) 1623 { 1624 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec); 1625 if (file_idx == UINT32_MAX) 1626 continue; 1627 } 1628 1629 if (line != 0) 1630 { 1631 LineTable *line_table = sc.comp_unit->GetLineTable(); 1632 1633 if (line_table != NULL && line != 0) 1634 { 1635 // We will have already looked up the file index if 1636 // we are searching for inline entries. 1637 if (!check_inlines) 1638 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec); 1639 1640 if (file_idx != UINT32_MAX) 1641 { 1642 uint32_t found_line; 1643 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry); 1644 found_line = sc.line_entry.line; 1645 1646 while (line_idx != UINT32_MAX) 1647 { 1648 sc.function = NULL; 1649 sc.block = NULL; 1650 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) 1651 { 1652 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress(); 1653 if (file_vm_addr != LLDB_INVALID_ADDRESS) 1654 { 1655 DWARFDebugInfoEntry *function_die = NULL; 1656 DWARFDebugInfoEntry *block_die = NULL; 1657 cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL); 1658 1659 if (function_die != NULL) 1660 { 1661 sc.function = sc.comp_unit->FindFunctionByUID (function_die->GetOffset()).get(); 1662 if (sc.function == NULL) 1663 sc.function = ParseCompileUnitFunction(sc, cu, function_die); 1664 } 1665 1666 if (sc.function != NULL) 1667 { 1668 Block& block = sc.function->GetBlock (true); 1669 1670 if (block_die != NULL) 1671 sc.block = block.FindBlockByID (block_die->GetOffset()); 1672 else 1673 sc.block = block.FindBlockByID (function_die->GetOffset()); 1674 } 1675 } 1676 } 1677 1678 sc_list.Append(sc); 1679 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry); 1680 } 1681 } 1682 } 1683 else if (file_spec_matches_cu_file_spec && !check_inlines) 1684 { 1685 // only append the context if we aren't looking for inline call sites 1686 // by file and line and if the file spec matches that of the compile unit 1687 sc_list.Append(sc); 1688 } 1689 } 1690 else if (file_spec_matches_cu_file_spec && !check_inlines) 1691 { 1692 // only append the context if we aren't looking for inline call sites 1693 // by file and line and if the file spec matches that of the compile unit 1694 sc_list.Append(sc); 1695 } 1696 1697 if (!check_inlines) 1698 break; 1699 } 1700 } 1701 } 1702 } 1703 return sc_list.GetSize() - prev_size; 1704} 1705 1706void 1707SymbolFileDWARF::Index () 1708{ 1709 if (m_indexed) 1710 return; 1711 m_indexed = true; 1712 Timer scoped_timer (__PRETTY_FUNCTION__, 1713 "SymbolFileDWARF::Index (%s)", 1714 GetObjectFile()->GetFileSpec().GetFilename().AsCString()); 1715 1716 DWARFDebugInfo* debug_info = DebugInfo(); 1717 if (debug_info) 1718 { 1719 m_aranges.reset(new DWARFDebugAranges()); 1720 1721 uint32_t cu_idx = 0; 1722 const uint32_t num_compile_units = GetNumCompileUnits(); 1723 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) 1724 { 1725 DWARFCompileUnit* cu = debug_info->GetCompileUnitAtIndex(cu_idx); 1726 1727 bool clear_dies = cu->ExtractDIEsIfNeeded (false) > 1; 1728 1729 cu->Index (cu_idx, 1730 m_function_basename_index, 1731 m_function_fullname_index, 1732 m_function_method_index, 1733 m_function_selector_index, 1734 m_objc_class_selectors_index, 1735 m_global_index, 1736 m_type_index, 1737 m_namespace_index, 1738 DebugRanges(), 1739 m_aranges.get()); 1740 1741 // Keep memory down by clearing DIEs if this generate function 1742 // caused them to be parsed 1743 if (clear_dies) 1744 cu->ClearDIEs (true); 1745 } 1746 1747 m_aranges->Sort(); 1748 1749#if defined (ENABLE_DEBUG_PRINTF) 1750 StreamFile s(stdout); 1751 s.Printf ("DWARF index for (%s) '%s/%s':", 1752 GetObjectFile()->GetModule()->GetArchitecture().AsCString(), 1753 GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), 1754 GetObjectFile()->GetFileSpec().GetFilename().AsCString()); 1755 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); 1756 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s); 1757 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s); 1758 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s); 1759 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s); 1760 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s); 1761 s.Printf("\nTypes:\n"); m_type_index.Dump (&s); 1762 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s); 1763 1764#endif 1765 } 1766} 1767 1768uint32_t 1769SymbolFileDWARF::FindGlobalVariables (const ConstString &name, bool append, uint32_t max_matches, VariableList& variables) 1770{ 1771 DWARFDebugInfo* info = DebugInfo(); 1772 if (info == NULL) 1773 return 0; 1774 1775 // If we aren't appending the results to this list, then clear the list 1776 if (!append) 1777 variables.Clear(); 1778 1779 // Remember how many variables are in the list before we search in case 1780 // we are appending the results to a variable list. 1781 const uint32_t original_size = variables.GetSize(); 1782 1783 // Index the DWARF if we haven't already 1784 if (!m_indexed) 1785 Index (); 1786 1787 SymbolContext sc; 1788 sc.module_sp = m_obj_file->GetModule()->GetSP(); 1789 assert (sc.module_sp); 1790 1791 DWARFCompileUnit* cu = NULL; 1792 DWARFCompileUnit* prev_cu = NULL; 1793 const DWARFDebugInfoEntry* die = NULL; 1794 std::vector<NameToDIE::Info> die_info_array; 1795 const size_t num_matches = m_global_index.Find(name, die_info_array); 1796 for (size_t i=0; i<num_matches; ++i, prev_cu = cu) 1797 { 1798 cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); 1799 1800 if (cu != prev_cu) 1801 cu->ExtractDIEsIfNeeded (false); 1802 1803 die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); 1804 1805 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT32_MAX); 1806 assert(sc.comp_unit != NULL); 1807 1808 ParseVariables(sc, cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); 1809 1810 if (variables.GetSize() - original_size >= max_matches) 1811 break; 1812 } 1813 1814 // Return the number of variable that were appended to the list 1815 return variables.GetSize() - original_size; 1816} 1817 1818uint32_t 1819SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) 1820{ 1821 DWARFDebugInfo* info = DebugInfo(); 1822 if (info == NULL) 1823 return 0; 1824 1825 // If we aren't appending the results to this list, then clear the list 1826 if (!append) 1827 variables.Clear(); 1828 1829 // Remember how many variables are in the list before we search in case 1830 // we are appending the results to a variable list. 1831 const uint32_t original_size = variables.GetSize(); 1832 1833 // Index the DWARF if we haven't already 1834 if (!m_indexed) 1835 Index (); 1836 1837 SymbolContext sc; 1838 sc.module_sp = m_obj_file->GetModule()->GetSP(); 1839 assert (sc.module_sp); 1840 1841 DWARFCompileUnit* cu = NULL; 1842 DWARFCompileUnit* prev_cu = NULL; 1843 const DWARFDebugInfoEntry* die = NULL; 1844 std::vector<NameToDIE::Info> die_info_array; 1845 const size_t num_matches = m_global_index.Find(regex, die_info_array); 1846 for (size_t i=0; i<num_matches; ++i, prev_cu = cu) 1847 { 1848 cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); 1849 1850 if (cu != prev_cu) 1851 cu->ExtractDIEsIfNeeded (false); 1852 1853 die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); 1854 1855 sc.comp_unit = GetCompUnitForDWARFCompUnit(cu, UINT32_MAX); 1856 assert(sc.comp_unit != NULL); 1857 1858 ParseVariables(sc, cu, LLDB_INVALID_ADDRESS, die, false, false, &variables); 1859 1860 if (variables.GetSize() - original_size >= max_matches) 1861 break; 1862 } 1863 1864 // Return the number of variable that were appended to the list 1865 return variables.GetSize() - original_size; 1866} 1867 1868 1869void 1870SymbolFileDWARF::FindFunctions 1871( 1872 const ConstString &name, 1873 const NameToDIE &name_to_die, 1874 SymbolContextList& sc_list 1875) 1876{ 1877 DWARFDebugInfo* info = DebugInfo(); 1878 if (info == NULL) 1879 return; 1880 1881 SymbolContext sc; 1882 sc.module_sp = m_obj_file->GetModule()->GetSP(); 1883 assert (sc.module_sp); 1884 1885 DWARFCompileUnit* cu = NULL; 1886 DWARFCompileUnit* prev_cu = NULL; 1887 const DWARFDebugInfoEntry* die = NULL; 1888 std::vector<NameToDIE::Info> die_info_array; 1889 const size_t num_matches = name_to_die.Find(name, die_info_array); 1890 for (size_t i=0; i<num_matches; ++i, prev_cu = cu) 1891 { 1892 cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); 1893 1894 if (cu != prev_cu) 1895 cu->ExtractDIEsIfNeeded (false); 1896 1897 die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); 1898 if (GetFunction (cu, die, sc)) 1899 { 1900 // We found the function, so we should find the line table 1901 // and line table entry as well 1902 LineTable *line_table = sc.comp_unit->GetLineTable(); 1903 if (line_table == NULL) 1904 { 1905 if (ParseCompileUnitLineTable(sc)) 1906 line_table = sc.comp_unit->GetLineTable(); 1907 } 1908 if (line_table != NULL) 1909 line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry); 1910 1911 sc_list.Append(sc); 1912 } 1913 } 1914} 1915 1916 1917void 1918SymbolFileDWARF::FindFunctions 1919( 1920 const RegularExpression ®ex, 1921 const NameToDIE &name_to_die, 1922 SymbolContextList& sc_list 1923) 1924{ 1925 DWARFDebugInfo* info = DebugInfo(); 1926 if (info == NULL) 1927 return; 1928 1929 SymbolContext sc; 1930 sc.module_sp = m_obj_file->GetModule()->GetSP(); 1931 assert (sc.module_sp); 1932 1933 DWARFCompileUnit* cu = NULL; 1934 DWARFCompileUnit* prev_cu = NULL; 1935 const DWARFDebugInfoEntry* die = NULL; 1936 std::vector<NameToDIE::Info> die_info_array; 1937 const size_t num_matches = name_to_die.Find(regex, die_info_array); 1938 for (size_t i=0; i<num_matches; ++i, prev_cu = cu) 1939 { 1940 cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); 1941 1942 if (cu != prev_cu) 1943 cu->ExtractDIEsIfNeeded (false); 1944 1945 die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); 1946 if (GetFunction (cu, die, sc)) 1947 { 1948 // We found the function, so we should find the line table 1949 // and line table entry as well 1950 LineTable *line_table = sc.comp_unit->GetLineTable(); 1951 if (line_table == NULL) 1952 { 1953 if (ParseCompileUnitLineTable(sc)) 1954 line_table = sc.comp_unit->GetLineTable(); 1955 } 1956 if (line_table != NULL) 1957 line_table->FindLineEntryByAddress (sc.function->GetAddressRange().GetBaseAddress(), sc.line_entry); 1958 1959 sc_list.Append(sc); 1960 } 1961 } 1962} 1963 1964uint32_t 1965SymbolFileDWARF::FindFunctions 1966( 1967 const ConstString &name, 1968 uint32_t name_type_mask, 1969 bool append, 1970 SymbolContextList& sc_list 1971) 1972{ 1973 Timer scoped_timer (__PRETTY_FUNCTION__, 1974 "SymbolFileDWARF::FindFunctions (name = '%s')", 1975 name.AsCString()); 1976 1977 // If we aren't appending the results to this list, then clear the list 1978 if (!append) 1979 sc_list.Clear(); 1980 1981 // Remember how many sc_list are in the list before we search in case 1982 // we are appending the results to a variable list. 1983 uint32_t original_size = sc_list.GetSize(); 1984 1985 // Index the DWARF if we haven't already 1986 if (!m_indexed) 1987 Index (); 1988 1989 if (name_type_mask & eFunctionNameTypeBase) 1990 FindFunctions (name, m_function_basename_index, sc_list); 1991 1992 if (name_type_mask & eFunctionNameTypeFull) 1993 FindFunctions (name, m_function_fullname_index, sc_list); 1994 1995 if (name_type_mask & eFunctionNameTypeMethod) 1996 FindFunctions (name, m_function_method_index, sc_list); 1997 1998 if (name_type_mask & eFunctionNameTypeSelector) 1999 FindFunctions (name, m_function_selector_index, sc_list); 2000 2001 // Return the number of variable that were appended to the list 2002 return sc_list.GetSize() - original_size; 2003} 2004 2005 2006uint32_t 2007SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool append, SymbolContextList& sc_list) 2008{ 2009 Timer scoped_timer (__PRETTY_FUNCTION__, 2010 "SymbolFileDWARF::FindFunctions (regex = '%s')", 2011 regex.GetText()); 2012 2013 // If we aren't appending the results to this list, then clear the list 2014 if (!append) 2015 sc_list.Clear(); 2016 2017 // Remember how many sc_list are in the list before we search in case 2018 // we are appending the results to a variable list. 2019 uint32_t original_size = sc_list.GetSize(); 2020 2021 // Index the DWARF if we haven't already 2022 if (!m_indexed) 2023 Index (); 2024 2025 FindFunctions (regex, m_function_basename_index, sc_list); 2026 2027 FindFunctions (regex, m_function_fullname_index, sc_list); 2028 2029 // Return the number of variable that were appended to the list 2030 return sc_list.GetSize() - original_size; 2031} 2032 2033uint32_t 2034SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, bool append, uint32_t max_matches, TypeList& types) 2035{ 2036 DWARFDebugInfo* info = DebugInfo(); 2037 if (info == NULL) 2038 return 0; 2039 2040 // If we aren't appending the results to this list, then clear the list 2041 if (!append) 2042 types.Clear(); 2043 2044 // Index if we already haven't to make sure the compile units 2045 // get indexed and make their global DIE index list 2046 if (!m_indexed) 2047 Index (); 2048 2049 const uint32_t initial_types_size = types.GetSize(); 2050 DWARFCompileUnit* cu = NULL; 2051 DWARFCompileUnit* prev_cu = NULL; 2052 const DWARFDebugInfoEntry* die = NULL; 2053 std::vector<NameToDIE::Info> die_info_array; 2054 const size_t num_matches = m_type_index.Find (name, die_info_array); 2055 for (size_t i=0; i<num_matches; ++i, prev_cu = cu) 2056 { 2057 cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx); 2058 2059 if (cu != prev_cu) 2060 cu->ExtractDIEsIfNeeded (false); 2061 2062 die = cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx); 2063 2064 Type *matching_type = ResolveType (cu, die); 2065 if (matching_type) 2066 { 2067 // We found a type pointer, now find the shared pointer form our type list 2068 TypeSP type_sp (m_obj_file->GetModule()->GetTypeList()->FindType(matching_type->GetID())); 2069 assert (type_sp.get() != NULL); 2070 types.InsertUnique (type_sp); 2071 if (types.GetSize() >= max_matches) 2072 break; 2073 } 2074 } 2075 return types.GetSize() - initial_types_size; 2076} 2077 2078 2079uint32_t 2080SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types) 2081{ 2082 // Remember how many sc_list are in the list before we search in case 2083 // we are appending the results to a variable list. 2084 uint32_t original_size = types.GetSize(); 2085 2086 const uint32_t num_die_offsets = die_offsets.size(); 2087 // Parse all of the types we found from the pubtypes matches 2088 uint32_t i; 2089 uint32_t num_matches = 0; 2090 for (i = 0; i < num_die_offsets; ++i) 2091 { 2092 Type *matching_type = ResolveTypeUID (die_offsets[i]); 2093 if (matching_type) 2094 { 2095 // We found a type pointer, now find the shared pointer form our type list 2096 TypeSP type_sp (m_obj_file->GetModule()->GetTypeList()->FindType(matching_type->GetID())); 2097 assert (type_sp.get() != NULL); 2098 types.InsertUnique (type_sp); 2099 ++num_matches; 2100 if (num_matches >= max_matches) 2101 break; 2102 } 2103 } 2104 2105 // Return the number of variable that were appended to the list 2106 return types.GetSize() - original_size; 2107} 2108 2109 2110size_t 2111SymbolFileDWARF::ParseChildParameters 2112( 2113 const SymbolContext& sc, 2114 TypeSP& type_sp, 2115 DWARFCompileUnit* dwarf_cu, 2116 const DWARFDebugInfoEntry *parent_die, 2117 bool skip_artificial, 2118 TypeList* type_list, 2119 std::vector<clang_type_t>& function_param_types, 2120 std::vector<clang::ParmVarDecl*>& function_param_decls 2121) 2122{ 2123 if (parent_die == NULL) 2124 return 0; 2125 2126 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 2127 2128 size_t count = 0; 2129 const DWARFDebugInfoEntry *die; 2130 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 2131 { 2132 dw_tag_t tag = die->Tag(); 2133 switch (tag) 2134 { 2135 case DW_TAG_formal_parameter: 2136 { 2137 DWARFDebugInfoEntry::Attributes attributes; 2138 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 2139 if (num_attributes > 0) 2140 { 2141 const char *name = NULL; 2142 Declaration decl; 2143 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; 2144 bool is_artificial = false; 2145 // one of None, Auto, Register, Extern, Static, PrivateExtern 2146 2147 clang::StorageClass storage = clang::SC_None; 2148 uint32_t i; 2149 for (i=0; i<num_attributes; ++i) 2150 { 2151 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2152 DWARFFormValue form_value; 2153 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2154 { 2155 switch (attr) 2156 { 2157 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2158 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2159 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2160 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 2161 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; 2162 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; 2163 case DW_AT_location: 2164 // if (form_value.BlockData()) 2165 // { 2166 // const DataExtractor& debug_info_data = debug_info(); 2167 // uint32_t block_length = form_value.Unsigned(); 2168 // DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); 2169 // } 2170 // else 2171 // { 2172 // } 2173 // break; 2174 case DW_AT_const_value: 2175 case DW_AT_default_value: 2176 case DW_AT_description: 2177 case DW_AT_endianity: 2178 case DW_AT_is_optional: 2179 case DW_AT_segment: 2180 case DW_AT_variable_parameter: 2181 default: 2182 case DW_AT_abstract_origin: 2183 case DW_AT_sibling: 2184 break; 2185 } 2186 } 2187 } 2188 2189 bool skip = false; 2190 if (skip_artificial) 2191 { 2192 if (is_artificial) 2193 skip = true; 2194 else 2195 { 2196 2197 // HACK: Objective C formal parameters "self" and "_cmd" 2198 // are not marked as artificial in the DWARF... 2199 CompileUnit *cu = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX); 2200 if (cu && (cu->GetLanguage() == eLanguageTypeObjC || cu->GetLanguage() == eLanguageTypeObjC_plus_plus)) 2201 { 2202 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) 2203 skip = true; 2204 } 2205 } 2206 } 2207 2208 if (!skip) 2209 { 2210 Type *type = ResolveTypeUID(param_type_die_offset); 2211 if (type) 2212 { 2213 function_param_types.push_back (type->GetClangForwardType()); 2214 2215 clang::ParmVarDecl *param_var_decl = type_list->GetClangASTContext().CreateParameterDeclaration (name, type->GetClangForwardType(), storage); 2216 assert(param_var_decl); 2217 function_param_decls.push_back(param_var_decl); 2218 } 2219 } 2220 } 2221 } 2222 break; 2223 2224 default: 2225 break; 2226 } 2227 } 2228 return count; 2229} 2230 2231size_t 2232SymbolFileDWARF::ParseChildEnumerators 2233( 2234 const SymbolContext& sc, 2235 clang_type_t enumerator_clang_type, 2236 uint32_t enumerator_byte_size, 2237 DWARFCompileUnit* dwarf_cu, 2238 const DWARFDebugInfoEntry *parent_die 2239) 2240{ 2241 if (parent_die == NULL) 2242 return 0; 2243 2244 size_t enumerators_added = 0; 2245 const DWARFDebugInfoEntry *die; 2246 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 2247 2248 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 2249 { 2250 const dw_tag_t tag = die->Tag(); 2251 if (tag == DW_TAG_enumerator) 2252 { 2253 DWARFDebugInfoEntry::Attributes attributes; 2254 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 2255 if (num_child_attributes > 0) 2256 { 2257 const char *name = NULL; 2258 bool got_value = false; 2259 int64_t enum_value = 0; 2260 Declaration decl; 2261 2262 uint32_t i; 2263 for (i=0; i<num_child_attributes; ++i) 2264 { 2265 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2266 DWARFFormValue form_value; 2267 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2268 { 2269 switch (attr) 2270 { 2271 case DW_AT_const_value: 2272 got_value = true; 2273 enum_value = form_value.Unsigned(); 2274 break; 2275 2276 case DW_AT_name: 2277 name = form_value.AsCString(&get_debug_str_data()); 2278 break; 2279 2280 case DW_AT_description: 2281 default: 2282 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2283 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2284 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2285 case DW_AT_sibling: 2286 break; 2287 } 2288 } 2289 } 2290 2291 if (name && name[0] && got_value) 2292 { 2293 TypeList* type_list = m_obj_file->GetModule()->GetTypeList(); 2294 type_list->GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type, 2295 enumerator_clang_type, 2296 decl, 2297 name, 2298 enum_value, 2299 enumerator_byte_size * 8); 2300 ++enumerators_added; 2301 } 2302 } 2303 } 2304 } 2305 return enumerators_added; 2306} 2307 2308void 2309SymbolFileDWARF::ParseChildArrayInfo 2310( 2311 const SymbolContext& sc, 2312 DWARFCompileUnit* dwarf_cu, 2313 const DWARFDebugInfoEntry *parent_die, 2314 int64_t& first_index, 2315 std::vector<uint64_t>& element_orders, 2316 uint32_t& byte_stride, 2317 uint32_t& bit_stride 2318) 2319{ 2320 if (parent_die == NULL) 2321 return; 2322 2323 const DWARFDebugInfoEntry *die; 2324 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize()); 2325 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling()) 2326 { 2327 const dw_tag_t tag = die->Tag(); 2328 switch (tag) 2329 { 2330 case DW_TAG_enumerator: 2331 { 2332 DWARFDebugInfoEntry::Attributes attributes; 2333 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 2334 if (num_child_attributes > 0) 2335 { 2336 const char *name = NULL; 2337 bool got_value = false; 2338 int64_t enum_value = 0; 2339 2340 uint32_t i; 2341 for (i=0; i<num_child_attributes; ++i) 2342 { 2343 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2344 DWARFFormValue form_value; 2345 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2346 { 2347 switch (attr) 2348 { 2349 case DW_AT_const_value: 2350 got_value = true; 2351 enum_value = form_value.Unsigned(); 2352 break; 2353 2354 case DW_AT_name: 2355 name = form_value.AsCString(&get_debug_str_data()); 2356 break; 2357 2358 case DW_AT_description: 2359 default: 2360 case DW_AT_decl_file: 2361 case DW_AT_decl_line: 2362 case DW_AT_decl_column: 2363 case DW_AT_sibling: 2364 break; 2365 } 2366 } 2367 } 2368 } 2369 } 2370 break; 2371 2372 case DW_TAG_subrange_type: 2373 { 2374 DWARFDebugInfoEntry::Attributes attributes; 2375 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes); 2376 if (num_child_attributes > 0) 2377 { 2378 const char *name = NULL; 2379 bool got_value = false; 2380 uint64_t byte_size = 0; 2381 int64_t enum_value = 0; 2382 uint64_t num_elements = 0; 2383 uint64_t lower_bound = 0; 2384 uint64_t upper_bound = 0; 2385 uint32_t i; 2386 for (i=0; i<num_child_attributes; ++i) 2387 { 2388 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2389 DWARFFormValue form_value; 2390 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2391 { 2392 switch (attr) 2393 { 2394 case DW_AT_const_value: 2395 got_value = true; 2396 enum_value = form_value.Unsigned(); 2397 break; 2398 2399 case DW_AT_name: 2400 name = form_value.AsCString(&get_debug_str_data()); 2401 break; 2402 2403 case DW_AT_count: 2404 num_elements = form_value.Unsigned(); 2405 break; 2406 2407 case DW_AT_bit_stride: 2408 bit_stride = form_value.Unsigned(); 2409 break; 2410 2411 case DW_AT_byte_stride: 2412 byte_stride = form_value.Unsigned(); 2413 break; 2414 2415 case DW_AT_byte_size: 2416 byte_size = form_value.Unsigned(); 2417 break; 2418 2419 case DW_AT_lower_bound: 2420 lower_bound = form_value.Unsigned(); 2421 break; 2422 2423 case DW_AT_upper_bound: 2424 upper_bound = form_value.Unsigned(); 2425 break; 2426 2427 default: 2428 case DW_AT_abstract_origin: 2429 case DW_AT_accessibility: 2430 case DW_AT_allocated: 2431 case DW_AT_associated: 2432 case DW_AT_data_location: 2433 case DW_AT_declaration: 2434 case DW_AT_description: 2435 case DW_AT_sibling: 2436 case DW_AT_threads_scaled: 2437 case DW_AT_type: 2438 case DW_AT_visibility: 2439 break; 2440 } 2441 } 2442 } 2443 2444 if (upper_bound > lower_bound) 2445 num_elements = upper_bound - lower_bound + 1; 2446 2447 if (num_elements > 0) 2448 element_orders.push_back (num_elements); 2449 } 2450 } 2451 break; 2452 } 2453 } 2454} 2455 2456TypeSP 2457SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry* die) 2458{ 2459 TypeSP type_sp; 2460 if (die != NULL) 2461 { 2462 assert(cu != NULL); 2463 Type *type_ptr = m_die_to_type.lookup (die); 2464 if (type_ptr == NULL) 2465 { 2466 SymbolContext sc(GetCompUnitForDWARFCompUnit(cu)); 2467 type_sp = ParseType(sc, cu, die, NULL); 2468 } 2469 else if (type_ptr != DIE_IS_BEING_PARSED) 2470 { 2471 // Grab the existing type from the master types lists 2472 type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(type_ptr->GetID()); 2473 } 2474 2475 } 2476 return type_sp; 2477} 2478 2479clang::DeclContext * 2480SymbolFileDWARF::GetClangDeclContextForDIEOffset (dw_offset_t die_offset) 2481{ 2482 if (die_offset != DW_INVALID_OFFSET) 2483 { 2484 DWARFCompileUnitSP cu_sp; 2485 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp); 2486 return GetClangDeclContextForDIE (cu_sp.get(), die); 2487 } 2488 return NULL; 2489} 2490 2491 2492 2493clang::DeclContext * 2494SymbolFileDWARF::GetClangDeclContextForDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die) 2495{ 2496 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die); 2497 if (pos != m_die_to_decl_ctx.end()) 2498 return pos->second; 2499 2500 while (die != NULL) 2501 { 2502 switch (die->Tag()) 2503 { 2504 case DW_TAG_namespace: 2505 { 2506 const char *namespace_name = die->GetAttributeValueAsString(this, cu, DW_AT_name, NULL); 2507 if (namespace_name) 2508 { 2509 TypeList* type_list = m_obj_file->GetModule()->GetTypeList(); 2510 assert(type_list); 2511 Declaration decl; // TODO: fill in the decl object 2512 clang::NamespaceDecl *namespace_decl = type_list->GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, decl, GetClangDeclContextForDIE (cu, die->GetParent())); 2513 if (namespace_decl) 2514 m_die_to_decl_ctx[die] = (clang::DeclContext*)namespace_decl; 2515 return namespace_decl; 2516 } 2517 } 2518 break; 2519 2520 default: 2521 break; 2522 } 2523 clang::DeclContext *decl_ctx; 2524 decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, cu, DW_AT_specification, DW_INVALID_OFFSET)); 2525 if (decl_ctx) 2526 return decl_ctx; 2527 2528 decl_ctx = GetClangDeclContextForDIEOffset (die->GetAttributeValueAsUnsigned(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET)); 2529 if (decl_ctx) 2530 return decl_ctx; 2531 2532 die = die->GetParent(); 2533 } 2534 return NULL; 2535} 2536 2537TypeSP 2538SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr) 2539{ 2540 TypeSP type_sp; 2541 2542 if (type_is_new_ptr) 2543 *type_is_new_ptr = false; 2544 2545 AccessType accessibility = eAccessNone; 2546 if (die != NULL) 2547 { 2548 Type *type_ptr = m_die_to_type.lookup (die); 2549 if (type_ptr == NULL) 2550 { 2551 if (type_is_new_ptr) 2552 *type_is_new_ptr = true; 2553 2554 const dw_tag_t tag = die->Tag(); 2555 2556 bool is_forward_declaration = false; 2557 DWARFDebugInfoEntry::Attributes attributes; 2558 const char *type_name_cstr = NULL; 2559 ConstString type_name_const_str; 2560 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; 2561 clang_type_t clang_type = NULL; 2562 2563 TypeList* type_list = m_obj_file->GetModule()->GetTypeList(); 2564 dw_attr_t attr; 2565 2566 switch (tag) 2567 { 2568 case DW_TAG_base_type: 2569 case DW_TAG_pointer_type: 2570 case DW_TAG_reference_type: 2571 case DW_TAG_typedef: 2572 case DW_TAG_const_type: 2573 case DW_TAG_restrict_type: 2574 case DW_TAG_volatile_type: 2575 { 2576 // Set a bit that lets us know that we are currently parsing this 2577 m_die_to_type[die] = DIE_IS_BEING_PARSED; 2578 2579 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 2580 Declaration decl; 2581 uint32_t encoding = 0; 2582 size_t byte_size = 0; 2583 lldb::user_id_t encoding_uid = LLDB_INVALID_UID; 2584 2585 if (num_attributes > 0) 2586 { 2587 uint32_t i; 2588 for (i=0; i<num_attributes; ++i) 2589 { 2590 attr = attributes.AttributeAtIndex(i); 2591 DWARFFormValue form_value; 2592 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2593 { 2594 switch (attr) 2595 { 2596 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2597 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2598 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2599 case DW_AT_name: 2600 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 2601 type_name_const_str.SetCString(type_name_cstr); 2602 break; 2603 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 2604 case DW_AT_encoding: encoding = form_value.Unsigned(); break; 2605 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; 2606 default: 2607 case DW_AT_sibling: 2608 break; 2609 } 2610 } 2611 } 2612 } 2613 2614 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); 2615 2616 switch (tag) 2617 { 2618 default: 2619 case DW_TAG_base_type: 2620 clang_type = type_list->GetClangASTContext().GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, encoding, byte_size * 8); 2621 break; 2622 2623 case DW_TAG_pointer_type: 2624 // The encoding_uid will be embedded into the 2625 // Type object and will be looked up when the Type::GetClangType() 2626 encoding_data_type = Type::eEncodingIsPointerUID; 2627 break; 2628 2629 case DW_TAG_reference_type: 2630 // The encoding_uid will be embedded into the 2631 // Type object and will be looked up when the Type::GetClangType() 2632 encoding_data_type = Type::eEncodingIsLValueReferenceUID; 2633 break; 2634 2635 case DW_TAG_typedef: 2636 // The encoding_uid will be embedded into the 2637 // Type object and will be looked up when the Type::GetClangType() 2638 encoding_data_type = Type::eEncodingIsTypedefUID; 2639 break; 2640 2641 case DW_TAG_const_type: 2642 // The encoding_uid will be embedded into the 2643 // Type object and will be looked up when the Type::GetClangType() 2644 encoding_data_type = Type::eEncodingIsConstUID; //ClangASTContext::AddConstModifier (clang_type); 2645 break; 2646 2647 case DW_TAG_restrict_type: 2648 // The encoding_uid will be embedded into the 2649 // Type object and will be looked up when the Type::GetClangType() 2650 encoding_data_type = Type::eEncodingIsRestrictUID; //ClangASTContext::AddRestrictModifier (clang_type); 2651 break; 2652 2653 case DW_TAG_volatile_type: 2654 // The encoding_uid will be embedded into the 2655 // Type object and will be looked up when the Type::GetClangType() 2656 encoding_data_type = Type::eEncodingIsVolatileUID; //ClangASTContext::AddVolatileModifier (clang_type); 2657 break; 2658 } 2659 2660 if (type_name_cstr != NULL && sc.comp_unit != NULL && 2661 (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus)) 2662 { 2663 static ConstString g_objc_type_name_id("id"); 2664 static ConstString g_objc_type_name_Class("Class"); 2665 static ConstString g_objc_type_name_selector("SEL"); 2666 2667 if (type_name_const_str == g_objc_type_name_id) 2668 { 2669 clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_id(); 2670 } 2671 else if (type_name_const_str == g_objc_type_name_Class) 2672 { 2673 clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_Class(); 2674 } 2675 else if (type_name_const_str == g_objc_type_name_selector) 2676 { 2677 clang_type = type_list->GetClangASTContext().GetBuiltInType_objc_selector(); 2678 } 2679 } 2680 2681 type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, encoding_uid, encoding_data_type, &decl, clang_type, clang_type == NULL)); 2682 2683 m_die_to_type[die] = type_sp.get(); 2684 2685// Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); 2686// if (encoding_type != NULL) 2687// { 2688// if (encoding_type != DIE_IS_BEING_PARSED) 2689// type_sp->SetEncodingType(encoding_type); 2690// else 2691// m_indirect_fixups.push_back(type_sp.get()); 2692// } 2693 } 2694 break; 2695 2696 case DW_TAG_structure_type: 2697 case DW_TAG_union_type: 2698 case DW_TAG_class_type: 2699 { 2700 // Set a bit that lets us know that we are currently parsing this 2701 m_die_to_type[die] = DIE_IS_BEING_PARSED; 2702 2703 size_t byte_size = 0; 2704 LanguageType class_language = eLanguageTypeUnknown; 2705 //bool struct_is_class = false; 2706 Declaration decl; 2707 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 2708 if (num_attributes > 0) 2709 { 2710 uint32_t i; 2711 for (i=0; i<num_attributes; ++i) 2712 { 2713 attr = attributes.AttributeAtIndex(i); 2714 DWARFFormValue form_value; 2715 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2716 { 2717 switch (attr) 2718 { 2719 case DW_AT_decl_file: 2720 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); 2721 break; 2722 2723 case DW_AT_decl_line: 2724 decl.SetLine(form_value.Unsigned()); 2725 break; 2726 2727 case DW_AT_decl_column: 2728 decl.SetColumn(form_value.Unsigned()); 2729 break; 2730 2731 case DW_AT_name: 2732 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 2733 type_name_const_str.SetCString(type_name_cstr); 2734 break; 2735 2736 case DW_AT_byte_size: 2737 byte_size = form_value.Unsigned(); 2738 break; 2739 2740 case DW_AT_accessibility: 2741 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 2742 break; 2743 2744 case DW_AT_declaration: 2745 is_forward_declaration = form_value.Unsigned() != 0; 2746 break; 2747 2748 case DW_AT_APPLE_runtime_class: 2749 class_language = (LanguageType)form_value.Signed(); 2750 break; 2751 2752 case DW_AT_allocated: 2753 case DW_AT_associated: 2754 case DW_AT_data_location: 2755 case DW_AT_description: 2756 case DW_AT_start_scope: 2757 case DW_AT_visibility: 2758 default: 2759 case DW_AT_sibling: 2760 break; 2761 } 2762 } 2763 } 2764 } 2765 2766 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); 2767 2768 int tag_decl_kind = -1; 2769 AccessType default_accessibility = eAccessNone; 2770 if (tag == DW_TAG_structure_type) 2771 { 2772 tag_decl_kind = clang::TTK_Struct; 2773 default_accessibility = eAccessPublic; 2774 } 2775 else if (tag == DW_TAG_union_type) 2776 { 2777 tag_decl_kind = clang::TTK_Union; 2778 default_accessibility = eAccessPublic; 2779 } 2780 else if (tag == DW_TAG_class_type) 2781 { 2782 tag_decl_kind = clang::TTK_Class; 2783 default_accessibility = eAccessPrivate; 2784 } 2785 2786 2787 if (is_forward_declaration) 2788 { 2789 // We have a forward declaration 2790 std::vector<NameToDIE::Info> die_info_array; 2791 const size_t num_matches = m_type_index.Find (type_name_const_str, die_info_array); 2792 DWARFCompileUnit* type_cu = NULL; 2793 DWARFCompileUnit* curr_cu = dwarf_cu; 2794 DWARFDebugInfo *info = DebugInfo(); 2795 for (size_t i=0; i<num_matches; ++i) 2796 { 2797 type_cu = info->GetCompileUnitAtIndex (die_info_array[i].cu_idx); 2798 2799 if (type_cu != curr_cu) 2800 { 2801 type_cu->ExtractDIEsIfNeeded (false); 2802 curr_cu = type_cu; 2803 } 2804 2805 DWARFDebugInfoEntry *type_die = type_cu->GetDIEAtIndexUnchecked (die_info_array[i].die_idx); 2806 2807 if (type_die != die && type_die->Tag() == tag) 2808 { 2809 // Hold off on comparing parent DIE tags until 2810 // we know what happens with stuff in namespaces 2811 // for gcc and clang... 2812// DWARFDebugInfoEntry *parent_die = die->GetParent(); 2813// DWARFDebugInfoEntry *parent_type_die = type_die->GetParent(); 2814// if (parent_die->Tag() == parent_type_die->Tag()) 2815 { 2816 Type *resolved_type = ResolveType (type_cu, type_die, false); 2817 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) 2818 { 2819 DEBUG_PRINTF ("resolved 0x%8.8x (cu 0x%8.8x) from %s to 0x%8.8x (cu 0x%8.8x)\n", 2820 die->GetOffset(), 2821 dwarf_cu->GetOffset(), 2822 m_obj_file->GetFileSpec().GetFilename().AsCString(), 2823 type_die->GetOffset(), 2824 type_cu->GetOffset()); 2825 2826 m_die_to_type[die] = resolved_type; 2827 type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(resolved_type->GetID()); 2828 return type_sp; 2829 } 2830 } 2831 } 2832 } 2833 } 2834 assert (tag_decl_kind != -1); 2835 bool clang_type_was_created = false; 2836 clang_type = m_forward_decl_die_to_clang_type.lookup (die); 2837 if (clang_type == NULL) 2838 { 2839 clang_type_was_created = true; 2840 clang_type = type_list->GetClangASTContext().CreateRecordType (type_name_cstr, tag_decl_kind, GetClangDeclContextForDIE (dwarf_cu, die), class_language); 2841 } 2842 2843 // Store a forward declaration to this class type in case any 2844 // parameters in any class methods need it for the clang 2845 // types for function prototypes. 2846 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type); 2847 const bool is_forward_decl = die->HasChildren(); 2848 type_sp.reset (new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, is_forward_decl)); 2849 2850 m_die_to_type[die] = type_sp.get(); 2851 2852 if (die->HasChildren() == false) 2853 { 2854 // No children for this struct/union/class, lets finish it 2855 type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type); 2856 type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type); 2857 } 2858 else if (clang_type_was_created) 2859 { 2860 // Leave this as a forward declaration until we need 2861 // to know the details of the type. lldb_private::Type 2862 // will automatically call the SymbolFile virtual function 2863 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" 2864 // When the definition needs to be defined. 2865 m_forward_decl_die_to_clang_type[die] = clang_type; 2866 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; 2867 } 2868 2869 } 2870 break; 2871 2872 case DW_TAG_enumeration_type: 2873 { 2874 // Set a bit that lets us know that we are currently parsing this 2875 m_die_to_type[die] = DIE_IS_BEING_PARSED; 2876 2877 size_t byte_size = 0; 2878 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET; 2879 Declaration decl; 2880 2881 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 2882 if (num_attributes > 0) 2883 { 2884 uint32_t i; 2885 2886 for (i=0; i<num_attributes; ++i) 2887 { 2888 attr = attributes.AttributeAtIndex(i); 2889 DWARFFormValue form_value; 2890 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2891 { 2892 switch (attr) 2893 { 2894 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2895 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2896 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2897 case DW_AT_name: 2898 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 2899 type_name_const_str.SetCString(type_name_cstr); 2900 break; 2901 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break; 2902 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 2903 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 2904 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; 2905 case DW_AT_allocated: 2906 case DW_AT_associated: 2907 case DW_AT_bit_stride: 2908 case DW_AT_byte_stride: 2909 case DW_AT_data_location: 2910 case DW_AT_description: 2911 case DW_AT_start_scope: 2912 case DW_AT_visibility: 2913 case DW_AT_specification: 2914 case DW_AT_abstract_origin: 2915 case DW_AT_sibling: 2916 break; 2917 } 2918 } 2919 } 2920 2921 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); 2922 2923 clang_type_t enumerator_clang_type = NULL; 2924 clang_type = m_forward_decl_die_to_clang_type.lookup (die); 2925 if (clang_type == NULL) 2926 { 2927 enumerator_clang_type = type_list->GetClangASTContext().GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, DW_ATE_signed, byte_size * 8); 2928 clang_type = type_list->GetClangASTContext().CreateEnumerationType(decl, type_name_cstr, enumerator_clang_type); 2929 } 2930 else 2931 { 2932 enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type); 2933 assert (enumerator_clang_type != NULL); 2934 } 2935 2936 m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type); 2937 type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, encoding_uid, Type::eEncodingIsUID, &decl, clang_type, true)); 2938 2939 m_die_to_type[die] = type_sp.get(); 2940 2941 // Leave this as a forward declaration until we need 2942 // to know the details of the type. lldb_private::Type 2943 // will automatically call the SymbolFile virtual function 2944 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)" 2945 // When the definition needs to be defined. 2946 m_forward_decl_die_to_clang_type[die] = clang_type; 2947 m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die; 2948 2949 } 2950 } 2951 break; 2952 2953 case DW_TAG_inlined_subroutine: 2954 case DW_TAG_subprogram: 2955 case DW_TAG_subroutine_type: 2956 { 2957 // Set a bit that lets us know that we are currently parsing this 2958 m_die_to_type[die] = DIE_IS_BEING_PARSED; 2959 2960 const char *mangled = NULL; 2961 dw_offset_t type_die_offset = DW_INVALID_OFFSET; 2962 Declaration decl; 2963 bool is_variadic = false; 2964 bool is_inline = false; 2965 bool is_static = false; 2966 bool is_virtual = false; 2967 bool is_explicit = false; 2968 2969 unsigned type_quals = 0; 2970 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern 2971 2972 2973 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 2974 if (num_attributes > 0) 2975 { 2976 uint32_t i; 2977 for (i=0; i<num_attributes; ++i) 2978 { 2979 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2980 DWARFFormValue form_value; 2981 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 2982 { 2983 switch (attr) 2984 { 2985 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2986 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2987 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2988 case DW_AT_name: 2989 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 2990 type_name_const_str.SetCString(type_name_cstr); 2991 break; 2992 2993 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; 2994 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; 2995 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 2996 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; 2997 case DW_AT_inline: is_inline = form_value.Unsigned() != 0; break; 2998 case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break; 2999 case DW_AT_explicit: is_explicit = form_value.Unsigned() != 0; break; 3000 3001 case DW_AT_external: 3002 if (form_value.Unsigned()) 3003 { 3004 if (storage == clang::SC_None) 3005 storage = clang::SC_Extern; 3006 else 3007 storage = clang::SC_PrivateExtern; 3008 } 3009 break; 3010 3011 case DW_AT_allocated: 3012 case DW_AT_associated: 3013 case DW_AT_address_class: 3014 case DW_AT_artificial: 3015 case DW_AT_calling_convention: 3016 case DW_AT_data_location: 3017 case DW_AT_elemental: 3018 case DW_AT_entry_pc: 3019 case DW_AT_frame_base: 3020 case DW_AT_high_pc: 3021 case DW_AT_low_pc: 3022 case DW_AT_object_pointer: 3023 case DW_AT_prototyped: 3024 case DW_AT_pure: 3025 case DW_AT_ranges: 3026 case DW_AT_recursive: 3027 case DW_AT_return_addr: 3028 case DW_AT_segment: 3029 case DW_AT_specification: 3030 case DW_AT_start_scope: 3031 case DW_AT_static_link: 3032 case DW_AT_trampoline: 3033 case DW_AT_visibility: 3034 case DW_AT_vtable_elem_location: 3035 case DW_AT_abstract_origin: 3036 case DW_AT_description: 3037 case DW_AT_sibling: 3038 break; 3039 } 3040 } 3041 } 3042 } 3043 3044 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); 3045 3046 clang_type_t return_clang_type = NULL; 3047 Type *func_type = NULL; 3048 3049 if (type_die_offset != DW_INVALID_OFFSET) 3050 func_type = ResolveTypeUID(type_die_offset); 3051 3052 if (func_type) 3053 return_clang_type = func_type->GetClangForwardType(); 3054 else 3055 return_clang_type = type_list->GetClangASTContext().GetBuiltInType_void(); 3056 3057 3058 std::vector<clang_type_t> function_param_types; 3059 std::vector<clang::ParmVarDecl*> function_param_decls; 3060 3061 // Parse the function children for the parameters 3062 if (die->HasChildren()) 3063 { 3064 bool skip_artificial = true; 3065 ParseChildParameters (sc, type_sp, dwarf_cu, die, skip_artificial, type_list, function_param_types, function_param_decls); 3066 } 3067 3068 // clang_type will get the function prototype clang type after this call 3069 clang_type = type_list->GetClangASTContext().CreateFunctionType (return_clang_type, &function_param_types[0], function_param_types.size(), is_variadic, type_quals); 3070 3071 if (type_name_cstr) 3072 { 3073 bool type_handled = false; 3074 const DWARFDebugInfoEntry *parent_die = die->GetParent(); 3075 if (tag == DW_TAG_subprogram) 3076 { 3077 if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+')) 3078 { 3079 // We need to find the DW_TAG_class_type or 3080 // DW_TAG_struct_type by name so we can add this 3081 // as a member function of the class. 3082 const char *class_name_start = type_name_cstr + 2; 3083 const char *class_name_end = ::strchr (class_name_start, ' '); 3084 SymbolContext empty_sc; 3085 clang_type_t class_opaque_type = NULL; 3086 if (class_name_start < class_name_end) 3087 { 3088 ConstString class_name (class_name_start, class_name_end - class_name_start); 3089 TypeList types; 3090 const uint32_t match_count = FindTypes (empty_sc, class_name, true, UINT32_MAX, types); 3091 if (match_count > 0) 3092 { 3093 for (uint32_t i=0; i<match_count; ++i) 3094 { 3095 Type *type = types.GetTypeAtIndex (i).get(); 3096 clang_type_t type_clang_forward_type = type->GetClangForwardType(); 3097 if (ClangASTContext::IsObjCClassType (type_clang_forward_type)) 3098 { 3099 class_opaque_type = type_clang_forward_type; 3100 break; 3101 } 3102 } 3103 } 3104 } 3105 3106 if (class_opaque_type) 3107 { 3108 // If accessibility isn't set to anything valid, assume public for 3109 // now... 3110 if (accessibility == eAccessNone) 3111 accessibility = eAccessPublic; 3112 3113 clang::ObjCMethodDecl *objc_method_decl; 3114 objc_method_decl = type_list->GetClangASTContext().AddMethodToObjCObjectType (class_opaque_type, 3115 type_name_cstr, 3116 clang_type, 3117 accessibility); 3118 type_handled = objc_method_decl != NULL; 3119 } 3120 } 3121 else if (parent_die->Tag() == DW_TAG_class_type || 3122 parent_die->Tag() == DW_TAG_structure_type) 3123 { 3124 // Look at the parent of this DIE and see if is is 3125 // a class or struct and see if this is actually a 3126 // C++ method 3127 Type *class_type = ResolveType (dwarf_cu, parent_die); 3128 if (class_type) 3129 { 3130 clang_type_t class_opaque_type = class_type->GetClangForwardType(); 3131 if (ClangASTContext::IsCXXClassType (class_opaque_type)) 3132 { 3133 // Neither GCC 4.2 nor clang++ currently set a valid accessibility 3134 // in the DWARF for C++ methods... Default to public for now... 3135 if (accessibility == eAccessNone) 3136 accessibility = eAccessPublic; 3137 3138 clang::CXXMethodDecl *cxx_method_decl; 3139 cxx_method_decl = type_list->GetClangASTContext().AddMethodToCXXRecordType (class_opaque_type, 3140 type_name_cstr, 3141 clang_type, 3142 accessibility, 3143 is_virtual, 3144 is_static, 3145 is_inline, 3146 is_explicit); 3147 type_handled = cxx_method_decl != NULL; 3148 } 3149 } 3150 } 3151 } 3152 3153 if (!type_handled) 3154 { 3155 // We just have a function that isn't part of a class 3156 clang::FunctionDecl *function_decl = type_list->GetClangASTContext().CreateFunctionDeclaration (type_name_cstr, clang_type, storage, is_inline); 3157 3158 // Add the decl to our DIE to decl context map 3159 assert (function_decl); 3160 m_die_to_decl_ctx[die] = function_decl; 3161 if (!function_param_decls.empty()) 3162 type_list->GetClangASTContext().SetFunctionParameters (function_decl, &function_param_decls.front(), function_param_decls.size()); 3163 } 3164 } 3165 type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, 0, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, false)); 3166 3167 m_die_to_type[die] = type_sp.get(); 3168 assert(type_sp.get()); 3169 } 3170 break; 3171 3172 case DW_TAG_array_type: 3173 { 3174 // Set a bit that lets us know that we are currently parsing this 3175 m_die_to_type[die] = DIE_IS_BEING_PARSED; 3176 3177 size_t byte_size = 0; 3178 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET; 3179 Declaration decl; 3180 int64_t first_index = 0; 3181 uint32_t byte_stride = 0; 3182 uint32_t bit_stride = 0; 3183 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 3184 3185 if (num_attributes > 0) 3186 { 3187 uint32_t i; 3188 for (i=0; i<num_attributes; ++i) 3189 { 3190 attr = attributes.AttributeAtIndex(i); 3191 DWARFFormValue form_value; 3192 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 3193 { 3194 switch (attr) 3195 { 3196 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 3197 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 3198 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 3199 case DW_AT_name: 3200 type_name_cstr = form_value.AsCString(&get_debug_str_data()); 3201 type_name_const_str.SetCString(type_name_cstr); 3202 break; 3203 3204 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; 3205 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 3206 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; 3207 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; 3208 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 3209 case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; 3210 case DW_AT_allocated: 3211 case DW_AT_associated: 3212 case DW_AT_data_location: 3213 case DW_AT_description: 3214 case DW_AT_ordering: 3215 case DW_AT_start_scope: 3216 case DW_AT_visibility: 3217 case DW_AT_specification: 3218 case DW_AT_abstract_origin: 3219 case DW_AT_sibling: 3220 break; 3221 } 3222 } 3223 } 3224 3225 DEBUG_PRINTF ("0x%8.8x: %s (\"%s\")\n", die->GetOffset(), DW_TAG_value_to_name(tag), type_name_cstr); 3226 3227 Type *element_type = ResolveTypeUID(type_die_offset); 3228 3229 if (element_type) 3230 { 3231 std::vector<uint64_t> element_orders; 3232 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride); 3233 // We have an array that claims to have no members, lets give it at least one member... 3234 if (element_orders.empty()) 3235 element_orders.push_back (1); 3236 if (byte_stride == 0 && bit_stride == 0) 3237 byte_stride = element_type->GetByteSize(); 3238 clang_type_t array_element_type = element_type->GetClangType(); 3239 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; 3240 uint64_t num_elements = 0; 3241 std::vector<uint64_t>::const_reverse_iterator pos; 3242 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); 3243 for (pos = element_orders.rbegin(); pos != end; ++pos) 3244 { 3245 num_elements = *pos; 3246 clang_type = type_list->GetClangASTContext().CreateArrayType (array_element_type, num_elements, num_elements * array_element_bit_stride); 3247 array_element_type = clang_type; 3248 array_element_bit_stride = array_element_bit_stride * num_elements; 3249 } 3250 ConstString empty_name; 3251 type_sp.reset( new Type(die->GetOffset(), this, empty_name, array_element_bit_stride / 8, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, false)); 3252 m_die_to_type[die] = type_sp.get(); 3253 } 3254 } 3255 } 3256 break; 3257 3258 case DW_TAG_ptr_to_member_type: 3259 { 3260 dw_offset_t type_die_offset = DW_INVALID_OFFSET; 3261 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET; 3262 3263 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 3264 3265 if (num_attributes > 0) { 3266 uint32_t i; 3267 for (i=0; i<num_attributes; ++i) 3268 { 3269 attr = attributes.AttributeAtIndex(i); 3270 DWARFFormValue form_value; 3271 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 3272 { 3273 switch (attr) 3274 { 3275 case DW_AT_type: 3276 type_die_offset = form_value.Reference(dwarf_cu); break; 3277 case DW_AT_containing_type: 3278 containing_type_die_offset = form_value.Reference(dwarf_cu); break; 3279 } 3280 } 3281 } 3282 3283 Type *pointee_type = ResolveTypeUID(type_die_offset); 3284 Type *class_type = ResolveTypeUID(containing_type_die_offset); 3285 3286 clang_type_t pointee_clang_type = pointee_type->GetClangType(); 3287 clang_type_t class_clang_type = class_type->GetClangType(); 3288 3289 clang_type = type_list->GetClangASTContext().CreateMemberPointerType(pointee_clang_type, class_clang_type); 3290 3291 size_t byte_size = ClangASTType::GetClangTypeBitWidth (type_list->GetClangASTContext().getASTContext(), clang_type) / 8; 3292 3293 type_sp.reset( new Type(die->GetOffset(), this, type_name_const_str, byte_size, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, NULL, clang_type, false)); 3294 m_die_to_type[die] = type_sp.get(); 3295 } 3296 3297 break; 3298 } 3299 default: 3300 assert(false && "Unhandled type tag!"); 3301 break; 3302 } 3303 3304 if (type_sp.get()) 3305 { 3306 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); 3307 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; 3308 3309 SymbolContextScope * symbol_context_scope = NULL; 3310 if (sc_parent_tag == DW_TAG_compile_unit) 3311 { 3312 symbol_context_scope = sc.comp_unit; 3313 } 3314 else if (sc.function != NULL) 3315 { 3316 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset()); 3317 if (symbol_context_scope == NULL) 3318 symbol_context_scope = sc.function; 3319 } 3320 3321 if (symbol_context_scope != NULL) 3322 { 3323 type_sp->SetSymbolContextScope(symbol_context_scope); 3324 } 3325 3326// if (udt_sp.get()) 3327// { 3328// if (is_forward_declaration) 3329// udt_sp->GetFlags().Set(UserDefType::flagIsForwardDefinition); 3330// type_sp->SetUserDefinedType(udt_sp); 3331// } 3332 3333 if (type_sp.unique()) 3334 { 3335 // We are ready to put this type into the uniqued list up at the module level 3336 m_obj_file->GetModule()->GetTypeList()->Insert (type_sp); 3337 3338 if (m_debug_map_symfile) 3339 m_debug_map_symfile->GetObjectFile()->GetModule()->GetTypeList()->Insert (type_sp); 3340 3341 m_die_to_type[die] = type_sp.get(); 3342 } 3343 } 3344 } 3345 else if (type_ptr != DIE_IS_BEING_PARSED) 3346 { 3347 type_sp = m_obj_file->GetModule()->GetTypeList()->FindType(type_ptr->GetID()); 3348 } 3349 } 3350 return type_sp; 3351} 3352 3353size_t 3354SymbolFileDWARF::ParseTypes 3355( 3356 const SymbolContext& sc, 3357 DWARFCompileUnit* dwarf_cu, 3358 const DWARFDebugInfoEntry *die, 3359 bool parse_siblings, 3360 bool parse_children 3361) 3362{ 3363 size_t types_added = 0; 3364 while (die != NULL) 3365 { 3366 bool type_is_new = false; 3367 if (ParseType(sc, dwarf_cu, die, &type_is_new).get()) 3368 { 3369 if (type_is_new) 3370 ++types_added; 3371 } 3372 3373 if (parse_children && die->HasChildren()) 3374 { 3375 if (die->Tag() == DW_TAG_subprogram) 3376 { 3377 SymbolContext child_sc(sc); 3378 child_sc.function = sc.comp_unit->FindFunctionByUID(die->GetOffset()).get(); 3379 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true); 3380 } 3381 else 3382 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true); 3383 } 3384 3385 if (parse_siblings) 3386 die = die->GetSibling(); 3387 else 3388 die = NULL; 3389 } 3390 return types_added; 3391} 3392 3393 3394size_t 3395SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc) 3396{ 3397 assert(sc.comp_unit && sc.function); 3398 size_t functions_added = 0; 3399 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); 3400 if (dwarf_cu) 3401 { 3402 dw_offset_t function_die_offset = sc.function->GetID(); 3403 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset); 3404 if (function_die) 3405 { 3406 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, false, true); 3407 } 3408 } 3409 3410 return functions_added; 3411} 3412 3413 3414size_t 3415SymbolFileDWARF::ParseTypes (const SymbolContext &sc) 3416{ 3417 // At least a compile unit must be valid 3418 assert(sc.comp_unit); 3419 size_t types_added = 0; 3420 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID()); 3421 if (dwarf_cu) 3422 { 3423 if (sc.function) 3424 { 3425 dw_offset_t function_die_offset = sc.function->GetID(); 3426 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset); 3427 if (func_die && func_die->HasChildren()) 3428 { 3429 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true); 3430 } 3431 } 3432 else 3433 { 3434 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE(); 3435 if (dwarf_cu_die && dwarf_cu_die->HasChildren()) 3436 { 3437 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true); 3438 } 3439 } 3440 } 3441 3442 return types_added; 3443} 3444 3445size_t 3446SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc) 3447{ 3448 if (sc.comp_unit != NULL) 3449 { 3450 DWARFDebugInfo* info = DebugInfo(); 3451 if (info == NULL) 3452 return 0; 3453 3454 uint32_t cu_idx = UINT32_MAX; 3455 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get(); 3456 3457 if (dwarf_cu == NULL) 3458 return 0; 3459 3460 if (sc.function) 3461 { 3462 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID()); 3463 3464 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS); 3465 assert (func_lo_pc != DW_INVALID_ADDRESS); 3466 3467 return ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true); 3468 } 3469 else if (sc.comp_unit) 3470 { 3471 uint32_t vars_added = 0; 3472 VariableListSP variables (sc.comp_unit->GetVariableList(false)); 3473 3474 if (variables.get() == NULL) 3475 { 3476 variables.reset(new VariableList()); 3477 sc.comp_unit->SetVariableList(variables); 3478 3479 // Index if we already haven't to make sure the compile units 3480 // get indexed and make their global DIE index list 3481 if (!m_indexed) 3482 Index (); 3483 3484 std::vector<NameToDIE::Info> global_die_info_array; 3485 const size_t num_globals = m_global_index.FindAllEntriesForCompileUnitWithIndex (cu_idx, global_die_info_array); 3486 for (size_t idx=0; idx<num_globals; ++idx) 3487 { 3488 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS)); 3489 if (var_sp) 3490 { 3491 variables->AddVariable(var_sp); 3492 ++vars_added; 3493 } 3494 } 3495 } 3496 return vars_added; 3497 } 3498 } 3499 return 0; 3500} 3501 3502 3503VariableSP 3504SymbolFileDWARF::ParseVariableDIE 3505( 3506 const SymbolContext& sc, 3507 DWARFCompileUnit* dwarf_cu, 3508 const DWARFDebugInfoEntry *die, 3509 const lldb::addr_t func_low_pc 3510) 3511{ 3512 3513 VariableSP var_sp; 3514 3515 const dw_tag_t tag = die->Tag(); 3516 DWARFDebugInfoEntry::Attributes attributes; 3517 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); 3518 if (num_attributes > 0) 3519 { 3520 const char *name = NULL; 3521 const char *mangled = NULL; 3522 Declaration decl; 3523 uint32_t i; 3524 Type *var_type = NULL; 3525 DWARFExpression location; 3526 bool is_external = false; 3527 bool is_artificial = false; 3528 AccessType accessibility = eAccessNone; 3529 3530 for (i=0; i<num_attributes; ++i) 3531 { 3532 dw_attr_t attr = attributes.AttributeAtIndex(i); 3533 DWARFFormValue form_value; 3534 if (attributes.ExtractFormValueAtIndex(this, i, form_value)) 3535 { 3536 switch (attr) 3537 { 3538 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 3539 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 3540 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 3541 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; 3542 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; 3543 case DW_AT_type: var_type = ResolveTypeUID(form_value.Reference(dwarf_cu)); break; 3544 case DW_AT_external: is_external = form_value.Unsigned() != 0; break; 3545 case DW_AT_location: 3546 { 3547 if (form_value.BlockData()) 3548 { 3549 const DataExtractor& debug_info_data = get_debug_info_data(); 3550 3551 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 3552 uint32_t block_length = form_value.Unsigned(); 3553 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length); 3554 } 3555 else 3556 { 3557 const DataExtractor& debug_loc_data = get_debug_loc_data(); 3558 const dw_offset_t debug_loc_offset = form_value.Unsigned(); 3559 3560 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset); 3561 if (loc_list_length > 0) 3562 { 3563 location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length); 3564 assert (func_low_pc != LLDB_INVALID_ADDRESS); 3565 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress()); 3566 } 3567 } 3568 } 3569 break; 3570 3571 case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; 3572 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 3573 case DW_AT_const_value: 3574 case DW_AT_declaration: 3575 case DW_AT_description: 3576 case DW_AT_endianity: 3577 case DW_AT_segment: 3578 case DW_AT_start_scope: 3579 case DW_AT_visibility: 3580 default: 3581 case DW_AT_abstract_origin: 3582 case DW_AT_sibling: 3583 case DW_AT_specification: 3584 break; 3585 } 3586 } 3587 } 3588 3589 if (location.IsValid()) 3590 { 3591 assert(var_type != DIE_IS_BEING_PARSED); 3592 3593 ConstString var_name; 3594 if (mangled) 3595 { 3596 Mangled mangled_var_name (mangled, true); 3597 var_name = mangled_var_name.GetDemangledName(); 3598 } 3599 3600 if (!var_name && name) 3601 { 3602 var_name.SetCString(name); 3603 } 3604 3605 ValueType scope = eValueTypeInvalid; 3606 3607 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die); 3608 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; 3609 3610 if (tag == DW_TAG_formal_parameter) 3611 scope = eValueTypeVariableArgument; 3612 else if (is_external || parent_tag == DW_TAG_compile_unit) 3613 scope = eValueTypeVariableGlobal; 3614 else 3615 scope = eValueTypeVariableLocal; 3616 3617 SymbolContextScope * symbol_context_scope = NULL; 3618 if (parent_tag == DW_TAG_compile_unit) 3619 { 3620 symbol_context_scope = sc.comp_unit; 3621 } 3622 else if (sc.function != NULL) 3623 { 3624 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset()); 3625 if (symbol_context_scope == NULL) 3626 symbol_context_scope = sc.function; 3627 } 3628 3629 assert(symbol_context_scope != NULL); 3630 var_sp.reset (new Variable(die->GetOffset(), 3631 var_name, 3632 var_type, 3633 scope, 3634 symbol_context_scope, 3635 &decl, 3636 location, 3637 is_external, 3638 is_artificial)); 3639 3640 m_die_to_variable_sp[die] = var_sp; 3641 } 3642 } 3643 return var_sp; 3644} 3645 3646size_t 3647SymbolFileDWARF::ParseVariables 3648( 3649 const SymbolContext& sc, 3650 DWARFCompileUnit* dwarf_cu, 3651 const lldb::addr_t func_low_pc, 3652 const DWARFDebugInfoEntry *orig_die, 3653 bool parse_siblings, 3654 bool parse_children, 3655 VariableList* cc_variable_list 3656) 3657{ 3658 if (orig_die == NULL) 3659 return 0; 3660 3661 size_t vars_added = 0; 3662 const DWARFDebugInfoEntry *die = orig_die; 3663 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die); 3664 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0; 3665 VariableListSP variables; 3666 switch (parent_tag) 3667 { 3668 case DW_TAG_compile_unit: 3669 if (sc.comp_unit != NULL) 3670 { 3671 variables = sc.comp_unit->GetVariableList(false); 3672 if (variables.get() == NULL) 3673 { 3674 variables.reset(new VariableList()); 3675 sc.comp_unit->SetVariableList(variables); 3676 } 3677 } 3678 else 3679 { 3680 assert(!"Parent DIE was a compile unit, yet we don't have a valid compile unit in the symbol context..."); 3681 vars_added = 0; 3682 } 3683 break; 3684 3685 case DW_TAG_subprogram: 3686 case DW_TAG_inlined_subroutine: 3687 case DW_TAG_lexical_block: 3688 if (sc.function != NULL) 3689 { 3690 // Check to see if we already have parsed the variables for the given scope 3691 3692 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die->GetOffset()); 3693 assert (block != NULL); 3694 variables = block->GetVariableList(false, false); 3695 if (variables.get() == NULL) 3696 { 3697 variables.reset(new VariableList()); 3698 block->SetVariableList(variables); 3699 } 3700 } 3701 else 3702 { 3703 assert(!"Parent DIE was a function or block, yet we don't have a function in the symbol context..."); 3704 vars_added = 0; 3705 } 3706 break; 3707 3708 default: 3709 assert(!"Didn't find appropriate parent DIE for variable list..."); 3710 break; 3711 } 3712 3713 // We need to have a variable list at this point that we can add variables to 3714 assert(variables.get()); 3715 3716 while (die != NULL) 3717 { 3718 dw_tag_t tag = die->Tag(); 3719 3720 // Check to see if we have already parsed this variable or constant? 3721 if (m_die_to_variable_sp[die]) 3722 { 3723 if (cc_variable_list) 3724 cc_variable_list->AddVariable (m_die_to_variable_sp[die]); 3725 } 3726 else 3727 { 3728 // We haven't already parsed it, lets do that now. 3729 if ((tag == DW_TAG_variable) || 3730 (tag == DW_TAG_constant) || 3731 (tag == DW_TAG_formal_parameter && sc.function)) 3732 { 3733 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc)); 3734 if (var_sp) 3735 { 3736 variables->AddVariable(var_sp); 3737 if (cc_variable_list) 3738 cc_variable_list->AddVariable (var_sp); 3739 ++vars_added; 3740 } 3741 } 3742 } 3743 3744 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram); 3745 3746 if (!skip_children && parse_children && die->HasChildren()) 3747 { 3748 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list); 3749 } 3750 3751 if (parse_siblings) 3752 die = die->GetSibling(); 3753 else 3754 die = NULL; 3755 } 3756 3757 return vars_added; 3758} 3759 3760//------------------------------------------------------------------ 3761// PluginInterface protocol 3762//------------------------------------------------------------------ 3763const char * 3764SymbolFileDWARF::GetPluginName() 3765{ 3766 return "SymbolFileDWARF"; 3767} 3768 3769const char * 3770SymbolFileDWARF::GetShortPluginName() 3771{ 3772 return GetPluginNameStatic(); 3773} 3774 3775uint32_t 3776SymbolFileDWARF::GetPluginVersion() 3777{ 3778 return 1; 3779} 3780 3781void 3782SymbolFileDWARF::GetPluginCommandHelp (const char *command, Stream *strm) 3783{ 3784} 3785 3786Error 3787SymbolFileDWARF::ExecutePluginCommand (Args &command, Stream *strm) 3788{ 3789 Error error; 3790 error.SetErrorString("No plug-in command are currently supported."); 3791 return error; 3792} 3793 3794Log * 3795SymbolFileDWARF::EnablePluginLogging (Stream *strm, Args &command) 3796{ 3797 return NULL; 3798} 3799 3800