Skip to content

Commit bcda8da

Browse files
[lldb][DWARFIndex][nfc] Factor out fully qualified name query (llvm#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. (cherry picked from commit b4ee7d6)
1 parent 34e1602 commit bcda8da

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
@@ -3056,7 +3056,7 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
30563056
}
30573057

30583058
const DWARFDeclContext die_dwarf_decl_ctx = GetDWARFDeclContext(die);
3059-
m_index->GetTypes(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
3059+
m_index->GetFullyQualifiedType(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
30603060
// Make sure type_die's language matches the type system we are
30613061
// looking for. We don't want to find a "Foo" type from Java if we
30623062
// are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
@@ -3083,9 +3083,8 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
30833083
return true;
30843084
}
30853085

3086-
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
3087-
30883086
if (log) {
3087+
DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
30893088
GetObjectFile()->GetModule()->LogMessage(
30903089
log,
30913090
"SymbolFileDWARF::"
@@ -3095,10 +3094,6 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
30953094
type_dwarf_decl_ctx.GetQualifiedName());
30963095
}
30973096

3098-
// Make sure the decl contexts match all the way up
3099-
if (die_dwarf_decl_ctx != type_dwarf_decl_ctx)
3100-
return true;
3101-
31023097
Type *resolved_type = ResolveType(type_die, false);
31033098
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
31043099
return true;

0 commit comments

Comments
 (0)