LLDB fails to access field info of dynamic values

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?

The type you get from GetPointeeType is still aware that it came from an SBValue with a static & dynamic components. For instance
if you print it, you see:

pointee = ptr.type.GetPointeeType()
print(pointee)
Dynamic:
class Impl : public Interface {
int field;
}
Static:
class Interface {
virtual ~Interface();
}

Though the value is obeying the preference to prefer dynamic values, the type it returns seems not to be consistent about that, and not
self-consistent either, returning the dynamic type’s value for GetNumberOfFields, but the static type for GetFieldAtIndex.

Definitely a bug, please file it.

Thanks,

Jim