Skip to content

Commit 61aed52

Browse files
committed
[lldb] Change FindDefinitionTypeForDWARFDeclContext() to take DWARFDIE
This simplifies an upcoming patch. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D138612
1 parent 3c51ea3 commit 61aed52

File tree

8 files changed

+102
-123
lines changed

8 files changed

+102
-123
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,17 +753,14 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
753753
if (type_sp)
754754
return type_sp;
755755

756-
DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
757-
758-
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
756+
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
759757

760758
if (!type_sp) {
761759
SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
762760
if (debug_map_symfile) {
763761
// We weren't able to find a full declaration in this DWARF,
764762
// see if we have a declaration anywhere else...
765-
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(
766-
die_decl_ctx);
763+
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(die);
767764
}
768765
}
769766

@@ -1732,19 +1729,16 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
17321729
if (type_sp)
17331730
return type_sp;
17341731

1735-
DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
1736-
17371732
// type_sp = FindDefinitionTypeForDIE (dwarf_cu, die,
17381733
// type_name_const_str);
1739-
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
1734+
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
17401735

17411736
if (!type_sp) {
17421737
SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
17431738
if (debug_map_symfile) {
17441739
// We weren't able to find a full declaration in this DWARF, see
17451740
// if we have a declaration anywhere else...
1746-
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(
1747-
die_decl_ctx);
1741+
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(die);
17481742
}
17491743
}
17501744

lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,10 @@ class DWARFDeclContext {
7575
m_qualified_name.clear();
7676
}
7777

78-
lldb::LanguageType GetLanguage() const { return m_language; }
79-
80-
void SetLanguage(lldb::LanguageType language) { m_language = language; }
81-
8278
protected:
8379
typedef std::vector<Entry> collection;
8480
collection m_entries;
8581
mutable std::string m_qualified_name;
86-
lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
8782
};
8883

8984
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 89 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon,
443443
lldb_private::SymbolContext &sc);
444444

445445
virtual lldb::TypeSP
446-
FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
446+
FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die);
447447

448448
virtual lldb::TypeSP
449449
FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die,

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,10 @@ SymbolFileDWARFDebugMap::ParseCallEdgesInFunction(UserID func_id) {
11251125
}
11261126

11271127
TypeSP SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext(
1128-
const DWARFDeclContext &die_decl_ctx) {
1128+
const DWARFDIE &die) {
11291129
TypeSP type_sp;
11301130
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1131-
type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
1131+
type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext(die);
11321132
return ((bool)type_sp);
11331133
});
11341134
return type_sp;

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFileCommon {
282282

283283
CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
284284

285-
lldb::TypeSP
286-
FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
285+
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die);
287286

288287
bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
289288

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() {
117117
return GetBaseSymbolFile().GetUniqueDWARFASTTypeMap();
118118
}
119119

120-
lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(
121-
const DWARFDeclContext &die_decl_ctx) {
122-
return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext(
123-
die_decl_ctx);
120+
lldb::TypeSP
121+
SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
122+
return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext(die);
124123
}
125124

126125
lldb::TypeSP SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE(

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {
6363

6464
UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() override;
6565

66-
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(
67-
const DWARFDeclContext &die_decl_ctx) override;
66+
lldb::TypeSP
67+
FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) override;
6868

6969
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
7070
const DWARFDIE &die, lldb_private::ConstString type_name,

0 commit comments

Comments
 (0)