[Lldb-commits] [PATCH] D134656: [LLDB][NativePDB] Add class/union layout bit size.

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 27 12:00:49 PDT 2022


labath added a comment.

In D134656#3818759 <https://reviews.llvm.org/D134656#3818759>, @zequanwu wrote:

> In D134656#3818234 <https://reviews.llvm.org/D134656#3818234>, @labath wrote:
>
>> That said, I am kinda surprised that this is the whole thing. I would have expected to see more here. In dwarf we specify the offsets of individual class members. Does PDB encode that information?
>
> Yes. It has offsets to non-inherited individual class members.

Yes, I only meant direct members. And when I speak of members here, I am also thinking about base classes as they behave very similarly here.

> For members from parent classes, pdb only has information saying that its direct parents class are at some offsets for this class. For class without vtable, it's easy to calculate inherited member offsets by adding parent class offsets with their member offsets. For class with vtable, it's more complicated to calculate the offsets.

Yes, so should we take the offsets from the debug info and provide them to clang (so that it does not have to recompute the offsets) ?

>> If not, how does it handle the case when the definition of some class is missing? If that class is a member of some other class, the offsets of all subsequent members in the bigger class will be wrong? That will probably be true even if we are always able to obtain the size of the smaller class, because of things like vtable pointers.
>
> I don't quite understand this. vtable pointers are ignored in this visitor https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp#L136-L139.

Imagine a class like `struct B : A { virtual void foo(); int b; };` and two classes like `struct A1 { virtual void bar(); }; struct A2 { void *a; };`. Both A1 and A2 have the same size (`sizeof(void *)`), but that doesn't mean the layout of B will be the same if we substitute it for the base <https://godbolt.org/z/rT98cxq53>. If A = A1, then B will reuse the vtable pointer of the base, and `offsetof(B, b)` will be 8. That can't happen with A2, so the compiler will create a new vtable pointer and `b` offset will be 16 (2*sizeof(void)) (at least that's how it works in the itanium ABI, but I'm sure you could create something similar with the MSVC ABI as well). If you don't have the definition of A, then you just can't know which of these two cases  you are in. That's why I think that getting the member locations from the debug info is important.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134656/new/

https://reviews.llvm.org/D134656



More information about the lldb-commits mailing list