Skip to content

Commit b4ee7d6

Browse files
[lldb][DWARFIndex][nfc] Factor out fully qualified name query (#76977)
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.
1 parent 2bf01d7 commit b4ee7d6

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"
10+
#include "DWARFDebugInfoEntry.h"
11+
#include "DWARFDeclContext.h"
1012
#include "Plugins/Language/ObjC/ObjCLanguage.h"
1113
#include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
1214
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
@@ -112,3 +114,21 @@ void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const {
112114
"bad die {0:x16} for '{1}')\n",
113115
ref.die_offset(), name.str().c_str());
114116
}
117+
118+
void DWARFIndex::GetFullyQualifiedType(
119+
const DWARFDeclContext &context,
120+
llvm::function_ref<bool(DWARFDIE die)> callback) {
121+
GetTypes(context, [&](DWARFDIE die) {
122+
return GetFullyQualifiedTypeImpl(context, die, callback);
123+
});
124+
}
125+
126+
bool DWARFIndex::GetFullyQualifiedTypeImpl(
127+
const DWARFDeclContext &context, DWARFDIE die,
128+
llvm::function_ref<bool(DWARFDIE die)> callback) {
129+
DWARFDeclContext dwarf_decl_ctx =
130+
die.GetDIE()->GetDWARFDeclContext(die.GetCU());
131+
if (dwarf_decl_ctx == context)
132+
return callback(die);
133+
return true;
134+
}

lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ class DWARFIndex {
5353
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
5454
virtual void GetTypes(const DWARFDeclContext &context,
5555
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
56+
57+
/// Finds all DIEs whose fully qualified name matches `context`. A base
58+
/// implementation is provided, and it uses the entire CU to check the DIE
59+
/// parent hierarchy. Specializations should override this if they are able
60+
/// to provide a faster implementation.
61+
virtual void
62+
GetFullyQualifiedType(const DWARFDeclContext &context,
63+
llvm::function_ref<bool(DWARFDIE die)> callback);
5664
virtual void
5765
GetNamespaces(ConstString name,
5866
llvm::function_ref<bool(DWARFDIE die)> callback) = 0;
@@ -102,6 +110,12 @@ class DWARFIndex {
102110
}
103111

104112
void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const;
113+
114+
/// Implementation of `GetFullyQualifiedType` to check a single entry,
115+
/// shareable with derived classes.
116+
bool
117+
GetFullyQualifiedTypeImpl(const DWARFDeclContext &context, DWARFDIE die,
118+
llvm::function_ref<bool(DWARFDIE die)> callback);
105119
};
106120
} // namespace dwarf
107121
} // namespace lldb_private::plugin

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,7 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
31383138
}
31393139

31403140
const DWARFDeclContext die_dwarf_decl_ctx = GetDWARFDeclContext(die);
3141-
m_index->GetTypes(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
3141+
m_index->GetFullyQualifiedType(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
31423142
// Make sure type_die's language matches the type system we are
31433143
// looking for. We don't want to find a "Foo" type from Java if we
31443144
// are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
@@ -3165,9 +3165,8 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
31653165
return true;
31663166
}
31673167

3168-
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
3169-
31703168
if (log) {
3169+
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
31713170
GetObjectFile()->GetModule()->LogMessage(
31723171
log,
31733172
"SymbolFileDWARF::"
@@ -3177,10 +3176,6 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
31773176
type_dwarf_decl_ctx.GetQualifiedName());
31783177
}
31793178

3180-
// Make sure the decl contexts match all the way up
3181-
if (die_dwarf_decl_ctx != type_dwarf_decl_ctx)
3182-
return true;
3183-
31843179
Type *resolved_type = ResolveType(type_die, false);
31853180
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
31863181
return true;

0 commit comments

Comments
 (0)