Skip to content

Commit bd2afa6

Browse files
feat: Add EXC_BAD_ACCESS subtypes to events (#2667)
Add EXC_BAD_ACCESS subtypes to unhandled errors on arm CPUs. Previously the CrashDoctor always diagnosed a memory crash as Attempted to dereference garbage pointer at 0x13fd4582e. Now the SDK replaces the generic message with the specific subtype.
1 parent 075a044 commit bd2afa6

File tree

10 files changed

+611
-18
lines changed

10 files changed

+611
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Cleanup AppHangTracking properly when closing SDK (#2671)
8+
- Add EXC_BAD_ACCESS subtypes to events (#2667)
89

910
## 8.1.0
1011

Sentry.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@
422422
7B9657252683104C00C66E25 /* NSData+Sentry.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B9657232683104C00C66E25 /* NSData+Sentry.h */; };
423423
7B9657262683104C00C66E25 /* NSData+Sentry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B9657242683104C00C66E25 /* NSData+Sentry.m */; };
424424
7B965728268321CD00C66E25 /* SentryCrashScopeObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B965727268321CD00C66E25 /* SentryCrashScopeObserverTests.swift */; };
425-
7B984A9F28E572AF001F4BEE /* CrashReportWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B984A9E28E572AF001F4BEE /* CrashReportWriter.swift */; };
425+
7B984A9F28E572AF001F4BEE /* CrashReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B984A9E28E572AF001F4BEE /* CrashReport.swift */; };
426426
7B98D7BC25FB607300C5A389 /* SentryWatchdogTerminationTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B98D7BB25FB607300C5A389 /* SentryWatchdogTerminationTracker.h */; };
427427
7B98D7CB25FB64EC00C5A389 /* SentryWatchdogTerminationTrackingIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B98D7CA25FB64EC00C5A389 /* SentryWatchdogTerminationTrackingIntegration.h */; };
428428
7B98D7CF25FB650F00C5A389 /* SentryWatchdogTerminationTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B98D7CE25FB650F00C5A389 /* SentryWatchdogTerminationTrackingIntegration.m */; };
@@ -572,6 +572,7 @@
572572
7BF6505F292B77EC00BBA5A8 /* SentryMetricKitIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF6505E292B77EC00BBA5A8 /* SentryMetricKitIntegrationTests.swift */; };
573573
7BF65062292B8F1C00BBA5A8 /* SentryMXCallStackTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF65061292B8F1C00BBA5A8 /* SentryMXCallStackTree.swift */; };
574574
7BF65064292B905A00BBA5A8 /* SentryMXCallStackTreeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF65063292B905A00BBA5A8 /* SentryMXCallStackTreeTests.swift */; };
575+
7BF69E072987D1FE002EBCA4 /* SentryCrashDoctorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF69E062987D1FE002EBCA4 /* SentryCrashDoctorTests.swift */; };
575576
7BF9EF722722A84800B5BBEF /* SentryClassRegistrator.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BF9EF712722A84800B5BBEF /* SentryClassRegistrator.h */; };
576577
7BF9EF742722A85B00B5BBEF /* SentryClassRegistrator.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BF9EF732722A85B00B5BBEF /* SentryClassRegistrator.m */; };
577578
7BF9EF762722B34700B5BBEF /* SentrySubClassFinder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BF9EF752722B34700B5BBEF /* SentrySubClassFinder.h */; };
@@ -1240,7 +1241,7 @@
12401241
7B9657242683104C00C66E25 /* NSData+Sentry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Sentry.m"; sourceTree = "<group>"; };
12411242
7B965727268321CD00C66E25 /* SentryCrashScopeObserverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashScopeObserverTests.swift; sourceTree = "<group>"; };
12421243
7B9660B12783500E0014A767 /* ThreadSanitizer.sup */ = {isa = PBXFileReference; lastKnownFileType = text; path = ThreadSanitizer.sup; sourceTree = "<group>"; };
1243-
7B984A9E28E572AF001F4BEE /* CrashReportWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReportWriter.swift; sourceTree = "<group>"; };
1244+
7B984A9E28E572AF001F4BEE /* CrashReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashReport.swift; sourceTree = "<group>"; };
12441245
7B98D7BB25FB607300C5A389 /* SentryWatchdogTerminationTracker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWatchdogTerminationTracker.h; path = include/SentryWatchdogTerminationTracker.h; sourceTree = "<group>"; };
12451246
7B98D7CA25FB64EC00C5A389 /* SentryWatchdogTerminationTrackingIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryWatchdogTerminationTrackingIntegration.h; path = include/SentryWatchdogTerminationTrackingIntegration.h; sourceTree = "<group>"; };
12461247
7B98D7CE25FB650F00C5A389 /* SentryWatchdogTerminationTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryWatchdogTerminationTrackingIntegration.m; sourceTree = "<group>"; };
@@ -1400,6 +1401,7 @@
14001401
7BF6505E292B77EC00BBA5A8 /* SentryMetricKitIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMetricKitIntegrationTests.swift; sourceTree = "<group>"; };
14011402
7BF65061292B8F1C00BBA5A8 /* SentryMXCallStackTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMXCallStackTree.swift; sourceTree = "<group>"; };
14021403
7BF65063292B905A00BBA5A8 /* SentryMXCallStackTreeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMXCallStackTreeTests.swift; sourceTree = "<group>"; };
1404+
7BF69E062987D1FE002EBCA4 /* SentryCrashDoctorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashDoctorTests.swift; sourceTree = "<group>"; };
14031405
7BF9EF712722A84800B5BBEF /* SentryClassRegistrator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryClassRegistrator.h; sourceTree = "<group>"; };
14041406
7BF9EF732722A85B00B5BBEF /* SentryClassRegistrator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryClassRegistrator.m; sourceTree = "<group>"; };
14051407
7BF9EF752722B34700B5BBEF /* SentrySubClassFinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentrySubClassFinder.h; sourceTree = "<group>"; };
@@ -2402,7 +2404,8 @@
24022404
7BED3574266F7BC600EAA70D /* TestSentryCrashWrapper.h */,
24032405
7BED3575266F7BFF00EAA70D /* TestSentryCrashWrapper.m */,
24042406
0ADC33EF28D9BE690078D980 /* TestSentryUIDeviceWrapper.swift */,
2405-
7B984A9E28E572AF001F4BEE /* CrashReportWriter.swift */,
2407+
7B984A9E28E572AF001F4BEE /* CrashReport.swift */,
2408+
7BF69E062987D1FE002EBCA4 /* SentryCrashDoctorTests.swift */,
24062409
);
24072410
path = SentryCrash;
24082411
sourceTree = "<group>";
@@ -4001,7 +4004,7 @@
40014004
D88817DD26D72BA500BF2251 /* SentryTraceStateTests.swift in Sources */,
40024005
8E25C97525F8511A00DC215B /* TestRandom.swift in Sources */,
40034006
7B26BBFB24C0A66D00A79CCC /* SentrySdkInfoNilTests.m in Sources */,
4004-
7B984A9F28E572AF001F4BEE /* CrashReportWriter.swift in Sources */,
4007+
7B984A9F28E572AF001F4BEE /* CrashReport.swift in Sources */,
40054008
7BAF3DD7243DD4A1008A5414 /* TestConstants.swift in Sources */,
40064009
035E73CC27D575B3005EEB11 /* SentrySamplingProfilerTests.mm in Sources */,
40074010
7BED3576266F7BFF00EAA70D /* TestSentryCrashWrapper.m in Sources */,
@@ -4103,6 +4106,7 @@
41034106
7BAF3DD2243DD05C008A5414 /* SentryTransportInitializerTests.swift in Sources */,
41044107
7B68D93625FF5F1A0082D139 /* SentryAppState+Equality.m in Sources */,
41054108
7B5CAF7E27F5AD3500ED0DB6 /* TestNSURLRequestBuilder.m in Sources */,
4109+
7BF69E072987D1FE002EBCA4 /* SentryCrashDoctorTests.swift in Sources */,
41064110
7B4F22DC294089530067EA17 /* FormatHexAddress.swift in Sources */,
41074111
8EAC7FF8265C8910005B44E5 /* SentryTracerTests.swift in Sources */,
41084112
0A1B497328E597DD00D7BFA3 /* TestLogOutput.swift in Sources */,

