diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc')
3 files changed, 128 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/Makefile new file mode 100644 index 00000000000..a3198db9e8e --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/Makefile @@ -0,0 +1,3 @@ +OBJC_SOURCES := main.m +LD_EXTRAS := -framework Foundation +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/TestContextObjectObjc.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/TestContextObjectObjc.py new file mode 100644 index 00000000000..4ae4fd8680d --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/TestContextObjectObjc.py @@ -0,0 +1,78 @@ +""" +Tests expression evaluation in context of an objc class. +""" + +import lldb +import lldbsuite.test.lldbutil as lldbutil +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + +class ContextObjectObjcTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @skipUnlessDarwin + def test_context_object_objc(self): + """Tests expression evaluation in context of an objc class.""" + self.build() + + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) + frame = thread.GetFrameAtIndex(0) + + # + # Test objc class variable + # + + obj_val = frame.FindVariable("objcClass") + self.assertTrue(obj_val.IsValid()) + obj_val = obj_val.Dereference() + self.assertTrue(obj_val.IsValid()) + + # Test an empty expression evaluation + value = obj_val.EvaluateExpression("") + self.assertFalse(value.IsValid()) + self.assertFalse(value.GetError().Success()) + + # Test retrieving of a field (not a local with the same name) + value = obj_val.EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + # Test if the self pointer is properly evaluated + + # Test retrieving of an objcClass's property through the self pointer + value = obj_val.EvaluateExpression("self.property") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 2222) + + # Test objcClass's methods evaluation through the self pointer + value = obj_val.EvaluateExpression("[self method]") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 3333) + + # Test if we can use a computation result reference object correctly + + obj_val = frame.EvaluateExpression("[ObjcClass createNew]") + self.assertTrue(obj_val.IsValid()) + obj_val = obj_val.Dereference() + self.assertTrue(obj_val.IsValid()) + + # Test an expression evaluation on it + value = obj_val.EvaluateExpression("1") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + + # Test retrieving of a field on it + value = obj_val.EvaluateExpression("field") + self.assertTrue(value.IsValid()) + self.assertTrue(value.GetError().Success()) + self.assertEqual(value.GetValueAsSigned(), 1111) + + def setUp(self): + TestBase.setUp(self) + + self.main_source = "main.m" + self.main_source_spec = lldb.SBFileSpec(self.main_source) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/main.m b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/main.m new file mode 100644 index 00000000000..5c495b24894 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/commands/expression/context-object-objc/main.m @@ -0,0 +1,47 @@ +#import <Foundation/Foundation.h> + +@interface ObjcClass : NSObject { + int field; +} + +@property int property; + ++(ObjcClass*)createNew; + +-(id)init; + +-(int)method; + +@end + +@implementation ObjcClass + ++(ObjcClass*)createNew { + return [ObjcClass new]; +} + +-(id)init { + self = [super init]; + if (self) { + field = 1111; + _property = 2222; + } + return self; +} + +-(int)method { + return 3333; +} + +@end + +int main() +{ + @autoreleasepool { + ObjcClass* objcClass = [ObjcClass new]; + + int field = 4444; + + return 0; // Break here + } +} |