Author: Pavel Labath Date: 2024-05-30T09:57:51+02:00 New Revision: 540a36ad7e31bfeb11e795047a42bb6e30bf9985
URL: https://github.com/llvm/llvm-project/commit/540a36ad7e31bfeb11e795047a42bb6e30bf9985 DIFF: https://github.com/llvm/llvm-project/commit/540a36ad7e31bfeb11e795047a42bb6e30bf9985.diff LOG: [lldb/DWARF] Follow DW_AT_signature when computing type contexts (#93675) This is necessary to correctly resolve the context within types, as the name of the type is only present in the type unit. Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test Removed: ################################################################################ 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) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits