Remove crashreporter plugin iOS implementation

Summary: Removes the iOS implementation of crash reporter plugin as its implemented as desktop plugin

Reviewed By: adamjernst

Differential Revision: D13451980

fbshipit-source-id: 19cca52a00bb4a6d350eff91ac405f6dd3b07818
This commit is contained in:
Pritesh Nandgaonkar
2018-12-18 13:30:50 -08:00
committed by Facebook Github Bot
parent a12768539e
commit 2c9feb40e9
8 changed files with 1 additions and 247 deletions

View File

@@ -166,13 +166,4 @@ Pod::Spec.new do |spec|
ss.source_files = "iOS/Plugins/FlipperKitExamplePlugin/**/*.{h,mm}" ss.source_files = "iOS/Plugins/FlipperKitExamplePlugin/**/*.{h,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" } ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }
end 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/FlipperKitCrashReporterPlugin.h'
ss.source_files = "iOS/Plugins/FlipperKitCrashReporterPlugin/**/*.{h,mm}"
ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }
end
end end

View File

@@ -1,21 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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>
@protocol CrashReporterDelegate
- (void)sendCrashParams:(NSDictionary *)params;
@end
@interface FlipperKitCrashReporterPlugin : NSObject<FlipperPlugin, CrashReporterDelegate>
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype) sharedInstance;
@end
#endif

View File

