#include #define UNW_LOCAL_ONLY #include #define NOINLINE __attribute__((noinline)) void show_backtrace (void) { void* pc0 = __builtin_return_address(0); printf( "Backtracing %08x\n", pc0 ); unw_cursor_t cursor; unw_context_t uc; unw_word_t ip, sp; unw_getcontext(&uc); unw_init_local(&cursor, &uc); while (unw_step(&cursor) > 0) { unw_get_reg(&cursor, UNW_REG_IP, &ip); unw_get_reg(&cursor, UNW_REG_SP, &sp); printf ("ip = %lx, sp = %lx\n", (long) ip, (long) sp); } } void f( int i ); void NOINLINE another( int i ) { printf( "calling f\n"); f( i ); } void NOINLINE f( int i ) { printf( "eek %d\n", i ); if( i > 0 ) f( i -1 ); else show_backtrace(); } int main( int argc, char** argv ) { printf( "hello world\n" ); f( 10 ); another( 5 ); pause(); return 0; }