Skip to content

Commit

Permalink
[bugfix#493]
Browse files Browse the repository at this point in the history
For NSException, the stack trace can be obtained through system APIs, and it is not necessary to obtain it in __cxa_throw. Therefore, this filtering is valuable and also provides some performance optimization.
But only for whether the name is an NSException as a judgment basis, still let go of some Objc exceptions. To optimize this, we suggest maintaining the list through a constant array, so far we have found _NSCoreDataException and __NSCFConstantString, and there may be more in the future;
  • Loading branch information
fantexi023 committed Jan 17, 2025
1 parent e62b011 commit 5e1c130
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void (*dest)(voi
}
}

static const char* kscm_nsexception_names[] = {

Check failure on line 111 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:111:18: error: code should be clang-formatted [-Wclang-format-violations]

Check failure on line 111 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:111:19: error: code should be clang-formatted [-Wclang-format-violations]

Check failure on line 111 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:111:48: error: code should be clang-formatted [-Wclang-format-violations]
"NSException",

Check failure on line 112 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:112:19: error: code should be clang-formatted [-Wclang-format-violations]
"_NSCoreDataException",

Check failure on line 113 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:113:28: error: code should be clang-formatted [-Wclang-format-violations]
"__NSCFConstantString"

Check failure on line 114 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:114:27: error: code should be clang-formatted [-Wclang-format-violations]
};

static bool kscm_nsexception_detected(const char* exception_name)

Check failure on line 117 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:117:49: error: code should be clang-formatted [-Wclang-format-violations]

Check failure on line 117 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:117:50: error: code should be clang-formatted [-Wclang-format-violations]
{
if (exception_name == NULL) return false;

Check failure on line 119 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:119:46: error: code should be clang-formatted [-Wclang-format-violations]

size_t num = sizeof(kscm_nsexception_names) / sizeof(kscm_nsexception_names[0]);
for (size_t i = 0; i < num; i++) {
if (strcmp(exception_name, kscm_nsexception_names[i]) == 0) {
return true;
}
}

Check failure on line 126 in Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp

View workflow job for this annotation

GitHub Actions / Formatting Check

Sources/KSCrashRecording/Monitors/KSCrashMonitor_CPPException.cpp:126:6: error: code should be clang-formatted [-Wclang-format-violations]

return false;
}

static void CPPExceptionTerminate(void)
{
thread_act_array_t threads = NULL;
Expand All @@ -120,7 +140,7 @@ static void CPPExceptionTerminate(void)
name = tinfo->name();
}

if (name == NULL || strcmp(name, "NSException") != 0) {
if (kscm_nsexception_detected(name) == false) {
kscm_notifyFatalExceptionCaptured(false);
KSCrash_MonitorContext *crashContext = &g_monitorContext;
memset(crashContext, 0, sizeof(*crashContext));
Expand Down

0 comments on commit 5e1c130

Please sign in to comment.