summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorKuba Mracek <mracek@apple.com>2018-11-12 19:12:31 +0000
committerKuba Mracek <mracek@apple.com>2018-11-12 19:12:31 +0000
commitc3f1e62920df794fc31f23327931ed68fa8b89ba (patch)
tree7a481c57b3bed34352ddb81acf731a5185979953 /lldb/packages/Python/lldbsuite/test
parent9a89d93d62525518faa518766b6fae4d14b26140 (diff)
downloadbcm5719-llvm-c3f1e62920df794fc31f23327931ed68fa8b89ba.tar.gz
bcm5719-llvm-c3f1e62920df794fc31f23327931ed68fa8b89ba.zip
[lldb] Extract more fields from NSException values
This patch teaches LLDB about more fields on NSException Obj-C objects, specifically we can now retrieve the "name" and "reason" of an NSException. The goal is to eventually be able to have SB API that can provide details about the currently thrown/caught/processed exception. Differential Revision: https://reviews.llvm.org/D43884 llvm-svn: 346695
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile9
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py90
-rw-r--r--lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.m36
3 files changed, 135 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile
new file mode 100644
index 00000000000..9f7fb1ca623
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/Makefile
@@ -0,0 +1,9 @@
+LEVEL = ../../../make
+
+OBJC_SOURCES := main.m
+
+CFLAGS_EXTRAS += -w
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation
diff --git a/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
new file mode 100644
index 00000000000..423776cd115
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/TestObjCExceptions.py
@@ -0,0 +1,90 @@
+# 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_1(self):
+ self.build()
+
+ target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+ self.assertTrue(target, VALID_TARGET)
+
+ lldbutil.run_to_source_breakpoint(self, "// Set break point at this line.", lldb.SBFileSpec("main.m"))
+
+ self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+ substrs=['stopped', 'stop reason = breakpoint'])
+
+ thread = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread()
+ frame = thread.GetSelectedFrame()
+
+ 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")
+ self.assertGreater(e2.GetChildMemberWithName("reserved").dynamic.num_children, 0)
diff --git a/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.m b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.m
new file mode 100644
index 00000000000..93ad7266256
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.m
@@ -0,0 +1,36 @@
+//===-- 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>
+
+void foo()
+{
+ NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"some_value", @"some_key", nil];
+ @throw [[NSException alloc] initWithName:@"ThrownException" reason:@"SomeReason" userInfo:info];
+}
+
+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();
+ } @catch(NSException *e) {
+ e2 = e;
+ }
+
+ NSLog(@"1"); // Set break point at this line.
+ [pool drain];
+ return 0;
+}
+
OpenPOWER on IntegriCloud