Skip to content

Commit

Permalink
update branch to use unity-specific kscrash enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Sep 28, 2017
1 parent c7c2dd3 commit f62ca6e
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Source/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,7 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";

+ (NSDateFormatter *_Nonnull)payloadDateFormatter;

+ (void)setSuspendThreadsForUserReported:(BOOL)suspendThreadsForUserReported;
+ (void)setReportWhenDebuggerIsAttached:(BOOL)reportWhenDebuggerIsAttached;

@end
9 changes: 9 additions & 0 deletions Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "BugsnagNotifier.h"
#import "BugsnagSink.h"
#import "BugsnagLogger.h"
#import "BSG_KSCrash.h"

static BugsnagNotifier* bsg_g_bugsnag_notifier = NULL;

Expand Down Expand Up @@ -186,6 +187,14 @@ + (NSDateFormatter *)payloadDateFormatter {
return formatter;
}

+ (void)setSuspendThreadsForUserReported:(BOOL)suspendThreadsForUserReported {
[[BSG_KSCrash sharedInstance] setSuspendThreadsForUserReported:suspendThreadsForUserReported];
}

+ (void)setReportWhenDebuggerIsAttached:(BOOL)reportWhenDebuggerIsAttached {
[[BSG_KSCrash sharedInstance] setReportWhenDebuggerIsAttached:reportWhenDebuggerIsAttached];
}

@end

//
Expand Down
15 changes: 15 additions & 0 deletions Source/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ typedef enum
stackTrace:(NSArray*) stackTrace
terminateProgram:(BOOL) terminateProgram;

/** If YES, user reported exceptions will suspend all threads during report generation.
* All threads will be suspended while generating a crash report for a user
* reported exception.
*
* Default: YES
*/
@property(nonatomic,readwrite,assign) BOOL suspendThreadsForUserReported;

/** If YES, reports will be sent even if a debugger is attached
*
* Default: NO
*/
@property(nonatomic,readwrite,assign) BOOL reportWhenDebuggerIsAttached;


@end

//! Project version number for BSG_KSCrashFramework.
Expand Down
14 changes: 14 additions & 0 deletions Source/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ @implementation BSG_KSCrash
@synthesize catchZombies = _catchZombies;
@synthesize doNotIntrospectClasses = _doNotIntrospectClasses;
@synthesize maxStoredReports = _maxStoredReports;
@synthesize suspendThreadsForUserReported = _suspendThreadsForUserReported;
@synthesize reportWhenDebuggerIsAttached = _reportWhenDebuggerIsAttached;


// ============================================================================
Expand Down Expand Up @@ -180,6 +182,8 @@ - (id) initWithReportFilesDirectory:(NSString *)reportFilesDirectory
self.introspectMemory = YES;
self.catchZombies = NO;
self.maxStoredReports = 5;
self.suspendThreadsForUserReported = YES;
self.reportWhenDebuggerIsAttached = NO;
}
return self;

Expand Down Expand Up @@ -260,6 +264,16 @@ - (void) setCatchZombies:(bool)catchZombies
bsg_kscrash_setCatchZombies(catchZombies);
}

- (void)setSuspendThreadsForUserReported:(BOOL) suspendThreadsForUserReported {
_suspendThreadsForUserReported = suspendThreadsForUserReported;
bsg_kscrash_setSuspendThreadsForUserReported(suspendThreadsForUserReported);
}

- (void)setReportWhenDebuggerIsAttached:(BOOL)reportWhenDebuggerIsAttached {
_reportWhenDebuggerIsAttached = reportWhenDebuggerIsAttached;
bsg_kscrash_setReportWhenDebuggerIsAttached(reportWhenDebuggerIsAttached);
}

- (void) setDoNotIntrospectClasses:(NSArray *)doNotIntrospectClasses
{
_doNotIntrospectClasses = doNotIntrospectClasses;
Expand Down
8 changes: 8 additions & 0 deletions Source/KSCrash/Source/KSCrash/Recording/BSG_KSCrashC.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,11 @@ void bsg_kscrash_reportUserException(const char* name,
stackTrace,
terminateProgram);
}

void bsg_kscrash_setSuspendThreadsForUserReported(bool suspendThreadsForUserReported) {
crashContext()->crash.suspendThreadsForUserReported = suspendThreadsForUserReported;
}

void bsg_kscrash_setReportWhenDebuggerIsAttached(bool reportWhenDebuggerIsAttached) {
crashContext()->crash.reportWhenDebuggerIsAttached = reportWhenDebuggerIsAttached;
}
16 changes: 16 additions & 0 deletions Source/KSCrash/Source/KSCrash/Recording/BSG_KSCrashC.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ void bsg_kscrash_reportUserException(const char* name,
const char* lineOfCode,
const char* stackTrace,
bool terminateProgram);


