tracy/client/TracyCallstack.hpp

57 lines
1.2 KiB
C++
Raw Normal View History

2018-06-18 23:17:19 +00:00
#ifndef __TRACYCALLSTACK_HPP__
#define __TRACYCALLSTACK_HPP__
2018-06-19 17:49:21 +00:00
#if defined _WIN32 || defined __CYGWIN__
2018-06-18 23:17:19 +00:00
# define TRACY_HAS_CALLSTACK
# ifndef MAXLONG
2018-06-19 17:49:21 +00:00
# ifdef __CYGWIN__
extern "C" __declspec(dllimport) unsigned short __stdcall RtlCaptureStackBackTrace( unsigned int, unsigned int, void**, unsigned int* );
# else
2018-06-18 23:17:19 +00:00
extern "C" __declspec(dllimport) unsigned short __stdcall RtlCaptureStackBackTrace( unsigned long, unsigned long, void**, unsigned long* );
2018-06-19 17:49:21 +00:00
# endif
2018-06-18 23:17:19 +00:00
# endif
#endif
#ifdef TRACY_HAS_CALLSTACK
2018-06-19 16:49:13 +00:00
#include <assert.h>
2018-06-18 23:17:19 +00:00
#include <stdint.h>
#include <string.h>
#include "../common/TracyAlloc.hpp"
#include "../common/TracyForceInline.hpp"
namespace tracy
{
struct CallstackEntry
{
const char* name;
const char* file;
uint32_t line;
};
2018-06-19 17:49:21 +00:00
#if defined _WIN32 || defined __CYGWIN__
2018-06-18 23:17:19 +00:00
void InitCallstack();
CallstackEntry DecodeCallstackPtr( uint64_t ptr );
2018-06-19 16:49:13 +00:00
static tracy_force_inline void* Callstack( int depth )
2018-06-18 23:17:19 +00:00
{
2018-06-19 16:49:13 +00:00
assert( depth >= 1 && depth <= 63 );
2018-06-18 23:17:19 +00:00
2018-06-19 16:49:13 +00:00
auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) );
const auto num = RtlCaptureStackBackTrace( 0, depth, (void**)( trace+1 ), nullptr );
2018-06-18 23:17:19 +00:00
*trace = num;
2018-06-19 15:27:03 +00:00
return trace;
2018-06-18 23:17:19 +00:00
}
#endif
}
#endif
#endif