[lldb][NFC] Change FindDefinitionTypeForDWARFDeclContext() to take DWARFDIE

This simplifies an upcoming patch.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D138612
This commit is contained in:
Arthur Eubanks 2022-11-23 14:29:40 -08:00
parent a46a746cfa
commit c3c423b6cb
8 changed files with 103 additions and 123 deletions

View File

@ -753,17 +753,14 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
if (type_sp)
return type_sp;
DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
if (!type_sp) {
SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
if (debug_map_symfile) {
// We weren't able to find a full declaration in this DWARF,
// see if we have a declaration anywhere else...
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(
die_decl_ctx);
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(die);
}
}
@ -1732,19 +1729,16 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
if (type_sp)
return type_sp;
DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
// type_sp = FindDefinitionTypeForDIE (dwarf_cu, die,
// type_name_const_str);
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
if (!type_sp) {
SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
if (debug_map_symfile) {
// We weren't able to find a full declaration in this DWARF, see
// if we have a declaration anywhere else...
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(
die_decl_ctx);
type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(die);
}
}

View File

@ -75,15 +75,10 @@ public:
m_qualified_name.clear();
}
lldb::LanguageType GetLanguage() const { return m_language; }
void SetLanguage(lldb::LanguageType language) { m_language = language; }
protected:
typedef std::vector<Entry> collection;
collection m_entries;
mutable std::string m_qualified_name;
lldb::LanguageType m_language = lldb::eLanguageTypeUnknown;
};
#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H

View File

@ -2946,119 +2946,113 @@ bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1,
return true;
}
TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(
const DWARFDeclContext &dwarf_decl_ctx) {
TypeSP
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
TypeSP type_sp;
const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
if (dwarf_decl_ctx_count > 0) {
const ConstString type_name(dwarf_decl_ctx[0].name);
const dw_tag_t tag = dwarf_decl_ctx[0].tag;
const ConstString type_name(die.GetName());
if (type_name) {
const dw_tag_t tag = die.Tag();
if (type_name) {
Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
if (log) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%"
"s, qualified-name='%s')",
DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
dwarf_decl_ctx.GetQualifiedName());
Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
if (log) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%"
"s, name='%s')",
DW_TAG_value_to_name(tag), die.GetName());
}
// Get the type system that we are looking to find a type for. We will
// use this to ensure any matches we find are in a language that this
// type system supports
const LanguageType language = GetLanguage(*die.GetCU());
TypeSystemSP type_system = nullptr;
if (language != eLanguageTypeUnknown) {
auto type_system_or_err = GetTypeSystemForLanguage(language);
if (auto err = type_system_or_err.takeError()) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
"Cannot get TypeSystem for language {}",
Language::GetNameForLanguageType(language));
} else {
type_system = *type_system_or_err;
}
}
// Get the type system that we are looking to find a type for. We will
// use this to ensure any matches we find are in a language that this
// type system supports
const LanguageType language = dwarf_decl_ctx.GetLanguage();
TypeSystemSP type_system = nullptr;
if (language != eLanguageTypeUnknown) {
auto type_system_or_err = GetTypeSystemForLanguage(language);
if (auto err = type_system_or_err.takeError()) {
LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
"Cannot get TypeSystem for language {}",
Language::GetNameForLanguageType(language));
} else {
type_system = *type_system_or_err;
m_index->GetTypes(type_name, [&](DWARFDIE type_die) {
// Make sure type_die's language matches the type system we are
// looking for. We don't want to find a "Foo" type from Java if we
// are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
if (type_system &&
!type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
return true;
bool try_resolving_type = false;
// Don't try and resolve the DIE we are looking for with the DIE
// itself!
const dw_tag_t type_tag = type_die.Tag();
// Make sure the tags match
if (type_tag == tag) {
// The tags match, lets try resolving this type
try_resolving_type = true;
} else {
// The tags don't match, but we need to watch our for a forward
// declaration for a struct and ("struct foo") ends up being a
// class ("class foo { ... };") or vice versa.
switch (type_tag) {
case DW_TAG_class_type:
// We had a "class foo", see if we ended up with a "struct foo
// { ... };"
try_resolving_type = (tag == DW_TAG_structure_type);
break;
case DW_TAG_structure_type:
// We had a "struct foo", see if we ended up with a "class foo
// { ... };"
try_resolving_type = (tag == DW_TAG_class_type);
break;
default:
// Tags don't match, don't event try to resolve using this type
// whose name matches....
break;
}
}
m_index->GetTypes(dwarf_decl_ctx, [&](DWARFDIE type_die) {
// Make sure type_die's language matches the type system we are
// looking for. We don't want to find a "Foo" type from Java if we
// are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
if (type_system &&
!type_system->SupportsLanguage(GetLanguage(*type_die.GetCU())))
return true;
bool try_resolving_type = false;
// Don't try and resolve the DIE we are looking for with the DIE
// itself!
const dw_tag_t type_tag = type_die.Tag();
// Make sure the tags match
if (type_tag == tag) {
// The tags match, lets try resolving this type
try_resolving_type = true;
} else {
// The tags don't match, but we need to watch our for a forward
// declaration for a struct and ("struct foo") ends up being a
// class ("class foo { ... };") or vice versa.
switch (type_tag) {
case DW_TAG_class_type:
// We had a "class foo", see if we ended up with a "struct foo
// { ... };"
try_resolving_type = (tag == DW_TAG_structure_type);
break;
case DW_TAG_structure_type:
// We had a "struct foo", see if we ended up with a "class foo
// { ... };"
try_resolving_type = (tag == DW_TAG_class_type);
break;
default:
// Tags don't match, don't event try to resolve using this type
// whose name matches....
break;
}
}
if (!try_resolving_type) {
if (log) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::"
"FindDefinitionTypeForDWARFDeclContext(tag=%s, "
"qualified-name='%s') ignoring die=0x%8.8x (%s)",
DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(),
type_die.GetName());
}
return true;
}
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
if (!try_resolving_type) {
if (log) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::"
"FindDefinitionTypeForDWARFDeclContext(tag=%s, "
"qualified-name='%s') trying die=0x%8.8x (%s)",
DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(),
type_dwarf_decl_ctx.GetQualifiedName());
"name='%s') ignoring die=0x%8.8x (%s)",
DW_TAG_value_to_name(tag), die.GetName(), type_die.GetOffset(),
type_die.GetName());
}
return true;
}
// Make sure the decl contexts match all the way up
if (dwarf_decl_ctx != type_dwarf_decl_ctx)
return true;
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
Type *resolved_type = ResolveType(type_die, false);
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
return true;
if (log) {
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::"
"FindDefinitionTypeForDWARFDeclContext(tag=%s, "
"name='%s') trying die=0x%8.8x (%s)",
DW_TAG_value_to_name(tag), die.GetName(), type_die.GetOffset(),
type_dwarf_decl_ctx.GetQualifiedName());
}
type_sp = resolved_type->shared_from_this();
return false;
});
}
// Make sure the decl contexts match all the way up
if (GetDWARFDeclContext(die) != type_dwarf_decl_ctx)
return true;
Type *resolved_type = ResolveType(type_die, false);
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
return true;
type_sp = resolved_type->shared_from_this();
return false;
});
}
return type_sp;
}
@ -4172,7 +4166,6 @@ DWARFDeclContext SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die) {
return {};
DWARFDeclContext dwarf_decl_ctx =
die.GetDIE()->GetDWARFDeclContext(die.GetCU());
dwarf_decl_ctx.SetLanguage(GetLanguage(*die.GetCU()));
return dwarf_decl_ctx;
}

