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

Add user-available post-crash handler #88

Merged
merged 1 commit into from
Feb 5, 2016
Merged
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
2 changes: 2 additions & 0 deletions Bugsnag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@
79659E151A0AFFF800280978 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
CODE_SIGN_IDENTITY = "Developer ID Application";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Developer ID Application";
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)";
Expand All @@ -994,6 +995,7 @@
79659E161A0AFFF800280978 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
CODE_SIGN_IDENTITY = "Developer ID Application";
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)";
};
Expand Down
2 changes: 2 additions & 0 deletions Source/Bugsnag/BugsnagConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import <Foundation/Foundation.h>

#import "BugsnagMetaData.h"
#import "KSCrashReportWriter.h"

@class BugsnagBreadcrumbs;

Expand All @@ -41,6 +42,7 @@
@property(nonatomic,readwrite,retain) BugsnagMetaData* metaData;
@property(nonatomic,readwrite,retain) BugsnagMetaData* config;
@property(nonatomic,readonly,strong) BugsnagBreadcrumbs* breadcrumbs;
@property(nonatomic) void (*onCrashHandler)(const KSCrashReportWriter* writer);

@property(nonatomic) BOOL autoNotify;

Expand Down
6 changes: 6 additions & 0 deletions Source/Bugsnag/BugsnagNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
char *configJSON;
// Contains notifier state, under "deviceState" and crash-specific information under "crash".
char *stateJSON;
// User onCrash handler
void (*onCrash)(const KSCrashReportWriter* writer);
};

static struct bugsnag_data_t g_bugsnag_data;
Expand All @@ -72,6 +74,9 @@ void BSSerializeDataCrashHandler(const KSCrashReportWriter *writer) {
if (g_bugsnag_data.stateJSON) {
writer->addJSONElement(writer, "state", g_bugsnag_data.stateJSON);
}
if (g_bugsnag_data.onCrash) {
g_bugsnag_data.onCrash(writer);
}
}

/**
Expand Down Expand Up @@ -117,6 +122,7 @@ - (id) initWithConfiguration:(BugsnagConfiguration*) initConfiguration {
[self metaDataChanged: self.configuration.metaData];
[self metaDataChanged: self.configuration.config];
[self metaDataChanged: self.state];
g_bugsnag_data.onCrash = self.configuration.onCrashHandler;
}

return self;
Expand Down
22 changes: 22 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ config.apiKey = @"YOUR_API_KEY_HERE";
[Bugsnag startBugsnagWithConfiguration: config];
```

### `onCrashHandler`

When a crash occurs in an application, information about the runtime state of
the application is collected and prepared to be sent to Bugsnag on the next
launch. The `onCrashHandler` hook allows you to execute additional code after
the crash report has been written.

**NOTE:** All functions called from a signal handler must be
[asynchronous-safe](https://www.securecoding.cert.org/confluence/display/c/SIG30-C.+Call+only+asynchronous-safe+functions+within+signal+handlers).
This excludes any Objective-C, in particular.

```objective-c
void HandleCrashedThread(const KSCrashReportWriter *writer) {
// possibly serialize data, call another crash reporter
}

// ...

BugsnagConfiguration *config = [[BugsnagConfiguration alloc] init];
config.onCrashHandler = &HandleCrashedThread;
```

### `releaseStage`

In order to distinguish between errors that occur in different stages of the
Expand Down