summaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/lang/objc/objc-stepping
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/lang/objc/objc-stepping')
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/objc-stepping/Makefile6
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py172
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/objc-stepping/stepping-tests.m138
3 files changed, 316 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/lang/objc/objc-stepping/Makefile b/packages/Python/lldbsuite/test/lang/objc/objc-stepping/Makefile
new file mode 100644
index 0000000..b097fe6
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/objc/objc-stepping/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJC_SOURCES := stepping-tests.m
+LDFLAGS = $(CFLAGS) -lobjc -framework Foundation
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py b/packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
new file mode 100644
index 0000000..1df416d
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/objc/objc-stepping/TestObjCStepping.py
@@ -0,0 +1,172 @@
+"""Test stepping through ObjC method dispatch in various forms."""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class TestObjCStepping(TestBase):
+
+ def getCategories (self):
+ return ['basic_process']
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line numbers that we will step to in main:
+ self.main_source = "stepping-tests.m"
+ self.source_randomMethod_line = line_number (self.main_source, '// Source randomMethod start line.')
+ self.sourceBase_randomMethod_line = line_number (self.main_source, '// SourceBase randomMethod start line.')
+ self.source_returnsStruct_start_line = line_number (self.main_source, '// Source returnsStruct start line.')
+ self.sourceBase_returnsStruct_start_line = line_number (self.main_source, '// SourceBase returnsStruct start line.')
+ self.stepped_past_nil_line = line_number (self.main_source, '// Step over nil should stop here.')
+
+ @skipUnlessDarwin
+ @add_test_categories(['pyapi'])
+ def test_with_python_api(self):
+ """Test stepping through ObjC method dispatch in various forms."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ self.main_source_spec = lldb.SBFileSpec (self.main_source)
+
+ breakpoints_to_disable = []
+
+ break1 = target.BreakpointCreateBySourceRegex ("// Set first breakpoint here.", self.main_source_spec)
+ self.assertTrue(break1, VALID_BREAKPOINT)
+ breakpoints_to_disable.append (break1)
+
+ break2 = target.BreakpointCreateBySourceRegex ("// Set second breakpoint here.", self.main_source_spec)
+ self.assertTrue(break2, VALID_BREAKPOINT)
+ breakpoints_to_disable.append (break2)
+
+ break3 = target.BreakpointCreateBySourceRegex ('// Set third breakpoint here.', self.main_source_spec)
+ self.assertTrue(break3, VALID_BREAKPOINT)
+ breakpoints_to_disable.append (break3)
+
+ break4 = target.BreakpointCreateBySourceRegex ('// Set fourth breakpoint here.', self.main_source_spec)
+ self.assertTrue(break4, VALID_BREAKPOINT)
+ breakpoints_to_disable.append (break4)
+
+ break5 = target.BreakpointCreateBySourceRegex ('// Set fifth breakpoint here.', self.main_source_spec)
+ self.assertTrue(break5, VALID_BREAKPOINT)
+ breakpoints_to_disable.append (break5)
+
+ break_returnStruct_call_super = target.BreakpointCreateBySourceRegex ('// Source returnsStruct call line.', self.main_source_spec)
+ self.assertTrue(break_returnStruct_call_super, VALID_BREAKPOINT)
+ breakpoints_to_disable.append (break_returnStruct_call_super)
+
+ break_step_nil = target.BreakpointCreateBySourceRegex ('// Set nil step breakpoint here.', self.main_source_spec)
+ self.assertTrue(break_step_nil, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple (None, None, self.get_process_working_directory())
+
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # The stop reason of the thread should be breakpoint.
+ threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1)
+ if len(threads) != 1:
+ self.fail ("Failed to stop at breakpoint 1.")
+
+ thread = threads[0]
+
+ mySource = thread.GetFrameAtIndex(0).FindVariable("mySource")
+ self.assertTrue(mySource, "Found mySource local variable.")
+ mySource_isa = mySource.GetChildMemberWithName ("isa")
+ self.assertTrue(mySource_isa, "Found mySource->isa local variable.")
+ className = mySource_isa.GetSummary ()
+
+ if self.TraceOn():
+ print(mySource_isa)
+
+ # Lets delete mySource so we can check that after stepping a child variable
+ # with no parent persists and is useful.
+ del (mySource)
+
+ # Now step in, that should leave us in the Source randomMethod:
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.source_randomMethod_line, "Stepped into Source randomMethod.")
+
+ # Now step in again, through the super call, and that should leave us in the SourceBase randomMethod:
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.sourceBase_randomMethod_line, "Stepped through super into SourceBase randomMethod.")
+
+ threads = lldbutil.continue_to_breakpoint (process, break2)
+ self.assertTrue (len(threads) == 1, "Continued to second breakpoint in main.")
+
+ # Again, step in twice gets us to a stret method and a stret super call:
+ thread = threads[0]
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.source_returnsStruct_start_line, "Stepped into Source returnsStruct.")
+
+ threads = lldbutil.continue_to_breakpoint (process, break_returnStruct_call_super)
+ self.assertTrue (len(threads) == 1, "Stepped to the call super line in Source returnsStruct.")
+ thread = threads[0]
+
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.sourceBase_returnsStruct_start_line, "Stepped through super into SourceBase returnsStruct.")
+
+ # Cool now continue to get past the call that initializes the Observer, and then do our steps in again to see that
+ # we can find our way when we're stepping through a KVO swizzled object.
+
+ threads = lldbutil.continue_to_breakpoint (process, break3)
+ self.assertTrue (len(threads) == 1, "Continued to third breakpoint in main, our object should now be swizzled.")
+
+ newClassName = mySource_isa.GetSummary ()
+
+ if self.TraceOn():
+ print(mySource_isa)
+
+ self.assertTrue (newClassName != className, "The isa did indeed change, swizzled!")
+
+ # Now step in, that should leave us in the Source randomMethod:
+ thread = threads[0]
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.source_randomMethod_line, "Stepped into Source randomMethod in swizzled object.")
+
+ # Now step in again, through the super call, and that should leave us in the SourceBase randomMethod:
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.sourceBase_randomMethod_line, "Stepped through super into SourceBase randomMethod in swizzled object.")
+
+ threads = lldbutil.continue_to_breakpoint (process, break4)
+ self.assertTrue (len(threads) == 1, "Continued to fourth breakpoint in main.")
+ thread = threads[0]
+
+ # Again, step in twice gets us to a stret method and a stret super call:
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.source_returnsStruct_start_line, "Stepped into Source returnsStruct in swizzled object.")
+
+ threads = lldbutil.continue_to_breakpoint(process, break_returnStruct_call_super)
+ self.assertTrue (len(threads) == 1, "Stepped to the call super line in Source returnsStruct - second time.")
+ thread = threads[0]
+
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.sourceBase_returnsStruct_start_line, "Stepped through super into SourceBase returnsStruct in swizzled object.")
+
+ for bkpt in breakpoints_to_disable:
+ bkpt.SetEnabled(False)
+
+ threads = lldbutil.continue_to_breakpoint (process, break_step_nil)
+ self.assertTrue (len(threads) == 1, "Continued to step nil breakpoint.")
+
+ thread.StepInto()
+ line_number = thread.GetFrameAtIndex(0).GetLineEntry().GetLine()
+ self.assertTrue (line_number == self.stepped_past_nil_line, "Step in over dispatch to nil stepped over.")
diff --git a/packages/Python/lldbsuite/test/lang/objc/objc-stepping/stepping-tests.m b/packages/Python/lldbsuite/test/lang/objc/objc-stepping/stepping-tests.m
new file mode 100644
index 0000000..63db536
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/objc/objc-stepping/stepping-tests.m
@@ -0,0 +1,138 @@
+#import <Foundation/Foundation.h>
+#include <stdio.h>
+
+struct return_me
+{
+ int first;
+ int second;
+};
+
+@interface SourceBase: NSObject
+{
+ struct return_me my_return;
+}
+- (SourceBase *) initWithFirst: (int) first andSecond: (int) second;
+- (void) randomMethod;
+- (struct return_me) returnsStruct;
+@end
+
+@implementation SourceBase
+- (void) randomMethod
+{
+ printf ("Called in SourceBase version of randomMethod.\n"); // SourceBase randomMethod start line.
+}
+
+- (struct return_me) returnsStruct
+{
+ return my_return; // SourceBase returnsStruct start line.
+}
+
+- (SourceBase *) initWithFirst: (int) first andSecond: (int) second
+{
+ my_return.first = first;
+ my_return.second = second;
+
+ return self;
+}
+@end
+
+@interface Source : SourceBase
+{
+ int _property;
+}
+- (void) setProperty: (int) newValue;
+- (void) randomMethod;
+- (struct return_me) returnsStruct;
+@end
+
+@implementation Source
+- (void) setProperty: (int) newValue
+{
+ _property = newValue;
+}
+
+- (void) randomMethod
+{
+ [super randomMethod]; // Source randomMethod start line.
+ printf ("Called in Source version of random method.");
+}
+
+- (struct return_me) returnsStruct
+{
+ printf ("Called in Source version of returnsStruct.\n"); // Source returnsStruct start line.
+ return [super returnsStruct]; // Source returnsStruct call line.
+}
+
+@end
+
+@interface Observer : NSObject
+{
+ Source *_source;
+}
++ (Observer *) observerWithSource: (Source *) source;
+- (Observer *) initWithASource: (Source *) source;
+- (void) observeValueForKeyPath: (NSString *) path
+ ofObject: (id) object
+ change: (NSDictionary *) change
+ context: (void *) context;
+@end
+
+@implementation Observer
+
++ (Observer *) observerWithSource: (Source *) inSource;
+{
+ Observer *retval;
+
+ retval = [[Observer alloc] initWithASource: inSource];
+ return retval;
+}
+
+- (Observer *) initWithASource: (Source *) source
+{
+ [super init];
+ _source = source;
+ [_source addObserver: self
+ forKeyPath: @"property"
+ options: (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
+ context: NULL];
+ return self;
+}
+
+- (void) observeValueForKeyPath: (NSString *) path
+ ofObject: (id) object
+ change: (NSDictionary *) change
+ context: (void *) context
+{
+ printf ("Observer function called.\n");
+ return;
+}
+@end
+
+int main ()
+{
+ Source *mySource;
+ Observer *myObserver;
+ struct return_me ret_val;
+
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ mySource = [[Source alloc] init];
+
+ [mySource randomMethod]; // Set first breakpoint here.
+ ret_val = [mySource returnsStruct]; // Set second breakpoint here.
+
+ myObserver = [Observer observerWithSource: mySource];
+
+ [mySource randomMethod]; // Set third breakpoint here.
+ ret_val = [mySource returnsStruct]; // Set fourth breakpoint here.
+ [mySource setProperty: 5]; // Set fifth breakpoint here.
+
+ // We also had a bug where stepping into a method dispatch to nil turned
+ // into continue. So make sure that works here:
+
+ mySource = nil;
+ [mySource randomMethod]; // Set nil step breakpoint here.
+ [pool release]; // Step over nil should stop here.
+ return 0;
+
+}
OpenPOWER on IntegriCloud