backtrace task finished

This commit is contained in:
2025-06-14 17:09:29 +08:00
parent b63d0c9147
commit 4c08583743
5 changed files with 31 additions and 1 deletions

View File

@ -343,7 +343,7 @@ grade:
@echo $(MAKE) clean
@$(MAKE) clean || \
(echo "'make clean' failed. HINT: Do you have another running instance of xv6?" && exit 1)
./grade-lab-$(LAB) $(GRADEFLAGS)
python3.12 ./grade-lab-$(LAB) $(GRADEFLAGS)
##
## FOR submissions

View File

@ -80,6 +80,7 @@ int pipewrite(struct pipe*, uint64, int);
int printf(char*, ...) __attribute__ ((format (printf, 1, 2)));
void panic(char*) __attribute__((noreturn));
void printfinit(void);
void backtrace(void);
// proc.c
int cpuid(void);

View File

@ -176,3 +176,22 @@ printfinit(void)
initlock(&pr.lock, "pr");
pr.locking = 1;
}
void
backtrace(void)
{
printf("barcktrace:\n");
uint64 ra,fp = r_fp();//frame pointer -> address
uint64 pre_fp = *((uint64*)(fp - 16));
while(PGROUNDDOWN(fp)==PGROUNDDOWN(pre_fp)){
ra = *(uint64 *)(fp - 8);
printf("%p\n", (void*)ra);
fp = pre_fp;
pre_fp = *((uint64*)(fp - 16));
}
ra = *(uint64 *)(fp - 8);
printf("%p\n",(void*)ra);
}

View File

@ -338,6 +338,14 @@ r_ra()
return x;
}
static inline uint64
r_fp()
{
uint64 x;
asm volatile("mv %0, s0" : "=r" (x) );
return x;
}
// flush the TLB.
static inline void
sfence_vma()

View File

@ -54,6 +54,8 @@ sys_sleep(void)
int n;
uint ticks0;
backtrace();
argint(0, &n);
if(n < 0)
n = 0;