Skip to content

Commit

Permalink
Upgrade bugsnag-cocoa to v5.15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench authored and kattrali committed Jan 26, 2018
1 parent b1003e1 commit cf06208
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cocoa/vendor/bugsnag-cocoa/Source/BugsnagCrashReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,6 @@ __deprecated_msg("Use toJson: instead.");
/**
* Returns the enhanced error message for the thread, or nil if none exists.
*/
- (NSString *_Nullable)enhancedErrorMessageForThread:(NSDictionary *_Nullable)thread;
- (NSString *_Nullable)enhancedErrorMessageForThread:(NSDictionary *_Nullable)thread __deprecated;

@end
112 changes: 70 additions & 42 deletions cocoa/vendor/bugsnag-cocoa/Source/BugsnagCrashReport.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ @interface NSDictionary (BSGKSMerge)
- (NSDictionary *)BSG_mergedInto:(NSDictionary *)dest;
@end

@interface RegisterErrorData : NSObject
@property (nonatomic, strong) NSString *errorClass;
@property (nonatomic, strong) NSString *errorMessage;
+ (instancetype)errorDataFromThreads:(NSArray *)threads;
- (instancetype)initWithClass:(NSString *_Nonnull)errorClass message:(NSString *_Nonnull)errorMessage NS_DESIGNATED_INITIALIZER;
@end

@interface BugsnagCrashReport ()

