From owner-freebsd-current@FreeBSD.ORG Thu Mar 5 20:00:25 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D4F9A1065672; Thu, 5 Mar 2009 20:00:25 +0000 (UTC) (envelope-from marius@nuenneri.ch) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.158]) by mx1.freebsd.org (Postfix) with ESMTP id 47A978FC0C; Thu, 5 Mar 2009 20:00:24 +0000 (UTC) (envelope-from marius@nuenneri.ch) Received: by fg-out-1718.google.com with SMTP id l26so367417fgb.35 for ; Thu, 05 Mar 2009 12:00:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.86.95.8 with SMTP id s8mr1331402fgb.79.1236283223997; Thu, 05 Mar 2009 12:00:23 -0800 (PST) In-Reply-To: References: <5f695cd0903050937h320e72dbrfef1d9e1a1d3b543@mail.gmail.com> Date: Thu, 5 Mar 2009 21:00:23 +0100 Message-ID: From: =?ISO-8859-1?Q?Marius_N=FCnnerich?= To: Robert Watson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: George Kumar , freebsd-current@freebsd.org Subject: Re: how to dump kernel function trace in freebsd X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Mar 2009 20:00:26 -0000 On Thu, Mar 5, 2009 at 19:32, Robert Watson wrote: > 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_tra= ce >> options in the config file ? is that correct ? > > For debugging purposes, kdb_backtrace() is the preferred interface, and a= s > 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. =A0Th= is > requires "options STACK" to be in the kernel configuration, but this is t= he > 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). =A0You can print stack traces to the console, > print them to sbuf's to be used elsewhere, etc. =A0Keep in mind that you'= ll > want to resolve the symbols (using a string conversion function) fairly s= oon > 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. As said in the forums a fairly elegant solution is to use DTrace for this task. Just add a SDT probe to the code in question and use stack() in your DTrace script. Maybe the FBT provider already provides an appropriate probe so you don't even need to add a SDT probe.