llvm / llvm/llvm-project

[lldb] Failure to resolve templated dynamic type

Open
#182,762 15 comments 0 reactions 0 assignees View on GitHub
lldb
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

LLDB sometimes fails to correctly resolve the dynamic type of pointers. Consider this example on macOS:
```c++
struct Interface {
virtual ~Interface() {}
};

struct Simple : public Interface {};

template
struct Complex : public Interface {};

template
struct Wrapper {};

int main(int argc, const char* argv[]) {
Interface* A = new Simple(); // (Simple *) 0x00000001007d47f0
Interface* B = new Complex(); // (Complex *) 0x00000001007d6460
Interface* C = new Complex>(); // (Interface *) 0x00000001007d6c30 <-- Bug!

__builtin_debugtrap();
return 0;
}
```

I have chased this down to [`ItaniumABILanguageRuntime::GetTypeInfo`](https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp#L57) failing in the case of `C` because it is looking for a different class name than what is contained in the DWARF.
```
(lldb) p lookup_name
(std::string) "::Complex>"

0x00000106: DW_TAG_structure_type
DW_AT_containing_type (0x00000061 "Interface")
DW_AT_calling_convention (DW_CC_pass_by_reference)
DW_AT_name ("Complex >") // <-- Note the additional space between the closing chevrons!
DW_AT_byte_size (0x08)
DW_AT_decl_file ("/Users/mentlerd/personal/projects/sample/sample/main.cpp")
DW_AT_decl_line (9)
```

I have also confirmed that patching `lookup_name` here to the version with the space between the chevrons results in the correct dynamic type resolution.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.