// FIXME: There should be a destructor for this function to free env and info void GetBackTrace(address_t* ipStackBuffer, int iTotalDepth, int iSkipLevel) { uint64_t ip; int status; int index = 0; int nPos = 0; if (!env) { env = uwx_init(); info = uwx_self_init_info(env); status = uwx_register_callbacks(env, (intptr_t)info, uwx_self_copyin, uwx_self_lookupip); if (status != UWX_OK) { env = NULL; return ; } } status = uwx_self_init_context(env); if (status != UWX_OK) { //hk_printf("uwx_self_init_context() error\n"); return ; } for(;;) { if (index >= iTotalDepth) break; if (nPos++ >= iSkipLevel + iTotalDepth) break; status = uwx_get_reg(env, UWX_REG_IP, &ip); if (status != UWX_OK) break; if (nPos > iSkipLevel) ipStackBuffer[index++] = (address_t)ip; status = uwx_step(env); if (status != UWX_OK) break; } // seal the array if(index < iTotalDepth) { ipStackBuffer[index] = 0; } return ; }
int main(int argc, char **argv) { int status; unsigned int *wp; uenv = uwx_init(); printf("uwx_init returned %08x\n", uenv); cbinfo = uwx_self_init_info(uenv); status = uwx_register_callbacks( uenv, (intptr_t)cbinfo, uwx_self_copyin, uwx_self_lookupip); printf("uwx_register_callbacks returned %d\n", status); uwx_self_init_context(uenv); printf("In main():\n"); dump_context((uint64_t *)uenv); (void) f1(); uwx_free(uenv); return 0; }