Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/crashloop #100

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions Backtrace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@
AFCCCE232625392300B83A28 /* ReportMetadataStorageMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCCCE222625392300B83A28 /* ReportMetadataStorageMock.swift */; };
AFCCCE242625392300B83A28 /* ReportMetadataStorageMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCCCE222625392300B83A28 /* ReportMetadataStorageMock.swift */; };
AFCCCE252625392300B83A28 /* ReportMetadataStorageMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCCCE222625392300B83A28 /* ReportMetadataStorageMock.swift */; };
B50C5A8028E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50C5A7F28E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift */; };
B50C5A8128E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50C5A7F28E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift */; };
B50C5A8228E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B50C5A7F28E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift */; };
B5E58C6928E1A843001F9650 /* BacktraceCrashLoopDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E58C6828E1A843001F9650 /* BacktraceCrashLoopDetector.swift */; };
B5E58C6A28E1A843001F9650 /* BacktraceCrashLoopDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E58C6828E1A843001F9650 /* BacktraceCrashLoopDetector.swift */; };
B5E58C6B28E1A843001F9650 /* BacktraceCrashLoopDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E58C6828E1A843001F9650 /* BacktraceCrashLoopDetector.swift */; };
DAF627C0CA0FE995B581C33B /* Pods_Backtrace_tvOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD097A22120C3DCE08382BA5 /* Pods_Backtrace_tvOSTests.framework */; };
F21211A5222348AC000B3692 /* BacktraceCrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F21211A4222348AC000B3692 /* BacktraceCrashReporter.swift */; };
F21211A6222348AC000B3692 /* BacktraceCrashReporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F21211A4222348AC000B3692 /* BacktraceCrashReporter.swift */; };
Expand Down Expand Up @@ -449,6 +455,8 @@
AF7833BA2613D1B400530A10 /* AttachmentsStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentsStorage.swift; sourceTree = "<group>"; };
AFCCCE222625392300B83A28 /* ReportMetadataStorageMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportMetadataStorageMock.swift; sourceTree = "<group>"; };
AFCCCEC126260BC400B83A28 /* AttachmentBookmarkHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentBookmarkHandler.swift; sourceTree = "<group>"; };
B50C5A7F28E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BacktraceCrashLoopDetectorTests.swift; sourceTree = "<group>"; };
B5E58C6828E1A843001F9650 /* BacktraceCrashLoopDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BacktraceCrashLoopDetector.swift; sourceTree = "<group>"; };
B7B445FAC6841A65683F35E9 /* Pods-Backtrace-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Backtrace-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-Backtrace-tvOS/Pods-Backtrace-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
BECDC44D2F82A1F1FD5CD9D1 /* Pods_Backtrace_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Backtrace_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BFAF826CD2E1314532AD4FF6 /* Pods_Example_iOS_ObjC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example_iOS_ObjC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -718,6 +726,14 @@
path = Model;
sourceTree = "<group>";
};
B51F3E33290173650096E21A /* CrashLoopDetector */ = {
isa = PBXGroup;
children = (
B5E58C6828E1A843001F9650 /* BacktraceCrashLoopDetector.swift */,
);
path = CrashLoopDetector;
sourceTree = "<group>";
};
E1CB76ADFD3A1D9326B4E46D /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -813,6 +829,7 @@
A24A4B4928B595D8004F5052 /* BacktraceWatcherTests.swift */,
A24A4B5528B595D8004F5052 /* CrashReporterTests.swift */,
A24A4B5228B595D8004F5052 /* DispatcherTests.swift */,
B50C5A7F28E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift */,
F21DD3AF2255E99E00404CC3 /* Resources */,
F2AB6370224647F000939BC9 /* Helpers */,
F2AB636F224647DE00939BC9 /* Mocks */,
Expand Down Expand Up @@ -932,11 +949,11 @@
F2AFB59622274E1400AAA1D7 /* Public */ = {
isa = PBXGroup;
children = (
F22EB87621BBD36800DEE94E /* BacktraceClient.swift */,
6E45A3A6273095E500DB0BAC /* BacktraceMetricsSettings.swift */,
F29CD79321FDD5E900216C59 /* BacktraceClientDelegate.swift */,
F2AFB59922274E5400AAA1D7 /* BacktraceClientCustomizing.swift */,
F240532021C578AA00FC9394 /* BacktraceLogger.swift */,
F22EB87621BBD36800DEE94E /* BacktraceClient.swift */,
F25F9E9921EE84EA00236E04 /* BacktraceResult.swift */,
28AC773B21FA5A8400FED661 /* BacktraceDatabaseSettings.swift */,
F2D7122021F10C45002D2A26 /* BacktraceClientConfiguration.swift */,
Expand Down Expand Up @@ -969,6 +986,7 @@
F2AFB5A022274F1000AAA1D7 /* Internal */ = {
isa = PBXGroup;
children = (
B51F3E33290173650096E21A /* CrashLoopDetector */,
F2A81B4C23EF1730007C63E4 /* BacktraceApiProtocol.swift */,
F21D302A224A18D50013B5D7 /* Store.swift */,
F2AB636C22442B5100939BC9 /* DebuggerChecker.swift */,
Expand Down Expand Up @@ -1917,6 +1935,7 @@
AF5AB0BB262622730003698C /* AttachmentBookmarkHandler.swift in Sources */,
28F95BD022526064003936E0 /* BacktraceClient.swift in Sources */,
28F95BCD2252605A003936E0 /* BacktraceClientDelegate.swift in Sources */,
B5E58C6B28E1A843001F9650 /* BacktraceCrashLoopDetector.swift in Sources */,
28F95BC92252602C003936E0 /* Foundation+Extensions.swift in Sources */,
28F95BD622526078003936E0 /* DebuggerChecker.swift in Sources */,
28A65308285D1BF700306631 /* Date+Extensions.swift in Sources */,
Expand Down Expand Up @@ -1981,6 +2000,7 @@
A24A4B7728B595D9004F5052 /* DispatcherTests.swift in Sources */,
A24A4B6828B595D9004F5052 /* BacktraceOomWatcherTests.swift in Sources */,
F21DD39F2255666F00404CC3 /* WatcherRepositoryMock.swift in Sources */,
B50C5A8228E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift in Sources */,
A24A4B5C28B595D9004F5052 /* BacktraceWatcherTests.swift in Sources */,
A24A4B7A28B595D9004F5052 /* AttributesTests.swift in Sources */,
A24A4B6E28B595D9004F5052 /* AttachmentTests.swift in Sources */,
Expand Down Expand Up @@ -2021,6 +2041,7 @@
F2AFB59E22274EDA00AAA1D7 /* Dispatching.swift in Sources */,
2846E1F9222F1DE60035F98C /* NetworkReachability.swift in Sources */,
F21211A9222348C2000B3692 /* SignalContext.swift in Sources */,
B5E58C6A28E1A843001F9650 /* BacktraceCrashLoopDetector.swift in Sources */,
F2AB639D22479A3600939BC9 /* Model.xcdatamodeld in Sources */,
F259E4E3222AD9F100F282C7 /* AttributesProvider.swift in Sources */,
F266B83321C77B9600D14417 /* BacktraceClient.swift in Sources */,
Expand Down Expand Up @@ -2075,6 +2096,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B50C5A8128E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift in Sources */,
A24A4B7C28B595D9004F5052 /* AttachmentStorageTests.swift in Sources */,
F2AB637F22464FD500939BC9 /* DebuggerCheckerMock.swift in Sources */,
A24A4B7328B595D9004F5052 /* BacktraceApiTests.swift in Sources */,
Expand Down Expand Up @@ -2150,6 +2172,7 @@
6E896E912727627C0005CDF2 /* BacktraceMetrics.swift in Sources */,
6EB713EC275ED4EF0075D1C1 /* SummedEventsPayload.swift in Sources */,
28A652F2285C6C1500306631 /* BacktraceBreadcrumbsLogManager.swift in Sources */,
B5E58C6928E1A843001F9650 /* BacktraceCrashLoopDetector.swift in Sources */,
F28F164621E28441008E4B96 /* BacktraceReporter.swift in Sources */,
F21211A5222348AC000B3692 /* BacktraceCrashReporter.swift in Sources */,
0B6B4CFD25CD8331002DA15C /* BacktraceOomWatcher.swift in Sources */,
Expand Down Expand Up @@ -2185,6 +2208,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B50C5A8028E4740A004BB1DA /* BacktraceCrashLoopDetectorTests.swift in Sources */,
A24A4B7B28B595D9004F5052 /* AttachmentStorageTests.swift in Sources */,
F2AB637E22464FD500939BC9 /* DebuggerCheckerMock.swift in Sources */,
A24A4B7228B595D9004F5052 /* BacktraceApiTests.swift in Sources */,
Expand Down Expand Up @@ -2381,7 +2405,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.7.4-beta2;
MARKETING_VERSION = "1.7.4-beta2";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -2460,7 +2484,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.7.4-beta2;
MARKETING_VERSION = "1.7.4-beta2";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = Backtrace.io.Backtrace;
Expand Down Expand Up @@ -2692,7 +2716,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.7.4-beta2;
MARKETING_VERSION = "1.7.4-beta2";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -2774,7 +2798,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.7.4-beta2;
MARKETING_VERSION = "1.7.4-beta2";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = Backtrace.io.Backtrace;
Expand Down Expand Up @@ -2979,6 +3003,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -3002,6 +3027,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -3058,6 +3084,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
ENABLE_NS_ASSERTIONS = NO;
Expand All @@ -3075,6 +3102,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = apptailors.co.backtrace.swift.tvos.example;
Expand Down Expand Up @@ -3185,7 +3213,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.7.4-beta2;
MARKETING_VERSION = "1.7.4-beta2";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -3269,7 +3297,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.7.4-beta2;
MARKETING_VERSION = "1.7.4-beta2";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = Backtrace.io.Backtrace;
Expand Down Expand Up @@ -3483,6 +3511,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = LZGFT5UUA9;
ENABLE_BITCODE = NO;
Expand All @@ -3507,6 +3536,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -3562,6 +3592,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = LZGFT5UUA9;
ENABLE_BITCODE = NO;
Expand All @@ -3580,6 +3611,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = apptailors.co.backtrace.swift.ios.example;
Expand Down
27 changes: 15 additions & 12 deletions Examples/Example-iOS-ObjC/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ @interface AppDelegate () <BacktraceClientDelegate>
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


/* Enable crash loop detector.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better if we describe the story what someone want to use it?

You can pass crashes count threshold (maximum amount of launching events to evaluate) here.
If threshold is not specified or you pass 0 - default value '5' will be used.
*/
[BacktraceClient enableCrashLoopDetection: 0];

if([BacktraceClient isSafeModeRequired]) {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
[BacktraceClient resetCrashLoopDetection];
// TODO: Perform any custom checks if necessary and decide if Backtrace should be launched
return NO;
}

NSArray *paths = @[[[NSBundle mainBundle] pathForResource: @"test" ofType: @"txt"]];
NSString *fileName = @"myCustomFile.txt";
NSURL *libraryUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory
Expand All @@ -32,18 +47,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
BacktraceClient.shared.attributes = @{@"foo": @"bar", @"testing": @YES};
BacktraceClient.shared.attachments = [NSArray arrayWithObjects:fileUrl, nil];

// sending NSException
@try {
NSArray *array = @[];
array[1]; // will throw exception
} @catch (NSException *exception) {
[[BacktraceClient shared] sendWithAttachmentPaths: [NSArray init] completion: ^(BacktraceResult * _Nonnull result) {
NSLog(@"%@", result);
}];
} @finally {

}

//sending NSError
[[BacktraceClient shared] sendWithAttachmentPaths: paths completion: ^(BacktraceResult * _Nonnull result) {
NSLog(@"%@", result);
Expand Down
5 changes: 5 additions & 0 deletions Examples/Example-iOS-ObjC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
wastedMemory = [[NSMutableData alloc] init];

NSString * text = [NSString stringWithFormat: @"BadEvents: %ld\nIs Safe to Launch: %s",
[BacktraceClient consecutiveCrashesCount],
[BacktraceClient isInSafeMode] ? "FALSE" : "TRUE" ];
[_textView setText: text];
}

- (IBAction) outOfMemoryReportAction: (id) sender {
Expand Down
14 changes: 14 additions & 0 deletions Examples/Example-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

/* Enable crash loop detector.
You can pass crashes count threshold (maximum amount of launching events to evaluate) here.
If threshold is not specified or you pass 0 - default value '5' will be used.
*/
BacktraceClient.enableCrashLoopDetection()

if BacktraceClient.isSafeModeRequired() {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
BacktraceClient.resetCrashLoopDetection()
// Perform any custom checks if necessary and decide if Backtrace should be launched
return true
}

let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: Keys.backtraceUrl as String)!,
token: Keys.backtraceToken as String)

Expand Down
2 changes: 2 additions & 0 deletions Examples/Example-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

textView.text = "BadEvents: " + BacktraceClient.consecutiveCrashesCount().description
+ "\nIs Safe to Launch: " + (BacktraceClient.isInSafeMode() ? "FALSE" : "TRUE")
}

@IBAction func outOfMemoryReportAction(_ sender: Any) {
Expand Down
10 changes: 10 additions & 0 deletions Examples/Example-macOS-ObjC/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

// Enable crash loop detector, pass 0 to use default threshold value '5'
[BacktraceClient enableCrashLoopDetection: 0];

if([BacktraceClient isSafeModeRequired]) {
// When crash loop is detected we need to reset crash loop counter to restart crash loop detection from scratch
[BacktraceClient resetCrashLoopDetection];
// TODO: Perform any custom checks if necessary and decide if Backtrace should be launched
return;
}

BacktraceCredentials *credentials = [[BacktraceCredentials alloc]
initWithSubmissionUrl: [NSURL URLWithString: Keys.backtraceSubmissionUrl]];
BacktraceDatabaseSettings *backtraceDatabaseSettings = [[BacktraceDatabaseSettings alloc] init];
Expand Down
Loading