@@ -1,67 +0,0 @@
/*
* 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>
#include <folly/io/async/ScopedEventBaseThread.h>
#import "FlipperKitSignalHandler.h"
@interface FlipperKitCrashReporterPlugin()
@property (strong, nonatomic) id<FlipperConnection> connection;
@property (assign, nonatomic) NSUInteger notificationID;
@property (assign, nonatomic) NSUncaughtExceptionHandler *prevHandler;
@end
@implementation FlipperKitCrashReporterPlugin {
std::unique_ptr<facebook::flipper::FlipperKitSignalHandler> _signalHandler;
folly::ScopedEventBaseThread _crashReporterThread;
}
- (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)sendCrashParams:(NSDictionary *)params {
self.notificationID += 1;
}
- (void)didConnect:(id<FlipperConnection>)connection {
self.connection = connection;
}
- (void)didDisconnect {
self.connection = nil;
}
- (BOOL)runInBackground {
return YES;
}
@end
#endif

View File

@@ -1,143 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*/
#ifndef __OBJC__
#error This header can only be included in .mm (ObjC++) files
#endif
#if FB_SONARKIT_ENABLED
#pragma once
#include <folly/io/async/AsyncSignalHandler.h>
#import "FlipperKitCrashReporterPlugin.h"
#import <FBCxxUtils/FBCxxFollyDynamicConvert.h>
#include <folly/io/async/ScopedEventBaseThread.h>
#include <execinfo.h>
#include <iostream>
#include <mutex>
#include <chrono>
namespace facebook {
namespace flipper {
using ObjCPlugin = NSObject<CrashReporterDelegate> *;
class FlipperKitSignalHandler : public folly::AsyncSignalHandler {
struct CrashDetails {
int signalType;
std::string reason;
std::vector<std::string> callStack;
NSTimeInterval time; //In milliseconds
bool operator==(const CrashDetails& rhs)
{
return signalType == rhs.signalType && reason == rhs.reason && callStack == rhs.callStack && (abs(rhs.time - time) < 10);
}
bool operator!=(const CrashDetails& rhs) {
return !(*this == rhs);
}
};
public:
FlipperKitSignalHandler(ObjCPlugin reporterPlugin, folly::EventBase *eventBase): folly::AsyncSignalHandler(eventBase), plugin_(reporterPlugin), eventbase_(eventBase) {
eventBase->add([this]{
registerSignalHandler(SIGILL);
registerSignalHandler(SIGSEGV);
registerSignalHandler(SIGFPE);
registerSignalHandler(SIGBUS);
registerSignalHandler(SIGABRT);
});
}
void unregisterSignalHandler() {
folly::AsyncSignalHandler::unregisterSignalHandler(SIGILL); // illegal instruction
folly::AsyncSignalHandler::unregisterSignalHandler(SIGSEGV); // segmentation violation
folly::AsyncSignalHandler::unregisterSignalHandler(SIGFPE); // floating point exception
folly::AsyncSignalHandler::unregisterSignalHandler(SIGBUS); // Bus error
folly::AsyncSignalHandler::unregisterSignalHandler(SIGABRT); // Abort
}
~FlipperKitSignalHandler() {
unregisterSignalHandler();
plugin_ = nullptr;
}
private:
ObjCPlugin plugin_;
folly::EventBase *eventbase_;
std::mutex mtx;
CrashDetails lastCrashDetails_;
std::string signalType(int signal) {
switch (signal) {
case SIGILL:
return "SIGILL";
case SIGSEGV:
return "SIGSEGV";
case SIGFPE:
return "SIGFPE";
case SIGBUS:
return "SIGBUS";
case SIGABRT:
return "SIGABRT";
default:
return "Unregistered Signal";
}
}
std::string reasonForSignalError(int signal) {
switch (signal) {
case SIGILL:
return "Illegal Instruction";
case SIGSEGV:
return "Segmentation Violation";
case SIGFPE:
return "Floating Point Exception";
case SIGBUS:
return "Bus Error";
case SIGABRT:
return "Abort Signal";
default:
return "Unregistered Signal";
}
}
void signalReceived(int signum) noexcept override {
void* callstack[2048];
int frames = backtrace(callstack, 2048);
char **strs = backtrace_symbols(callstack, frames);
folly::dynamic arr = folly::dynamic::array();
std::vector<std::string> vec;
for (int i = 0; i < frames; ++i) {
NSString *str = [NSString stringWithUTF8String:strs[i]];
vec.push_back(std::string([str UTF8String]));
arr.push_back(std::string([str UTF8String]));
}
std::string reasonforSignalError = reasonForSignalError(signum);
CrashDetails currentCrash({signum, reasonforSignalError, vec, [[NSDate date] timeIntervalSince1970] * 1000});
// This check is added, because I reproduced a scenario where lot of signal errors of same kind were thrown in a short period of span. So this basically makes sure that we just send one notification.
// To reproduce that case, use this snippet `void (*nullFunction)() = NULL; nullFunction();`, it will cause segfault.
if (lastCrashDetails_ != currentCrash) {
[plugin_ sendCrashParams:facebook::cxxutils::convertFollyDynamicToId(folly::dynamic::object("reason", reasonforSignalError)("name", std::string("Signal Error ") + signalType(signum))("callstack", arr))];
eventbase_->runAfterDelay([this, signum]{
unregisterSignalHandler(); // Unregister signal handler as we will be reraising the signal.
// Raising the signal after delay, because message is sent in an asyncronous way to flipper. If its raised with no delay then its observed that flipper doesn't receive the message
raise(signum);}, 10);
}
lastCrashDetails_ = currentCrash;
}
};
} // namespace flipper
} // namespace facebook
#endif

View File

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

View File

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

View File

@@ -11,8 +11,6 @@ target 'SampleSwift' do
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec' pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec' pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', :path => '../../FlipperKit.podspec' pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', :path => '../../FlipperKit.podspec'
pod 'FlipperKit/FlipperKitCrashReporterPlugin', :path => '../../FlipperKit.podspec'
post_install do |installer| post_install do |installer|
installer.pods_project.targets.each do |target| installer.pods_project.targets.each do |target|

View File

@@ -21,7 +21,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
client?.add(FlipperKitNetworkPlugin(networkAdapter: SKIOSNetworkAdapter())) client?.add(FlipperKitNetworkPlugin(networkAdapter: SKIOSNetworkAdapter()))
client?.add(FlipperKitExamplePlugin.sharedInstance()); client?.add(FlipperKitExamplePlugin.sharedInstance());
client?.add(FKUserDefaultsPlugin.init(suiteName: nil)) client?.add(FKUserDefaultsPlugin.init(suiteName: nil))
client?.add(FlipperKitCrashReporterPlugin.sharedInstance());
client?.start() client?.start()
let storyboard = UIStoryboard(name: "MainStoryBoard", bundle: nil) let storyboard = UIStoryboard(name: "MainStoryBoard", bundle: nil)