RFC: Stack saving/tracing functionality.

Antoine Brodin antoine.brodin at laposte.net
Fri Jun 10 21:33:00 GMT 2005


"Poul-Henning Kamp" <phk at phk.freebsd.dk> wrote:
> In message <20050608221829.75c2de12.antoine.brodin at laposte.net>, Antoine Brodin writes:
> >Hi,
> >
> >
> >With Jeff@'s help, I implemented stack saving/tracing functionality.
> 
> Thankyou!
> 
> >Another question: Since the stack saving/tracing functionality depends
> >on ddb, should kern/subr_stack.c be moved to ddb/stack.c and
> >sys/stack.h to ddb/stack.h?
> 
> No.
> 
> This code should be compiled in as standard so that any panic prints
> a stacktrace on the console, also for non-KDB kernels.

I put the MD code in <arch>/<arch>/db_trace.c to avoid the duplication
of some structure declarations like i386_frame, or the definition of the
INKERNEL macro.
Should I move these to something like <arch>/include/frame.h and put
stack_save in its own file (this function is around 20 lines per arch) ?

> A sysctl to enable grepping a backtrace from core-dumping processes
> would be wonderful as well.

It isn't possible to backtrace processes while they're in userland yet,
and I'm not sure it would be safe (one could corrupt its own stack to
try to confuse the kernel) and useful (gdb handles core dumps very
well).
But you can grab the end of life of the process in the kernel like:
%%%
#0 0xc04d712c at sigexit+0xfc
#1 0xc04d6d9c at postsig+0x19c
#2 0xc04f8fc8 at ast+0x4d8
#3 0xc061726d at doreti_ast+0x17
%%%
I don't know if this is what you were looking for ?

An updated patch with a correction in the alpha case is at:
http://bsd.miki.eu.org/~antoine/stack/stack-06-10.diff

Cheers,

Antoine


More information about the freebsd-arch mailing list