Skip to content

Commit 6c16e7a

Browse files
committed
Deprecate KSCrashMonitor_Deadlock in favor of Watchdog monitor
- Add KSCRASH_DEPRECATED macro to KSSystemCapabilities.h - Mark kscm_deadlock_getAPI() and kscm_setDeadlockHandlerWatchdogInterval() as deprecated with guidance to use KSCrashMonitor_Watchdog - Deprecate deadlockWatchdogInterval property in KSCrashConfiguration - Remove KSCrashMonitorTypeMainThreadDeadlock from KSCrashMonitorTypeAll and KSCrashMonitorTypeFatal composite types - Set KSCrashMonitorTypeExperimental to KSCrashMonitorTypeNone - Add pragma suppression for internal uses of deprecated APIs
1 parent 14be141 commit 6c16e7a

File tree

12 files changed

+112
-49
lines changed

12 files changed

+112
-49
lines changed

Sources/KSCrashCore/include/KSSystemCapabilities.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,16 @@
157157
#define KSCRASH_HAS_REACHABILITY 0
158158
#endif
159159

160+
// ============================================================================
161+
#pragma mark - Compiler Attributes -
162+
// ============================================================================
163+
164+
#ifndef KSCRASH_DEPRECATED
165+
#if defined(__has_attribute) && __has_attribute(deprecated)
166+
#define KSCRASH_DEPRECATED(msg) __attribute__((deprecated(msg)))
167+
#else
168+
#define KSCRASH_DEPRECATED(msg)
169+
#endif
170+
#endif
171+
160172
#endif // HDR_KSSystemCapabilities_h

Sources/KSCrashRecording/KSCrashC.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,21 @@ typedef enum {
7474
static const struct KSCrashMonitorMapping {
7575
KSCrashMonitorType type;
7676
KSCrashMonitorAPI *(*getAPI)(void);
77-
} g_monitorMappings[] = { { KSCrashMonitorTypeMachException, kscm_machexception_getAPI },
78-
{ KSCrashMonitorTypeSignal, kscm_signal_getAPI },
79-
{ KSCrashMonitorTypeCPPException, kscm_cppexception_getAPI },
80-
{ KSCrashMonitorTypeNSException, kscm_nsexception_getAPI },
81-
{ KSCrashMonitorTypeMainThreadDeadlock, kscm_deadlock_getAPI },
82-
{ KSCrashMonitorTypeUserReported, kscm_user_getAPI },
83-
{ KSCrashMonitorTypeSystem, kscm_system_getAPI },
84-
{ KSCrashMonitorTypeApplicationState, kscm_appstate_getAPI },
85-
{ KSCrashMonitorTypeZombie, kscm_zombie_getAPI },
86-
{ KSCrashMonitorTypeMemoryTermination, kscm_memory_getAPI },
87-
{ KSCrashMonitorTypeWatchdog, kscm_watchdog_getAPI } };
77+
}
78+
#pragma clang diagnostic push
79+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
80+
g_monitorMappings[] = { { KSCrashMonitorTypeMachException, kscm_machexception_getAPI },
81+
{ KSCrashMonitorTypeSignal, kscm_signal_getAPI },
82+
{ KSCrashMonitorTypeCPPException, kscm_cppexception_getAPI },
83+
{ KSCrashMonitorTypeNSException, kscm_nsexception_getAPI },
84+
{ KSCrashMonitorTypeMainThreadDeadlock, kscm_deadlock_getAPI },
85+
{ KSCrashMonitorTypeUserReported, kscm_user_getAPI },
86+
{ KSCrashMonitorTypeSystem, kscm_system_getAPI },
87+
{ KSCrashMonitorTypeApplicationState, kscm_appstate_getAPI },
88+
{ KSCrashMonitorTypeZombie, kscm_zombie_getAPI },
89+
{ KSCrashMonitorTypeMemoryTermination, kscm_memory_getAPI },
90+
{ KSCrashMonitorTypeWatchdog, kscm_watchdog_getAPI } };
91+
#pragma clang diagnostic pop
8892

8993
static const size_t g_monitorMappingCount = sizeof(g_monitorMappings) / sizeof(g_monitorMappings[0]);
9094

@@ -254,7 +258,10 @@ static void handleConfiguration(KSCrashCConfiguration *configuration)
254258
kscrashreport_setUserInfoJSON(configuration->userInfoJSON);
255259
}
256260
#if KSCRASH_HAS_OBJC
261+
#pragma clang diagnostic push
262+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
257263
kscm_setDeadlockHandlerWatchdogInterval(configuration->deadlockWatchdogInterval);
264+
#pragma clang diagnostic pop
258265
#endif
259266
kstc_setSearchQueueNames(configuration->enableQueueNameSearch);
260267
kscrashreport_setIntrospectMemory(configuration->enableMemoryIntrospection);

