From: Thomas Veerman Date: Fri, 30 Mar 2012 09:16:46 +0000 (+0000) Subject: libmthread: add stack traces X-Git-Tag: v3.2.1~602 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/expt.png?a=commitdiff_plain;h=8ae9987dcaddb0bbf9b658e4a6b780b4859f8604;p=minix.git libmthread: add stack traces --- diff --git a/include/minix/mthread.h b/include/minix/mthread.h index 786557a09..1ac6b0c70 100644 --- a/include/minix/mthread.h +++ b/include/minix/mthread.h @@ -114,6 +114,8 @@ int mthread_setspecific(mthread_key_t key, void *value); void mthread_stats(void); void mthread_verify_f(char *f, int l); #define mthread_verify() mthread_verify_f(__FILE__, __LINE__) +void mthread_stacktrace(mthread_thread_t t); +void mthread_stacktraces(void); /* mutex.c */ int mthread_mutex_destroy(mthread_mutex_t *mutex); diff --git a/lib/libmthread/misc.c b/lib/libmthread/misc.c index ae7a9b2df..c9c9f1775 100644 --- a/lib/libmthread/misc.c +++ b/lib/libmthread/misc.c @@ -109,3 +109,53 @@ void mthread_stats(void) } #endif + + +/*===========================================================================* + * mthread_stacktrace * + *===========================================================================*/ +void mthread_stacktrace(mthread_thread_t t) +{ + unsigned long bp, hbp, pc; + mthread_tcb_t *tcb; + ucontext_t *ctx; + mcontext_t *mtx; + struct stackframe_s *frame; + + printf("thread %d: ", t); + + tcb = mthread_find_tcb(t); + ctx = &tcb->m_context; + mtx = &ctx->uc_mcontext; + frame = &mtx->mc_p_reg; + bp = frame->fp; + + while (bp) { + pc = ((unsigned long *) bp)[1]; + hbp = ((unsigned long *) bp)[0]; + + printf("0x%lx ", (unsigned long) pc); + + if (hbp != 0 && hbp <= bp) { + pc = -1; + printf("0x%lx ", (unsigned long) pc); + break; + } + bp = hbp; + } + + printf("\n"); +} + +/*===========================================================================* + * mthread_stacktraces * + *===========================================================================*/ +void mthread_stacktraces(void) +{ + mthread_thread_t t; + + mthread_stacktrace(MAIN_THREAD); + + for (t = (mthread_thread_t) 0; t < no_threads; t++) + mthread_stacktrace(t); +}