[Lldb-commits] [lldb] d434f43 - [LLDB][NativePDB] Add class/union layout bit size.
Zequan Wu via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 27 11:42:28 PDT 2022
Author: Zequan Wu
Date: 2022-09-27T11:41:55-07:00
New Revision: d434f437200bdf8d94a47346dd5c64cc3cc5c5fa
URL: https://github.com/llvm/llvm-project/commit/d434f437200bdf8d94a47346dd5c64cc3cc5c5fa
DIFF: https://github.com/llvm/llvm-project/commit/d434f437200bdf8d94a47346dd5c64cc3cc5c5fa.diff
LOG: [LLDB][NativePDB] Add class/union layout bit size.
Missing it causes lldb to crash or give incorrect result.
Differential Revision: https://reviews.llvm.org/D134656
Added:
lldb/test/Shell/SymbolFile/NativePDB/packed_class_layout.cpp
Modified:
lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
index 16e9990ff3f09..183ee5ad9c07a 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
@@ -45,10 +45,12 @@ UdtRecordCompleter::UdtRecordCompleter(
break;
case LF_UNION:
llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, m_cvr.ur));
+ m_layout.bit_size = m_cvr.ur.getSize() * 8;
break;
case LF_CLASS:
case LF_STRUCTURE:
llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(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
index 0000000000000..0389ae2a4edde
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/NativePDB/packed_class_layout.cpp
@@ -0,0 +1,39 @@
+// 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 b.c" -o "expr b.u.c" -o "expr b.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 b.c
+// CHECK-NEXT: (char) $1 = 'a'
+// CHECK-NEXT: (lldb) expr b.u.c
+// CHECK-NEXT: (char[2]) $2 = "b"
+// CHECK-NEXT: (lldb) expr b.u.i
+// CHECK-NEXT: (int) $3 = 98
+
+struct __attribute__((packed, aligned(1))) A {
+ char d1;
+ int d2;
+ int d3;
+ char d4;
+};
+
+struct __attribute__((packed, aligned(1))) B {
+ char c;
+ union {
+ char c[2];
+ int i;
+ } u;
+};
+
+A a = {'a', 1, 2, 'b'};
+B b = {'a', {"b"}};
+
+int main() {
+ return 0;
+}
More information about the lldb-commits
mailing list