diff --git a/Source/BugsnagKeys.h b/Source/BugsnagKeys.h index 5af422432..f63e23880 100644 --- a/Source/BugsnagKeys.h +++ b/Source/BugsnagKeys.h @@ -52,6 +52,16 @@ static NSString *const BSGKeyIsLR = @"isLR"; static NSString *const BSGKeyMachoFile = @"machoFile"; static NSString *const BSGKeyMachoUUID = @"machoUUID"; static NSString *const BSGKeyMachoVMAddress = @"machoVMAddress"; +static NSString *const BSGKeyImageAddress = @"image_addr"; +static NSString *const BSGKeyImageVmAddress = @"image_vmaddr"; +static NSString *const BSGKeyInstructionAddress = @"instruction_addr"; +static NSString *const BSGKeySymbolAddress = @"symbol_addr"; +static NSString *const BSGKeyObjectAddress = @"object_addr"; +static NSString *const BSGKeyFrameAddress = @"frameAddress"; +static NSString *const BSGKeyObjectName = @"object_name"; +static NSString *const BSGKeyUuid = @"uuid"; +static NSString *const BSGKeyMethod = @"method"; +static NSString *const BSGKeySymbolName = @"symbol_name"; static NSString *const BSGKeyCppException = @"cpp_exception"; static NSString *const BSGKeyExceptionName = @"exception_name"; static NSString *const BSGKeyMach = @"mach"; diff --git a/Source/BugsnagStackframe.m b/Source/BugsnagStackframe.m index 123c7d643..31d612f44 100644 --- a/Source/BugsnagStackframe.m +++ b/Source/BugsnagStackframe.m @@ -14,7 +14,7 @@ @implementation BugsnagStackframe + (NSDictionary *_Nullable)findImageAddr:(unsigned long)addr inImages:(NSArray *)images { for (NSDictionary *image in images) { - if ([(NSNumber *)image[@"image_addr"] unsignedLongValue] == addr) { + if ([(NSNumber *)image[BSGKeyImageAddress] unsignedLongValue] == addr) { return image; } } @@ -24,33 +24,33 @@ + (NSDictionary *_Nullable)findImageAddr:(unsigned long)addr inImages:(NSArray * + (BugsnagStackframe *)frameFromDict:(NSDictionary *)dict withImages:(NSArray *)binaryImages { BugsnagStackframe *frame = [BugsnagStackframe new]; - frame.frameAddress = [dict[@"instruction_addr"] unsignedLongValue]; - frame.symbolAddress = [dict[@"symbol_addr"] unsignedLongValue]; - frame.machoLoadAddress = [dict[@"object_addr"] unsignedLongValue]; - frame.machoFile = dict[@"object_name"]; - frame.method = dict[@"symbol_name"]; + frame.frameAddress = [dict[BSGKeyInstructionAddress] unsignedLongValue]; + frame.symbolAddress = [dict[BSGKeySymbolAddress] unsignedLongValue]; + frame.machoLoadAddress = [dict[BSGKeyObjectAddress] unsignedLongValue]; + frame.machoFile = dict[BSGKeyObjectName]; + frame.method = dict[BSGKeySymbolName]; frame.isPc = [dict[BSGKeyIsPC] boolValue]; frame.isLr = [dict[BSGKeyIsLR] boolValue]; NSDictionary *image = [self findImageAddr:frame.machoLoadAddress inImages:binaryImages]; if (image != nil) { - frame.machoUuid = image[@"uuid"]; - frame.machoVmAddress = [image[@"image_vmaddr"] unsignedLongValue]; + frame.machoUuid = image[BSGKeyUuid]; + frame.machoVmAddress = [image[BSGKeyImageVmAddress] unsignedLongValue]; return frame; } else { // invalid frame, skip return nil; } } -- (NSDictionary *)toDict { +- (NSDictionary *)toDictionary { NSMutableDictionary *dict = [NSMutableDictionary new]; BSGDictInsertIfNotNil(dict, self.machoFile, BSGKeyMachoFile); - BSGDictInsertIfNotNil(dict, self.method, @"method"); + BSGDictInsertIfNotNil(dict, self.method, BSGKeyMethod); BSGDictInsertIfNotNil(dict, self.machoUuid, BSGKeyMachoUUID); NSString *frameAddr = [NSString stringWithFormat:BSGKeyFrameAddrFormat, self.frameAddress]; - BSGDictSetSafeObject(dict, frameAddr, @"frameAddress"); + BSGDictSetSafeObject(dict, frameAddr, BSGKeyFrameAddress); NSString *symbolAddr = [NSString stringWithFormat:BSGKeyFrameAddrFormat, self.symbolAddress]; BSGDictSetSafeObject(dict, symbolAddr, BSGKeySymbolAddr); diff --git a/Source/BugsnagStacktrace.h b/Source/BugsnagStacktrace.h index e7446f49e..d789498a1 100644 --- a/Source/BugsnagStacktrace.h +++ b/Source/BugsnagStacktrace.h @@ -20,6 +20,4 @@ - (NSArray *)toArray; -@property NSMutableArray *trace; - @end diff --git a/Source/BugsnagStacktrace.m b/Source/BugsnagStacktrace.m index 836b1c6fd..47167d6af 100644 --- a/Source/BugsnagStacktrace.m +++ b/Source/BugsnagStacktrace.m @@ -8,13 +8,15 @@ #import "BugsnagStacktrace.h" #import "BugsnagStackframe.h" -#import "BugsnagCollections.h" -#import "BugsnagKeys.h" @interface BugsnagStackframe () + (BugsnagStackframe *)frameFromDict:(NSDictionary *)dict withImages:(NSArray *)binaryImages; -- (NSDictionary *)toDict; +- (NSDictionary *)toDictionary; +@end + +@interface BugsnagStacktrace () +@property NSMutableArray *trace; @end @implementation BugsnagStacktrace @@ -38,7 +40,7 @@ - (instancetype)initWithTrace:(NSArray *)trace - (NSArray *)toArray { NSMutableArray *array = [NSMutableArray new]; for (BugsnagStackframe *frame in self.trace) { - [array addObject:[frame toDict]]; + [array addObject:[frame toDictionary]]; } return array; } diff --git a/Tests/BugsnagStackframeTest.m b/Tests/BugsnagStackframeTest.m index 0cc22c1a8..0f0aa6d27 100644 --- a/Tests/BugsnagStackframeTest.m +++ b/Tests/BugsnagStackframeTest.m @@ -10,7 +10,7 @@ #import "BugsnagStackframe.h" @interface BugsnagStackframe () -- (NSDictionary *)toDict; +- (NSDictionary *)toDictionary; + (BugsnagStackframe *)frameFromDict:(NSDictionary *)dict withImages:(NSArray *)binaryImages; @end @@ -52,7 +52,7 @@ - (void)testStackframeFromDict { - (void)testStackframeToDict { BugsnagStackframe *frame = [BugsnagStackframe frameFromDict:self.frameDict withImages:self.binaryImages]; - NSDictionary *dict = [frame toDict]; + NSDictionary *dict = [frame toDictionary]; XCTAssertEqualObjects(@"-[BugsnagClient notify:handledState:block:]", dict[@"method"]); XCTAssertEqualObjects(@"/Users/foo/Bugsnag.h", dict[@"machoFile"]); XCTAssertEqualObjects(@"B6D80CB5-A772-3D2F-B5A1-A3A137B8B58F", dict[@"machoUUID"]); diff --git a/Tests/BugsnagStacktraceTest.m b/Tests/BugsnagStacktraceTest.m index 8a74a14c4..93e025428 100644 --- a/Tests/BugsnagStacktraceTest.m +++ b/Tests/BugsnagStacktraceTest.m @@ -15,6 +15,10 @@ @interface BugsnagStacktraceTest : XCTestCase @property NSArray *binaryImages; @end +@interface BugsnagStacktrace () +@property NSMutableArray *trace; +@end + @implementation BugsnagStacktraceTest - (void)setUp {