Skip to content

Commit

Permalink
[lldb][DWARFIndex][nfc] Factor out fully qualified name query (llvm#7…
Browse files Browse the repository at this point in the history
…6977)

This moves the functionally of finding a DIE based on a fully qualified
name from SymbolFileDWARF into DWARFIndex itself, so that
specializations of DWARFIndex can implement faster versions of this
query.

(cherry picked from commit b4ee7d6)
  • Loading branch information
felipepiovezan committed Feb 2, 2024
1 parent 34e1602 commit bcda8da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
20 changes: 20 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//

#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"
#include "DWARFDebugInfoEntry.h"
#include "DWARFDeclContext.h"
#include "Plugins/Language/ObjC/ObjCLanguage.h"
#include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
Expand Down Expand Up @@ -112,3 +114,21 @@ void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const {
"bad die {0:x16} for '{1}')\n",
ref.die_offset(), name.str().c_str());
}

void DWARFIndex::GetFullyQualifiedType(
const DWARFDeclContext &context,
llvm::function_ref<bool(DWARFDIE die)> callback) {
GetTypes(context, [&](DWARFDIE die) {
return GetFullyQualifiedTypeImpl(context, die, callback);
});
}

bool DWARFIndex::GetFullyQualifiedTypeImpl(
const DWARFDeclContext &context, DWARFDIE die,
llvm::function_ref<bool(DWARFDIE die)> callback) {
DWARFDeclContext dwarf_decl_ctx =
die.GetDIE()->GetDWARFDeclContext(die.GetCU());
if (dwarf_decl_ctx == context)
return callback(die);
return true;
}
14 changes: 14 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class DWARFIndex {
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
virtual void GetTypes(const DWARFDeclContext &context,
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;

/// Finds all DIEs whose fully qualified name matches `context`. A base
/// implementation is provided, and it uses the entire CU to check the DIE
/// parent hierarchy. Specializations should override this if they are able
/// to provide a faster implementation.
virtual void
GetFullyQualifiedType(const DWARFDeclContext &context,
llvm::function_ref<bool(DWARFDIE die)> callback);
virtual void
GetNamespaces(ConstString name,
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
Expand Down Expand Up @@ -102,6 +110,12 @@ class DWARFIndex {
}

void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const;

/// Implementation of `GetFullyQualifiedType` to check a single entry,
/// shareable with derived classes.
bool
GetFullyQualifiedTypeImpl(const DWARFDeclContext &context, DWARFDIE die,
llvm::function_ref<bool(DWARFDIE die)> callback);
};
} // namespace dwarf
} // namespace lldb_private::plugin
Expand Down
9 changes: 2 additions & 7 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,7 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
}

const DWARFDeclContext die_dwarf_decl_ctx = GetDWARFDeclContext(die);
m_index->GetTypes(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
m_index->GetFullyQualifiedType(die_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++.
Expand All @@ -3083,9 +3083,8 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
return true;
}

DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);

if (log) {
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
GetObjectFile()->GetModule()->LogMessage(
log,
"SymbolFileDWARF::"
Expand All @@ -3095,10 +3094,6 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
type_dwarf_decl_ctx.GetQualifiedName());
}

// Make sure the decl contexts match all the way up
if (die_dwarf_decl_ctx != type_dwarf_decl_ctx)
return true;

Type *resolved_type = ResolveType(type_die, false);
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
return true;
Expand Down

0 comments on commit bcda8da

Please sign in to comment.