@@ -3045,118 +3045,113 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
30453045 return type_sp;
30463046}
30473047
3048- TypeSP
3049- SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDIE &die) {
3050- TypeSP type_sp;
3048+ DWARFDIE
3049+ SymbolFileDWARF::FindDefinitionDIE (const DWARFDIE &die) {
3050+ if (!die.GetName ())
3051+ return {};
30513052
3052- if (die.GetName ()) {
3053- const dw_tag_t tag = die.Tag ();
3053+ const dw_tag_t tag = die.Tag ();
30543054
3055- Log *log = GetLog (DWARFLog::TypeCompletion | DWARFLog::Lookups);
3056- if (log) {
3057- GetObjectFile ()->GetModule ()->LogMessage (
3058- log,
3059- " SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (tag={0} "
3060- " ({1}), name='{2}')" ,
3061- DW_TAG_value_to_name (tag), tag, die.GetName ());
3062- }
3055+ Log *log = GetLog (DWARFLog::TypeCompletion | DWARFLog::Lookups);
3056+ if (log) {
3057+ GetObjectFile ()->GetModule ()->LogMessage (
3058+ log,
3059+ " SymbolFileDWARF::FindDefinitionDIE (tag={0} "
3060+ " ({1}), name='{2}')" ,
3061+ DW_TAG_value_to_name (tag), tag, die.GetName ());
3062+ }
30633063
3064- // Get the type system that we are looking to find a type for. We will
3065- // use this to ensure any matches we find are in a language that this
3066- // type system supports
3067- const LanguageType language = GetLanguage (*die.GetCU ());
3068- TypeSystemSP type_system = nullptr ;
3069- if (language != eLanguageTypeUnknown) {
3070- auto type_system_or_err = GetTypeSystemForLanguage (language);
3071- if (auto err = type_system_or_err.takeError ()) {
3072- LLDB_LOG_ERROR (GetLog (LLDBLog::Symbols), std::move (err),
3073- " Cannot get TypeSystem for language {1}: {0}" ,
3074- Language::GetNameForLanguageType (language));
3075- } else {
3076- type_system = *type_system_or_err;
3077- }
3064+ // Get the type system that we are looking to find a type for. We will
3065+ // use this to ensure any matches we find are in a language that this
3066+ // type system supports
3067+ const LanguageType language = GetLanguage (*die.GetCU ());
3068+ TypeSystemSP type_system = nullptr ;
3069+ if (language != eLanguageTypeUnknown) {
3070+ auto type_system_or_err = GetTypeSystemForLanguage (language);
3071+ if (auto err = type_system_or_err.takeError ()) {
3072+ LLDB_LOG_ERROR (GetLog (LLDBLog::Symbols), std::move (err),
3073+ " Cannot get TypeSystem for language {1}: {0}" ,
3074+ Language::GetNameForLanguageType (language));
3075+ } else {
3076+ type_system = *type_system_or_err;
30783077 }
3078+ }
30793079
3080- // See comments below about -gsimple-template-names for why we attempt to
3081- // compute missing template parameter names.
3082- std::vector<std::string> template_params;
3083- DWARFDeclContext die_dwarf_decl_ctx;
3084- DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser () : nullptr ;
3085- for (DWARFDIE ctx_die = die; ctx_die && !isUnitType (ctx_die.Tag ());
3086- ctx_die = ctx_die.GetParentDeclContextDIE ()) {
3087- die_dwarf_decl_ctx.AppendDeclContext (ctx_die.Tag (), ctx_die.GetName ());
3088- template_params.push_back (
3089- (ctx_die.IsStructUnionOrClass () && dwarf_ast)
3090- ? dwarf_ast->GetDIEClassTemplateParams (ctx_die)
3091- : " " );
3092- }
3093- const bool any_template_params = llvm::any_of (
3094- template_params, [](llvm::StringRef p) { return !p.empty (); });
3095-
3096- auto die_matches = [&](DWARFDIE type_die) {
3097- // Resolve the type if both have the same tag or {class, struct} tags.
3098- const bool tag_matches =
3099- type_die.Tag () == tag ||
3100- (IsStructOrClassTag (type_die.Tag ()) && IsStructOrClassTag (tag));
3101- if (!tag_matches)
3102- return false ;
3103- if (any_template_params) {
3104- size_t pos = 0 ;
3105- for (DWARFDIE ctx_die = type_die;
3106- ctx_die && !isUnitType (ctx_die.Tag ()) &&
3107- pos < template_params.size ();
3108- ctx_die = ctx_die.GetParentDeclContextDIE (), ++pos) {
3109- if (template_params[pos].empty ())
3110- continue ;
3111- if (template_params[pos] != dwarf_ast->GetDIEClassTemplateParams (ctx_die))
3112- return false ;
3113- }
3114- if (pos != template_params.size ())
3080+ // See comments below about -gsimple-template-names for why we attempt to
3081+ // compute missing template parameter names.
3082+ std::vector<std::string> template_params;
3083+ DWARFDeclContext die_dwarf_decl_ctx;
3084+ DWARFASTParser *dwarf_ast =
3085+ type_system ? type_system->GetDWARFParser () : nullptr ;
3086+ for (DWARFDIE ctx_die = die; ctx_die && !isUnitType (ctx_die.Tag ());
3087+ ctx_die = ctx_die.GetParentDeclContextDIE ()) {
3088+ die_dwarf_decl_ctx.AppendDeclContext (ctx_die.Tag (), ctx_die.GetName ());
3089+ template_params.push_back (
3090+ (ctx_die.IsStructUnionOrClass () && dwarf_ast)
3091+ ? dwarf_ast->GetDIEClassTemplateParams (ctx_die)
3092+ : " " );
3093+ }
3094+ const bool any_template_params = llvm::any_of (
3095+ template_params, [](llvm::StringRef p) { return !p.empty (); });
3096+
3097+ auto die_matches = [&](DWARFDIE type_die) {
3098+ // Resolve the type if both have the same tag or {class, struct} tags.
3099+ const bool tag_matches =
3100+ type_die.Tag () == tag ||
3101+ (IsStructOrClassTag (type_die.Tag ()) && IsStructOrClassTag (tag));
3102+ if (!tag_matches)
3103+ return false ;
3104+ if (any_template_params) {
3105+ size_t pos = 0 ;
3106+ for (DWARFDIE ctx_die = type_die; ctx_die && !isUnitType (ctx_die.Tag ()) &&
3107+ pos < template_params.size ();
3108+ ctx_die = ctx_die.GetParentDeclContextDIE (), ++pos) {
3109+ if (template_params[pos].empty ())
3110+ continue ;
3111+ if (template_params[pos] !=
3112+ dwarf_ast->GetDIEClassTemplateParams (ctx_die))
31153113 return false ;
31163114 }
3115+ if (pos != template_params.size ())
3116+ return false ;
3117+ }
3118+ return true ;
3119+ };
3120+ DWARFDIE result;
3121+ m_index->GetFullyQualifiedType (die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
3122+ // Make sure type_die's language matches the type system we are
3123+ // looking for. We don't want to find a "Foo" type from Java if we
3124+ // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
3125+ if (type_system &&
3126+ !type_system->SupportsLanguage (GetLanguage (*type_die.GetCU ())))
31173127 return true ;
3118- };
3119- m_index->GetFullyQualifiedType (die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
3120- // Make sure type_die's language matches the type system we are
3121- // looking for. We don't want to find a "Foo" type from Java if we
3122- // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
3123- if (type_system &&
3124- !type_system->SupportsLanguage (GetLanguage (*type_die.GetCU ())))
3125- return true ;
3126-
3127- if (!die_matches (type_die)) {
3128- if (log) {
3129- GetObjectFile ()->GetModule ()->LogMessage (
3130- log,
3131- " SymbolFileDWARF::"
3132- " FindDefinitionTypeForDWARFDeclContext(tag={0} ({1}), "
3133- " name='{2}') ignoring die={3:x16} ({4})" ,
3134- DW_TAG_value_to_name (tag), tag, die.GetName (),
3135- type_die.GetOffset (), type_die.GetName ());
3136- }
3137- return true ;
3138- }
31393128
3129+ if (!die_matches (type_die)) {
31403130 if (log) {
3141- DWARFDeclContext type_dwarf_decl_ctx = type_die.GetDWARFDeclContext ();
31423131 GetObjectFile ()->GetModule ()->LogMessage (
31433132 log,
3144- " SymbolFileDWARF::"
3145- " FindDefinitionTypeForDWARFDeclContext(tag={0} ({1}), name='{2}') "
3146- " trying die={3:x16} ({4})" ,
3133+ " SymbolFileDWARF::FindDefinitionDIE(tag={0} ({1}), "
3134+ " name='{2}') ignoring die={3:x16} ({4})" ,
31473135 DW_TAG_value_to_name (tag), tag, die.GetName (), type_die.GetOffset (),
3148- type_dwarf_decl_ctx. GetQualifiedName ());
3136+ type_die. GetName ());
31493137 }
3138+ return true ;
3139+ }
31503140
3151- Type *resolved_type = ResolveType (type_die, false );
3152- if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
3153- return true ;
3141+ if (log) {
3142+ DWARFDeclContext type_dwarf_decl_ctx = type_die.GetDWARFDeclContext ();
3143+ GetObjectFile ()->GetModule ()->LogMessage (
3144+ log,
3145+ " SymbolFileDWARF::FindDefinitionTypeDIE(tag={0} ({1}), name='{2}') "
3146+ " trying die={3:x16} ({4})" ,
3147+ DW_TAG_value_to_name (tag), tag, die.GetName (), type_die.GetOffset (),
3148+ type_dwarf_decl_ctx.GetQualifiedName ());
3149+ }
31543150
3155- type_sp = resolved_type->shared_from_this ();
3156- return false ;
3157- });
3158- }
3159- return type_sp;
3151+ result = type_die;
3152+ return false ;
3153+ });
3154+ return result;
31603155}
31613156
31623157TypeSP SymbolFileDWARF::ParseType (const SymbolContext &sc, const DWARFDIE &die,
0 commit comments