Skip to content

[lldb][DWARFIndex] Adapt DWARFIndex DIERefCallback to IterationAction #152001

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ HasImplementationFlag(const llvm::AppleAcceleratorTable::Entry &entry) {
(*Flags & llvm::dwarf::AcceleratorTable::DW_FLAG_type_implementation);
}

void AppleDWARFIndex::SearchFor(const llvm::AppleAcceleratorTable &table,
llvm::StringRef name,
llvm::function_ref<bool(DWARFDIE die)> callback,
std::optional<dw_tag_t> search_for_tag,
std::optional<uint32_t> search_for_qualhash) {
void AppleDWARFIndex::SearchFor(
const llvm::AppleAcceleratorTable &table, llvm::StringRef name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
std::optional<dw_tag_t> search_for_tag,
std::optional<uint32_t> search_for_qualhash) {
auto converted_cb = DIERefCallback(callback, name);
for (const auto &entry : table.equal_range(name)) {
if (search_for_qualhash &&
!EntryHasMatchingQualhash(entry, *search_for_qualhash))
continue;
if (search_for_tag && !EntryHasMatchingTag(entry, *search_for_tag))
continue;
if (!converted_cb(entry))
if (converted_cb(entry) == IterationAction::Stop)
break;
}
}
Expand All @@ -140,7 +140,7 @@ void AppleDWARFIndex::GetGlobalVariables(
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_names_up)
return;
SearchFor(*m_apple_names_up, basename, IterationActionAdaptor(callback));
SearchFor(*m_apple_names_up, basename, callback);
}

void AppleDWARFIndex::GetGlobalVariables(
Expand All @@ -149,14 +149,12 @@ void AppleDWARFIndex::GetGlobalVariables(
if (!m_apple_names_up)
return;

auto adataped_cb = IterationActionAdaptor(callback);
DIERefCallbackImpl converted_cb =
DIERefCallback(adataped_cb, regex.GetText());
DIERefCallbackImpl converted_cb = DIERefCallback(callback, regex.GetText());

for (const auto &entry : m_apple_names_up->entries())
if (std::optional<llvm::StringRef> name = entry.readName();
name && Mangled(*name).NameMatches(regex))
if (!converted_cb(entry.BaseEntry))
if (converted_cb(entry.BaseEntry) == IterationAction::Stop)
return;
}

Expand All @@ -172,11 +170,10 @@ void AppleDWARFIndex::GetGlobalVariables(
return val.has_value() && *val >= lower_bound && *val < upper_bound;
};

auto adataped_cb = IterationActionAdaptor(callback);
DIERefCallbackImpl converted_cb = DIERefCallback(adataped_cb);
DIERefCallbackImpl converted_cb = DIERefCallback(callback);
for (auto entry : m_apple_names_up->entries()) {
if (is_in_range(entry.BaseEntry.getDIESectionOffset()))
if (!converted_cb(entry.BaseEntry))
if (converted_cb(entry.BaseEntry) == IterationAction::Stop)
return;
}
}
Expand All @@ -186,7 +183,7 @@ void AppleDWARFIndex::GetObjCMethods(
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_objc_up)
return;
SearchFor(*m_apple_objc_up, class_name, IterationActionAdaptor(callback));
SearchFor(*m_apple_objc_up, class_name, callback);
}

