From 2c9feb40e9966ced3998b991bef7fb6e48c2fc57 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 18 Dec 2018 13:30:50 -0800 Subject: [PATCH] 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 --- iOS/FlipperKit.podspec | 9 -- .../FlipperKitCrashReporterPlugin.h | 21 --- .../FlipperKitCrashReporterPlugin.mm | 67 -------- .../FlipperKitSignalHandler.h | 143 ------------------ iOS/Sample/AppDelegate.mm | 4 +- iOS/Sample/Podfile | 1 - iOS/SampleSwift/Podfile | 2 - iOS/SampleSwift/SampleSwift/AppDelegate.swift | 1 - 8 files changed, 1 insertion(+), 247 deletions(-) delete mode 100644 iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h delete mode 100644 iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.mm delete mode 100644 iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitSignalHandler.h diff --git a/iOS/FlipperKit.podspec b/iOS/FlipperKit.podspec index 2c89be247..886b57bfd 100644 --- a/iOS/FlipperKit.podspec +++ b/iOS/FlipperKit.podspec @@ -166,13 +166,4 @@ 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/FlipperKitCrashReporterPlugin.h' - ss.source_files = "iOS/Plugins/FlipperKitCrashReporterPlugin/**/*.{h,mm}" - ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" } - end end diff --git a/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h b/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h deleted file mode 100644 index ef040061b..000000000 --- a/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.h +++ /dev/null @@ -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 -#import - -@protocol CrashReporterDelegate -- (void)sendCrashParams:(NSDictionary *)params; -@end - -@interface FlipperKitCrashReporterPlugin : NSObject -- (instancetype)init NS_UNAVAILABLE; -+ (instancetype) sharedInstance; -@end - -#endif diff --git a/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.mm b/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.mm deleted file mode 100644 index e1a801533..000000000 --- a/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin.mm +++ /dev/null @@ -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 -#include -#import "FlipperKitSignalHandler.h" - -@interface FlipperKitCrashReporterPlugin() -@property (strong, nonatomic) id connection; -@property (assign, nonatomic) NSUInteger notificationID; -@property (assign, nonatomic) NSUncaughtExceptionHandler *prevHandler; - -@end - -@implementation FlipperKitCrashReporterPlugin { - std::unique_ptr _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)connection { - self.connection = connection; -} - -- (void)didDisconnect { - self.connection = nil; -} - -- (BOOL)runInBackground { - return YES; -} - -@end -#endif diff --git a/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitSignalHandler.h b/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitSignalHandler.h deleted file mode 100644 index e44d4c9a6..000000000 --- a/iOS/Plugins/FlipperKitCrashReporterPlugin/FlipperKitCrashReporterPlugin/FlipperKitSignalHandler.h +++ /dev/null @@ -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 -#import "FlipperKitCrashReporterPlugin.h" -#import -#include -#include -#include -#include -#include - -namespace facebook { - namespace flipper { - using ObjCPlugin = NSObject *; - - class FlipperKitSignalHandler : public folly::AsyncSignalHandler { - - struct CrashDetails { - int signalType; - std::string reason; - std::vector 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 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 diff --git a/iOS/Sample/AppDelegate.mm b/iOS/Sample/AppDelegate.mm index 19a2284f4..46b8819ea 100644 --- a/iOS/Sample/AppDelegate.mm +++ b/iOS/Sample/AppDelegate.mm @@ -6,7 +6,6 @@ * */ #import "AppDelegate.h" -#import #import #import #import @@ -36,9 +35,8 @@ [FlipperKitLayoutComponentKitSupport setUpWithDescriptorMapper: layoutDescriptorMapper]; [client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]]; - + [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; - [client addPlugin:[FlipperKitCrashReporterPlugin sharedInstance]]; [[FlipperClient sharedClient] addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client addPlugin:[FlipperKitExamplePlugin sharedInstance]]; diff --git a/iOS/Sample/Podfile b/iOS/Sample/Podfile index a01055e56..22e288af4 100644 --- a/iOS/Sample/Podfile +++ b/iOS/Sample/Podfile @@ -10,7 +10,6 @@ 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| diff --git a/iOS/SampleSwift/Podfile b/iOS/SampleSwift/Podfile index d5d1dade3..924878685 100644 --- a/iOS/SampleSwift/Podfile +++ b/iOS/SampleSwift/Podfile @@ -11,8 +11,6 @@ target 'SampleSwift' do pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => '../../FlipperKit.podspec' pod 'FlipperKit/FlipperKitExamplePlugin', :path => '../../FlipperKit.podspec' pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', :path => '../../FlipperKit.podspec' - pod 'FlipperKit/FlipperKitCrashReporterPlugin', :path => '../../FlipperKit.podspec' - post_install do |installer| installer.pods_project.targets.each do |target| diff --git a/iOS/SampleSwift/SampleSwift/AppDelegate.swift b/iOS/SampleSwift/SampleSwift/AppDelegate.swift index 8d84a4704..5c5597fc7 100644 --- a/iOS/SampleSwift/SampleSwift/AppDelegate.swift +++ b/iOS/SampleSwift/SampleSwift/AppDelegate.swift @@ -21,7 +21,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { client?.add(FlipperKitNetworkPlugin(networkAdapter: SKIOSNetworkAdapter())) client?.add(FlipperKitExamplePlugin.sharedInstance()); client?.add(FKUserDefaultsPlugin.init(suiteName: nil)) - client?.add(FlipperKitCrashReporterPlugin.sharedInstance()); client?.start() let storyboard = UIStoryboard(name: "MainStoryBoard", bundle: nil)