Skip to content

Commit 540a36a

Browse files
authored
[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.
1 parent d554f23 commit 540a36a

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "lldb/Symbol/Type.h"
1717

1818
#include "llvm/ADT/iterator.h"
19+
#include "llvm/BinaryFormat/Dwarf.h"
1920

2021
using namespace lldb_private;
2122
using namespace lldb_private::dwarf;
@@ -390,6 +391,11 @@ static void GetDeclContextImpl(DWARFDIE die,
390391
die = spec;
391392
continue;
392393
}
394+
// To find the name of a type in a type unit, we must follow the signature.
395+
if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_signature)) {
396+
die = spec;
397+
continue;
398+
}
393399

394400
// Add this DIE's contribution at the end of the chain.
395401
auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
@@ -444,6 +450,12 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
444450
std::vector<CompilerContext> &context) {
445451
// Stop if we hit a cycle.
446452
while (die && seen.insert(die.GetID()).second) {
453+
// To find the name of a type in a type unit, we must follow the signature.
454+
if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_signature)) {
455+
die = spec;
456+
continue;
457+
}
458+
447459
// If there is no name, then there is no need to look anything up for this
448460
// DIE.
449461
const char *name = die.GetName();

lldb/test/Shell/SymbolFile/DWARF/x86/Inputs/debug-types-basic.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ struct A {
1010
EC ec;
1111
};
1212

13+
struct Outer {
14+
int i;
15+
struct Inner {
16+
long l;
17+
};
18+
};
19+
1320
extern constexpr A a{42, 47l, 4.2f, 4.7, e1, EC::e3};
1421
extern constexpr E e(e2);
1522
extern constexpr EC ec(EC::e2);
23+
extern constexpr Outer outer{47};
24+
extern constexpr Outer::Inner outer_inner{42l};

lldb/test/Shell/SymbolFile/DWARF/x86/debug-types-basic.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ type lookup EC
5151
# CHECK-NEXT: e3
5252
# CHECK-NEXT: }
5353

54+
type lookup Outer::Inner
55+
# CHECK-LABEL: type lookup Outer::Inner
56+
# CHECK: struct Inner {
57+
# CHECK-NEXT: long l;
58+
# CHECK-NEXT: }
59+
5460
expression (E) 1
5561
# CHECK-LABEL: expression (E) 1
5662
# CHECK: (E) $0 = e2
@@ -59,8 +65,9 @@ expression (EC) 1
5965
# CHECK-LABEL: expression (EC) 1
6066
# CHECK: (EC) $1 = e2
6167

62-
target variable a e ec
68+
target variable a e ec outer_inner
6369
# CHECK-LABEL: target variable a e ec
6470
# CHECK: (const A) a = (i = 42, l = 47, f = 4.{{[12].*}}, d = 4.{{[67].*}}, e = e1, ec = e3)
6571
# CHECK: (const E) e = e2
6672
# CHECK: (const EC) ec = e2
73+
# CHECK: (const Outer::Inner) outer_inner = (l = 42)

0 commit comments

Comments
 (0)