/**
Expand Down Expand Up @@ -217,10 +224,16 @@ - (instancetype)initWithKSReport:(NSDictionary *)report {

_error = [report valueForKeyPath:@"crash.error"];
_errorType = _error[BSGKeyType];
_errorClass = BSGParseErrorClass(_error, _errorType);
_errorMessage = BSGParseErrorMessage(report, _error, _errorType);
_binaryImages = report[@"binary_images"];
_threads = [report valueForKeyPath:@"crash.threads"];
RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:_threads];
if (data) {
_errorClass = data.errorClass;
_errorMessage = data.errorMessage;
} else {
_errorClass = BSGParseErrorClass(_error, _errorType);
_errorMessage = BSGParseErrorMessage(report, _error, _errorType);
}
_binaryImages = report[@"binary_images"];
_breadcrumbs = BSGParseBreadcrumbs(report);
_severity = BSGParseSeverity(
[report valueForKeyPath:@"user.state.crash.severity"]);
Expand Down Expand Up @@ -542,12 +555,6 @@ - (NSArray *)serializeThreadsWithException:(NSMutableDictionary *)exception {
BOOL isCrashedThread = [thread[@"crashed"] boolValue];

if (isCrashedThread) {
NSString *errMsg = [self enhancedErrorMessageForThread:thread];

if (errMsg) { // use enhanced error message (currently swift assertions)
BSGDictInsertIfNotNil(exception, errMsg, BSGKeyMessage);
}

NSUInteger seen = 0;
NSMutableArray *stacktrace = [NSMutableArray array];

Expand Down Expand Up @@ -593,41 +600,47 @@ - (NSArray *)serializeThreadsWithException:(NSMutableDictionary *)exception {
return bugsnagThreads;
}

/**
* Returns the enhanced error message for the thread, or nil if none exists.
*
* This relies very heavily on heuristics rather than any documented APIs.
*/
- (NSString *)enhancedErrorMessageForThread:(NSDictionary *)thread {
NSDictionary *notableAddresses = thread[@"notable_addresses"];
NSMutableArray *msgBuffer = [NSMutableArray new];
BOOL hasReservedWord = NO;

if (notableAddresses) {
- (NSString *_Nullable)enhancedErrorMessageForThread:(NSDictionary *_Nullable)thread {
return [self errorMessage];
}

@end

@implementation RegisterErrorData
+ (instancetype)errorDataFromThreads:(NSArray *)threads {
for (NSDictionary *thread in threads) {
if (![thread[@"crashed"] boolValue]) {
continue;
}
NSDictionary *notableAddresses = thread[@"notable_addresses"];
NSMutableArray *interestingValues = [NSMutableArray new];
NSString *reservedWord = nil;

for (NSString *key in notableAddresses) {
if (![key hasPrefix:@"stack"]) { // skip stack frames, only use register values
NSDictionary *data = notableAddresses[key];
NSString *contentValue = data[@"value"];

hasReservedWord = hasReservedWord || [self isReservedWord:contentValue];

if ([key hasPrefix:@"stack"]) { // skip stack frames, only use register values
continue;
}
NSDictionary *data = notableAddresses[key];
if (![@"string" isEqualToString:data[BSGKeyType]]) {
continue;
}
NSString *contentValue = data[@"value"];

if ([self isReservedWord:contentValue]) {
reservedWord = contentValue;
} else if (!([[contentValue componentsSeparatedByString:@"/"] count] > 2)) {
// must be a string that isn't a reserved word and isn't a filepath
if ([@"string" isEqualToString:data[BSGKeyType]]
&& ![self isReservedWord:contentValue]
&& !([[contentValue componentsSeparatedByString:@"/"] count] > 2)) {

[msgBuffer addObject:contentValue];
}
[interestingValues addObject:contentValue];
}
}
[msgBuffer sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}

if (hasReservedWord && [msgBuffer count] > 0) { // needs to have a reserved word used + a message
return [msgBuffer componentsJoinedByString:@" | "];
} else {
return nil;

[interestingValues sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

NSString *message = [interestingValues componentsJoinedByString:@" | "];
return [[RegisterErrorData alloc] initWithClass:reservedWord
message:message];
}
return nil;
}

/**
Expand All @@ -637,9 +650,24 @@ - (NSString *)enhancedErrorMessageForThread:(NSDictionary *)thread {
*
* For assert, "assertion failed" will be in one of the registers.
*/
- (BOOL)isReservedWord:(NSString *)contentValue {
return [@"assertion failed" isEqualToString:contentValue]
|| [@"fatal error" isEqualToString:contentValue];
+ (BOOL)isReservedWord:(NSString *)contentValue {
return [@"assertion failed" caseInsensitiveCompare:contentValue] == NSOrderedSame
|| [@"fatal error" caseInsensitiveCompare:contentValue] == NSOrderedSame
|| [@"precondition failed" caseInsensitiveCompare:contentValue] == NSOrderedSame;
}

- (instancetype)init {
return [self initWithClass:@"Unknown" message:@"<unset>"];
}

- (instancetype)initWithClass:(NSString *)errorClass message:(NSString *)errorMessage {
if (errorClass.length == 0) {
return nil;
}
if (self = [super init]) {
_errorClass = errorClass;
_errorMessage = errorMessage;
}
return self;
}
@end
3 changes: 2 additions & 1 deletion cocoa/vendor/bugsnag-cocoa/Source/BugsnagFileStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@
+ (NSString *)findReportStorePath:(NSString *)customDirectory
bundleName:(NSString *)bundleName;

@end
- (NSString *)fileIdFromFilename:(NSString *)filename;
@end
3 changes: 1 addition & 2 deletions cocoa/vendor/bugsnag-cocoa/Source/BugsnagNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#import <AppKit/AppKit.h>
#endif

NSString *const NOTIFIER_VERSION = @"5.15.0";
NSString *const NOTIFIER_VERSION = @"5.15.3";
NSString *const NOTIFIER_URL = @"https://github.com/bugsnag/bugsnag-cocoa";
NSString *const BSTabCrash = @"crash";
NSString *const BSAttributeDepth = @"depth";
Expand Down Expand Up @@ -410,7 +410,6 @@ - (void)willEnterBackground:(id)sender {

- (void)sessionTick:(id)sender {
[self.sessionTracker send];
NSLog(@"Session Tick!");
}

- (void)flushPendingReports {
Expand Down
1 change: 1 addition & 0 deletions cocoa/vendor/bugsnag-cocoa/Source/BugsnagSink.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ - (void)filterReports:(NSArray *)reports
- (NSDictionary *)getBodyFromReports:(NSArray *)reports {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
BSGDictSetSafeObject(data, [Bugsnag notifier].details, BSGKeyNotifier);
BSGDictSetSafeObject(data, [Bugsnag notifier].configuration.apiKey, BSGKeyApiKey);

NSMutableArray *formatted =
[[NSMutableArray alloc] initWithCapacity:[reports count]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
typedef enum {
BSG_CPUFamilyUnknown,
BSG_CPUFamilyArm,
BSG_CPUFamilyArm64,
BSG_CPUFamilyX86,
BSG_CPUFamilyX86_64
} BSG_CPUFamily;
Expand Down Expand Up @@ -170,15 +171,17 @@ - (NSDictionary *)errorReport:(NSDictionary *)report {
- (BSG_CPUFamily)cpuFamily:(NSDictionary *)report {
NSDictionary *system = [self systemReport:report];
NSString *cpuArch = system[@BSG_KSSystemField_CPUArch];
if ([cpuArch isEqualToString:@"arm64"]) {
return BSG_CPUFamilyArm64;
}
if ([cpuArch rangeOfString:@"arm"].location == 0) {
return BSG_CPUFamilyArm;
}
if ([cpuArch rangeOfString:@"i"].location == 0 &&
[cpuArch rangeOfString:@"86"].location == 2) {
return BSG_CPUFamilyX86;
}
if ([cpuArch rangeOfString:@"x86_64" options:NSCaseInsensitiveSearch]
.location != NSNotFound) {
if ([@[@"x86_64", @"x86"] containsObject:cpuArch]) {
return BSG_CPUFamilyX86_64;
}
return BSG_CPUFamilyUnknown;
Expand All @@ -199,6 +202,18 @@ - (NSString *)registerNameForFamily:(BSG_CPUFamily)family
return @"r3";
}
}
case BSG_CPUFamilyArm64: {
switch (index) {
case 0:
return @"x0";
case 1:
return @"x1";
case 2:
return @"x2";
case 3:
return @"x3";
}
}
case BSG_CPUFamilyX86: {
switch (index) {
case 0:
Expand Down Expand Up @@ -367,10 +382,13 @@ - (BSG_KSCrashDoctorFunctionCall *)lastFunctionCall:(NSDictionary *)report {
BSG_CPUFamily family = [self cpuFamily:report];
NSDictionary *registers =
[self basicRegistersFromThreadReport:crashedThread];
NSArray *regNames = @[[self registerNameForFamily:family paramIndex:0],
[self registerNameForFamily:family paramIndex:1],
[self registerNameForFamily:family paramIndex:2],
[self registerNameForFamily:family paramIndex:3]];
NSMutableArray *regNames = [NSMutableArray arrayWithCapacity:4];
for (int paramIndex = 0; paramIndex <= 3; paramIndex++) {
NSString *regName = [self registerNameForFamily:family paramIndex:paramIndex];
if (regName.length > 0) {
[regNames addObject:regName];
}
}
NSMutableArray *params = [NSMutableArray arrayWithCapacity:4];
for (NSString *regName in regNames) {
BSG_KSCrashDoctorParam *param = [[BSG_KSCrashDoctorParam alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ + (NSString *)appUUID {
+ (NSString *)deviceAndAppHash {
NSMutableData *data = nil;

#if KSCRASH_HAS_UIDEVICE
#if BSG_KSCRASH_HAS_UIDEVICE
if ([[UIDevice currentDevice]
respondsToSelector:@selector(identifierForVendor)]) {
data = [NSMutableData dataWithLength:16];
Expand Down Expand Up @@ -393,7 +393,7 @@ + (NSDictionary *)systemInfo {
[sysInfo bsg_ksc_safeSetObject:@"simulator"
forKey:@BSG_KSSystemField_Model];
} else {
#if KSCRASH_HOST_OSX
#if BSG_KSCRASH_HOST_OSX
// MacOS has the machine in the model field, and no model
[sysInfo bsg_ksc_safeSetObject:[self stringSysctl:BSGKeyHwModel]
forKey:@BSG_KSSystemField_Machine];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct {
} BSG_CrashSentry;

static BSG_CrashSentry bsg_g_sentries[] = {
#if KSCRASH_HAS_MACH
#if BSG_KSCRASH_HAS_MACH
{
BSG_KSCrashTypeMachException, bsg_kscrashsentry_installMachHandler,
bsg_kscrashsentry_uninstallMachHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//#define BSG_KSLogger_LocalLevel TRACE
#include "BSG_KSLogger.h"

#if KSCRASH_HAS_MACH
#if BSG_KSCRASH_HAS_MACH

#include <pthread.h>

Expand Down
Loading

0 comments on commit cf06208

Please sign in to comment.