Crash reporter plugin
Summary: iOS side of crash reporter plugin Reviewed By: jknoxville Differential Revision: D13176725 fbshipit-source-id: be104958c5e26aa67709a33ef43c0b99600ca2b7
This commit is contained in:
committed by
Facebook Github Bot
parent
543bc6c4fb
commit
d475a50f2a
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
#if FB_SONARKIT_ENABLED
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <FlipperKit/FlipperPlugin.h>
|
||||
|
||||
@interface FlipperKitCrashReporterPlugin : NSObject<FlipperPlugin>
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
+ (instancetype) sharedInstance;
|
||||
@end
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
#if FB_SONARKIT_ENABLED
|
||||
#import "FlipperKitCrashReporterPlugin.h"
|
||||
#import <FlipperKit/FlipperConnection.h>
|
||||
|
||||
@interface FlipperKitCrashReporterPlugin()
|
||||
@property (strong, nonatomic) id<FlipperConnection> connection;
|
||||
@property (assign, nonatomic) NSUInteger notificationID;
|
||||
@property (assign, nonatomic) NSUncaughtExceptionHandler *prevHandler;
|
||||
- (void) handleException:(NSException *)exception;
|
||||
|
||||
@end
|
||||
|
||||
void flipperkitUncaughtExceptionHandler(NSException *exception) {
|
||||
NSLog(@"CRASH: %@", exception);
|
||||
NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
|
||||
[[FlipperKitCrashReporterPlugin sharedInstance] handleException:exception];
|
||||
}
|
||||
|
||||
@implementation FlipperKitCrashReporterPlugin
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_connection = nil;
|
||||
_notificationID = 0;
|
||||
_prevHandler = NSGetUncaughtExceptionHandler();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
static FlipperKitCrashReporterPlugin *sInstance = nil;
|
||||
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sInstance = [FlipperKitCrashReporterPlugin new];
|
||||
});
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
- (NSString *)identifier {
|
||||
return @"CrashReporter";
|
||||
}
|
||||
|
||||
- (void) handleException:(NSException *)exception {
|
||||
// TODO: Rather than having indirection from c function, somehow pass objective c selectors as a c function pointer to NSSetUncaughtExceptionHandler
|
||||
self.notificationID += 1;
|
||||
[self.connection send:@"crash-report" withParams:@{@"reason": [exception reason], @"name": [exception name], @"callstack": [exception callStackSymbols]}];
|
||||
if (self.prevHandler) {
|
||||
self.prevHandler(exception);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didConnect:(id<FlipperConnection>)connection {
|
||||
self.connection = connection;
|
||||
NSSetUncaughtExceptionHandler(&flipperkitUncaughtExceptionHandler);
|
||||
}
|
||||
|
||||
- (void)didDisconnect {
|
||||
self.connection = nil;
|
||||
NSSetUncaughtExceptionHandler(self.prevHandler);
|
||||
}
|
||||
|
||||
- (BOOL)runInBackground {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
#endif
|
||||
Reference in New Issue
Block a user