[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 13 23:32:36 PDT 2024


https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/95405

>From 2e84cf46b9378307d9059aa1ce2a97046b0866b4 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 13 Jun 2024 14:00:07 +0100
Subject: [PATCH 1/4] [lldb][test] Add test for completing ObjCObjectType

This is a minimal reproducer for a crash reported internally
where we would try to call `DumpTypeDescription` on an incomplete
type. This crash surfaced as part of an NFC refactor of some
of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.      Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc -- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb                     0x0000000102ec768c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb                     0x0000000102ec6010 llvm::sys::RunSignalHandlers() + 112
2  lldb                     0x0000000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x000000018c7a8c44 _sigtramp + 56
4  LLDB                     0x0000000116b2030c lldb_private::TypeSystemClang::DumpTypeDescription(void*, lldb_private::Stream&, lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) + 588
5  LLDB                     0x00000001166b5124 lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB                     0x0000000116d4f08c IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122
---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
new file mode 100644
index 0000000000000..011bd943b5967
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o exit 2>&1 | FileCheck %s
+
+int main() { return 0; }
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory

>From 6081327e68d1df1594f17bda97e0f12506681772 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 13 Jun 2024 14:07:19 +0100
Subject: [PATCH 2/4] fixup! clang-format

---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
index 011bd943b5967..919f35ce6060e 100644
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -6,5 +6,5 @@
 
 int main() { return 0; }
 
-// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: (lldb) expression --language objc -- *(id)0x1234
 // CHECK: error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory

>From 2e3f16035167472fa82502cc8c05e68fee325d95 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 13 Jun 2024 22:18:50 +0100
Subject: [PATCH 3/4] fixup! skip on linux and windows, change pointer value,
 move source into separate file

---
 lldb/test/Shell/Expr/Inputs/objc-cast.cpp |  1 +
 lldb/test/Shell/Expr/TestObjCIDCast.cpp   | 10 ----------
 lldb/test/Shell/Expr/TestObjCIDCast.test  |  9 +++++++++
 3 files changed, 10 insertions(+), 10 deletions(-)
 create mode 100644 lldb/test/Shell/Expr/Inputs/objc-cast.cpp
 delete mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.test

diff --git a/lldb/test/Shell/Expr/Inputs/objc-cast.cpp b/lldb/test/Shell/Expr/Inputs/objc-cast.cpp
new file mode 100644
index 0000000000000..76e8197013aab
--- /dev/null
+++ b/lldb/test/Shell/Expr/Inputs/objc-cast.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
deleted file mode 100644
index 919f35ce6060e..0000000000000
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clangxx_host %s -g -o %t
-//
-// RUN: %lldb -f %t \
-// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
-// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o exit 2>&1 | FileCheck %s
-
-int main() { return 0; }
-
-// CHECK: (lldb) expression --language objc -- *(id)0x1234
-// CHECK: error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.test b/lldb/test/Shell/Expr/TestObjCIDCast.test
new file mode 100644
index 0000000000000..4e0e2fea83a3e
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.test
@@ -0,0 +1,9 @@
+// UNSUPPORTED: system-linux, system-windows
+//
+// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
+// RUN: %lldb %t \
+// RUN:   -o "b main" -o run -o "expression --language objc -- *(id)0x1" \
+// RUN:   -b 2>&1 | FileCheck %s
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1
+// CHECK: error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory

>From bde5145c42b6584aa491b84c221d21e75db60471 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 14 Jun 2024 07:32:19 +0100
Subject: [PATCH 4/4] fixup! remove batch mode, which caused the test to flag
 as an error

---
 lldb/test/Shell/Expr/TestObjCIDCast.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.test b/lldb/test/Shell/Expr/TestObjCIDCast.test
index 4e0e2fea83a3e..0611171da09e2 100644
--- a/lldb/test/Shell/Expr/TestObjCIDCast.test
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.test
@@ -3,7 +3,7 @@
 // RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
 // RUN: %lldb %t \
 // RUN:   -o "b main" -o run -o "expression --language objc -- *(id)0x1" \
-// RUN:   -b 2>&1 | FileCheck %s
+// RUN:   2>&1 | FileCheck %s
 
 // CHECK: (lldb) expression --language objc -- *(id)0x1
 // CHECK: error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory



More information about the lldb-commits mailing list