Sources/KSCrashRecording/KSCrashConfiguration.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ - (instancetype)init
5151
_userInfoJSON = nil;
5252
}
5353

54+
#pragma clang diagnostic push
55+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
5456
_deadlockWatchdogInterval = cConfig.deadlockWatchdogInterval;
57+
#pragma clang diagnostic pop
5558
_enableQueueNameSearch = cConfig.enableQueueNameSearch ? YES : NO;
5659
_enableMemoryIntrospection = cConfig.enableMemoryIntrospection ? YES : NO;
5760
_doNotIntrospectClasses = nil;
@@ -90,7 +93,10 @@ - (KSCrashCConfiguration)toCConfiguration
9093
config.reportStoreConfiguration = [self.reportStoreConfiguration toCConfiguration];
9194
config.monitors = self.monitors;
9295
config.userInfoJSON = self.userInfoJSON ? [self jsonStringFromDictionary:self.userInfoJSON] : NULL;
96+
#pragma clang diagnostic push
97+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
9398
config.deadlockWatchdogInterval = self.deadlockWatchdogInterval;
99+
#pragma clang diagnostic pop
94100
config.enableQueueNameSearch = self.enableQueueNameSearch;
95101
config.enableMemoryIntrospection = self.enableMemoryIntrospection;
96102
config.doNotIntrospectClasses.strings = [self createCStringArrayFromNSArray:self.doNotIntrospectClasses];
@@ -162,7 +168,10 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone
162168
copy.installPath = [self.installPath copyWithZone:zone];
163169
copy.monitors = self.monitors;
164170
copy.userInfoJSON = [self.userInfoJSON copyWithZone:zone];
171+
#pragma clang diagnostic push
172+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
165173
copy.deadlockWatchdogInterval = self.deadlockWatchdogInterval;
174+
#pragma clang diagnostic pop
166175
copy.enableQueueNameSearch = self.enableQueueNameSearch;
167176
copy.enableMemoryIntrospection = self.enableMemoryIntrospection;
168177
copy.doNotIntrospectClasses = self.doNotIntrospectClasses

