diff --git a/CHANGELOG.md b/CHANGELOG.md index ed3ef2d002..5142e5cf9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - Convert one of the two remaining usages of `sprintf` to `snprintf` (#2866) +- Fix use-after-free ASAN warning (#3042) - Fix memory leaks in the profiler (#3055, #3061) ## 8.7.2 diff --git a/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard b/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard index f96c14a2d7..4ab62f660b 100644 --- a/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard +++ b/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard @@ -359,10 +359,10 @@ - + - + + + + + + + + + + + + + + diff --git a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift index 78b85d1b9d..a02ab1e087 100644 --- a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift @@ -4,6 +4,7 @@ import UIKit class ErrorsViewController: UIViewController { + @IBOutlet weak var imageView: UIImageView! private let dispatchQueue = DispatchQueue(label: "ErrorsViewController", attributes: .concurrent) private let diskWriteException = DiskWriteException() @@ -12,6 +13,10 @@ class ErrorsViewController: UIViewController { SentrySDK.reportFullyDisplayed() } + @IBAction func useAfterFree(_ sender: UIButton) { + imageView.image = UIImage(named: "") + } + @IBAction func diskWriteException(_ sender: UIButton) { highlightButton(sender) diskWriteException.continuouslyWriteToDisk() diff --git a/Samples/iOS-Swift/iOS-SwiftUITests/LaunchUITests.swift b/Samples/iOS-Swift/iOS-SwiftUITests/LaunchUITests.swift index e23999227b..71b2390d42 100644 --- a/Samples/iOS-Swift/iOS-SwiftUITests/LaunchUITests.swift +++ b/Samples/iOS-Swift/iOS-SwiftUITests/LaunchUITests.swift @@ -98,6 +98,25 @@ class LaunchUITests: XCTestCase { app.buttons["Extra"].tap() checkSlowAndFrozenFrames() } + + /** + * We received a customer report that ASAN reports a use-after-free error after + * calling UIImage(named:) with an empty string argument. Recording another + * transaction leads to the ASAN error. + */ + func testUseAfterFreeAfterUIImageNamedEmptyString() throws { + guard #available(iOS 14, *) else { + throw XCTSkip("Only run for iOS 14 or later") + } + + let app = XCUIApplication() + + // this primes the state required according to the customer report, by setting a UIImageView.image property to a UIImage(named: "") + app/*@START_MENU_TOKEN@*/.staticTexts["Use-after-free"]/*[[".buttons[\"Use-after-free\"].staticTexts[\"Use-after-free\"]",".staticTexts[\"Use-after-free\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() + + // this causes another transaction to be recorded which hits the codepath necessary for the ASAN to trip + app.tabBars["Tab Bar"].buttons["Extra"].tap() + } } private extension LaunchUITests { diff --git a/Sources/Sentry/PrivateSentrySDKOnly.m b/Sources/Sentry/PrivateSentrySDKOnly.m index 630cda46cb..ba4383095d 100644 --- a/Sources/Sentry/PrivateSentrySDKOnly.m +++ b/Sources/Sentry/PrivateSentrySDKOnly.m @@ -41,7 +41,14 @@ + (nullable SentryEnvelope *)envelopeWithData:(NSData *)data + (NSArray *)getDebugImages { - return [[SentryDependencyContainer sharedInstance].debugImageProvider getDebugImages]; + // maintains previous behavior for the same method call by also trying to gather crash info + return [self getDebugImagesCrashed:YES]; +} + ++ (NSArray *)getDebugImagesCrashed:(BOOL)isCrash +{ + return [[SentryDependencyContainer sharedInstance].debugImageProvider + getDebugImagesCrashed:isCrash]; } + (nullable SentryAppStartMeasurement *)appStartMeasurement diff --git a/Sources/Sentry/Public/SentryDebugImageProvider.h b/Sources/Sentry/Public/SentryDebugImageProvider.h index 9a4c27a7fe..fd0210a958 100644 --- a/Sources/Sentry/Public/SentryDebugImageProvider.h +++ b/Sources/Sentry/Public/SentryDebugImageProvider.h @@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Reserved for hybrid SDKs that the debug image list for symbolication. + * @todo This class should be renamed to @c SentryDebugImage in a future version. */ @interface SentryDebugImageProvider : NSObject @@ -14,22 +15,65 @@ NS_ASSUME_NONNULL_BEGIN /** * Returns a list of debug images that are being referenced in the given threads. - * @param threads A list of @c SentryThread that may or may not contain stacktracse. + * @param threads A list of @c SentryThread that may or may not contain stacktraces. + * @warning This assumes a crash has occurred and attempts to read the crash information from each + * image's data segment, which may not be present or be invalid if a crash has not actually + * occurred. To avoid this, use the new @c -[getDebugImagesForThreads:isCrash:] instead. + * @deprecated Use @c -[getDebugImagesForThreads:isCrash:] instead. + */ +- (NSArray *)getDebugImagesForThreads:(NSArray *)threads + DEPRECATED_MSG_ATTRIBUTE("Use -[getDebugImagesForThreads:isCrash:] instead."); + +/** + * Returns a list of debug images that are being referenced in the given threads. + * @param threads A list of @c SentryThread that may or may not contain stacktraces. + * @param isCrash @c YES if we're collecting binary images for a crash report, @c NO if we're + * gathering them for other backtrace information, like a performance transaction. If this is for a + * crash, each image's data section crash info is also included. + */ +- (NSArray *)getDebugImagesForThreads:(NSArray *)threads + isCrash:(BOOL)isCrash; + +/** + * Returns a list of debug images that are being referenced by the given frames. + * @param frames A list of stack frames. + * @warning This assumes a crash has occurred and attempts to read the crash information from each + * image's data segment, which may not be present or be invalid if a crash has not actually + * occurred. To avoid this, use the new @c -[getDebugImagesForFrames:isCrash:] instead. + * @deprecated Use @c -[getDebugImagesForFrames:isCrash:] instead. */ -- (NSArray *)getDebugImagesForThreads:(NSArray *)threads; +- (NSArray *)getDebugImagesForFrames:(NSArray *)frames + DEPRECATED_MSG_ATTRIBUTE("Use -[getDebugImagesForFrames:isCrash:] instead."); /** * Returns a list of debug images that are being referenced by the given frames. * @param frames A list of stack frames. + * @param isCrash @c YES if we're collecting binary images for a crash report, @c NO if we're + * gathering them for other backtrace information, like a performance transaction. If this is for a + * crash, each image's data section crash info is also included. */ -- (NSArray *)getDebugImagesForFrames:(NSArray *)frames; +- (NSArray *)getDebugImagesForFrames:(NSArray *)frames + isCrash:(BOOL)isCrash; /** * Returns the current list of debug images. Be aware that the @c SentryDebugMeta is actually * describing a debug image. - * @todo This class should be renamed to @c SentryDebugImage in a future version. + * @warning This assumes a crash has occurred and attempts to read the crash information from each + * image's data segment, which may not be present or be invalid if a crash has not actually + * occurred. To avoid this, use the new @c -[getDebugImagesCrashed:] instead. + * @deprecated Use @c -[getDebugImagesCrashed:] instead. + */ +- (NSArray *)getDebugImages DEPRECATED_MSG_ATTRIBUTE( + "Use -[getDebugImagesCrashed:] instead."); + +/** + * Returns the current list of debug images. Be aware that the @c SentryDebugMeta is actually + * describing a debug image. + * @param isCrash @c YES if we're collecting binary images for a crash report, @c NO if we're + * gathering them for other backtrace information, like a performance transaction. If this is for a + * crash, each image's data section crash info is also included. */ -- (NSArray *)getDebugImages; +- (NSArray *)getDebugImagesCrashed:(BOOL)isCrash; @end diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index 5520824878..ca6ea32fa2 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -587,7 +587,8 @@ - (SentryEvent *_Nullable)prepareEvent:(SentryEvent *)event BOOL debugMetaNotAttached = !(nil != event.debugMeta && event.debugMeta.count > 0); if (!isCrashEvent && shouldAttachStacktrace && debugMetaNotAttached && event.threads != nil) { - event.debugMeta = [self.debugImageProvider getDebugImagesForThreads:event.threads]; + event.debugMeta = [self.debugImageProvider getDebugImagesForThreads:event.threads + isCrash:NO]; } } diff --git a/Sources/Sentry/SentryCrashDefaultBinaryImageProvider.m b/Sources/Sentry/SentryCrashDefaultBinaryImageProvider.m index 4159a499a0..cfbf34ad44 100644 --- a/Sources/Sentry/SentryCrashDefaultBinaryImageProvider.m +++ b/Sources/Sentry/SentryCrashDefaultBinaryImageProvider.m @@ -10,10 +10,10 @@ - (NSInteger)getImageCount return sentrycrashdl_imageCount(); } -- (SentryCrashBinaryImage)getBinaryImage:(NSInteger)index +- (SentryCrashBinaryImage)getBinaryImage:(NSInteger)index isCrash:(BOOL)isCrash { SentryCrashBinaryImage image = { 0 }; - sentrycrashdl_getBinaryImage((int)index, &image); + sentrycrashdl_getBinaryImage((int)index, &image, isCrash); return image; } diff --git a/Sources/Sentry/SentryDebugImageProvider.m b/Sources/Sentry/SentryDebugImageProvider.m index ee93fbfa47..2f7e355726 100644 --- a/Sources/Sentry/SentryDebugImageProvider.m +++ b/Sources/Sentry/SentryDebugImageProvider.m @@ -39,10 +39,11 @@ - (instancetype)initWithBinaryImageProvider:(id) } - (NSArray *)getDebugImagesForAddresses:(NSSet *)addresses + isCrash:(BOOL)isCrash { NSMutableArray *result = [NSMutableArray array]; - NSArray *binaryImages = [self getDebugImages]; + NSArray *binaryImages = [self getDebugImagesCrashed:isCrash]; for (SentryDebugMeta *sourceImage in binaryImages) { if ([addresses containsObject:sourceImage.imageAddress]) { @@ -64,13 +65,27 @@ - (void)extractDebugImageAddressFromFrames:(NSArray *)frames } - (NSArray *)getDebugImagesForFrames:(NSArray *)frames +{ + // maintains previous behavior for the same method call by also trying to gather crash info + return [self getDebugImagesForFrames:frames isCrash:YES]; +} + +- (NSArray *)getDebugImagesForFrames:(NSArray *)frames + isCrash:(BOOL)isCrash { NSMutableSet *imageAdresses = [[NSMutableSet alloc] init]; [self extractDebugImageAddressFromFrames:frames intoSet:imageAdresses]; - return [self getDebugImagesForAddresses:imageAdresses]; + return [self getDebugImagesForAddresses:imageAdresses isCrash:isCrash]; } - (NSArray *)getDebugImagesForThreads:(NSArray *)threads +{ + // maintains previous behavior for the same method call by also trying to gather crash info + return [self getDebugImagesForThreads:threads isCrash:YES]; +} + +- (NSArray *)getDebugImagesForThreads:(NSArray *)threads + isCrash:(BOOL)isCrash { NSMutableSet *imageAdresses = [[NSMutableSet alloc] init]; @@ -78,16 +93,22 @@ - (void)extractDebugImageAddressFromFrames:(NSArray *)frames [self extractDebugImageAddressFromFrames:thread.stacktrace.frames intoSet:imageAdresses]; } - return [self getDebugImagesForAddresses:imageAdresses]; + return [self getDebugImagesForAddresses:imageAdresses isCrash:isCrash]; } - (NSArray *)getDebugImages +{ + // maintains previous behavior for the same method call by also trying to gather crash info + return [self getDebugImagesCrashed:YES]; +} + +- (NSArray *)getDebugImagesCrashed:(BOOL)isCrash { NSMutableArray *debugMetaArray = [NSMutableArray new]; NSInteger imageCount = [self.binaryImageProvider getImageCount]; for (NSInteger i = 0; i < imageCount; i++) { - SentryCrashBinaryImage image = [self.binaryImageProvider getBinaryImage:i]; + SentryCrashBinaryImage image = [self.binaryImageProvider getBinaryImage:i isCrash:isCrash]; SentryDebugMeta *debugMeta = [self fillDebugMetaFrom:image]; [debugMetaArray addObject:debugMeta]; } diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 6d10ecb34d..1e1c707d4c 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -592,7 +592,7 @@ + (void)useFramesTracker:(SentryFramesTracker *)framesTracker ?: _gCurrentProfiler->_hub.getClient.options.environment, _gCurrentProfiler->_hub.getClient.options.releaseName, [_gCurrentProfiler->_metricProfiler serializeForTransaction:transaction], - [_gCurrentProfiler->_debugImageProvider getDebugImages]); + [_gCurrentProfiler->_debugImageProvider getDebugImagesCrashed:NO]); } + (void)timeoutAbort diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index cfe62b28a8..797231cd39 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -586,7 +586,8 @@ - (SentryTransaction *)toTransaction if (framesOfAllSpans.count > 0) { SentryDebugImageProvider *debugImageProvider = SentryDependencyContainer.sharedInstance.debugImageProvider; - transaction.debugMeta = [debugImageProvider getDebugImagesForFrames:framesOfAllSpans]; + transaction.debugMeta = [debugImageProvider getDebugImagesForFrames:framesOfAllSpans + isCrash:NO]; } [self addMeasurements:transaction]; diff --git a/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h b/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h index e4ab93cadc..06044f827b 100644 --- a/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h +++ b/Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h @@ -40,10 +40,21 @@ typedef void (^SentryOnAppStartMeasurementAvailable)( /** * Returns the current list of debug images. Be aware that the @c SentryDebugMeta is actually * describing a debug image. - * @todo This class should be renamed to @c SentryDebugImage in a future version. + * @warning This assumes a crash has occurred and attempts to read the crash information from each + * image's data segment, which may not be present or be invalid if a crash has not actually + * occurred. To avoid this, use the new @c +[getDebugImagesCrashed:] instead. */ + (NSArray *)getDebugImages; +/** + * Returns the current list of debug images. Be aware that the @c SentryDebugMeta is actually + * describing a debug image. + * @param isCrash @c YES if we're collecting binary images for a crash report, @c NO if we're + * gathering them for other backtrace information, like a performance transaction. If this is for a + * crash, each image's data section crash info is also included. + */ ++ (NSArray *)getDebugImagesCrashed:(BOOL)isCrash; + /** * Override SDK information. */ diff --git a/Sources/Sentry/include/SentryCrashBinaryImageProvider.h b/Sources/Sentry/include/SentryCrashBinaryImageProvider.h index 56150bff0f..ee3c16ae89 100644 --- a/Sources/Sentry/include/SentryCrashBinaryImageProvider.h +++ b/Sources/Sentry/include/SentryCrashBinaryImageProvider.h @@ -10,7 +10,13 @@ NS_ASSUME_NONNULL_BEGIN - (NSInteger)getImageCount; -- (SentryCrashBinaryImage)getBinaryImage:(NSInteger)index; +/** + * Returns information for the image at the specified index. + * @param isCrash @c YES if we're collecting binary images for a crash report, @c NO if we're + * gathering them for other backtrace information, like a performance transaction. If this is for a + * crash, each image's data section crash info is also included. + */ +- (SentryCrashBinaryImage)getBinaryImage:(NSInteger)index isCrash:(BOOL)isCrash; @end diff --git a/Sources/SentryCrash/Recording/SentryCrashReport.c b/Sources/SentryCrash/Recording/SentryCrashReport.c index 89e97d15fa..29e63088a8 100644 --- a/Sources/SentryCrash/Recording/SentryCrashReport.c +++ b/Sources/SentryCrash/Recording/SentryCrashReport.c @@ -1166,7 +1166,7 @@ writeBinaryImage( const SentryCrashReportWriter *const writer, const char *const key, const int index) { SentryCrashBinaryImage image = { 0 }; - if (!sentrycrashdl_getBinaryImage(index, &image)) { + if (!sentrycrashdl_getBinaryImage(index, &image, /*isCrash*/ true)) { return; } diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.c b/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.c index 4706b6de38..682131019d 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.c @@ -341,20 +341,20 @@ sentrycrashdl_imageCount(void) } bool -sentrycrashdl_getBinaryImage(int index, SentryCrashBinaryImage *buffer) +sentrycrashdl_getBinaryImage(int index, SentryCrashBinaryImage *buffer, bool isCrash) { const struct mach_header *header = _dyld_get_image_header((unsigned)index); if (header == NULL) { return false; } - return sentrycrashdl_getBinaryImageForHeader( - (const void *)header, _dyld_get_image_name((unsigned)index), buffer); + const char *imageName = _dyld_get_image_name((unsigned)index); + return sentrycrashdl_getBinaryImageForHeader((const void *)header, imageName, buffer, isCrash); } bool -sentrycrashdl_getBinaryImageForHeader( - const void *const header_ptr, const char *const image_name, SentryCrashBinaryImage *buffer) +sentrycrashdl_getBinaryImageForHeader(const void *const header_ptr, const char *const image_name, + SentryCrashBinaryImage *buffer, bool isCrash) { const struct mach_header *header = (const struct mach_header *)header_ptr; uintptr_t cmdPtr = firstCmdAfterHeader(header); @@ -413,7 +413,9 @@ sentrycrashdl_getBinaryImageForHeader( buffer->majorVersion = version >> 16; buffer->minorVersion = (version >> 8) & 0xff; buffer->revisionVersion = version & 0xff; - getCrashInfo(header, buffer); + if (isCrash) { + getCrashInfo(header, buffer); + } return true; } diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.h b/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.h index 7f7bfda843..4e66e1fb6d 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashDynamicLinker.h @@ -63,7 +63,7 @@ int sentrycrashdl_imageCount(void); * * @return True if the image was successfully queried. */ -bool sentrycrashdl_getBinaryImage(int index, SentryCrashBinaryImage *buffer); +bool sentrycrashdl_getBinaryImage(int index, SentryCrashBinaryImage *buffer, bool isCrash); /** Get information about a binary image based on mach_header. * @@ -75,8 +75,8 @@ bool sentrycrashdl_getBinaryImage(int index, SentryCrashBinaryImage *buffer); * * @return True if the image was successfully queried. */ -bool sentrycrashdl_getBinaryImageForHeader( - const void *const header_ptr, const char *const image_name, SentryCrashBinaryImage *buffer); +bool sentrycrashdl_getBinaryImageForHeader(const void *const header_ptr, + const char *const image_name, SentryCrashBinaryImage *buffer, bool isCrash); /** Find a loaded binary image with the specified name. * diff --git a/Tests/SentryTests/Helper/TestDebugImageProvider.swift b/Tests/SentryTests/Helper/TestDebugImageProvider.swift index c01d72256b..ed30b385c2 100644 --- a/Tests/SentryTests/Helper/TestDebugImageProvider.swift +++ b/Tests/SentryTests/Helper/TestDebugImageProvider.swift @@ -4,6 +4,10 @@ class TestDebugImageProvider: SentryDebugImageProvider { var debugImages: [DebugMeta]? override func getDebugImages() -> [DebugMeta] { - return debugImages ?? super.getDebugImages() + getDebugImagesCrashed(true) + } + + override func getDebugImagesCrashed(_ isCrash: Bool) -> [DebugMeta] { + debugImages ?? super.getDebugImagesCrashed(isCrash) } } diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index bbfcfadb3b..0257c815db 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -1565,7 +1565,7 @@ class SentryClientTest: XCTestCase { } private func assertValidDebugMeta(actual: [DebugMeta]?, forThreads threads: [SentryThread]?) { - let debugMetas = fixture.debugImageBuilder.getDebugImages(for: threads ?? []) + let debugMetas = fixture.debugImageBuilder.getDebugImages(for: threads ?? [], isCrash: false) XCTAssertEqual(debugMetas, actual ?? []) } diff --git a/Tests/SentryTests/SentryCrash/SentryCrashDefaultBinaryImageProviderTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashDefaultBinaryImageProviderTests.swift index 2d8308a93e..6e757d75ff 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashDefaultBinaryImageProviderTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashDefaultBinaryImageProviderTests.swift @@ -23,10 +23,10 @@ class SentryCrashDefaultBinaryImageProviderTests: XCTestCase { let sut = fixture.getSut() let imageCount = sut.getImageCount() for i in 0 ... imageCount { - let actual = sut.getBinaryImage(i) + let actual = sut.getBinaryImage(i, isCrash: true) var expected = SentryCrashBinaryImage() - sentrycrashdl_getBinaryImage(Int32(i), &expected) + sentrycrashdl_getBinaryImage(Int32(i), &expected, /*isCrash*/ false) XCTAssertEqual(expected.uuid, actual.uuid) XCTAssertEqual(expected.vmAddress, actual.vmAddress) diff --git a/Tests/SentryTests/SentryCrash/SentryDebugImageProviderTests.swift b/Tests/SentryTests/SentryCrash/SentryDebugImageProviderTests.swift index 4e8b6dae5d..5cc2576bed 100644 --- a/Tests/SentryTests/SentryCrash/SentryDebugImageProviderTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryDebugImageProviderTests.swift @@ -57,7 +57,7 @@ class SentryDebugImageProviderTests: XCTestCase { func testThreeImages() { let sut = fixture.getSut(images: fixture.getTestImages()) - let actual = sut.getDebugImages() + let actual = sut.getDebugImagesCrashed(false) XCTAssertEqual(3, actual.count) @@ -77,7 +77,7 @@ class SentryDebugImageProviderTests: XCTestCase { let image = SentryDebugImageProviderTests.createSentryCrashBinaryImage(vmAddress: 0) let sut = fixture.getSut(images: [image]) - let actual = sut.getDebugImages() + let actual = sut.getDebugImagesCrashed(false) XCTAssertNil(actual[0].imageVmAddress) } @@ -86,7 +86,7 @@ class SentryDebugImageProviderTests: XCTestCase { func testWith(value: UInt64) { let image = SentryDebugImageProviderTests.createSentryCrashBinaryImage(size: value) let sut = fixture.getSut(images: [image]) - let actual = sut.getDebugImages() + let actual = sut.getDebugImagesCrashed(false) XCTAssertEqual(NSNumber(value: value), actual[0].imageSize) } @@ -99,7 +99,7 @@ class SentryDebugImageProviderTests: XCTestCase { func testWith(value: UInt64, expected: String) { let image = SentryDebugImageProviderTests.createSentryCrashBinaryImage(address: value) let sut = fixture.getSut(images: [image]) - let actual = sut.getDebugImages() + let actual = sut.getDebugImagesCrashed(false) XCTAssertEqual(1, actual.count) @@ -114,7 +114,7 @@ class SentryDebugImageProviderTests: XCTestCase { } func testNoImages() { - let actual = fixture.getSut().getDebugImages() + let actual = fixture.getSut().getDebugImagesCrashed(false) XCTAssertEqual(0, actual.count) } @@ -127,7 +127,7 @@ class SentryDebugImageProviderTests: XCTestCase { frame.imageAddress = "0x0000000105705000" thread.stacktrace = SentryStacktrace(frames: [frame], registers: [:]) - var actual = sut.getDebugImages(for: [thread]) + var actual = sut.getDebugImages(for: [thread], isCrash: false) XCTAssertEqual(actual.count, 1) XCTAssertEqual(actual[0].codeFile, "dyld_sim") @@ -139,7 +139,7 @@ class SentryDebugImageProviderTests: XCTestCase { frame3.imageAddress = "0x000000017ca5e400" thread.stacktrace = SentryStacktrace(frames: [frame2, frame3], registers: [:]) - actual = sut.getDebugImages(for: [thread]) + actual = sut.getDebugImages(for: [thread], isCrash: false) XCTAssertEqual(actual.count, 2) XCTAssertEqual(actual[0].codeFile, "UIKit") @@ -152,7 +152,7 @@ class SentryDebugImageProviderTests: XCTestCase { func test_NoImage_ForThread_WithoutStackTrace() { let sut = fixture.getSut(images: fixture.getTestImages()) let thread = SentryThread(threadId: NSNumber(value: 1)) - let actual = sut.getDebugImages(for: [thread]) + let actual = sut.getDebugImages(for: [thread], isCrash: false) XCTAssertEqual(actual.count, 0) } diff --git a/Tests/SentryTests/SentryCrash/TestSentryCrashBinaryImageProvider.swift b/Tests/SentryTests/SentryCrash/TestSentryCrashBinaryImageProvider.swift index a88a6ca19f..5bbb4dde54 100644 --- a/Tests/SentryTests/SentryCrash/TestSentryCrashBinaryImageProvider.swift +++ b/Tests/SentryTests/SentryCrash/TestSentryCrashBinaryImageProvider.swift @@ -5,6 +5,10 @@ public class TestSentryCrashBinaryImageProvider: NSObject, SentryCrashBinaryImag var binaryImage: [SentryCrashBinaryImage] = [] public func getBinaryImage(_ index: Int) -> SentryCrashBinaryImage { + getBinaryImage(index, isCrash: true) + } + + public func getBinaryImage(_ index: Int, isCrash: Bool) -> SentryCrashBinaryImage { binaryImage[Int(index)] }