@@ -2946,119 +2946,112 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1,
29462946 return true ;
29472947}
29482948
2949- TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (
2950- const DWARFDeclContext &dwarf_decl_ctx ) {
2949+ TypeSP
2950+ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext ( const DWARFDIE &die ) {
29512951 TypeSP type_sp;
29522952
2953- const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize ();
2954- if (dwarf_decl_ctx_count > 0 ) {
2955- const ConstString type_name (dwarf_decl_ctx[0 ].name );
2956- const dw_tag_t tag = dwarf_decl_ctx[0 ].tag ;
2953+ if (die.GetName ()) {
2954+ const dw_tag_t tag = die.Tag ();
29572955
2958- if (type_name) {
2959- Log *log = GetLog (DWARFLog::TypeCompletion | DWARFLog::Lookups);
2960- if (log) {
2961- GetObjectFile ()->GetModule ()->LogMessage (
2962- log,
2963- " SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%"
2964- " s, qualified-name='%s')" ,
2965- DW_TAG_value_to_name (dwarf_decl_ctx[0 ].tag ),
2966- dwarf_decl_ctx.GetQualifiedName ());
2967- }
2956+ Log *log = GetLog (DWARFLog::TypeCompletion | DWARFLog::Lookups);
2957+ if (log) {
2958+ GetObjectFile ()->GetModule ()->LogMessage (
2959+ log,
2960+ " SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%"
2961+ " s, name='%s')" ,
2962+ DW_TAG_value_to_name (tag), die.GetName ());
2963+ }
29682964
2969- // Get the type system that we are looking to find a type for. We will
2970- // use this to ensure any matches we find are in a language that this
2971- // type system supports
2972- const LanguageType language = dwarf_decl_ctx.GetLanguage ();
2973- TypeSystemSP type_system = nullptr ;
2974- if (language != eLanguageTypeUnknown) {
2975- auto type_system_or_err = GetTypeSystemForLanguage (language);
2976- if (auto err = type_system_or_err.takeError ()) {
2977- LLDB_LOG_ERROR (GetLog (LLDBLog::Symbols), std::move (err),
2978- " Cannot get TypeSystem for language {}" ,
2979- Language::GetNameForLanguageType (language));
2980- } else {
2981- type_system = *type_system_or_err;
2982- }
2965+ // Get the type system that we are looking to find a type for. We will
2966+ // use this to ensure any matches we find are in a language that this
2967+ // type system supports
2968+ const LanguageType language = GetLanguage (*die.GetCU ());
2969+ TypeSystemSP type_system = nullptr ;
2970+ if (language != eLanguageTypeUnknown) {
2971+ auto type_system_or_err = GetTypeSystemForLanguage (language);
2972+ if (auto err = type_system_or_err.takeError ()) {
2973+ LLDB_LOG_ERROR (GetLog (LLDBLog::Symbols), std::move (err),
2974+ " Cannot get TypeSystem for language {}" ,
2975+ Language::GetNameForLanguageType (language));
2976+ } else {
2977+ type_system = *type_system_or_err;
29832978 }
2979+ }
29842980
2985- m_index->GetTypes (dwarf_decl_ctx, [&](DWARFDIE type_die) {
2986- // Make sure type_die's language matches the type system we are
2987- // looking for. We don't want to find a "Foo" type from Java if we
2988- // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
2989- if (type_system &&
2990- !type_system->SupportsLanguage (GetLanguage (*type_die.GetCU ())))
2991- return true ;
2992- bool try_resolving_type = false ;
2993-
2994- // Don't try and resolve the DIE we are looking for with the DIE
2995- // itself!
2996- const dw_tag_t type_tag = type_die.Tag ();
2997- // Make sure the tags match
2998- if (type_tag == tag) {
2999- // The tags match, lets try resolving this type
3000- try_resolving_type = true ;
3001- } else {
3002- // The tags don't match, but we need to watch our for a forward
3003- // declaration for a struct and ("struct foo") ends up being a
3004- // class ("class foo { ... };") or vice versa.
3005- switch (type_tag) {
3006- case DW_TAG_class_type:
3007- // We had a "class foo", see if we ended up with a "struct foo
3008- // { ... };"
3009- try_resolving_type = (tag == DW_TAG_structure_type);
3010- break ;
3011- case DW_TAG_structure_type:
3012- // We had a "struct foo", see if we ended up with a "class foo
3013- // { ... };"
3014- try_resolving_type = (tag == DW_TAG_class_type);
3015- break ;
3016- default :
3017- // Tags don't match, don't event try to resolve using this type
3018- // whose name matches....
3019- break ;
3020- }
3021- }
3022-
3023- if (!try_resolving_type) {
3024- if (log) {
3025- GetObjectFile ()->GetModule ()->LogMessage (
3026- log,
3027- " SymbolFileDWARF::"
3028- " FindDefinitionTypeForDWARFDeclContext(tag=%s, "
3029- " qualified-name='%s') ignoring die=0x%8.8x (%s)" ,
3030- DW_TAG_value_to_name (dwarf_decl_ctx[0 ].tag ),
3031- dwarf_decl_ctx.GetQualifiedName (), type_die.GetOffset (),
3032- type_die.GetName ());
3033- }
3034- return true ;
2981+ m_index->GetTypes (GetDWARFDeclContext (die), [&](DWARFDIE type_die) {
2982+ // Make sure type_die's language matches the type system we are
2983+ // looking for. We don't want to find a "Foo" type from Java if we
2984+ // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
2985+ if (type_system &&
2986+ !type_system->SupportsLanguage (GetLanguage (*type_die.GetCU ())))
2987+ return true ;
2988+ bool try_resolving_type = false ;
2989+
2990+ // Don't try and resolve the DIE we are looking for with the DIE
2991+ // itself!
2992+ const dw_tag_t type_tag = type_die.Tag ();
2993+ // Make sure the tags match
2994+ if (type_tag == tag) {
2995+ // The tags match, lets try resolving this type
2996+ try_resolving_type = true ;
2997+ } else {
2998+ // The tags don't match, but we need to watch our for a forward
2999+ // declaration for a struct and ("struct foo") ends up being a
3000+ // class ("class foo { ... };") or vice versa.
3001+ switch (type_tag) {
3002+ case DW_TAG_class_type:
3003+ // We had a "class foo", see if we ended up with a "struct foo
3004+ // { ... };"
3005+ try_resolving_type = (tag == DW_TAG_structure_type);
3006+ break ;
3007+ case DW_TAG_structure_type:
3008+ // We had a "struct foo", see if we ended up with a "class foo
3009+ // { ... };"
3010+ try_resolving_type = (tag == DW_TAG_class_type);
3011+ break ;
3012+ default :
3013+ // Tags don't match, don't event try to resolve using this type
3014+ // whose name matches....
3015+ break ;
30353016 }
3017+ }
30363018
3037- DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext (type_die);
3038-
3019+ if (!try_resolving_type) {
30393020 if (log) {
30403021 GetObjectFile ()->GetModule ()->LogMessage (
30413022 log,
30423023 " SymbolFileDWARF::"
30433024 " FindDefinitionTypeForDWARFDeclContext(tag=%s, "
3044- " qualified-name='%s') trying die=0x%8.8x (%s)" ,
3045- DW_TAG_value_to_name (dwarf_decl_ctx[0 ].tag ),
3046- dwarf_decl_ctx.GetQualifiedName (), type_die.GetOffset (),
3047- type_dwarf_decl_ctx.GetQualifiedName ());
3025+ " name='%s') ignoring die=0x%8.8x (%s)" ,
3026+ DW_TAG_value_to_name (tag), die.GetName (), type_die.GetOffset (),
3027+ type_die.GetName ());
30483028 }
3029+ return true ;
3030+ }
30493031
3050- // Make sure the decl contexts match all the way up
3051- if (dwarf_decl_ctx != type_dwarf_decl_ctx)
3052- return true ;
3032+ DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext (type_die);
30533033
3054- Type *resolved_type = ResolveType (type_die, false );
3055- if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
3056- return true ;
3034+ if (log) {
3035+ GetObjectFile ()->GetModule ()->LogMessage (
3036+ log,
3037+ " SymbolFileDWARF::"
3038+ " FindDefinitionTypeForDWARFDeclContext(tag=%s, "
3039+ " name='%s') trying die=0x%8.8x (%s)" ,
3040+ DW_TAG_value_to_name (tag), die.GetName (), type_die.GetOffset (),
3041+ type_dwarf_decl_ctx.GetQualifiedName ());
3042+ }
30573043
3058- type_sp = resolved_type->shared_from_this ();
3059- return false ;
3060- });
3061- }
3044+ // Make sure the decl contexts match all the way up
3045+ if (GetDWARFDeclContext (die) != type_dwarf_decl_ctx)
3046+ return true ;
3047+
3048+ Type *resolved_type = ResolveType (type_die, false );
3049+ if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
3050+ return true ;
3051+
3052+ type_sp = resolved_type->shared_from_this ();
3053+ return false ;
3054+ });
30623055 }
30633056 return type_sp;
30643057}
@@ -4172,7 +4165,6 @@ DWARFDeclContext SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die) {
41724165 return {};
41734166 DWARFDeclContext dwarf_decl_ctx =
41744167 die.GetDIE ()->GetDWARFDeclContext (die.GetCU ());
4175- dwarf_decl_ctx.SetLanguage (GetLanguage (*die.GetCU ()));
41764168 return dwarf_decl_ctx;
41774169}
41784170
0 commit comments