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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Loading