1 //===-- DWARFASTParserClang.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 "DWARFASTParserClang.h" 11 #include "DWARFCompileUnit.h" 12 #include "DWARFDebugInfo.h" 13 #include "DWARFDeclContext.h" 14 #include "DWARFDefines.h" 15 #include "DWARFDIE.h" 16 #include "DWARFDIECollection.h" 17 #include "SymbolFileDWARF.h" 18 #include "SymbolFileDWARFDebugMap.h" 19 #include "UniqueDWARFASTType.h" 20 21 #include "Plugins/Language/ObjC/ObjCLanguage.h" 22 #include "lldb/Core/Log.h" 23 #include "lldb/Core/Module.h" 24 #include "lldb/Core/StreamString.h" 25 #include "lldb/Core/Value.h" 26 #include "lldb/Host/Host.h" 27 #include "lldb/Interpreter/Args.h" 28 #include "lldb/Symbol/ClangASTImporter.h" 29 #include "lldb/Symbol/ClangExternalASTSourceCommon.h" 30 #include "lldb/Symbol/ClangUtil.h" 31 #include "lldb/Symbol/CompileUnit.h" 32 #include "lldb/Symbol/Function.h" 33 #include "lldb/Symbol/ObjectFile.h" 34 #include "lldb/Symbol/SymbolVendor.h" 35 #include "lldb/Symbol/TypeList.h" 36 #include "lldb/Symbol/TypeMap.h" 37 #include "lldb/Target/Language.h" 38 #include "lldb/Utility/LLDBAssert.h" 39 40 #include "clang/AST/DeclCXX.h" 41 #include "clang/AST/DeclObjC.h" 42 43 #include <map> 44 #include <vector> 45 46 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN 47 48 #ifdef ENABLE_DEBUG_PRINTF 49 #include <stdio.h> 50 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) 51 #else 52 #define DEBUG_PRINTF(fmt, ...) 53 #endif 54 55 56 using namespace lldb; 57 using namespace lldb_private; 58 DWARFASTParserClang::DWARFASTParserClang (ClangASTContext &ast) : 59 m_ast (ast), 60 m_die_to_decl_ctx (), 61 m_decl_ctx_to_die () 62 { 63 } 64 65 DWARFASTParserClang::~DWARFASTParserClang () 66 { 67 } 68 69 70 static AccessType 71 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility) 72 { 73 switch (dwarf_accessibility) 74 { 75 case DW_ACCESS_public: return eAccessPublic; 76 case DW_ACCESS_private: return eAccessPrivate; 77 case DW_ACCESS_protected: return eAccessProtected; 78 default: break; 79 } 80 return eAccessNone; 81 } 82 83 static bool 84 DeclKindIsCXXClass (clang::Decl::Kind decl_kind) 85 { 86 switch (decl_kind) 87 { 88 case clang::Decl::CXXRecord: 89 case clang::Decl::ClassTemplateSpecialization: 90 return true; 91 default: 92 break; 93 } 94 return false; 95 } 96 97 struct BitfieldInfo 98 { 99 uint64_t bit_size; 100 uint64_t bit_offset; 101 102 BitfieldInfo () : 103 bit_size (LLDB_INVALID_ADDRESS), 104 bit_offset (LLDB_INVALID_ADDRESS) 105 { 106 } 107 108 void 109 Clear() 110 { 111 bit_size = LLDB_INVALID_ADDRESS; 112 bit_offset = LLDB_INVALID_ADDRESS; 113 } 114 115 bool IsValid () 116 { 117 return (bit_size != LLDB_INVALID_ADDRESS) && 118 (bit_offset != LLDB_INVALID_ADDRESS); 119 } 120 }; 121 122 123 ClangASTImporter & 124 DWARFASTParserClang::GetClangASTImporter() 125 { 126 if (!m_clang_ast_importer_ap) 127 { 128 m_clang_ast_importer_ap.reset (new ClangASTImporter); 129 } 130 return *m_clang_ast_importer_ap; 131 } 132 133 134 TypeSP 135 DWARFASTParserClang::ParseTypeFromDWO (const DWARFDIE &die, Log *log) 136 { 137 ModuleSP dwo_module_sp = die.GetContainingDWOModule(); 138 if (dwo_module_sp) 139 { 140 // This type comes from an external DWO module 141 std::vector<CompilerContext> dwo_context; 142 die.GetDWOContext(dwo_context); 143 TypeMap dwo_types; 144 if (dwo_module_sp->GetSymbolVendor()->FindTypes(dwo_context, true, dwo_types)) 145 { 146 const size_t num_dwo_types = dwo_types.GetSize(); 147 if (num_dwo_types == 1) 148 { 149 // We found a real definition for this type elsewhere 150 // so lets use it and cache the fact that we found 151 // a complete type for this die 152 TypeSP dwo_type_sp = dwo_types.GetTypeAtIndex(0); 153 if (dwo_type_sp) 154 { 155 lldb_private::CompilerType dwo_type = dwo_type_sp->GetForwardCompilerType(); 156 157 lldb_private::CompilerType type = GetClangASTImporter().CopyType (m_ast, dwo_type); 158 159 //printf ("copied_qual_type: ast = %p, clang_type = %p, name = '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(), external_type->GetName().GetCString()); 160 if (type) 161 { 162 SymbolFileDWARF *dwarf = die.GetDWARF(); 163 TypeSP type_sp (new Type (die.GetID(), 164 dwarf, 165 dwo_type_sp->GetName(), 166 dwo_type_sp->GetByteSize(), 167 NULL, 168 LLDB_INVALID_UID, 169 Type::eEncodingInvalid, 170 &dwo_type_sp->GetDeclaration(), 171 type, 172 Type::eResolveStateForward)); 173 174 dwarf->GetTypeList()->Insert(type_sp); 175 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 176 clang::TagDecl *tag_decl = ClangASTContext::GetAsTagDecl(type); 177 if (tag_decl) 178 LinkDeclContextToDIE(tag_decl, die); 179 else 180 { 181 clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die); 182 if (defn_decl_ctx) 183 LinkDeclContextToDIE(defn_decl_ctx, die); 184 } 185 return type_sp; 186 } 187 } 188 } 189 } 190 } 191 return TypeSP(); 192 } 193 194 TypeSP 195 DWARFASTParserClang::ParseTypeFromDWARF (const SymbolContext& sc, 196 const DWARFDIE &die, 197 Log *log, 198 bool *type_is_new_ptr) 199 { 200 TypeSP type_sp; 201 202 if (type_is_new_ptr) 203 *type_is_new_ptr = false; 204 205 AccessType accessibility = eAccessNone; 206 if (die) 207 { 208 SymbolFileDWARF *dwarf = die.GetDWARF(); 209 if (log) 210 { 211 DWARFDIE context_die; 212 clang::DeclContext *context = GetClangDeclContextContainingDIE (die, &context_die); 213 214 dwarf->GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')", 215 die.GetOffset(), 216 static_cast<void*>(context), 217 context_die.GetOffset(), 218 die.GetTagAsCString(), 219 die.GetName()); 220 221 } 222 // 223 // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 224 // if (log && dwarf_cu) 225 // { 226 // StreamString s; 227 // die->DumpLocation (this, dwarf_cu, s); 228 // dwarf->GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); 229 // 230 // } 231 232 Type *type_ptr = dwarf->GetDIEToType().lookup (die.GetDIE()); 233 TypeList* type_list = dwarf->GetTypeList(); 234 if (type_ptr == NULL) 235 { 236 if (type_is_new_ptr) 237 *type_is_new_ptr = true; 238 239 const dw_tag_t tag = die.Tag(); 240 241 bool is_forward_declaration = false; 242 DWARFAttributes attributes; 243 const char *type_name_cstr = NULL; 244 ConstString type_name_const_str; 245 Type::ResolveState resolve_state = Type::eResolveStateUnresolved; 246 uint64_t byte_size = 0; 247 Declaration decl; 248 249 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; 250 CompilerType clang_type; 251 DWARFFormValue form_value; 252 253 dw_attr_t attr; 254 255 switch (tag) 256 { 257 case DW_TAG_typedef: 258 // Try to parse a typedef from the DWO file first as modules 259 // can contain typedef'ed structures that have no names like: 260 // 261 // typedef struct { int a; } Foo; 262 // 263 // In this case we will have a structure with no name and a 264 // typedef named "Foo" that points to this unnamed structure. 265 // The name in the typedef is the only identifier for the struct, 266 // so always try to get typedefs from DWO files if possible. 267 // 268 // The type_sp returned will be empty if the typedef doesn't exist 269 // in a DWO file, so it is cheap to call this function just to check. 270 // 271 // If we don't do this we end up creating a TypeSP that says this 272 // is a typedef to type 0x123 (the DW_AT_type value would be 0x123 273 // in the DW_TAG_typedef), and this is the unnamed structure type. 274 // We will have a hard time tracking down an unnammed structure 275 // type in the module DWO file, so we make sure we don't get into 276 // this situation by always resolving typedefs from the DWO file. 277 type_sp = ParseTypeFromDWO(die, log); 278 if (type_sp) 279 return type_sp; 280 281 LLVM_FALLTHROUGH; 282 case DW_TAG_base_type: 283 case DW_TAG_pointer_type: 284 case DW_TAG_reference_type: 285 case DW_TAG_rvalue_reference_type: 286 case DW_TAG_const_type: 287 case DW_TAG_restrict_type: 288 case DW_TAG_volatile_type: 289 case DW_TAG_unspecified_type: 290 { 291 // Set a bit that lets us know that we are currently parsing this 292 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; 293 294 const size_t num_attributes = die.GetAttributes (attributes); 295 uint32_t encoding = 0; 296 DWARFFormValue encoding_uid; 297 298 if (num_attributes > 0) 299 { 300 uint32_t i; 301 for (i=0; i<num_attributes; ++i) 302 { 303 attr = attributes.AttributeAtIndex(i); 304 if (attributes.ExtractFormValueAtIndex(i, form_value)) 305 { 306 switch (attr) 307 { 308 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 309 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 310 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 311 case DW_AT_name: 312 313 type_name_cstr = form_value.AsCString(); 314 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't 315 // include the "&"... 316 if (tag == DW_TAG_reference_type) 317 { 318 if (strchr (type_name_cstr, '&') == NULL) 319 type_name_cstr = NULL; 320 } 321 if (type_name_cstr) 322 type_name_const_str.SetCString(type_name_cstr); 323 break; 324 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 325 case DW_AT_encoding: encoding = form_value.Unsigned(); break; 326 case DW_AT_type: encoding_uid = form_value; break; 327 default: 328 case DW_AT_sibling: 329 break; 330 } 331 } 332 } 333 } 334 335 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid.Reference()); 336 337 switch (tag) 338 { 339 default: 340 break; 341 342 case DW_TAG_unspecified_type: 343 if (strcmp(type_name_cstr, "nullptr_t") == 0 || 344 strcmp(type_name_cstr, "decltype(nullptr)") == 0 ) 345 { 346 resolve_state = Type::eResolveStateFull; 347 clang_type = m_ast.GetBasicType(eBasicTypeNullPtr); 348 break; 349 } 350 // Fall through to base type below in case we can handle the type there... 351 LLVM_FALLTHROUGH; 352 353 case DW_TAG_base_type: 354 resolve_state = Type::eResolveStateFull; 355 clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, 356 encoding, 357 byte_size * 8); 358 break; 359 360 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break; 361 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break; 362 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break; 363 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break; 364 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break; 365 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break; 366 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break; 367 } 368 369 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL) 370 { 371 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); 372 373 if (translation_unit_is_objc) 374 { 375 if (type_name_cstr != NULL) 376 { 377 static ConstString g_objc_type_name_id("id"); 378 static ConstString g_objc_type_name_Class("Class"); 379 static ConstString g_objc_type_name_selector("SEL"); 380 381 if (type_name_const_str == g_objc_type_name_id) 382 { 383 if (log) 384 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 385 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.", 386 die.GetOffset(), 387 die.GetTagAsCString(), 388 die.GetName()); 389 clang_type = m_ast.GetBasicType(eBasicTypeObjCID); 390 encoding_data_type = Type::eEncodingIsUID; 391 encoding_uid.Clear(); 392 resolve_state = Type::eResolveStateFull; 393 394 } 395 else if (type_name_const_str == g_objc_type_name_Class) 396 { 397 if (log) 398 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 399 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.", 400 die.GetOffset(), 401 die.GetTagAsCString(), 402 die.GetName()); 403 clang_type = m_ast.GetBasicType(eBasicTypeObjCClass); 404 encoding_data_type = Type::eEncodingIsUID; 405 encoding_uid.Clear(); 406 resolve_state = Type::eResolveStateFull; 407 } 408 else if (type_name_const_str == g_objc_type_name_selector) 409 { 410 if (log) 411 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 412 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.", 413 die.GetOffset(), 414 die.GetTagAsCString(), 415 die.GetName()); 416 clang_type = m_ast.GetBasicType(eBasicTypeObjCSel); 417 encoding_data_type = Type::eEncodingIsUID; 418 encoding_uid.Clear(); 419 resolve_state = Type::eResolveStateFull; 420 } 421 } 422 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid.IsValid()) 423 { 424 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id". 425 426 const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid)); 427 428 if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type) 429 { 430 if (const char *struct_name = encoding_die.GetName()) 431 { 432 if (!strcmp(struct_name, "objc_object")) 433 { 434 if (log) 435 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 436 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.", 437 die.GetOffset(), 438 die.GetTagAsCString(), 439 die.GetName()); 440 clang_type = m_ast.GetBasicType(eBasicTypeObjCID); 441 encoding_data_type = Type::eEncodingIsUID; 442 encoding_uid.Clear(); 443 resolve_state = Type::eResolveStateFull; 444 } 445 } 446 } 447 } 448 } 449 } 450 451 type_sp.reset( new Type (die.GetID(), 452 dwarf, 453 type_name_const_str, 454 byte_size, 455 NULL, 456 DIERef(encoding_uid).GetUID(dwarf), 457 encoding_data_type, 458 &decl, 459 clang_type, 460 resolve_state)); 461 462 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 463 464 // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false); 465 // if (encoding_type != NULL) 466 // { 467 // if (encoding_type != DIE_IS_BEING_PARSED) 468 // type_sp->SetEncodingType(encoding_type); 469 // else 470 // m_indirect_fixups.push_back(type_sp.get()); 471 // } 472 } 473 break; 474 475 case DW_TAG_structure_type: 476 case DW_TAG_union_type: 477 case DW_TAG_class_type: 478 { 479 // Set a bit that lets us know that we are currently parsing this 480 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; 481 bool byte_size_valid = false; 482 483 LanguageType class_language = eLanguageTypeUnknown; 484 bool is_complete_objc_class = false; 485 //bool struct_is_class = false; 486 const size_t num_attributes = die.GetAttributes (attributes); 487 if (num_attributes > 0) 488 { 489 uint32_t i; 490 for (i=0; i<num_attributes; ++i) 491 { 492 attr = attributes.AttributeAtIndex(i); 493 if (attributes.ExtractFormValueAtIndex(i, form_value)) 494 { 495 switch (attr) 496 { 497 case DW_AT_decl_file: 498 if (die.GetCU()->DW_AT_decl_file_attributes_are_invalid()) 499 { 500 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always 501 // point to the compile unit file, so we clear this invalid value 502 // so that we can still unique types efficiently. 503 decl.SetFile(FileSpec ("<invalid>", false)); 504 } 505 else 506 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); 507 break; 508 509 case DW_AT_decl_line: 510 decl.SetLine(form_value.Unsigned()); 511 break; 512 513 case DW_AT_decl_column: 514 decl.SetColumn(form_value.Unsigned()); 515 break; 516 517 case DW_AT_name: 518 type_name_cstr = form_value.AsCString(); 519 type_name_const_str.SetCString(type_name_cstr); 520 break; 521 522 case DW_AT_byte_size: 523 byte_size = form_value.Unsigned(); 524 byte_size_valid = true; 525 break; 526 527 case DW_AT_accessibility: 528 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 529 break; 530 531 case DW_AT_declaration: 532 is_forward_declaration = form_value.Boolean(); 533 break; 534 535 case DW_AT_APPLE_runtime_class: 536 class_language = (LanguageType)form_value.Signed(); 537 break; 538 539 case DW_AT_APPLE_objc_complete_type: 540 is_complete_objc_class = form_value.Signed(); 541 break; 542 543 case DW_AT_allocated: 544 case DW_AT_associated: 545 case DW_AT_data_location: 546 case DW_AT_description: 547 case DW_AT_start_scope: 548 case DW_AT_visibility: 549 default: 550 case DW_AT_sibling: 551 break; 552 } 553 } 554 } 555 } 556 557 // UniqueDWARFASTType is large, so don't create a local variables on the 558 // stack, put it on the heap. This function is often called recursively 559 // and clang isn't good and sharing the stack space for variables in different blocks. 560 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType()); 561 562 ConstString unique_typename(type_name_const_str); 563 Declaration unique_decl(decl); 564 565 if (type_name_const_str) 566 { 567 LanguageType die_language = die.GetLanguage(); 568 if (Language::LanguageIsCPlusPlus(die_language)) 569 { 570 // For C++, we rely solely upon the one definition rule that says only 571 // one thing can exist at a given decl context. We ignore the file and 572 // line that things are declared on. 573 std::string qualified_name; 574 if (die.GetQualifiedName(qualified_name)) 575 unique_typename = ConstString(qualified_name); 576 unique_decl.Clear(); 577 } 578 579 if (dwarf->GetUniqueDWARFASTTypeMap().Find(unique_typename, die, unique_decl, 580 byte_size_valid ? byte_size : -1, 581 *unique_ast_entry_ap)) 582 { 583 type_sp = unique_ast_entry_ap->m_type_sp; 584 if (type_sp) 585 { 586 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 587 return type_sp; 588 } 589 } 590 } 591 592 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); 593 594 int tag_decl_kind = -1; 595 AccessType default_accessibility = eAccessNone; 596 if (tag == DW_TAG_structure_type) 597 { 598 tag_decl_kind = clang::TTK_Struct; 599 default_accessibility = eAccessPublic; 600 } 601 else if (tag == DW_TAG_union_type) 602 { 603 tag_decl_kind = clang::TTK_Union; 604 default_accessibility = eAccessPublic; 605 } 606 else if (tag == DW_TAG_class_type) 607 { 608 tag_decl_kind = clang::TTK_Class; 609 default_accessibility = eAccessPrivate; 610 } 611 612 if (byte_size_valid && byte_size == 0 && type_name_cstr && 613 die.HasChildren() == false && 614 sc.comp_unit->GetLanguage() == eLanguageTypeObjC) 615 { 616 // Work around an issue with clang at the moment where 617 // forward declarations for objective C classes are emitted 618 // as: 619 // DW_TAG_structure_type [2] 620 // DW_AT_name( "ForwardObjcClass" ) 621 // DW_AT_byte_size( 0x00 ) 622 // DW_AT_decl_file( "..." ) 623 // DW_AT_decl_line( 1 ) 624 // 625 // Note that there is no DW_AT_declaration and there are 626 // no children, and the byte size is zero. 627 is_forward_declaration = true; 628 } 629 630 if (class_language == eLanguageTypeObjC || 631 class_language == eLanguageTypeObjC_plus_plus) 632 { 633 if (!is_complete_objc_class && die.Supports_DW_AT_APPLE_objc_complete_type()) 634 { 635 // We have a valid eSymbolTypeObjCClass class symbol whose 636 // name matches the current objective C class that we 637 // are trying to find and this DIE isn't the complete 638 // definition (we checked is_complete_objc_class above and 639 // know it is false), so the real definition is in here somewhere 640 type_sp = dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); 641 642 if (!type_sp) 643 { 644 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); 645 if (debug_map_symfile) 646 { 647 // We weren't able to find a full declaration in 648 // this DWARF, see if we have a declaration anywhere 649 // else... 650 type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true); 651 } 652 } 653 654 if (type_sp) 655 { 656 if (log) 657 { 658 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 659 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64, 660 static_cast<void*>(this), 661 die.GetOffset(), 662 DW_TAG_value_to_name(tag), 663 type_name_cstr, 664 type_sp->GetID()); 665 } 666 667 // We found a real definition for this type elsewhere 668 // so lets use it and cache the fact that we found 669 // a complete type for this die 670 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 671 return type_sp; 672 } 673 } 674 } 675 676 677 if (is_forward_declaration) 678 { 679 // We have a forward declaration to a type and we need 680 // to try and find a full declaration. We look in the 681 // current type index just in case we have a forward 682 // declaration followed by an actual declarations in the 683 // DWARF. If this fails, we need to look elsewhere... 684 if (log) 685 { 686 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 687 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type", 688 static_cast<void*>(this), 689 die.GetOffset(), 690 DW_TAG_value_to_name(tag), 691 type_name_cstr); 692 } 693 694 // See if the type comes from a DWO module and if so, track down that type. 695 type_sp = ParseTypeFromDWO(die, log); 696 if (type_sp) 697 return type_sp; 698 699 DWARFDeclContext die_decl_ctx; 700 die.GetDWARFDeclContext(die_decl_ctx); 701 702 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str); 703 type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 704 705 if (!type_sp) 706 { 707 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); 708 if (debug_map_symfile) 709 { 710 // We weren't able to find a full declaration in 711 // this DWARF, see if we have a declaration anywhere 712 // else... 713 type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 714 } 715 } 716 717 if (type_sp) 718 { 719 if (log) 720 { 721 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 722 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, 723 static_cast<void*>(this), 724 die.GetOffset(), 725 DW_TAG_value_to_name(tag), 726 type_name_cstr, 727 type_sp->GetID()); 728 } 729 730 // We found a real definition for this type elsewhere 731 // so lets use it and cache the fact that we found 732 // a complete type for this die 733 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 734 clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE( 735 dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID(), dwarf))); 736 if (defn_decl_ctx) 737 LinkDeclContextToDIE(defn_decl_ctx, die); 738 return type_sp; 739 } 740 } 741 assert (tag_decl_kind != -1); 742 bool clang_type_was_created = false; 743 clang_type.SetCompilerType(&m_ast, dwarf->GetForwardDeclDieToClangType().lookup (die.GetDIE())); 744 if (!clang_type) 745 { 746 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (die, nullptr); 747 if (accessibility == eAccessNone && decl_ctx) 748 { 749 // Check the decl context that contains this class/struct/union. 750 // If it is a class we must give it an accessibility. 751 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind(); 752 if (DeclKindIsCXXClass (containing_decl_kind)) 753 accessibility = default_accessibility; 754 } 755 756 ClangASTMetadata metadata; 757 metadata.SetUserID(die.GetID()); 758 metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual (die)); 759 760 if (type_name_cstr && strchr (type_name_cstr, '<')) 761 { 762 ClangASTContext::TemplateParameterInfos template_param_infos; 763 if (ParseTemplateParameterInfos (die, template_param_infos)) 764 { 765 clang::ClassTemplateDecl *class_template_decl = m_ast.ParseClassTemplateDecl (decl_ctx, 766 accessibility, 767 type_name_cstr, 768 tag_decl_kind, 769 template_param_infos); 770 771 clang::ClassTemplateSpecializationDecl *class_specialization_decl = m_ast.CreateClassTemplateSpecializationDecl (decl_ctx, 772 class_template_decl, 773 tag_decl_kind, 774 template_param_infos); 775 clang_type = m_ast.CreateClassTemplateSpecializationType (class_specialization_decl); 776 clang_type_was_created = true; 777 778 m_ast.SetMetadata (class_template_decl, metadata); 779 m_ast.SetMetadata (class_specialization_decl, metadata); 780 } 781 } 782 783 if (!clang_type_was_created) 784 { 785 clang_type_was_created = true; 786 clang_type = m_ast.CreateRecordType (decl_ctx, 787 accessibility, 788 type_name_cstr, 789 tag_decl_kind, 790 class_language, 791 &metadata); 792 } 793 } 794 795 // Store a forward declaration to this class type in case any 796 // parameters in any class methods need it for the clang 797 // types for function prototypes. 798 LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die); 799 type_sp.reset (new Type (die.GetID(), 800 dwarf, 801 type_name_const_str, 802 byte_size, 803 NULL, 804 LLDB_INVALID_UID, 805 Type::eEncodingIsUID, 806 &decl, 807 clang_type, 808 Type::eResolveStateForward)); 809 810 type_sp->SetIsCompleteObjCClass(is_complete_objc_class); 811 812 813 // Add our type to the unique type map so we don't 814 // end up creating many copies of the same type over 815 // and over in the ASTContext for our module 816 unique_ast_entry_ap->m_type_sp = type_sp; 817 unique_ast_entry_ap->m_die = die; 818 unique_ast_entry_ap->m_declaration = unique_decl; 819 unique_ast_entry_ap->m_byte_size = byte_size; 820 dwarf->GetUniqueDWARFASTTypeMap().Insert (unique_typename, 821 *unique_ast_entry_ap); 822 823 if (is_forward_declaration && die.HasChildren()) 824 { 825 // Check to see if the DIE actually has a definition, some version of GCC will 826 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram, 827 // members, or inheritance, so we can't trust it 828 DWARFDIE child_die = die.GetFirstChild(); 829 while (child_die) 830 { 831 switch (child_die.Tag()) 832 { 833 case DW_TAG_inheritance: 834 case DW_TAG_subprogram: 835 case DW_TAG_member: 836 case DW_TAG_APPLE_property: 837 case DW_TAG_class_type: 838 case DW_TAG_structure_type: 839 case DW_TAG_enumeration_type: 840 case DW_TAG_typedef: 841 case DW_TAG_union_type: 842 child_die.Clear(); 843 is_forward_declaration = false; 844 break; 845 default: 846 child_die = child_die.GetSibling(); 847 break; 848 } 849 } 850 } 851 852 if (!is_forward_declaration) 853 { 854 // Always start the definition for a class type so that 855 // if the class has child classes or types that require 856 // the class to be created for use as their decl contexts 857 // the class will be ready to accept these child definitions. 858 if (die.HasChildren() == false) 859 { 860 // No children for this struct/union/class, lets finish it 861 ClangASTContext::StartTagDeclarationDefinition (clang_type); 862 ClangASTContext::CompleteTagDeclarationDefinition (clang_type); 863 864 if (tag == DW_TAG_structure_type) // this only applies in C 865 { 866 clang::RecordDecl *record_decl = ClangASTContext::GetAsRecordDecl(clang_type); 867 868 if (record_decl) 869 { 870 GetClangASTImporter().InsertRecordDecl(record_decl, ClangASTImporter::LayoutInfo()); 871 } 872 } 873 } 874 else if (clang_type_was_created) 875 { 876 // Start the definition if the class is not objective C since 877 // the underlying decls respond to isCompleteDefinition(). Objective 878 // C decls don't respond to isCompleteDefinition() so we can't 879 // start the declaration definition right away. For C++ class/union/structs 880 // we want to start the definition in case the class is needed as the 881 // declaration context for a contained class or type without the need 882 // to complete that type.. 883 884 if (class_language != eLanguageTypeObjC && 885 class_language != eLanguageTypeObjC_plus_plus) 886 ClangASTContext::StartTagDeclarationDefinition (clang_type); 887 888 // Leave this as a forward declaration until we need 889 // to know the details of the type. lldb_private::Type 890 // will automatically call the SymbolFile virtual function 891 // "SymbolFileDWARF::CompleteType(Type *)" 892 // When the definition needs to be defined. 893 assert(!dwarf->GetForwardDeclClangTypeToDie().count( 894 ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType()) && 895 "Type already in the forward declaration map!"); 896 // Can't assume m_ast.GetSymbolFile() is actually a SymbolFileDWARF, it can be a 897 // SymbolFileDWARFDebugMap for Apple binaries. 898 dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = clang_type.GetOpaqueQualType(); 899 dwarf->GetForwardDeclClangTypeToDie()[ClangUtil::RemoveFastQualifiers(clang_type) 900 .GetOpaqueQualType()] = die.GetDIERef(); 901 m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), true); 902 } 903 } 904 } 905 break; 906 907 case DW_TAG_enumeration_type: 908 { 909 // Set a bit that lets us know that we are currently parsing this 910 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; 911 912 DWARFFormValue encoding_form; 913 914 const size_t num_attributes = die.GetAttributes (attributes); 915 if (num_attributes > 0) 916 { 917 uint32_t i; 918 919 for (i=0; i<num_attributes; ++i) 920 { 921 attr = attributes.AttributeAtIndex(i); 922 if (attributes.ExtractFormValueAtIndex(i, form_value)) 923 { 924 switch (attr) 925 { 926 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 927 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 928 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 929 case DW_AT_name: 930 type_name_cstr = form_value.AsCString(); 931 type_name_const_str.SetCString(type_name_cstr); 932 break; 933 case DW_AT_type: encoding_form = form_value; break; 934 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 935 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 936 case DW_AT_declaration: is_forward_declaration = form_value.Boolean(); break; 937 case DW_AT_allocated: 938 case DW_AT_associated: 939 case DW_AT_bit_stride: 940 case DW_AT_byte_stride: 941 case DW_AT_data_location: 942 case DW_AT_description: 943 case DW_AT_start_scope: 944 case DW_AT_visibility: 945 case DW_AT_specification: 946 case DW_AT_abstract_origin: 947 case DW_AT_sibling: 948 break; 949 } 950 } 951 } 952 953 if (is_forward_declaration) 954 { 955 type_sp = ParseTypeFromDWO(die, log); 956 if (type_sp) 957 return type_sp; 958 959 DWARFDeclContext die_decl_ctx; 960 die.GetDWARFDeclContext(die_decl_ctx); 961 962 type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 963 964 if (!type_sp) 965 { 966 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); 967 if (debug_map_symfile) 968 { 969 // We weren't able to find a full declaration in 970 // this DWARF, see if we have a declaration anywhere 971 // else... 972 type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx); 973 } 974 } 975 976 if (type_sp) 977 { 978 if (log) 979 { 980 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 981 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64, 982 static_cast<void*>(this), 983 die.GetOffset(), 984 DW_TAG_value_to_name(tag), 985 type_name_cstr, 986 type_sp->GetID()); 987 } 988 989 // We found a real definition for this type elsewhere 990 // so lets use it and cache the fact that we found 991 // a complete type for this die 992 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 993 clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID(), dwarf))); 994 if (defn_decl_ctx) 995 LinkDeclContextToDIE(defn_decl_ctx, die); 996 return type_sp; 997 } 998 999 } 1000 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); 1001 1002 CompilerType enumerator_clang_type; 1003 clang_type.SetCompilerType (&m_ast, dwarf->GetForwardDeclDieToClangType().lookup (die.GetDIE())); 1004 if (!clang_type) 1005 { 1006 if (encoding_form.IsValid()) 1007 { 1008 Type *enumerator_type = dwarf->ResolveTypeUID(DIERef(encoding_form)); 1009 if (enumerator_type) 1010 enumerator_clang_type = enumerator_type->GetFullCompilerType (); 1011 } 1012 1013 if (!enumerator_clang_type) 1014 enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL, 1015 DW_ATE_signed, 1016 byte_size * 8); 1017 1018 clang_type = m_ast.CreateEnumerationType (type_name_cstr, 1019 GetClangDeclContextContainingDIE (die, nullptr), 1020 decl, 1021 enumerator_clang_type); 1022 } 1023 else 1024 { 1025 enumerator_clang_type = m_ast.GetEnumerationIntegerType (clang_type.GetOpaqueQualType()); 1026 } 1027 1028 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die); 1029 1030 type_sp.reset( new Type (die.GetID(), 1031 dwarf, 1032 type_name_const_str, 1033 byte_size, 1034 NULL, 1035 DIERef(encoding_form).GetUID(dwarf), 1036 Type::eEncodingIsUID, 1037 &decl, 1038 clang_type, 1039 Type::eResolveStateForward)); 1040 1041 ClangASTContext::StartTagDeclarationDefinition (clang_type); 1042 if (die.HasChildren()) 1043 { 1044 SymbolContext cu_sc(die.GetLLDBCompileUnit()); 1045 bool is_signed = false; 1046 enumerator_clang_type.IsIntegerType(is_signed); 1047 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), die); 1048 } 1049 ClangASTContext::CompleteTagDeclarationDefinition (clang_type); 1050 } 1051 } 1052 break; 1053 1054 case DW_TAG_inlined_subroutine: 1055 case DW_TAG_subprogram: 1056 case DW_TAG_subroutine_type: 1057 { 1058 // Set a bit that lets us know that we are currently parsing this 1059 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; 1060 1061 DWARFFormValue type_die_form; 1062 bool is_variadic = false; 1063 bool is_inline = false; 1064 bool is_static = false; 1065 bool is_virtual = false; 1066 bool is_explicit = false; 1067 bool is_artificial = false; 1068 bool has_template_params = false; 1069 DWARFFormValue specification_die_form; 1070 DWARFFormValue abstract_origin_die_form; 1071 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET; 1072 1073 unsigned type_quals = 0; 1074 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern 1075 1076 1077 const size_t num_attributes = die.GetAttributes (attributes); 1078 if (num_attributes > 0) 1079 { 1080 uint32_t i; 1081 for (i=0; i<num_attributes; ++i) 1082 { 1083 attr = attributes.AttributeAtIndex(i); 1084 if (attributes.ExtractFormValueAtIndex(i, form_value)) 1085 { 1086 switch (attr) 1087 { 1088 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 1089 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 1090 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 1091 case DW_AT_name: 1092 type_name_cstr = form_value.AsCString(); 1093 type_name_const_str.SetCString(type_name_cstr); 1094 break; 1095 1096 case DW_AT_linkage_name: 1097 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&dwarf->get_debug_str_data()); break; 1098 case DW_AT_type: type_die_form = form_value; break; 1099 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 1100 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; 1101 case DW_AT_inline: is_inline = form_value.Boolean(); break; 1102 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break; 1103 case DW_AT_explicit: is_explicit = form_value.Boolean(); break; 1104 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 1105 1106 1107 case DW_AT_external: 1108 if (form_value.Unsigned()) 1109 { 1110 if (storage == clang::SC_None) 1111 storage = clang::SC_Extern; 1112 else 1113 storage = clang::SC_PrivateExtern; 1114 } 1115 break; 1116 1117 case DW_AT_specification: 1118 specification_die_form = form_value; 1119 break; 1120 1121 case DW_AT_abstract_origin: 1122 abstract_origin_die_form = form_value; 1123 break; 1124 1125 case DW_AT_object_pointer: 1126 object_pointer_die_offset = form_value.Reference(); 1127 break; 1128 1129 case DW_AT_allocated: 1130 case DW_AT_associated: 1131 case DW_AT_address_class: 1132 case DW_AT_calling_convention: 1133 case DW_AT_data_location: 1134 case DW_AT_elemental: 1135 case DW_AT_entry_pc: 1136 case DW_AT_frame_base: 1137 case DW_AT_high_pc: 1138 case DW_AT_low_pc: 1139 case DW_AT_prototyped: 1140 case DW_AT_pure: 1141 case DW_AT_ranges: 1142 case DW_AT_recursive: 1143 case DW_AT_return_addr: 1144 case DW_AT_segment: 1145 case DW_AT_start_scope: 1146 case DW_AT_static_link: 1147 case DW_AT_trampoline: 1148 case DW_AT_visibility: 1149 case DW_AT_vtable_elem_location: 1150 case DW_AT_description: 1151 case DW_AT_sibling: 1152 break; 1153 } 1154 } 1155 } 1156 } 1157 1158 std::string object_pointer_name; 1159 if (object_pointer_die_offset != DW_INVALID_OFFSET) 1160 { 1161 DWARFDIE object_pointer_die = die.GetDIE (object_pointer_die_offset); 1162 if (object_pointer_die) 1163 { 1164 const char *object_pointer_name_cstr = object_pointer_die.GetName(); 1165 if (object_pointer_name_cstr) 1166 object_pointer_name = object_pointer_name_cstr; 1167 } 1168 } 1169 1170 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); 1171 1172 CompilerType return_clang_type; 1173 Type *func_type = NULL; 1174 1175 if (type_die_form.IsValid()) 1176 func_type = dwarf->ResolveTypeUID(DIERef(type_die_form)); 1177 1178 if (func_type) 1179 return_clang_type = func_type->GetForwardCompilerType (); 1180 else 1181 return_clang_type = m_ast.GetBasicType(eBasicTypeVoid); 1182 1183 1184 std::vector<CompilerType> function_param_types; 1185 std::vector<clang::ParmVarDecl*> function_param_decls; 1186 1187 // Parse the function children for the parameters 1188 1189 DWARFDIE decl_ctx_die; 1190 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (die, &decl_ctx_die); 1191 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); 1192 1193 bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind); 1194 // Start off static. This will be set to false in ParseChildParameters(...) 1195 // if we find a "this" parameters as the first parameter 1196 if (is_cxx_method) 1197 { 1198 is_static = true; 1199 } 1200 1201 if (die.HasChildren()) 1202 { 1203 bool skip_artificial = true; 1204 ParseChildParameters (sc, 1205 containing_decl_ctx, 1206 die, 1207 skip_artificial, 1208 is_static, 1209 is_variadic, 1210 has_template_params, 1211 function_param_types, 1212 function_param_decls, 1213 type_quals); 1214 } 1215 1216 bool ignore_containing_context = false; 1217 // Check for templatized class member functions. If we had any DW_TAG_template_type_parameter 1218 // or DW_TAG_template_value_parameter the DW_TAG_subprogram DIE, then we can't let this become 1219 // a method in a class. Why? Because templatized functions are only emitted if one of the 1220 // templatized methods is used in the current compile unit and we will end up with classes 1221 // that may or may not include these member functions and this means one class won't match another 1222 // class definition and it affects our ability to use a class in the clang expression parser. So 1223 // for the greater good, we currently must not allow any template member functions in a class definition. 1224 if (is_cxx_method && has_template_params) 1225 { 1226 ignore_containing_context = true; 1227 is_cxx_method = false; 1228 } 1229 1230 // clang_type will get the function prototype clang type after this call 1231 clang_type = m_ast.CreateFunctionType (return_clang_type, 1232 function_param_types.data(), 1233 function_param_types.size(), 1234 is_variadic, 1235 type_quals); 1236 1237 1238 if (type_name_cstr) 1239 { 1240 bool type_handled = false; 1241 if (tag == DW_TAG_subprogram || 1242 tag == DW_TAG_inlined_subroutine) 1243 { 1244 ObjCLanguage::MethodName objc_method (type_name_cstr, true); 1245 if (objc_method.IsValid(true)) 1246 { 1247 CompilerType class_opaque_type; 1248 ConstString class_name(objc_method.GetClassName()); 1249 if (class_name) 1250 { 1251 TypeSP complete_objc_class_type_sp (dwarf->FindCompleteObjCDefinitionTypeForDIE (DWARFDIE(), class_name, false)); 1252 1253 if (complete_objc_class_type_sp) 1254 { 1255 CompilerType type_clang_forward_type = complete_objc_class_type_sp->GetForwardCompilerType (); 1256 if (ClangASTContext::IsObjCObjectOrInterfaceType(type_clang_forward_type)) 1257 class_opaque_type = type_clang_forward_type; 1258 } 1259 } 1260 1261 if (class_opaque_type) 1262 { 1263 // If accessibility isn't set to anything valid, assume public for 1264 // now... 1265 if (accessibility == eAccessNone) 1266 accessibility = eAccessPublic; 1267 1268 clang::ObjCMethodDecl *objc_method_decl = m_ast.AddMethodToObjCObjectType (class_opaque_type, 1269 type_name_cstr, 1270 clang_type, 1271 accessibility, 1272 is_artificial); 1273 type_handled = objc_method_decl != NULL; 1274 if (type_handled) 1275 { 1276 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die); 1277 m_ast.SetMetadataAsUserID (objc_method_decl, die.GetID()); 1278 } 1279 else 1280 { 1281 dwarf->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", 1282 die.GetOffset(), 1283 tag, 1284 DW_TAG_value_to_name(tag)); 1285 } 1286 } 1287 } 1288 else if (is_cxx_method) 1289 { 1290 // Look at the parent of this DIE and see if is is 1291 // a class or struct and see if this is actually a 1292 // C++ method 1293 Type *class_type = dwarf->ResolveType (decl_ctx_die); 1294 if (class_type) 1295 { 1296 bool alternate_defn = false; 1297 if (class_type->GetID() != decl_ctx_die.GetID() || decl_ctx_die.GetContainingDWOModuleDIE()) 1298 { 1299 alternate_defn = true; 1300 1301 // We uniqued the parent class of this function to another class 1302 // so we now need to associate all dies under "decl_ctx_die" to 1303 // DIEs in the DIE for "class_type"... 1304 SymbolFileDWARF *class_symfile = NULL; 1305 DWARFDIE class_type_die; 1306 1307 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile(); 1308 if (debug_map_symfile) 1309 { 1310 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID())); 1311 class_type_die = class_symfile->DebugInfo()->GetDIE (DIERef(class_type->GetID(), dwarf)); 1312 } 1313 else 1314 { 1315 class_symfile = dwarf; 1316 class_type_die = dwarf->DebugInfo()->GetDIE (DIERef(class_type->GetID(), dwarf)); 1317 } 1318 if (class_type_die) 1319 { 1320 DWARFDIECollection failures; 1321 1322 CopyUniqueClassMethodTypes (decl_ctx_die, 1323 class_type_die, 1324 class_type, 1325 failures); 1326 1327 // FIXME do something with these failures that's smarter than 1328 // just dropping them on the ground. Unfortunately classes don't 1329 // like having stuff added to them after their definitions are 1330 // complete... 1331 1332 type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; 1333 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) 1334 { 1335 type_sp = type_ptr->shared_from_this(); 1336 break; 1337 } 1338 } 1339 } 1340 1341 if (specification_die_form.IsValid()) 1342 { 1343 // We have a specification which we are going to base our function 1344 // prototype off of, so we need this type to be completed so that the 1345 // m_die_to_decl_ctx for the method in the specification has a valid 1346 // clang decl context. 1347 class_type->GetForwardCompilerType (); 1348 // If we have a specification, then the function type should have been 1349 // made with the specification and not with this die. 1350 DWARFDIE spec_die = dwarf->DebugInfo()->GetDIE(DIERef(specification_die_form)); 1351 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (spec_die); 1352 if (spec_clang_decl_ctx) 1353 { 1354 LinkDeclContextToDIE(spec_clang_decl_ctx, die); 1355 } 1356 else 1357 { 1358 dwarf->GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8" PRIx64 ") has no decl\n", 1359 die.GetID(), 1360 specification_die_form.Reference()); 1361 } 1362 type_handled = true; 1363 } 1364 else if (abstract_origin_die_form.IsValid()) 1365 { 1366 // We have a specification which we are going to base our function 1367 // prototype off of, so we need this type to be completed so that the 1368 // m_die_to_decl_ctx for the method in the abstract origin has a valid 1369 // clang decl context. 1370 class_type->GetForwardCompilerType (); 1371 1372 DWARFDIE abs_die = dwarf->DebugInfo()->GetDIE (DIERef(abstract_origin_die_form)); 1373 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (abs_die); 1374 if (abs_clang_decl_ctx) 1375 { 1376 LinkDeclContextToDIE (abs_clang_decl_ctx, die); 1377 } 1378 else 1379 { 1380 dwarf->GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8" PRIx64 ") has no decl\n", 1381 die.GetID(), 1382 abstract_origin_die_form.Reference()); 1383 } 1384 type_handled = true; 1385 } 1386 else 1387 { 1388 CompilerType class_opaque_type = class_type->GetForwardCompilerType (); 1389 if (ClangASTContext::IsCXXClassType(class_opaque_type)) 1390 { 1391 if (class_opaque_type.IsBeingDefined () || alternate_defn) 1392 { 1393 if (!is_static && !die.HasChildren()) 1394 { 1395 // We have a C++ member function with no children (this pointer!) 1396 // and clang will get mad if we try and make a function that isn't 1397 // well formed in the DWARF, so we will just skip it... 1398 type_handled = true; 1399 } 1400 else 1401 { 1402 bool add_method = true; 1403 if (alternate_defn) 1404 { 1405 // If an alternate definition for the class exists, then add the method only if an 1406 // equivalent is not already present. 1407 clang::CXXRecordDecl *record_decl = m_ast.GetAsCXXRecordDecl(class_opaque_type.GetOpaqueQualType()); 1408 if (record_decl) 1409 { 1410 for (auto method_iter = record_decl->method_begin(); 1411 method_iter != record_decl->method_end(); 1412 method_iter++) 1413 { 1414 clang::CXXMethodDecl *method_decl = *method_iter; 1415 if (method_decl->getNameInfo().getAsString() == std::string(type_name_cstr)) 1416 { 1417 if (method_decl->getType() == 1418 ClangUtil::GetQualType(clang_type)) 1419 { 1420 add_method = false; 1421 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(method_decl), die); 1422 type_handled = true; 1423 1424 break; 1425 } 1426 } 1427 } 1428 } 1429 } 1430 1431 if (add_method) 1432 { 1433 // REMOVE THE CRASH DESCRIPTION BELOW 1434 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s", 1435 type_name_cstr, 1436 class_type->GetName().GetCString(), 1437 die.GetID(), 1438 dwarf->GetObjectFile()->GetFileSpec().GetPath().c_str()); 1439 1440 const bool is_attr_used = false; 1441 // Neither GCC 4.2 nor clang++ currently set a valid accessibility 1442 // in the DWARF for C++ methods... Default to public for now... 1443 if (accessibility == eAccessNone) 1444 accessibility = eAccessPublic; 1445 1446 clang::CXXMethodDecl *cxx_method_decl; 1447 cxx_method_decl = m_ast.AddMethodToCXXRecordType (class_opaque_type.GetOpaqueQualType(), 1448 type_name_cstr, 1449 clang_type, 1450 accessibility, 1451 is_virtual, 1452 is_static, 1453 is_inline, 1454 is_explicit, 1455 is_attr_used, 1456 is_artificial); 1457 1458 type_handled = cxx_method_decl != NULL; 1459 1460 if (type_handled) 1461 { 1462 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die); 1463 1464 Host::SetCrashDescription (NULL); 1465 1466 ClangASTMetadata metadata; 1467 metadata.SetUserID(die.GetID()); 1468 1469 if (!object_pointer_name.empty()) 1470 { 1471 metadata.SetObjectPtrName(object_pointer_name.c_str()); 1472 if (log) 1473 log->Printf ("Setting object pointer name: %s on method object %p.\n", 1474 object_pointer_name.c_str(), 1475 static_cast<void*>(cxx_method_decl)); 1476 } 1477 m_ast.SetMetadata (cxx_method_decl, metadata); 1478 } 1479 else 1480 { 1481 ignore_containing_context = true; 1482 } 1483 } 1484 } 1485 } 1486 else 1487 { 1488 // We were asked to parse the type for a method in a class, yet the 1489 // class hasn't been asked to complete itself through the 1490 // clang::ExternalASTSource protocol, so we need to just have the 1491 // class complete itself and do things the right way, then our 1492 // DIE should then have an entry in the dwarf->GetDIEToType() map. First 1493 // we need to modify the dwarf->GetDIEToType() so it doesn't think we are 1494 // trying to parse this DIE anymore... 1495 dwarf->GetDIEToType()[die.GetDIE()] = NULL; 1496 1497 // Now we get the full type to force our class type to complete itself 1498 // using the clang::ExternalASTSource protocol which will parse all 1499 // base classes and all methods (including the method for this DIE). 1500 class_type->GetFullCompilerType (); 1501 1502 // The type for this DIE should have been filled in the function call above 1503 type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; 1504 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) 1505 { 1506 type_sp = type_ptr->shared_from_this(); 1507 break; 1508 } 1509 1510 // FIXME This is fixing some even uglier behavior but we really need to 1511 // uniq the methods of each class as well as the class itself. 1512 // <rdar://problem/11240464> 1513 type_handled = true; 1514 } 1515 } 1516 } 1517 } 1518 } 1519 } 1520 1521 if (!type_handled) 1522 { 1523 clang::FunctionDecl *function_decl = nullptr; 1524 1525 if (abstract_origin_die_form.IsValid()) 1526 { 1527 DWARFDIE abs_die = dwarf->DebugInfo()->GetDIE (DIERef(abstract_origin_die_form)); 1528 1529 SymbolContext sc; 1530 1531 if (dwarf->ResolveType (abs_die)) 1532 { 1533 function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(GetCachedClangDeclContextForDIE(abs_die)); 1534 1535 if (function_decl) 1536 { 1537 LinkDeclContextToDIE(function_decl, die); 1538 } 1539 } 1540 } 1541 1542 if (!function_decl) 1543 { 1544 // We just have a function that isn't part of a class 1545 function_decl = m_ast.CreateFunctionDeclaration (ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx, 1546 type_name_cstr, 1547 clang_type, 1548 storage, 1549 is_inline); 1550 1551 // if (template_param_infos.GetSize() > 0) 1552 // { 1553 // clang::FunctionTemplateDecl *func_template_decl = CreateFunctionTemplateDecl (containing_decl_ctx, 1554 // function_decl, 1555 // type_name_cstr, 1556 // template_param_infos); 1557 // 1558 // CreateFunctionTemplateSpecializationInfo (function_decl, 1559 // func_template_decl, 1560 // template_param_infos); 1561 // } 1562 // Add the decl to our DIE to decl context map 1563 1564 lldbassert (function_decl); 1565 1566 if (function_decl) 1567 { 1568 LinkDeclContextToDIE(function_decl, die); 1569 1570 if (!function_param_decls.empty()) 1571 m_ast.SetFunctionParameters (function_decl, 1572 &function_param_decls.front(), 1573 function_param_decls.size()); 1574 1575 ClangASTMetadata metadata; 1576 metadata.SetUserID(die.GetID()); 1577 1578 if (!object_pointer_name.empty()) 1579 { 1580 metadata.SetObjectPtrName(object_pointer_name.c_str()); 1581 if (log) 1582 log->Printf ("Setting object pointer name: %s on function object %p.", 1583 object_pointer_name.c_str(), 1584 static_cast<void*>(function_decl)); 1585 } 1586 m_ast.SetMetadata (function_decl, metadata); 1587 } 1588 } 1589 } 1590 } 1591 type_sp.reset( new Type (die.GetID(), 1592 dwarf, 1593 type_name_const_str, 1594 0, 1595 NULL, 1596 LLDB_INVALID_UID, 1597 Type::eEncodingIsUID, 1598 &decl, 1599 clang_type, 1600 Type::eResolveStateFull)); 1601 assert(type_sp.get()); 1602 } 1603 break; 1604 1605 case DW_TAG_array_type: 1606 { 1607 // Set a bit that lets us know that we are currently parsing this 1608 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; 1609 1610 DWARFFormValue type_die_form; 1611 int64_t first_index = 0; 1612 uint32_t byte_stride = 0; 1613 uint32_t bit_stride = 0; 1614 bool is_vector = false; 1615 const size_t num_attributes = die.GetAttributes (attributes); 1616 1617 if (num_attributes > 0) 1618 { 1619 uint32_t i; 1620 for (i=0; i<num_attributes; ++i) 1621 { 1622 attr = attributes.AttributeAtIndex(i); 1623 if (attributes.ExtractFormValueAtIndex(i, form_value)) 1624 { 1625 switch (attr) 1626 { 1627 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 1628 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 1629 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 1630 case DW_AT_name: 1631 type_name_cstr = form_value.AsCString(); 1632 type_name_const_str.SetCString(type_name_cstr); 1633 break; 1634 1635 case DW_AT_type: type_die_form = form_value; break; 1636 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break; 1637 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break; 1638 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break; 1639 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break; 1640 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; 1641 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break; 1642 case DW_AT_allocated: 1643 case DW_AT_associated: 1644 case DW_AT_data_location: 1645 case DW_AT_description: 1646 case DW_AT_ordering: 1647 case DW_AT_start_scope: 1648 case DW_AT_visibility: 1649 case DW_AT_specification: 1650 case DW_AT_abstract_origin: 1651 case DW_AT_sibling: 1652 break; 1653 } 1654 } 1655 } 1656 1657 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); 1658 1659 Type *element_type = dwarf->ResolveTypeUID(DIERef(type_die_form)); 1660 1661 if (element_type) 1662 { 1663 std::vector<uint64_t> element_orders; 1664 ParseChildArrayInfo(sc, die, first_index, element_orders, byte_stride, bit_stride); 1665 if (byte_stride == 0 && bit_stride == 0) 1666 byte_stride = element_type->GetByteSize(); 1667 CompilerType array_element_type = element_type->GetForwardCompilerType (); 1668 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; 1669 if (element_orders.size() > 0) 1670 { 1671 uint64_t num_elements = 0; 1672 std::vector<uint64_t>::const_reverse_iterator pos; 1673 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend(); 1674 for (pos = element_orders.rbegin(); pos != end; ++pos) 1675 { 1676 num_elements = *pos; 1677 clang_type = m_ast.CreateArrayType (array_element_type, 1678 num_elements, 1679 is_vector); 1680 array_element_type = clang_type; 1681 array_element_bit_stride = num_elements ? 1682 array_element_bit_stride * num_elements : 1683 array_element_bit_stride; 1684 } 1685 } 1686 else 1687 { 1688 clang_type = m_ast.CreateArrayType (array_element_type, 0, is_vector); 1689 } 1690 ConstString empty_name; 1691 type_sp.reset( new Type (die.GetID(), 1692 dwarf, 1693 empty_name, 1694 array_element_bit_stride / 8, 1695 NULL, 1696 DIERef(type_die_form).GetUID(dwarf), 1697 Type::eEncodingIsUID, 1698 &decl, 1699 clang_type, 1700 Type::eResolveStateFull)); 1701 type_sp->SetEncodingType (element_type); 1702 } 1703 } 1704 } 1705 break; 1706 1707 case DW_TAG_ptr_to_member_type: 1708 { 1709 DWARFFormValue type_die_form; 1710 DWARFFormValue containing_type_die_form; 1711 1712 const size_t num_attributes = die.GetAttributes (attributes); 1713 1714 if (num_attributes > 0) { 1715 uint32_t i; 1716 for (i=0; i<num_attributes; ++i) 1717 { 1718 attr = attributes.AttributeAtIndex(i); 1719 if (attributes.ExtractFormValueAtIndex(i, form_value)) 1720 { 1721 switch (attr) 1722 { 1723 case DW_AT_type: 1724 type_die_form = form_value; break; 1725 case DW_AT_containing_type: 1726 containing_type_die_form = form_value; break; 1727 } 1728 } 1729 } 1730 1731 Type *pointee_type = dwarf->ResolveTypeUID(DIERef(type_die_form)); 1732 Type *class_type = dwarf->ResolveTypeUID(DIERef(containing_type_die_form)); 1733 1734 CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType (); 1735 CompilerType class_clang_type = class_type->GetLayoutCompilerType (); 1736 1737 clang_type = ClangASTContext::CreateMemberPointerType(class_clang_type, pointee_clang_type); 1738 1739 byte_size = clang_type.GetByteSize(nullptr); 1740 1741 type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, byte_size, NULL, 1742 LLDB_INVALID_UID, Type::eEncodingIsUID, NULL, clang_type, 1743 Type::eResolveStateForward)); 1744 } 1745 1746 break; 1747 } 1748 default: 1749 dwarf->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message", 1750 die.GetOffset(), 1751 tag, 1752 DW_TAG_value_to_name(tag)); 1753 break; 1754 } 1755 1756 if (type_sp.get()) 1757 { 1758 DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE(die); 1759 dw_tag_t sc_parent_tag = sc_parent_die.Tag(); 1760 1761 SymbolContextScope * symbol_context_scope = NULL; 1762 if (sc_parent_tag == DW_TAG_compile_unit) 1763 { 1764 symbol_context_scope = sc.comp_unit; 1765 } 1766 else if (sc.function != NULL && sc_parent_die) 1767 { 1768 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); 1769 if (symbol_context_scope == NULL) 1770 symbol_context_scope = sc.function; 1771 } 1772 1773 if (symbol_context_scope != NULL) 1774 { 1775 type_sp->SetSymbolContextScope(symbol_context_scope); 1776 } 1777 1778 // We are ready to put this type into the uniqued list up at the module level 1779 type_list->Insert (type_sp); 1780 1781 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); 1782 } 1783 } 1784 else if (type_ptr != DIE_IS_BEING_PARSED) 1785 { 1786 type_sp = type_ptr->shared_from_this(); 1787 } 1788 } 1789 return type_sp; 1790 } 1791 1792 // DWARF parsing functions 1793 1794 class DWARFASTParserClang::DelayedAddObjCClassProperty 1795 { 1796 public: 1797 DelayedAddObjCClassProperty(const CompilerType &class_opaque_type, 1798 const char *property_name, 1799 const CompilerType &property_opaque_type, // The property type is only required if you don't have an ivar decl 1800 clang::ObjCIvarDecl *ivar_decl, 1801 const char *property_setter_name, 1802 const char *property_getter_name, 1803 uint32_t property_attributes, 1804 const ClangASTMetadata *metadata) : 1805 m_class_opaque_type (class_opaque_type), 1806 m_property_name (property_name), 1807 m_property_opaque_type (property_opaque_type), 1808 m_ivar_decl (ivar_decl), 1809 m_property_setter_name (property_setter_name), 1810 m_property_getter_name (property_getter_name), 1811 m_property_attributes (property_attributes) 1812 { 1813 if (metadata != NULL) 1814 { 1815 m_metadata_ap.reset(new ClangASTMetadata()); 1816 *m_metadata_ap = *metadata; 1817 } 1818 } 1819 1820 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs) 1821 { 1822 *this = rhs; 1823 } 1824 1825 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs) 1826 { 1827 m_class_opaque_type = rhs.m_class_opaque_type; 1828 m_property_name = rhs.m_property_name; 1829 m_property_opaque_type = rhs.m_property_opaque_type; 1830 m_ivar_decl = rhs.m_ivar_decl; 1831 m_property_setter_name = rhs.m_property_setter_name; 1832 m_property_getter_name = rhs.m_property_getter_name; 1833 m_property_attributes = rhs.m_property_attributes; 1834 1835 if (rhs.m_metadata_ap.get()) 1836 { 1837 m_metadata_ap.reset (new ClangASTMetadata()); 1838 *m_metadata_ap = *rhs.m_metadata_ap; 1839 } 1840 return *this; 1841 } 1842 1843 bool 1844 Finalize() 1845 { 1846 return ClangASTContext::AddObjCClassProperty (m_class_opaque_type, 1847 m_property_name, 1848 m_property_opaque_type, 1849 m_ivar_decl, 1850 m_property_setter_name, 1851 m_property_getter_name, 1852 m_property_attributes, 1853 m_metadata_ap.get()); 1854 } 1855 1856 private: 1857 CompilerType m_class_opaque_type; 1858 const char *m_property_name; 1859 CompilerType m_property_opaque_type; 1860 clang::ObjCIvarDecl *m_ivar_decl; 1861 const char *m_property_setter_name; 1862 const char *m_property_getter_name; 1863 uint32_t m_property_attributes; 1864 std::unique_ptr<ClangASTMetadata> m_metadata_ap; 1865 }; 1866 1867 bool 1868 DWARFASTParserClang::ParseTemplateDIE (const DWARFDIE &die, 1869 ClangASTContext::TemplateParameterInfos &template_param_infos) 1870 { 1871 const dw_tag_t tag = die.Tag(); 1872 1873 switch (tag) 1874 { 1875 case DW_TAG_template_type_parameter: 1876 case DW_TAG_template_value_parameter: 1877 { 1878 DWARFAttributes attributes; 1879 const size_t num_attributes = die.GetAttributes (attributes); 1880 const char *name = NULL; 1881 Type *lldb_type = NULL; 1882 CompilerType clang_type; 1883 uint64_t uval64 = 0; 1884 bool uval64_valid = false; 1885 if (num_attributes > 0) 1886 { 1887 DWARFFormValue form_value; 1888 for (size_t i=0; i<num_attributes; ++i) 1889 { 1890 const dw_attr_t attr = attributes.AttributeAtIndex(i); 1891 1892 switch (attr) 1893 { 1894 case DW_AT_name: 1895 if (attributes.ExtractFormValueAtIndex(i, form_value)) 1896 name = form_value.AsCString(); 1897 break; 1898 1899 case DW_AT_type: 1900 if (attributes.ExtractFormValueAtIndex(i, form_value)) 1901 { 1902 lldb_type = die.ResolveTypeUID(DIERef(form_value)); 1903 if (lldb_type) 1904 clang_type = lldb_type->GetForwardCompilerType (); 1905 } 1906 break; 1907 1908 case DW_AT_const_value: 1909 if (attributes.ExtractFormValueAtIndex(i, form_value)) 1910 { 1911 uval64_valid = true; 1912 uval64 = form_value.Unsigned(); 1913 } 1914 break; 1915 default: 1916 break; 1917 } 1918 } 1919 1920 clang::ASTContext *ast = m_ast.getASTContext(); 1921 if (!clang_type) 1922 clang_type = m_ast.GetBasicType(eBasicTypeVoid); 1923 1924 if (clang_type) 1925 { 1926 bool is_signed = false; 1927 if (name && name[0]) 1928 template_param_infos.names.push_back(name); 1929 else 1930 template_param_infos.names.push_back(NULL); 1931 1932 if (tag == DW_TAG_template_value_parameter && 1933 lldb_type != NULL && 1934 clang_type.IsIntegerType (is_signed) && 1935 uval64_valid) 1936 { 1937 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); 1938 template_param_infos.args.push_back( 1939 clang::TemplateArgument(*ast, llvm::APSInt(apint), ClangUtil::GetQualType(clang_type))); 1940 } 1941 else 1942 { 1943 template_param_infos.args.push_back( 1944 clang::TemplateArgument(ClangUtil::GetQualType(clang_type))); 1945 } 1946 } 1947 else 1948 { 1949 return false; 1950 } 1951 1952 } 1953 } 1954 return true; 1955 1956 default: 1957 break; 1958 } 1959 return false; 1960 } 1961 1962 bool 1963 DWARFASTParserClang::ParseTemplateParameterInfos (const DWARFDIE &parent_die, 1964 ClangASTContext::TemplateParameterInfos &template_param_infos) 1965 { 1966 1967 if (!parent_die) 1968 return false; 1969 1970 Args template_parameter_names; 1971 for (DWARFDIE die = parent_die.GetFirstChild(); 1972 die.IsValid(); 1973 die = die.GetSibling()) 1974 { 1975 const dw_tag_t tag = die.Tag(); 1976 1977 switch (tag) 1978 { 1979 case DW_TAG_template_type_parameter: 1980 case DW_TAG_template_value_parameter: 1981 ParseTemplateDIE (die, template_param_infos); 1982 break; 1983 1984 default: 1985 break; 1986 } 1987 } 1988 if (template_param_infos.args.empty()) 1989 return false; 1990 return template_param_infos.args.size() == template_param_infos.names.size(); 1991 } 1992 1993 bool 1994 DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type) 1995 { 1996 SymbolFileDWARF *dwarf = die.GetDWARF(); 1997 1998 lldb_private::Mutex::Locker locker(dwarf->GetObjectFile()->GetModule()->GetMutex()); 1999 2000 // Disable external storage for this type so we don't get anymore 2001 // clang::ExternalASTSource queries for this type. 2002 m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), false); 2003 2004 if (!die) 2005 return false; 2006 2007 const dw_tag_t tag = die.Tag(); 2008 2009 Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); 2010 if (log) 2011 dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log, 2012 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", 2013 die.GetID(), 2014 die.GetTagAsCString(), 2015 type->GetName().AsCString()); 2016 assert (clang_type); 2017 DWARFAttributes attributes; 2018 switch (tag) 2019 { 2020 case DW_TAG_structure_type: 2021 case DW_TAG_union_type: 2022 case DW_TAG_class_type: 2023 { 2024 ClangASTImporter::LayoutInfo layout_info; 2025 2026 { 2027 if (die.HasChildren()) 2028 { 2029 LanguageType class_language = eLanguageTypeUnknown; 2030 if (ClangASTContext::IsObjCObjectOrInterfaceType(clang_type)) 2031 { 2032 class_language = eLanguageTypeObjC; 2033 // For objective C we don't start the definition when 2034 // the class is created. 2035 ClangASTContext::StartTagDeclarationDefinition (clang_type); 2036 } 2037 2038 int tag_decl_kind = -1; 2039 AccessType default_accessibility = eAccessNone; 2040 if (tag == DW_TAG_structure_type) 2041 { 2042 tag_decl_kind = clang::TTK_Struct; 2043 default_accessibility = eAccessPublic; 2044 } 2045 else if (tag == DW_TAG_union_type) 2046 { 2047 tag_decl_kind = clang::TTK_Union; 2048 default_accessibility = eAccessPublic; 2049 } 2050 else if (tag == DW_TAG_class_type) 2051 { 2052 tag_decl_kind = clang::TTK_Class; 2053 default_accessibility = eAccessPrivate; 2054 } 2055 2056 SymbolContext sc(die.GetLLDBCompileUnit()); 2057 std::vector<clang::CXXBaseSpecifier *> base_classes; 2058 std::vector<int> member_accessibilities; 2059 bool is_a_class = false; 2060 // Parse members and base classes first 2061 DWARFDIECollection member_function_dies; 2062 2063 DelayedPropertyList delayed_properties; 2064 ParseChildMembers (sc, 2065 die, 2066 clang_type, 2067 class_language, 2068 base_classes, 2069 member_accessibilities, 2070 member_function_dies, 2071 delayed_properties, 2072 default_accessibility, 2073 is_a_class, 2074 layout_info); 2075 2076 // Now parse any methods if there were any... 2077 size_t num_functions = member_function_dies.Size(); 2078 if (num_functions > 0) 2079 { 2080 for (size_t i=0; i<num_functions; ++i) 2081 { 2082 dwarf->ResolveType(member_function_dies.GetDIEAtIndex(i)); 2083 } 2084 } 2085 2086 if (class_language == eLanguageTypeObjC) 2087 { 2088 ConstString class_name (clang_type.GetTypeName()); 2089 if (class_name) 2090 { 2091 DIEArray method_die_offsets; 2092 dwarf->GetObjCMethodDIEOffsets(class_name, method_die_offsets); 2093 2094 if (!method_die_offsets.empty()) 2095 { 2096 DWARFDebugInfo* debug_info = dwarf->DebugInfo(); 2097 2098 const size_t num_matches = method_die_offsets.size(); 2099 for (size_t i=0; i<num_matches; ++i) 2100 { 2101 const DIERef& die_ref = method_die_offsets[i]; 2102 DWARFDIE method_die = debug_info->GetDIE (die_ref); 2103 2104 if (method_die) 2105 method_die.ResolveType (); 2106 } 2107 } 2108 2109 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); 2110 pi != pe; 2111 ++pi) 2112 pi->Finalize(); 2113 } 2114 } 2115 2116 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we 2117 // need to tell the clang type it is actually a class. 2118 if (class_language != eLanguageTypeObjC) 2119 { 2120 if (is_a_class && tag_decl_kind != clang::TTK_Class) 2121 m_ast.SetTagTypeKind(ClangUtil::GetQualType(clang_type), clang::TTK_Class); 2122 } 2123 2124 // Since DW_TAG_structure_type gets used for both classes 2125 // and structures, we may need to set any DW_TAG_member 2126 // fields to have a "private" access if none was specified. 2127 // When we parsed the child members we tracked that actual 2128 // accessibility value for each DW_TAG_member in the 2129 // "member_accessibilities" array. If the value for the 2130 // member is zero, then it was set to the "default_accessibility" 2131 // which for structs was "public". Below we correct this 2132 // by setting any fields to "private" that weren't correctly 2133 // set. 2134 if (is_a_class && !member_accessibilities.empty()) 2135 { 2136 // This is a class and all members that didn't have 2137 // their access specified are private. 2138 m_ast.SetDefaultAccessForRecordFields (m_ast.GetAsRecordDecl(clang_type), 2139 eAccessPrivate, 2140 &member_accessibilities.front(), 2141 member_accessibilities.size()); 2142 } 2143 2144 if (!base_classes.empty()) 2145 { 2146 // Make sure all base classes refer to complete types and not 2147 // forward declarations. If we don't do this, clang will crash 2148 // with an assertion in the call to clang_type.SetBaseClassesForClassType() 2149 for (auto &base_class : base_classes) 2150 { 2151 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo(); 2152 if (type_source_info) 2153 { 2154 CompilerType base_class_type (&m_ast, type_source_info->getType().getAsOpaquePtr()); 2155 if (base_class_type.GetCompleteType() == false) 2156 { 2157 auto module = dwarf->GetObjectFile()->GetModule(); 2158 module->ReportError ( 2159 ":: Class '%s' has a base class '%s' which does not have a complete definition.", 2160 die.GetName(), 2161 base_class_type.GetTypeName().GetCString()); 2162 if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang) 2163 module->ReportError (":: Try compiling the source file with -fno-limit-debug-info."); 2164 2165 // We have no choice other than to pretend that the base class 2166 // is complete. If we don't do this, clang will crash when we 2167 // call setBases() inside of "clang_type.SetBaseClassesForClassType()" 2168 // below. Since we provide layout assistance, all ivars in this 2169 // class and other classes will be fine, this is the best we can do 2170 // short of crashing. 2171 ClangASTContext::StartTagDeclarationDefinition (base_class_type); 2172 ClangASTContext::CompleteTagDeclarationDefinition (base_class_type); 2173 } 2174 } 2175 } 2176 m_ast.SetBaseClassesForClassType (clang_type.GetOpaqueQualType(), 2177 &base_classes.front(), 2178 base_classes.size()); 2179 2180 // Clang will copy each CXXBaseSpecifier in "base_classes" 2181 // so we have to free them all. 2182 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(), 2183 base_classes.size()); 2184 } 2185 } 2186 } 2187 2188 ClangASTContext::BuildIndirectFields (clang_type); 2189 ClangASTContext::CompleteTagDeclarationDefinition (clang_type); 2190 2191 if (!layout_info.field_offsets.empty() || 2192 !layout_info.base_offsets.empty() || 2193 !layout_info.vbase_offsets.empty() ) 2194 { 2195 if (type) 2196 layout_info.bit_size = type->GetByteSize() * 8; 2197 if (layout_info.bit_size == 0) 2198 layout_info.bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8; 2199 2200 clang::CXXRecordDecl *record_decl = m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType()); 2201 if (record_decl) 2202 { 2203 if (log) 2204 { 2205 ModuleSP module_sp = dwarf->GetObjectFile()->GetModule(); 2206 2207 if (module_sp) 2208 { 2209 module_sp->LogMessage (log, 2210 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", 2211 static_cast<void*>(clang_type.GetOpaqueQualType()), 2212 static_cast<void*>(record_decl), 2213 layout_info.bit_size, 2214 layout_info.alignment, 2215 static_cast<uint32_t>(layout_info.field_offsets.size()), 2216 static_cast<uint32_t>(layout_info.base_offsets.size()), 2217 static_cast<uint32_t>(layout_info.vbase_offsets.size())); 2218 2219 uint32_t idx; 2220 { 2221 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos, 2222 end = layout_info.field_offsets.end(); 2223 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) 2224 { 2225 module_sp->LogMessage(log, 2226 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", 2227 static_cast<void *>(clang_type.GetOpaqueQualType()), 2228 idx, 2229 static_cast<uint32_t>(pos->second), 2230 pos->first->getNameAsString().c_str()); 2231 } 2232 } 2233 2234 { 2235 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, 2236 base_end = layout_info.base_offsets.end(); 2237 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) 2238 { 2239 module_sp->LogMessage(log, 2240 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", 2241 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(), 2242 base_pos->first->getNameAsString().c_str()); 2243 } 2244 } 2245 { 2246 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, 2247 vbase_end = layout_info.vbase_offsets.end(); 2248 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) 2249 { 2250 module_sp->LogMessage(log, 2251 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", 2252 static_cast<void *>(clang_type.GetOpaqueQualType()), idx, 2253 static_cast<uint32_t>(vbase_pos->second.getQuantity()), 2254 vbase_pos->first->getNameAsString().c_str()); 2255 } 2256 } 2257 2258 } 2259 } 2260 GetClangASTImporter().InsertRecordDecl(record_decl, layout_info); 2261 } 2262 } 2263 } 2264 2265 return (bool)clang_type; 2266 2267 case DW_TAG_enumeration_type: 2268 ClangASTContext::StartTagDeclarationDefinition (clang_type); 2269 if (die.HasChildren()) 2270 { 2271 SymbolContext sc(die.GetLLDBCompileUnit()); 2272 bool is_signed = false; 2273 clang_type.IsIntegerType(is_signed); 2274 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), die); 2275 } 2276 ClangASTContext::CompleteTagDeclarationDefinition (clang_type); 2277 return (bool)clang_type; 2278 2279 default: 2280 assert(false && "not a forward clang type decl!"); 2281 break; 2282 } 2283 2284 return false; 2285 } 2286 2287 std::vector<DWARFDIE> 2288 DWARFASTParserClang::GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) 2289 { 2290 std::vector<DWARFDIE> result; 2291 for (auto it = m_decl_ctx_to_die.find((clang::DeclContext *)decl_context.GetOpaqueDeclContext()); it != m_decl_ctx_to_die.end(); it++) 2292 result.push_back(it->second); 2293 return result; 2294 } 2295 2296 CompilerDecl 2297 DWARFASTParserClang::GetDeclForUIDFromDWARF (const DWARFDIE &die) 2298 { 2299 clang::Decl *clang_decl = GetClangDeclForDIE(die); 2300 if (clang_decl != nullptr) 2301 return CompilerDecl(&m_ast, clang_decl); 2302 return CompilerDecl(); 2303 } 2304 2305 CompilerDeclContext 2306 DWARFASTParserClang::GetDeclContextForUIDFromDWARF (const DWARFDIE &die) 2307 { 2308 clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE (die); 2309 if (clang_decl_ctx) 2310 return CompilerDeclContext(&m_ast, clang_decl_ctx); 2311 return CompilerDeclContext(); 2312 } 2313 2314 CompilerDeclContext 2315 DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die) 2316 { 2317 clang::DeclContext *clang_decl_ctx = GetClangDeclContextContainingDIE (die, nullptr); 2318 if (clang_decl_ctx) 2319 return CompilerDeclContext(&m_ast, clang_decl_ctx); 2320 return CompilerDeclContext(); 2321 } 2322 2323 size_t 2324 DWARFASTParserClang::ParseChildEnumerators (const SymbolContext& sc, 2325 lldb_private::CompilerType &clang_type, 2326 bool is_signed, 2327 uint32_t enumerator_byte_size, 2328 const DWARFDIE &parent_die) 2329 { 2330 if (!parent_die) 2331 return 0; 2332 2333 size_t enumerators_added = 0; 2334 2335 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) 2336 { 2337 const dw_tag_t tag = die.Tag(); 2338 if (tag == DW_TAG_enumerator) 2339 { 2340 DWARFAttributes attributes; 2341 const size_t num_child_attributes = die.GetAttributes(attributes); 2342 if (num_child_attributes > 0) 2343 { 2344 const char *name = NULL; 2345 bool got_value = false; 2346 int64_t enum_value = 0; 2347 Declaration decl; 2348 2349 uint32_t i; 2350 for (i=0; i<num_child_attributes; ++i) 2351 { 2352 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2353 DWARFFormValue form_value; 2354 if (attributes.ExtractFormValueAtIndex(i, form_value)) 2355 { 2356 switch (attr) 2357 { 2358 case DW_AT_const_value: 2359 got_value = true; 2360 if (is_signed) 2361 enum_value = form_value.Signed(); 2362 else 2363 enum_value = form_value.Unsigned(); 2364 break; 2365 2366 case DW_AT_name: 2367 name = form_value.AsCString(); 2368 break; 2369 2370 case DW_AT_description: 2371 default: 2372 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2373 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2374 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2375 case DW_AT_sibling: 2376 break; 2377 } 2378 } 2379 } 2380 2381 if (name && name[0] && got_value) 2382 { 2383 m_ast.AddEnumerationValueToEnumerationType (clang_type.GetOpaqueQualType(), 2384 m_ast.GetEnumerationIntegerType(clang_type.GetOpaqueQualType()), 2385 decl, 2386 name, 2387 enum_value, 2388 enumerator_byte_size * 8); 2389 ++enumerators_added; 2390 } 2391 } 2392 } 2393 } 2394 return enumerators_added; 2395 } 2396 2397 #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE) 2398 2399 class DIEStack 2400 { 2401 public: 2402 2403 void Push (const DWARFDIE &die) 2404 { 2405 m_dies.push_back (die); 2406 } 2407 2408 2409 void LogDIEs (Log *log) 2410 { 2411 StreamString log_strm; 2412 const size_t n = m_dies.size(); 2413 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n); 2414 for (size_t i=0; i<n; i++) 2415 { 2416 std::string qualified_name; 2417 const DWARFDIE &die = m_dies[i]; 2418 die.GetQualifiedName(qualified_name); 2419 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n", 2420 (uint64_t)i, 2421 die.GetOffset(), 2422 die.GetTagAsCString(), 2423 qualified_name.c_str()); 2424 } 2425 log->PutCString(log_strm.GetData()); 2426 } 2427 void Pop () 2428 { 2429 m_dies.pop_back(); 2430 } 2431 2432 class ScopedPopper 2433 { 2434 public: 2435 ScopedPopper (DIEStack &die_stack) : 2436 m_die_stack (die_stack), 2437 m_valid (false) 2438 { 2439 } 2440 2441 void 2442 Push (const DWARFDIE &die) 2443 { 2444 m_valid = true; 2445 m_die_stack.Push (die); 2446 } 2447 2448 ~ScopedPopper () 2449 { 2450 if (m_valid) 2451 m_die_stack.Pop(); 2452 } 2453 2454 2455 2456 protected: 2457 DIEStack &m_die_stack; 2458 bool m_valid; 2459 }; 2460 2461 protected: 2462 typedef std::vector<DWARFDIE> Stack; 2463 Stack m_dies; 2464 }; 2465 #endif 2466 2467 Function * 2468 DWARFASTParserClang::ParseFunctionFromDWARF (const SymbolContext& sc, 2469 const DWARFDIE &die) 2470 { 2471 DWARFRangeList func_ranges; 2472 const char *name = NULL; 2473 const char *mangled = NULL; 2474 int decl_file = 0; 2475 int decl_line = 0; 2476 int decl_column = 0; 2477 int call_file = 0; 2478 int call_line = 0; 2479 int call_column = 0; 2480 DWARFExpression frame_base(die.GetCU()); 2481 2482 const dw_tag_t tag = die.Tag(); 2483 2484 if (tag != DW_TAG_subprogram) 2485 return NULL; 2486 2487 if (die.GetDIENamesAndRanges (name, 2488 mangled, 2489 func_ranges, 2490 decl_file, 2491 decl_line, 2492 decl_column, 2493 call_file, 2494 call_line, 2495 call_column, 2496 &frame_base)) 2497 { 2498 2499 // Union of all ranges in the function DIE (if the function is discontiguous) 2500 AddressRange func_range; 2501 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0); 2502 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0); 2503 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr) 2504 { 2505 ModuleSP module_sp (die.GetModule()); 2506 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList()); 2507 if (func_range.GetBaseAddress().IsValid()) 2508 func_range.SetByteSize(highest_func_addr - lowest_func_addr); 2509 } 2510 2511 if (func_range.GetBaseAddress().IsValid()) 2512 { 2513 Mangled func_name; 2514 if (mangled) 2515 func_name.SetValue(ConstString(mangled), true); 2516 else if (die.GetParent().Tag() == DW_TAG_compile_unit && 2517 Language::LanguageIsCPlusPlus(die.GetLanguage()) && 2518 name && strcmp(name, "main") != 0) 2519 { 2520 // If the mangled name is not present in the DWARF, generate the demangled name 2521 // using the decl context. We skip if the function is "main" as its name is 2522 // never mangled. 2523 bool is_static = false; 2524 bool is_variadic = false; 2525 bool has_template_params = false; 2526 unsigned type_quals = 0; 2527 std::vector<CompilerType> param_types; 2528 std::vector<clang::ParmVarDecl*> param_decls; 2529 DWARFDeclContext decl_ctx; 2530 StreamString sstr; 2531 2532 die.GetDWARFDeclContext(decl_ctx); 2533 sstr << decl_ctx.GetQualifiedName(); 2534 2535 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(die, nullptr); 2536 ParseChildParameters(sc, 2537 containing_decl_ctx, 2538 die, 2539 true, 2540 is_static, 2541 is_variadic, 2542 has_template_params, 2543 param_types, 2544 param_decls, 2545 type_quals); 2546 sstr << "("; 2547 for (size_t i = 0; i < param_types.size(); i++) 2548 { 2549 if (i > 0) 2550 sstr << ", "; 2551 sstr << param_types[i].GetTypeName(); 2552 } 2553 if (is_variadic) 2554 sstr << ", ..."; 2555 sstr << ")"; 2556 if (type_quals & clang::Qualifiers::Const) 2557 sstr << " const"; 2558 2559 func_name.SetValue(ConstString(sstr.GetData()), false); 2560 } 2561 else 2562 func_name.SetValue(ConstString(name), false); 2563 2564 FunctionSP func_sp; 2565 std::unique_ptr<Declaration> decl_ap; 2566 if (decl_file != 0 || decl_line != 0 || decl_column != 0) 2567 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), 2568 decl_line, 2569 decl_column)); 2570 2571 SymbolFileDWARF *dwarf = die.GetDWARF(); 2572 // Supply the type _only_ if it has already been parsed 2573 Type *func_type = dwarf->GetDIEToType().lookup (die.GetDIE()); 2574 2575 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED); 2576 2577 if (dwarf->FixupAddress (func_range.GetBaseAddress())) 2578 { 2579 const user_id_t func_user_id = die.GetID(); 2580 func_sp.reset(new Function (sc.comp_unit, 2581 func_user_id, // UserID is the DIE offset 2582 func_user_id, 2583 func_name, 2584 func_type, 2585 func_range)); // first address range 2586 2587 if (func_sp.get() != NULL) 2588 { 2589 if (frame_base.IsValid()) 2590 func_sp->GetFrameBaseExpression() = frame_base; 2591 sc.comp_unit->AddFunction(func_sp); 2592 return func_sp.get(); 2593 } 2594 } 2595 } 2596 } 2597 return NULL; 2598 } 2599 2600 bool 2601 DWARFASTParserClang::ParseChildMembers(const SymbolContext &sc, const DWARFDIE &parent_die, 2602 CompilerType &class_clang_type, const LanguageType class_language, 2603 std::vector<clang::CXXBaseSpecifier *> &base_classes, 2604 std::vector<int> &member_accessibilities, 2605 DWARFDIECollection &member_function_dies, 2606 DelayedPropertyList &delayed_properties, AccessType &default_accessibility, 2607 bool &is_a_class, ClangASTImporter::LayoutInfo &layout_info) 2608 { 2609 if (!parent_die) 2610 return 0; 2611 2612 uint32_t member_idx = 0; 2613 BitfieldInfo last_field_info; 2614 2615 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule(); 2616 ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(class_clang_type.GetTypeSystem()); 2617 if (ast == nullptr) 2618 return 0; 2619 2620 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) 2621 { 2622 dw_tag_t tag = die.Tag(); 2623 2624 switch (tag) 2625 { 2626 case DW_TAG_member: 2627 case DW_TAG_APPLE_property: 2628 { 2629 DWARFAttributes attributes; 2630 const size_t num_attributes = die.GetAttributes (attributes); 2631 if (num_attributes > 0) 2632 { 2633 Declaration decl; 2634 //DWARFExpression location; 2635 const char *name = NULL; 2636 const char *prop_name = NULL; 2637 const char *prop_getter_name = NULL; 2638 const char *prop_setter_name = NULL; 2639 uint32_t prop_attributes = 0; 2640 2641 2642 bool is_artificial = false; 2643 DWARFFormValue encoding_form; 2644 AccessType accessibility = eAccessNone; 2645 uint32_t member_byte_offset = (parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX; 2646 size_t byte_size = 0; 2647 size_t bit_offset = 0; 2648 size_t bit_size = 0; 2649 bool is_external = false; // On DW_TAG_members, this means the member is static 2650 uint32_t i; 2651 for (i=0; i<num_attributes && !is_artificial; ++i) 2652 { 2653 const dw_attr_t attr = attributes.AttributeAtIndex(i); 2654 DWARFFormValue form_value; 2655 if (attributes.ExtractFormValueAtIndex(i, form_value)) 2656 { 2657 switch (attr) 2658 { 2659 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 2660 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 2661 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 2662 case DW_AT_name: name = form_value.AsCString(); break; 2663 case DW_AT_type: encoding_form = form_value; break; 2664 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break; 2665 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break; 2666 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; 2667 case DW_AT_data_member_location: 2668 if (form_value.BlockData()) 2669 { 2670 Value initialValue(0); 2671 Value memberOffset(0); 2672 const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data(); 2673 uint32_t block_length = form_value.Unsigned(); 2674 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 2675 if (DWARFExpression::Evaluate(nullptr, // ExecutionContext * 2676 nullptr, // ClangExpressionVariableList * 2677 nullptr, // ClangExpressionDeclMap * 2678 nullptr, // RegisterContext * 2679 module_sp, 2680 debug_info_data, 2681 die.GetCU(), 2682 block_offset, 2683 block_length, 2684 eRegisterKindDWARF, 2685 &initialValue, 2686 nullptr, 2687 memberOffset, 2688 nullptr)) 2689 { 2690 member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); 2691 } 2692 } 2693 else 2694 { 2695 // With DWARF 3 and later, if the value is an integer constant, 2696 // this form value is the offset in bytes from the beginning 2697 // of the containing entity. 2698 member_byte_offset = form_value.Unsigned(); 2699 } 2700 break; 2701 2702 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break; 2703 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 2704 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(); 2705 break; 2706 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(); 2707 break; 2708 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(); 2709 break; 2710 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break; 2711 case DW_AT_external: is_external = form_value.Boolean(); break; 2712 2713 default: 2714 case DW_AT_declaration: 2715 case DW_AT_description: 2716 case DW_AT_mutable: 2717 case DW_AT_visibility: 2718 case DW_AT_sibling: 2719 break; 2720 } 2721 } 2722 } 2723 2724 if (prop_name) 2725 { 2726 ConstString fixed_getter; 2727 ConstString fixed_setter; 2728 2729 // Check if the property getter/setter were provided as full 2730 // names. We want basenames, so we extract them. 2731 2732 if (prop_getter_name && prop_getter_name[0] == '-') 2733 { 2734 ObjCLanguage::MethodName prop_getter_method(prop_getter_name, true); 2735 prop_getter_name = prop_getter_method.GetSelector().GetCString(); 2736 } 2737 2738 if (prop_setter_name && prop_setter_name[0] == '-') 2739 { 2740 ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true); 2741 prop_setter_name = prop_setter_method.GetSelector().GetCString(); 2742 } 2743 2744 // If the names haven't been provided, they need to be 2745 // filled in. 2746 2747 if (!prop_getter_name) 2748 { 2749 prop_getter_name = prop_name; 2750 } 2751 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly)) 2752 { 2753 StreamString ss; 2754 2755 ss.Printf("set%c%s:", 2756 toupper(prop_name[0]), 2757 &prop_name[1]); 2758 2759 fixed_setter.SetCString(ss.GetData()); 2760 prop_setter_name = fixed_setter.GetCString(); 2761 } 2762 } 2763 2764 // Clang has a DWARF generation bug where sometimes it 2765 // represents fields that are references with bad byte size 2766 // and bit size/offset information such as: 2767 // 2768 // DW_AT_byte_size( 0x00 ) 2769 // DW_AT_bit_size( 0x40 ) 2770 // DW_AT_bit_offset( 0xffffffffffffffc0 ) 2771 // 2772 // So check the bit offset to make sure it is sane, and if 2773 // the values are not sane, remove them. If we don't do this 2774 // then we will end up with a crash if we try to use this 2775 // type in an expression when clang becomes unhappy with its 2776 // recycled debug info. 2777 2778 if (bit_offset > 128) 2779 { 2780 bit_size = 0; 2781 bit_offset = 0; 2782 } 2783 2784 // FIXME: Make Clang ignore Objective-C accessibility for expressions 2785 if (class_language == eLanguageTypeObjC || 2786 class_language == eLanguageTypeObjC_plus_plus) 2787 accessibility = eAccessNone; 2788 2789 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name)) 2790 { 2791 // Not all compilers will mark the vtable pointer 2792 // member as artificial (llvm-gcc). We can't have 2793 // the virtual members in our classes otherwise it 2794 // throws off all child offsets since we end up 2795 // having and extra pointer sized member in our 2796 // class layouts. 2797 is_artificial = true; 2798 } 2799 2800 // Handle static members 2801 if (is_external && member_byte_offset == UINT32_MAX) 2802 { 2803 Type *var_type = die.ResolveTypeUID(DIERef(encoding_form)); 2804 2805 if (var_type) 2806 { 2807 if (accessibility == eAccessNone) 2808 accessibility = eAccessPublic; 2809 ClangASTContext::AddVariableToRecordType (class_clang_type, 2810 name, 2811 var_type->GetLayoutCompilerType (), 2812 accessibility); 2813 } 2814 break; 2815 } 2816 2817 if (is_artificial == false) 2818 { 2819 Type *member_type = die.ResolveTypeUID(DIERef(encoding_form)); 2820 2821 clang::FieldDecl *field_decl = NULL; 2822 if (tag == DW_TAG_member) 2823 { 2824 if (member_type) 2825 { 2826 if (accessibility == eAccessNone) 2827 accessibility = default_accessibility; 2828 member_accessibilities.push_back(accessibility); 2829 2830 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8)); 2831 if (bit_size > 0) 2832 { 2833 2834 BitfieldInfo this_field_info; 2835 this_field_info.bit_offset = field_bit_offset; 2836 this_field_info.bit_size = bit_size; 2837 2838 ///////////////////////////////////////////////////////////// 2839 // How to locate a field given the DWARF debug information 2840 // 2841 // AT_byte_size indicates the size of the word in which the 2842 // bit offset must be interpreted. 2843 // 2844 // AT_data_member_location indicates the byte offset of the 2845 // word from the base address of the structure. 2846 // 2847 // AT_bit_offset indicates how many bits into the word 2848 // (according to the host endianness) the low-order bit of 2849 // the field starts. AT_bit_offset can be negative. 2850 // 2851 // AT_bit_size indicates the size of the field in bits. 2852 ///////////////////////////////////////////////////////////// 2853 2854 if (byte_size == 0) 2855 byte_size = member_type->GetByteSize(); 2856 2857 if (die.GetDWARF()->GetObjectFile()->GetByteOrder() == eByteOrderLittle) 2858 { 2859 this_field_info.bit_offset += byte_size * 8; 2860 this_field_info.bit_offset -= (bit_offset + bit_size); 2861 } 2862 else 2863 { 2864 this_field_info.bit_offset += bit_offset; 2865 } 2866 2867 // Update the field bit offset we will report for layout 2868 field_bit_offset = this_field_info.bit_offset; 2869 2870 // If the member to be emitted did not start on a character boundary and there is 2871 // empty space between the last field and this one, then we need to emit an 2872 // anonymous member filling up the space up to its start. There are three cases 2873 // here: 2874 // 2875 // 1 If the previous member ended on a character boundary, then we can emit an 2876 // anonymous member starting at the most recent character boundary. 2877 // 2878 // 2 If the previous member did not end on a character boundary and the distance 2879 // from the end of the previous member to the current member is less than a 2880 // word width, then we can emit an anonymous member starting right after the 2881 // previous member and right before this member. 2882 // 2883 // 3 If the previous member did not end on a character boundary and the distance 2884 // from the end of the previous member to the current member is greater than 2885 // or equal a word width, then we act as in Case 1. 2886 2887 const uint64_t character_width = 8; 2888 const uint64_t word_width = 32; 2889 2890 // Objective-C has invalid DW_AT_bit_offset values in older versions 2891 // of clang, so we have to be careful and only insert unnamed bitfields 2892 // if we have a new enough clang. 2893 bool detect_unnamed_bitfields = true; 2894 2895 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus) 2896 detect_unnamed_bitfields = die.GetCU()->Supports_unnamed_objc_bitfields (); 2897 2898 if (detect_unnamed_bitfields) 2899 { 2900 BitfieldInfo anon_field_info; 2901 2902 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned 2903 { 2904 uint64_t last_field_end = 0; 2905 2906 if (last_field_info.IsValid()) 2907 last_field_end = last_field_info.bit_offset + last_field_info.bit_size; 2908 2909 if (this_field_info.bit_offset != last_field_end) 2910 { 2911 if (((last_field_end % character_width) == 0) || // case 1 2912 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3 2913 { 2914 anon_field_info.bit_size = this_field_info.bit_offset % character_width; 2915 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size; 2916 } 2917 else // case 2 2918 { 2919 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end; 2920 anon_field_info.bit_offset = last_field_end; 2921 } 2922 } 2923 } 2924 2925 if (anon_field_info.IsValid()) 2926 { 2927 clang::FieldDecl *unnamed_bitfield_decl = 2928 ClangASTContext::AddFieldToRecordType (class_clang_type, 2929 NULL, 2930 m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), 2931 accessibility, 2932 anon_field_info.bit_size); 2933 2934 layout_info.field_offsets.insert( 2935 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); 2936 } 2937 } 2938 last_field_info = this_field_info; 2939 } 2940 else 2941 { 2942 last_field_info.Clear(); 2943 } 2944 2945 CompilerType member_clang_type = member_type->GetLayoutCompilerType (); 2946 if (!member_clang_type.IsCompleteType()) 2947 member_clang_type.GetCompleteType(); 2948 2949 { 2950 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>). 2951 // If the current field is at the end of the structure, then there is definitely no room for extra 2952 // elements and we override the type to array[0]. 2953 2954 CompilerType member_array_element_type; 2955 uint64_t member_array_size; 2956 bool member_array_is_incomplete; 2957 2958 if (member_clang_type.IsArrayType(&member_array_element_type, 2959 &member_array_size, 2960 &member_array_is_incomplete) && 2961 !member_array_is_incomplete) 2962 { 2963 uint64_t parent_byte_size = parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX); 2964 2965 if (member_byte_offset >= parent_byte_size) 2966 { 2967 if (member_array_size != 1 && (member_array_size != 0 || member_byte_offset > parent_byte_size)) 2968 { 2969 module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64, 2970 die.GetID(), 2971 name, 2972 encoding_form.Reference(), 2973 parent_die.GetID()); 2974 } 2975 2976 member_clang_type = m_ast.CreateArrayType(member_array_element_type, 0, false); 2977 } 2978 } 2979 } 2980 2981 if (ClangASTContext::IsCXXClassType(member_clang_type) && member_clang_type.GetCompleteType() == false) 2982 { 2983 if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang) 2984 module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type is a forward declaration, not a complete definition.\nTry compiling the source file with -fno-limit-debug-info", 2985 parent_die.GetOffset(), 2986 parent_die.GetName(), 2987 die.GetOffset(), 2988 name); 2989 else 2990 module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s", 2991 parent_die.GetOffset(), 2992 parent_die.GetName(), 2993 die.GetOffset(), 2994 name, 2995 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file"); 2996 // We have no choice other than to pretend that the member class 2997 // is complete. If we don't do this, clang will crash when trying 2998 // to layout the class. Since we provide layout assistance, all 2999 // ivars in this class and other classes will be fine, this is 3000 // the best we can do short of crashing. 3001 ClangASTContext::StartTagDeclarationDefinition(member_clang_type); 3002 ClangASTContext::CompleteTagDeclarationDefinition(member_clang_type); 3003 } 3004 3005 field_decl = ClangASTContext::AddFieldToRecordType (class_clang_type, 3006 name, 3007 member_clang_type, 3008 accessibility, 3009 bit_size); 3010 3011 m_ast.SetMetadataAsUserID (field_decl, die.GetID()); 3012 3013 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); 3014 } 3015 else 3016 { 3017 if (name) 3018 module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed", 3019 die.GetID(), 3020 name, 3021 encoding_form.Reference()); 3022 else 3023 module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed", 3024 die.GetID(), 3025 encoding_form.Reference()); 3026 } 3027 } 3028 3029 if (prop_name != NULL && member_type) 3030 { 3031 clang::ObjCIvarDecl *ivar_decl = NULL; 3032 3033 if (field_decl) 3034 { 3035 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); 3036 assert (ivar_decl != NULL); 3037 } 3038 3039 ClangASTMetadata metadata; 3040 metadata.SetUserID (die.GetID()); 3041 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type, 3042 prop_name, 3043 member_type->GetLayoutCompilerType (), 3044 ivar_decl, 3045 prop_setter_name, 3046 prop_getter_name, 3047 prop_attributes, 3048 &metadata)); 3049 3050 if (ivar_decl) 3051 m_ast.SetMetadataAsUserID (ivar_decl, die.GetID()); 3052 } 3053 } 3054 } 3055 ++member_idx; 3056 } 3057 break; 3058 3059 case DW_TAG_subprogram: 3060 // Let the type parsing code handle this one for us. 3061 member_function_dies.Append (die); 3062 break; 3063 3064 case DW_TAG_inheritance: 3065 { 3066 is_a_class = true; 3067 if (default_accessibility == eAccessNone) 3068 default_accessibility = eAccessPrivate; 3069 // TODO: implement DW_TAG_inheritance type parsing 3070 DWARFAttributes attributes; 3071 const size_t num_attributes = die.GetAttributes (attributes); 3072 if (num_attributes > 0) 3073 { 3074 Declaration decl; 3075 DWARFExpression location(die.GetCU()); 3076 DWARFFormValue encoding_form; 3077 AccessType accessibility = default_accessibility; 3078 bool is_virtual = false; 3079 bool is_base_of_class = true; 3080 off_t member_byte_offset = 0; 3081 uint32_t i; 3082 for (i=0; i<num_attributes; ++i) 3083 { 3084 const dw_attr_t attr = attributes.AttributeAtIndex(i); 3085 DWARFFormValue form_value; 3086 if (attributes.ExtractFormValueAtIndex(i, form_value)) 3087 { 3088 switch (attr) 3089 { 3090 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 3091 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 3092 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 3093 case DW_AT_type: encoding_form = form_value; break; 3094 case DW_AT_data_member_location: 3095 if (form_value.BlockData()) 3096 { 3097 Value initialValue(0); 3098 Value memberOffset(0); 3099 const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data(); 3100 uint32_t block_length = form_value.Unsigned(); 3101 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart(); 3102 if (DWARFExpression::Evaluate (nullptr, 3103 nullptr, 3104 nullptr, 3105 nullptr, 3106 module_sp, 3107 debug_info_data, 3108 die.GetCU(), 3109 block_offset, 3110 block_length, 3111 eRegisterKindDWARF, 3112 &initialValue, 3113 nullptr, 3114 memberOffset, 3115 nullptr)) 3116 { 3117 member_byte_offset = memberOffset.ResolveValue(NULL).UInt(); 3118 } 3119 } 3120 else 3121 { 3122 // With DWARF 3 and later, if the value is an integer constant, 3123 // this form value is the offset in bytes from the beginning 3124 // of the containing entity. 3125 member_byte_offset = form_value.Unsigned(); 3126 } 3127 break; 3128 3129 case DW_AT_accessibility: 3130 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); 3131 break; 3132 3133 case DW_AT_virtuality: 3134 is_virtual = form_value.Boolean(); 3135 break; 3136 3137 case DW_AT_sibling: 3138 break; 3139 3140 default: 3141 break; 3142 } 3143 } 3144 } 3145 3146 Type *base_class_type = die.ResolveTypeUID(DIERef(encoding_form)); 3147 if (base_class_type == NULL) 3148 { 3149 module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message", 3150 die.GetOffset(), 3151 encoding_form.Reference(), 3152 parent_die.GetOffset()); 3153 break; 3154 } 3155 3156 CompilerType base_class_clang_type = base_class_type->GetFullCompilerType (); 3157 assert (base_class_clang_type); 3158 if (class_language == eLanguageTypeObjC) 3159 { 3160 ast->SetObjCSuperClass(class_clang_type, base_class_clang_type); 3161 } 3162 else 3163 { 3164 base_classes.push_back (ast->CreateBaseClassSpecifier (base_class_clang_type.GetOpaqueQualType(), 3165 accessibility, 3166 is_virtual, 3167 is_base_of_class)); 3168 3169 if (is_virtual) 3170 { 3171 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't 3172 // give us a constant offset, but gives us a DWARF expressions that requires an actual object 3173 // in memory. the DW_AT_data_member_location for a virtual base class looks like: 3174 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus ) 3175 // Given this, there is really no valid response we can give to clang for virtual base 3176 // class offsets, and this should eventually be removed from LayoutRecordType() in the external 3177 // AST source in clang. 3178 } 3179 else 3180 { 3181 layout_info.base_offsets.insert( 3182 std::make_pair(ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()), 3183 clang::CharUnits::fromQuantity(member_byte_offset))); 3184 } 3185 } 3186 } 3187 } 3188 break; 3189 3190 default: 3191 break; 3192 } 3193 } 3194 3195 return true; 3196 } 3197 3198 3199 size_t 3200 DWARFASTParserClang::ParseChildParameters (const SymbolContext& sc, 3201 clang::DeclContext *containing_decl_ctx, 3202 const DWARFDIE &parent_die, 3203 bool skip_artificial, 3204 bool &is_static, 3205 bool &is_variadic, 3206 bool &has_template_params, 3207 std::vector<CompilerType>& function_param_types, 3208 std::vector<clang::ParmVarDecl*>& function_param_decls, 3209 unsigned &type_quals) 3210 { 3211 if (!parent_die) 3212 return 0; 3213 3214 size_t arg_idx = 0; 3215 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) 3216 { 3217 const dw_tag_t tag = die.Tag(); 3218 switch (tag) 3219 { 3220 case DW_TAG_formal_parameter: 3221 { 3222 DWARFAttributes attributes; 3223 const size_t num_attributes = die.GetAttributes(attributes); 3224 if (num_attributes > 0) 3225 { 3226 const char *name = NULL; 3227 Declaration decl; 3228 DWARFFormValue param_type_die_form; 3229 bool is_artificial = false; 3230 // one of None, Auto, Register, Extern, Static, PrivateExtern 3231 3232 clang::StorageClass storage = clang::SC_None; 3233 uint32_t i; 3234 for (i=0; i<num_attributes; ++i) 3235 { 3236 const dw_attr_t attr = attributes.AttributeAtIndex(i); 3237 DWARFFormValue form_value; 3238 if (attributes.ExtractFormValueAtIndex(i, form_value)) 3239 { 3240 switch (attr) 3241 { 3242 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; 3243 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; 3244 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; 3245 case DW_AT_name: name = form_value.AsCString(); 3246 break; 3247 case DW_AT_type: param_type_die_form = form_value; break; 3248 case DW_AT_artificial: is_artificial = form_value.Boolean(); break; 3249 case DW_AT_location: 3250 // if (form_value.BlockData()) 3251 // { 3252 // const DWARFDataExtractor& debug_info_data = debug_info(); 3253 // uint32_t block_length = form_value.Unsigned(); 3254 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length); 3255 // } 3256 // else 3257 // { 3258 // } 3259 // break; 3260 case DW_AT_const_value: 3261 case DW_AT_default_value: 3262 case DW_AT_description: 3263 case DW_AT_endianity: 3264 case DW_AT_is_optional: 3265 case DW_AT_segment: 3266 case DW_AT_variable_parameter: 3267 default: 3268 case DW_AT_abstract_origin: 3269 case DW_AT_sibling: 3270 break; 3271 } 3272 } 3273 } 3274 3275 bool skip = false; 3276 if (skip_artificial) 3277 { 3278 if (is_artificial) 3279 { 3280 // In order to determine if a C++ member function is 3281 // "const" we have to look at the const-ness of "this"... 3282 // Ugly, but that 3283 if (arg_idx == 0) 3284 { 3285 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) 3286 { 3287 // Often times compilers omit the "this" name for the 3288 // specification DIEs, so we can't rely upon the name 3289 // being in the formal parameter DIE... 3290 if (name == NULL || ::strcmp(name, "this")==0) 3291 { 3292 Type *this_type = die.ResolveTypeUID (DIERef(param_type_die_form)); 3293 if (this_type) 3294 { 3295 uint32_t encoding_mask = this_type->GetEncodingMask(); 3296 if (encoding_mask & Type::eEncodingIsPointerUID) 3297 { 3298 is_static = false; 3299 3300 if (encoding_mask & (1u << Type::eEncodingIsConstUID)) 3301 type_quals |= clang::Qualifiers::Const; 3302 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) 3303 type_quals |= clang::Qualifiers::Volatile; 3304 } 3305 } 3306 } 3307 } 3308 } 3309 skip = true; 3310 } 3311 else 3312 { 3313 3314 // HACK: Objective C formal parameters "self" and "_cmd" 3315 // are not marked as artificial in the DWARF... 3316 CompileUnit *comp_unit = die.GetLLDBCompileUnit(); 3317 if (comp_unit) 3318 { 3319 switch (comp_unit->GetLanguage()) 3320 { 3321 case eLanguageTypeObjC: 3322 case eLanguageTypeObjC_plus_plus: 3323 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0)) 3324 skip = true; 3325 break; 3326 default: 3327 break; 3328 } 3329 } 3330 } 3331 } 3332 3333 if (!skip) 3334 { 3335 Type *type = die.ResolveTypeUID(DIERef(param_type_die_form)); 3336 if (type) 3337 { 3338 function_param_types.push_back (type->GetForwardCompilerType ()); 3339 3340 clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration (name, 3341 type->GetForwardCompilerType (), 3342 storage); 3343 assert(param_var_decl); 3344 function_param_decls.push_back(param_var_decl); 3345 3346 m_ast.SetMetadataAsUserID (param_var_decl, die.GetID()); 3347 } 3348 } 3349 } 3350 arg_idx++; 3351 } 3352 break; 3353 3354 case DW_TAG_unspecified_parameters: 3355 is_variadic = true; 3356 break; 3357 3358 case DW_TAG_template_type_parameter: 3359 case DW_TAG_template_value_parameter: 3360 // The one caller of this was never using the template_param_infos, 3361 // and the local variable was taking up a large amount of stack space 3362 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need 3363 // the template params back, we can add them back. 3364 // ParseTemplateDIE (dwarf_cu, die, template_param_infos); 3365 has_template_params = true; 3366 break; 3367 3368 default: 3369 break; 3370 } 3371 } 3372 return arg_idx; 3373 } 3374 3375 void 3376 DWARFASTParserClang::ParseChildArrayInfo (const SymbolContext& sc, 3377 const DWARFDIE &parent_die, 3378 int64_t& first_index, 3379 std::vector<uint64_t>& element_orders, 3380 uint32_t& byte_stride, 3381 uint32_t& bit_stride) 3382 { 3383 if (!parent_die) 3384 return; 3385 3386 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) 3387 { 3388 const dw_tag_t tag = die.Tag(); 3389 switch (tag) 3390 { 3391 case DW_TAG_subrange_type: 3392 { 3393 DWARFAttributes attributes; 3394 const size_t num_child_attributes = die.GetAttributes(attributes); 3395 if (num_child_attributes > 0) 3396 { 3397 uint64_t num_elements = 0; 3398 uint64_t lower_bound = 0; 3399 uint64_t upper_bound = 0; 3400 bool upper_bound_valid = false; 3401 uint32_t i; 3402 for (i=0; i<num_child_attributes; ++i) 3403 { 3404 const dw_attr_t attr = attributes.AttributeAtIndex(i); 3405 DWARFFormValue form_value; 3406 if (attributes.ExtractFormValueAtIndex(i, form_value)) 3407 { 3408 switch (attr) 3409 { 3410 case DW_AT_name: 3411 break; 3412 3413 case DW_AT_count: 3414 num_elements = form_value.Unsigned(); 3415 break; 3416 3417 case DW_AT_bit_stride: 3418 bit_stride = form_value.Unsigned(); 3419 break; 3420 3421 case DW_AT_byte_stride: 3422 byte_stride = form_value.Unsigned(); 3423 break; 3424 3425 case DW_AT_lower_bound: 3426 lower_bound = form_value.Unsigned(); 3427 break; 3428 3429 case DW_AT_upper_bound: 3430 upper_bound_valid = true; 3431 upper_bound = form_value.Unsigned(); 3432 break; 3433 3434 default: 3435 case DW_AT_abstract_origin: 3436 case DW_AT_accessibility: 3437 case DW_AT_allocated: 3438 case DW_AT_associated: 3439 case DW_AT_data_location: 3440 case DW_AT_declaration: 3441 case DW_AT_description: 3442 case DW_AT_sibling: 3443 case DW_AT_threads_scaled: 3444 case DW_AT_type: 3445 case DW_AT_visibility: 3446 break; 3447 } 3448 } 3449 } 3450 3451 if (num_elements == 0) 3452 { 3453 if (upper_bound_valid && upper_bound >= lower_bound) 3454 num_elements = upper_bound - lower_bound + 1; 3455 } 3456 3457 element_orders.push_back (num_elements); 3458 } 3459 } 3460 break; 3461 } 3462 } 3463 } 3464 3465 Type * 3466 DWARFASTParserClang::GetTypeForDIE (const DWARFDIE &die) 3467 { 3468 if (die) 3469 { 3470 SymbolFileDWARF *dwarf = die.GetDWARF(); 3471 DWARFAttributes attributes; 3472 const size_t num_attributes = die.GetAttributes(attributes); 3473 if (num_attributes > 0) 3474 { 3475 DWARFFormValue type_die_form; 3476 for (size_t i = 0; i < num_attributes; ++i) 3477 { 3478 dw_attr_t attr = attributes.AttributeAtIndex(i); 3479 DWARFFormValue form_value; 3480 3481 if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value)) 3482 return dwarf->ResolveTypeUID(dwarf->GetDIE (DIERef(form_value)), true); 3483 } 3484 } 3485 } 3486 3487 return nullptr; 3488 } 3489 3490 clang::Decl * 3491 DWARFASTParserClang::GetClangDeclForDIE (const DWARFDIE &die) 3492 { 3493 if (!die) 3494 return nullptr; 3495 3496 switch (die.Tag()) 3497 { 3498 case DW_TAG_variable: 3499 case DW_TAG_constant: 3500 case DW_TAG_formal_parameter: 3501 case DW_TAG_imported_declaration: 3502 case DW_TAG_imported_module: 3503 break; 3504 default: 3505 return nullptr; 3506 } 3507 3508 DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE()); 3509 if (cache_pos != m_die_to_decl.end()) 3510 return cache_pos->second; 3511 3512 if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) 3513 { 3514 clang::Decl *decl = GetClangDeclForDIE(spec_die); 3515 m_die_to_decl[die.GetDIE()] = decl; 3516 m_decl_to_die[decl].insert(die.GetDIE()); 3517 return decl; 3518 } 3519 3520 clang::Decl *decl = nullptr; 3521 switch (die.Tag()) 3522 { 3523 case DW_TAG_variable: 3524 case DW_TAG_constant: 3525 case DW_TAG_formal_parameter: 3526 { 3527 SymbolFileDWARF *dwarf = die.GetDWARF(); 3528 Type *type = GetTypeForDIE(die); 3529 const char *name = die.GetName(); 3530 clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID())); 3531 decl = m_ast.CreateVariableDeclaration(decl_context, name, 3532 ClangUtil::GetQualType(type->GetForwardCompilerType())); 3533 break; 3534 } 3535 case DW_TAG_imported_declaration: 3536 { 3537 SymbolFileDWARF *dwarf = die.GetDWARF(); 3538 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); 3539 if (imported_uid) 3540 { 3541 CompilerDecl imported_decl = imported_uid.GetDecl(); 3542 if (imported_decl) 3543 { 3544 clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID())); 3545 if (clang::NamedDecl *clang_imported_decl = llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)imported_decl.GetOpaqueDecl())) 3546 decl = m_ast.CreateUsingDeclaration(decl_context, clang_imported_decl); 3547 } 3548 } 3549 break; 3550 } 3551 case DW_TAG_imported_module: 3552 { 3553 SymbolFileDWARF *dwarf = die.GetDWARF(); 3554 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); 3555 3556 if (imported_uid) 3557 { 3558 CompilerDeclContext imported_decl_ctx = imported_uid.GetDeclContext(); 3559 if (imported_decl_ctx) 3560 { 3561 clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID())); 3562 if (clang::NamespaceDecl *ns_decl = ClangASTContext::DeclContextGetAsNamespaceDecl(imported_decl_ctx)) 3563 decl = m_ast.CreateUsingDirectiveDeclaration(decl_context, ns_decl); 3564 } 3565 } 3566 break; 3567 } 3568 default: 3569 break; 3570 } 3571 3572 m_die_to_decl[die.GetDIE()] = decl; 3573 m_decl_to_die[decl].insert(die.GetDIE()); 3574 3575 return decl; 3576 } 3577 3578 clang::DeclContext * 3579 DWARFASTParserClang::GetClangDeclContextForDIE (const DWARFDIE &die) 3580 { 3581 if (die) 3582 { 3583 clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE (die); 3584 if (decl_ctx) 3585 return decl_ctx; 3586 3587 bool try_parsing_type = true; 3588 switch (die.Tag()) 3589 { 3590 case DW_TAG_compile_unit: 3591 decl_ctx = m_ast.GetTranslationUnitDecl(); 3592 try_parsing_type = false; 3593 break; 3594 3595 case DW_TAG_namespace: 3596 decl_ctx = ResolveNamespaceDIE (die); 3597 try_parsing_type = false; 3598 break; 3599 3600 case DW_TAG_lexical_block: 3601 decl_ctx = (clang::DeclContext *)ResolveBlockDIE(die); 3602 try_parsing_type = false; 3603 break; 3604 3605 default: 3606 break; 3607 } 3608 3609 if (decl_ctx == nullptr && try_parsing_type) 3610 { 3611 Type* type = die.GetDWARF()->ResolveType (die); 3612 if (type) 3613 decl_ctx = GetCachedClangDeclContextForDIE (die); 3614 } 3615 3616 if (decl_ctx) 3617 { 3618 LinkDeclContextToDIE (decl_ctx, die); 3619 return decl_ctx; 3620 } 3621 } 3622 return nullptr; 3623 } 3624 3625 clang::BlockDecl * 3626 DWARFASTParserClang::ResolveBlockDIE (const DWARFDIE &die) 3627 { 3628 if (die && die.Tag() == DW_TAG_lexical_block) 3629 { 3630 clang::BlockDecl *decl = llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]); 3631 3632 if (!decl) 3633 { 3634 DWARFDIE decl_context_die; 3635 clang::DeclContext *decl_context = GetClangDeclContextContainingDIE(die, &decl_context_die); 3636 decl = m_ast.CreateBlockDeclaration(decl_context); 3637 3638 if (decl) 3639 LinkDeclContextToDIE((clang::DeclContext *)decl, die); 3640 } 3641 3642 return decl; 3643 } 3644 return nullptr; 3645 } 3646 3647 clang::NamespaceDecl * 3648 DWARFASTParserClang::ResolveNamespaceDIE (const DWARFDIE &die) 3649 { 3650 if (die && die.Tag() == DW_TAG_namespace) 3651 { 3652 // See if we already parsed this namespace DIE and associated it with a 3653 // uniqued namespace declaration 3654 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]); 3655 if (namespace_decl) 3656 return namespace_decl; 3657 else 3658 { 3659 const char *namespace_name = die.GetName(); 3660 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (die, nullptr); 3661 namespace_decl = m_ast.GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx); 3662 Log *log = nullptr;// (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); 3663 if (log) 3664 { 3665 SymbolFileDWARF *dwarf = die.GetDWARF(); 3666 if (namespace_name) 3667 { 3668 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 3669 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", 3670 static_cast<void*>(m_ast.getASTContext()), 3671 die.GetID(), 3672 namespace_name, 3673 static_cast<void*>(namespace_decl), 3674 static_cast<void*>(namespace_decl->getOriginalNamespace())); 3675 } 3676 else 3677 { 3678 dwarf->GetObjectFile()->GetModule()->LogMessage (log, 3679 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", 3680 static_cast<void*>(m_ast.getASTContext()), 3681 die.GetID(), 3682 static_cast<void*>(namespace_decl), 3683 static_cast<void*>(namespace_decl->getOriginalNamespace())); 3684 } 3685 } 3686 3687 if (namespace_decl) 3688 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die); 3689 return namespace_decl; 3690 } 3691 } 3692 return nullptr; 3693 } 3694 3695 clang::DeclContext * 3696 DWARFASTParserClang::GetClangDeclContextContainingDIE (const DWARFDIE &die, 3697 DWARFDIE *decl_ctx_die_copy) 3698 { 3699 SymbolFileDWARF *dwarf = die.GetDWARF(); 3700 3701 DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE (die); 3702 3703 if (decl_ctx_die_copy) 3704 *decl_ctx_die_copy = decl_ctx_die; 3705 3706 if (decl_ctx_die) 3707 { 3708 clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE (decl_ctx_die); 3709 if (clang_decl_ctx) 3710 return clang_decl_ctx; 3711 } 3712 return m_ast.GetTranslationUnitDecl(); 3713 } 3714 3715 clang::DeclContext * 3716 DWARFASTParserClang::GetCachedClangDeclContextForDIE (const DWARFDIE &die) 3717 { 3718 if (die) 3719 { 3720 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE()); 3721 if (pos != m_die_to_decl_ctx.end()) 3722 return pos->second; 3723 } 3724 return nullptr; 3725 } 3726 3727 void 3728 DWARFASTParserClang::LinkDeclContextToDIE (clang::DeclContext *decl_ctx, const DWARFDIE &die) 3729 { 3730 m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; 3731 // There can be many DIEs for a single decl context 3732 //m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE()); 3733 m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); 3734 } 3735 3736 bool 3737 DWARFASTParserClang::CopyUniqueClassMethodTypes (const DWARFDIE &src_class_die, 3738 const DWARFDIE &dst_class_die, 3739 lldb_private::Type *class_type, 3740 DWARFDIECollection &failures) 3741 { 3742 if (!class_type || !src_class_die || !dst_class_die) 3743 return false; 3744 if (src_class_die.Tag() != dst_class_die.Tag()) 3745 return false; 3746 3747 // We need to complete the class type so we can get all of the method types 3748 // parsed so we can then unique those types to their equivalent counterparts 3749 // in "dst_cu" and "dst_class_die" 3750 class_type->GetFullCompilerType (); 3751 3752 DWARFDIE src_die; 3753 DWARFDIE dst_die; 3754 UniqueCStringMap<DWARFDIE> src_name_to_die; 3755 UniqueCStringMap<DWARFDIE> dst_name_to_die; 3756 UniqueCStringMap<DWARFDIE> src_name_to_die_artificial; 3757 UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial; 3758 for (src_die = src_class_die.GetFirstChild(); src_die.IsValid(); src_die = src_die.GetSibling()) 3759 { 3760 if (src_die.Tag() == DW_TAG_subprogram) 3761 { 3762 // Make sure this is a declaration and not a concrete instance by looking 3763 // for DW_AT_declaration set to 1. Sometimes concrete function instances 3764 // are placed inside the class definitions and shouldn't be included in 3765 // the list of things are are tracking here. 3766 if (src_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) 3767 { 3768 const char *src_name = src_die.GetMangledName (); 3769 if (src_name) 3770 { 3771 ConstString src_const_name(src_name); 3772 if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) 3773 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die); 3774 else 3775 src_name_to_die.Append(src_const_name.GetCString(), src_die); 3776 } 3777 } 3778 } 3779 } 3780 for (dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid(); dst_die = dst_die.GetSibling()) 3781 { 3782 if (dst_die.Tag() == DW_TAG_subprogram) 3783 { 3784 // Make sure this is a declaration and not a concrete instance by looking 3785 // for DW_AT_declaration set to 1. Sometimes concrete function instances 3786 // are placed inside the class definitions and shouldn't be included in 3787 // the list of things are are tracking here. 3788 if (dst_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) 3789 { 3790 const char *dst_name = dst_die.GetMangledName (); 3791 if (dst_name) 3792 { 3793 ConstString dst_const_name(dst_name); 3794 if ( dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) 3795 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die); 3796 else 3797 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die); 3798 } 3799 } 3800 } 3801 } 3802 const uint32_t src_size = src_name_to_die.GetSize (); 3803 const uint32_t dst_size = dst_name_to_die.GetSize (); 3804 Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); 3805 3806 // Is everything kosher so we can go through the members at top speed? 3807 bool fast_path = true; 3808 3809 if (src_size != dst_size) 3810 { 3811 if (src_size != 0 && dst_size != 0) 3812 { 3813 if (log) 3814 log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)", 3815 src_class_die.GetOffset(), 3816 dst_class_die.GetOffset(), 3817 src_size, 3818 dst_size); 3819 } 3820 3821 fast_path = false; 3822 } 3823 3824 uint32_t idx; 3825 3826 if (fast_path) 3827 { 3828 for (idx = 0; idx < src_size; ++idx) 3829 { 3830 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); 3831 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); 3832 3833 if (src_die.Tag() != dst_die.Tag()) 3834 { 3835 if (log) 3836 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)", 3837 src_class_die.GetOffset(), 3838 dst_class_die.GetOffset(), 3839 src_die.GetOffset(), 3840 src_die.GetTagAsCString(), 3841 dst_die.GetOffset(), 3842 dst_die.GetTagAsCString()); 3843 fast_path = false; 3844 } 3845 3846 const char *src_name = src_die.GetMangledName (); 3847 const char *dst_name = dst_die.GetMangledName (); 3848 3849 // Make sure the names match 3850 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0)) 3851 continue; 3852 3853 if (log) 3854 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)", 3855 src_class_die.GetOffset(), 3856 dst_class_die.GetOffset(), 3857 src_die.GetOffset(), 3858 src_name, 3859 dst_die.GetOffset(), 3860 dst_name); 3861 3862 fast_path = false; 3863 } 3864 } 3865 3866 DWARFASTParserClang *src_dwarf_ast_parser = (DWARFASTParserClang *)src_die.GetDWARFParser(); 3867 DWARFASTParserClang *dst_dwarf_ast_parser = (DWARFASTParserClang *)dst_die.GetDWARFParser(); 3868 3869 // Now do the work of linking the DeclContexts and Types. 3870 if (fast_path) 3871 { 3872 // We can do this quickly. Just run across the tables index-for-index since 3873 // we know each node has matching names and tags. 3874 for (idx = 0; idx < src_size; ++idx) 3875 { 3876 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx); 3877 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx); 3878 3879 clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; 3880 if (src_decl_ctx) 3881 { 3882 if (log) 3883 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", 3884 static_cast<void*>(src_decl_ctx), 3885 src_die.GetOffset(), dst_die.GetOffset()); 3886 dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die); 3887 } 3888 else 3889 { 3890 if (log) 3891 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", 3892 src_die.GetOffset(), dst_die.GetOffset()); 3893 } 3894 3895 Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; 3896 if (src_child_type) 3897 { 3898 if (log) 3899 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", 3900 static_cast<void*>(src_child_type), 3901 src_child_type->GetID(), 3902 src_die.GetOffset(), dst_die.GetOffset()); 3903 dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; 3904 } 3905 else 3906 { 3907 if (log) 3908 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); 3909 } 3910 } 3911 } 3912 else 3913 { 3914 // We must do this slowly. For each member of the destination, look 3915 // up a member in the source with the same name, check its tag, and 3916 // unique them if everything matches up. Report failures. 3917 3918 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) 3919 { 3920 src_name_to_die.Sort(); 3921 3922 for (idx = 0; idx < dst_size; ++idx) 3923 { 3924 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx); 3925 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); 3926 src_die = src_name_to_die.Find(dst_name, DWARFDIE()); 3927 3928 if (src_die && (src_die.Tag() == dst_die.Tag())) 3929 { 3930 clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; 3931 if (src_decl_ctx) 3932 { 3933 if (log) 3934 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", 3935 static_cast<void*>(src_decl_ctx), 3936 src_die.GetOffset(), 3937 dst_die.GetOffset()); 3938 dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die); 3939 } 3940 else 3941 { 3942 if (log) 3943 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); 3944 } 3945 3946 Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; 3947 if (src_child_type) 3948 { 3949 if (log) 3950 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", 3951 static_cast<void*>(src_child_type), 3952 src_child_type->GetID(), 3953 src_die.GetOffset(), 3954 dst_die.GetOffset()); 3955 dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; 3956 } 3957 else 3958 { 3959 if (log) 3960 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); 3961 } 3962 } 3963 else 3964 { 3965 if (log) 3966 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die.GetOffset()); 3967 3968 failures.Append(dst_die); 3969 } 3970 } 3971 } 3972 } 3973 3974 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize (); 3975 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize (); 3976 3977 if (src_size_artificial && dst_size_artificial) 3978 { 3979 dst_name_to_die_artificial.Sort(); 3980 3981 for (idx = 0; idx < src_size_artificial; ++idx) 3982 { 3983 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx); 3984 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx); 3985 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE()); 3986 3987 if (dst_die) 3988 { 3989 // Both classes have the artificial types, link them 3990 clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; 3991 if (src_decl_ctx) 3992 { 3993 if (log) 3994 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", 3995 static_cast<void*>(src_decl_ctx), 3996 src_die.GetOffset(), dst_die.GetOffset()); 3997 dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die); 3998 } 3999 else 4000 { 4001 if (log) 4002 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); 4003 } 4004 4005 Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; 4006 if (src_child_type) 4007 { 4008 if (log) 4009 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", 4010 static_cast<void*>(src_child_type), 4011 src_child_type->GetID(), 4012 src_die.GetOffset(), dst_die.GetOffset()); 4013 dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; 4014 } 4015 else 4016 { 4017 if (log) 4018 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset()); 4019 } 4020 } 4021 } 4022 } 4023 4024 if (dst_size_artificial) 4025 { 4026 for (idx = 0; idx < dst_size_artificial; ++idx) 4027 { 4028 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx); 4029 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx); 4030 if (log) 4031 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die.GetOffset(), dst_name_artificial); 4032 4033 failures.Append(dst_die); 4034 } 4035 } 4036 4037 return (failures.Size() != 0); 4038 } 4039 4040