// 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 f4(void) { int status; int foo[10]; f5(foo); uwx_self_init_context(uenv); printf("In f4():\n"); dump_context((uint64_t *)uenv); for (;;) { status = uwx_step(uenv); printf("uwx_step returned %d\n", status); if (status != UWX_OK) break; printf("After step:\n"); dump_context((uint64_t *)uenv); } return 0; }