Skip to content

Commit e0a15a5

Browse files
authored
ref: Convert SentryFrameRemover to Swift (#6225)
1 parent aff3b66 commit e0a15a5

File tree

8 files changed

+28
-55
lines changed

8 files changed

+28
-55
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,6 @@
347347
7B05A61824A4D14A00EF211D /* SentrySessionGeneratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B05A61724A4D14A00EF211D /* SentrySessionGeneratorTests.swift */; };
348348
7B08A3452924CF6C0059603A /* SentryMetricKitIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B08A3442924CF6C0059603A /* SentryMetricKitIntegration.h */; };
349349
7B08A3472924CF9C0059603A /* SentryMetricKitIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B08A3462924CF9C0059603A /* SentryMetricKitIntegration.m */; };
350-
7B0A54222521C21E00A71716 /* SentryFrameRemover.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B0A54212521C21E00A71716 /* SentryFrameRemover.h */; };
351-
7B0A54282521C22C00A71716 /* SentryFrameRemover.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A54272521C22C00A71716 /* SentryFrameRemover.m */; };
352350
7B0A542E2521C62400A71716 /* SentryFrameRemoverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A542D2521C62400A71716 /* SentryFrameRemoverTests.swift */; };
353351
7B0A5452252311CE00A71716 /* SentryBreadcrumbTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A5451252311CE00A71716 /* SentryBreadcrumbTests.swift */; };
354352
7B0A54562523178700A71716 /* SentryScopeSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B0A54552523178700A71716 /* SentryScopeSwiftTests.swift */; };
@@ -1118,6 +1116,7 @@
11181116
FAE2DABA2E1F318900262307 /* SentryProfilingSwiftHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */; };
11191117
FAE5798D2E7D9D4C00B710F9 /* SentrySysctl.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */; };
11201118
FAE579C22E7DDDE700B710F9 /* SentryThreadWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579BC2E7DDDE400B710F9 /* SentryThreadWrapper.swift */; };
1119+
FAE579CC2E7DE14900B710F9 /* SentryFrameRemover.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAE579C62E7DE14400B710F9 /* SentryFrameRemover.swift */; };
11211120
FAE80C242E4695B40010A595 /* SentryEvent+Serialize.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */; };
11221121
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
11231122
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
@@ -1598,8 +1597,6 @@
15981597
7B05A61724A4D14A00EF211D /* SentrySessionGeneratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySessionGeneratorTests.swift; sourceTree = "<group>"; };
15991598
7B08A3442924CF6C0059603A /* SentryMetricKitIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryMetricKitIntegration.h; path = include/SentryMetricKitIntegration.h; sourceTree = "<group>"; };
16001599
7B08A3462924CF9C0059603A /* SentryMetricKitIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMetricKitIntegration.m; sourceTree = "<group>"; };
1601-
7B0A54212521C21E00A71716 /* SentryFrameRemover.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryFrameRemover.h; path = include/SentryFrameRemover.h; sourceTree = "<group>"; };
1602-
7B0A54272521C22C00A71716 /* SentryFrameRemover.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryFrameRemover.m; sourceTree = "<group>"; };
16031600
7B0A542D2521C62400A71716 /* SentryFrameRemoverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFrameRemoverTests.swift; sourceTree = "<group>"; };
16041601
7B0A5451252311CE00A71716 /* SentryBreadcrumbTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBreadcrumbTests.swift; sourceTree = "<group>"; };
16051602
7B0A54552523178700A71716 /* SentryScopeSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScopeSwiftTests.swift; sourceTree = "<group>"; };
@@ -2464,6 +2461,7 @@
24642461
FAE2DAB92E1F318900262307 /* SentryProfilingSwiftHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryProfilingSwiftHelpers.h; path = Sources/Sentry/include/SentryProfilingSwiftHelpers.h; sourceTree = SOURCE_ROOT; };
24652462
FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySysctl.swift; sourceTree = "<group>"; };
24662463
FAE579BC2E7DDDE400B710F9 /* SentryThreadWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryThreadWrapper.swift; sourceTree = "<group>"; };
2464+
FAE579C62E7DE14400B710F9 /* SentryFrameRemover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFrameRemover.swift; sourceTree = "<group>"; };
24672465
FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryEvent+Serialize.h"; path = "include/SentryEvent+Serialize.h"; sourceTree = "<group>"; };
24682466
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
24692467
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
@@ -2840,8 +2838,6 @@
28402838
7BA61CC9247D128B00C130A8 /* SentryThreadInspector.m */,
28412839
7B7D872B2486480B00D2ECFF /* SentryStacktraceBuilder.h */,
28422840
7B7D872D2486482600D2ECFF /* SentryStacktraceBuilder.m */,
2843-
7B0A54212521C21E00A71716 /* SentryFrameRemover.h */,
2844-
7B0A54272521C22C00A71716 /* SentryFrameRemover.m */,
28452841
7B14089524878F090035403D /* SentryCrashStackEntryMapper.h */,
28462842
7B14089724878F950035403D /* SentryCrashStackEntryMapper.m */,
28472843
7B7D873124864BB900D2ECFF /* SentryCrashMachineContextWrapper.h */,
@@ -4750,6 +4746,7 @@
47504746
F4FE9E062E6248BB0014FED5 /* SentryCrash */ = {
47514747
isa = PBXGroup;
47524748
children = (
4749+
FAE579C62E7DE14400B710F9 /* SentryFrameRemover.swift */,
47534750
F4FE9E072E6248E40014FED5 /* SentryCrashWrapper.swift */,
47544751
);
47554752
path = SentryCrash;
@@ -4948,7 +4945,6 @@
49484945
63FE717D20DA4C1100CDBAE8 /* SentryCrashCachedData.h in Headers */,
49494946
03BCC38A27E1BF49003232C7 /* SentryTime.h in Headers */,
49504947
925824C22CB5897700C9B20B /* SentrySessionReplayIntegration-Hybrid.h in Headers */,
4951-
7B0A54222521C21E00A71716 /* SentryFrameRemover.h in Headers */,
49524948
63FE70CD20DA4C1000CDBAE8 /* SentryCrashDoctor.h in Headers */,
49534949
7B6438AA26A70F24000D0F65 /* UIViewController+Sentry.h in Headers */,
49544950
33EB2A912C3412E4004FED3D /* SentryWithoutUIKit.h in Headers */,
@@ -5687,6 +5683,7 @@
56875683
63FE711D20DA4C1000CDBAE8 /* SentryCrashCPU_arm64.c in Sources */,
56885684
844EDC77294144DB00C86F34 /* SentrySystemWrapper.mm in Sources */,
56895685
D451ED5F2D92ECDE00C9BEA8 /* SentryReplayFrame.swift in Sources */,
5686+
FAE579CC2E7DE14900B710F9 /* SentryFrameRemover.swift in Sources */,
56905687
D49480D72DC23FE300A3B6E9 /* SentrySessionReplayDelegate.swift in Sources */,
56915688
FA67DCC12DDBD4C800896B02 /* SentrySDKLog+Configure.swift in Sources */,
56925689
6281C5722D3E4F12009D0978 /* DecodeArbitraryData.swift in Sources */,
@@ -5751,7 +5748,6 @@
57515748
63FE70D520DA4C1000CDBAE8 /* SentryCrashMonitor_NSException.m in Sources */,
57525749
62F70E952D423BCD00634054 /* SentryMechanismCodable.swift in Sources */,
57535750
0AAE201E28ED9B9400D0CD80 /* SentryReachability.m in Sources */,
5754-
7B0A54282521C22C00A71716 /* SentryFrameRemover.m in Sources */,
57555751
6283085F2D50AA8C00EAEF77 /* SentryMessage.swift in Sources */,
57565752
7BC63F0A28081288009D9E37 /* SentrySwizzleWrapper.m in Sources */,
57575753
6276350C2D59FACC00F7CEF6 /* SentryEventDecoder.swift in Sources */,

Sources/Sentry/SentryFrameRemover.m

Lines changed: 0 additions & 23 deletions
This file was deleted.

Sources/Sentry/SentryStacktraceBuilder.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#import "SentryCrashStackEntryMapper.h"
66
#import "SentryCrashSymbolicator.h"
77
#import "SentryFrame.h"
8-
#import "SentryFrameRemover.h"
98
#import "SentryLogC.h"
109
#import "SentryStacktrace.h"
10+
#import "SentrySwift.h"
1111
#import <dlfcn.h>
1212

1313
NS_ASSUME_NONNULL_BEGIN

Sources/Sentry/include/SentryFrameRemover.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/Sentry/include/SentryStacktraceBuilder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#import <Foundation/Foundation.h>
66

77
@class SentryCrashStackEntryMapper;
8-
@class SentryFrameRemover;
98
@class SentryStacktrace;
109
@class SentryFrame;
1110

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@_spi(Private) public final class SentryFrameRemover: NSObject {
2+
3+
/// Removes Sentry SDK frames until a frame from a different package is found.
4+
/// @discussion When a user includes Sentry as a static library, the package is the same as the
5+
/// application. Therefore removing frames with a package containing "sentry" doesn't work. We can't
6+
/// look into the function name as in release builds, the function name can be obfuscated, or we
7+
/// remove functions that are not from this SDK and contain "sentry". Therefore this logic only works
8+
/// for apps including Sentry dynamically.
9+
@objc public static func removeNonSdkFrames(_ frames: [Frame]) -> [Frame] {
10+
let indexOfFirstNonSentryFrame = frames.firstIndex { frame in
11+
guard let package = frame.package?.lowercased() else {
12+
return true
13+
}
14+
return !package.contains("/sentry.framework/") && !package.contains("/sentryprivate.framework/")
15+
}
16+
17+
if let indexOfFirstNonSentryFrame {
18+
return Array(frames[indexOfFirstNonSentryFrame...])
19+
}
20+
return frames
21+
}
22+
}

Tests/SentryTests/SentryCrash/SentryFrameRemoverTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@_spi(Private) import Sentry
12
import XCTest
23

34
class SentryFrameRemoverTests: XCTestCase {

Tests/SentryTests/SentryTests-Bridging-Header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
#import "SentryFileManager.h"
124124
#import "SentryFormatter.h"
125125
#import "SentryFrame.h"
126-
#import "SentryFrameRemover.h"
127126
#import "SentryFramesTrackingIntegration.h"
128127
#import "SentryGlobalEventProcessor.h"
129128
#import "SentryHttpDateParser.h"

0 commit comments

Comments
 (0)