[Lldb-commits] [lldb] 9000a36 - Manual DWARF index: don't skip over -gmodules debug info

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 27 16:00:00 PST 2023


Author: Adrian Prantl
Date: 2023-01-27T15:59:46-08:00
New Revision: 9000a36f5cbd2993cd9c746610f7666ed173991a

URL: https://github.com/llvm/llvm-project/commit/9000a36f5cbd2993cd9c746610f7666ed173991a
DIFF: https://github.com/llvm/llvm-project/commit/9000a36f5cbd2993cd9c746610f7666ed173991a.diff

LOG: 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

Added: 
    lldb/test/Shell/SymbolFile/DWARF/Inputs/pch.h
    lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
    lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
index a70628a3866a..bc55b093e894 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -223,6 +223,8 @@ class DWARFUnit : public lldb_private::UserID {
 
   uint8_t GetUnitType() const { return m_header.GetUnitType(); }
   bool IsTypeUnit() const { return m_header.IsTypeUnit(); }
+  /// Note that this check only works for DWARF5+.
+  bool IsSkeletonUnit() const { return GetUnitType() == llvm::dwarf::DW_UT_skeleton; }
 
   std::optional<uint64_t> GetStringOffsetSectionItem(uint32_t index) const;
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
index a31622fc8b99..90ac5afb179a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -162,12 +162,13 @@ void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
   // though as some functions have template parameter types and other things
   // that cause extra copies of types to be included, but we should find these
   // types in the .dwo file only as methods could have return types removed and
-  // we don't have to index incomplete types from the skeletone compile unit.
+  // we don't have to index incomplete types from the skeleton compile unit.
   if (unit.GetDWOId()) {
+    // Index the .dwo or dwp instead of the skeleton unit.
     if (SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile()) {
       // Type units in a dwp file are indexed separately, so we just need to
-      // process the split unit here. However, if the split unit is in a dwo file,
-      // then we need to process type units here.
+      // process the split unit here. However, if the split unit is in a dwo
+      // file, then we need to process type units here.
       if (dwo_symbol_file == dwp) {
         IndexUnitImpl(unit.GetNonSkeletonUnit(), cu_language, set);
       } else {
@@ -175,11 +176,22 @@ void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
         for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i)
           IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), cu_language, set);
       }
+      return;
     }
-  } else {
-    // We either have a normal compile unit which we want to index.
-    IndexUnitImpl(unit, cu_language, set);
+    // This was a DWARF5 skeleton CU and the .dwo file couldn't be located.
+    if (unit.GetVersion() >= 5 && unit.IsSkeletonUnit())
+      return;
+
+    // Either this is a DWARF 4 + fission CU with the .dwo file
+    // missing, or it's a -gmodules pch or pcm. Try to detect the
+    // latter by checking whether the first DIE is a DW_TAG_module.
+    // If it's a pch/pcm, continue indexing it.
+    if (unit.GetDIE(unit.GetFirstDIEOffset()).GetFirstChild().Tag() !=
+        llvm::dwarf::DW_TAG_module)
+      return;
   }
+  // We have a normal compile unit which we want to index.
+  IndexUnitImpl(unit, cu_language, set);
 }
 
 void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit,

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/Inputs/pch.h b/lldb/test/Shell/SymbolFile/DWARF/Inputs/pch.h
new file mode 100644
index 000000000000..a478d907e837
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/Inputs/pch.h
@@ -0,0 +1,5 @@
+typedef int anchor_t;
+
+struct TypeFromPCH {
+  int field;
+};

diff  --git a/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c b/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c
new file mode 100644
index 000000000000..f42a5d3907df
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c
@@ -0,0 +1,18 @@
+// UNSUPPORTED: system-windows
+
+// Test that LLDB can follow DWO links produced by -gmodules debug
+// info to find a type in a precompiled header.
+//
+// RUN: %clangxx_host -g -gmodules -fmodules -std=c99 -x c-header %S/Inputs/pch.h -g -c -o %t.pch
+// RUN: %clangxx_host -g -gmodules -fmodules -std=c99 -x c -include-pch %t.pch %s -c -o %t.o
+// RUN: %clangxx_host %t.o -o %t.exe
+// RUN: lldb-test symbols -dump-clang-ast -find type --language=C99 \
+// RUN:   -compiler-context 'AnyModule:*,Struct:TypeFromPCH' %t.exe | FileCheck %s
+
+anchor_t anchor;
+
+int main(int argc, char **argv) { return 0; }
+
+// CHECK: Found 1 type
+// CHECK: "TypeFromPCH"
+// CHECK: FieldDecl {{.*}} field


        


More information about the lldb-commits mailing list