Skip to content

Commit a0db373

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 (cherry picked from commit 9000a36)
1 parent e20a020 commit a0db373

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
@@ -222,6 +222,8 @@ class DWARFUnit : public lldb_private::UserID {
222222

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

226228
llvm::Optional<uint64_t> GetStringOffsetSectionItem(uint32_t index) const;
227229

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

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

184196
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)