🐛 修复traceback终点判断的bug

This commit is contained in:
fslongjin 2022-06-23 11:44:42 +08:00
parent 1ab51cb334
commit 325bc981fe
2 changed files with 6 additions and 4 deletions

View File

@ -51,14 +51,16 @@ void traceback(struct pt_regs *regs)
// 最大追踪10层调用栈
for (int i = 0; i < 10; ++i)
{
printk_color(ORANGE, BLACK, "rbp:%#018lx,*rbp:%#018lx\n", rbp, *rbp);
if (lookup_kallsyms(ret_addr, i) != 0)
break;
// 由于内核栈大小32K因此当前rbp的值为按照32K对齐时表明调用栈已经到头了追踪结束。
if (((*rbp) & (~STACK_SIZE)) == 0)
// 当前栈帧的rbp的地址大于等于内核栈的rbp的时候表明调用栈已经到头了追踪结束。
// 当前rbp的地址为用户空间时直接退出
if((uint64_t)(rbp) >= current_pcb->thread->rbp || ((uint64_t)rbp<regs->rsp))
break;
printk_color(ORANGE, BLACK, "rbp:%#018lx,*rbp:%#018lx\n", rbp, *rbp);
// 由于x86处理器在执行call指令时先将调用返回地址压入栈中然后再把函数的rbp入栈最后将rsp设为新的rbp。
// 因此此处的rbp就是上一层的rsp那么*(rbp+1)得到的就是上一层函数的返回地址
ret_addr = *(rbp + 1);

View File

@ -73,7 +73,7 @@ int main()
int kb_fd = open(kb_file_path, 0);
// printf("keyboard fd = %d\n", kb_fd);
print_ascii_logo();
int a = 1/0;
main_loop(kb_fd);
while (1)
;