1 //===-- DWARFASTParserClang.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "DWARFASTParserClang.h"
13 #include "DWARFCompileUnit.h"
14 #include "DWARFDebugInfo.h"
15 #include "DWARFDeclContext.h"
16 #include "DWARFDefines.h"
18 #include "DWARFDIECollection.h"
19 #include "SymbolFileDWARF.h"
20 #include "SymbolFileDWARFDebugMap.h"
21 #include "UniqueDWARFASTType.h"
23 #include "Plugins/Language/ObjC/ObjCLanguage.h"
24 #include "lldb/Core/Log.h"
25 #include "lldb/Core/Module.h"
26 #include "lldb/Core/StreamString.h"
27 #include "lldb/Core/Value.h"
28 #include "lldb/Host/Host.h"
29 #include "lldb/Interpreter/Args.h"
30 #include "lldb/Symbol/ClangASTImporter.h"
31 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
32 #include "lldb/Symbol/ClangUtil.h"
33 #include "lldb/Symbol/CompileUnit.h"
34 #include "lldb/Symbol/Function.h"
35 #include "lldb/Symbol/ObjectFile.h"
36 #include "lldb/Symbol/SymbolVendor.h"
37 #include "lldb/Symbol/TypeList.h"
38 #include "lldb/Symbol/TypeMap.h"
39 #include "lldb/Target/Language.h"
40 #include "lldb/Utility/LLDBAssert.h"
42 #include "clang/AST/DeclCXX.h"
43 #include "clang/AST/DeclObjC.h"
48 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
50 #ifdef ENABLE_DEBUG_PRINTF
52 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
54 #define DEBUG_PRINTF(fmt, ...)
59 using namespace lldb_private;
60 DWARFASTParserClang::DWARFASTParserClang (ClangASTContext &ast) :
67 DWARFASTParserClang::~DWARFASTParserClang ()
73 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
75 switch (dwarf_accessibility)
77 case DW_ACCESS_public: return eAccessPublic;
78 case DW_ACCESS_private: return eAccessPrivate;
79 case DW_ACCESS_protected: return eAccessProtected;
86 DeclKindIsCXXClass (clang::Decl::Kind decl_kind)
90 case clang::Decl::CXXRecord:
91 case clang::Decl::ClassTemplateSpecialization:
105 bit_size(LLDB_INVALID_ADDRESS),
106 bit_offset(LLDB_INVALID_ADDRESS)
113 bit_size = LLDB_INVALID_ADDRESS;
114 bit_offset = LLDB_INVALID_ADDRESS;
120 return (bit_size != LLDB_INVALID_ADDRESS) &&
121 (bit_offset != LLDB_INVALID_ADDRESS);
125 NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const
129 // This bitfield info is valid, so any subsequent bitfields
130 // must not overlap and must be at a higher bit offset than
131 // any previous bitfield + size.
132 return (bit_size + bit_offset) <= next_bit_offset;
136 // If the this BitfieldInfo is not valid, then any offset isOK
144 DWARFASTParserClang::GetClangASTImporter()
146 if (!m_clang_ast_importer_ap)
148 m_clang_ast_importer_ap.reset (new ClangASTImporter);
150 return *m_clang_ast_importer_ap;
155 DWARFASTParserClang::ParseTypeFromDWO (const DWARFDIE &die, Log *log)
157 ModuleSP dwo_module_sp = die.GetContainingDWOModule();
160 // This type comes from an external DWO module
161 std::vector<CompilerContext> dwo_context;
162 die.GetDWOContext(dwo_context);
164 if (dwo_module_sp->GetSymbolVendor()->FindTypes(dwo_context, true, dwo_types))
166 const size_t num_dwo_types = dwo_types.GetSize();
167 if (num_dwo_types == 1)
169 // We found a real definition for this type elsewhere
170 // so lets use it and cache the fact that we found
171 // a complete type for this die
172 TypeSP dwo_type_sp = dwo_types.GetTypeAtIndex(0);
175 lldb_private::CompilerType dwo_type = dwo_type_sp->GetForwardCompilerType();
177 lldb_private::CompilerType type = GetClangASTImporter().CopyType (m_ast, dwo_type);
179 //printf ("copied_qual_type: ast = %p, clang_type = %p, name = '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(), external_type->GetName().GetCString());
182 SymbolFileDWARF *dwarf = die.GetDWARF();
183 TypeSP type_sp (new Type (die.GetID(),
185 dwo_type_sp->GetName(),
186 dwo_type_sp->GetByteSize(),
189 Type::eEncodingInvalid,
190 &dwo_type_sp->GetDeclaration(),
192 Type::eResolveStateForward));
194 dwarf->GetTypeList()->Insert(type_sp);
195 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
196 clang::TagDecl *tag_decl = ClangASTContext::GetAsTagDecl(type);
198 LinkDeclContextToDIE(tag_decl, die);
201 clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die);
203 LinkDeclContextToDIE(defn_decl_ctx, die);
215 DWARFASTParserClang::ParseTypeFromDWARF (const SymbolContext& sc,
218 bool *type_is_new_ptr)
223 *type_is_new_ptr = false;
225 AccessType accessibility = eAccessNone;
228 SymbolFileDWARF *dwarf = die.GetDWARF();
231 DWARFDIE context_die;
232 clang::DeclContext *context = GetClangDeclContextContainingDIE (die, &context_die);
234 dwarf->GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
236 static_cast<void*>(context),
237 context_die.GetOffset(),
238 die.GetTagAsCString(),
243 // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
244 // if (log && dwarf_cu)
247 // die->DumpLocation (this, dwarf_cu, s);
248 // dwarf->GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
252 Type *type_ptr = dwarf->GetDIEToType().lookup (die.GetDIE());
253 TypeList* type_list = dwarf->GetTypeList();
254 if (type_ptr == NULL)
257 *type_is_new_ptr = true;
259 const dw_tag_t tag = die.Tag();
261 bool is_forward_declaration = false;
262 DWARFAttributes attributes;
263 const char *type_name_cstr = NULL;
264 ConstString type_name_const_str;
265 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
266 uint64_t byte_size = 0;
269 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
270 CompilerType clang_type;
271 DWARFFormValue form_value;
278 case DW_TAG_base_type:
279 case DW_TAG_pointer_type:
280 case DW_TAG_reference_type:
281 case DW_TAG_rvalue_reference_type:
282 case DW_TAG_const_type:
283 case DW_TAG_restrict_type:
284 case DW_TAG_volatile_type:
285 case DW_TAG_unspecified_type:
287 // Set a bit that lets us know that we are currently parsing this
288 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
290 const size_t num_attributes = die.GetAttributes (attributes);
291 uint32_t encoding = 0;
292 DWARFFormValue encoding_uid;
294 if (num_attributes > 0)
297 for (i=0; i<num_attributes; ++i)
299 attr = attributes.AttributeAtIndex(i);
300 if (attributes.ExtractFormValueAtIndex(i, form_value))
304 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
305 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
306 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
309 type_name_cstr = form_value.AsCString();
310 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
311 // include the "&"...
312 if (tag == DW_TAG_reference_type)
314 if (strchr (type_name_cstr, '&') == NULL)
315 type_name_cstr = NULL;
318 type_name_const_str.SetCString(type_name_cstr);
320 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
321 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
322 case DW_AT_type: encoding_uid = form_value; break;
331 if (tag == DW_TAG_typedef && encoding_uid.IsValid())
333 // Try to parse a typedef from the DWO file first as modules
334 // can contain typedef'ed structures that have no names like:
336 // typedef struct { int a; } Foo;
338 // In this case we will have a structure with no name and a
339 // typedef named "Foo" that points to this unnamed structure.
340 // The name in the typedef is the only identifier for the struct,
341 // so always try to get typedefs from DWO files if possible.
343 // The type_sp returned will be empty if the typedef doesn't exist
344 // in a DWO file, so it is cheap to call this function just to check.
346 // If we don't do this we end up creating a TypeSP that says this
347 // is a typedef to type 0x123 (the DW_AT_type value would be 0x123
348 // in the DW_TAG_typedef), and this is the unnamed structure type.
349 // We will have a hard time tracking down an unnammed structure
350 // type in the module DWO file, so we make sure we don't get into
351 // this situation by always resolving typedefs from the DWO file.
352 const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid));
354 // First make sure that the die that this is typedef'ed to _is_
355 // just a declaration (DW_AT_declaration == 1), not a full definition
356 // since template types can't be represented in modules since only
357 // concrete instances of templates are ever emitted and modules
358 // won't contain those
359 if (encoding_die && encoding_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1)
361 type_sp = ParseTypeFromDWO(die, log);
367 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid.Reference());
374 case DW_TAG_unspecified_type:
375 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
376 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
378 resolve_state = Type::eResolveStateFull;
379 clang_type = m_ast.GetBasicType(eBasicTypeNullPtr);
382 // Fall through to base type below in case we can handle the type there...
385 case DW_TAG_base_type:
386 resolve_state = Type::eResolveStateFull;
387 clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
392 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
393 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
394 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
395 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
396 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
397 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
398 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
401 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
403 if (tag == DW_TAG_pointer_type)
405 DWARFDIE target_die = die.GetReferencedDIE(DW_AT_type);
407 if (target_die.GetAttributeValueAsUnsigned(DW_AT_APPLE_block, 0))
409 // Blocks have a __FuncPtr inside them which is a pointer to a function of the proper type.
411 for (DWARFDIE child_die = target_die.GetFirstChild();
413 child_die = child_die.GetSibling())
415 if (!strcmp(child_die.GetAttributeValueAsString(DW_AT_name, ""), "__FuncPtr"))
417 DWARFDIE function_pointer_type = child_die.GetReferencedDIE(DW_AT_type);
419 if (function_pointer_type)
421 DWARFDIE function_type = function_pointer_type.GetReferencedDIE(DW_AT_type);
423 bool function_type_is_new_pointer;
424 TypeSP lldb_function_type_sp = ParseTypeFromDWARF(sc, function_type, log, &function_type_is_new_pointer);
426 if (lldb_function_type_sp)
428 clang_type = m_ast.CreateBlockPointerType(lldb_function_type_sp->GetForwardCompilerType());
429 encoding_data_type = Type::eEncodingIsUID;
430 encoding_uid.Clear();
431 resolve_state = Type::eResolveStateFull;
441 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
443 if (translation_unit_is_objc)
445 if (type_name_cstr != NULL)
447 static ConstString g_objc_type_name_id("id");
448 static ConstString g_objc_type_name_Class("Class");
449 static ConstString g_objc_type_name_selector("SEL");
451 if (type_name_const_str == g_objc_type_name_id)
454 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
455 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
457 die.GetTagAsCString(),
459 clang_type = m_ast.GetBasicType(eBasicTypeObjCID);
460 encoding_data_type = Type::eEncodingIsUID;
461 encoding_uid.Clear();
462 resolve_state = Type::eResolveStateFull;
465 else if (type_name_const_str == g_objc_type_name_Class)
468 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
469 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
471 die.GetTagAsCString(),
473 clang_type = m_ast.GetBasicType(eBasicTypeObjCClass);
474 encoding_data_type = Type::eEncodingIsUID;
475 encoding_uid.Clear();
476 resolve_state = Type::eResolveStateFull;
478 else if (type_name_const_str == g_objc_type_name_selector)
481 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
482 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
484 die.GetTagAsCString(),
486 clang_type = m_ast.GetBasicType(eBasicTypeObjCSel);
487 encoding_data_type = Type::eEncodingIsUID;
488 encoding_uid.Clear();
489 resolve_state = Type::eResolveStateFull;
492 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid.IsValid())
494 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
496 const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid));
498 if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type)
500 if (const char *struct_name = encoding_die.GetName())
502 if (!strcmp(struct_name, "objc_object"))
505 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
506 "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
508 die.GetTagAsCString(),
510 clang_type = m_ast.GetBasicType(eBasicTypeObjCID);
511 encoding_data_type = Type::eEncodingIsUID;
512 encoding_uid.Clear();
513 resolve_state = Type::eResolveStateFull;
521 type_sp.reset( new Type (die.GetID(),
526 DIERef(encoding_uid).GetUID(dwarf),
532 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
534 // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
535 // if (encoding_type != NULL)
537 // if (encoding_type != DIE_IS_BEING_PARSED)
538 // type_sp->SetEncodingType(encoding_type);
540 // m_indirect_fixups.push_back(type_sp.get());
545 case DW_TAG_structure_type:
546 case DW_TAG_union_type:
547 case DW_TAG_class_type:
549 // Set a bit that lets us know that we are currently parsing this
550 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
551 bool byte_size_valid = false;
553 LanguageType class_language = eLanguageTypeUnknown;
554 bool is_complete_objc_class = false;
555 //bool struct_is_class = false;
556 const size_t num_attributes = die.GetAttributes (attributes);
557 if (num_attributes > 0)
560 for (i=0; i<num_attributes; ++i)
562 attr = attributes.AttributeAtIndex(i);
563 if (attributes.ExtractFormValueAtIndex(i, form_value))
567 case DW_AT_decl_file:
568 if (die.GetCU()->DW_AT_decl_file_attributes_are_invalid())
570 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
571 // point to the compile unit file, so we clear this invalid value
572 // so that we can still unique types efficiently.
573 decl.SetFile(FileSpec ("<invalid>", false));
576 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
579 case DW_AT_decl_line:
580 decl.SetLine(form_value.Unsigned());
583 case DW_AT_decl_column:
584 decl.SetColumn(form_value.Unsigned());
588 type_name_cstr = form_value.AsCString();
589 type_name_const_str.SetCString(type_name_cstr);
592 case DW_AT_byte_size:
593 byte_size = form_value.Unsigned();
594 byte_size_valid = true;
597 case DW_AT_accessibility:
598 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
601 case DW_AT_declaration:
602 is_forward_declaration = form_value.Boolean();
605 case DW_AT_APPLE_runtime_class:
606 class_language = (LanguageType)form_value.Signed();
609 case DW_AT_APPLE_objc_complete_type:
610 is_complete_objc_class = form_value.Signed();
613 case DW_AT_allocated:
614 case DW_AT_associated:
615 case DW_AT_data_location:
616 case DW_AT_description:
617 case DW_AT_start_scope:
618 case DW_AT_visibility:
627 // UniqueDWARFASTType is large, so don't create a local variables on the
628 // stack, put it on the heap. This function is often called recursively
629 // and clang isn't good and sharing the stack space for variables in different blocks.
630 std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap(new UniqueDWARFASTType());
632 ConstString unique_typename(type_name_const_str);
633 Declaration unique_decl(decl);
635 if (type_name_const_str)
637 LanguageType die_language = die.GetLanguage();
638 if (Language::LanguageIsCPlusPlus(die_language))
640 // For C++, we rely solely upon the one definition rule that says only
641 // one thing can exist at a given decl context. We ignore the file and
642 // line that things are declared on.
643 std::string qualified_name;
644 if (die.GetQualifiedName(qualified_name))
645 unique_typename = ConstString(qualified_name);
649 if (dwarf->GetUniqueDWARFASTTypeMap().Find(unique_typename, die, unique_decl,
650 byte_size_valid ? byte_size : -1,
651 *unique_ast_entry_ap))
653 type_sp = unique_ast_entry_ap->m_type_sp;
656 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
662 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr);
664 int tag_decl_kind = -1;
665 AccessType default_accessibility = eAccessNone;
666 if (tag == DW_TAG_structure_type)
668 tag_decl_kind = clang::TTK_Struct;
669 default_accessibility = eAccessPublic;
671 else if (tag == DW_TAG_union_type)
673 tag_decl_kind = clang::TTK_Union;
674 default_accessibility = eAccessPublic;
676 else if (tag == DW_TAG_class_type)
678 tag_decl_kind = clang::TTK_Class;
679 default_accessibility = eAccessPrivate;
682 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
683 die.HasChildren() == false &&
684 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
686 // Work around an issue with clang at the moment where
687 // forward declarations for objective C classes are emitted
689 // DW_TAG_structure_type [2]
690 // DW_AT_name( "ForwardObjcClass" )
691 // DW_AT_byte_size( 0x00 )
692 // DW_AT_decl_file( "..." )
693 // DW_AT_decl_line( 1 )
695 // Note that there is no DW_AT_declaration and there are
696 // no children, and the byte size is zero.
697 is_forward_declaration = true;
700 if (class_language == eLanguageTypeObjC ||
701 class_language == eLanguageTypeObjC_plus_plus)
703 if (!is_complete_objc_class && die.Supports_DW_AT_APPLE_objc_complete_type())
705 // We have a valid eSymbolTypeObjCClass class symbol whose
706 // name matches the current objective C class that we
707 // are trying to find and this DIE isn't the complete
708 // definition (we checked is_complete_objc_class above and
709 // know it is false), so the real definition is in here somewhere
710 type_sp = dwarf->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
714 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
715 if (debug_map_symfile)
717 // We weren't able to find a full declaration in
718 // this DWARF, see if we have a declaration anywhere
720 type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
728 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
729 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
730 static_cast<void*>(this),
732 DW_TAG_value_to_name(tag),
737 // We found a real definition for this type elsewhere
738 // so lets use it and cache the fact that we found
739 // a complete type for this die
740 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
747 if (is_forward_declaration)
749 // We have a forward declaration to a type and we need
750 // to try and find a full declaration. We look in the
751 // current type index just in case we have a forward
752 // declaration followed by an actual declarations in the
753 // DWARF. If this fails, we need to look elsewhere...
756 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
757 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
758 static_cast<void*>(this),
760 DW_TAG_value_to_name(tag),
764 // See if the type comes from a DWO module and if so, track down that type.
765 type_sp = ParseTypeFromDWO(die, log);
769 DWARFDeclContext die_decl_ctx;
770 die.GetDWARFDeclContext(die_decl_ctx);
772 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
773 type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
777 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
778 if (debug_map_symfile)
780 // We weren't able to find a full declaration in
781 // this DWARF, see if we have a declaration anywhere
783 type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
791 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
792 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
793 static_cast<void*>(this),
795 DW_TAG_value_to_name(tag),
800 // We found a real definition for this type elsewhere
801 // so lets use it and cache the fact that we found
802 // a complete type for this die
803 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
804 clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(
805 dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID(), dwarf)));
807 LinkDeclContextToDIE(defn_decl_ctx, die);
811 assert (tag_decl_kind != -1);
812 bool clang_type_was_created = false;
813 clang_type.SetCompilerType(&m_ast, dwarf->GetForwardDeclDieToClangType().lookup (die.GetDIE()));
816 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (die, nullptr);
817 if (accessibility == eAccessNone && decl_ctx)
819 // Check the decl context that contains this class/struct/union.
820 // If it is a class we must give it an accessibility.
821 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
822 if (DeclKindIsCXXClass (containing_decl_kind))
823 accessibility = default_accessibility;
826 ClangASTMetadata metadata;
827 metadata.SetUserID(die.GetID());
828 metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual (die));
830 if (type_name_cstr && strchr (type_name_cstr, '<'))
832 ClangASTContext::TemplateParameterInfos template_param_infos;
833 if (ParseTemplateParameterInfos (die, template_param_infos))
835 clang::ClassTemplateDecl *class_template_decl = m_ast.ParseClassTemplateDecl (decl_ctx,
839 template_param_infos);
841 clang::ClassTemplateSpecializationDecl *class_specialization_decl = m_ast.CreateClassTemplateSpecializationDecl (decl_ctx,
844 template_param_infos);
845 clang_type = m_ast.CreateClassTemplateSpecializationType (class_specialization_decl);
846 clang_type_was_created = true;
848 m_ast.SetMetadata (class_template_decl, metadata);
849 m_ast.SetMetadata (class_specialization_decl, metadata);
853 if (!clang_type_was_created)
855 clang_type_was_created = true;
856 clang_type = m_ast.CreateRecordType (decl_ctx,
865 // Store a forward declaration to this class type in case any
866 // parameters in any class methods need it for the clang
867 // types for function prototypes.
868 LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die);
869 type_sp.reset (new Type (die.GetID(),
875 Type::eEncodingIsUID,
878 Type::eResolveStateForward));
880 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
883 // Add our type to the unique type map so we don't
884 // end up creating many copies of the same type over
885 // and over in the ASTContext for our module
886 unique_ast_entry_ap->m_type_sp = type_sp;
887 unique_ast_entry_ap->m_die = die;
888 unique_ast_entry_ap->m_declaration = unique_decl;
889 unique_ast_entry_ap->m_byte_size = byte_size;
890 dwarf->GetUniqueDWARFASTTypeMap().Insert (unique_typename,
891 *unique_ast_entry_ap);
893 if (is_forward_declaration && die.HasChildren())
895 // Check to see if the DIE actually has a definition, some version of GCC will
896 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
897 // members, or inheritance, so we can't trust it
898 DWARFDIE child_die = die.GetFirstChild();
901 switch (child_die.Tag())
903 case DW_TAG_inheritance:
904 case DW_TAG_subprogram:
906 case DW_TAG_APPLE_property:
907 case DW_TAG_class_type:
908 case DW_TAG_structure_type:
909 case DW_TAG_enumeration_type:
911 case DW_TAG_union_type:
913 is_forward_declaration = false;
916 child_die = child_die.GetSibling();
922 if (!is_forward_declaration)
924 // Always start the definition for a class type so that
925 // if the class has child classes or types that require
926 // the class to be created for use as their decl contexts
927 // the class will be ready to accept these child definitions.
928 if (die.HasChildren() == false)
930 // No children for this struct/union/class, lets finish it
931 if (ClangASTContext::StartTagDeclarationDefinition (clang_type))
933 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
937 dwarf->GetObjectFile()->GetModule()->ReportError("DWARF DIE at 0x%8.8x named \"%s\" was not able to start its definition.\nPlease file a bug and attach the file at the start of this error message",
942 if (tag == DW_TAG_structure_type) // this only applies in C
944 clang::RecordDecl *record_decl = ClangASTContext::GetAsRecordDecl(clang_type);
948 GetClangASTImporter().InsertRecordDecl(record_decl, ClangASTImporter::LayoutInfo());
952 else if (clang_type_was_created)
954 // Start the definition if the class is not objective C since
955 // the underlying decls respond to isCompleteDefinition(). Objective
956 // C decls don't respond to isCompleteDefinition() so we can't
957 // start the declaration definition right away. For C++ class/union/structs
958 // we want to start the definition in case the class is needed as the
959 // declaration context for a contained class or type without the need
960 // to complete that type..
962 if (class_language != eLanguageTypeObjC &&
963 class_language != eLanguageTypeObjC_plus_plus)
964 ClangASTContext::StartTagDeclarationDefinition (clang_type);
966 // Leave this as a forward declaration until we need
967 // to know the details of the type. lldb_private::Type
968 // will automatically call the SymbolFile virtual function
969 // "SymbolFileDWARF::CompleteType(Type *)"
970 // When the definition needs to be defined.
971 assert(!dwarf->GetForwardDeclClangTypeToDie().count(
972 ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType()) &&
973 "Type already in the forward declaration map!");
974 // Can't assume m_ast.GetSymbolFile() is actually a SymbolFileDWARF, it can be a
975 // SymbolFileDWARFDebugMap for Apple binaries.
976 dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = clang_type.GetOpaqueQualType();
977 dwarf->GetForwardDeclClangTypeToDie()[ClangUtil::RemoveFastQualifiers(clang_type)
978 .GetOpaqueQualType()] = die.GetDIERef();
979 m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), true);
985 case DW_TAG_enumeration_type:
987 // Set a bit that lets us know that we are currently parsing this
988 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
990 DWARFFormValue encoding_form;
992 const size_t num_attributes = die.GetAttributes (attributes);
993 if (num_attributes > 0)
997 for (i=0; i<num_attributes; ++i)
999 attr = attributes.AttributeAtIndex(i);
1000 if (attributes.ExtractFormValueAtIndex(i, form_value))
1004 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1005 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1006 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1008 type_name_cstr = form_value.AsCString();
1009 type_name_const_str.SetCString(type_name_cstr);
1011 case DW_AT_type: encoding_form = form_value; break;
1012 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1013 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
1014 case DW_AT_declaration: is_forward_declaration = form_value.Boolean(); break;
1015 case DW_AT_allocated:
1016 case DW_AT_associated:
1017 case DW_AT_bit_stride:
1018 case DW_AT_byte_stride:
1019 case DW_AT_data_location:
1020 case DW_AT_description:
1021 case DW_AT_start_scope:
1022 case DW_AT_visibility:
1023 case DW_AT_specification:
1024 case DW_AT_abstract_origin:
1031 if (is_forward_declaration)
1033 type_sp = ParseTypeFromDWO(die, log);
1037 DWARFDeclContext die_decl_ctx;
1038 die.GetDWARFDeclContext(die_decl_ctx);
1040 type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
1044 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
1045 if (debug_map_symfile)
1047 // We weren't able to find a full declaration in
1048 // this DWARF, see if we have a declaration anywhere
1050 type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
1058 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
1059 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
1060 static_cast<void*>(this),
1062 DW_TAG_value_to_name(tag),
1067 // We found a real definition for this type elsewhere
1068 // so lets use it and cache the fact that we found
1069 // a complete type for this die
1070 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1071 clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID(), dwarf)));
1073 LinkDeclContextToDIE(defn_decl_ctx, die);
1078 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr);
1080 CompilerType enumerator_clang_type;
1081 clang_type.SetCompilerType (&m_ast, dwarf->GetForwardDeclDieToClangType().lookup (die.GetDIE()));
1084 if (encoding_form.IsValid())
1086 Type *enumerator_type = dwarf->ResolveTypeUID(DIERef(encoding_form));
1087 if (enumerator_type)
1088 enumerator_clang_type = enumerator_type->GetFullCompilerType ();
1091 if (!enumerator_clang_type)
1095 enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(NULL,
1101 enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt);
1105 clang_type = m_ast.CreateEnumerationType (type_name_cstr,
1106 GetClangDeclContextContainingDIE (die, nullptr),
1108 enumerator_clang_type);
1112 enumerator_clang_type = m_ast.GetEnumerationIntegerType (clang_type.GetOpaqueQualType());
1115 LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
1117 type_sp.reset( new Type (die.GetID(),
1119 type_name_const_str,
1122 DIERef(encoding_form).GetUID(dwarf),
1123 Type::eEncodingIsUID,
1126 Type::eResolveStateForward));
1128 if (ClangASTContext::StartTagDeclarationDefinition (clang_type))
1130 if (die.HasChildren())
1132 SymbolContext cu_sc(die.GetLLDBCompileUnit());
1133 bool is_signed = false;
1134 enumerator_clang_type.IsIntegerType(is_signed);
1135 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), die);
1137 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
1141 dwarf->GetObjectFile()->GetModule()->ReportError("DWARF DIE at 0x%8.8x named \"%s\" was not able to start its definition.\nPlease file a bug and attach the file at the start of this error message",
1149 case DW_TAG_inlined_subroutine:
1150 case DW_TAG_subprogram:
1151 case DW_TAG_subroutine_type:
1153 // Set a bit that lets us know that we are currently parsing this
1154 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
1156 DWARFFormValue type_die_form;
1157 bool is_variadic = false;
1158 bool is_inline = false;
1159 bool is_static = false;
1160 bool is_virtual = false;
1161 bool is_explicit = false;
1162 bool is_artificial = false;
1163 bool has_template_params = false;
1164 DWARFFormValue specification_die_form;
1165 DWARFFormValue abstract_origin_die_form;
1166 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
1168 unsigned type_quals = 0;
1169 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
1172 const size_t num_attributes = die.GetAttributes (attributes);
1173 if (num_attributes > 0)
1176 for (i=0; i<num_attributes; ++i)
1178 attr = attributes.AttributeAtIndex(i);
1179 if (attributes.ExtractFormValueAtIndex(i, form_value))
1183 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1184 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1185 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1187 type_name_cstr = form_value.AsCString();
1188 type_name_const_str.SetCString(type_name_cstr);
1191 case DW_AT_linkage_name:
1192 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&dwarf->get_debug_str_data()); break;
1193 case DW_AT_type: type_die_form = form_value; break;
1194 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
1195 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
1196 case DW_AT_inline: is_inline = form_value.Boolean(); break;
1197 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
1198 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
1199 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
1202 case DW_AT_external:
1203 if (form_value.Unsigned())
1205 if (storage == clang::SC_None)
1206 storage = clang::SC_Extern;
1208 storage = clang::SC_PrivateExtern;
1212 case DW_AT_specification:
1213 specification_die_form = form_value;
1216 case DW_AT_abstract_origin:
1217 abstract_origin_die_form = form_value;
1220 case DW_AT_object_pointer:
1221 object_pointer_die_offset = form_value.Reference();
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:
1234 case DW_AT_prototyped:
1237 case DW_AT_recursive:
1238 case DW_AT_return_addr:
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:
1253 std::string object_pointer_name;
1254 if (object_pointer_die_offset != DW_INVALID_OFFSET)
1256 DWARFDIE object_pointer_die = die.GetDIE (object_pointer_die_offset);
1257 if (object_pointer_die)
1259 const char *object_pointer_name_cstr = object_pointer_die.GetName();
1260 if (object_pointer_name_cstr)
1261 object_pointer_name = object_pointer_name_cstr;
1265 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr);
1267 CompilerType return_clang_type;
1268 Type *func_type = NULL;
1270 if (type_die_form.IsValid())
1271 func_type = dwarf->ResolveTypeUID(DIERef(type_die_form));
1274 return_clang_type = func_type->GetForwardCompilerType ();
1276 return_clang_type = m_ast.GetBasicType(eBasicTypeVoid);
1279 std::vector<CompilerType> function_param_types;
1280 std::vector<clang::ParmVarDecl*> function_param_decls;
1282 // Parse the function children for the parameters
1284 DWARFDIE decl_ctx_die;
1285 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (die, &decl_ctx_die);
1286 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
1288 bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
1289 // Start off static. This will be set to false in ParseChildParameters(...)
1290 // if we find a "this" parameters as the first parameter
1296 if (die.HasChildren())
1298 bool skip_artificial = true;
1299 ParseChildParameters (sc,
1300 containing_decl_ctx,
1305 has_template_params,
1306 function_param_types,
1307 function_param_decls,
1311 bool ignore_containing_context = false;
1312 // Check for templatized class member functions. If we had any DW_TAG_template_type_parameter
1313 // or DW_TAG_template_value_parameter the DW_TAG_subprogram DIE, then we can't let this become
1314 // a method in a class. Why? Because templatized functions are only emitted if one of the
1315 // templatized methods is used in the current compile unit and we will end up with classes
1316 // that may or may not include these member functions and this means one class won't match another
1317 // class definition and it affects our ability to use a class in the clang expression parser. So
1318 // for the greater good, we currently must not allow any template member functions in a class definition.
1319 if (is_cxx_method && has_template_params)
1321 ignore_containing_context = true;
1322 is_cxx_method = false;
1325 // clang_type will get the function prototype clang type after this call
1326 clang_type = m_ast.CreateFunctionType (return_clang_type,
1327 function_param_types.data(),
1328 function_param_types.size(),
1335 bool type_handled = false;
1336 if (tag == DW_TAG_subprogram ||
1337 tag == DW_TAG_inlined_subroutine)
1339 ObjCLanguage::MethodName objc_method (type_name_cstr, true);
1340 if (objc_method.IsValid(true))
1342 CompilerType class_opaque_type;
1343 ConstString class_name(objc_method.GetClassName());
1346 TypeSP complete_objc_class_type_sp (dwarf->FindCompleteObjCDefinitionTypeForDIE (DWARFDIE(), class_name, false));
1348 if (complete_objc_class_type_sp)
1350 CompilerType type_clang_forward_type = complete_objc_class_type_sp->GetForwardCompilerType ();
1351 if (ClangASTContext::IsObjCObjectOrInterfaceType(type_clang_forward_type))
1352 class_opaque_type = type_clang_forward_type;
1356 if (class_opaque_type)
1358 // If accessibility isn't set to anything valid, assume public for
1360 if (accessibility == eAccessNone)
1361 accessibility = eAccessPublic;
1363 clang::ObjCMethodDecl *objc_method_decl = m_ast.AddMethodToObjCObjectType (class_opaque_type,
1369 type_handled = objc_method_decl != NULL;
1372 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
1373 m_ast.SetMetadataAsUserID (objc_method_decl, die.GetID());
1377 dwarf->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
1380 DW_TAG_value_to_name(tag));
1384 else if (is_cxx_method)
1386 // Look at the parent of this DIE and see if is is
1387 // a class or struct and see if this is actually a
1389 Type *class_type = dwarf->ResolveType (decl_ctx_die);
1392 bool alternate_defn = false;
1393 if (class_type->GetID() != decl_ctx_die.GetID() || decl_ctx_die.GetContainingDWOModuleDIE())
1395 alternate_defn = true;
1397 // We uniqued the parent class of this function to another class
1398 // so we now need to associate all dies under "decl_ctx_die" to
1399 // DIEs in the DIE for "class_type"...
1400 SymbolFileDWARF *class_symfile = NULL;
1401 DWARFDIE class_type_die;
1403 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
1404 if (debug_map_symfile)
1406 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
1407 class_type_die = class_symfile->DebugInfo()->GetDIE (DIERef(class_type->GetID(), dwarf));
1411 class_symfile = dwarf;
1412 class_type_die = dwarf->DebugInfo()->GetDIE (DIERef(class_type->GetID(), dwarf));
1416 DWARFDIECollection failures;
1418 CopyUniqueClassMethodTypes (decl_ctx_die,
1423 // FIXME do something with these failures that's smarter than
1424 // just dropping them on the ground. Unfortunately classes don't
1425 // like having stuff added to them after their definitions are
1428 type_ptr = dwarf->GetDIEToType()[die.GetDIE()];
1429 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
1431 type_sp = type_ptr->shared_from_this();
1437 if (specification_die_form.IsValid())
1439 // We have a specification which we are going to base our function
1440 // prototype off of, so we need this type to be completed so that the
1441 // m_die_to_decl_ctx for the method in the specification has a valid
1442 // clang decl context.
1443 class_type->GetForwardCompilerType ();
1444 // If we have a specification, then the function type should have been
1445 // made with the specification and not with this die.
1446 DWARFDIE spec_die = dwarf->DebugInfo()->GetDIE(DIERef(specification_die_form));
1447 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (spec_die);
1448 if (spec_clang_decl_ctx)
1450 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
1454 dwarf->GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8" PRIx64 ") has no decl\n",
1456 specification_die_form.Reference());
1458 type_handled = true;
1460 else if (abstract_origin_die_form.IsValid())
1462 // We have a specification which we are going to base our function
1463 // prototype off of, so we need this type to be completed so that the
1464 // m_die_to_decl_ctx for the method in the abstract origin has a valid
1465 // clang decl context.
1466 class_type->GetForwardCompilerType ();
1468 DWARFDIE abs_die = dwarf->DebugInfo()->GetDIE (DIERef(abstract_origin_die_form));
1469 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (abs_die);
1470 if (abs_clang_decl_ctx)
1472 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
1476 dwarf->GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8" PRIx64 ") has no decl\n",
1478 abstract_origin_die_form.Reference());
1480 type_handled = true;
1484 CompilerType class_opaque_type = class_type->GetForwardCompilerType ();
1485 if (ClangASTContext::IsCXXClassType(class_opaque_type))
1487 if (class_opaque_type.IsBeingDefined () || alternate_defn)
1489 if (!is_static && !die.HasChildren())
1491 // We have a C++ member function with no children (this pointer!)
1492 // and clang will get mad if we try and make a function that isn't
1493 // well formed in the DWARF, so we will just skip it...
1494 type_handled = true;
1498 bool add_method = true;
1501 // If an alternate definition for the class exists, then add the method only if an
1502 // equivalent is not already present.
1503 clang::CXXRecordDecl *record_decl = m_ast.GetAsCXXRecordDecl(class_opaque_type.GetOpaqueQualType());
1506 for (auto method_iter = record_decl->method_begin();
1507 method_iter != record_decl->method_end();
1510 clang::CXXMethodDecl *method_decl = *method_iter;
1511 if (method_decl->getNameInfo().getAsString() == std::string(type_name_cstr))
1513 if (method_decl->getType() ==
1514 ClangUtil::GetQualType(clang_type))
1517 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(method_decl), die);
1518 type_handled = true;
1529 // REMOVE THE CRASH DESCRIPTION BELOW
1530 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s",
1532 class_type->GetName().GetCString(),
1534 dwarf->GetObjectFile()->GetFileSpec().GetPath().c_str());
1536 const bool is_attr_used = false;
1537 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
1538 // in the DWARF for C++ methods... Default to public for now...
1539 if (accessibility == eAccessNone)
1540 accessibility = eAccessPublic;
1542 clang::CXXMethodDecl *cxx_method_decl;
1543 cxx_method_decl = m_ast.AddMethodToCXXRecordType (class_opaque_type.GetOpaqueQualType(),
1554 type_handled = cxx_method_decl != NULL;
1558 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
1560 Host::SetCrashDescription (NULL);
1562 ClangASTMetadata metadata;
1563 metadata.SetUserID(die.GetID());
1565 if (!object_pointer_name.empty())
1567 metadata.SetObjectPtrName(object_pointer_name.c_str());
1569 log->Printf ("Setting object pointer name: %s on method object %p.\n",
1570 object_pointer_name.c_str(),
1571 static_cast<void*>(cxx_method_decl));
1573 m_ast.SetMetadata (cxx_method_decl, metadata);
1577 ignore_containing_context = true;
1584 // We were asked to parse the type for a method in a class, yet the
1585 // class hasn't been asked to complete itself through the
1586 // clang::ExternalASTSource protocol, so we need to just have the
1587 // class complete itself and do things the right way, then our
1588 // DIE should then have an entry in the dwarf->GetDIEToType() map. First
1589 // we need to modify the dwarf->GetDIEToType() so it doesn't think we are
1590 // trying to parse this DIE anymore...
1591 dwarf->GetDIEToType()[die.GetDIE()] = NULL;
1593 // Now we get the full type to force our class type to complete itself
1594 // using the clang::ExternalASTSource protocol which will parse all
1595 // base classes and all methods (including the method for this DIE).
1596 class_type->GetFullCompilerType ();
1598 // The type for this DIE should have been filled in the function call above
1599 type_ptr = dwarf->GetDIEToType()[die.GetDIE()];
1600 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
1602 type_sp = type_ptr->shared_from_this();
1606 // FIXME This is fixing some even uglier behavior but we really need to
1607 // uniq the methods of each class as well as the class itself.
1608 // <rdar://problem/11240464>
1609 type_handled = true;
1619 clang::FunctionDecl *function_decl = nullptr;
1621 if (abstract_origin_die_form.IsValid())
1623 DWARFDIE abs_die = dwarf->DebugInfo()->GetDIE (DIERef(abstract_origin_die_form));
1627 if (dwarf->ResolveType (abs_die))
1629 function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(GetCachedClangDeclContextForDIE(abs_die));
1633 LinkDeclContextToDIE(function_decl, die);
1640 // We just have a function that isn't part of a class
1641 function_decl = m_ast.CreateFunctionDeclaration (ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx,
1647 // if (template_param_infos.GetSize() > 0)
1649 // clang::FunctionTemplateDecl *func_template_decl = CreateFunctionTemplateDecl (containing_decl_ctx,
1652 // template_param_infos);
1654 // CreateFunctionTemplateSpecializationInfo (function_decl,
1655 // func_template_decl,
1656 // template_param_infos);
1658 // Add the decl to our DIE to decl context map
1660 lldbassert (function_decl);
1664 LinkDeclContextToDIE(function_decl, die);
1666 if (!function_param_decls.empty())
1667 m_ast.SetFunctionParameters (function_decl,
1668 &function_param_decls.front(),
1669 function_param_decls.size());
1671 ClangASTMetadata metadata;
1672 metadata.SetUserID(die.GetID());
1674 if (!object_pointer_name.empty())
1676 metadata.SetObjectPtrName(object_pointer_name.c_str());
1678 log->Printf ("Setting object pointer name: %s on function object %p.",
1679 object_pointer_name.c_str(),
1680 static_cast<void*>(function_decl));
1682 m_ast.SetMetadata (function_decl, metadata);
1687 type_sp.reset( new Type (die.GetID(),
1689 type_name_const_str,
1693 Type::eEncodingIsUID,
1696 Type::eResolveStateFull));
1697 assert(type_sp.get());
1701 case DW_TAG_array_type:
1703 // Set a bit that lets us know that we are currently parsing this
1704 dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
1706 DWARFFormValue type_die_form;
1707 int64_t first_index = 0;
1708 uint32_t byte_stride = 0;
1709 uint32_t bit_stride = 0;
1710 bool is_vector = false;
1711 const size_t num_attributes = die.GetAttributes (attributes);
1713 if (num_attributes > 0)
1716 for (i=0; i<num_attributes; ++i)
1718 attr = attributes.AttributeAtIndex(i);
1719 if (attributes.ExtractFormValueAtIndex(i, form_value))
1723 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1724 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1725 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1727 type_name_cstr = form_value.AsCString();
1728 type_name_const_str.SetCString(type_name_cstr);
1731 case DW_AT_type: type_die_form = form_value; break;
1732 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
1733 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
1734 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
1735 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
1736 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
1737 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
1738 case DW_AT_allocated:
1739 case DW_AT_associated:
1740 case DW_AT_data_location:
1741 case DW_AT_description:
1742 case DW_AT_ordering:
1743 case DW_AT_start_scope:
1744 case DW_AT_visibility:
1745 case DW_AT_specification:
1746 case DW_AT_abstract_origin:
1753 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr);
1755 DIERef type_die_ref(type_die_form);
1756 Type *element_type = dwarf->ResolveTypeUID(type_die_ref);
1760 std::vector<uint64_t> element_orders;
1761 ParseChildArrayInfo(sc, die, first_index, element_orders, byte_stride, bit_stride);
1762 if (byte_stride == 0 && bit_stride == 0)
1763 byte_stride = element_type->GetByteSize();
1764 CompilerType array_element_type = element_type->GetForwardCompilerType ();
1766 if (ClangASTContext::IsCXXClassType(array_element_type) && array_element_type.GetCompleteType() == false)
1768 ModuleSP module_sp = die.GetModule();
1771 if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang)
1772 module_sp->ReportError ("DWARF DW_TAG_array_type DIE at 0x%8.8x has a class/union/struct element type DIE 0x%8.8x that is a forward declaration, not a complete definition.\nTry compiling the source file with -fno-limit-debug-info or disable -gmodule",
1774 type_die_ref.die_offset);
1776 module_sp->ReportError ("DWARF DW_TAG_array_type DIE at 0x%8.8x has a class/union/struct element type DIE 0x%8.8x that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s",
1778 type_die_ref.die_offset,
1779 die.GetLLDBCompileUnit() ? die.GetLLDBCompileUnit()->GetPath().c_str() : "the source file");
1782 // We have no choice other than to pretend that the element class type
1783 // is complete. If we don't do this, clang will crash when trying
1784 // to layout the class. Since we provide layout assistance, all
1785 // ivars in this class and other classes will be fine, this is
1786 // the best we can do short of crashing.
1787 if (ClangASTContext::StartTagDeclarationDefinition(array_element_type))
1789 ClangASTContext::CompleteTagDeclarationDefinition(array_element_type);
1793 module_sp->ReportError ("DWARF DIE at 0x%8.8x was not able to start its definition.\nPlease file a bug and attach the file at the start of this error message",
1794 type_die_ref.die_offset);
1798 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
1799 if (element_orders.size() > 0)
1801 uint64_t num_elements = 0;
1802 std::vector<uint64_t>::const_reverse_iterator pos;
1803 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
1804 for (pos = element_orders.rbegin(); pos != end; ++pos)
1806 num_elements = *pos;
1807 clang_type = m_ast.CreateArrayType (array_element_type,
1810 array_element_type = clang_type;
1811 array_element_bit_stride = num_elements ?
1812 array_element_bit_stride * num_elements :
1813 array_element_bit_stride;
1818 clang_type = m_ast.CreateArrayType (array_element_type, 0, is_vector);
1820 ConstString empty_name;
1821 type_sp.reset( new Type (die.GetID(),
1824 array_element_bit_stride / 8,
1826 DIERef(type_die_form).GetUID(dwarf),
1827 Type::eEncodingIsUID,
1830 Type::eResolveStateFull));
1831 type_sp->SetEncodingType (element_type);
1837 case DW_TAG_ptr_to_member_type:
1839 DWARFFormValue type_die_form;
1840 DWARFFormValue containing_type_die_form;
1842 const size_t num_attributes = die.GetAttributes (attributes);
1844 if (num_attributes > 0) {
1846 for (i=0; i<num_attributes; ++i)
1848 attr = attributes.AttributeAtIndex(i);
1849 if (attributes.ExtractFormValueAtIndex(i, form_value))
1854 type_die_form = form_value; break;
1855 case DW_AT_containing_type:
1856 containing_type_die_form = form_value; break;
1861 Type *pointee_type = dwarf->ResolveTypeUID(DIERef(type_die_form));
1862 Type *class_type = dwarf->ResolveTypeUID(DIERef(containing_type_die_form));
1864 CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType ();
1865 CompilerType class_clang_type = class_type->GetLayoutCompilerType ();
1867 clang_type = ClangASTContext::CreateMemberPointerType(class_clang_type, pointee_clang_type);
1869 byte_size = clang_type.GetByteSize(nullptr);
1871 type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, byte_size, NULL,
1872 LLDB_INVALID_UID, Type::eEncodingIsUID, NULL, clang_type,
1873 Type::eResolveStateForward));
1879 dwarf->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
1882 DW_TAG_value_to_name(tag));
1888 DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE(die);
1889 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
1891 SymbolContextScope * symbol_context_scope = NULL;
1892 if (sc_parent_tag == DW_TAG_compile_unit)
1894 symbol_context_scope = sc.comp_unit;
1896 else if (sc.function != NULL && sc_parent_die)
1898 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
1899 if (symbol_context_scope == NULL)
1900 symbol_context_scope = sc.function;
1903 if (symbol_context_scope != NULL)
1905 type_sp->SetSymbolContextScope(symbol_context_scope);
1908 // We are ready to put this type into the uniqued list up at the module level
1909 type_list->Insert (type_sp);
1911 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1914 else if (type_ptr != DIE_IS_BEING_PARSED)
1916 type_sp = type_ptr->shared_from_this();
1922 // DWARF parsing functions
1924 class DWARFASTParserClang::DelayedAddObjCClassProperty
1927 DelayedAddObjCClassProperty(const CompilerType &class_opaque_type,
1928 const char *property_name,
1929 const CompilerType &property_opaque_type, // The property type is only required if you don't have an ivar decl
1930 clang::ObjCIvarDecl *ivar_decl,
1931 const char *property_setter_name,
1932 const char *property_getter_name,
1933 uint32_t property_attributes,
1934 const ClangASTMetadata *metadata) :
1935 m_class_opaque_type (class_opaque_type),
1936 m_property_name (property_name),
1937 m_property_opaque_type (property_opaque_type),
1938 m_ivar_decl (ivar_decl),
1939 m_property_setter_name (property_setter_name),
1940 m_property_getter_name (property_getter_name),
1941 m_property_attributes (property_attributes)
1943 if (metadata != NULL)
1945 m_metadata_ap.reset(new ClangASTMetadata());
1946 *m_metadata_ap = *metadata;
1950 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1955 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1957 m_class_opaque_type = rhs.m_class_opaque_type;
1958 m_property_name = rhs.m_property_name;
1959 m_property_opaque_type = rhs.m_property_opaque_type;
1960 m_ivar_decl = rhs.m_ivar_decl;
1961 m_property_setter_name = rhs.m_property_setter_name;
1962 m_property_getter_name = rhs.m_property_getter_name;
1963 m_property_attributes = rhs.m_property_attributes;
1965 if (rhs.m_metadata_ap.get())
1967 m_metadata_ap.reset (new ClangASTMetadata());
1968 *m_metadata_ap = *rhs.m_metadata_ap;
1976 return ClangASTContext::AddObjCClassProperty (m_class_opaque_type,
1978 m_property_opaque_type,
1980 m_property_setter_name,
1981 m_property_getter_name,
1982 m_property_attributes,
1983 m_metadata_ap.get());
1987 CompilerType m_class_opaque_type;
1988 const char *m_property_name;
1989 CompilerType m_property_opaque_type;
1990 clang::ObjCIvarDecl *m_ivar_decl;
1991 const char *m_property_setter_name;
1992 const char *m_property_getter_name;
1993 uint32_t m_property_attributes;
1994 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
1998 DWARFASTParserClang::ParseTemplateDIE (const DWARFDIE &die,
1999 ClangASTContext::TemplateParameterInfos &template_param_infos)
2001 const dw_tag_t tag = die.Tag();
2005 case DW_TAG_template_type_parameter:
2006 case DW_TAG_template_value_parameter:
2008 DWARFAttributes attributes;
2009 const size_t num_attributes = die.GetAttributes (attributes);
2010 const char *name = nullptr;
2011 CompilerType clang_type;
2012 uint64_t uval64 = 0;
2013 bool uval64_valid = false;
2014 if (num_attributes > 0)
2016 DWARFFormValue form_value;
2017 for (size_t i=0; i<num_attributes; ++i)
2019 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2024 if (attributes.ExtractFormValueAtIndex(i, form_value))
2025 name = form_value.AsCString();
2029 if (attributes.ExtractFormValueAtIndex(i, form_value))
2031 Type *lldb_type = die.ResolveTypeUID(DIERef(form_value));
2033 clang_type = lldb_type->GetForwardCompilerType ();
2037 case DW_AT_const_value:
2038 if (attributes.ExtractFormValueAtIndex(i, form_value))
2040 uval64_valid = true;
2041 uval64 = form_value.Unsigned();
2049 clang::ASTContext *ast = m_ast.getASTContext();
2051 clang_type = m_ast.GetBasicType(eBasicTypeVoid);
2055 bool is_signed = false;
2056 if (name && name[0])
2057 template_param_infos.names.push_back(name);
2059 template_param_infos.names.push_back(NULL);
2061 // Get the signed value for any integer or enumeration if available
2062 clang_type.IsIntegerOrEnumerationType (is_signed);
2064 if (tag == DW_TAG_template_value_parameter && uval64_valid)
2066 llvm::APInt apint (clang_type.GetBitSize(nullptr), uval64, is_signed);
2067 template_param_infos.args.push_back(
2068 clang::TemplateArgument(*ast, llvm::APSInt(apint, !is_signed), ClangUtil::GetQualType(clang_type)));
2072 template_param_infos.args.push_back(
2073 clang::TemplateArgument(ClangUtil::GetQualType(clang_type)));
2092 DWARFASTParserClang::ParseTemplateParameterInfos (const DWARFDIE &parent_die,
2093 ClangASTContext::TemplateParameterInfos &template_param_infos)
2099 Args template_parameter_names;
2100 for (DWARFDIE die = parent_die.GetFirstChild();
2102 die = die.GetSibling())
2104 const dw_tag_t tag = die.Tag();
2108 case DW_TAG_template_type_parameter:
2109 case DW_TAG_template_value_parameter:
2110 ParseTemplateDIE (die, template_param_infos);
2117 if (template_param_infos.args.empty())
2119 return template_param_infos.args.size() == template_param_infos.names.size();
2123 DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type)
2125 SymbolFileDWARF *dwarf = die.GetDWARF();
2127 std::lock_guard<std::recursive_mutex> guard(dwarf->GetObjectFile()->GetModule()->GetMutex());
2129 // Disable external storage for this type so we don't get anymore
2130 // clang::ExternalASTSource queries for this type.
2131 m_ast.SetHasExternalStorage (clang_type.GetOpaqueQualType(), false);
2136 #if defined LLDB_CONFIGURATION_DEBUG
2137 //----------------------------------------------------------------------
2138 // For debugging purposes, the LLDB_DWARF_DONT_COMPLETE_TYPENAMES
2139 // environment variable can be set with one or more typenames separated
2140 // by ';' characters. This will cause this function to not complete any
2141 // types whose names match.
2143 // Examples of setting this environment variable:
2145 // LLDB_DWARF_DONT_COMPLETE_TYPENAMES=Foo
2146 // LLDB_DWARF_DONT_COMPLETE_TYPENAMES=Foo;Bar;Baz
2147 //----------------------------------------------------------------------
2148 const char *dont_complete_typenames_cstr = getenv("LLDB_DWARF_DONT_COMPLETE_TYPENAMES");
2149 if (dont_complete_typenames_cstr && dont_complete_typenames_cstr[0])
2151 const char *die_name = die.GetName();
2152 if (die_name && die_name[0])
2154 const char *match = strstr(dont_complete_typenames_cstr, die_name);
2157 size_t die_name_length = strlen(die_name);
2160 const char separator_char = ';';
2161 const char next_char = match[die_name_length];
2162 if (next_char == '\0' || next_char == separator_char)
2164 if (match == dont_complete_typenames_cstr || match[-1] == separator_char)
2167 match = strstr(match+1, die_name);
2174 const dw_tag_t tag = die.Tag();
2176 Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
2178 dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
2179 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
2181 die.GetTagAsCString(),
2182 type->GetName().AsCString());
2183 assert (clang_type);
2184 DWARFAttributes attributes;
2187 case DW_TAG_structure_type:
2188 case DW_TAG_union_type:
2189 case DW_TAG_class_type:
2191 ClangASTImporter::LayoutInfo layout_info;
2194 if (die.HasChildren())
2196 LanguageType class_language = eLanguageTypeUnknown;
2197 if (ClangASTContext::IsObjCObjectOrInterfaceType(clang_type))
2199 class_language = eLanguageTypeObjC;
2200 // For objective C we don't start the definition when
2201 // the class is created.
2202 ClangASTContext::StartTagDeclarationDefinition (clang_type);
2205 int tag_decl_kind = -1;
2206 AccessType default_accessibility = eAccessNone;
2207 if (tag == DW_TAG_structure_type)
2209 tag_decl_kind = clang::TTK_Struct;
2210 default_accessibility = eAccessPublic;
2212 else if (tag == DW_TAG_union_type)
2214 tag_decl_kind = clang::TTK_Union;
2215 default_accessibility = eAccessPublic;
2217 else if (tag == DW_TAG_class_type)
2219 tag_decl_kind = clang::TTK_Class;
2220 default_accessibility = eAccessPrivate;
2223 SymbolContext sc(die.GetLLDBCompileUnit());
2224 std::vector<clang::CXXBaseSpecifier *> base_classes;
2225 std::vector<int> member_accessibilities;
2226 bool is_a_class = false;
2227 // Parse members and base classes first
2228 DWARFDIECollection member_function_dies;
2230 DelayedPropertyList delayed_properties;
2231 ParseChildMembers (sc,
2236 member_accessibilities,
2237 member_function_dies,
2239 default_accessibility,
2243 // Now parse any methods if there were any...
2244 size_t num_functions = member_function_dies.Size();
2245 if (num_functions > 0)
2247 for (size_t i=0; i<num_functions; ++i)
2249 dwarf->ResolveType(member_function_dies.GetDIEAtIndex(i));
2253 if (class_language == eLanguageTypeObjC)
2255 ConstString class_name (clang_type.GetTypeName());
2258 DIEArray method_die_offsets;
2259 dwarf->GetObjCMethodDIEOffsets(class_name, method_die_offsets);
2261 if (!method_die_offsets.empty())
2263 DWARFDebugInfo* debug_info = dwarf->DebugInfo();
2265 const size_t num_matches = method_die_offsets.size();
2266 for (size_t i=0; i<num_matches; ++i)
2268 const DIERef& die_ref = method_die_offsets[i];
2269 DWARFDIE method_die = debug_info->GetDIE (die_ref);
2272 method_die.ResolveType ();
2276 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2283 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2284 // need to tell the clang type it is actually a class.
2285 if (class_language != eLanguageTypeObjC)
2287 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2288 m_ast.SetTagTypeKind(ClangUtil::GetQualType(clang_type), clang::TTK_Class);
2291 // Since DW_TAG_structure_type gets used for both classes
2292 // and structures, we may need to set any DW_TAG_member
2293 // fields to have a "private" access if none was specified.
2294 // When we parsed the child members we tracked that actual
2295 // accessibility value for each DW_TAG_member in the
2296 // "member_accessibilities" array. If the value for the
2297 // member is zero, then it was set to the "default_accessibility"
2298 // which for structs was "public". Below we correct this
2299 // by setting any fields to "private" that weren't correctly
2301 if (is_a_class && !member_accessibilities.empty())
2303 // This is a class and all members that didn't have
2304 // their access specified are private.
2305 m_ast.SetDefaultAccessForRecordFields (m_ast.GetAsRecordDecl(clang_type),
2307 &member_accessibilities.front(),
2308 member_accessibilities.size());
2311 if (!base_classes.empty())
2313 // Make sure all base classes refer to complete types and not
2314 // forward declarations. If we don't do this, clang will crash
2315 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2316 for (auto &base_class : base_classes)
2318 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2319 if (type_source_info)
2321 CompilerType base_class_type (&m_ast, type_source_info->getType().getAsOpaquePtr());
2322 if (base_class_type.GetCompleteType() == false)
2324 auto module = dwarf->GetObjectFile()->GetModule();
2325 module->ReportError (
2326 ":: Class '%s' has a base class '%s' which does not have a complete definition.",
2328 base_class_type.GetTypeName().GetCString());
2329 if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang)
2330 module->ReportError (":: Try compiling the source file with -fno-limit-debug-info.");
2332 // We have no choice other than to pretend that the base class
2333 // is complete. If we don't do this, clang will crash when we
2334 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2335 // below. Since we provide layout assistance, all ivars in this
2336 // class and other classes will be fine, this is the best we can do
2337 // short of crashing.
2338 if (ClangASTContext::StartTagDeclarationDefinition (base_class_type))
2340 ClangASTContext::CompleteTagDeclarationDefinition (base_class_type);
2345 m_ast.SetBaseClassesForClassType (clang_type.GetOpaqueQualType(),
2346 &base_classes.front(),
2347 base_classes.size());
2349 // Clang will copy each CXXBaseSpecifier in "base_classes"
2350 // so we have to free them all.
2351 ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2352 base_classes.size());
2357 ClangASTContext::BuildIndirectFields (clang_type);
2358 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
2360 if (!layout_info.field_offsets.empty() ||
2361 !layout_info.base_offsets.empty() ||
2362 !layout_info.vbase_offsets.empty() )
2365 layout_info.bit_size = type->GetByteSize() * 8;
2366 if (layout_info.bit_size == 0)
2367 layout_info.bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
2369 clang::CXXRecordDecl *record_decl = m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
2374 ModuleSP module_sp = dwarf->GetObjectFile()->GetModule();
2378 module_sp->LogMessage (log,
2379 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
2380 static_cast<void*>(clang_type.GetOpaqueQualType()),
2381 static_cast<void*>(record_decl),
2382 layout_info.bit_size,
2383 layout_info.alignment,
2384 static_cast<uint32_t>(layout_info.field_offsets.size()),
2385 static_cast<uint32_t>(layout_info.base_offsets.size()),
2386 static_cast<uint32_t>(layout_info.vbase_offsets.size()));
2390 llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator pos,
2391 end = layout_info.field_offsets.end();
2392 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
2394 module_sp->LogMessage(log,
2395 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
2396 static_cast<void *>(clang_type.GetOpaqueQualType()),
2398 static_cast<uint32_t>(pos->second),
2399 pos->first->getNameAsString().c_str());
2404 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos,
2405 base_end = layout_info.base_offsets.end();
2406 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2408 module_sp->LogMessage(log,
2409 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2410 clang_type.GetOpaqueQualType(), idx, (uint32_t)base_pos->second.getQuantity(),
2411 base_pos->first->getNameAsString().c_str());
2415 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos,
2416 vbase_end = layout_info.vbase_offsets.end();
2417 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2419 module_sp->LogMessage(log,
2420 "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2421 static_cast<void *>(clang_type.GetOpaqueQualType()), idx,
2422 static_cast<uint32_t>(vbase_pos->second.getQuantity()),
2423 vbase_pos->first->getNameAsString().c_str());
2429 GetClangASTImporter().InsertRecordDecl(record_decl, layout_info);
2434 return (bool)clang_type;
2436 case DW_TAG_enumeration_type:
2437 if (ClangASTContext::StartTagDeclarationDefinition (clang_type))
2439 if (die.HasChildren())
2441 SymbolContext sc(die.GetLLDBCompileUnit());
2442 bool is_signed = false;
2443 clang_type.IsIntegerType(is_signed);
2444 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), die);
2446 ClangASTContext::CompleteTagDeclarationDefinition (clang_type);
2448 return (bool)clang_type;
2451 assert(false && "not a forward clang type decl!");
2458 std::vector<DWARFDIE>
2459 DWARFASTParserClang::GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context)
2461 std::vector<DWARFDIE> result;
2462 for (auto it = m_decl_ctx_to_die.find((clang::DeclContext *)decl_context.GetOpaqueDeclContext()); it != m_decl_ctx_to_die.end(); it++)
2463 result.push_back(it->second);
2468 DWARFASTParserClang::GetDeclForUIDFromDWARF (const DWARFDIE &die)
2470 clang::Decl *clang_decl = GetClangDeclForDIE(die);
2471 if (clang_decl != nullptr)
2472 return CompilerDecl(&m_ast, clang_decl);
2473 return CompilerDecl();
2477 DWARFASTParserClang::GetDeclContextForUIDFromDWARF (const DWARFDIE &die)
2479 clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE (die);
2481 return CompilerDeclContext(&m_ast, clang_decl_ctx);
2482 return CompilerDeclContext();
2486 DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die)
2488 clang::DeclContext *clang_decl_ctx = GetClangDeclContextContainingDIE (die, nullptr);
2490 return CompilerDeclContext(&m_ast, clang_decl_ctx);
2491 return CompilerDeclContext();
2495 DWARFASTParserClang::ParseChildEnumerators (const SymbolContext& sc,
2496 lldb_private::CompilerType &clang_type,
2498 uint32_t enumerator_byte_size,
2499 const DWARFDIE &parent_die)
2504 size_t enumerators_added = 0;
2506 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling())
2508 const dw_tag_t tag = die.Tag();
2509 if (tag == DW_TAG_enumerator)
2511 DWARFAttributes attributes;
2512 const size_t num_child_attributes = die.GetAttributes(attributes);
2513 if (num_child_attributes > 0)
2515 const char *name = NULL;
2516 bool got_value = false;
2517 int64_t enum_value = 0;
2521 for (i=0; i<num_child_attributes; ++i)
2523 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2524 DWARFFormValue form_value;
2525 if (attributes.ExtractFormValueAtIndex(i, form_value))
2529 case DW_AT_const_value:
2532 enum_value = form_value.Signed();
2534 enum_value = form_value.Unsigned();
2538 name = form_value.AsCString();
2541 case DW_AT_description:
2543 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2544 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2545 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2552 if (name && name[0] && got_value)
2554 m_ast.AddEnumerationValueToEnumerationType (clang_type.GetOpaqueQualType(),
2555 m_ast.GetEnumerationIntegerType(clang_type.GetOpaqueQualType()),
2559 enumerator_byte_size * 8);
2560 ++enumerators_added;
2565 return enumerators_added;
2568 #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE)
2574 void Push (const DWARFDIE &die)
2576 m_dies.push_back (die);
2580 void LogDIEs (Log *log)
2582 StreamString log_strm;
2583 const size_t n = m_dies.size();
2584 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
2585 for (size_t i=0; i<n; i++)
2587 std::string qualified_name;
2588 const DWARFDIE &die = m_dies[i];
2589 die.GetQualifiedName(qualified_name);
2590 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
2593 die.GetTagAsCString(),
2594 qualified_name.c_str());
2596 log->PutCString(log_strm.GetData());
2606 ScopedPopper (DIEStack &die_stack) :
2607 m_die_stack (die_stack),
2613 Push (const DWARFDIE &die)
2616 m_die_stack.Push (die);
2628 DIEStack &m_die_stack;
2633 typedef std::vector<DWARFDIE> Stack;
2639 DWARFASTParserClang::ParseFunctionFromDWARF (const SymbolContext& sc,
2640 const DWARFDIE &die)
2642 DWARFRangeList func_ranges;
2643 const char *name = NULL;
2644 const char *mangled = NULL;
2647 int decl_column = 0;
2650 int call_column = 0;
2651 DWARFExpression frame_base(die.GetCU());
2653 const dw_tag_t tag = die.Tag();
2655 if (tag != DW_TAG_subprogram)
2658 if (die.GetDIENamesAndRanges (name,
2670 // Union of all ranges in the function DIE (if the function is discontiguous)
2671 AddressRange func_range;
2672 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
2673 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
2674 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
2676 ModuleSP module_sp (die.GetModule());
2677 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
2678 if (func_range.GetBaseAddress().IsValid())
2679 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
2682 if (func_range.GetBaseAddress().IsValid())
2686 func_name.SetValue(ConstString(mangled), true);
2687 else if (die.GetParent().Tag() == DW_TAG_compile_unit &&
2688 Language::LanguageIsCPlusPlus(die.GetLanguage()) &&
2689 name && strcmp(name, "main") != 0)
2691 // If the mangled name is not present in the DWARF, generate the demangled name
2692 // using the decl context. We skip if the function is "main" as its name is
2694 bool is_static = false;
2695 bool is_variadic = false;
2696 bool has_template_params = false;
2697 unsigned type_quals = 0;
2698 std::vector<CompilerType> param_types;
2699 std::vector<clang::ParmVarDecl*> param_decls;
2700 DWARFDeclContext decl_ctx;
2703 die.GetDWARFDeclContext(decl_ctx);
2704 sstr << decl_ctx.GetQualifiedName();
2706 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(die, nullptr);
2707 ParseChildParameters(sc,
2708 containing_decl_ctx,
2713 has_template_params,
2718 for (size_t i = 0; i < param_types.size(); i++)
2722 sstr << param_types[i].GetTypeName();
2727 if (type_quals & clang::Qualifiers::Const)
2730 func_name.SetValue(ConstString(sstr.GetData()), false);
2733 func_name.SetValue(ConstString(name), false);
2736 std::unique_ptr<Declaration> decl_ap;
2737 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
2738 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
2742 SymbolFileDWARF *dwarf = die.GetDWARF();
2743 // Supply the type _only_ if it has already been parsed
2744 Type *func_type = dwarf->GetDIEToType().lookup (die.GetDIE());
2746 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
2748 if (dwarf->FixupAddress (func_range.GetBaseAddress()))
2750 const user_id_t func_user_id = die.GetID();
2751 func_sp.reset(new Function (sc.comp_unit,
2752 func_user_id, // UserID is the DIE offset
2756 func_range)); // first address range
2758 if (func_sp.get() != NULL)
2760 if (frame_base.IsValid())
2761 func_sp->GetFrameBaseExpression() = frame_base;
2762 sc.comp_unit->AddFunction(func_sp);
2763 return func_sp.get();
2772 DWARFASTParserClang::ParseChildMembers(const SymbolContext &sc, const DWARFDIE &parent_die,
2773 CompilerType &class_clang_type, const LanguageType class_language,
2774 std::vector<clang::CXXBaseSpecifier *> &base_classes,
2775 std::vector<int> &member_accessibilities,
2776 DWARFDIECollection &member_function_dies,
2777 DelayedPropertyList &delayed_properties, AccessType &default_accessibility,
2778 bool &is_a_class, ClangASTImporter::LayoutInfo &layout_info)
2783 // Get the parent byte size so we can verify any members will fit
2784 const uint64_t parent_byte_size = parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX) * 8;
2785 const uint64_t parent_bit_size = parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
2787 uint32_t member_idx = 0;
2788 BitfieldInfo last_field_info;
2790 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2791 ClangASTContext *ast = llvm::dyn_cast_or_null<ClangASTContext>(class_clang_type.GetTypeSystem());
2795 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling())
2797 dw_tag_t tag = die.Tag();
2802 case DW_TAG_APPLE_property:
2804 DWARFAttributes attributes;
2805 const size_t num_attributes = die.GetAttributes (attributes);
2806 if (num_attributes > 0)
2809 //DWARFExpression location;
2810 const char *name = NULL;
2811 const char *prop_name = NULL;
2812 const char *prop_getter_name = NULL;
2813 const char *prop_setter_name = NULL;
2814 uint32_t prop_attributes = 0;
2817 bool is_artificial = false;
2818 DWARFFormValue encoding_form;
2819 AccessType accessibility = eAccessNone;
2820 uint32_t member_byte_offset = (parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX;
2821 size_t byte_size = 0;
2822 int64_t bit_offset = 0;
2823 uint64_t data_bit_offset = UINT64_MAX;
2824 size_t bit_size = 0;
2825 bool is_external = false; // On DW_TAG_members, this means the member is static
2827 for (i=0; i<num_attributes && !is_artificial; ++i)
2829 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2830 DWARFFormValue form_value;
2831 if (attributes.ExtractFormValueAtIndex(i, form_value))
2835 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2836 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2837 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2838 case DW_AT_name: name = form_value.AsCString(); break;
2839 case DW_AT_type: encoding_form = form_value; break;
2840 case DW_AT_bit_offset: bit_offset = form_value.Signed(); break;
2841 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
2842 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
2843 case DW_AT_data_bit_offset: data_bit_offset = form_value.Unsigned(); break;
2844 case DW_AT_data_member_location:
2845 if (form_value.BlockData())
2847 Value initialValue(0);
2848 Value memberOffset(0);
2849 const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data();
2850 uint32_t block_length = form_value.Unsigned();
2851 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2852 if (DWARFExpression::Evaluate(nullptr, // ExecutionContext *
2853 nullptr, // ClangExpressionVariableList *
2854 nullptr, // ClangExpressionDeclMap *
2855 nullptr, // RegisterContext *
2867 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
2872 // With DWARF 3 and later, if the value is an integer constant,
2873 // this form value is the offset in bytes from the beginning
2874 // of the containing entity.
2875 member_byte_offset = form_value.Unsigned();
2879 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
2880 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
2881 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString();
2883 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString();
2885 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString();
2887 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
2888 case DW_AT_external: is_external = form_value.Boolean(); break;
2891 case DW_AT_declaration:
2892 case DW_AT_description:
2894 case DW_AT_visibility:
2903 ConstString fixed_getter;
2904 ConstString fixed_setter;
2906 // Check if the property getter/setter were provided as full
2907 // names. We want basenames, so we extract them.
2909 if (prop_getter_name && prop_getter_name[0] == '-')
2911 ObjCLanguage::MethodName prop_getter_method(prop_getter_name, true);
2912 prop_getter_name = prop_getter_method.GetSelector().GetCString();
2915 if (prop_setter_name && prop_setter_name[0] == '-')
2917 ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true);
2918 prop_setter_name = prop_setter_method.GetSelector().GetCString();
2921 // If the names haven't been provided, they need to be
2924 if (!prop_getter_name)
2926 prop_getter_name = prop_name;
2928 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
2932 ss.Printf("set%c%s:",
2933 toupper(prop_name[0]),
2936 fixed_setter.SetCString(ss.GetData());
2937 prop_setter_name = fixed_setter.GetCString();
2941 // Clang has a DWARF generation bug where sometimes it
2942 // represents fields that are references with bad byte size
2943 // and bit size/offset information such as:
2945 // DW_AT_byte_size( 0x00 )
2946 // DW_AT_bit_size( 0x40 )
2947 // DW_AT_bit_offset( 0xffffffffffffffc0 )
2949 // So check the bit offset to make sure it is sane, and if
2950 // the values are not sane, remove them. If we don't do this
2951 // then we will end up with a crash if we try to use this
2952 // type in an expression when clang becomes unhappy with its
2953 // recycled debug info.
2955 if (byte_size == 0 && bit_offset < 0)
2961 // FIXME: Make Clang ignore Objective-C accessibility for expressions
2962 if (class_language == eLanguageTypeObjC ||
2963 class_language == eLanguageTypeObjC_plus_plus)
2964 accessibility = eAccessNone;
2966 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
2968 // Not all compilers will mark the vtable pointer
2969 // member as artificial (llvm-gcc). We can't have
2970 // the virtual members in our classes otherwise it
2971 // throws off all child offsets since we end up
2972 // having and extra pointer sized member in our
2974 is_artificial = true;
2977 // Handle static members
2978 if (is_external && member_byte_offset == UINT32_MAX)
2980 Type *var_type = die.ResolveTypeUID(DIERef(encoding_form));
2984 if (accessibility == eAccessNone)
2985 accessibility = eAccessPublic;
2986 ClangASTContext::AddVariableToRecordType (class_clang_type,
2988 var_type->GetLayoutCompilerType (),
2994 if (is_artificial == false)
2996 Type *member_type = die.ResolveTypeUID(DIERef(encoding_form));
2998 clang::FieldDecl *field_decl = NULL;
2999 if (tag == DW_TAG_member)
3003 if (accessibility == eAccessNone)
3004 accessibility = default_accessibility;
3005 member_accessibilities.push_back(accessibility);
3007 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
3011 BitfieldInfo this_field_info;
3012 this_field_info.bit_offset = field_bit_offset;
3013 this_field_info.bit_size = bit_size;
3015 /////////////////////////////////////////////////////////////
3016 // How to locate a field given the DWARF debug information
3018 // AT_byte_size indicates the size of the word in which the
3019 // bit offset must be interpreted.
3021 // AT_data_member_location indicates the byte offset of the
3022 // word from the base address of the structure.
3024 // AT_bit_offset indicates how many bits into the word
3025 // (according to the host endianness) the low-order bit of
3026 // the field starts. AT_bit_offset can be negative.
3028 // AT_bit_size indicates the size of the field in bits.
3029 /////////////////////////////////////////////////////////////
3031 if (data_bit_offset != UINT64_MAX)
3033 this_field_info.bit_offset = data_bit_offset;
3038 byte_size = member_type->GetByteSize();
3040 ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
3041 if (objfile->GetByteOrder() == eByteOrderLittle)
3043 this_field_info.bit_offset += byte_size * 8;
3044 this_field_info.bit_offset -= (bit_offset + bit_size);
3048 this_field_info.bit_offset += bit_offset;
3052 if ((this_field_info.bit_offset >= parent_bit_size) || !last_field_info.NextBitfieldOffsetIsValid(this_field_info.bit_offset))
3054 ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
3055 objfile->GetModule()->ReportWarning("0x%8.8" PRIx64 ": %s bitfield named \"%s\" has invalid bit offset (0x%8.8" PRIx64 ") member will be ignored. Please file a bug against the compiler and include the preprocessed output for %s\n",
3057 DW_TAG_value_to_name(tag),
3059 this_field_info.bit_offset,
3060 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
3061 this_field_info.Clear();
3065 // Update the field bit offset we will report for layout
3066 field_bit_offset = this_field_info.bit_offset;
3068 // If the member to be emitted did not start on a character boundary and there is
3069 // empty space between the last field and this one, then we need to emit an
3070 // anonymous member filling up the space up to its start. There are three cases
3073 // 1 If the previous member ended on a character boundary, then we can emit an
3074 // anonymous member starting at the most recent character boundary.
3076 // 2 If the previous member did not end on a character boundary and the distance
3077 // from the end of the previous member to the current member is less than a
3078 // word width, then we can emit an anonymous member starting right after the
3079 // previous member and right before this member.
3081 // 3 If the previous member did not end on a character boundary and the distance
3082 // from the end of the previous member to the current member is greater than
3083 // or equal a word width, then we act as in Case 1.
3085 const uint64_t character_width = 8;
3086 const uint64_t word_width = 32;
3088 // Objective-C has invalid DW_AT_bit_offset values in older versions
3089 // of clang, so we have to be careful and only insert unnamed bitfields
3090 // if we have a new enough clang.
3091 bool detect_unnamed_bitfields = true;
3093 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
3094 detect_unnamed_bitfields = die.GetCU()->Supports_unnamed_objc_bitfields ();
3096 if (detect_unnamed_bitfields)
3098 BitfieldInfo anon_field_info;
3100 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
3102 uint64_t last_field_end = 0;
3104 if (last_field_info.IsValid())
3105 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
3107 if (this_field_info.bit_offset != last_field_end)
3109 if (((last_field_end % character_width) == 0) || // case 1
3110 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
3112 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
3113 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
3117 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
3118 anon_field_info.bit_offset = last_field_end;
3123 if (anon_field_info.IsValid())
3125 clang::FieldDecl *unnamed_bitfield_decl =
3126 ClangASTContext::AddFieldToRecordType (class_clang_type,
3128 m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
3130 anon_field_info.bit_size);
3132 layout_info.field_offsets.insert(
3133 std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
3136 last_field_info = this_field_info;
3140 last_field_info.Clear();
3143 CompilerType member_clang_type = member_type->GetLayoutCompilerType ();
3144 if (!member_clang_type.IsCompleteType())
3145 member_clang_type.GetCompleteType();
3148 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
3149 // If the current field is at the end of the structure, then there is definitely no room for extra
3150 // elements and we override the type to array[0].
3152 CompilerType member_array_element_type;
3153 uint64_t member_array_size;
3154 bool member_array_is_incomplete;
3156 if (member_clang_type.IsArrayType(&member_array_element_type,
3158 &member_array_is_incomplete) &&
3159 !member_array_is_incomplete)
3161 uint64_t parent_byte_size = parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
3163 if (member_byte_offset >= parent_byte_size)
3165 if (member_array_size != 1 && (member_array_size != 0 || member_byte_offset > parent_byte_size))
3167 module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64,
3170 encoding_form.Reference(),
3171 parent_die.GetID());
3174 member_clang_type = m_ast.CreateArrayType(member_array_element_type, 0, false);
3179 if (ClangASTContext::IsCXXClassType(member_clang_type) && member_clang_type.GetCompleteType() == false)
3181 if (die.GetCU()->GetProducer() == DWARFCompileUnit::eProducerClang)
3182 module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type is a forward declaration, not a complete definition.\nTry compiling the source file with -fno-limit-debug-info",
3183 parent_die.GetOffset(),
3184 parent_die.GetName(),
3188 module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s",
3189 parent_die.GetOffset(),
3190 parent_die.GetName(),
3193 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
3194 // We have no choice other than to pretend that the member class
3195 // is complete. If we don't do this, clang will crash when trying
3196 // to layout the class. Since we provide layout assistance, all
3197 // ivars in this class and other classes will be fine, this is
3198 // the best we can do short of crashing.
3199 if (ClangASTContext::StartTagDeclarationDefinition(member_clang_type))
3201 ClangASTContext::CompleteTagDeclarationDefinition(member_clang_type);
3205 module_sp->ReportError ("DWARF DIE at 0x%8.8x (class %s) has a member variable 0x%8.8x (%s) whose type claims to be a C++ class but we were not able to start its definition.\nPlease file a bug and attach the file at the start of this error message",
3206 parent_die.GetOffset(),
3207 parent_die.GetName(),
3213 field_decl = ClangASTContext::AddFieldToRecordType (class_clang_type,
3219 m_ast.SetMetadataAsUserID (field_decl, die.GetID());
3221 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
3226 module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
3229 encoding_form.Reference());
3231 module_sp->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
3233 encoding_form.Reference());
3237 if (prop_name != NULL && member_type)
3239 clang::ObjCIvarDecl *ivar_decl = NULL;
3243 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
3244 assert (ivar_decl != NULL);
3247 ClangASTMetadata metadata;
3248 metadata.SetUserID (die.GetID());
3249 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
3251 member_type->GetLayoutCompilerType (),
3259 m_ast.SetMetadataAsUserID (ivar_decl, die.GetID());
3267 case DW_TAG_subprogram:
3268 // Let the type parsing code handle this one for us.
3269 member_function_dies.Append (die);
3272 case DW_TAG_inheritance:
3275 if (default_accessibility == eAccessNone)
3276 default_accessibility = eAccessPrivate;
3277 // TODO: implement DW_TAG_inheritance type parsing
3278 DWARFAttributes attributes;
3279 const size_t num_attributes = die.GetAttributes (attributes);
3280 if (num_attributes > 0)
3283 DWARFExpression location(die.GetCU());
3284 DWARFFormValue encoding_form;
3285 AccessType accessibility = default_accessibility;
3286 bool is_virtual = false;
3287 bool is_base_of_class = true;
3288 off_t member_byte_offset = 0;
3290 for (i=0; i<num_attributes; ++i)
3292 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3293 DWARFFormValue form_value;
3294 if (attributes.ExtractFormValueAtIndex(i, form_value))
3298 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3299 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3300 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3301 case DW_AT_type: encoding_form = form_value; break;
3302 case DW_AT_data_member_location:
3303 if (form_value.BlockData())
3305 Value initialValue(0);
3306 Value memberOffset(0);
3307 const DWARFDataExtractor& debug_info_data = die.GetDWARF()->get_debug_info_data();
3308 uint32_t block_length = form_value.Unsigned();
3309 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
3310 if (DWARFExpression::Evaluate (nullptr,
3325 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
3330 // With DWARF 3 and later, if the value is an integer constant,
3331 // this form value is the offset in bytes from the beginning
3332 // of the containing entity.
3333 member_byte_offset = form_value.Unsigned();
3337 case DW_AT_accessibility:
3338 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
3341 case DW_AT_virtuality:
3342 is_virtual = form_value.Boolean();
3354 Type *base_class_type = die.ResolveTypeUID(DIERef(encoding_form));
3355 if (base_class_type == NULL)
3357 module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to resolve the base class at 0x%8.8" PRIx64 " from enclosing type 0x%8.8x. \nPlease file a bug and attach the file at the start of this error message",
3359 encoding_form.Reference(),
3360 parent_die.GetOffset());
3364 CompilerType base_class_clang_type = base_class_type->GetFullCompilerType ();
3365 assert (base_class_clang_type);
3366 if (class_language == eLanguageTypeObjC)
3368 ast->SetObjCSuperClass(class_clang_type, base_class_clang_type);
3372 base_classes.push_back (ast->CreateBaseClassSpecifier (base_class_clang_type.GetOpaqueQualType(),
3379 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
3380 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
3381 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
3382 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
3383 // Given this, there is really no valid response we can give to clang for virtual base
3384 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
3385 // AST source in clang.
3389 layout_info.base_offsets.insert(
3390 std::make_pair(ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()),
3391 clang::CharUnits::fromQuantity(member_byte_offset)));
3408 DWARFASTParserClang::ParseChildParameters (const SymbolContext& sc,
3409 clang::DeclContext *containing_decl_ctx,
3410 const DWARFDIE &parent_die,
3411 bool skip_artificial,
3414 bool &has_template_params,
3415 std::vector<CompilerType>& function_param_types,
3416 std::vector<clang::ParmVarDecl*>& function_param_decls,
3417 unsigned &type_quals)
3423 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling())
3425 const dw_tag_t tag = die.Tag();
3428 case DW_TAG_formal_parameter:
3430 DWARFAttributes attributes;
3431 const size_t num_attributes = die.GetAttributes(attributes);
3432 if (num_attributes > 0)
3434 const char *name = NULL;
3436 DWARFFormValue param_type_die_form;
3437 bool is_artificial = false;
3438 // one of None, Auto, Register, Extern, Static, PrivateExtern
3440 clang::StorageClass storage = clang::SC_None;
3442 for (i=0; i<num_attributes; ++i)
3444 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3445 DWARFFormValue form_value;
3446 if (attributes.ExtractFormValueAtIndex(i, form_value))
3450 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3451 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
3452 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3453 case DW_AT_name: name = form_value.AsCString();
3455 case DW_AT_type: param_type_die_form = form_value; break;
3456 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
3457 case DW_AT_location:
3458 // if (form_value.BlockData())
3460 // const DWARFDataExtractor& debug_info_data = debug_info();
3461 // uint32_t block_length = form_value.Unsigned();
3462 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3468 case DW_AT_const_value:
3469 case DW_AT_default_value:
3470 case DW_AT_description:
3471 case DW_AT_endianity:
3472 case DW_AT_is_optional:
3474 case DW_AT_variable_parameter:
3476 case DW_AT_abstract_origin:
3484 if (skip_artificial)
3488 // In order to determine if a C++ member function is
3489 // "const" we have to look at the const-ness of "this"...
3493 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
3495 // Often times compilers omit the "this" name for the
3496 // specification DIEs, so we can't rely upon the name
3497 // being in the formal parameter DIE...
3498 if (name == NULL || ::strcmp(name, "this")==0)
3500 Type *this_type = die.ResolveTypeUID (DIERef(param_type_die_form));
3503 uint32_t encoding_mask = this_type->GetEncodingMask();
3504 if (encoding_mask & Type::eEncodingIsPointerUID)
3508 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3509 type_quals |= clang::Qualifiers::Const;
3510 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3511 type_quals |= clang::Qualifiers::Volatile;
3522 // HACK: Objective C formal parameters "self" and "_cmd"
3523 // are not marked as artificial in the DWARF...
3524 CompileUnit *comp_unit = die.GetLLDBCompileUnit();
3527 switch (comp_unit->GetLanguage())
3529 case eLanguageTypeObjC:
3530 case eLanguageTypeObjC_plus_plus:
3531 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3543 Type *type = die.ResolveTypeUID(DIERef(param_type_die_form));
3546 function_param_types.push_back (type->GetForwardCompilerType ());
3548 clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration (name,
3549 type->GetForwardCompilerType (),
3551 assert(param_var_decl);
3552 function_param_decls.push_back(param_var_decl);
3554 m_ast.SetMetadataAsUserID (param_var_decl, die.GetID());
3562 case DW_TAG_unspecified_parameters:
3566 case DW_TAG_template_type_parameter:
3567 case DW_TAG_template_value_parameter:
3568 // The one caller of this was never using the template_param_infos,
3569 // and the local variable was taking up a large amount of stack space
3570 // in SymbolFileDWARF::ParseType() so this was removed. If we ever need
3571 // the template params back, we can add them back.
3572 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
3573 has_template_params = true;
3584 DWARFASTParserClang::ParseChildArrayInfo (const SymbolContext& sc,
3585 const DWARFDIE &parent_die,
3586 int64_t& first_index,
3587 std::vector<uint64_t>& element_orders,
3588 uint32_t& byte_stride,
3589 uint32_t& bit_stride)
3594 for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling())
3596 const dw_tag_t tag = die.Tag();
3599 case DW_TAG_subrange_type:
3601 DWARFAttributes attributes;
3602 const size_t num_child_attributes = die.GetAttributes(attributes);
3603 if (num_child_attributes > 0)
3605 uint64_t num_elements = 0;
3606 uint64_t lower_bound = 0;
3607 uint64_t upper_bound = 0;
3608 bool upper_bound_valid = false;
3610 for (i=0; i<num_child_attributes; ++i)
3612 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3613 DWARFFormValue form_value;
3614 if (attributes.ExtractFormValueAtIndex(i, form_value))
3622 num_elements = form_value.Unsigned();
3625 case DW_AT_bit_stride:
3626 bit_stride = form_value.Unsigned();
3629 case DW_AT_byte_stride:
3630 byte_stride = form_value.Unsigned();
3633 case DW_AT_lower_bound:
3634 lower_bound = form_value.Unsigned();
3637 case DW_AT_upper_bound:
3638 upper_bound_valid = true;
3639 upper_bound = form_value.Unsigned();
3643 case DW_AT_abstract_origin:
3644 case DW_AT_accessibility:
3645 case DW_AT_allocated:
3646 case DW_AT_associated:
3647 case DW_AT_data_location:
3648 case DW_AT_declaration:
3649 case DW_AT_description:
3651 case DW_AT_threads_scaled:
3653 case DW_AT_visibility:
3659 if (num_elements == 0)
3661 if (upper_bound_valid && upper_bound >= lower_bound)
3662 num_elements = upper_bound - lower_bound + 1;
3665 element_orders.push_back (num_elements);
3674 DWARFASTParserClang::GetTypeForDIE (const DWARFDIE &die)
3678 SymbolFileDWARF *dwarf = die.GetDWARF();
3679 DWARFAttributes attributes;
3680 const size_t num_attributes = die.GetAttributes(attributes);
3681 if (num_attributes > 0)
3683 DWARFFormValue type_die_form;
3684 for (size_t i = 0; i < num_attributes; ++i)
3686 dw_attr_t attr = attributes.AttributeAtIndex(i);
3687 DWARFFormValue form_value;
3689 if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value))
3690 return dwarf->ResolveTypeUID(dwarf->GetDIE (DIERef(form_value)), true);
3699 DWARFASTParserClang::GetClangDeclForDIE (const DWARFDIE &die)
3706 case DW_TAG_variable:
3707 case DW_TAG_constant:
3708 case DW_TAG_formal_parameter:
3709 case DW_TAG_imported_declaration:
3710 case DW_TAG_imported_module:
3716 DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE());
3717 if (cache_pos != m_die_to_decl.end())
3718 return cache_pos->second;
3720 if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
3722 clang::Decl *decl = GetClangDeclForDIE(spec_die);
3723 m_die_to_decl[die.GetDIE()] = decl;
3724 m_decl_to_die[decl].insert(die.GetDIE());
3728 if (DWARFDIE abstract_origin_die = die.GetReferencedDIE(DW_AT_abstract_origin))
3730 clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die);
3731 m_die_to_decl[die.GetDIE()] = decl;
3732 m_decl_to_die[decl].insert(die.GetDIE());
3736 clang::Decl *decl = nullptr;
3739 case DW_TAG_variable:
3740 case DW_TAG_constant:
3741 case DW_TAG_formal_parameter:
3743 SymbolFileDWARF *dwarf = die.GetDWARF();
3744 Type *type = GetTypeForDIE(die);
3747 const char *name = die.GetName();
3748 clang::DeclContext *decl_context =
3749 ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID()));
3750 decl = m_ast.CreateVariableDeclaration(decl_context, name,
3751 ClangUtil::GetQualType(type->GetForwardCompilerType()));
3755 case DW_TAG_imported_declaration:
3757 SymbolFileDWARF *dwarf = die.GetDWARF();
3758 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3761 CompilerDecl imported_decl = imported_uid.GetDecl();
3764 clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID()));
3765 if (clang::NamedDecl *clang_imported_decl = llvm::dyn_cast<clang::NamedDecl>((clang::Decl *)imported_decl.GetOpaqueDecl()))
3766 decl = m_ast.CreateUsingDeclaration(decl_context, clang_imported_decl);
3771 case DW_TAG_imported_module:
3773 SymbolFileDWARF *dwarf = die.GetDWARF();
3774 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3778 CompilerDeclContext imported_decl_ctx = imported_uid.GetDeclContext();
3779 if (imported_decl_ctx)
3781 clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext(dwarf->GetDeclContextContainingUID(die.GetID()));
3782 if (clang::NamespaceDecl *ns_decl = ClangASTContext::DeclContextGetAsNamespaceDecl(imported_decl_ctx))
3783 decl = m_ast.CreateUsingDirectiveDeclaration(decl_context, ns_decl);
3792 m_die_to_decl[die.GetDIE()] = decl;
3793 m_decl_to_die[decl].insert(die.GetDIE());
3798 clang::DeclContext *
3799 DWARFASTParserClang::GetClangDeclContextForDIE (const DWARFDIE &die)
3803 clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE (die);
3807 bool try_parsing_type = true;
3810 case DW_TAG_compile_unit:
3811 decl_ctx = m_ast.GetTranslationUnitDecl();
3812 try_parsing_type = false;
3815 case DW_TAG_namespace:
3816 decl_ctx = ResolveNamespaceDIE (die);
3817 try_parsing_type = false;
3820 case DW_TAG_lexical_block:
3821 decl_ctx = (clang::DeclContext *)ResolveBlockDIE(die);
3822 try_parsing_type = false;
3829 if (decl_ctx == nullptr && try_parsing_type)
3831 Type* type = die.GetDWARF()->ResolveType (die);
3833 decl_ctx = GetCachedClangDeclContextForDIE (die);
3838 LinkDeclContextToDIE (decl_ctx, die);
3846 DWARFASTParserClang::ResolveBlockDIE (const DWARFDIE &die)
3848 if (die && die.Tag() == DW_TAG_lexical_block)
3850 clang::BlockDecl *decl = llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]);
3854 DWARFDIE decl_context_die;
3855 clang::DeclContext *decl_context = GetClangDeclContextContainingDIE(die, &decl_context_die);
3856 decl = m_ast.CreateBlockDeclaration(decl_context);
3859 LinkDeclContextToDIE((clang::DeclContext *)decl, die);
3867 clang::NamespaceDecl *
3868 DWARFASTParserClang::ResolveNamespaceDIE (const DWARFDIE &die)
3870 if (die && die.Tag() == DW_TAG_namespace)
3872 // See if we already parsed this namespace DIE and associated it with a
3873 // uniqued namespace declaration
3874 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]);
3876 return namespace_decl;
3879 const char *namespace_name = die.GetName();
3880 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (die, nullptr);
3881 namespace_decl = m_ast.GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
3882 Log *log = nullptr;// (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3885 SymbolFileDWARF *dwarf = die.GetDWARF();
3888 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
3889 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
3890 static_cast<void*>(m_ast.getASTContext()),
3893 static_cast<void*>(namespace_decl),
3894 static_cast<void*>(namespace_decl->getOriginalNamespace()));
3898 dwarf->GetObjectFile()->GetModule()->LogMessage (log,
3899 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
3900 static_cast<void*>(m_ast.getASTContext()),
3902 static_cast<void*>(namespace_decl),
3903 static_cast<void*>(namespace_decl->getOriginalNamespace()));
3908 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
3909 return namespace_decl;
3915 clang::DeclContext *
3916 DWARFASTParserClang::GetClangDeclContextContainingDIE (const DWARFDIE &die,
3917 DWARFDIE *decl_ctx_die_copy)
3919 SymbolFileDWARF *dwarf = die.GetDWARF();
3921 DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE (die);
3923 if (decl_ctx_die_copy)
3924 *decl_ctx_die_copy = decl_ctx_die;
3928 clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE (decl_ctx_die);
3930 return clang_decl_ctx;
3932 return m_ast.GetTranslationUnitDecl();
3935 clang::DeclContext *
3936 DWARFASTParserClang::GetCachedClangDeclContextForDIE (const DWARFDIE &die)
3940 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE());
3941 if (pos != m_die_to_decl_ctx.end())
3948 DWARFASTParserClang::LinkDeclContextToDIE (clang::DeclContext *decl_ctx, const DWARFDIE &die)
3950 m_die_to_decl_ctx[die.GetDIE()] = decl_ctx;
3951 // There can be many DIEs for a single decl context
3952 //m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE());
3953 m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die));
3957 DWARFASTParserClang::CopyUniqueClassMethodTypes (const DWARFDIE &src_class_die,
3958 const DWARFDIE &dst_class_die,
3959 lldb_private::Type *class_type,
3960 DWARFDIECollection &failures)
3962 if (!class_type || !src_class_die || !dst_class_die)
3964 if (src_class_die.Tag() != dst_class_die.Tag())
3967 // We need to complete the class type so we can get all of the method types
3968 // parsed so we can then unique those types to their equivalent counterparts
3969 // in "dst_cu" and "dst_class_die"
3970 class_type->GetFullCompilerType ();
3974 UniqueCStringMap<DWARFDIE> src_name_to_die;
3975 UniqueCStringMap<DWARFDIE> dst_name_to_die;
3976 UniqueCStringMap<DWARFDIE> src_name_to_die_artificial;
3977 UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial;
3978 for (src_die = src_class_die.GetFirstChild(); src_die.IsValid(); src_die = src_die.GetSibling())
3980 if (src_die.Tag() == DW_TAG_subprogram)
3982 // Make sure this is a declaration and not a concrete instance by looking
3983 // for DW_AT_declaration set to 1. Sometimes concrete function instances
3984 // are placed inside the class definitions and shouldn't be included in
3985 // the list of things are are tracking here.
3986 if (src_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1)
3988 const char *src_name = src_die.GetMangledName ();
3991 ConstString src_const_name(src_name);
3992 if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
3993 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
3995 src_name_to_die.Append(src_const_name.GetCString(), src_die);
4000 for (dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid(); dst_die = dst_die.GetSibling())
4002 if (dst_die.Tag() == DW_TAG_subprogram)
4004 // Make sure this is a declaration and not a concrete instance by looking
4005 // for DW_AT_declaration set to 1. Sometimes concrete function instances
4006 // are placed inside the class definitions and shouldn't be included in
4007 // the list of things are are tracking here.
4008 if (dst_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1)
4010 const char *dst_name = dst_die.GetMangledName ();
4013 ConstString dst_const_name(dst_name);
4014 if ( dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
4015 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
4017 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
4022 const uint32_t src_size = src_name_to_die.GetSize ();
4023 const uint32_t dst_size = dst_name_to_die.GetSize ();
4024 Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
4026 // Is everything kosher so we can go through the members at top speed?
4027 bool fast_path = true;
4029 if (src_size != dst_size)
4031 if (src_size != 0 && dst_size != 0)
4034 log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)",
4035 src_class_die.GetOffset(),
4036 dst_class_die.GetOffset(),
4048 for (idx = 0; idx < src_size; ++idx)
4050 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4051 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4053 if (src_die.Tag() != dst_die.Tag())
4056 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)",
4057 src_class_die.GetOffset(),
4058 dst_class_die.GetOffset(),
4059 src_die.GetOffset(),
4060 src_die.GetTagAsCString(),
4061 dst_die.GetOffset(),
4062 dst_die.GetTagAsCString());
4066 const char *src_name = src_die.GetMangledName ();
4067 const char *dst_name = dst_die.GetMangledName ();
4069 // Make sure the names match
4070 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
4074 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)",
4075 src_class_die.GetOffset(),
4076 dst_class_die.GetOffset(),
4077 src_die.GetOffset(),
4079 dst_die.GetOffset(),
4086 DWARFASTParserClang *src_dwarf_ast_parser = (DWARFASTParserClang *)src_die.GetDWARFParser();
4087 DWARFASTParserClang *dst_dwarf_ast_parser = (DWARFASTParserClang *)dst_die.GetDWARFParser();
4089 // Now do the work of linking the DeclContexts and Types.
4092 // We can do this quickly. Just run across the tables index-for-index since
4093 // we know each node has matching names and tags.
4094 for (idx = 0; idx < src_size; ++idx)
4096 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
4097 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
4099 clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()];
4103 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
4104 static_cast<void*>(src_decl_ctx),
4105 src_die.GetOffset(), dst_die.GetOffset());
4106 dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die);
4111 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found",
4112 src_die.GetOffset(), dst_die.GetOffset());
4115 Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()];
4119 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
4120 static_cast<void*>(src_child_type),
4121 src_child_type->GetID(),
4122 src_die.GetOffset(), dst_die.GetOffset());
4123 dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type;
4128 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset());
4134 // We must do this slowly. For each member of the destination, look
4135 // up a member in the source with the same name, check its tag, and
4136 // unique them if everything matches up. Report failures.
4138 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
4140 src_name_to_die.Sort();
4142 for (idx = 0; idx < dst_size; ++idx)
4144 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
4145 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
4146 src_die = src_name_to_die.Find(dst_name, DWARFDIE());
4148 if (src_die && (src_die.Tag() == dst_die.Tag()))
4150 clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()];
4154 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
4155 static_cast<void*>(src_decl_ctx),
4156 src_die.GetOffset(),
4157 dst_die.GetOffset());
4158 dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die);
4163 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset());
4166 Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()];
4170 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
4171 static_cast<void*>(src_child_type),
4172 src_child_type->GetID(),
4173 src_die.GetOffset(),
4174 dst_die.GetOffset());
4175 dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type;
4180 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset());
4186 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die.GetOffset());
4188 failures.Append(dst_die);
4194 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
4195 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
4197 if (src_size_artificial && dst_size_artificial)
4199 dst_name_to_die_artificial.Sort();
4201 for (idx = 0; idx < src_size_artificial; ++idx)
4203 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
4204 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
4205 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE());
4209 // Both classes have the artificial types, link them
4210 clang::DeclContext *src_decl_ctx = src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()];
4214 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x",
4215 static_cast<void*>(src_decl_ctx),
4216 src_die.GetOffset(), dst_die.GetOffset());
4217 dst_dwarf_ast_parser->LinkDeclContextToDIE (src_decl_ctx, dst_die);
4222 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset());
4225 Type *src_child_type = dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()];
4229 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
4230 static_cast<void*>(src_child_type),
4231 src_child_type->GetID(),
4232 src_die.GetOffset(), dst_die.GetOffset());
4233 dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type;
4238 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die.GetOffset(), dst_die.GetOffset());
4244 if (dst_size_artificial)
4246 for (idx = 0; idx < dst_size_artificial; ++idx)
4248 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
4249 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
4251 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die.GetOffset(), dst_name_artificial);
4253 failures.Append(dst_die);
4257 return (failures.Size() != 0);