-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Improve namespace lookup using .debug_names parent chain #110062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,14 @@ class DWARFIndex { | |
virtual void | ||
GetTypesWithQuery(TypeQuery &query, | ||
llvm::function_ref<bool(DWARFDIE die)> callback); | ||
/// Get namespace DIEs whose base name match \param name with \param | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is out of date now. Update to mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no |
||
/// parent_decl_ctx in its decl parent chain. A base implementation | ||
/// is provided. Specializations should override this if they are able to | ||
/// provide a faster implementation. | ||
virtual void | ||
GetNamespacesWithParents(ConstString name, | ||
const CompilerDeclContext &parent_decl_ctx, | ||
llvm::function_ref<bool(DWARFDIE die)> callback); | ||
virtual void | ||
GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, | ||
const CompilerDeclContext &parent_decl_ctx, | ||
|
@@ -127,6 +135,9 @@ class DWARFIndex { | |
bool | ||
ProcessTypeDIEMatchQuery(TypeQuery &query, DWARFDIE die, | ||
llvm::function_ref<bool(DWARFDIE die)> callback); | ||
bool ProcessNamespaceDieMatchParents( | ||
const CompilerDeclContext &parent_decl_ctx, DWARFDIE die, | ||
llvm::function_ref<bool(DWARFDIE die)> callback); | ||
}; | ||
} // namespace dwarf | ||
} // namespace lldb_private::plugin | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -368,9 +368,10 @@ void DebugNamesDWARFIndex::GetFullyQualifiedType( | |||||||||||||
continue; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (SameParentChain(parent_names, *parent_chain) && | ||||||||||||||
!ProcessEntry(entry, callback)) | ||||||||||||||
return; | ||||||||||||||
if (SameParentChain(parent_names, *parent_chain)) { | ||||||||||||||
if (!ProcessEntry(entry, callback)) | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
m_fallback.GetFullyQualifiedType(context, callback); | ||||||||||||||
} | ||||||||||||||
|
@@ -554,17 +555,60 @@ void DebugNamesDWARFIndex::GetTypesWithQuery( | |||||||||||||
continue; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (WithinParentChain(parent_contexts, *parent_chain) && | ||||||||||||||
!ProcessEntry(entry, [&](DWARFDIE die) { | ||||||||||||||
// After .debug_names filtering still sending to base class for | ||||||||||||||
// further filtering before calling the callback. | ||||||||||||||
return ProcessTypeDIEMatchQuery(query, die, callback); | ||||||||||||||
})) | ||||||||||||||
return; | ||||||||||||||
if (WithinParentChain(parent_contexts, *parent_chain)) { | ||||||||||||||
if (!ProcessEntry(entry, [&](DWARFDIE die) { | ||||||||||||||
// After .debug_names filtering still sending to base class for | ||||||||||||||
// further filtering before calling the callback. | ||||||||||||||
return ProcessTypeDIEMatchQuery(query, die, callback); | ||||||||||||||
})) | ||||||||||||||
// If the callback returns false, we're done. | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
m_fallback.GetTypesWithQuery(query, callback); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
void DebugNamesDWARFIndex::GetNamespacesWithParents( | ||||||||||||||
ConstString name, const CompilerDeclContext &parent_decl_ctx, | ||||||||||||||
llvm::function_ref<bool(DWARFDIE die)> callback) { | ||||||||||||||
std::vector<lldb_private::CompilerContext> parent_contexts = | ||||||||||||||
parent_decl_ctx.GetCompilerContext(); | ||||||||||||||
llvm::SmallVector<CompilerContext> parent_named_contexts; | ||||||||||||||
std::copy_if(parent_contexts.rbegin(), parent_contexts.rend(), | ||||||||||||||
std::back_inserter(parent_named_contexts), | ||||||||||||||
[](const CompilerContext &ctx) { return !ctx.name.IsEmpty(); }); | ||||||||||||||
Comment on lines
+576
to
+579
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you wanted to be really fancy, you could try something like this:
Suggested change
:P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for sharing, good to know. Did not find any lldb code using this API, so will keep existing code. |
||||||||||||||
for (const DebugNames::Entry &entry : | ||||||||||||||
m_debug_names_up->equal_range(name.GetStringRef())) { | ||||||||||||||
lldb_private::dwarf::Tag entry_tag = entry.tag(); | ||||||||||||||
if (entry_tag == DW_TAG_namespace || | ||||||||||||||
entry_tag == DW_TAG_imported_declaration) { | ||||||||||||||
std::optional<llvm::SmallVector<Entry, 4>> parent_chain = | ||||||||||||||
getParentChain(entry); | ||||||||||||||
if (!parent_chain) { | ||||||||||||||
// Fallback: use the base class implementation. | ||||||||||||||
if (!ProcessEntry(entry, [&](DWARFDIE die) { | ||||||||||||||
return ProcessNamespaceDieMatchParents(parent_decl_ctx, die, | ||||||||||||||
callback); | ||||||||||||||
})) | ||||||||||||||
return; | ||||||||||||||
continue; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (WithinParentChain(parent_named_contexts, *parent_chain)) { | ||||||||||||||
if (!ProcessEntry(entry, [&](DWARFDIE die) { | ||||||||||||||
// After .debug_names filtering still sending to base class for | ||||||||||||||
// further filtering before calling the callback. | ||||||||||||||
return ProcessNamespaceDieMatchParents(parent_decl_ctx, die, | ||||||||||||||
callback); | ||||||||||||||
})) | ||||||||||||||
// If the callback returns false, we're done. | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
m_fallback.GetNamespacesWithParents(name, parent_decl_ctx, callback); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
void DebugNamesDWARFIndex::GetFunctions( | ||||||||||||||
const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, | ||||||||||||||
const CompilerDeclContext &parent_decl_ctx, | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
die
here aDW_AT_namespace
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes