10 # include <execinfo.h> 11 # include <sys/syscall.h> 12 # include <ucontext.h> 14 # define UNW_LOCAL_ONLY 15 # include <libunwind.h> 19 extern "C" void _sigtramp(
void );
24 #if !defined MAP_ANONYMOUS && defined MAP_ANON 25 # define MAP_ANONYMOUS MAP_ANON 35 #if 0 && __x86_64__ && __linux 64 struct IgHookTraceArgs
80 static _Unwind_Reason_Code
81 GCCBackTrace (_Unwind_Context *context,
void *arg)
83 IgHookTraceArgs *
args = (IgHookTraceArgs *) arg;
84 if (args->stack.top < 0 || args->stack.top >= args->stack.size)
85 return _URC_END_OF_STACK;
87 args->stack.addresses [args->stack.top++] = (
void *) _Unwind_GetIP (context);
88 args->prevframe = (
void **) _Unwind_GetCFA (context);
89 return _URC_NO_REASON;
110 size_t psize = getpagesize();
111 size_t hunk = psize * 20;
112 if ( hunk < bytes ) hunk = ( hunk + psize - 1 ) & ~( psize - 1 );
113 void* addr = mmap( 0, hunk, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 );
114 if ( addr == MAP_FAILED )
return 0;
130 return alloc ? alloc->allocate( n ) : ::operator
new(
n );
134 unsigned long long value )
135 : m_counter( counter ), m_next( next ), m_value( value ), m_count( 0 ) {}
193 return alloc ? alloc->allocate( n ) : ::operator
new(
n );
215 liboffset = (
unsigned long)address;
218 if ( dladdr( address, &info ) ) {
219 if ( info.dli_fname && info.dli_fname[0] ) lib = info.dli_fname;
221 if ( info.dli_fbase ) liboffset = (
unsigned long)address - (
unsigned long)info.dli_fbase;
223 if ( info.dli_saddr ) offset = (
unsigned long)address - (
unsigned long)info.dli_saddr;
225 if ( info.dli_sname && info.dli_sname[0] ) sym = info.dli_sname;
239 return ( dladdr( address, &info ) && info.dli_fname && info.dli_fname[0] && info.dli_saddr ) ? info.dli_saddr
CounterValue * next(void)
static void * tosymbol(void *address)
IgHookTrace * parent(void)
unsigned long long untick(void)
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
unsigned long long add(unsigned long long value)
unsigned long long tick(void)
Value for a counter chained from a trace.
static bool symbol(void *address, const char *&sym, const char *&lib, int &offset, int &liboffset)
unsigned long long max(unsigned long long value)
unsigned long long value(void)
unsigned long long m_value
unsigned long long sub(unsigned long long value)
Nearly dummy object type to identify a counter.
CounterValue(Counter *counter, CounterValue *next=0, unsigned long long value=0)
unsigned long long m_count
CounterValue * m_counters
IgHookTraceAlloc * m_alloc
unsigned long long count(void)
IgHookTrace(IgHookTrace *parent=0, void *address=0)
void * allocate(size_t bytes)