@@ -64,27 +64,25 @@ DebugNamesDWARFIndex::GetNonSkeletonUnit(const DebugNames::Entry &entry) const {
64
64
return cu ? &cu->GetNonSkeletonUnit () : nullptr ;
65
65
}
66
66
67
- std::optional<DIERef>
68
- DebugNamesDWARFIndex::ToDIERef (const DebugNames::Entry &entry) const {
67
+ DWARFDIE DebugNamesDWARFIndex::GetDIE (const DebugNames::Entry &entry) const {
69
68
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 ();
77
80
}
78
81
79
82
bool DebugNamesDWARFIndex::ProcessEntry (
80
83
const DebugNames::Entry &entry,
81
84
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);
88
86
if (!die)
89
87
return true ;
90
88
// Clang erroneously emits index entries for declaration DIEs in case when the
@@ -187,27 +185,22 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
187
185
llvm::function_ref<bool (DWARFDIE die)> callback) {
188
186
// Keep a list of incomplete types as fallback for when we don't find the
189
187
// complete type.
190
- DIEArray incomplete_types;
188
+ std::vector<DWARFDIE> incomplete_types;
191
189
192
190
for (const DebugNames::Entry &entry :
193
191
m_debug_names_up->equal_range (class_name.GetStringRef ())) {
194
192
if (entry.tag () != DW_TAG_structure_type &&
195
193
entry.tag () != DW_TAG_class_type)
196
194
continue ;
197
195
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
205
199
continue ;
206
200
}
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);
211
204
continue ;
212
205
}
213
206
@@ -216,12 +209,11 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(
216
209
callback (die);
217
210
return ;
218
211
}
219
- incomplete_types.push_back (*ref );
212
+ incomplete_types.push_back (die );
220
213
}
221
214
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))
225
217
return ;
226
218
227
219
m_fallback.GetCompleteObjCClass (class_name, must_be_implementation, callback);
@@ -383,8 +375,8 @@ void DebugNamesDWARFIndex::GetFunctions(
383
375
if (tag != DW_TAG_subprogram && tag != DW_TAG_inlined_subroutine)
384
376
continue ;
385
377
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,
388
380
[&](DWARFDIE die) {
389
381
if (!seen.insert (die.GetDIE ()).second )
390
382
return true ;
0 commit comments