From: Ben Gras Date: Thu, 29 Jun 2006 13:35:27 +0000 (+0000) Subject: Make stack traces on exceptions possible. X-Git-Tag: v3.1.3~275 X-Git-Url: http://zhaoyanbai.com/repos/doc/static/gitweb.css?a=commitdiff_plain;h=f1222a09a60ae4ef107bb02a0f7fd8de7cd8319e;p=minix.git Make stack traces on exceptions possible. --- diff --git a/kernel/debug.h b/kernel/debug.h index 534ae06a5..7169559a4 100644 --- a/kernel/debug.h +++ b/kernel/debug.h @@ -20,6 +20,7 @@ * are disabled. */ #define DEBUG_ENABLE_IPC_WARNINGS 0 +#define DEBUG_STACKTRACE 1 /* It's interesting to measure the time spent withing locked regions, because * this is the time that the system is deaf to interrupts. diff --git a/kernel/exception.c b/kernel/exception.c index d269f4af9..df6343ace 100755 --- a/kernel/exception.c +++ b/kernel/exception.c @@ -65,6 +65,10 @@ unsigned vec_nr; saved_proc->p_reg.cs, saved_proc->p_reg.pc, saved_proc->p_reg.ss, saved_proc->p_reg.sp); kprintf("edi = 0x%x\n", saved_proc->p_reg.di); + +#if DEBUG_STACKTRACE + stacktrace(saved_proc); +#endif } #endif @@ -85,3 +89,34 @@ unsigned vec_nr; panic("exception in a kernel task", NO_NUM); } +#if DEBUG_STACKTRACE +/*===========================================================================* + * stacktrace * + *===========================================================================*/ +PUBLIC void stacktrace(proc) +struct proc *proc; +{ + reg_t bp, v_bp, v_pc, v_hbp; + + v_bp = proc->p_reg.fp; + + kprintf("stacktrace: "); + while(v_bp) { + phys_bytes p; + if(!(p = umap_local(proc, D, v_bp, sizeof(v_bp)))) { + kprintf("(bad bp %lx)", v_bp); + break; + } + phys_copy(p+sizeof(v_pc), vir2phys(&v_pc), sizeof(v_pc)); + phys_copy(p, vir2phys(&v_hbp), sizeof(v_hbp)); + kprintf("0x%lx ", (unsigned long) v_pc); + if(v_hbp != 0 && v_hbp <= v_bp) { + kprintf("(bad hbp %lx)", v_hbp); + break; + } + v_bp = v_hbp; + } + kprintf("\n"); +} +#endif + diff --git a/kernel/proto.h b/kernel/proto.h index bfaa88e3d..f9a68f226 100755 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -74,6 +74,9 @@ _PROTOTYPE( int newmap, (struct proc *rp, struct mem_map *map_ptr) ); /* exception.c */ _PROTOTYPE( void exception, (unsigned vec_nr) ); +#if DEBUG_STACK_TRACE +_PROTOTYPE( void stacktrace, (struct proc *) ); +#endif /* i8259.c */ _PROTOTYPE( void intr_init, (int mine) );