Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Mar 2009 18:32:28 +0000 (GMT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        George Kumar <grgkumar4@gmail.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: how to dump kernel function trace in freebsd
Message-ID:  <alpine.BSF.2.00.0903051830030.31079@fledge.watson.org>
In-Reply-To: <5f695cd0903050937h320e72dbrfef1d9e1a1d3b543@mail.gmail.com>
References:  <5f695cd0903050937h320e72dbrfef1d9e1a1d3b543@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 5 Mar 2009, George Kumar wrote:

> In Linux I could use dump_stack() this to see how a function was called - 
> (In essence stack trace back ),
>
> Function() {
> dump_stack();
> .....
> ...
> }
> What is the equivalent to dump_stack() in freebsd ?
>
> Is it kdb_backtrace() ? But for this I need to have kdb, ddb and kdb_trace 
> options in the config file ? is that correct ?

For debugging purposes, kdb_backtrace() is the preferred interface, and as you 
point out, it depends on the kernel debugger being present.

For more general (read: production) use, you can also capture, print, and 
generally manage stack traces using the stack(9) kernel interfaces.  This 
requires "options STACK" to be in the kernel configuration, but this is the 
default in 7.x and 8.x as it is required for procstat's -k command line option 
to work (which allows userspace to print out kernel stacks without using the 
kernel debugger).  You can print stack traces to the console, print them to 
sbuf's to be used elsewhere, etc.  Keep in mind that you'll want to resolve 
the symbols (using a string conversion function) fairly soon after the stack 
is captured so that symbol names in kernel modules are resolved before there's 
an opportunity for the module to be unloaded.

Robert N M Watson
Computer Laboratory
University of Cambridge



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.00.0903051830030.31079>