https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/151668
>From 6fa2b6e3acaeffd5fd55f46eded372944ba2c328 Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Thu, 31 Jul 2025 14:50:59 +0100 Subject: [PATCH 1/4] Namespaces and global variables to IterationAction --- .../SymbolFile/DWARF/AppleDWARFIndex.cpp | 18 ++++++------ .../SymbolFile/DWARF/AppleDWARFIndex.h | 8 ++--- .../Plugins/SymbolFile/DWARF/DWARFIndex.cpp | 8 ++--- .../Plugins/SymbolFile/DWARF/DWARFIndex.h | 14 ++++----- .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 26 ++++++++--------- .../SymbolFile/DWARF/DebugNamesDWARFIndex.h | 11 +++---- .../SymbolFile/DWARF/ManualDWARFIndex.cpp | 16 +++++----- .../SymbolFile/DWARF/ManualDWARFIndex.h | 9 +++--- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 29 ++++++++++++------- 9 files changed, 75 insertions(+), 64 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index 9762ead3273da..8e09ce8650cb0 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -136,19 +136,19 @@ void AppleDWARFIndex::SearchFor(const llvm::AppleAcceleratorTable &table, } void AppleDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) { + ConstString basename, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!m_apple_names_up) return; - SearchFor(*m_apple_names_up, basename, callback); + SearchFor(*m_apple_names_up, basename, IterationActionAdaptor(callback)); } void AppleDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) { + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!m_apple_names_up) return; - DIERefCallbackImpl converted_cb = DIERefCallback(callback, regex.GetText()); + DIERefCallbackImpl converted_cb = DIERefCallback(IterationActionAdaptor(callback), regex.GetText()); for (const auto &entry : m_apple_names_up->entries()) if (std::optional<llvm::StringRef> name = entry.readName(); @@ -158,7 +158,7 @@ void AppleDWARFIndex::GetGlobalVariables( } void AppleDWARFIndex::GetGlobalVariables( - DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) { + DWARFUnit &cu, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!m_apple_names_up) return; @@ -169,7 +169,7 @@ void AppleDWARFIndex::GetGlobalVariables( return val.has_value() && *val >= lower_bound && *val < upper_bound; }; - DIERefCallbackImpl converted_cb = DIERefCallback(callback); + DIERefCallbackImpl converted_cb = DIERefCallback(IterationActionAdaptor(callback)); for (auto entry : m_apple_names_up->entries()) { if (is_in_range(entry.BaseEntry.getDIESectionOffset())) if (!converted_cb(entry.BaseEntry)) @@ -267,10 +267,10 @@ void AppleDWARFIndex::GetTypes( } void AppleDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) { + ConstString name, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!m_apple_namespaces_up) return; - SearchFor(*m_apple_namespaces_up, name, callback); + SearchFor(*m_apple_namespaces_up, name, IterationActionAdaptor(callback)); } void AppleDWARFIndex::GetFunctions( @@ -298,7 +298,7 @@ void AppleDWARFIndex::GetFunctions( void AppleDWARFIndex::GetFunctions( const RegularExpression ®ex, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { - return GetGlobalVariables(regex, IterationActionAdaptor(callback)); + return GetGlobalVariables(regex, callback); } void AppleDWARFIndex::Dump(Stream &s) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h index c0f0eb646ee98..1965ba7b59d57 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -43,13 +43,13 @@ class AppleDWARFIndex : public DWARFIndex { void GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetGlobalVariables(DWARFUnit &cu, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetCompleteObjCClass( @@ -60,7 +60,7 @@ class AppleDWARFIndex : public DWARFIndex { void GetTypes(const DWARFDeclContext &context, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetNamespaces(ConstString name, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetFunctions( const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp index a8065061fdf21..579103046644d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp @@ -165,16 +165,16 @@ bool DWARFIndex::ProcessTypeDIEMatchQuery( void DWARFIndex::GetNamespacesWithParents( ConstString name, const CompilerDeclContext &parent_decl_ctx, - llvm::function_ref<bool(DWARFDIE die)> callback) { + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { GetNamespaces(name, [&](DWARFDIE die) { return ProcessNamespaceDieMatchParents(parent_decl_ctx, die, callback); }); } -bool DWARFIndex::ProcessNamespaceDieMatchParents( +IterationAction DWARFIndex::ProcessNamespaceDieMatchParents( const CompilerDeclContext &parent_decl_ctx, DWARFDIE die, - llvm::function_ref<bool(DWARFDIE die)> callback) { + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - return true; + return IterationAction::Continue; return callback(die); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h index 3578824e720fb..bef0d42441da6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -35,15 +35,15 @@ class DWARFIndex { /// the consumer. virtual void GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DWARFDIE die)> callback) = 0; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; virtual void GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) = 0; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; /// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit(). virtual void GetGlobalVariables(DWARFUnit &cu, - llvm::function_ref<bool(DWARFDIE die)> callback) = 0; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; virtual void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) = 0; @@ -64,7 +64,7 @@ class DWARFIndex { llvm::function_ref<bool(DWARFDIE die)> callback); virtual void GetNamespaces(ConstString name, - llvm::function_ref<bool(DWARFDIE die)> callback) = 0; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; /// Get type DIEs meeting requires of \a query. /// in its decl parent chain as subset. A base implementation is provided, /// Specializations should override this if they are able to provide a faster @@ -79,7 +79,7 @@ class DWARFIndex { virtual void GetNamespacesWithParents(ConstString name, const CompilerDeclContext &parent_decl_ctx, - llvm::function_ref<bool(DWARFDIE die)> callback); + llvm::function_ref<IterationAction(DWARFDIE die)> callback); virtual void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, @@ -139,9 +139,9 @@ class DWARFIndex { bool ProcessTypeDIEMatchQuery(TypeQuery &query, DWARFDIE die, llvm::function_ref<bool(DWARFDIE die)> callback); - bool ProcessNamespaceDieMatchParents( + IterationAction ProcessNamespaceDieMatchParents( const CompilerDeclContext &parent_decl_ctx, DWARFDIE die, - llvm::function_ref<bool(DWARFDIE die)> callback); + llvm::function_ref<IterationAction(DWARFDIE die)> callback); /// Helper to convert callbacks that return an \c IterationAction /// to a callback that returns a \c bool, where \c true indicates diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index 3ae9fcc70893b..b998a21150883 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -178,13 +178,13 @@ void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, } void DebugNamesDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) { + ConstString basename, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(basename.GetStringRef())) { if (entry.tag() != DW_TAG_variable) continue; - if (!ProcessEntry(entry, callback)) + if (!ProcessEntry(entry, IterationActionAdaptor(callback))) return; } @@ -193,7 +193,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables( void DebugNamesDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) { + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { Mangled mangled_name(nte.getString()); @@ -206,7 +206,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables( if (entry_or->tag() != DW_TAG_variable) continue; - if (!ProcessEntry(*entry_or, callback)) + if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback))) return; } MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); @@ -217,7 +217,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables( } void DebugNamesDWARFIndex::GetGlobalVariables( - DWARFUnit &cu, llvm::function_ref<bool(DWARFDIE die)> callback) { + DWARFUnit &cu, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { uint64_t cu_offset = cu.GetOffset(); bool found_entry_for_cu = false; for (const DebugNames::NameIndex &ni : *m_debug_names_up) { @@ -242,7 +242,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables( continue; found_entry_for_cu = true; - if (!ProcessEntry(*entry_or, callback)) + if (!ProcessEntry(*entry_or, IterationActionAdaptor(callback))) return; } MaybeLogLookupError(entry_or.takeError(), ni, nte.getString()); @@ -482,13 +482,13 @@ void DebugNamesDWARFIndex::GetTypes( } void DebugNamesDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) { + ConstString name, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { llvm::dwarf::Tag entry_tag = entry.tag(); if (entry_tag == DW_TAG_namespace || entry_tag == DW_TAG_imported_declaration) { - if (!ProcessEntry(entry, callback)) + if (!ProcessEntry(entry, IterationActionAdaptor(callback))) return; } } @@ -566,7 +566,7 @@ void DebugNamesDWARFIndex::GetTypesWithQuery( void DebugNamesDWARFIndex::GetNamespacesWithParents( ConstString name, const CompilerDeclContext &parent_decl_ctx, - llvm::function_ref<bool(DWARFDIE die)> callback) { + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { std::vector<lldb_private::CompilerContext> parent_contexts = parent_decl_ctx.GetCompilerContext(); llvm::SmallVector<CompilerContext> parent_named_contexts; @@ -582,21 +582,21 @@ void DebugNamesDWARFIndex::GetNamespacesWithParents( getParentChain(entry); if (!parent_chain) { // Fallback: use the base class implementation. - if (!ProcessEntry(entry, [&](DWARFDIE die) { + if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) { return ProcessNamespaceDieMatchParents(parent_decl_ctx, die, callback); - })) + }))) return; continue; } if (WithinParentChain(parent_named_contexts, *parent_chain)) { - if (!ProcessEntry(entry, [&](DWARFDIE die) { + if (!ProcessEntry(entry, IterationActionAdaptor([&](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; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h index 210591904e419..ebf23cbab4253 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -13,6 +13,7 @@ #include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" #include "lldb/Utility/ConstString.h" +#include "lldb/lldb-private-enumerations.h" #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" #include <optional> @@ -28,13 +29,13 @@ class DebugNamesDWARFIndex : public DWARFIndex { void GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetGlobalVariables(DWARFUnit &cu, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override {} @@ -51,13 +52,13 @@ class DebugNamesDWARFIndex : public DWARFIndex { void GetTypes(const DWARFDeclContext &context, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetNamespaces(ConstString name, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetTypesWithQuery(TypeQuery &query, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetNamespacesWithParents( ConstString name, const CompilerDeclContext &parent_decl_ctx, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetFunctions( const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index f96ac7e8793e4..542dec110bd75 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -414,23 +414,23 @@ void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, } void ManualDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<bool(DWARFDIE die)> callback) { + ConstString basename, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { Index(); m_set.globals.Find(basename, - DIERefCallback(callback, basename.GetStringRef())); + DIERefCallback(IterationActionAdaptor(callback), basename.GetStringRef())); } void ManualDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) { + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { Index(); - m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText())); + m_set.globals.Find(regex, DIERefCallback(IterationActionAdaptor(callback), regex.GetText())); } void ManualDWARFIndex::GetGlobalVariables( - DWARFUnit &unit, llvm::function_ref<bool(DWARFDIE die)> callback) { + DWARFUnit &unit, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { Index(); - m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback)); + m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(IterationActionAdaptor(callback))); } void ManualDWARFIndex::GetObjCMethods( @@ -464,9 +464,9 @@ void ManualDWARFIndex::GetTypes( } void ManualDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<bool(DWARFDIE die)> callback) { + ConstString name, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { Index(); - m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef())); + m_set.namespaces.Find(name, DIERefCallback(IterationActionAdaptor(callback), name.GetStringRef())); } void ManualDWARFIndex::GetFunctions( diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h index 5685ba456f423..d58f49f0001df 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -12,6 +12,7 @@ #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" #include "Plugins/SymbolFile/DWARF/ManualDWARFIndexSet.h" #include "Plugins/SymbolFile/DWARF/NameToDIE.h" +#include "lldb/lldb-private-enumerations.h" #include "llvm/ADT/DenseSet.h" namespace lldb_private::plugin { @@ -32,13 +33,13 @@ class ManualDWARFIndex : public DWARFIndex { void GetGlobalVariables(ConstString basename, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetGlobalVariables(DWARFUnit &unit, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetCompleteObjCClass( @@ -49,7 +50,7 @@ class ManualDWARFIndex : public DWARFIndex { void GetTypes(const DWARFDeclContext &context, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetNamespaces(ConstString name, - llvm::function_ref<bool(DWARFDIE die)> callback) override; + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetFunctions( const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index a3ba061424cc1..42a66ce75d6d6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2349,11 +2349,11 @@ void SymbolFileDWARF::FindGlobalVariables( assert(sc.module_sp); if (die.Tag() != DW_TAG_variable && die.Tag() != DW_TAG_member) - return true; + return IterationAction::Continue; auto *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); if (!dwarf_cu) - return true; + return IterationAction::Continue; sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); if (parent_decl_ctx) { @@ -2368,7 +2368,7 @@ void SymbolFileDWARF::FindGlobalVariables( if (!actual_parent_decl_ctx || (actual_parent_decl_ctx != parent_decl_ctx && !parent_decl_ctx.IsContainedInLookup(actual_parent_decl_ctx))) - return true; + return IterationAction::Continue; } } @@ -2382,7 +2382,10 @@ void SymbolFileDWARF::FindGlobalVariables( variables.RemoveVariableAtIndex(pruned_idx); } - return variables.GetSize() - original_size < max_matches; + if (variables.GetSize() - original_size < max_matches) + return IterationAction::Continue; + + return IterationAction::Stop; }); // Return the number of variable that were appended to the list @@ -2422,12 +2425,15 @@ void SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex, DWARFCompileUnit *dwarf_cu = llvm::dyn_cast<DWARFCompileUnit>(die.GetCU()); if (!dwarf_cu) - return true; + return IterationAction::Continue; sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); ParseAndAppendGlobalVariable(sc, die, variables); - return variables.GetSize() - original_size < max_matches; + if (variables.GetSize() - original_size < max_matches) + return IterationAction::Continue; + + return IterationAction::Stop; }); } @@ -2847,14 +2853,17 @@ SymbolFileDWARF::FindNamespace(ConstString name, m_index->GetNamespacesWithParents(name, parent_decl_ctx, [&](DWARFDIE die) { if (!DIEInDeclContext(parent_decl_ctx, die, only_root_namespaces)) - return true; // The containing decl contexts don't match + return IterationAction::Continue; DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); if (!dwarf_ast) - return true; + return IterationAction::Continue; namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); - return !namespace_decl_ctx.IsValid(); + if (namespace_decl_ctx.IsValid()) + return IterationAction::Stop; + + return IterationAction::Continue; }); if (log && namespace_decl_ctx) { @@ -3295,7 +3304,7 @@ size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) { variables->AddVariableIfUnique(var_sp); ++vars_added; } - return true; + return IterationAction::Continue; }); } return vars_added; >From 4f9b242974cf8f889f488fd1564fb86e945b21a3 Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Fri, 1 Aug 2025 09:14:28 +0100 Subject: [PATCH 2/4] fixup! clang-format --- .../SymbolFile/DWARF/AppleDWARFIndex.cpp | 12 ++++++--- .../SymbolFile/DWARF/AppleDWARFIndex.h | 23 +++++++++-------- .../Plugins/SymbolFile/DWARF/DWARFIndex.h | 25 +++++++++---------- .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 23 +++++++++-------- .../SymbolFile/DWARF/DebugNamesDWARFIndex.h | 23 +++++++++-------- .../SymbolFile/DWARF/ManualDWARFIndex.cpp | 22 ++++++++++------ .../SymbolFile/DWARF/ManualDWARFIndex.h | 23 +++++++++-------- 7 files changed, 83 insertions(+), 68 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index 8e09ce8650cb0..0414d83b9155e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -136,7 +136,8 @@ void AppleDWARFIndex::SearchFor(const llvm::AppleAcceleratorTable &table, } void AppleDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + ConstString basename, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!m_apple_names_up) return; SearchFor(*m_apple_names_up, basename, IterationActionAdaptor(callback)); @@ -148,7 +149,8 @@ void AppleDWARFIndex::GetGlobalVariables( if (!m_apple_names_up) return; - DIERefCallbackImpl converted_cb = DIERefCallback(IterationActionAdaptor(callback), regex.GetText()); + DIERefCallbackImpl converted_cb = + DIERefCallback(IterationActionAdaptor(callback), regex.GetText()); for (const auto &entry : m_apple_names_up->entries()) if (std::optional<llvm::StringRef> name = entry.readName(); @@ -169,7 +171,8 @@ void AppleDWARFIndex::GetGlobalVariables( return val.has_value() && *val >= lower_bound && *val < upper_bound; }; - DIERefCallbackImpl converted_cb = DIERefCallback(IterationActionAdaptor(callback)); + DIERefCallbackImpl converted_cb = + DIERefCallback(IterationActionAdaptor(callback)); for (auto entry : m_apple_names_up->entries()) { if (is_in_range(entry.BaseEntry.getDIESectionOffset())) if (!converted_cb(entry.BaseEntry)) @@ -267,7 +270,8 @@ void AppleDWARFIndex::GetTypes( } void AppleDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + ConstString name, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { if (!m_apple_namespaces_up) return; SearchFor(*m_apple_namespaces_up, name, IterationActionAdaptor(callback)); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h index 1965ba7b59d57..74da0b2d051f6 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -41,15 +41,15 @@ class AppleDWARFIndex : public DWARFIndex { void Preload() override {} - void - GetGlobalVariables(ConstString basename, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; - void - GetGlobalVariables(DWARFUnit &cu, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + ConstString basename, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + DWARFUnit &cu, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetCompleteObjCClass( @@ -59,8 +59,9 @@ class AppleDWARFIndex : public DWARFIndex { llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetTypes(const DWARFDeclContext &context, llvm::function_ref<bool(DWARFDIE die)> callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetNamespaces( + ConstString name, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetFunctions( const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h index bef0d42441da6..6718024a42e8c 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -33,17 +33,17 @@ class DWARFIndex { /// Finds global variables with the given base name. Any additional filtering /// (e.g., to only retrieve variables from a given context) should be done by /// the consumer. - virtual void - GetGlobalVariables(ConstString basename, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; + virtual void GetGlobalVariables( + ConstString basename, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; - virtual void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; + virtual void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; /// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit(). - virtual void - GetGlobalVariables(DWARFUnit &cu, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; + virtual void GetGlobalVariables( + DWARFUnit &cu, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0; virtual void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) = 0; @@ -76,10 +76,9 @@ class DWARFIndex { /// 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<IterationAction(DWARFDIE die)> callback); + virtual void GetNamespacesWithParents( + ConstString name, const CompilerDeclContext &parent_decl_ctx, + llvm::function_ref<IterationAction(DWARFDIE die)> callback); virtual void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp index b998a21150883..8944005ab356a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -178,7 +178,8 @@ void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, } void DebugNamesDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + ConstString basename, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(basename.GetStringRef())) { if (entry.tag() != DW_TAG_variable) @@ -482,7 +483,8 @@ void DebugNamesDWARFIndex::GetTypes( } void DebugNamesDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + ConstString name, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { llvm::dwarf::Tag entry_tag = entry.tag(); @@ -583,20 +585,21 @@ void DebugNamesDWARFIndex::GetNamespacesWithParents( if (!parent_chain) { // Fallback: use the base class implementation. if (!ProcessEntry(entry, IterationActionAdaptor([&](DWARFDIE die) { - return ProcessNamespaceDieMatchParents(parent_decl_ctx, die, - callback); - }))) + return ProcessNamespaceDieMatchParents( + parent_decl_ctx, die, callback); + }))) return; continue; } if (WithinParentChain(parent_named_contexts, *parent_chain)) { if (!ProcessEntry(entry, IterationActionAdaptor([&](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); - }))) + // 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; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h index ebf23cbab4253..deee6b7c30516 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -27,15 +27,15 @@ class DebugNamesDWARFIndex : public DWARFIndex { void Preload() override { m_fallback.Preload(); } - void - GetGlobalVariables(ConstString basename, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; - void - GetGlobalVariables(DWARFUnit &cu, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + ConstString basename, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + DWARFUnit &cu, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override {} @@ -51,8 +51,9 @@ class DebugNamesDWARFIndex : public DWARFIndex { llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetTypes(const DWARFDeclContext &context, llvm::function_ref<bool(DWARFDIE die)> callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetNamespaces( + ConstString name, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetTypesWithQuery(TypeQuery &query, llvm::function_ref<bool(DWARFDIE die)> callback) override; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index 542dec110bd75..45179274c8b4f 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -414,23 +414,27 @@ void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, } void ManualDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + 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(IterationActionAdaptor(callback), + basename.GetStringRef())); } void ManualDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { Index(); - m_set.globals.Find(regex, DIERefCallback(IterationActionAdaptor(callback), regex.GetText())); + m_set.globals.Find( + regex, DIERefCallback(IterationActionAdaptor(callback), regex.GetText())); } void ManualDWARFIndex::GetGlobalVariables( - DWARFUnit &unit, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + DWARFUnit &unit, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) { Index(); - m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(IterationActionAdaptor(callback))); + m_set.globals.FindAllEntriesForUnit( + unit, DIERefCallback(IterationActionAdaptor(callback))); } void ManualDWARFIndex::GetObjCMethods( @@ -464,9 +468,11 @@ void ManualDWARFIndex::GetTypes( } void ManualDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref<IterationAction(DWARFDIE die)> callback) { + 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(IterationActionAdaptor(callback), + name.GetStringRef())); } void ManualDWARFIndex::GetFunctions( diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h index d58f49f0001df..746170cad2985 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -31,15 +31,15 @@ class ManualDWARFIndex : public DWARFIndex { void Preload() override { Index(); } - void - GetGlobalVariables(ConstString basename, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; - void - GetGlobalVariables(DWARFUnit &unit, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + ConstString basename, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetGlobalVariables( + DWARFUnit &unit, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetObjCMethods(ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetCompleteObjCClass( @@ -49,8 +49,9 @@ class ManualDWARFIndex : public DWARFIndex { llvm::function_ref<bool(DWARFDIE die)> callback) override; void GetTypes(const DWARFDeclContext &context, llvm::function_ref<bool(DWARFDIE die)> callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; + void GetNamespaces( + ConstString name, + llvm::function_ref<IterationAction(DWARFDIE die)> callback) override; void GetFunctions( const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, >From 2e774d3262f84c77a5122c615f7dc23c1ce71bae Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Sat, 2 Aug 2025 15:18:49 +0100 Subject: [PATCH 3/4] fixup! extend lifetime of adapted callback --- lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index 0414d83b9155e..c446682d6f427 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -149,8 +149,9 @@ void AppleDWARFIndex::GetGlobalVariables( if (!m_apple_names_up) return; + auto adataped_cb = IterationActionAdaptor(callback); DIERefCallbackImpl converted_cb = - DIERefCallback(IterationActionAdaptor(callback), regex.GetText()); + DIERefCallback(adataped_cb, regex.GetText()); for (const auto &entry : m_apple_names_up->entries()) if (std::optional<llvm::StringRef> name = entry.readName(); @@ -171,8 +172,9 @@ void AppleDWARFIndex::GetGlobalVariables( return val.has_value() && *val >= lower_bound && *val < upper_bound; }; + auto adataped_cb = IterationActionAdaptor(callback); DIERefCallbackImpl converted_cb = - DIERefCallback(IterationActionAdaptor(callback)); + DIERefCallback(adataped_cb); for (auto entry : m_apple_names_up->entries()) { if (is_in_range(entry.BaseEntry.getDIESectionOffset())) if (!converted_cb(entry.BaseEntry)) >From 2c4b164c7277aab2aa23aa1bd8e6d4befb77b89e Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Sat, 2 Aug 2025 15:19:12 +0100 Subject: [PATCH 4/4] fixup! clang-format --- lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp index c446682d6f427..d2edfe14b2bae 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -173,8 +173,7 @@ void AppleDWARFIndex::GetGlobalVariables( }; auto adataped_cb = IterationActionAdaptor(callback); - DIERefCallbackImpl converted_cb = - DIERefCallback(adataped_cb); + DIERefCallbackImpl converted_cb = DIERefCallback(adataped_cb); for (auto entry : m_apple_names_up->entries()) { if (is_in_range(entry.BaseEntry.getDIESectionOffset())) if (!converted_cb(entry.BaseEntry)) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits