Skip to content

Commit ea1768c

Browse files
authored
Merge 20a2fee into bd2462e
2 parents bd2462e + 20a2fee commit ea1768c

File tree

3 files changed

+104
-80
lines changed

3 files changed

+104
-80
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#import "RNSentry.h"
2+
#import "RNSentryBreadcrumb.h"
3+
#import "RNSentryId.h"
4+
#import <Sentry/PrivateSentrySDKOnly.h>
5+
#import <Sentry/SentryAppStartMeasurement.h>
6+
#import <Sentry/SentryBreadcrumb.h>
7+
#import <Sentry/SentryDebugImageProvider+HybridSDKs.h>
8+
#import <Sentry/SentryDebugMeta.h>
9+
#import <Sentry/SentryDependencyContainer.h>
10+
#import <Sentry/SentryEvent.h>
11+
#import <Sentry/SentryException.h>
12+
#import <Sentry/SentryFormatter.h>
13+
#import <Sentry/SentryOptions.h>
14+
#import <Sentry/SentryUser.h>
15+
@import Sentry;
16+
17+
// This method was moved to a new category so we can use `@import Sentry` to use Sentry's Swift classes
18+
@implementation RNSentry (fetchNativeStack)
19+
20+
- (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAddr
21+
symbolicate:(SymbolicateCallbackType)symbolicate
22+
{
23+
#if CROSS_PLATFORM_TEST
24+
BOOL shouldSymbolicateLocally = [SentrySDKInternal.options debug];
25+
#else
26+
BOOL shouldSymbolicateLocally = [SentrySDK.options debug];
27+
#endif
28+
NSString *appPackageName = [[NSBundle mainBundle] executablePath];
29+
30+
NSMutableSet<NSString *> *_Nonnull imagesAddrToRetrieveDebugMetaImages =
31+
[[NSMutableSet alloc] init];
32+
NSMutableArray<NSDictionary<NSString *, id> *> *_Nonnull serializedFrames =
33+
[[NSMutableArray alloc] init];
34+
35+
for (NSNumber *addr in instructionsAddr) {
36+
SentryBinaryImageInfo *_Nullable image = [[[SentryDependencyContainer sharedInstance]
37+
binaryImageCache] imageByAddress:[addr unsignedLongLongValue]];
38+
if (image != nil) {
39+
NSString *imageAddr = sentry_formatHexAddressUInt64([image address]);
40+
[imagesAddrToRetrieveDebugMetaImages addObject:imageAddr];
41+
42+
NSDictionary<NSString *, id> *_Nonnull nativeFrame = @{
43+
@"platform" : @"cocoa",
44+
@"instruction_addr" : sentry_formatHexAddress(addr),
45+
@"package" : [image name],
46+
@"image_addr" : imageAddr,
47+
@"in_app" : [NSNumber numberWithBool:[appPackageName isEqualToString:[image name]]],
48+
};
49+
50+
if (shouldSymbolicateLocally) {
51+
Dl_info symbolsBuffer;
52+
bool symbols_succeed = false;
53+
symbols_succeed
54+
= symbolicate((void *)[addr unsignedLongLongValue], &symbolsBuffer) != 0;
55+
if (symbols_succeed) {
56+
NSMutableDictionary<NSString *, id> *_Nonnull symbolicated
57+
= nativeFrame.mutableCopy;
58+
symbolicated[@"symbol_addr"]
59+
= sentry_formatHexAddressUInt64((uintptr_t)symbolsBuffer.dli_saddr);
60+
symbolicated[@"function"] = [NSString stringWithCString:symbolsBuffer.dli_sname
61+
encoding:NSUTF8StringEncoding];
62+
63+
nativeFrame = symbolicated;
64+
}
65+
}
66+
67+
[serializedFrames addObject:nativeFrame];
68+
} else {
69+
[serializedFrames addObject:@{
70+
@"platform" : @"cocoa",
71+
@"instruction_addr" : sentry_formatHexAddress(addr),
72+
}];
73+
}
74+
}
75+
76+
if (shouldSymbolicateLocally) {
77+
return @{
78+
@"frames" : serializedFrames,
79+
};
80+
} else {
81+
NSMutableArray<NSDictionary<NSString *, id> *> *_Nonnull serializedDebugMetaImages =
82+
[[NSMutableArray alloc] init];
83+
84+
NSArray<SentryDebugMeta *> *debugMetaImages =
85+
[[[SentryDependencyContainer sharedInstance] debugImageProvider]
86+
getDebugImagesForImageAddressesFromCache:imagesAddrToRetrieveDebugMetaImages];
87+
88+
for (SentryDebugMeta *debugImage in debugMetaImages) {
89+
[serializedDebugMetaImages addObject:[debugImage serialize]];
90+
}
91+
92+
return @{
93+
@"frames" : serializedFrames,
94+
@"debugMetaImages" : serializedDebugMetaImages,
95+
};
96+
}
97+
}
98+
99+
@end

packages/core/ios/RNSentry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ SentrySDK (Private)
3131

3232
- (void)setEventOriginTag:(SentryEvent *)event;
3333

34+
@end
35+
36+
@interface RNSentry (fetchNativeStack)
37+
3438
- (NSDictionary *_Nonnull)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAddr
3539
symbolicate:(SymbolicateCallbackType)symbolicate;
3640

packages/core/ios/RNSentry.mm

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#import "RNSentryId.h"
2121
#import <Sentry/PrivateSentrySDKOnly.h>
2222
#import <Sentry/SentryAppStartMeasurement.h>
23-
#import <Sentry/SentryBinaryImageCache.h>
2423
#import <Sentry/SentryBreadcrumb.h>
2524
#import <Sentry/SentryDebugImageProvider+HybridSDKs.h>
2625
#import <Sentry/SentryDebugMeta.h>
@@ -30,6 +29,7 @@
3029
#import <Sentry/SentryFormatter.h>
3130
#import <Sentry/SentryOptions.h>
3231
#import <Sentry/SentryUser.h>
32+
3333
#if __has_include(<Sentry/SentryOptions+HybridSDKs.h>)
3434
# define USE_SENTRY_OPTIONS 1
3535
# import <Sentry/SentryOptions+HybridSDKs.h>
@@ -358,85 +358,6 @@ - (void)stopObserving
358358
return packageName;
359359
}
360360