View File

@ -443,7 +443,7 @@ protected:
lldb_private::SymbolContext &sc);
virtual lldb::TypeSP
FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die);
virtual lldb::TypeSP
FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die,

View File

@ -1125,10 +1125,10 @@ SymbolFileDWARFDebugMap::ParseCallEdgesInFunction(UserID func_id) {
}
TypeSP SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext(
const DWARFDeclContext &die_decl_ctx) {
const DWARFDIE &die) {
TypeSP type_sp;
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext(die);
return ((bool)type_sp);
});
return type_sp;

View File

@ -282,8 +282,7 @@ protected:
CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
lldb::TypeSP
FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die);
bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);

View File

@ -117,10 +117,9 @@ UniqueDWARFASTTypeMap &SymbolFileDWARFDwo::GetUniqueDWARFASTTypeMap() {
return GetBaseSymbolFile().GetUniqueDWARFASTTypeMap();
}
lldb::TypeSP SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(
const DWARFDeclContext &die_decl_ctx) {
return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext(
die_decl_ctx);
lldb::TypeSP
SymbolFileDWARFDwo::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
return GetBaseSymbolFile().FindDefinitionTypeForDWARFDeclContext(die);
}
lldb::TypeSP SymbolFileDWARFDwo::FindCompleteObjCDefinitionTypeForDIE(

View File

@ -63,8 +63,8 @@ protected:
UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() override;
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(
const DWARFDeclContext &die_decl_ctx) override;
lldb::TypeSP
FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) override;
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
const DWARFDIE &die, lldb_private::ConstString type_name,