More involved callstack frame description on linux.

This commit is contained in:
Bartosz Taudul 2018-06-20 22:54:42 +02:00
parent 36d81412a0
commit c8f51d7f11
2 changed files with 32 additions and 14 deletions

View File

@ -5,6 +5,8 @@
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
# include <windows.h> # include <windows.h>
# include <dbghelp.h> # include <dbghelp.h>
#elif defined _GNU_SOURCE
# include <dlfcn.h>
#endif #endif
namespace tracy namespace tracy
@ -71,32 +73,48 @@ CallstackEntry DecodeCallstackPtr( uint64_t ptr )
CallstackEntry DecodeCallstackPtr( uint64_t ptr ) CallstackEntry DecodeCallstackPtr( uint64_t ptr )
{ {
CallstackEntry ret; CallstackEntry ret;
ret.line = 0;
const char* symname; const char* symname = nullptr;
const char* symloc = nullptr;
auto vptr = (void*)ptr; auto vptr = (void*)ptr;
auto sym = backtrace_symbols( &vptr, 1 ); char** sym = nullptr;
if( !sym )
Dl_info dlinfo;
if( dladdr( vptr, &dlinfo ) )
{ {
symname = "[unknown]"; symloc = dlinfo.dli_fname;
symname = dlinfo.dli_sname;
} }
else
if( !symname )
{ {
symname = *sym; sym = backtrace_symbols( &vptr, 1 );
if( !sym )
{
symname = "[unknown]";
}
else
{
symname = *sym;
}
}
if( !symloc )
{
symloc = "[unknown]";
} }
const auto namelen = strlen( symname ); const auto namelen = strlen( symname );
auto name = (char*)tracy_malloc( namelen + 1 ); auto name = (char*)tracy_malloc( namelen + 1 );
memcpy( name, symname, namelen ); memcpy( name, symname, namelen );
name[namelen] = '\0'; name[namelen] = '\0';
ret.name = name; ret.name = name;
auto unknown = (char*)tracy_malloc( 10 ); const auto loclen = strlen( symloc );
memcpy( unknown, "[unknown]", 9 ); auto loc = (char*)tracy_malloc( loclen + 1 );
unknown[9] = '\0'; memcpy( loc, symloc, loclen );
loc[loclen] = '\0';
ret.file = unknown; ret.file = loc;
ret.line = 0;
if( sym ) free( sym ); if( sym ) free( sym );

View File

@ -3,7 +3,7 @@ CFLAGS := $(OPTFLAGS) -Wall -DTRACY_ENABLE -rdynamic
CXXFLAGS := $(CFLAGS) -std=gnu++17 CXXFLAGS := $(CFLAGS) -std=gnu++17
DEFINES += DEFINES +=
INCLUDES := INCLUDES :=
LIBS := -lpthread LIBS := -lpthread -ldl
IMAGE := tracy_test IMAGE := tracy_test
SRC := \ SRC := \