int mon_backtrace(int argc, char **argv, struct Trapframe *tf) { // Your code here. uint64_t *rbp = (uint64_t *)read_rbp(); uint64_t rip; read_rip(rip); cprintf("Stack backtrace: \n"); do { cprintf("rbp %16.0x rip %16.0x\n", rbp, rip); struct Ripdebuginfo info; debuginfo_rip(rip, &info); //file name and line within that file of the stack frame's rip, followed by the name of the function and the offset of the rip from the first instruction of the function int offset=rip-info.rip_fn_addr; cprintf(" %s:%d: %s+%16.0x ",info.rip_file, info.rip_line, info.rip_fn_name,offset); cprintf("args:%x ",info.rip_fn_narg); //number of arguments int i; for(i = 1; i <= info.rip_fn_narg; i++) cprintf("%16.0x ", *((int *)(rbp) -i)); cprintf("\n"); rip = (uint64_t) *(rbp+1); rbp = (uint64_t *)(*rbp); } while (rbp!=0); return 0; }
int mon_backtrace(int argc, char **argv, struct Trapframe *tf) { // Your code here. uint64_t rbp = 0x0; uint64_t rip = 0x0; uint64_t* prbp = NULL; struct Ripdebuginfo info; cprintf("Stack backtrace:\n"); rbp = read_rbp(); read_rip(rip); if(rbp == 0x0 || rip == 0x0) { cprintf("Not able to show backtrace"); return -1; } prbp = (uint64_t*)(rbp); cprintf(" rbp %016x rip %016x\n", prbp, rip); debuginfo_rip(rip ,&info); cprintf(" %s:%d: ",info.rip_file, info.rip_line); cprintf("%.*s+%016x",info.rip_fn_namelen, info.rip_fn_name, (rip - info.rip_fn_addr)); cprintf(" args:%d", info.rip_fn_narg); printArgList(prbp, &info); while(prbp && *(prbp) != 0x0 && *(prbp+1) != 0x0) { cprintf(" rbp %016x rip %016x\n",*(prbp),*((prbp) +1)); debuginfo_rip(*(prbp+1) ,&info); cprintf(" %s:%d: ",info.rip_file, info.rip_line); cprintf("%.*s+%016x",info.rip_fn_namelen, info.rip_fn_name, (rip - info.rip_fn_addr)); cprintf(" args:%d", info.rip_fn_narg); printArgList((uint64_t*)(*(prbp)), &info); prbp = (uint64_t*)(*(prbp)); } return 0; }
int mon_backtrace(int argc, char **argv, struct Trapframe *tf) { // Your code here. cprintf("Stack backtrace:\n"); uint64_t stack_base_p = read_rbp(); uint64_t ret_inst_p; struct Ripdebuginfo rip_debug_info; read_rip(ret_inst_p); while(stack_base_p != 0) { cprintf("%5s %016x%5s %016x\n", "rbp", stack_base_p, "rip", ret_inst_p); if (debuginfo_rip(ret_inst_p, &rip_debug_info) == 0) { // Print th file name and line within that file of the stack frame's rip cprintf("%7s%s:%d: ", " ", rip_debug_info.rip_file, rip_debug_info.rip_line); // Print the name of the function cprintf("%.*s+", rip_debug_info.rip_fn_namelen, rip_debug_info.rip_fn_name); // Print the offset of the rip from the first instruction of the function cprintf("%016x", ret_inst_p - rip_debug_info.rip_fn_addr); // Print the number of function arguments cprintf(" args:%d ", rip_debug_info.rip_fn_narg); // Print the actual arguments themselves int arg_num; uint64_t arg_addr = stack_base_p; for (arg_num = 0; arg_num < rip_debug_info.rip_fn_narg; arg_num++) { arg_addr -= rip_debug_info.size_fn_arg[arg_num]; if (rip_debug_info.size_fn_arg[arg_num] == sizeof(uint32_t)) { cprintf(" %016x", *(uint32_t *)arg_addr); } else { arg_addr = arg_addr - arg_addr % 8; cprintf(" %016x", *(uint64_t *)arg_addr); } } cprintf("\n"); } ret_inst_p = *((uint64_t *)(stack_base_p + 1 * sizeof(uint64_t))); stack_base_p = *(uint64_t *)stack_base_p; } return 0; }