mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 20:33:52 +00:00
Linux callstack retrieval.
This commit is contained in:
parent
dc20742b5b
commit
5541cd6c97
@ -10,6 +10,8 @@
|
|||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
|
|
||||||
void InitCallstack()
|
void InitCallstack()
|
||||||
{
|
{
|
||||||
SymInitialize( GetCurrentProcess(), nullptr, true );
|
SymInitialize( GetCurrentProcess(), nullptr, true );
|
||||||
@ -64,6 +66,44 @@ CallstackEntry DecodeCallstackPtr( uint64_t ptr )
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined _GNU_SOURCE
|
||||||
|
|
||||||
|
CallstackEntry DecodeCallstackPtr( uint64_t ptr )
|
||||||
|
{
|
||||||
|
CallstackEntry ret;
|
||||||
|
|
||||||
|
const char* symname;
|
||||||
|
auto vptr = (void*)ptr;
|
||||||
|
auto sym = backtrace_symbols( &vptr, 1 );
|
||||||
|
if( !sym )
|
||||||
|
{
|
||||||
|
symname = "[unknown]";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
symname = *sym;
|
||||||
|
free( sym );
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto namelen = strlen( symname );
|
||||||
|
auto name = (char*)tracy_malloc( namelen + 1 );
|
||||||
|
memcpy( name, symname, namelen );
|
||||||
|
name[namelen] = '\0';
|
||||||
|
|
||||||
|
ret.name = name;
|
||||||
|
|
||||||
|
auto unknown = (char*)tracy_malloc( 10 );
|
||||||
|
memcpy( unknown, "[unknown]", 9 );
|
||||||
|
unknown[9] = '\0';
|
||||||
|
|
||||||
|
ret.file = unknown;
|
||||||
|
ret.line = 0;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,8 +10,12 @@ extern "C" __declspec(dllimport) unsigned short __stdcall RtlCaptureStackBackTra
|
|||||||
extern "C" __declspec(dllimport) unsigned short __stdcall RtlCaptureStackBackTrace( unsigned long, unsigned long, void**, unsigned long* );
|
extern "C" __declspec(dllimport) unsigned short __stdcall RtlCaptureStackBackTrace( unsigned long, unsigned long, void**, unsigned long* );
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
#elif defined _GNU_SOURCE
|
||||||
|
# define TRACY_HAS_CALLSTACK
|
||||||
|
# include <execinfo.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef TRACY_HAS_CALLSTACK
|
#ifdef TRACY_HAS_CALLSTACK
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -31,10 +35,11 @@ struct CallstackEntry
|
|||||||
uint32_t line;
|
uint32_t line;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CallstackEntry DecodeCallstackPtr( uint64_t ptr );
|
||||||
|
|
||||||
#if defined _WIN32 || defined __CYGWIN__
|
#if defined _WIN32 || defined __CYGWIN__
|
||||||
|
|
||||||
void InitCallstack();
|
void InitCallstack();
|
||||||
CallstackEntry DecodeCallstackPtr( uint64_t ptr );
|
|
||||||
|
|
||||||
static tracy_force_inline void* Callstack( int depth )
|
static tracy_force_inline void* Callstack( int depth )
|
||||||
{
|
{
|
||||||
@ -47,6 +52,21 @@ static tracy_force_inline void* Callstack( int depth )
|
|||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined _GNU_SOURCE
|
||||||
|
|
||||||
|
static tracy_force_inline void InitCallstack() {}
|
||||||
|
|
||||||
|
static tracy_force_inline void* Callstack( int depth )
|
||||||
|
{
|
||||||
|
assert( depth >= 1 );
|
||||||
|
|
||||||
|
auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) );
|
||||||
|
const auto num = backtrace( (void**)(trace+1), depth );
|
||||||
|
*trace = num;
|
||||||
|
|
||||||
|
return trace;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user