Sources/SentryCrash/Recording/SentryCrashDoctor.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,17 @@ - (NSString *)diagnoseCrash:(NSDictionary *)report
458458
if (address == 0) {
459459
return @"Attempted to dereference null pointer.";
460460
}
461-
return [NSString
462-
stringWithFormat:@"Attempted to dereference garbage pointer %p.", (void *)address];
461+
462+
NSString *codeName = errorReport[@SentryCrashField_Mach][@SentryCrashField_CodeName];
463+
if (codeName != nil) {
464+
// Inspired by
465+
// https://developer.apple.com/documentation/xcode/investigating-memory-access-crashes
466+
return [NSString stringWithFormat:@"%@ at %p.", codeName, (void *)address];
467+
} else {
468+
return
469+
[NSString stringWithFormat:@"Attempted to dereference garbage pointer at %p.",
470+
(void *)address];
471+
}
463472
}
464473

465474
return nil;

Sources/SentryCrash/Recording/Tools/SentryCrashMach.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <mach/mach.h>
2828
#include <stdlib.h>
2929

30+
#if defined(__arm__) || defined(__arm64__)
31+
# include <mach/arm/exception.h>
32+
#endif /* defined (__arm__) || defined (__arm64__) */
33+
3034
#define RETURN_NAME_FOR_ENUM(A) \
3135
case A: \
3236
return #A
@@ -104,6 +108,19 @@ sentrycrashmach_kernelReturnCodeName(const int64_t returnCode)
104108
RETURN_NAME_FOR_ENUM(KERN_NOT_WAITING);
105109
RETURN_NAME_FOR_ENUM(KERN_OPERATION_TIMED_OUT);
106110
RETURN_NAME_FOR_ENUM(KERN_CODESIGN_ERROR);
111+
112+
#if defined(__arm__) || defined(__arm64__)
113+
/*
114+
* Located at mach/arm/exception.h
115+
* For EXC_BAD_ACCESS
116+
* Note: do not conflict with kern_return_t values returned by vm_fault
117+
*/
118+
RETURN_NAME_FOR_ENUM(EXC_ARM_DA_ALIGN);
119+
RETURN_NAME_FOR_ENUM(EXC_ARM_DA_DEBUG);
120+
RETURN_NAME_FOR_ENUM(EXC_ARM_SP_ALIGN);
121+
RETURN_NAME_FOR_ENUM(EXC_ARM_SWP);
122+
RETURN_NAME_FOR_ENUM(EXC_ARM_PAC_FAIL);
123+
#endif /* defined (__arm__) || defined (__arm64__) */
107124
}
108125
return NULL;
109126
}
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
{
2+
"report": {
3+
"version": "3.2.0",
4+
"id": "42A64046-9255-4995-98C2-553FA204DF4D",
5+
"process_name": "iOS-Swift",
6+
"timestamp": 1675069636,
7+
"type": "standard"
8+
},
9+
"process": {},
10+
"system": {
11+
"system_name": "iOS",
12+
"system_version": "16.2",
13+
"machine": "iPhone11,8",
14+
"model": "N841AP",
15+
"kernel_version": "Darwin Kernel Version 22.2.0: Tue Nov 1 21:21:17 PDT 2022; root:xnu-8792.60.51.122.1~1/RELEASE_ARM64_T8020",
16+
"os_version": "20C5043e",
17+
"jailbroken": false,
18+
"boot_time": "2023-01-30T08:43:25Z",
19+
"app_start_time": "2023-01-30T09:05:01Z",
20+
"CFBundleExecutablePath": "/private/var/containers/Bundle/Application/53C684E3-9F0E-4FE3-8291-88677BAB718C/iOS-Swift.app/iOS-Swift",
21+
"CFBundleExecutable": "iOS-Swift",
22+
"CFBundleIdentifier": "io.sentry.sample.iOS-Swift",
23+
"CFBundleName": "iOS-Swift",
24+
"CFBundleVersion": "1",
25+
"CFBundleShortVersionString": "7.31.5",
26+
"app_uuid": "C488D0BE-E733-3031-AEF3-CC5182AB1E3B",
27+
"cpu_arch": "arm64",
28+
"cpu_type": 16777228,
29+
"cpu_subtype": 2,
30+
"binary_cpu_type": 16777228,
31+
"binary_cpu_subtype": 0,
32+
"process_name": "iOS-Swift",
33+
"process_id": 495,
34+
"parent_process_id": 1,
35+
"device_app_hash": "9116712086e95f0c91b259ee97270e8f6a8a7768",
36+
"build_type": "debug",
37+
"total_storage": 63933894656,
38+
"free_storage": 26521919488,
39+
"memory": {
40+
"size": 2976202752,
41+
"usable": 2550726656,
42+
"free": 66846720
43+
},
44+
"application_stats": {
45+
"application_active": true,
46+
"application_in_foreground": true,
47+
"launches_since_last_crash": 1,
48+
"sessions_since_last_crash": 2,
49+
"active_time_since_last_crash": 120.664,
50+
"background_time_since_last_crash": 12.2669,
51+
"sessions_since_launch": 2,
52+
"active_time_since_launch": 120.664,
53+
"background_time_since_launch": 12.2669
54+
}
55+
},
56+
"crash": {
57+
"error": {
58+
"mach": {
59+
"exception": 1,
60+
"exception_name": "EXC_BAD_ACCESS",
61+
"code": 257,
62+
"subcode": 5365848110
63+
},
64+
"signal": {
65+
"signal": 10,
66+
"name": "SIGBUS",
67+
"code": 0,
68+
"code_name": "BUS_NOOP"
69+
},
70+
"address": 5365848110,
71+
"type": "mach"
72+
}
73+
},
74+
"sentry_sdk_scope": {
75+
"user": {
76+
"email": "[email protected]",
77+
"id": "1"
78+
},
79+
"environment": "debug",
80+
"tags": {
81+
"language": "swift"
82+
},
83+
"extra": {
84+
"currentViewController": "<iOS_Swift.ViewController: 0x159d05ac0>"
85+
},
86+
"breadcrumbs": [
87+
{
88+
"category": "started",
89+
"level": "info",
90+
"message": "Breadcrumb Tracking",
91+
"timestamp": "2023-01-30T09:05:01.740Z",
92+
"type": "debug"
93+
},
94+
{
95+
"category": "device.orientation",
96+
"data": {
97+
"position": "portrait"
98+
},
99+
"level": "info",
100+
"timestamp": "2023-01-30T09:05:01.757Z",
101+
"type": "navigation"
102+
},
103+
{
104+
"category": "ui.lifecycle",
105+
"data": {
106+
"beingPresented": "false",
107+
"is_window_rootViewController": "true",
108+
"screen": "UINavigationController",
109+
"window": "<UIWindow: 0x159d0af90; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x282ec60a0>; backgroundColor = <UIDynamicSystemColor: 0x2835fe280; name = _windowBackgroundColor>; layer = <UIWindowLayer: 0x282ec6400>>",
110+
"window_isKeyWindow": "true",
111+
"window_windowLevel": "0.000000"
112+
},
113+
"level": "info",
114+
"timestamp": "2023-01-30T09:05:01.819Z",
115+
"type": "navigation"
116+
},
117+
{
118+
"category": "ui.lifecycle",
119+
"data": {
120+
"beingPresented": "false",
121+
"is_window_rootViewController": "false",
122+
"parentViewController": "UINavigationController",
123+
"screen": "ViewController",
124+
"title": "Sentry Test App (Swift)",
125+
"window": "<UIWindow: 0x159d0af90; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x282ec60a0>; backgroundColor = <UIDynamicSystemColor: 0x2835fe280; name = _windowBackgroundColor>; layer = <UIWindowLayer: 0x282ec6400>>",
126+
"window_isKeyWindow": "true",
127+
"window_windowLevel": "0.000000"
128+
},
129+
"level": "info",
130+
"timestamp": "2023-01-30T09:05:01.819Z",
131+
"type": "navigation"
132+
},
133+
{
134+
"category": "app.lifecycle",
135+
"data": {
136+
"state": "foreground"
137+
},
138+
"level": "info",
139+
"timestamp": "2023-01-30T09:05:01.987Z",
140+
"type": "navigation"
141+
},
142+
{
143+
"category": "device.event",
144+
"data": {
145+
"action": "BATTERY_STATE_CHANGE",
146+
"level": 4,
147+
"plugged": true
148+
},
149+
"level": "info",
150+
"timestamp": "2023-01-30T09:05:21.053Z",
151+
"type": "system"
152+
},
153+
{
154+
"category": "device.event",
155+
"data": {
156+
"action": "BATTERY_STATE_CHANGE",
157+
"level": 3,
158+
"plugged": true
159+
},
160+
"level": "info",
161+
"timestamp": "2023-01-30T09:05:41.050Z",
162+
"type": "system"
163+
},
164+
{
165+
"category": "device.event",
166+
"data": {
167+
"action": "BATTERY_STATE_CHANGE",
168+
"level": 4,
169+
"plugged": true
170+
},
171+
"level": "info",
172+
"timestamp": "2023-01-30T09:06:01.086Z",
173+
"type": "system"
174+
},
175+
{
176+
"category": "device.event",
177+
"data": {
178+
"action": "BATTERY_STATE_CHANGE",
179+
"level": 3,
180+
"plugged": true
181+
},
182+
"level": "info",
183+
"timestamp": "2023-01-30T09:06:21.115Z",
184+
"type": "system"
185+
},
186+
{
187+
"category": "app.lifecycle",
188+
"data": {
189+
"state": "background"
190+
},
191+
"level": "info",
192+
"timestamp": "2023-01-30T09:07:02.658Z",
193+
"type": "navigation"
194+
},
195+
{
196+
"category": "device.orientation",
197+
"data": {
198+
"position": "portrait"
199+
},
200+
"level": "info",
201+
"timestamp": "2023-01-30T09:07:14.286Z",
202+
"type": "navigation"
203+
},
204+
{
205+
"category": "app.lifecycle",
206+
"data": {
207+
"state": "foreground"
208+
},
209+
"level": "info",
210+
"timestamp": "2023-01-30T09:07:15.480Z",
211+
"type": "navigation"
212+
},
213+
{
214+
"category": "touch",
215+
"data": {
216+
"title": "crash",
217+
"view": "<UIButton: 0x159e43020; frame = (0 210; 181.5 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x2820d8980>>"
218+
},
219+
"level": "info",
220+
"message": "crash:",
221+
"timestamp": "2023-01-30T09:07:16.198Z",
222+
"type": "user"
223+
}
224+
]
225+
},
226+
"user": {
227+
"context": {
228+
"app": {
229+
"app_build": "1",
230+
"app_id": "C488D0BE-E733-3031-AEF3-CC5182AB1E3B",
231+
"app_identifier": "io.sentry.sample.iOS-Swift",
232+
"app_name": "iOS-Swift",
233+
"app_start_time": "2023-01-30T09:05:01Z",
234+
"app_version": "7.31.5",
235+
"build_type": "debug",
236+
"device_app_hash": "9116712086e95f0c91b259ee97270e8f6a8a7768"
237+
},
238+
"device": {
239+
"arch": "arm64",
240+
"boot_time": "2023-01-30T08:43:25Z",
241+
"family": "iOS",
242+
"free_memory": 38764544,
243+
"free_storage": 26521919488,
244+
"locale": "en_AT",
245+
"memory_size": 2976202752,
246+
"model": "iPhone11,8",
247+
"model_id": "N841AP",
248+
"screen_height_pixels": 896,
249+
"screen_width_pixels": 414,
250+
"simulator": false,
251+
"storage_size": 63933894656,
252+
"usable_memory": 2552430592
253+
},
254+
"os": {
255+
"build": "20C5043e",
256+
"kernel_version": "Darwin Kernel Version 22.2.0: Tue Nov 1 21:21:17 PDT 2022; root:xnu-8792.60.51.122.1~1/RELEASE_ARM64_T8020",
257+
"name": "iOS",
258+
"rooted": false,
259+
"version": "16.2"
260+
}
261+
},
262+
"release": "[email protected]+1"
263+
},
264+
"debug": {}
265+
}

0 commit comments

Comments
 (0)