Issue 182762
Summary [lldb] Failure to resolve templated dynamic type
Labels new issue
Assignees
Reporter mentlerd
    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<typename T>
struct Complex : public Interface {};

template<typename T>
struct Wrapper {};

int main(int argc, const char* argv[]) {
    Interface* A = new Simple();                // (Simple *) 0x00000001007d47f0
    Interface* B = new Complex<int>();          // (Complex<int> *) 0x00000001007d6460
    Interface* C = new Complex<Wrapper<int>>(); // (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<Wrapper<int>>"

0x00000106: DW_TAG_structure_type
                DW_AT_containing_type   (0x00000061 "Interface")
                DW_AT_calling_convention (DW_CC_pass_by_reference)
                DW_AT_name ("Complex<Wrapper<int> >") // <-- 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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to