/** If YES, user reported exceptions will suspend all threads during report generation.
* All threads will be suspended while generating a crash report for a user
* reported exception.
*
* Default: YES
*/
void bsg_kscrash_setSuspendThreadsForUserReported(bool suspendThreadsForUserReported);

/** If YES, user reported exceptions even if a debugger is attached
*
* Default: NO
*/
void bsg_kscrash_setReportWhenDebuggerIsAttached(bool reportWhenDebuggerIsAttached);


#ifdef __cplusplus
}
Expand Down
22 changes: 14 additions & 8 deletions Source/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,10 @@ void bsg_kscrashreport_writeStandardReport(BSG_KSCrash_Context* const crashConte
crashContext->config.crashID,
crashContext->config.processName);

bsg_kscrw_i_writeBinaryImages(writer, BSG_KSCrashField_BinaryImages);
// Don't write the binary images for user reported crashes to improve performance
if (crashContext->crash.crashType != BSG_KSCrashTypeUserReported) { // TODO!!!
bsg_kscrw_i_writeBinaryImages(writer, BSG_KSCrashField_BinaryImages);
}

bsg_kscrw_i_writeProcessState(writer, BSG_KSCrashField_ProcessState);

Expand All @@ -2205,13 +2208,16 @@ void bsg_kscrashreport_writeStandardReport(BSG_KSCrash_Context* const crashConte

writer->beginObject(writer, BSG_KSCrashField_Crash);
{
bsg_kscrw_i_writeAllThreads(writer,
BSG_KSCrashField_Threads,
&crashContext->crash,
crashContext->config.introspectionRules.enabled,
crashContext->config.searchThreadNames,
crashContext->config.searchQueueNames);
bsg_kscrw_i_writeError(writer, BSG_KSCrashField_Error, &crashContext->crash);
// Don't write the threads for user reported crashes to improve performance
if (crashContext->crash.crashType != BSG_KSCrashTypeUserReported) { // TODO!!!
bsg_kscrw_i_writeAllThreads(writer,
BSG_KSCrashField_Threads,
&crashContext->crash,
crashContext->config.introspectionRules.enabled,
crashContext->config.searchThreadNames,
crashContext->config.searchQueueNames);
bsg_kscrw_i_writeError(writer, BSG_KSCrashField_Error, &crashContext->crash);
}
}
writer->endContainer(writer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ static bool bsg_g_threads_are_running = true;

BSG_KSCrashType bsg_kscrashsentry_installWithContext(BSG_KSCrash_SentryContext* context,
BSG_KSCrashType crashTypes,
void (*onCrash)(void))
{
if(bsg_ksmachisBeingTraced())
{
BSG_KSLOGBASIC_WARN("KSCrash: App is running in a debugger. Only user reported events will be handled.");
crashTypes = BSG_KSCrashTypeUserReported;
void (*onCrash)(void)) {
if (bsg_ksmachisBeingTraced()) {
if (context->reportWhenDebuggerIsAttached) {
BSG_KSLOG_WARN("KSCrash: App is running in a debugger. Crash handling is enabled via configuration.");
BSG_KSLOG_INFO("Installing handlers with context %p, crash types 0x%x.", context, crashTypes);
} else {
BSG_KSLOG_WARN("KSCrash: App is running in a debugger. Only user reported events will be handled.");
crashTypes = BSG_KSCrashTypeUserReported;
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ typedef struct BSG_KSCrash_SentryContext

/** Called by the crash handler when a crash is detected. */
void (*onCrash)(void);


/** If true, will suspend threads for user reported exceptions. */
bool suspendThreadsForUserReported;

/** If true, will send reports even if debugger is attached. */
bool reportWhenDebuggerIsAttached;

// Implementation defined values. Caller does not initialize these.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ void bsg_kscrashsentry_reportUserException(const char* name,
{
bsg_kscrashsentry_beginHandlingCrash(bsg_g_context);

BSG_KSLOG_DEBUG("Suspending all threads");
bsg_kscrashsentry_suspendThreads();
if (bsg_g_context->suspendThreadsForUserReported) {
BSG_KSLOG_DEBUG("Suspending all threads");
bsg_kscrashsentry_suspendThreads();
}

BSG_KSLOG_DEBUG("Fetching call stack.");
int callstackCount = 100;
Expand Down

0 comments on commit f62ca6e

Please sign in to comment.