Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Apr 8, 2020
1 parent 0f49808 commit c50dbaa
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
10 changes: 10 additions & 0 deletions Source/BugsnagKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
22 changes: 11 additions & 11 deletions Source/BugsnagStackframe.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions Source/BugsnagStacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

- (NSArray *)toArray;

@property NSMutableArray<BugsnagStackframe *> *trace;

@end
10 changes: 6 additions & 4 deletions Source/BugsnagStacktrace.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<BugsnagStackframe *> *trace;
@end

@implementation BugsnagStacktrace
Expand All @@ -38,7 +40,7 @@ - (instancetype)initWithTrace:(NSArray<NSDictionary *> *)trace
- (NSArray *)toArray {
NSMutableArray *array = [NSMutableArray new];
for (BugsnagStackframe *frame in self.trace) {
[array addObject:[frame toDict]];
[array addObject:[frame toDictionary]];
}
return array;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagStackframeTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "BugsnagStackframe.h"

@interface BugsnagStackframe ()
- (NSDictionary *)toDict;
- (NSDictionary *)toDictionary;
+ (BugsnagStackframe *)frameFromDict:(NSDictionary *)dict withImages:(NSArray *)binaryImages;
@end

Expand Down Expand Up @@ -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"]);
Expand Down
4 changes: 4 additions & 0 deletions Tests/BugsnagStacktraceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ @interface BugsnagStacktraceTest : XCTestCase
@property NSArray *binaryImages;
@end

@interface BugsnagStacktrace ()
@property NSMutableArray<BugsnagStackframe *> *trace;
@end

@implementation BugsnagStacktraceTest

- (void)setUp {
Expand Down

0 comments on commit c50dbaa

Please sign in to comment.