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