Skip to content

Commit 53d79fe

Browse files
authored
[lldb/DWARF] Bypass the compres^Wconstruction of DIERefs in debug_names (#93296)
DebugNamesDWARFIndex was jumping through hoops to construct a DIERef from an index entry only to jump through them back a short while later to construct a DWARFDIE. This used to be necessary as the index lookup was a two stage process, where we first enumerated all matches, and then examined them (so it was important that the enumeration was cheap -- does not trigger unnecessary parsing). However, now that the processing is callback based, we are always immediately examining the DWARFDIE right after finding the entry, and the DIERef just gets in the way.
1 parent 70091dc commit 53d79fe

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ void AppleDWARFIndex::GetFunctions(
284284
for (const auto &entry : m_apple_names_up->equal_range(name)) {
285285
DIERef die_ref(std::nullopt, DIERef::Section::DebugInfo,
286286
*entry.getDIESectionOffset());
287-
if (!ProcessFunctionDIE(lookup_info, die_ref, dwarf, parent_decl_ctx,
288-
callback))
287+
DWARFDIE die = dwarf.GetDIE(die_ref);
288+
if (!die) {
289+
ReportInvalidDIERef(die_ref, name);
290+
continue;
291+
}
292+
if (!ProcessFunctionDIE(lookup_info, die, parent_decl_ctx, callback))
289293
return;
290294
}
291295
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ using namespace lldb_private::plugin::dwarf;
2424
DWARFIndex::~DWARFIndex() = default;
2525

2626
bool DWARFIndex::ProcessFunctionDIE(
27-
const Module::LookupInfo &lookup_info, DIERef ref, SymbolFileDWARF &dwarf,
27+
const Module::LookupInfo &lookup_info, DWARFDIE die,
2828
const CompilerDeclContext &parent_decl_ctx,
2929
llvm::function_ref<bool(DWARFDIE die)> callback) {
3030
llvm::StringRef name = lookup_info.GetLookupName().GetStringRef();
3131
FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
32-
DWARFDIE die = dwarf.GetDIE(ref);
33-
if (!die) {
34-
ReportInvalidDIERef(ref, name);
35-
return true;
36-
}
3732

3833
if (!(name_type_mask & eFunctionNameTypeFull)) {
3934
ConstString name_to_match_against;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ class DWARFIndex {
8181
StatsDuration m_index_time;
8282

8383
/// Helper function implementing common logic for processing function dies. If
84-
/// the function given by "ref" matches search criteria given by
85-
/// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies"
86-
/// vector.
87-
bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DIERef ref,
88-
SymbolFileDWARF &dwarf,
84+
/// the function given by "die" matches search criteria given by
85+
/// "parent_decl_ctx" and "name_type_mask", it calls the callback with the
86+
/// given die.
87+
bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DWARFDIE die,
8988
const CompilerDeclContext &parent_decl_ctx,
9089
llvm::function_ref<bool(DWARFDIE die)> callback);
9190

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

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,25 @@ DebugNamesDWARFIndex::GetNonSkeletonUnit(const DebugNames::Entry &entry) const {
6464
return cu ? &cu->GetNonSkeletonUnit() : nullptr;
6565
}
6666

67-
std::optional<DIERef>
68-
DebugNamesDWARFIndex::ToDIERef(const DebugNames::Entry &entry) const {
67+
DWARFDIE DebugNamesDWARFIndex::GetDIE(const DebugNames::Entry &entry) const {
6968
DWARFUnit *unit = GetNonSkeletonUnit(entry);
70-
if (!unit)
71-
return std::nullopt;
72-
if (std::optional<uint64_t> die_offset = entry.getDIEUnitOffset())
73-
return DIERef(unit->GetSymbolFileDWARF().GetFileIndex(),
74-
DIERef::Section::DebugInfo, unit->GetOffset() + *die_offset);
75-
76-
return std::nullopt;
69+
std::optional<uint64_t> die_offset = entry.getDIEUnitOffset();
70+
if (!unit || !die_offset)
71+
return DWARFDIE();
72+
if (DWARFDIE die = unit->GetDIE(unit->GetOffset() + *die_offset))
73+
return die;
74+
75+
m_module.ReportErrorIfModifyDetected(
76+
"the DWARF debug information has been modified (bad offset {0:x} in "
77+
"debug_names section)\n",
78+
*die_offset);
79+
return DWARFDIE();
7780
}
7881

7982
bool DebugNamesDWARFIndex::ProcessEntry(
8083
const DebugNames::Entry &entry,
8184
llvm::function_ref<bool(DWARFDIE die)> callback) {
82-
std::optional<DIERef> ref = ToDIERef(entry);
83-
if (!ref)
84-
return true;
85-
SymbolFileDWARF &dwarf = *llvm::cast<SymbolFileDWARF>(
86-
m_module.GetSymbolFile()->GetBackingSymbolFile());
87-
DWARFDIE die = dwarf.GetDIE(*ref);
85+
DWARFDIE die = GetDIE(entry);
8886
if (!die)
8987
return true;
9088
// Clang erroneously emits index entries for declaration DIEs in case when the
@@ -187,27 +185,22 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
187185
llvm::function_ref<bool(DWARFDIE die)> callback) {
188186
// Keep a list of incomplete types as fallback for when we don't find the
189187
// complete type.
190-
DIEArray incomplete_types;
188+
std::vector<DWARFDIE> incomplete_types;
191189

192190
for (const DebugNames::Entry &entry :
193191
m_debug_names_up->equal_range(class_name.GetStringRef())) {
194192
if (entry.tag() != DW_TAG_structure_type &&
195193
entry.tag() != DW_TAG_class_type)
196194
continue;
197195

198-
std::optional<DIERef> ref = ToDIERef(entry);
199-
if (!ref)
200-
continue;
201-
202-
DWARFUnit *cu = m_debug_info.GetUnit(*ref);
203-
if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) {
204-
incomplete_types.push_back(*ref);
196+
DWARFDIE die = GetDIE(entry);
197+
if (!die) {
198+
// Report invalid
205199
continue;
206200
}
207-
208-
DWARFDIE die = m_debug_info.GetDIE(*ref);
209-
if (!die) {
210-
ReportInvalidDIERef(*ref, class_name.GetStringRef());
201+
DWARFUnit *cu = die.GetCU();
202+
if (!cu->Supports_DW_AT_APPLE_objc_complete_type()) {
203+
incomplete_types.push_back(die);
211204
continue;
212205
}
213206

@@ -216,12 +209,11 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
216209
callback(die);
217210
return;
218211
}
219-
incomplete_types.push_back(*ref);
212+
incomplete_types.push_back(die);
220213
}
221214

222-
auto dierefcallback = DIERefCallback(callback, class_name.GetStringRef());
223-
for (DIERef ref : incomplete_types)
224-
if (!dierefcallback(ref))
215+
for (DWARFDIE die : incomplete_types)
216+
if (!callback(die))
225217
return;
226218

227219
m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, callback);
@@ -383,8 +375,8 @@ void DebugNamesDWARFIndex::GetFunctions(
383375
if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
384376
continue;
385377

386-
if (std::optional<DIERef> ref = ToDIERef(entry)) {
387-
if (!ProcessFunctionDIE(lookup_info, *ref, dwarf, parent_decl_ctx,
378+
if (DWARFDIE die = GetDIE(entry)) {
379+
if (!ProcessFunctionDIE(lookup_info, die, parent_decl_ctx,
388380
[&](DWARFDIE die) {
389381
if (!seen.insert(die.GetDIE()).second)
390382
return true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DebugNamesDWARFIndex : public DWARFIndex {
8484
ManualDWARFIndex m_fallback;
8585

8686
DWARFUnit *GetNonSkeletonUnit(const DebugNames::Entry &entry) const;
87-
std::optional<DIERef> ToDIERef(const DebugNames::Entry &entry) const;
87+
DWARFDIE GetDIE(const DebugNames::Entry &entry) const;
8888
bool ProcessEntry(const DebugNames::Entry &entry,
8989
llvm::function_ref<bool(DWARFDIE die)> callback);
9090

0 commit comments

Comments
 (0)