Hi, I was debugging dynamic values and noticed that accessing fields info results in invalid information.
Source:
class Interface {
public:
virtual ~Interface() {}
};
class Impl : public Interface {
public:
int field = 10;
};
int main() {
Interface* ptr = new Impl();
// BREAK HERE
return 0;
}
Compilation:
clang++ -g -stdlib=libc++ -lc++ source.cc -o source
Debugging:
$ lldb source
(lldb) break set -l 14
(lldb) run
(lldb) script
>>> ptr = lldb.frame.FindVariable("ptr")
>>> ptr.type.name
'Impl *'
>>> ptr.type.GetPointeeType().name
'Impl'
>>> ptr.type.GetPointeeType().GetNumberOfFields()
1
>>> ptr.type.GetPointeeType().GetFieldAtIndex(0).name
>>> ptr.type.GetPointeeType().GetFieldAtIndex(0).type.name
''
One workaround is to dereference the value first, and then access field info, e.g.:
>>> ptr.Dereference().type.GetFieldAtIndex(0).name
'field'
>>> ptr.Dereference().type.GetFieldAtIndex(0).type.name
'int'
These steps were reproduced on Linux (x86_64-pc-linux-gnu) using clang and lldb version 13.0.1.
Note that this only issue for dynamic values. If ptr
is declared as Impl* ptr = new Impl()
, then everything works fine.
We decided to use the workaround solution for now, but I’d expect the original approach should also work. Is this a known issue?