Merged in tillrathmann/tracy (pull request #33)

Fixed DLL support
This commit is contained in:
Till Rathmann 2019-02-20 17:24:12 +00:00 committed by Bartosz Taudul
commit 9d7c4a2861
4 changed files with 58 additions and 49 deletions

View File

@ -59,14 +59,17 @@ namespace tracy
#endif
#ifdef TRACY_COLLECT_THREAD_NAMES
DLL_IMPORT std::atomic<ThreadNameData*>& get_threadnamedata();
DLL_IMPORT std::atomic<ThreadNameData*>&(*get_getthreadnamedata())();
DLL_IMPORT void(*get_rpmalloc_thread_initialize())();
DLL_IMPORT void(*get_InitRPMallocThread())();
static std::atomic<ThreadNameData*>&(*GetThreadNameData_fpt)() = get_getthreadnamedata();
static void(*rpmalloc_thread_initialize_fpt)() = get_rpmalloc_thread_initialize();
static void(*InitRPMallocThread_fpt)() = get_InitRPMallocThread();
std::atomic<ThreadNameData*>& GetThreadNameData() { return GetThreadNameData_fpt(); }
void rpmalloc_thread_initialize(void) { rpmalloc_thread_initialize_fpt(); }
void InitRPMallocThread() { InitRPMallocThread_fpt(); }
#endif
#ifdef TRACY_ON_DEMAND

View File

@ -49,7 +49,8 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
const auto proc = GetCurrentProcess();
#ifndef __CYGWIN__
const auto inlineNum = std::min<DWORD>( MaxCbTrace - 1, SymAddrIncludeInlineTrace( proc, ptr ) );
DWORD ctx, idx;
DWORD ctx = 0;
DWORD idx;
BOOL doInline = FALSE;
if( inlineNum != 0 ) doInline = SymQueryInlineTrace( proc, ptr, 0, ptr, ptr, &ctx, &idx );
if( doInline )
@ -75,33 +76,36 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
si->NameLen = 9;
}
auto name = (char*)tracy_malloc( si->NameLen + 1 );
memcpy( name, si->Name, si->NameLen );
name[si->NameLen] = '\0';
cb_data[write].name = name;
const char* filename;
IMAGEHLP_LINE64 line;
DWORD displacement = 0;
line.SizeOfStruct = sizeof( IMAGEHLP_LINE64 );
if( SymGetLineFromAddr64( proc, ptr, &displacement, &line ) == 0 )
{
filename = "[unknown]";
cb_data[write].line = 0;
}
else
{
filename = line.FileName;
cb_data[write].line = line.LineNumber;
}
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
const auto fsz = strlen( filename );
auto file = (char*)tracy_malloc( fsz + 1 );
memcpy( file, filename, fsz );
file[fsz] = '\0';
{
auto name = (char*)tracy_malloc(si->NameLen + 1);
memcpy(name, si->Name, si->NameLen);
name[si->NameLen] = '\0';
cb_data[write].file = file;
cb_data[write].name = name;
const char* filename;
if (SymGetLineFromAddr64(proc, ptr, &displacement, &line) == 0)
{
filename = "[unknown]";
cb_data[write].line = 0;
}
else
{
filename = line.FileName;
cb_data[write].line = line.LineNumber;
}
const auto fsz = strlen(filename);
auto file = (char*)tracy_malloc(fsz + 1);
memcpy(file, filename, fsz);
file[fsz] = '\0';
cb_data[write].file = file;
}
#ifndef __CYGWIN__
if( doInline )
@ -121,6 +125,7 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
name[si->NameLen] = '\0';
cb.name = name;
const char* filename;
if( SymGetLineFromInlineContext( proc, ptr, ctx, 0, &displacement, &line ) == 0 )
{
filename = "[unknown]";
@ -257,7 +262,7 @@ static inline char* CopyString( const char* src )
return dst;
}
static int CallstackDataCb( void* data, uintptr_t pc, const char* fn, int lineno, const char* function )
static int CallstackDataCb( void* /*data*/, uintptr_t pc, const char* fn, int lineno, const char* function )
{
enum { DemangleBufLen = 64*1024 };
char demangled[DemangleBufLen];
@ -354,7 +359,7 @@ static int CallstackDataCb( void* data, uintptr_t pc, const char* fn, int lineno
}
}
static void CallstackErrorCb( void* data, const char* msg, int errnum )
static void CallstackErrorCb( void* /*data*/, const char* /*msg*/, int /*errnum*/ )
{
for( int i=0; i<cb_num; i++ )
{

View File

@ -95,9 +95,9 @@ namespace tracy
namespace
{
BOOL CALLBACK InitOnceCallback(
PINIT_ONCE initOnce,
PVOID Parameter,
PVOID *Context)
PINIT_ONCE /*initOnce*/,
PVOID /*Parameter*/,
PVOID* /*Context*/)
{
rpmalloc_initialize();
return TRUE;
@ -412,13 +412,13 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
switch( pExp->ExceptionRecord->ExceptionInformation[0] )
{
case 0:
msgPtr += sprintf( msgPtr, "Read violation at address 0x%" PRIxMAX ".", pExp->ExceptionRecord->ExceptionInformation[1] );
msgPtr += sprintf( msgPtr, "Read violation at address 0x%" PRIxPTR ".", pExp->ExceptionRecord->ExceptionInformation[1] );
break;
case 1:
msgPtr += sprintf( msgPtr, "Write violation at address 0x%" PRIxMAX ".", pExp->ExceptionRecord->ExceptionInformation[1] );
msgPtr += sprintf( msgPtr, "Write violation at address 0x%" PRIxPTR ".", pExp->ExceptionRecord->ExceptionInformation[1] );
break;
case 8:
msgPtr += sprintf( msgPtr, "DEP violation at address 0x%" PRIxMAX ".", pExp->ExceptionRecord->ExceptionInformation[1] );
msgPtr += sprintf( msgPtr, "DEP violation at address 0x%" PRIxPTR ".", pExp->ExceptionRecord->ExceptionInformation[1] );
break;
default:
break;
@ -519,7 +519,7 @@ static long s_profilerTid = 0;
static char s_crashText[1024];
static std::atomic<bool> s_alreadyCrashed( false );
static void ThreadFreezer( int signal )
static void ThreadFreezer( int /*signal*/ )
{
for(;;) sleep( 1000 );
}
@ -550,7 +550,7 @@ static inline void HexPrint( char*& ptr, uint64_t val )
while( bptr != buf );
}
static void CrashHandler( int signal, siginfo_t* info, void* ucontext )
static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
{
bool expected = false;
if( !s_alreadyCrashed.compare_exchange_strong( expected, true ) ) ThreadFreezer( signal );
@ -905,8 +905,9 @@ DLL_EXPORT int64_t(*get_GetTimeImpl())() { return GetTimeImpl; }
#endif
#ifdef TRACY_COLLECT_THREAD_NAMES
DLL_EXPORT std::atomic<ThreadNameData*>&(*get_threadnamedata())() { return GetThreadNameData; }
DLL_EXPORT std::atomic<ThreadNameData*>&(*get_getthreadnamedata())() { return GetThreadNameData; }
DLL_EXPORT void(*get_rpmalloc_thread_initialize())() { return rpmalloc_thread_initialize; }
DLL_EXPORT void(*get_InitRPMallocThread())() { return InitRPMallocThread; }
#endif
#ifdef TRACY_ON_DEMAND

View File

@ -850,10 +850,10 @@ read_attribute (enum dwarf_form form, struct dwarf_buf *buf,
return 1;
case DW_FORM_indirect:
{
uint64_t form;
uint64_t form2;
form = read_uleb128 (buf);
return read_attribute ((enum dwarf_form) form, buf, is_dwarf64,
form2 = read_uleb128 (buf);
return read_attribute ((enum dwarf_form) form2, buf, is_dwarf64,
version, addrsize, dwarf_str, dwarf_str_size,
val);
}
@ -2855,22 +2855,22 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata,
if (entry->u->abs_filename == NULL)
{
const char *filename;
const char *filename2;
filename = entry->u->filename;
if (filename != NULL
&& !IS_ABSOLUTE_PATH (filename)
filename2 = entry->u->filename;
if (filename2 != NULL
&& !IS_ABSOLUTE_PATH (filename2)
&& entry->u->comp_dir != NULL)
{
size_t filename_len;
size_t filename2_len;
const char *dir;
size_t dir_len;
char *s;
filename_len = strlen (filename);
filename2_len = strlen (filename2);
dir = entry->u->comp_dir;
dir_len = strlen (dir);
s = (char *) backtrace_alloc (state, dir_len + filename_len + 2,
s = (char *) backtrace_alloc (state, dir_len + filename2_len + 2,
error_callback, data);
if (s == NULL)
{
@ -2880,10 +2880,10 @@ dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata,
memcpy (s, dir, dir_len);
/* FIXME: Should use backslash if DOS file system. */
s[dir_len] = '/';
memcpy (s + dir_len + 1, filename, filename_len + 1);
filename = s;
memcpy (s + dir_len + 1, filename2, filename2_len + 1);
filename2 = s;
}
entry->u->abs_filename = filename;
entry->u->abs_filename = filename2;
}
return callback (data, pc, entry->u->abs_filename, 0, NULL);