Recommit [lldb] Test 'v' support for direct ivar access (NFC)
authorDave Lee <davelee.com@gmail.com>
Mon, 6 Mar 2023 03:26:29 +0000 (19:26 -0800)
committerDave Lee <davelee.com@gmail.com>
Mon, 6 Mar 2023 19:52:41 +0000 (11:52 -0800)
Add basic tests for `frame variable`'s ability to direct access fields of `this` and
ivars of `self`.

This splits the tests, preventing ObjC tests from running on Linux.

Differential Revision: https://reviews.llvm.org/D145348

lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile [new file with mode: 0644]
lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py [new file with mode: 0644]
lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp [new file with mode: 0644]
lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile [new file with mode: 0644]
lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py [new file with mode: 0644]
lldb/test/API/commands/frame/var/direct-ivar/objc/main.m [new file with mode: 0644]

diff --git a/lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile b/lldb/test/API/commands/frame/var/direct-ivar/cpp/Makefile
new file mode 100644 (file)
index 0000000..3d0b98f
--- /dev/null
@@ -0,0 +1,2 @@
+CXX_SOURCES := main.cpp
+include Makefile.rules
diff --git a/lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py b/lldb/test/API/commands/frame/var/direct-ivar/cpp/TestFrameVarDirectIvarCpp.py
new file mode 100644 (file)
index 0000000..f483899
--- /dev/null
@@ -0,0 +1,11 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+    def test_cpp_this(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// check this", lldb.SBFileSpec("main.cpp"))
+        self.expect("frame variable m_field", startstr="(int) m_field = 30")
diff --git a/lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp b/lldb/test/API/commands/frame/var/direct-ivar/cpp/main.cpp
new file mode 100644 (file)
index 0000000..eadb02b
--- /dev/null
@@ -0,0 +1,12 @@
+struct Structure {
+  int m_field;
+  void fun() {
+    // check this
+  }
+};
+
+int main() {
+  Structure s;
+  s.m_field = 30;
+  s.fun();
+}
diff --git a/lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile b/lldb/test/API/commands/frame/var/direct-ivar/objc/Makefile
new file mode 100644 (file)
index 0000000..d0aadc1
--- /dev/null
@@ -0,0 +1,2 @@
+OBJC_SOURCES := main.m
+include Makefile.rules
diff --git a/lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py b/lldb/test/API/commands/frame/var/direct-ivar/objc/TestFrameVarDirectIvarObjC.py
new file mode 100644 (file)
index 0000000..395e014
--- /dev/null
@@ -0,0 +1,12 @@
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+    @skipUnlessDarwin
+    def test_objc_self(self):
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// check self", lldb.SBFileSpec("main.m"))
+        self.expect("frame variable _ivar", startstr="(int) _ivar = 30")
diff --git a/lldb/test/API/commands/frame/var/direct-ivar/objc/main.m b/lldb/test/API/commands/frame/var/direct-ivar/objc/main.m
new file mode 100644 (file)
index 0000000..3d5ef38
--- /dev/null
@@ -0,0 +1,19 @@
+#include <objc/NSObject.h>
+
+@interface Classic : NSObject {
+@public
+  int _ivar;
+}
+@end
+
+@implementation Classic
+- (int)fun {
+  // check self
+}
+@end
+
+int main() {
+  Classic *c = [Classic new];
+  c->_ivar = 30;
+  [c fun];
+}