Skip to content

Commit 3e023d8

Browse files
authored
[lldb] Remove DWARFDebugInfo DIERef footguns (#92894)
DWARFDebugInfo doesn't know how to resolve the "file_index" component of a DIERef. This patch removes GetUnit (in favor of existing GetUnitContainingDIEOffset) and changes GetDIE to take only the components it actually uses.
1 parent e6821dd commit 3e023d8

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(DIERef::Section section,
222222
return result;
223223
}
224224

225-
DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef &die_ref) {
226-
return GetUnitContainingDIEOffset(die_ref.section(), die_ref.die_offset());
227-
}
228-
229225
DWARFUnit *
230226
DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section,
231227
dw_offset_t die_offset) {
@@ -253,9 +249,8 @@ bool DWARFDebugInfo::ContainsTypeUnits() {
253249
//
254250
// Get the DIE (Debug Information Entry) with the specified offset.
255251
DWARFDIE
256-
DWARFDebugInfo::GetDIE(const DIERef &die_ref) {
257-
DWARFUnit *cu = GetUnit(die_ref);
258-
if (cu)
259-
return cu->GetNonSkeletonUnit().GetDIE(die_ref.die_offset());
252+
DWARFDebugInfo::GetDIE(DIERef::Section section, dw_offset_t die_offset) {
253+
if (DWARFUnit *cu = GetUnitContainingDIEOffset(section, die_offset))
254+
return cu->GetNonSkeletonUnit().GetDIE(die_offset);
260255
return DWARFDIE(); // Not found
261256
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ class DWARFDebugInfo {
3838
uint32_t *idx_ptr = nullptr);
3939
DWARFUnit *GetUnitContainingDIEOffset(DIERef::Section section,
4040
dw_offset_t die_offset);
41-
DWARFUnit *GetUnit(const DIERef &die_ref);
4241
DWARFUnit *GetSkeletonUnit(DWARFUnit *dwo_unit);
4342
DWARFTypeUnit *GetTypeUnitForHash(uint64_t hash);
4443
bool ContainsTypeUnits();
45-
DWARFDIE GetDIE(const DIERef &die_ref);
44+
DWARFDIE GetDIE(DIERef::Section section, dw_offset_t die_offset);
4645

4746
enum {
4847
eDumpFlag_Verbose = (1 << 0), // Verbose dumping

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,8 @@ SymbolFileDWARF::GetDIE(const DIERef &die_ref) {
17611761
if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile()) {
17621762
symbol_file = debug_map->GetSymbolFileByOSOIndex(*file_index); // OSO case
17631763
if (symbol_file)
1764-
return symbol_file->DebugInfo().GetDIE(die_ref);
1764+
return symbol_file->DebugInfo().GetDIE(die_ref.section(),
1765+
die_ref.die_offset());
17651766
return DWARFDIE();
17661767
}
17671768

@@ -1778,7 +1779,7 @@ SymbolFileDWARF::GetDIE(const DIERef &die_ref) {
17781779
if (symbol_file)
17791780
return symbol_file->GetDIE(die_ref);
17801781

1781-
return DebugInfo().GetDIE(die_ref);
1782+
return DebugInfo().GetDIE(die_ref.section(), die_ref.die_offset());
17821783
}
17831784

17841785
/// Return the DW_AT_(GNU_)dwo_id.
@@ -3786,7 +3787,7 @@ SymbolFileDWARF::FindBlockContainingSpecification(
37863787
// Give the concrete function die specified by "func_die_offset", find the
37873788
// concrete block whose DW_AT_specification or DW_AT_abstract_origin points
37883789
// to "spec_block_die_offset"
3789-
return FindBlockContainingSpecification(DebugInfo().GetDIE(func_die_ref),
3790+
return FindBlockContainingSpecification(GetDIE(func_die_ref),
37903791
spec_block_die_offset);
37913792
}
37923793

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ SymbolFileDWARFDwo::GetTypeSystemForLanguage(LanguageType language) {
145145
DWARFDIE
146146
SymbolFileDWARFDwo::GetDIE(const DIERef &die_ref) {
147147
if (die_ref.file_index() == GetFileIndex())
148-
return DebugInfo().GetDIE(die_ref);
148+
return DebugInfo().GetDIE(die_ref.section(), die_ref.die_offset());
149149
return GetBaseSymbolFile().GetDIE(die_ref);
150150
}
151151

0 commit comments

Comments
 (0)