diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp @@ -45,10 +45,12 @@ break; case LF_UNION: llvm::cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.ur)); + m_layout.bit_size = m_cvr.ur.getSize() * 8; break; case LF_CLASS: case LF_STRUCTURE: llvm::cantFail(TypeDeserializer::deserializeAs(cvt, m_cvr.cr)); + m_layout.bit_size = m_cvr.cr.getSize() * 8; break; default: llvm_unreachable("unreachable!"); diff --git a/lldb/test/Shell/SymbolFile/NativePDB/packed_class_layout.cpp b/lldb/test/Shell/SymbolFile/NativePDB/packed_class_layout.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/NativePDB/packed_class_layout.cpp @@ -0,0 +1,34 @@ +// clang-format off +// REQUIRES: lld, x86 + +// Make sure class layout is correct. +// RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -c /Fo%t.obj -- %s +// RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj -out:%t.exe -pdb:%t.pdb +// RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe \ +// RUN: -o "expr a" -o "expr u.c" -o "expr u.i" -o "exit" | FileCheck %s + +// CHECK: (lldb) expr a +// CHECK-NEXT: (A) $0 = (d1 = 'a', d2 = 1, d3 = 2, d4 = 'b') +// CHECK-NEXT: (lldb) expr u.c +// CHECK-NEXT: (char[3]) $1 = "a" +// CHECK-NEXT: (lldb) expr u.i +// CHECK-NEXT: (int) $2 = 97 + +struct __attribute__((packed, aligned(1))) A { + char d1; + int d2; + int d3; + char d4; +}; + +union __attribute__((packed, aligned(1))) U { + char c[2]; + int i; +}; + +A a = {'a', 1, 2, 'b'}; +U u = {"a"}; + +int main() { + return 0; +}