Skip to content

Commit 9000a36

Browse files
committed
Manual DWARF index: don't skip over -gmodules debug info
This fixes a regression introduced by https://reviews.llvm.org/D131437. The intention of the patch was to avoid indexing DWO skeleton units, but it also skipped over full DWARF compile units linked via a -gmodules DW_AT_dwo_name attribute. This patch restores the functionality and adds a test for it. Differential Revision: https://reviews.llvm.org/D142683
1 parent f0c5a4d commit 9000a36

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ class DWARFUnit : public lldb_private::UserID {
223223

224224
uint8_t GetUnitType() const { return m_header.GetUnitType(); }
225225
bool IsTypeUnit() const { return m_header.IsTypeUnit(); }
226+
/// Note that this check only works for DWARF5+.
227+
bool IsSkeletonUnit() const { return GetUnitType() == llvm::dwarf::DW_UT_skeleton; }
226228

227229
std::optional<uint64_t> GetStringOffsetSectionItem(uint32_t index) const;
228230

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,36 @@ void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
162162
// though as some functions have template parameter types and other things
163163
// that cause extra copies of types to be included, but we should find these
164164
// types in the .dwo file only as methods could have return types removed and
165-
// we don't have to index incomplete types from the skeletone compile unit.
165+
// we don't have to index incomplete types from the skeleton compile unit.
166166
if (unit.GetDWOId()) {
167+
// Index the .dwo or dwp instead of the skeleton unit.
167168
if (SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile()) {
168169
// Type units in a dwp file are indexed separately, so we just need to
169-
// process the split unit here. However, if the split unit is in a dwo file,
170-
// then we need to process type units here.
170+
// process the split unit here. However, if the split unit is in a dwo
171+
// file, then we need to process type units here.
171172
if (dwo_symbol_file == dwp) {
172173
IndexUnitImpl(unit.GetNonSkeletonUnit(), cu_language, set);
173174
} else {
174175
DWARFDebugInfo &dwo_info = dwo_symbol_file->DebugInfo();
175176
for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i)
176177
IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), cu_language, set);
177178
}
179+
return;
178180
}
179-
} else {
180-
// We either have a normal compile unit which we want to index.
181-
IndexUnitImpl(unit, cu_language, set);
181+
// This was a DWARF5 skeleton CU and the .dwo file couldn't be located.
182+
if (unit.GetVersion() >= 5 && unit.IsSkeletonUnit())
183+
return;
184+
185+
// Either this is a DWARF 4 + fission CU with the .dwo file
186+
// missing, or it's a -gmodules pch or pcm. Try to detect the
187+
// latter by checking whether the first DIE is a DW_TAG_module.
188+
// If it's a pch/pcm, continue indexing it.
189+
if (unit.GetDIE(unit.GetFirstDIEOffset()).GetFirstChild().Tag() !=
190+
llvm::dwarf::DW_TAG_module)
191+
return;
182192
}
193+
// We have a normal compile unit which we want to index.
194+
IndexUnitImpl(unit, cu_language, set);
183195
}
184196

185197
void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typedef int anchor_t;
2+
3+
struct TypeFromPCH {
4+
int field;
5+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// UNSUPPORTED: system-windows
2+
3+
// Test that LLDB can follow DWO links produced by -gmodules debug
4+
// info to find a type in a precompiled header.
5+
//
6+
// RUN: %clangxx_host -g -gmodules -fmodules -std=c99 -x c-header %S/Inputs/pch.h -g -c -o %t.pch
7+
// RUN: %clangxx_host -g -gmodules -fmodules -std=c99 -x c -include-pch %t.pch %s -c -o %t.o
8+
// RUN: %clangxx_host %t.o -o %t.exe
9+
// RUN: lldb-test symbols -dump-clang-ast -find type --language=C99 \
10+
// RUN: -compiler-context 'AnyModule:*,Struct:TypeFromPCH' %t.exe | FileCheck %s
11+
12+
anchor_t anchor;
13+
14+
int main(int argc, char **argv) { return 0; }
15+
16+
// CHECK: Found 1 type
17+
// CHECK: "TypeFromPCH"
18+
// CHECK: FieldDecl {{.*}} field

0 commit comments

Comments
 (0)