From c8f51d7f1164831a2f7645b63f42a2a4110e9dba Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 20 Jun 2018 22:54:42 +0200 Subject: [PATCH] More involved callstack frame description on linux. --- client/TracyCallstack.cpp | 44 +++++++++++++++++++++++++++------------ test/Makefile | 2 +- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index f21e857b..201c4a0a 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -5,6 +5,8 @@ #if defined _WIN32 || defined __CYGWIN__ # include # include +#elif defined _GNU_SOURCE +# include #endif namespace tracy @@ -71,32 +73,48 @@ CallstackEntry DecodeCallstackPtr( uint64_t ptr ) CallstackEntry DecodeCallstackPtr( uint64_t ptr ) { CallstackEntry ret; + ret.line = 0; - const char* symname; + const char* symname = nullptr; + const char* symloc = nullptr; auto vptr = (void*)ptr; - auto sym = backtrace_symbols( &vptr, 1 ); - if( !sym ) + char** sym = nullptr; + + 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 ); 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; + const auto loclen = strlen( symloc ); + auto loc = (char*)tracy_malloc( loclen + 1 ); + memcpy( loc, symloc, loclen ); + loc[loclen] = '\0'; + ret.file = loc; if( sym ) free( sym ); diff --git a/test/Makefile b/test/Makefile index b9d72bb2..5d9d4690 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ CFLAGS := $(OPTFLAGS) -Wall -DTRACY_ENABLE -rdynamic CXXFLAGS := $(CFLAGS) -std=gnu++17 DEFINES += INCLUDES := -LIBS := -lpthread +LIBS := -lpthread -ldl IMAGE := tracy_test SRC := \