From edfd311758fe3dcaaea024846c1fe2901bbb59a8 Mon Sep 17 00:00:00 2001 From: Nikolay Volosatov Date: Sun, 3 Nov 2024 13:22:37 +0000 Subject: [PATCH] Fix noinline attribute usage --- Sources/KSCrashCore/include/KSCompilerDefines.h | 6 +++++- .../Monitors/KSCrashMonitor_CPPException.cpp | 2 +- .../KSCrashRecording/Monitors/KSCrashMonitor_NSException.m | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/KSCrashCore/include/KSCompilerDefines.h b/Sources/KSCrashCore/include/KSCompilerDefines.h index 3dad35bc..6d4f7469 100644 --- a/Sources/KSCrashCore/include/KSCompilerDefines.h +++ b/Sources/KSCrashCore/include/KSCompilerDefines.h @@ -29,7 +29,11 @@ /// Disables optimisations to ensure a function remains in stacktrace. /// Usually used in pair with `KS_THWART_TAIL_CALL_OPTIMISATION`. -#define KS_KEEP_FUNCTION_IN_STACKTRACE __attribute__((disable_tail_calls)) __attribute__((noinline)) +#define KS_KEEP_FUNCTION_IN_STACKTRACE __attribute__((disable_tail_calls)) + +/// Disables inline optimisation. +/// Usually used in pair with `KS_KEEP_FUNCTION_IN_STACKTRACE`. +#define KS_NOINLINE __attribute__((noinline)) /// Extra safety measure to ensure a method is not tail-call optimised. /// This define should be placed at the end of a function. diff --git a/Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp b/Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp index 0e78c1eb..cf6841fd 100644 --- a/Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp +++ b/Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp @@ -78,7 +78,7 @@ static KSStackCursor g_stackCursor; #pragma mark - Callbacks - // ============================================================================ -static void captureStackTrace(void *, std::type_info *tinfo, void (*)(void *)) KS_KEEP_FUNCTION_IN_STACKTRACE +static KS_NOINLINE void captureStackTrace(void *, std::type_info *tinfo, void (*)(void *)) KS_KEEP_FUNCTION_IN_STACKTRACE { if (tinfo != nullptr && strcmp(tinfo->name(), "NSException") == 0) { return; diff --git a/Sources/KSCrashRecording/Monitors/KSCrashMonitor_NSException.m b/Sources/KSCrashRecording/Monitors/KSCrashMonitor_NSException.m index 9e86921f..6186f10f 100644 --- a/Sources/KSCrashRecording/Monitors/KSCrashMonitor_NSException.m +++ b/Sources/KSCrashRecording/Monitors/KSCrashMonitor_NSException.m @@ -55,7 +55,7 @@ #pragma mark - Callbacks - // ============================================================================ -static void initStackCursor(KSStackCursor *cursor, NSException *exception, uintptr_t *callstack, +static KS_NOINLINE void initStackCursor(KSStackCursor *cursor, NSException *exception, uintptr_t *callstack, BOOL isUserReported) KS_KEEP_FUNCTION_IN_STACKTRACE { // Use stacktrace from NSException if present, @@ -91,7 +91,7 @@ static void initStackCursor(KSStackCursor *cursor, NSException *exception, uintp * * @param exception The exception that was raised. */ -static void handleException(NSException *exception, BOOL isUserReported, +static KS_NOINLINE void handleException(NSException *exception, BOOL isUserReported, BOOL logAllThreads) KS_KEEP_FUNCTION_IN_STACKTRACE { KSLOG_DEBUG(@"Trapped exception %@", exception);