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:
Pritesh Nandgaonkar
2018-11-26 03:41:16 -08:00
committed by Facebook Github Bot
parent 543bc6c4fb
commit d475a50f2a
6 changed files with 112 additions and 6 deletions

View File

@@ -156,4 +156,13 @@ Pod::Spec.new do |spec|
ss.source_files = "iOS/Plugins/FlipperKitExamplePlugin/**/*.{h,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }
end
spec.subspec "FlipperKitCrashReporterPlugin" do |ss|
ss.header_dir = "FlipperKitCrashReporterPlugin"
ss.dependency 'FlipperKit/Core'
ss.compiler_flags = folly_compiler_flags
ss.public_header_files = 'iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h'
ss.source_files = "iOS/Plugins/FlipperKitCrashReporterPlugin/**/*.{h,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }
end
end

View File

@@ -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

View File

@@ -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

View File

@@ -6,7 +6,7 @@
*
*/
#import "AppDelegate.h"
#import <FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h>
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
@@ -38,6 +38,7 @@
withDescriptorMapper: layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitCrashReporterPlugin sharedInstance]];
[[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client addPlugin:[FlipperKitExamplePlugin sharedInstance]];

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@@ -259,6 +259,9 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sonarpattern" translatesAutoresizingMaskIntoConstraints="NO" id="ytS-7A-bty">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WSh-CB-RQ8">
<rect key="frame" x="40" y="257.5" width="295" height="152"/>
<subviews>
@@ -319,9 +322,6 @@
<constraint firstItem="Fel-3h-2Ts" firstAttribute="top" secondItem="cp1-5I-XfA" secondAttribute="bottom" constant="8" id="sAQ-IL-GiU"/>
</constraints>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sonarpattern" translatesAutoresizingMaskIntoConstraints="NO" id="ytS-7A-bty">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>

View File

@@ -10,6 +10,7 @@ target 'Sample' do
pod 'FlipperKit/SKIOSNetworkPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitCrashReporterPlugin', :path => '../../FlipperKit.podspec'
pod 'Flipper', :path => '../../Flipper.podspec'
post_install do |installer|