Sources/KSCrashRecording/KSCrashReportC.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,10 @@ static void writeError(const KSCrashReportWriter *const writer, const char *cons
13221322
writer->addStringElement(writer, KSCrashField_Name, crash->CPPException.name);
13231323
}
13241324
writer->endContainer(writer);
1325+
#pragma clang diagnostic push
1326+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
13251327
} else if (isCrashOfMonitorType(crash, kscm_deadlock_getAPI())) {
1328+
#pragma clang diagnostic pop
13261329
writer->addStringElement(writer, KSCrashField_Type, KSCrashExcType_Deadlock);
13271330

13281331
} else if (isCrashOfMonitorType(crash, kscm_memory_getAPI())) {

Sources/KSCrashRecording/Monitors/KSCrashMonitor_Deadlock.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@
2424
// THE SOFTWARE.
2525
//
2626

27-
/* Catches deadlocks in threads and queues.
27+
/**
28+
* @file KSCrashMonitor_Deadlock.h
29+
* @brief Catches deadlocks in threads and queues.
30+
*
31+
* @deprecated This monitor is deprecated. Use KSCrashMonitor_Watchdog instead,
32+
* which provides better hang detection, watchdog timeout reporting, and an
33+
* observer API for monitoring hang state changes.
34+
*
35+
* @see KSCrashMonitor_Watchdog.h
2836
*/
2937

3038
#ifndef HDR_KSCrashMonitor_Deadlock_h
@@ -38,16 +46,23 @@ extern "C" {
3846

3947
#include "KSCrashMonitorAPI.h"
4048
#include "KSCrashNamespace.h"
49+
#include "KSSystemCapabilities.h"
4150

4251
/** Set the interval between watchdog checks on the main thread.
4352
* Default is 5 seconds.
4453
*
4554
* @param value The number of seconds between checks (0 = disabled).
55+
*
56+
* @deprecated Use KSCrashMonitor_Watchdog instead.
4657
*/
58+
KSCRASH_DEPRECATED("Use KSCrashMonitor_Watchdog instead")
4759
void kscm_setDeadlockHandlerWatchdogInterval(double value);
4860

4961
/** Access the Monitor API.
62+
*
63+
* @deprecated Use kscm_watchdog_getAPI() from KSCrashMonitor_Watchdog.h instead.
5064
*/
65+
KSCRASH_DEPRECATED("Use kscm_watchdog_getAPI() instead")
5166
KSCrashMonitorAPI *kscm_deadlock_getAPI(void);
5267

5368
#ifdef __cplusplus

Sources/KSCrashRecording/Monitors/KSCrashMonitor_Deadlock.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ - (void)__attribute__((noreturn)) handleDeadlock
119119
kssc_initWithMachineContext(&stackCursor, KSSC_MAX_STACK_DEPTH, &machineContext);
120120

121121
KSLOG_DEBUG(@"Filling out context.");
122+
#pragma clang diagnostic push
123+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
122124
kscm_fillMonitorContext(crashContext, kscm_deadlock_getAPI());
125+
#pragma clang diagnostic pop
123126
crashContext->registersAreValid = false;
124127
crashContext->offendingMachineContext = &machineContext;
125128
crashContext->stackCursor = &stackCursor;

Sources/KSCrashRecording/include/KSCrashCConfiguration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ typedef struct {
124124
* this value, including application startup. You may need to initialize your
125125
* application on a different thread or set this to a higher value until initialization
126126
* is complete.
127+
*
128+
* @note Deprecated. Use `KSCrashMonitorTypeWatchdog` in the `monitors` field instead.
129+
* The watchdog monitor provides better hang detection with a fixed 250ms threshold.
127130
*/
128131
double deadlockWatchdogInterval;
129132

Sources/KSCrashRecording/include/KSCrashConfiguration.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ NS_ASSUME_NONNULL_BEGIN
7676
* this value, including application startup. You may need to initialize your
7777
* application on a different thread or set this to a higher value until initialization
7878
* is complete.
79+
*
80+
* @note Deprecated. Use `KSCrashMonitorTypeWatchdog` in the `monitors` property instead.
81+
* The watchdog monitor provides better hang detection with a fixed 250ms threshold.
7982
*/
80-
@property(nonatomic, assign) double deadlockWatchdogInterval;
83+
@property(nonatomic, assign) double deadlockWatchdogInterval
84+
__attribute__((deprecated("Use KSCrashMonitorTypeWatchdog in monitors instead.")));
8185

8286
/** If true, attempt to fetch dispatch queue names for each running thread.
8387
*

Sources/KSCrashRecording/include/KSCrashMonitorType.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ enum
7171
/** Monitor uncaught Objective-C NSExceptions. */
7272
KSCrashMonitorTypeNSException = 1 << 3,
7373

74-
/** Detect deadlocks on the main thread. */
74+
/** Detect deadlocks on the main thread.
75+
* @note Deprecated. Use KSCrashMonitorTypeWatchdog instead.
76+
*/
7577
KSCrashMonitorTypeMainThreadDeadlock = 1 << 4,
7678

7779
/** Monitor user-reported custom exceptions. */
@@ -98,7 +100,6 @@ enum
98100
KSCrashMonitorTypeSignal |
99101
KSCrashMonitorTypeCPPException |
100102
KSCrashMonitorTypeNSException |
101-
KSCrashMonitorTypeMainThreadDeadlock |
102103
KSCrashMonitorTypeUserReported |
103104
KSCrashMonitorTypeSystem |
104105
KSCrashMonitorTypeApplicationState |
@@ -107,18 +108,19 @@ enum
107108
KSCrashMonitorTypeWatchdog
108109
),
109110

110-
/** Fatal monitors track exceptions that lead to error termination of the process.. */
111+
/** Fatal monitors track exceptions that lead to error termination of the process. */
111112
KSCrashMonitorTypeFatal = (
112113
KSCrashMonitorTypeMachException |
113114
KSCrashMonitorTypeSignal |
114115
KSCrashMonitorTypeCPPException |
115116
KSCrashMonitorTypeNSException |
116-
KSCrashMonitorTypeMainThreadDeadlock |
117117
KSCrashMonitorTypeWatchdog
118118
),
119119

120-
/** Enable experimental monitoring options. */
121-
KSCrashMonitorTypeExperimental = KSCrashMonitorTypeMainThreadDeadlock,
120+
/** Enable experimental monitoring options.
121+
* @note Currently empty as KSCrashMonitorTypeMainThreadDeadlock is deprecated.
122+
*/
123+
KSCrashMonitorTypeExperimental = KSCrashMonitorTypeNone,
122124

123125
/** Monitor options unsafe for use with a debugger. */
124126
KSCrashMonitorTypeDebuggerUnsafe = KSCrashMonitorTypeMachException,

Tests/KSCrashRecordingTests/KSCrashConfiguration_Tests.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ @interface KSCrashConfigurationTests : XCTestCase
3838

3939
@implementation KSCrashConfigurationTests
4040

41+
#pragma clang diagnostic push
42+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
43+
4144
- (void)setUp
4245
{
4346
clearCallbackData();
@@ -283,9 +286,6 @@ - (void)testCallbacksInCConfiguration
283286

284287
#pragma mark - Backward Compatibility Tests
285288

286-
#pragma clang diagnostic push
287-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
288-
289289
static struct {
290290
BOOL legacyCrashNotifyCallbackCalled;
291291
BOOL legacyReportWrittenCallbackCalled;

0 commit comments

Comments
 (0)