From ad48c32e1e64462a82d0cd24b0aa256b8b3a2b6b Mon Sep 17 00:00:00 2001 From: Arvid Gerstmann Date: Sat, 14 Jul 2018 11:08:17 +0200 Subject: [PATCH] Support for callstacks on Linux without glibc --- client/TracyCallstack.cpp | 10 +++++----- client/TracyCallstack.hpp | 21 +++++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index 94a5afd4..8e549b65 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -3,10 +3,10 @@ #ifdef TRACY_HAS_CALLSTACK -#if defined _WIN32 || defined __CYGWIN__ +#if TRACY_HAS_CALLSTACK == 1 # include # include -#elif defined _GNU_SOURCE +#elif TRACY_HAS_CALLSTACK >= 2 # include # include #endif @@ -14,7 +14,7 @@ namespace tracy { -#if defined _WIN32 || defined __CYGWIN__ +#if TRACY_HAS_CALLSTACK == 1 extern "C" t_RtlWalkFrameChain RtlWalkFrameChain = 0; @@ -77,7 +77,7 @@ CallstackEntry DecodeCallstackPtr( uint64_t ptr ) return ret; } -#elif defined __ANDROID__ +#elif TRACY_HAS_CALLSTACK == 2 CallstackEntry DecodeCallstackPtr( uint64_t ptr ) { @@ -156,7 +156,7 @@ CallstackEntry DecodeCallstackPtr( uint64_t ptr ) return ret; } -#elif defined _GNU_SOURCE +#elif TRACY_HAS_CALLSTACK == 3 CallstackEntry DecodeCallstackPtr( uint64_t ptr ) { diff --git a/client/TracyCallstack.hpp b/client/TracyCallstack.hpp index 0f46ebc1..c9a4b235 100644 --- a/client/TracyCallstack.hpp +++ b/client/TracyCallstack.hpp @@ -2,18 +2,23 @@ #define __TRACYCALLSTACK_HPP__ #if defined _WIN32 || defined __CYGWIN__ -# define TRACY_HAS_CALLSTACK +# define TRACY_HAS_CALLSTACK 1 extern "C" { typedef unsigned long (__stdcall *t_RtlWalkFrameChain)( void**, unsigned long, unsigned long ); extern t_RtlWalkFrameChain RtlWalkFrameChain; } #elif defined __ANDROID__ -# define TRACY_HAS_CALLSTACK +# define TRACY_HAS_CALLSTACK 2 # include -#elif defined _GNU_SOURCE -# define TRACY_HAS_CALLSTACK -# include +#elif defined __linux +# if defined _GNU_SOURCE && defined __has_include && __has_include() +# define TRACY_HAS_CALLSTACK 3 +# include +# elif defined __has_include && __has_include() +# define TRACY_HAS_CALLSTACK 2 +# include +# endif #endif @@ -38,7 +43,7 @@ struct CallstackEntry CallstackEntry DecodeCallstackPtr( uint64_t ptr ); -#if defined _WIN32 || defined __CYGWIN__ +#if TRACY_HAS_CALLSTACK == 1 void InitCallstack(); @@ -53,7 +58,7 @@ static tracy_force_inline void* Callstack( int depth ) return trace; } -#elif defined __ANDROID__ +#elif TRACY_HAS_CALLSTACK == 2 static tracy_force_inline void InitCallstack() {} @@ -88,7 +93,7 @@ static tracy_force_inline void* Callstack( int depth ) return trace; } -#elif defined _GNU_SOURCE +#elif TRACY_HAS_CALLSTACK == 3 static tracy_force_inline void InitCallstack() {}