From c9e1190a27864868324c20aabd8fa648a8247c5a Mon Sep 17 00:00:00 2001 From: Kuba Mracek Date: Thu, 20 Dec 2018 02:01:59 +0000 Subject: [lldb] Retrieve currently handled Obj-C exception via __cxa_current_exception_type and add GetCurrentExceptionBacktrace SB ABI This builds on https://reviews.llvm.org/D43884 and https://reviews.llvm.org/D43886 and extends LLDB support of Obj-C exceptions to also look for a "current exception" for a thread in the C++ exception handling runtime metadata (via call to __cxa_current_exception_type). We also construct an actual historical SBThread/ThreadSP that contains frames from the backtrace in the Obj-C exception object. The high level goal this achieves is that when we're already crashed (because an unhandled exception occurred), we can still access the exception object and retrieve the backtrace from the throw point. In Obj-C, this is particularly useful because a catch+rethrow is very common and in those cases you currently don't have any access to the throw point backtrace. Differential Revision: https://reviews.llvm.org/D44072 llvm-svn: 349718 --- .../lldbsuite/test/lang/objc/exceptions/main.mm | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm (limited to 'lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm') diff --git a/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm b/lldb/packages/Python/lldbsuite/test/lang/objc/exceptions/main.mm new file mode 100644 index 00000000000..5683882486d --- /dev/null +++ b/lldb/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 + +#import +#import + +@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; +} + -- cgit v1.2.3