11#import " SentryDebugImageProvider.h"
2+ #import " SentryBinaryImageCache.h"
23#import " SentryCrashDefaultBinaryImageProvider.h"
34#import " SentryCrashDynamicLinker.h"
45#import " SentryCrashUUIDConversion.h"
56#import " SentryDebugMeta.h"
7+ #import " SentryDependencyContainer.h"
68#import " SentryFormatter.h"
79#import " SentryFrame.h"
810#import " SentryInternalDefines.h"
1416@interface SentryDebugImageProvider ()
1517
1618@property (nonatomic , strong ) id <SentryCrashBinaryImageProvider> binaryImageProvider;
19+ @property (nonatomic , strong ) SentryBinaryImageCache *binaryImageCache;
20+
1721@end
1822
1923@implementation SentryDebugImageProvider
@@ -23,16 +27,20 @@ - (instancetype)init
2327 SentryCrashDefaultBinaryImageProvider *provider =
2428 [[SentryCrashDefaultBinaryImageProvider alloc ] init ];
2529
26- self = [self initWithBinaryImageProvider: provider];
30+ self = [self
31+ initWithBinaryImageProvider: provider
32+ binaryImageCache: SentryDependencyContainer.sharedInstance.binaryImageCache];
2733
2834 return self;
2935}
3036
3137/* * Internal constructor for testing */
3238- (instancetype )initWithBinaryImageProvider : (id <SentryCrashBinaryImageProvider>)binaryImageProvider
39+ binaryImageCache : (SentryBinaryImageCache *)binaryImageCache
3340{
3441 if (self = [super init ]) {
3542 self.binaryImageProvider = binaryImageProvider;
43+ self.binaryImageCache = binaryImageCache;
3644 }
3745 return self;
3846}
@@ -95,6 +103,55 @@ - (void)extractDebugImageAddressFromFrames:(NSArray<SentryFrame *> *)frames
95103 return [self getDebugImagesForAddresses: imageAddresses isCrash: isCrash];
96104}
97105
106+ - (NSArray <SentryDebugMeta *> *)getDebugImagesFromCacheForFrames : (NSArray <SentryFrame *> *)frames
107+ {
108+ NSMutableSet <NSString *> *imageAddresses = [[NSMutableSet alloc ] init ];
109+ [self extractDebugImageAddressFromFrames: frames intoSet: imageAddresses];
110+
111+ return [self getDebugImagesForImageAddressesFromCache: imageAddresses];
112+ }
113+
114+ - (NSArray <SentryDebugMeta *> *)getDebugImagesFromCacheForThreads : (NSArray <SentryThread *> *)threads
115+ {
116+ NSMutableSet <NSString *> *imageAddresses = [[NSMutableSet alloc ] init ];
117+
118+ for (SentryThread *thread in threads) {
119+ [self extractDebugImageAddressFromFrames: thread.stacktrace.frames intoSet: imageAddresses];
120+ }
121+
122+ return [self getDebugImagesForImageAddressesFromCache: imageAddresses];
123+ }
124+
125+ - (NSArray <SentryDebugMeta *> *)getDebugImagesForImageAddressesFromCache :
126+ (NSSet <NSString *> *)imageAddresses
127+ {
128+ NSMutableArray <SentryDebugMeta *> *result = [NSMutableArray array ];
129+
130+ for (NSString *imageAddress in imageAddresses) {
131+ const uint64_t imageAddressAsUInt64 = sentry_UInt64ForHexAddress (imageAddress);
132+ SentryBinaryImageInfo *info = [self .binaryImageCache imageByAddress: imageAddressAsUInt64];
133+ if (info == nil ) {
134+ continue ;
135+ }
136+
137+ SentryDebugMeta *debugMeta = [[SentryDebugMeta alloc ] init ];
138+ debugMeta.debugID = info.UUID ;
139+ debugMeta.type = SentryDebugImageType;
140+
141+ if (info.vmAddress > 0 ) {
142+ debugMeta.imageVmAddress = sentry_formatHexAddressUInt64 (info.vmAddress );
143+ }
144+
145+ debugMeta.imageAddress = sentry_formatHexAddressUInt64 (info.address );
146+ debugMeta.imageSize = @(info.size );
147+ debugMeta.codeFile = info.name ;
148+
149+ [result addObject: debugMeta];
150+ }
151+
152+ return result;
153+ }
154+
98155- (NSArray <SentryDebugMeta *> *)getDebugImages
99156{
100157 // maintains previous behavior for the same method call by also trying to gather crash info
@@ -118,7 +175,7 @@ - (void)extractDebugImageAddressFromFrames:(NSArray<SentryFrame *> *)frames
118175- (SentryDebugMeta *)fillDebugMetaFrom : (SentryCrashBinaryImage)image
119176{
120177 SentryDebugMeta *debugMeta = [[SentryDebugMeta alloc ] init ];
121- debugMeta.debugID = [SentryDebugImageProvider convertUUID: image.uuid];
178+ debugMeta.debugID = [SentryBinaryImageCache convertUUID: image.uuid];
122179 debugMeta.type = SentryDebugImageType;
123180
124181 if (image.vmAddress > 0 ) {
@@ -136,15 +193,4 @@ - (SentryDebugMeta *)fillDebugMetaFrom:(SentryCrashBinaryImage)image
136193 return debugMeta;
137194}
138195
139- + (NSString *_Nullable)convertUUID : (const unsigned char *const )value
140- {
141- if (nil == value) {
142- return nil ;
143- }
144-
145- char uuidBuffer[37 ];
146- sentrycrashdl_convertBinaryImageUUID (value, uuidBuffer);
147- return [[NSString alloc ] initWithCString: uuidBuffer encoding: NSASCIIStringEncoding];
148- }
149-
150196@end
0 commit comments