From 5fb8b38f3a6497dc739971a19b803d9d2f104c52 Mon Sep 17 00:00:00 2001 From: Blake Taylor Date: Tue, 26 Apr 2022 21:19:56 -0700 Subject: [PATCH 1/2] Add flag to disable crash handler --- client/TracyProfiler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index a9f674bd..db0d9c00 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -738,7 +738,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz, return msg; } -#if defined _WIN32 && !defined TRACY_UWP +#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER static DWORD s_profilerThreadId = 0; static char s_crashText[1024]; @@ -847,7 +847,7 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp ) } #endif -#ifdef __linux__ +#ifdef __linux__ && !defined TRACY_NO_CRASH_HANDLER # ifndef TRACY_CRASH_SIGNAL # define TRACY_CRASH_SIGNAL SIGPWR # endif @@ -1416,12 +1416,12 @@ void Profiler::SpawnWorkerThreads() new(s_symbolThread) Thread( LaunchSymbolWorker, this ); #endif -#if defined _WIN32 && !defined TRACY_UWP +#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER s_profilerThreadId = GetThreadId( s_thread->Handle() ); m_exceptionHandler = AddVectoredExceptionHandler( 1, CrashFilter ); #endif -#ifdef __linux__ +#if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER struct sigaction threadFreezer = {}; threadFreezer.sa_handler = ThreadFreezer; sigaction( TRACY_CRASH_SIGNAL, &threadFreezer, &m_prevSignal.pwr ); @@ -1437,7 +1437,9 @@ void Profiler::SpawnWorkerThreads() sigaction( SIGABRT, &crashHandler, &m_prevSignal.abrt ); #endif +#ifndef TRACY_NO_CRASH_HANDLER m_crashHandlerInstalled = true; +#endif #ifdef TRACY_HAS_CALLSTACK InitCallstack(); From 8c5120ee5a8262dd1ecff515af4db9499b2bab91 Mon Sep 17 00:00:00 2001 From: Blake Taylor Date: Tue, 26 Apr 2022 21:19:56 -0700 Subject: [PATCH 2/2] Add flag to disable crash handler --- CMakeLists.txt | 1 + client/TracyProfiler.cpp | 10 ++++++---- manual/tracy.tex | 2 +- meson.build | 4 ++++ meson_options.txt | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40aed1fe..3b590358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ set_option(TRACY_NO_SYS_TRACE "Disable systrace sampling" OFF) set_option(TRACY_DELAYED_INIT "Enable delayed initialization of the library (init on first call)" OFF) set_option(TRACY_MANUAL_LIFETIME "Enable the manual lifetime management of the profile" OFF) set_option(TRACY_FIBERS "Enable fibers support" OFF) +set_option(TRACY_NO_CRASH_HANDLER, "Disable crash handling" OFF) if(BUILD_SHARED_LIBS) target_compile_definitions(TracyClient PRIVATE TRACY_EXPORTS) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index a9f674bd..db0d9c00 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -738,7 +738,7 @@ static BroadcastMessage& GetBroadcastMessage( const char* procname, size_t pnsz, return msg; } -#if defined _WIN32 && !defined TRACY_UWP +#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER static DWORD s_profilerThreadId = 0; static char s_crashText[1024]; @@ -847,7 +847,7 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp ) } #endif -#ifdef __linux__ +#ifdef __linux__ && !defined TRACY_NO_CRASH_HANDLER # ifndef TRACY_CRASH_SIGNAL # define TRACY_CRASH_SIGNAL SIGPWR # endif @@ -1416,12 +1416,12 @@ void Profiler::SpawnWorkerThreads() new(s_symbolThread) Thread( LaunchSymbolWorker, this ); #endif -#if defined _WIN32 && !defined TRACY_UWP +#if defined _WIN32 && !defined TRACY_UWP && !defined TRACY_NO_CRASH_HANDLER s_profilerThreadId = GetThreadId( s_thread->Handle() ); m_exceptionHandler = AddVectoredExceptionHandler( 1, CrashFilter ); #endif -#ifdef __linux__ +#if defined __linux__ && !defined TRACY_NO_CRASH_HANDLER struct sigaction threadFreezer = {}; threadFreezer.sa_handler = ThreadFreezer; sigaction( TRACY_CRASH_SIGNAL, &threadFreezer, &m_prevSignal.pwr ); @@ -1437,7 +1437,9 @@ void Profiler::SpawnWorkerThreads() sigaction( SIGABRT, &crashHandler, &m_prevSignal.abrt ); #endif +#ifndef TRACY_NO_CRASH_HANDLER m_crashHandlerInstalled = true; +#endif #ifdef TRACY_HAS_CALLSTACK InitCallstack(); diff --git a/manual/tracy.tex b/manual/tracy.tex index 23c9a2e3..c6e49b1b 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -803,7 +803,7 @@ Tracy will try to capture thread names through operating system data if context On selected platforms (see section~\ref{featurematrix}) Tracy will intercept application crashes\footnote{For example, invalid memory accesses ('segmentation faults', 'null pointer exceptions'), divisions by zero, etc.}. This serves two purposes. First, the client application will be able to send the remaining profiling data to the server. Second, the server will receive a crash report with the crash reason, call stack at the time of the crash, etc. -This is an automatic process, and it doesn't require user interaction. +This is an automatic process, and it doesn't require user interaction. If you are experiencing issues with crash handling you may want to try defining the \texttt{TRACY\_NO\_CRASH\_HANDLER} macro to disable the built in crash handling. \begin{bclogo}[ noborder=true, diff --git a/meson.build b/meson.build index 55834747..9c343001 100644 --- a/meson.build +++ b/meson.build @@ -81,6 +81,10 @@ if tracy_shared_libs add_project_arguments('-DTRACY_EXPORTS', language : 'cpp') endif +if get_option('tracy_no_crash_handler') + add_project_arguments('-DTRACY_NO_CRASH_HANDLER', language : 'cpp') +endif + threads_dep = dependency('threads') includes = [ diff --git a/meson_options.txt b/meson_options.txt index 5d6f42ce..ddf950ee 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -18,3 +18,4 @@ option('tracy_delayed_init', type : 'boolean', value : false, description : 'Ena option('tracy_manual_lifetime', type : 'boolean', value : false, description : 'Enable the manual lifetime management of the profile') option('tracy_fibers', type : 'boolean', value : false, description : 'Enable fibers support') option('tracy_shared_libs', type : 'boolean', value : false, description : 'Builds Tracy as a shared object') +option('tracy_no_crash_handler', type : 'boolean', value : false, description : 'Disable crash handling')