void AppleDWARFIndex::GetCompleteObjCClass(
Expand All @@ -196,8 +193,7 @@ void AppleDWARFIndex::GetCompleteObjCClass(
return;

llvm::SmallVector<DIERef> decl_dies;
auto adapted_cb = IterationActionAdaptor(callback);
auto converted_cb = DIERefCallback(adapted_cb, class_name);
auto converted_cb = DIERefCallback(callback, class_name);

for (const auto &entry : m_apple_types_up->equal_range(class_name)) {
if (HasImplementationFlag(entry)) {
Expand All @@ -212,7 +208,7 @@ void AppleDWARFIndex::GetCompleteObjCClass(
if (must_be_implementation)
return;
for (DIERef ref : decl_dies)
if (!converted_cb(ref))
if (converted_cb(ref) == IterationAction::Stop)
return;
}

Expand All @@ -221,7 +217,7 @@ void AppleDWARFIndex::GetTypes(
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_types_up)
return;
SearchFor(*m_apple_types_up, name, IterationActionAdaptor(callback));
SearchFor(*m_apple_types_up, name, callback);
}

void AppleDWARFIndex::GetTypes(
Expand All @@ -244,16 +240,14 @@ void AppleDWARFIndex::GetTypes(
llvm::djbHash(context.GetQualifiedName());
if (log)
m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()");
SearchFor(*m_apple_types_up, expected_name,
IterationActionAdaptor(callback), expected_tag,
SearchFor(*m_apple_types_up, expected_name, callback, expected_tag,
expected_qualname_hash);
return;
}

// Historically, if there are no tags, we also ignore qual_hash (why?)
if (!entries_have_tag) {
SearchFor(*m_apple_names_up, expected_name,
IterationActionAdaptor(callback));
SearchFor(*m_apple_names_up, expected_name, callback);
return;
}

Expand All @@ -272,16 +266,15 @@ void AppleDWARFIndex::GetTypes(
if (log)
m_module.LogMessage(log, "FindByNameAndTag()");
const dw_tag_t expected_tag = context[0].tag;
SearchFor(*m_apple_types_up, expected_name, IterationActionAdaptor(callback),
expected_tag);
SearchFor(*m_apple_types_up, expected_name, callback, expected_tag);
}

void AppleDWARFIndex::GetNamespaces(
ConstString name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_namespaces_up)
return;
SearchFor(*m_apple_namespaces_up, name, IterationActionAdaptor(callback));
SearchFor(*m_apple_namespaces_up, name, callback);
}

void AppleDWARFIndex::GetFunctions(
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ class AppleDWARFIndex : public DWARFIndex {
/// each match. If `search_for_tag` is provided, ignore entries whose tag is
/// not `search_for_tag`. If `search_for_qualhash` is provided, ignore entries
/// whose qualified name hash does not match `search_for_qualhash`.
/// If `callback` returns false for an entry, the search is interrupted.
/// If `callback` returns `IterationAction::Stop` for an entry, the search is
/// interrupted.
void SearchFor(const llvm::AppleAcceleratorTable &table, llvm::StringRef name,
llvm::function_ref<bool(DWARFDIE die)> callback,
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
std::optional<dw_tag_t> search_for_tag = std::nullopt,
std::optional<uint32_t> search_for_qualhash = std::nullopt);
};
Expand Down
9 changes: 5 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,22 @@ IterationAction DWARFIndex::ProcessFunctionDIE(
}

DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl(
const DWARFIndex &index, llvm::function_ref<bool(DWARFDIE die)> callback,
const DWARFIndex &index,
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
llvm::StringRef name)
: m_index(index),
m_dwarf(*llvm::cast<SymbolFileDWARF>(
index.m_module.GetSymbolFile()->GetBackingSymbolFile())),
m_callback(callback), m_name(name) {}

bool DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {
IterationAction DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const {
if (DWARFDIE die = m_dwarf.GetDIE(ref))
return m_callback(die);
m_index.ReportInvalidDIERef(ref, m_name);
return true;
return IterationAction::Continue;
}

bool DWARFIndex::DIERefCallbackImpl::operator()(
IterationAction DWARFIndex::DIERefCallbackImpl::operator()(
const llvm::AppleAcceleratorTable::Entry &entry) const {
return this->operator()(DIERef(std::nullopt, DIERef::Section::DebugInfo,
*entry.getDIESectionOffset()));
Expand Down
16 changes: 9 additions & 7 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,22 @@ class DWARFIndex {

class DIERefCallbackImpl {
public:
DIERefCallbackImpl(const DWARFIndex &index,
llvm::function_ref<bool(DWARFDIE die)> callback,
llvm::StringRef name);
bool operator()(DIERef ref) const;
bool operator()(const llvm::AppleAcceleratorTable::Entry &entry) const;
DIERefCallbackImpl(
const DWARFIndex &index,
llvm::function_ref<IterationAction(DWARFDIE die)> callback,
llvm::StringRef name);
IterationAction operator()(DIERef ref) const;
IterationAction
operator()(const llvm::AppleAcceleratorTable::Entry &entry) const;

private:
const DWARFIndex &m_index;
SymbolFileDWARF &m_dwarf;
const llvm::function_ref<bool(DWARFDIE die)> m_callback;
const llvm::function_ref<IterationAction(DWARFDIE die)> m_callback;
const llvm::StringRef m_name;
};
DIERefCallbackImpl
DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback,
DIERefCallback(llvm::function_ref<IterationAction(DWARFDIE die)> callback,
llvm::StringRef name = {}) const {
return DIERefCallbackImpl(*this, callback, name);
}
Expand Down
74 changes: 33 additions & 41 deletions lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,67 +417,61 @@ void ManualDWARFIndex::GetGlobalVariables(
ConstString basename,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.globals.Find(basename, DIERefCallback(IterationActionAdaptor(callback),
basename.GetStringRef()));
m_set.globals.Find(basename,
DIERefCallback(callback, basename.GetStringRef()));
}

void ManualDWARFIndex::GetGlobalVariables(
const RegularExpression &regex,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.globals.Find(
regex, DIERefCallback(IterationActionAdaptor(callback), regex.GetText()));
m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText()));
}

void ManualDWARFIndex::GetGlobalVariables(
DWARFUnit &unit,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.globals.FindAllEntriesForUnit(
unit, DIERefCallback(IterationActionAdaptor(callback)));
m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback));
}

void ManualDWARFIndex::GetObjCMethods(
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.objc_class_selectors.Find(
class_name, DIERefCallback(IterationActionAdaptor(callback),
class_name.GetStringRef()));
class_name, DIERefCallback(callback, class_name.GetStringRef()));
}

void ManualDWARFIndex::GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.types.Find(class_name, DIERefCallback(IterationActionAdaptor(callback),
class_name.GetStringRef()));
m_set.types.Find(class_name,
DIERefCallback(callback, class_name.GetStringRef()));
}

void ManualDWARFIndex::GetTypes(
ConstString name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.types.Find(name, DIERefCallback(IterationActionAdaptor(callback),
name.GetStringRef()));
m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef()));
}

void ManualDWARFIndex::GetTypes(
const DWARFDeclContext &context,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
auto name = context[0].name;
m_set.types.Find(
ConstString(name),
DIERefCallback(IterationActionAdaptor(callback), llvm::StringRef(name)));
m_set.types.Find(ConstString(name),
DIERefCallback(callback, llvm::StringRef(name)));
}

void ManualDWARFIndex::GetNamespaces(
ConstString name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();
m_set.namespaces.Find(name, DIERefCallback(IterationActionAdaptor(callback),
name.GetStringRef()));
m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef()));
}

