-
-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathRNSentry+fetchNativeStack.m
More file actions
88 lines (74 loc) · 3.44 KB
/
RNSentry+fetchNativeStack.m
File metadata and controls
88 lines (74 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#import "RNSentry+formatters.h"
#import "RNSentry.h"
#import "RNSentryBreadcrumb.h"
#import "RNSentryId.h"
#import <Sentry/PrivateSentrySDKOnly.h>
@import Sentry;
// This method was moved to a new category so we can use `@import Sentry` to use Sentry's Swift
// classes
@implementation RNSentry (fetchNativeStack)
- (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAddr
symbolicate:(SymbolicateCallbackType)symbolicate
{
BOOL shouldSymbolicateLocally = [SentrySDKInternal.options debug];
NSString *appPackageName = [[NSBundle mainBundle] executablePath];
NSMutableSet<NSString *> *_Nonnull imagesAddrToRetrieveDebugMetaImages =
[[NSMutableSet alloc] init];
NSMutableArray<NSDictionary<NSString *, id> *> *_Nonnull serializedFrames =
[[NSMutableArray alloc] init];
for (NSNumber *addr in instructionsAddr) {
SentryBinaryImageInfo *_Nullable image = [[[SentryDependencyContainer sharedInstance]
binaryImageCache] imageByAddress:[addr unsignedLongLongValue]];
if (image != nil) {
NSString *imageAddr = sentry_formatHexAddressUInt64([image address]);
[imagesAddrToRetrieveDebugMetaImages addObject:imageAddr];
NSDictionary<NSString *, id> *_Nonnull nativeFrame = @{
@"platform" : @"cocoa",
@"instruction_addr" : sentry_formatHexAddress(addr),
@"package" : [image name],
@"image_addr" : imageAddr,
@"in_app" : [NSNumber numberWithBool:[appPackageName isEqualToString:[image name]]],
};
if (shouldSymbolicateLocally) {
Dl_info symbolsBuffer;
bool symbols_succeed = false;
symbols_succeed
= symbolicate((void *)[addr unsignedLongLongValue], &symbolsBuffer) != 0;
if (symbols_succeed) {
NSMutableDictionary<NSString *, id> *_Nonnull symbolicated
= nativeFrame.mutableCopy;
symbolicated[@"symbol_addr"]
= sentry_formatHexAddressUInt64((uintptr_t)symbolsBuffer.dli_saddr);
symbolicated[@"function"] = [NSString stringWithCString:symbolsBuffer.dli_sname
encoding:NSUTF8StringEncoding];
nativeFrame = symbolicated;
}
}
[serializedFrames addObject:nativeFrame];
} else {
[serializedFrames addObject:@{
@"platform" : @"cocoa",
@"instruction_addr" : sentry_formatHexAddress(addr),
}];
}
}
if (shouldSymbolicateLocally) {
return @{
@"frames" : serializedFrames,
};
} else {
NSMutableArray<NSDictionary<NSString *, id> *> *_Nonnull serializedDebugMetaImages =
[[NSMutableArray alloc] init];
NSArray<SentryDebugMeta *> *debugMetaImages =
[[[SentryDependencyContainer sharedInstance] debugImageProvider]
getDebugImagesForImageAddressesFromCache:imagesAddrToRetrieveDebugMetaImages];
for (SentryDebugMeta *debugImage in debugMetaImages) {
[serializedDebugMetaImages addObject:[debugImage serialize]];
}
return @{
@"frames" : serializedFrames,
@"debugMetaImages" : serializedDebugMetaImages,
};
}
}
@end