Skip to content

Commit 7126349

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 7126349

File tree

14 files changed

+118
-51
lines changed

14 files changed

+118
-51
lines changed

Samples/Common/Sources/LibraryBridge/InstallBridge.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ extension InstallBridge {
180180
(.signal, "Signal", "UNIX-style signals indicating abnormal program termination"),
181181
(.cppException, "C++ Exception", "Unhandled exceptions in C++ code"),
182182
(.nsException, "NSException", "Unhandled Objective-C exceptions"),
183-
(.mainThreadDeadlock, "Main Thread Deadlock", "Situations where the main thread becomes unresponsive"),
183+
(.watchdog, "Watchdog", "Hangs and watchdog timeout terminations"),
184184
(.memoryTermination, "Memory Termination", "Termination due to excessive memory usage"),
185185
(.zombie, "Zombie", "Attempts to access deallocated objects"),
186186
(.userReported, "User Reported", "Custom crash reports"),
@@ -194,7 +194,6 @@ extension InstallBridge {
194194

195195
(.productionSafe, "Production-safe"),
196196
(.productionSafeMinimal, "Production-safe Minimal"),
197-
(.experimental, "Experimental"),
198197

199198
(.required, "Required"),
200199
(.optional, "Optional"),

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/Monitors/KSCrashMonitor_Watchdog.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ @implementation KSHangMonitor
201201
// Returns the current task role (foreground, background, etc).
202202
static int TaskRole(void)
203203
{
204+
#if TARGET_OS_TV || TARGET_OS_WATCH
205+
// task_policy_get is not available on tvOS or watchOS
206+
return TASK_UNSPECIFIED;
207+
#else
204208
task_category_policy_data_t policy;
205209
mach_msg_type_number_t count = TASK_CATEGORY_POLICY_COUNT;
206210
boolean_t getDefault = NO;
@@ -209,6 +213,7 @@ static int TaskRole(void)
209213
task_policy_get(mach_task_self(), TASK_CATEGORY_POLICY, (task_policy_t)&policy, &count, &getDefault);
210214

211215
return kr == KERN_SUCCESS ? policy.role : TASK_UNSPECIFIED;
216+
#endif
212217
}
213218

214219
- (instancetype)initWithRunLoop:(CFRunLoopRef)runLoop threshold:(NSTimeInterval)threshold

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
*

0 commit comments

Comments
 (0)