teemperor added a comment.

> (and it could tell clang exactly how large the structure is too - from the 
> DWARF)

We are actually doing that to my knowledge and return the `DW_AT_byte_size` 
value for the record type. The relevant API that LLDB implements to get 
layout/size info back to Clang is:

  bool layoutRecordType(
      const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
          &BaseOffsets,
      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
          &VirtualBaseOffsets) override;

I think the `sizeof` part actually works* in this regard as we just return 
whatever we got from DWARF. I get the correct results for the example above 
(both with and without this patch). There might be some weirder corner cases 
that could go wrong but I think the main concern are more complicated 
situations like in the crash that is fixed here.

FWIW, I took a look at the DWARF standard and I think that is actually 
something we should already emit in the form of a `DW_AT_byte_size 0` attribute 
at the field? Quote:

  If the size of a data member is not the same as the size of the type given 
for the data member, the data member has either a DW_AT_byte_size or a 
DW_AT_bit_size attribute whose integer constant value (see Section 2.19) is the 
amount of storage needed to hold the value of the data member.

I am not a DWARF laywer so maybe I understand that part wrong.

(*I actually found a bug that miscalculated empty structs while testing, but 
that's unrelated. Patch incoming).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101237

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to