361-
- (NSDictionary *)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAddr
362-
symbolicate:(SymbolicateCallbackType)symbolicate
363-
{
364-
#if CROSS_PLATFORM_TEST
365-
BOOL shouldSymbolicateLocally = [SentrySDKInternal.options debug];
366-
#else
367-
BOOL shouldSymbolicateLocally = [SentrySDK.options debug];
368-
#endif
369-
NSString *appPackageName = [[NSBundle mainBundle] executablePath];
370-
371-
NSMutableSet<NSString *> *_Nonnull imagesAddrToRetrieveDebugMetaImages =
372-
[[NSMutableSet alloc] init];
373-
NSMutableArray<NSDictionary<NSString *, id> *> *_Nonnull serializedFrames =
374-
[[NSMutableArray alloc] init];
375-
376-
for (NSNumber *addr in instructionsAddr) {
377-
SentryBinaryImageInfo *_Nullable image = [[[SentryDependencyContainer sharedInstance]
378-
binaryImageCache] imageByAddress:[addr unsignedLongLongValue]];
379-
if (image != nil) {
380-
NSString *imageAddr = sentry_formatHexAddressUInt64([image address]);
381-
[imagesAddrToRetrieveDebugMetaImages addObject:imageAddr];
382-
383-
NSDictionary<NSString *, id> *_Nonnull nativeFrame = @{
384-
@"platform" : @"cocoa",
385-
@"instruction_addr" : sentry_formatHexAddress(addr),
386-
@"package" : [image name],
387-
@"image_addr" : imageAddr,
388-
@"in_app" : [NSNumber numberWithBool:[appPackageName isEqualToString:[image name]]],
389-
};
390-
391-
if (shouldSymbolicateLocally) {
392-
Dl_info symbolsBuffer;
393-
bool symbols_succeed = false;
394-
symbols_succeed
395-
= symbolicate((void *)[addr unsignedLongLongValue], &symbolsBuffer) != 0;
396-
if (symbols_succeed) {
397-
NSMutableDictionary<NSString *, id> *_Nonnull symbolicated
398-
= nativeFrame.mutableCopy;
399-
symbolicated[@"symbol_addr"]
400-
= sentry_formatHexAddressUInt64((uintptr_t)symbolsBuffer.dli_saddr);
401-
symbolicated[@"function"] = [NSString stringWithCString:symbolsBuffer.dli_sname
402-
encoding:NSUTF8StringEncoding];
403-
404-
nativeFrame = symbolicated;
405-
}
406-
}
407-
408-
[serializedFrames addObject:nativeFrame];
409-
} else {
410-
[serializedFrames addObject:@{
411-
@"platform" : @"cocoa",
412-
@"instruction_addr" : sentry_formatHexAddress(addr),
413-
}];
414-
}
415-
}
416-
417-
if (shouldSymbolicateLocally) {
418-
return @{
419-
@"frames" : serializedFrames,
420-
};
421-
} else {
422-
NSMutableArray<NSDictionary<NSString *, id> *> *_Nonnull serializedDebugMetaImages =
423-
[[NSMutableArray alloc] init];
424-
425-
NSArray<SentryDebugMeta *> *debugMetaImages =
426-
[[[SentryDependencyContainer sharedInstance] debugImageProvider]
427-
getDebugImagesForImageAddressesFromCache:imagesAddrToRetrieveDebugMetaImages];
428-
429-
for (SentryDebugMeta *debugImage in debugMetaImages) {
430-
[serializedDebugMetaImages addObject:[debugImage serialize]];
431-
}
432-
433-
return @{
434-
@"frames" : serializedFrames,
435-
@"debugMetaImages" : serializedDebugMetaImages,
436-
};
437-
}
438-
}
439-
440361
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSDictionary *, fetchNativeStackFramesBy
441362
: (NSArray *)instructionsAddr)
442363
{

0 commit comments

Comments
 (0)