void ManualDWARFIndex::GetFunctions(
Expand All @@ -490,39 +484,39 @@ void ManualDWARFIndex::GetFunctions(

if (name_type_mask & eFunctionNameTypeFull) {
if (!m_set.function_fullnames.Find(
name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
if (!SymbolFileDWARF::DIEInDeclContext(
parent_decl_ctx, die))
return IterationAction::Continue;
return callback(die);
}),
name.GetStringRef())))
name, DIERefCallback(
[&](DWARFDIE die) {
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
die))
return IterationAction::Continue;
return callback(die);
},
name.GetStringRef())))
return;
}
if (name_type_mask & eFunctionNameTypeBase) {
if (!m_set.function_basenames.Find(
name, DIERefCallback(IterationActionAdaptor([&](DWARFDIE die) {
if (!SymbolFileDWARF::DIEInDeclContext(
parent_decl_ctx, die))
return IterationAction::Continue;
return callback(die);
}),
name.GetStringRef())))
name, DIERefCallback(
[&](DWARFDIE die) {
if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx,
die))
return IterationAction::Continue;
return callback(die);
},
name.GetStringRef())))
return;
}

if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) {
if (!m_set.function_methods.Find(
name, DIERefCallback(IterationActionAdaptor(callback),
name.GetStringRef())))
name, DIERefCallback(callback, name.GetStringRef())))
return;
}

if (name_type_mask & eFunctionNameTypeSelector &&
!parent_decl_ctx.IsValid()) {
if (!m_set.function_selectors.Find(
name, DIERefCallback(IterationActionAdaptor(callback),
name.GetStringRef())))
name, DIERefCallback(callback, name.GetStringRef())))
return;
}
}
Expand All @@ -532,13 +526,11 @@ void ManualDWARFIndex::GetFunctions(
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
Index();

if (!m_set.function_basenames.Find(
regex,
DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
if (!m_set.function_basenames.Find(regex,
DIERefCallback(callback, regex.GetText())))
return;
if (!m_set.function_fullnames.Find(
regex,
DIERefCallback(IterationActionAdaptor(callback), regex.GetText())))
if (!m_set.function_fullnames.Find(regex,
DIERefCallback(callback, regex.GetText())))
return;
}

Expand Down
Loading
Loading