Skip to content

[lldb][DWARFIndex] Adapt DWARFIndex ObjC APIs to IterationAction #151839

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,22 @@ void AppleDWARFIndex::GetGlobalVariables(
}

void AppleDWARFIndex::GetObjCMethods(
ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_objc_up)
return;
SearchFor(*m_apple_objc_up, class_name, callback);
SearchFor(*m_apple_objc_up, class_name, IterationActionAdaptor(callback));
}

void AppleDWARFIndex::GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<bool(DWARFDIE die)> callback) {
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
if (!m_apple_types_up)
return;

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

for (const auto &entry : m_apple_types_up->equal_range(class_name)) {
if (HasImplementationFlag(entry)) {
Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_APPLEDWARFINDEX_H

#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"
#include "lldb/lldb-private-enumerations.h"
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"

namespace lldb_private::plugin {
Expand Down Expand Up @@ -50,11 +51,12 @@ class AppleDWARFIndex : public DWARFIndex {
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 GetObjCMethods(
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void GetTypes(ConstString name,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
void GetTypes(const DWARFDeclContext &context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/lldb-private-enumerations.h"

#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclBase.h"
Expand Down Expand Up @@ -2223,7 +2224,7 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
if (class_name) {
dwarf->GetObjCMethods(class_name, [&](DWARFDIE method_die) {
method_die.ResolveType();
return true;
return IterationAction::Continue;
});

for (DelayedAddObjCClassProperty &property : delayed_properties)
Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class DWARFIndex {
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;
virtual void
GetCompleteObjCClass(ConstString class_name, bool must_be_implementation,
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
virtual void GetObjCMethods(
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
virtual void GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) = 0;
virtual void GetTypes(ConstString name,
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
virtual void GetTypes(const DWARFDeclContext &context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void DebugNamesDWARFIndex::GetGlobalVariables(

void DebugNamesDWARFIndex::GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<bool(DWARFDIE die)> callback) {
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
// Keep a list of incomplete types as fallback for when we don't find the
// complete type.
std::vector<DWARFDIE> incomplete_types;
Expand All @@ -283,7 +283,7 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
}

for (DWARFDIE die : incomplete_types)
if (!callback(die))
if (callback(die) == IterationAction::Stop)
return;

m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, callback);
Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class DebugNamesDWARFIndex : public DWARFIndex {
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 GetObjCMethods(
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override {}
void GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

/// Uses DWARF5's IDX_parent fields, when available, to speed up this query.
void GetFullyQualifiedType(
Expand Down
12 changes: 7 additions & 5 deletions lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,20 @@ void ManualDWARFIndex::GetGlobalVariables(
}

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

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

void ManualDWARFIndex::GetTypes(
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ class ManualDWARFIndex : public DWARFIndex {
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 GetObjCMethods(
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void GetCompleteObjCClass(
ConstString class_name, bool must_be_implementation,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
void GetTypes(ConstString name,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
void GetTypes(const DWARFDeclContext &context,
Expand Down
11 changes: 6 additions & 5 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,8 @@ SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu) {
}

void SymbolFileDWARF::GetObjCMethods(
ConstString class_name, llvm::function_ref<bool(DWARFDIE die)> callback) {
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
m_index->GetObjCMethods(class_name, callback);
}

Expand Down Expand Up @@ -2993,18 +2994,18 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
// Don't try and resolve the DIE we are looking for with the DIE
// itself!
if (type_die == die || !IsStructOrClassTag(type_die.Tag()))
return true;
return IterationAction::Continue;

if (must_be_implementation) {
const bool try_resolving_type = type_die.GetAttributeValueAsUnsigned(
DW_AT_APPLE_objc_complete_type, 0);
if (!try_resolving_type)
return true;
return IterationAction::Continue;
}

Type *resolved_type = ResolveType(type_die, false, true);
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
return true;
return IterationAction::Continue;

DEBUG_PRINTF(
"resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64
Expand All @@ -3016,7 +3017,7 @@ TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
if (die)
GetDIEToType()[die.GetDIE()] = resolved_type;
type_sp = resolved_type->shared_from_this();
return false;
return IterationAction::Stop;
});
return type_sp;
}
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ class SymbolFileDWARF : public SymbolFileCommon {

CompileUnit *GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu);

virtual void GetObjCMethods(ConstString class_name,
llvm::function_ref<bool(DWARFDIE die)> callback);
virtual void
GetObjCMethods(ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback);

DebugMacrosSP ParseDebugMacros(lldb::offset_t *offset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ SymbolFileDWARFDwo::GetForwardDeclCompilerTypeToDIE() {

void SymbolFileDWARFDwo::GetObjCMethods(
lldb_private::ConstString class_name,
llvm::function_ref<bool(DWARFDIE die)> callback) {
llvm::function_ref<IterationAction(DWARFDIE die)> callback) {
GetBaseSymbolFile().GetObjCMethods(class_name, callback);
}

Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDWO_H

#include "SymbolFileDWARF.h"
#include "lldb/lldb-private-enumerations.h"
#include <optional>

namespace lldb_private::plugin {
Expand All @@ -34,8 +35,9 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF {

DWARFCompileUnit *GetDWOCompileUnitForHash(uint64_t hash);

void GetObjCMethods(ConstString class_name,
llvm::function_ref<bool(DWARFDIE die)> callback) override;
void GetObjCMethods(
ConstString class_name,
llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;

llvm::Expected<lldb::TypeSystemSP>
GetTypeSystemForLanguage(lldb::LanguageType language) override;
Expand Down
Loading