summaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/lang/objc
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/lang/objc')
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile9
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py205
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm63
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/modules-inline-functions/TestModulesInlineFunctions.py17
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/real-definition/Bar.h2
-rw-r--r--packages/Python/lldbsuite/test/lang/objc/real-definition/Foo.h2
6 files changed, 281 insertions, 17 deletions
diff --git a/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile b/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile
new file mode 100644
index 000000000000..261658b10ae8
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile
@@ -0,0 +1,9 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+
+CFLAGS_EXTRAS += -w
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation
diff --git a/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py b/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
new file mode 100644
index 000000000000..92b32504cf20
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
@@ -0,0 +1,205 @@
+# encoding: utf-8
+"""
+Test lldb Obj-C exception support.
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class ObjCExceptionsTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipUnlessDarwin
+ def test_objc_exceptions_at_throw(self):
+ self.build()
+
+ target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+ self.assertTrue(target, VALID_TARGET)
+
+ launch_info = lldb.SBLaunchInfo(["a.out", "0"])
+ lldbutil.run_to_name_breakpoint(self, "objc_exception_throw", launch_info=launch_info)
+
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs=['stopped', 'stop reason = breakpoint'])
+
+ self.expect('thread exception', substrs=[
+ '(NSException *) exception = ',
+ 'name: "ThrownException" - reason: "SomeReason"',
+ ])
+
+ target = self.dbg.GetSelectedTarget()
+ thread = target.GetProcess().GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ opts = lldb.SBVariablesOptions()
+ opts.SetIncludeRecognizedArguments(True)
+ variables = frame.GetVariables(opts)
+
+ self.assertEqual(variables.GetSize(), 1)
+ self.assertEqual(variables.GetValueAtIndex(0).name, "exception")
+
+ lldbutil.run_to_source_breakpoint(self, "// Set break point at this line.", lldb.SBFileSpec("main.mm"), launch_info=launch_info)
+
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs=['stopped', 'stop reason = breakpoint'])
+
+ target = self.dbg.GetSelectedTarget()
+ thread = target.GetProcess().GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ # No exception being currently thrown/caught at this point
+ self.assertFalse(thread.GetCurrentException().IsValid())
+ self.assertFalse(thread.GetCurrentExceptionBacktrace().IsValid())
+
+ self.expect(
+ 'frame variable e1',
+ substrs=[
+ '(NSException *) e1 = ',
+ 'name: "ExceptionName" - reason: "SomeReason"'
+ ])
+
+ self.expect(
+ 'frame variable --dynamic-type no-run-target *e1',
+ substrs=[
+ '(NSException) *e1 = ',
+ 'name = ', '"ExceptionName"',
+ 'reason = ', '"SomeReason"',
+ 'userInfo = ', '1 key/value pair',
+ 'reserved = ', 'nil',
+ ])
+
+ e1 = frame.FindVariable("e1")
+ self.assertTrue(e1)
+ self.assertEqual(e1.type.name, "NSException *")
+ self.assertEqual(e1.GetSummary(), 'name: "ExceptionName" - reason: "SomeReason"')
+ self.assertEqual(e1.GetChildMemberWithName("name").description, "ExceptionName")
+ self.assertEqual(e1.GetChildMemberWithName("reason").description, "SomeReason")
+ userInfo = e1.GetChildMemberWithName("userInfo").dynamic
+ self.assertEqual(userInfo.summary, "1 key/value pair")
+ self.assertEqual(userInfo.GetChildAtIndex(0).GetChildAtIndex(0).description, "some_key")
+ self.assertEqual(userInfo.GetChildAtIndex(0).GetChildAtIndex(1).description, "some_value")
+ self.assertEqual(e1.GetChildMemberWithName("reserved").description, "<nil>")
+
+ self.expect(
+ 'frame variable e2',
+ substrs=[
+ '(NSException *) e2 = ',
+ 'name: "ThrownException" - reason: "SomeReason"'
+ ])
+
+ self.expect(
+ 'frame variable --dynamic-type no-run-target *e2',
+ substrs=[
+ '(NSException) *e2 = ',
+ 'name = ', '"ThrownException"',
+ 'reason = ', '"SomeReason"',
+ 'userInfo = ', '1 key/value pair',
+ 'reserved = ',
+ ])
+
+ e2 = frame.FindVariable("e2")
+ self.assertTrue(e2)
+ self.assertEqual(e2.type.name, "NSException *")
+ self.assertEqual(e2.GetSummary(), 'name: "ThrownException" - reason: "SomeReason"')
+ self.assertEqual(e2.GetChildMemberWithName("name").description, "ThrownException")
+ self.assertEqual(e2.GetChildMemberWithName("reason").description, "SomeReason")
+ userInfo = e2.GetChildMemberWithName("userInfo").dynamic
+ self.assertEqual(userInfo.summary, "1 key/value pair")
+ self.assertEqual(userInfo.GetChildAtIndex(0).GetChildAtIndex(0).description, "some_key")
+ self.assertEqual(userInfo.GetChildAtIndex(0).GetChildAtIndex(1).description, "some_value")
+ reserved = e2.GetChildMemberWithName("reserved").dynamic
+ self.assertGreater(reserved.num_children, 0)
+ callStackReturnAddresses = [reserved.GetChildAtIndex(i).GetChildAtIndex(1) for i in range(0, reserved.GetNumChildren())
+ if reserved.GetChildAtIndex(i).GetChildAtIndex(0).description == "callStackReturnAddresses"][0].dynamic
+ children = [callStackReturnAddresses.GetChildAtIndex(i) for i in range(0, callStackReturnAddresses.num_children)]
+
+ pcs = [i.unsigned for i in children]
+ names = [target.ResolveSymbolContextForAddress(lldb.SBAddress(pc, target), lldb.eSymbolContextSymbol).GetSymbol().name for pc in pcs]
+ for n in ["objc_exception_throw", "foo(int)", "main"]:
+ self.assertTrue(n in names, "%s is in the exception backtrace (%s)" % (n, names))
+
+ @skipUnlessDarwin
+ def test_objc_exceptions_at_abort(self):
+ self.build()
+
+ target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+ self.assertTrue(target, VALID_TARGET)
+
+ self.runCmd("run 0")
+
+ # We should be stopped at pthread_kill because of an unhandled exception
+ self.expect("thread list",
+ substrs=['stopped', 'stop reason = signal SIGABRT'])
+
+ self.expect('thread exception', substrs=[
+ '(NSException *) exception = ',
+ 'name: "ThrownException" - reason: "SomeReason"',
+ 'libobjc.A.dylib`objc_exception_throw',
+ 'a.out`foo', 'at main.mm:25',
+ 'a.out`rethrow', 'at main.mm:36',
+ 'a.out`main',
+ ])
+
+ process = self.dbg.GetSelectedTarget().process
+ thread = process.GetSelectedThread()
+
+ # There is an exception being currently processed at this point
+ self.assertTrue(thread.GetCurrentException().IsValid())
+ self.assertTrue(thread.GetCurrentExceptionBacktrace().IsValid())
+
+ history_thread = thread.GetCurrentExceptionBacktrace()
+ self.assertGreaterEqual(history_thread.num_frames, 4)
+ for n in ["objc_exception_throw", "foo(int)", "rethrow(int)", "main"]:
+ self.assertEqual(len([f for f in history_thread.frames if f.GetFunctionName() == n]), 1)
+
+ self.runCmd("kill")
+
+ self.runCmd("run 1")
+ # We should be stopped at pthread_kill because of an unhandled exception
+ self.expect("thread list",
+ substrs=['stopped', 'stop reason = signal SIGABRT'])
+
+ self.expect('thread exception', substrs=[
+ '(MyCustomException *) exception = ',
+ 'libobjc.A.dylib`objc_exception_throw',
+ 'a.out`foo', 'at main.mm:27',
+ 'a.out`rethrow', 'at main.mm:36',
+ 'a.out`main',
+ ])
+
+ process = self.dbg.GetSelectedTarget().process
+ thread = process.GetSelectedThread()
+
+ history_thread = thread.GetCurrentExceptionBacktrace()
+ self.assertGreaterEqual(history_thread.num_frames, 4)
+ for n in ["objc_exception_throw", "foo(int)", "rethrow(int)", "main"]:
+ self.assertEqual(len([f for f in history_thread.frames if f.GetFunctionName() == n]), 1)
+
+ @skipUnlessDarwin
+ def test_cxx_exceptions_at_abort(self):
+ self.build()
+
+ target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+ self.assertTrue(target, VALID_TARGET)
+
+ self.runCmd("run 2")
+
+ # We should be stopped at pthread_kill because of an unhandled exception
+ self.expect("thread list",
+ substrs=['stopped', 'stop reason = signal SIGABRT'])
+
+ self.expect('thread exception', substrs=[])
+
+ process = self.dbg.GetSelectedTarget().process
+ thread = process.GetSelectedThread()
+
+ # C++ exceptions are not exposed in the API (yet).
+ self.assertFalse(thread.GetCurrentException().IsValid())
+ self.assertFalse(thread.GetCurrentExceptionBacktrace().IsValid())
diff --git a/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm b/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm
new file mode 100644
index 000000000000..5683882486d8
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm
@@ -0,0 +1,63 @@
+//===-- main.m ------------------------------------------------*- ObjC -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#import <Foundation/Foundation.h>
+
+#import <exception>
+#import <stdexcept>
+
+@interface MyCustomException: NSException
+@end
+@implementation MyCustomException
+@end
+
+void foo(int n)
+{
+ NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"some_value", @"some_key", nil];
+ switch (n) {
+ case 0:
+ @throw [[NSException alloc] initWithName:@"ThrownException" reason:@"SomeReason" userInfo:info];
+ case 1:
+ @throw [[MyCustomException alloc] initWithName:@"ThrownException" reason:@"SomeReason" userInfo:info];
+ case 2:
+ throw std::runtime_error("C++ exception");
+ }
+}
+
+void rethrow(int n)
+{
+ @try {
+ foo(n);
+ } @catch(NSException *e) {
+ @throw;
+ }
+}
+
+int main(int argc, const char * argv[])
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"some_value", @"some_key", nil];
+ NSException *e1 = [[NSException alloc] initWithName:@"ExceptionName" reason:@"SomeReason" userInfo:info];
+ NSException *e2;
+
+ @try {
+ foo(atoi(argv[1]));
+ } @catch(NSException *e) {
+ e2 = e;
+ }
+
+ NSLog(@"1"); // Set break point at this line.
+
+ rethrow(atoi(argv[1]));
+
+ [pool drain];
+ return 0;
+}
+
diff --git a/packages/Python/lldbsuite/test/lang/objc/modules-inline-functions/TestModulesInlineFunctions.py b/packages/Python/lldbsuite/test/lang/objc/modules-inline-functions/TestModulesInlineFunctions.py
index 29d386253fb4..e9dbe6af864f 100644
--- a/packages/Python/lldbsuite/test/lang/objc/modules-inline-functions/TestModulesInlineFunctions.py
+++ b/packages/Python/lldbsuite/test/lang/objc/modules-inline-functions/TestModulesInlineFunctions.py
@@ -23,8 +23,6 @@ class ModulesInlineFunctionsTestCase(TestBase):
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
- # Find the line number to break inside main().
- self.line = line_number('main.m', '// Set breakpoint here.')
@skipUnlessDarwin
@skipIf(macos_version=["<", "10.12"], debug_info=no_match(["gmodules"]))
@@ -34,19 +32,8 @@ class ModulesInlineFunctionsTestCase(TestBase):
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break inside the foo function which takes a bar_ptr argument.
- lldbutil.run_break_set_by_file_and_line(
- self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
-
- self.runCmd("run", RUN_SUCCEEDED)
-
- # The stop reason of the thread should be breakpoint.
- self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
- substrs=['stopped',
- 'stop reason = breakpoint'])
-
- # The breakpoint should have a hit count of 1.
- self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
- substrs=[' resolved, hit count = 1'])
+ lldbutil.run_to_source_breakpoint(
+ self, '// Set breakpoint here.', lldb.SBFileSpec('main.m'))
self.runCmd(
"settings set target.clang-module-search-paths \"" +
diff --git a/packages/Python/lldbsuite/test/lang/objc/real-definition/Bar.h b/packages/Python/lldbsuite/test/lang/objc/real-definition/Bar.h
index 20a81faa1017..5ee6acb2425e 100644
--- a/packages/Python/lldbsuite/test/lang/objc/real-definition/Bar.h
+++ b/packages/Python/lldbsuite/test/lang/objc/real-definition/Bar.h
@@ -9,4 +9,4 @@
- (NSString *)description;
-@end \ No newline at end of file
+@end
diff --git a/packages/Python/lldbsuite/test/lang/objc/real-definition/Foo.h b/packages/Python/lldbsuite/test/lang/objc/real-definition/Foo.h
index 14ff9eed50fd..d58da600765a 100644
--- a/packages/Python/lldbsuite/test/lang/objc/real-definition/Foo.h
+++ b/packages/Python/lldbsuite/test/lang/objc/real-definition/Foo.h
@@ -8,4 +8,4 @@
- (NSString *)description;
-@end \ No newline at end of file
+@end