Skip to content

[lldb/DWARF] Follow DW_AT_signature when computing type contexts #93675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024

Conversation

labath
Copy link
Collaborator

@labath labath commented May 29, 2024

This is necessary to correctly resolve the context within types, as the name of the type is only present in the type unit.

(The DWARFYAML enthusiasm didn't last long, as it does not support type units. It can still be used for testing a lot of other things though.)

This is necessary to correctly resolve the context within types, as the
name of the type is only present in the type unit.
@labath labath requested a review from Michael137 May 29, 2024 12:26
@labath labath requested a review from JDevlieghere as a code owner May 29, 2024 12:26
@llvmbot llvmbot added the lldb label May 29, 2024
@llvmbot
Copy link
Member

llvmbot commented May 29, 2024

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

This is necessary to correctly resolve the context within types, as the name of the type is only present in the type unit.

(The DWARFYAML enthusiasm didn't last long, as it does not support type units. It can still be used for testing a lot of other things though.)


Full diff: https://github.com/llvm/llvm-project/pull/93675.diff

3 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp (+12)
  • (modified) lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp (+9)
  • (modified) lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test (+8-1)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index 03e289bbf3300..7cf92adc6ef57 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Symbol/Type.h"
 
 #include "llvm/ADT/iterator.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 
 using namespace lldb_private;
 using namespace lldb_private::dwarf;
@@ -390,6 +391,11 @@ static void GetDeclContextImpl(DWARFDIE die,
       die = spec;
       continue;
     }
+    // To find the name of a type in a type unit, we must follow the signature.
+    if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_signature)) {
+      die = spec;
+      continue;
+    }
 
     // Add this DIE's contribution at the end of the chain.
     auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
@@ -444,6 +450,12 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
                                      std::vector<CompilerContext> &context) {
   // Stop if we hit a cycle.
   while (die && seen.insert(die.GetID()).second) {
+    // To find the name of a type in a type unit, we must follow the signature.
+    if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_signature)) {
+      die = spec;
+      continue;
+    }
+
     // If there is no name, then there is no need to look anything up for this
     // DIE.
     const char *name = die.GetName();
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp
index defa8ba5c69e7..24fa05505fd38 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp
@@ -10,6 +10,15 @@ struct A {
   EC ec;
 };
 
+struct Outer {
+  int i;
+  struct Inner {
+    long l;
+  };
+};
+
 extern constexpr A a{42, 47l, 4.2f, 4.7, e1, EC::e3};
 extern constexpr E e(e2);
 extern constexpr EC ec(EC::e2);
+extern constexpr Outer outer{47};
+extern constexpr Outer::Inner outer_inner{42l};
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test b/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test
index dc8005f73930e..47a6ecf39033d 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test
@@ -51,6 +51,12 @@ type lookup EC
 # CHECK-NEXT:   e3
 # CHECK-NEXT: }
 
+type lookup Outer::Inner
+# CHECK-LABEL: type lookup Outer::Inner
+# CHECK:      struct Inner {
+# CHECK-NEXT:   long l;
+# CHECK-NEXT: }
+
 expression (E) 1
 # CHECK-LABEL: expression (E) 1
 # CHECK: (E) $0 = e2
@@ -59,8 +65,9 @@ expression (EC) 1
 # CHECK-LABEL: expression (EC) 1
 # CHECK: (EC) $1 = e2
 
-target variable a e ec
+target variable a e ec outer_inner
 # CHECK-LABEL: target variable a e ec
 # CHECK: (const A) a = (i = 42, l = 47, f = 4.{{[12].*}}, d = 4.{{[67].*}}, e = e1, ec = e3)
 # CHECK: (const E) e = e2
 # CHECK: (const EC) ec = e2
+# CHECK: (const Outer::Inner) outer_inner = (l = 42)

@labath labath merged commit 540a36a into llvm:main May 30, 2024
7 checks passed
@labath labath deleted the signature branch May 30, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants